Search Unity

Grab pass with geometry queue or surface transparent with zwrite.

Discussion in 'Shaders' started by kripto289, Mar 24, 2017.

  1. kripto289

    kripto289

    Joined:
    Feb 21, 2013
    Posts:
    505
    Hello,
    I write water shader and shader does not work with posteffects (because does not write to zbuffer).
    Shader is "surface".
    When I write
    Code (CSharp):
    1.   Tags{ "RenderType" = "Opaque" "Queue" = "Geometry" }
    then Zwrite works, but "grabpass" is flickering (because it should grab after opaque geometry).

    Grabpass works only when I write
    Code (CSharp):
    1. Tags{ "RenderType" = "Transperent" "Queue" = "Transparent" }
    But then does not work Zwrite.

    How I can write to zbuffer with transparent surface shader?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
  3. kripto289

    kripto289

    Joined:
    Feb 21, 2013
    Posts:
    505
    It does not work, grabpass is flickering, because 0-2500 renderer queue is steel "opaque". Grabpass works after 2500 (for example Geometry+501), but then zwrite does not work again.
     
  4. kripto289

    kripto289

    Joined:
    Feb 21, 2013
    Posts:
    505
    Maybe I can write to zbuffer manualy? How I can do that with SV_Depth? I don't understand how it works.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    If you're using the forward rendering path, the depth texture used by post effects is actually a separate rendering of the entire scene using the shadowcaster pass of your shader. It's also what the scene's main directional shadows actually cast onto, so if you make your water surface render during that pass stuff underwater won't get properly shadowed.

    If you're using the deferred rendering path the depth texture is actually the z depth rendered during the gbuffer passes, and it uses the same shadow caster pass used to render forward which renders black into the albedo gbuffer.

    If you use the frame debugger and step through rendering you can see all this happening.

    So, to answer your question, yes, you can render into the depth separately. The easiest way I can think of to do it setup two different materials with one using the opaque queue, but rendering nothing in the forward pass, and a second that renders your water. There's probably a better way to do it, but you'll probably have to look at some of the water shaders on the asset store to figure out a better way.
     
    Leoo likes this.