• Unity
  • How to write to Z as the Spine/Sprite/ shaders

Hello everyone,

my question is how do I have similar "write to Z" feature from the spine/sprites shaders for a custom shader graph shader I did?

I did a foliage sway shader that I use on the tree and bush sprites on my game, I want to use some depth of field post processing but the sprites that use my shader are always blurred because they don't write to Z, they use the sprite renderer. My sprites using the spine/sprite shaders do behave as intended with DoF because they do write to Z thanks to the feature of the Spine shaders. Is there any way to do that with my shader graph shader?

I don't know how to code shaders so I use shader graph instead, and because of that I can't copy the code that enables Z write in the spine shaders to my custom shader graph shader or open the spine shaders and add the foliage sway (vertex displacement via a gradient noise)

Thank you!

Hopefully someone can help me with this.

Related Discussions
...

You can right click on the master node in shader graph, select "Show Generated Code" then save it to somewhere and add the code that enables Z write.

Thanks, and how do I save the modified shader? as .shader or .shadergraph, I recently tried to do that and Unity didn't recognize the shader as a shader in my list of shaders for the material.
And what is the code that enables Z write?

As .shader of course. I doubt shader graph will accept arbitrary code, but I can confirm unity sees shaders generated via generated code, as long as they don't have errors.

As for z write, I'm no expert, but you might take a look at Spine/Sprite/Unlit shader which has a setting for enabling it.

DarkTI wrote

And what is the code that enables Z write?

You place the line ZWrite On in your shader pass block to have it always enabled, without using a parameter to control if it's enabled or disabled.