- Home /
Found undocumented ZTest mode, unity_GUIZTestMode for Shader. What kind of ZTest mode this is?
While writing my GUI shaders, I noticed that the built-in default UI shader had a particular ZTest mode called "unity_GUIZTestMode". I've searched the documents and Google with no one mentioning what this particular ZTest means. Does anyone know what it is?
I would assume it forces rendering on top of any object, no matter its ztest value.
Probably something implemented just to counteract the Greater ZTest mode. Useful information, nonetheless.
Answer by Bunny83 · Jul 27, 2016 at 08:42 PM
"unity_GUIZTestMode" is not a "particular ZTest mode" but a shader variable. It allows you to specify the ZTest mode from outside. Unity does this for multiple shader settings so they can be changed either in the material inspector or via code. The inspector only shows properties which has been declared at the top of the shader. "unity_GUIZTestMode" has to be a built-in variable. Who sets it and to what default value i have no idea.
Answer by Sk205000 · Jan 06, 2017 at 04:59 PM
To my point unity_GUIZTestMode is important when use ugui,which make the material used on Image work on iphone,while dont need on mac.
Believe it or not, I`ve just registered account for saying "Thank you" for this answer :) unity_GUIZTest$$anonymous$$ode really needs for UGUI shaders
Answer by Celtc · Sep 26, 2017 at 04:10 AM
To gain access to the ZTest from the material inspector, add the following line in the shader properties
[Enum(UnityEngine.Rendering.CompareFunction)] unity_GUIZTestMode("ZTest", Float) = 4
This will display an enum with all possible values of the Z Testing, with the default value of LEqual.
I'm attaching a sample shader which has this property added.
Documentation :
ZTest: https://docs.unity3d.com/Manual/SL-CullAndDepth.html
Material Property Drawers: https://docs.unity3d.com/ScriptReference/MaterialPropertyDrawer.html
You can also change it directly in code without modifying the shader like so
Canvas.GetDefaultCanvas$$anonymous$$aterial().SetInt(
"unity_GUIZTest$$anonymous$$ode",
(int)UnityEngine.Rendering.CompareFunction.Always
);
Your answer
![](https://koobas.hobune.stream/wayback/20220612085310im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A Cg shader semantic problem 2 Answers
Shader - What is float3.xy? 1 Answer
How to achive the same look? Which shaders to use? 2 Answers
shadertoy to unity,Shadertoy to unity 0 Answers
Unity Advanced Shader Help 0 Answers