Search Unity

DepthNormal texture - exclude objects?

Discussion in 'Shaders' started by Samhayne, Jun 18, 2020.

  1. Samhayne

    Samhayne

    Joined:
    Jun 15, 2009
    Posts:
    45
    Hey ho,

    I’m really unhappy.
    I managed to get a working setup for my water shader for which scene cameras and game cameras are rendering a depthNormal texture.

    To make the rendering for the scene view work I had to have a “main camera” tagged camera in the scene, rendering the depthNormal texture.

    But I observe that the draw calls pretty much doubled now as pretty much every object is rendered again, using the internal replacement shader to create the depth texture.

    For the water it would be enough to just render the ground and a few selected objects touching the water to the depth buffer... but how to filter?

    The only method I can think of:

    Do the shader replacement manually and render the depthTexture with its own camera, as a child of the main camera.
    I could then use layers to only render selected objects to the depthTexture... but...
    a) I’d get quite a few layer permutations (GroundWithWater, GroundNoWater, DecoObject, DecoObjectTouchingWater,...) turning the code everywhere messy where layers are used. And...
    b) The SceneView camera wouldn’t display the water shader correctly any more, as I’d need to setup a depth texture rendering camera for each SceneView camera as well (and that won’t be the end b/c how should the water shader know which of all the depthTextures it should use? I wonder how Unity solved this internally... as it currently works with my scene views and game views when I enable DepthTextureMode.DepthNormal for a main camera and all other game cameras.)

    Instead of layers I could also define a custom replacement tag, which I only put in shaders of objects which should render to the depthNormal texture.
    Though this is also pretty bad... some objects would touch the water, others wouldn’t... and while they now share the same material (and so shader), they wouldn’t anymore if I use shader tags to distinct them.

    Phew... this is all pretty ugly.
    I doubt there’s any nice solution... but I thought I’d ask anyway as I’m just not making progress on this topic any more.
    Or do I know all there is to be known about it and it’s just a matter of “pick your poison”?
     
    Last edited: Jun 18, 2020
    ROBYER1 likes this.