ZWrite in shader graph

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?


1 Like

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.

Any news on this?

1 Like

Yeah, would be good to have ZWrite and ZTest options in URP. Hopefully they’re working on it…

2 Likes

+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.

3 Likes

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.

29 Likes

This is Gold! Thanks a lot!

5 Likes

I find myself often going back to Amplify specifically for this.

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

3 Likes

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:

"
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."

1 Like

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!!!

1 Like

Any updates on this? Making a 2.5D game in URP is a huge pain without this functionality.

Thanks a lot for that piece of information! Would be cool to have this inside of the shadergraph too though

1 Like

OMG! Problem solved, to a better result I applied Alpha Clip to our crazy mesh alpha structure.
My team (college project) worship you @florianBrn :slight_smile:

1 Like

Yes you can turn on zWrite. I do this on alot of my shaders…

  • Make your shader in the graph
  • Select your graph and click “Copy Shader” in the inspector
  • Create a blank unlit shader and open it in visual studio then erase everything
  • paste the shader code in the clip board to the shader in visual studio
  • Ctrl H to find and replace zwrite off to zwrite on
  • save it and now you can create materials from it
2 Likes

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

of course its not ideal, this is the BS we have to deal with in Unity.

1 Like

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.

2 Likes

Wow I took a year off from shadergraph and it’s still not available for URP? Bizarre. Can only laugh now.

2 Likes

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.

6 Likes