Version: 2021.3
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.

レンダーパイプラインの互換性

機能名 ビルトインレンダーパイプライン ユニバーサルレンダーパイプライン (URP) HD レンダーパイプライン (HDRP) カスタム SRP
ZTest

使用法

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.

シグネチャ Example syntax 機能
ZTest [operation] ZTest Less Set the conditions under which geometry passes or fails depth testing.

有効なパラメーター値

パラメーター   機能
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.

このコードサンプルでは、Pass ブロックでこのコマンドを使用するための構文を示しています。

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