Version: 2020.3
Language : English
ShaderLab command: ZClip
ShaderLab command: ZWrite

ShaderLab command: ZTest

Sets the conditions under which geometry passes or fails depth testing.

Depth testing allows GPUs that have “Early-Z” functionality to reject geometry early in the pipeline, and also ensures correct ordering of the geometry. You can change the conditions of depth testing to achieve visual effects such as object occlusion.

Render pipeline compatibility

Feature name Built-in Render Pipeline Universal Render Pipeline (URP) High Definition Render Pipeline (HDRP) Custom SRP
ZTest Yes Yes Yes Yes

Usage

This command makes a change to the render state. Use it in a Pass block to set the render state for that Pass, or use it in a SubShader block to set the render state for all Passes in that SubShader.

Signature Example syntax Function
ZTest [operation] ZTest Less Set the conditions under which geometry passes or fails depth testing.

Valid parameter values

Parameter Value Function
operation Less Draw geometry that is in front of existing geometry. Do not draw geometry that is at the same distance as or behind existing geometry.
LEqual Draw geometry that is in front of or at the same distance as existing geometry. Do not draw geometry that is behind existing geometry.

This is the default value.
Equal Draw geometry that is at the same distance as existing geometry. Do not draw geometry that is in front of or behind existing geometry.
GEqual Draw geometry that is behind or at the same distance as existing geometry. Do not draw geometry that is in front of existing geometry.
Greater Draw geometry that is behind existing geometry. Do not draw geometry that is at the same distance as or in front of existing geometry.
NotEqual Draw geometry that is not at the same distance as existing geometry. Do not draw geometry that is at the same distance as existing geometry.
Always No depth testing occurs. Draw all geometry, regardless of distance.

Examples

This example code demonstrates the syntax for using this command in a Pass block.

Shader "Examples/CommandExample"
{
    SubShader
    {
         // The rest of the code that defines the SubShader goes here.

        Pass
        {    
              // Sets the depth test operation to Equal for all pixels in this Pass
              // You would typically do this if you want to render the geometry exactly where already rendered geometry is
              ZTest Equal
            
              // The rest of the code that defines the Pass goes here.
        }
    }
}

This example code demonstrates the syntax for using this command in a SubShader block.

Shader "Examples/CommandExample"
{
    SubShader
    {
        // Sets the depth test operation to Equal for all pixels in this Pass
        // You would typically do this if you want to render the geometry exactly where already rendered geometry is
        ZTest Equal

         // The rest of the code that defines the SubShader goes here.        

        Pass
        {    
              // The rest of the code that defines the Pass goes here.
        }
    }
}
ShaderLab command: ZClip
ShaderLab command: ZWrite