Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UAV, Surface shader and early z-test

Discussion in 'Shaders' started by NeonTanto, Mar 3, 2017.

  1. NeonTanto

    NeonTanto

    Joined:
    Jun 19, 2013
    Posts:
    156
    Hi all. Maybe somebody knows answer to my question. I need fill UAV in surface shader with ZTest, but if shader use UAVs, optimizer turn off early ZTest (because it think, that I need fill UAV even if it not drawn)... And I dont find any method for turn on [earlydepthstencil] attrbute in Surface shaders. Write all light stuff in vert/frag - its mean have too many problems with updates in future. Somebidy can help me with suggestions?
    Actually I have two problems...
    1) How turn on early Z-Test (put [earlydepthstencil] to frag) into Surface shader?
    2) Or if its impossible, how I can simulate Z-Test manually in fastest way and dont write data into UAV if fragment is discarded?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You'll have to do this as a vertex fragment shader, this is exercising a surface shader behind beyond its intended goals.

    However you can use a surface shader to build the vertex fragment shader and just apply the changes you need from the generated shader code to reduce upkeep some.

    Select a surface shader, click on show generated code.
     
    Last edited: Mar 4, 2017
  3. NeonTanto

    NeonTanto

    Joined:
    Jun 19, 2013
    Posts:
    156
    I know about this method, but thx for answer.