- I have some UI shaders and noticed there is `ZTest [unity_GUIZTestMode]` inside them.
- How do I set the ZTest compare function from outside of the shader?
- I encountered the following line in one of the shaders we are using: `ZTest [unity_GUIZTestMode]`
ZTest [unity_GUIZTestMode] is used in some built-in UI shaders and is set depending on the Canvas type just before a Canvas is rendered.
If you are creating custom shaders/materials for UI components you will need to add
ZTest [unity_GUIZTestMode] in your shader so the ZTest is automatically set correctly for each Canvas (LEqual, unless the Canvas is set to Screen Space Overlay, which sets it to Always). This should not be set manually as undefined behavior could occur. If this is not for a UI component or if you just want to be able to control the ZTest compare function from outside of a shader then you could create a property instead:
Information verified accurate for Unity 5.5.0f3 - 2021.2.0b3