Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Render the scene only using a given a renderType tag

Discussion in 'Shaders' started by Okari-Draconis, Jul 2, 2014.

  1. Okari-Draconis

    Okari-Draconis

    Joined:
    Sep 2, 2013
    Posts:
    21
    Hi, is there a way I can tell the a Camera to render the whole scene, and only render objects with a specific RenderType

    With Out replacing their current shader...

    Basicly, I want to write an additional pass on multiple Shaders tagged renderType="AwesomePass"
    MainCamera will do its its normal stuff.
    Then I tell a 2nd camera to render the scene only using the AwesomePass, and then each object that has an AwesomePass will use its Own shader code, and not a replacement One.

    another way to put this is...

    I want to have Multiple Shaders that are on a Select few objects to have a Special pass tagged with renderType="AwesomePass"
    When I call a render to the scene, only the objects, that use a Shader that is tagged with "AwesomePass" will then render That specific Pass.

    I am rendering this AwesomePass to a render Texture. and Again, I DO NOT want to replace their current shader
     
    Last edited: Jul 2, 2014
    metaleap likes this.
  2. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    I might need the same I'm thinking!

    Internally there should be something like this --- for example, in Unity's Deferred render path they only render opaque meshes/materials first, then in a separate Forward pass(es) they render only alphablended meshes/materials.

    This is all happening automagically without having to set up a special separate camera or anything, so yeah would be cool for us users to be able to do something similar
     
    Okari-Draconis likes this.
  3. Okari-Draconis

    Okari-Draconis

    Joined:
    Sep 2, 2013
    Posts:
    21
    Sounds like in your experience there is no way to do what I'm asking or...?
     
  4. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    I haven't yet investigated myself since this is one of those "gonna need this soonish but not right now" cases.

    So the question, everyone, remains open!
     
  5. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,872
    You dont need shader business for that, why dont you put your awesome objects in a seperate layer and you can render these only with the second camera culling only this layer.
     
  6. Okari-Draconis

    Okari-Draconis

    Joined:
    Sep 2, 2013
    Posts:
    21
    Wont work. I need to do a main pass that renders the scene the regular way. Then do an additional pass which will render out completly different data.

    Then im planning on doing a further addutional pass for some special effects, tjat will use both the data fro my awesome pass, and the origonal screen rendering

    To clarify, i need to render the same object in 2 different ways.. and the ovject layers cant be changed due to thier tie ins with physics and mutiple other issues.

    Bottom line.. same object... same shader... rendered normaly... then rendered again with a different pass into a render texture... and i still need access to its mainTextures as well. And to complicate matters aome of the objects us a 3Dtexture for the shader, some use 2Dtexture and some are sprites
     
    Last edited: Jul 2, 2014
  7. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    Maybe i'm failing hard on this one, but why can't you do that with Camera.RenderWithShader?

    You tell it to render all objects with the tag you want and you use a simple shader that outputs the camera render texture.

    I did a glow effect that would render objects with my tag into a rendertexture and then i would blur it and composite back into the first camera.

    [edit]
    I think i got the problem, if you use the RenderWithShader that would mean that the shader code needs to be in the replacement shader
     
    Last edited: Jul 2, 2014
  8. Okari-Draconis

    Okari-Draconis

    Joined:
    Sep 2, 2013
    Posts:
    21
    Exactly, and it would be highly ideal to have the shader have acceas to the texture maps and properties of the material. ON that object..

    Some objects will have a special texture assigned to it that will help the output of this second pass. Some use a data texture kinda like a heightmap that changes via player input. exceot more complicated

    Some are calvulated on the fly from thier standard texture.

    Some use a 2D texture some us a 3D one
     
  9. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    well RenderWithShader does have access to the properties of each individual object, the glow effect i talked earlier was accessing the glow texture that each object had to create the effect

    one question, what would the output be when a given object that does NOT contain the tag is in from of another that does contain the tag? would it render it anyway or would it cutit away just like the 1st camera?

    i'm asking because it might be possible to create a mask
     
    Okari-Draconis likes this.
  10. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    How about giving names to each pass at each shader you intend to use the effect for and then use "USEPASS" in the replacement shader? This way you only ever needed to place the proper names in the replacement shader and you only had to edit the shader of the original object.

    I actually use this to create variants of the same shader that share the same code
     
    Okari-Draconis likes this.
  11. Okari-Draconis

    Okari-Draconis

    Joined:
    Sep 2, 2013
    Posts:
    21
    Hmm interesting suggestions ill look further ibto these to see if i can make it happen
     
  12. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,872
    It would work but you havent understood.

    Anyways, assuming you dont have too many different shaders used in scene, another method is to write a replacement shader for every rendertype you have with their original shaders in place and your awesome stuff as a second pass. But that will give you troubles later on.
     
    Okari-Draconis likes this.
  13. Okari-Draconis

    Okari-Draconis

    Joined:
    Sep 2, 2013
    Posts:
    21
    After reading some of kebras' posts, i now understand that a replacement shader has access to everything the main shader has access to...

    I think going with your idea of having a different render tag for each different one will work... but i have one other question..

    When I was looking at some of the built in shaders. I noticed some lines of #if usePixel or #if pointlight (or something like that)...

    Is there a way to have my own custom ones and how can i set them from a script??
     
  14. Okari-Draconis

    Okari-Draconis

    Joined:
    Sep 2, 2013
    Posts:
    21
    Actualy, just found all the info for that in the docs. Something called keywords and multicompile

    And canbjust do in a script Shader.setKeyword or sonething sinilar to set a global keyword..

    So it looks like i do my custom "pass" i can just wraped in some pragmas and mark it for multicompile...

    Then for my pass i turn on the global variable.. but now i realize it wont exclude the other shader i dont want...so that wont work
     
  15. Okari-Draconis

    Okari-Draconis

    Joined:
    Sep 2, 2013
    Posts:
    21
    *** Update ***
    Thank you both for your help, between both of you I found out that:
    When using a Replacement Shader, its being executed as if its running in that file : IE: that you have access to all the same properties and variables

    And I just had to do write a replacement shader for every rendertype I had that would Output this information.
    But instead of of using RenderType = AwesomePass. I used AwesomePass = Terrain, and AwesomePass = Fun, etc etc. Since I didn't want to completely overwrite the RenderTypes.

    ScreenShot 2D Game:

     
    Gistix, Reanimate_L and kebrus like this.
  16. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    OOOhhh...Fancy.....