深度偏差,也称为深度偏移,是 GPU 上的一个设置,决定了 GPU 绘制几何体的深度。调整深度偏差可强制 GPU 在具有相同深度的其他几何体之上绘制几何体。这可以帮助您避免不需要的视觉效果,例如深度冲突和阴影暗斑。
要为特定几何体设置深度偏差,请使用此命令或 RenderStateBlock。要设置影响所有几何体的全局深度偏差,请使用 CommandBuffer.SetGlobalDepthBias。除了全局深度偏差之外,GPU 还可以为特定几何体应用深度偏差。
为了减少阴影暗斑,您可以使用光源偏差 (Light Bias) 设置实现类似的视觉效果;但是,这些设置的工作方式不同,并且不会更改 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.
}
}
}