Is it possible to create a shader property for cull, ztest?

Hey folks,

Is there any way to create a shader property for cull or ztest? I have one shader I’d like to apply to all of my meshes, but there are a handful that I want to change the cull settings on.

I looked at the ShaderLab documentation and I couldn’t see any way to have “cull” or “ztest” be accessible as properties.

I was thinking of creating a separate vector property _myCull and then somehow using this to say if the _myCull was (1, 0, 0, 0) then cull off, if it was (0, 0, 0, 0) then cull back. Is something like that possible in a shader? I’ve modified a few of the built-in shaders but I’ve never had to deal with conditionals in this way.

Thanks,
Jared

No, that’s not possible.

Thanks for letting me know.

-Jared

This seems to do what you’re asking about:

(allowing culling options to be decided by an enum in the material, accessible via script)

This was a question from 2008 (thus for Unity 2.0), and that link is from 2014 (and is the same Aras who originally responded to this thread) talking about a feature added in 2013 to Unity 4.3.

But yes, you can do this now for pretty much every shader setting.

2 Likes

Try this:

Property
[Enum(Off,0,On,1)]_ZWrite (“ZWrite”, Float) = 1.0
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest(“ZTest”, Float) = 4 //“LessEqual”
[Enum(UnityEngine.Rendering.CullMode)] _Culling (“Culling”, Float) = 0

Pass
ZWrite [_ZWrite]
ZTest [_ZTest]
Cull [_Culling]

10 Likes

Thank you very much, you are a genius! :slight_smile: