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.

Thank you. I will look up what is the best way. And post my final solution!

3 Answers

3

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_GUIZTestMode really needs for UGUI shaders

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

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 [102595-billboard-ui-transparent-colored-batchedshader.txt|102595] 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.GetDefaultCanvasMaterial().SetInt( "unity_GUIZTestMode", (int)UnityEngine.Rendering.CompareFunction.Always );

Quality setting is fastest with shadow off. I am using default unity material with one directional light. I am not familiar with mip-map. I should check it out now! @Pangamini added picutres!