Search Unity

Question 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:

    Sinister-Design likes this.
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    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:
    196
    Any news on this?
     
    noio likes this.
  4. deram_scholzara

    deram_scholzara

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

    Jackrabbit82

    Joined:
    Mar 13, 2013
    Posts:
    16
    +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:
    53
    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!
     
  8. noio

    noio

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

    nicholascarrow

    Joined:
    Feb 20, 2018
    Posts:
    2

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

    melos_han_tani

    Joined:
    Jan 11, 2018
    Posts:
    79
    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.
  11. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    856
    It is really basic but does not include, really weird. We have shader graph but without basic settings.
    In fact, we do not need fresnel, noise, rotation and a bunch of nodes because they can be implemented but ZTest!!!
     
    cultureulterior likes this.
  12. Sinister-Design

    Sinister-Design

    Joined:
    Sep 19, 2015
    Posts:
    66
    Any updates on this? Making a 2.5D game in URP is a huge pain without this functionality.
     
  13. Fressbrett

    Fressbrett

    Joined:
    Apr 11, 2018
    Posts:
    97
    Thanks a lot for that piece of information! Would be cool to have this inside of the shadergraph too though
     
    florianBrn likes this.
  14. vlab22

    vlab22

    Joined:
    Nov 22, 2012
    Posts:
    17
    OMG! Problem solved, to a better result I applied Alpha Clip to our crazy mesh alpha structure.
    My team (college project) worship you @florianBrn :)
     
    florianBrn likes this.
  15. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    Yes you can turn on zWrite. I do this on alot of my shaders..


    1. Make your shader in the graph
    2. Select your graph and click "Copy Shader" in the inspector
    3. Create a blank unlit shader and open it in visual studio then erase everything
    4. paste the shader code in the clip board to the shader in visual studio
    5. Ctrl H to find and replace zwrite off to zwrite on
    6. save it and now you can create materials from it
     
    coreybeavers1999 and X28 like this.
  16. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
    This will work, but then every time you make changes to your shader you have to repeat steps 2 to 6, not an ideal solution imho
     
  17. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    of course its not ideal, this is the BS we have to deal with in Unity.
     
    alti likes this.
  18. vambier

    vambier

    Joined:
    Oct 1, 2012
    Posts:
    102
    True, I don't understand why such trivial things are not included in shader graph which is otherwise a superb method for creating shaders imho.
     
  19. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Wow I took a year off from shadergraph and it's still not available for URP? Bizarre. Can only laugh now.
     
  20. Deleted User

    Deleted User

    Guest

    I'm running the 2021.2 beta (for custom interpolators in shadergraph) and I've got Depth Write and Depth Test in the Graph Inspector.
     

    Attached Files:

    bobbaluba, DrViJ, Seromu and 3 others like this.
  21. azevedco

    azevedco

    Joined:
    Mar 2, 2014
    Posts:
    34
    Wow, bright side there's a light at the end of the tunnel.
    Until then, found a video tutorial for applying a dithering affect for opaque shaders that can help fake transparency. Was useful for my use case!
    Here's the link:
     
  22. Oyshoboy

    Oyshoboy

    Joined:
    Jan 6, 2017
    Posts:
    20
    What's the version of Shader Graph?
     
    K0ST4S likes this.
  23. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    I set it to force enabled, but I don't see where to plug the wire in.
     
  24. Xiaozo

    Xiaozo

    Joined:
    Jun 29, 2016
    Posts:
    2
    Cheers! I was having an issue in which my models were getting culled because they were in front of other models that were transparent. I upgraded my project and under "Depth Write" I enabled "Force Enabled' and it fixed it.
     

    Attached Files:

  25. edd95al

    edd95al

    Joined:
    Sep 15, 2022
    Posts:
    2
    Dios, eres tú?
    This really saved my ass, thank you so much! TuT
     
  26. jesselugassy_unity

    jesselugassy_unity

    Joined:
    Jul 2, 2018
    Posts:
    4
    this does not work on version 222.3.11f1
     
  27. richardzzzarnold

    richardzzzarnold

    Joined:
    Aug 2, 2012
    Posts:
    142
    Thank you so much
    for this solution!