Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted ZWrite in shader graph

Discussion in 'Shader Graph' started by pushpindersingh, Jul 30, 2019.

  1. pushpindersingh

    pushpindersingh

    Joined:
    Apr 15, 2013
    Posts:
    1
    Can we set ZTest and ZWrite in shader graph?

    I am creating an unlit shader graph in lwrp. The aim of this shader is stylized flat shading with gradient s of color and alpha.

    When I change the unlit master node surface type to transparent, the object geometry is not occluded since the ZWrite is off.

    I am trying to change the generated shader code to ZWrite On but it reverts back when the shader is recompiled.

    Is there a way to change the ZWrite in shader graph shaders?
     

    Attached Files:

  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,295
    No.*

    It looks like this is something that has added to the latest versions of HDRP, but I haven't seen anything for LWRP yet. Technically production on LWRP has ceased as they've moved to the Universal RP (really, renamed the next version of LWRP to URP), so I would expect that feature to show up in the URP eventually.
     
  3. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    179
    Any news on this?
     
    noio likes this.
  4. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,028
    Yeah, would be good to have ZWrite and ZTest options in URP. Hopefully they're working on it...
     
  5. Jackrabbit82

    Jackrabbit82

    Joined:
    Mar 13, 2013
    Posts:
    13
    +1000 on this ! I mean it is just dumb to not have the Ztesting from the beginning in any shader tools ... it's been almost 2 years now! It's impractical/impossible to have a good looking transparent shader, I've been bypassing this with tweaking a scenecolor node in opaque (which even if not supposed to work, did the tricks for a while) ... let's just say it's a less than ideal solution.
    Custom MasterNode seems the way to go, but as anything these days in unity, it's a complete mess to try to find documentation on the matter. Getting a bit worned up to feel like a noob with 10 years of dev I would really hope that unity would stop shooting from the hip everywhere and actually finish/polish features.
     
  6. florianBrn

    florianBrn

    Joined:
    Jul 31, 2019
    Posts:
    19
    You can add the objects you want to attach your material to a new layer, then in the URP_Renderer asset add a new renderer feature. Give it a name, select the layer you want and check the box Depth, then Write Depth, and choose a Depth Test setting.

    I use this quite a lot, for example for water or grass, and it works really well.
     
  7. PhilipRauSW

    PhilipRauSW

    Joined:
    Feb 2, 2018
    Posts:
    1
    This is Gold! Thanks a lot!
     
    slembcke2 and florianBrn like this.
  8. noio

    noio

    Joined:
    Dec 17, 2013
    Posts:
    146
    I find myself often going back to Amplify specifically for this.
     
  9. nicholascarrow

    nicholascarrow

    Joined:
    Feb 20, 2018
    Posts:
    1

    Thank you I've been searching for like 3 hours straight this is really the simple answer finally. Lol
     
    cultureulterior and florianBrn like this.
  10. seagaia

    seagaia

    Joined:
    Jan 11, 2018
    Posts:
    50
    that worked for me! In trying to understand why (as I can't find any documentation about this feature lol...?) the post by Andre here was helpful:

    https://forum.unity.com/threads/renderer-features-new-renderobjects.853381/

    "
    Yes this works as if filtering objects based on some settings and then rendering them again(or the first time if they are not already rendered) and there are some options to override some settings such as how they affect/test againt depth/stencil and also material override.

    It's not quite the same as shader replacement as that replaces the shader, here we are replacing the whole material."
     
    florianBrn likes this.
unityunity