Version: 6000.3
语言: 中文
在着色器中设置剔除模式
在着色器中设置深度剪辑模式

在着色器中设置深度偏差

深度偏差,也称为深度偏移,是GPU上的一项设置,用于确定其绘制几何体的深度。调整深度偏差以强制GPU在相同深度的其他几何体之上绘制几何体。这可以帮助您避免不必要的视觉效果,例如 z 战斗和阴影痤疮。

要设置特定几何体的深度偏差,请使用此命令或 RenderStateBlock。要设置影响所有几何体的全局深度偏差,请使用 CommandBuffer.SetGlobalDepthBias。除了全局深度偏差之外,GPU 还对特定几何体应用深度偏差。

为了减少阴影粉刺,您可以通过光线偏差设置来实现类似的视觉效果;但是,这些设置的工作方式不同,它们不会更改 GPU 上的状态。有关详细信息,请参阅影子故障排除

此示例代码演示了在 Pass 块中使用此命令的语法。

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

        Pass
        {    
              // Sets the depth offset for this geometry so that the GPU draws this geometry closer to the camera
              // You would typically do this to avoid z-fighting
              Offset -1, -1

              // The rest of the code that defines the Pass goes here.
        }
    }
}

其他资源

在着色器中设置剔除模式
在着色器中设置深度剪辑模式