设置 GPU 上的深度偏差。
深度偏差,也称为深度偏移,是 GPU 上的一个设置,决定了 GPU 绘制几何体的深度。调整深度偏差以强制 GPU 在具有相同深度的其他几何体之上绘制几何体。这可以帮助您避免不需要的视觉效果,例如深度冲突和阴影暗斑。
要为特定几何体设置深度偏差,请使用此命令或 RenderStateBlock 。要设置影响所有几何体的全局深度偏差,请使用 CommandBuffer.SetGlobalDepthBias。除了全局深度偏差之外,GPU 还为特定几何体应用深度偏差。
为了减少阴影暗斑,您可以使用 light bias 设置实现类似的视觉效果;但是,这些设置的工作方式不同,并且不会更改 GPU 上的状态。有关更多信息,请参阅阴影故障排除。
功能名称 | 内置渲染管线 | 通用渲染管线 (URP) | 高清渲染管线 (HDRP) | 自定义 SRP |
---|---|---|---|---|
Offset | 是 | 是 | 是 | 是 |
此命令会更改渲染状态。在 Pass
代码块中使用它可为该通道设置渲染状态,或者在 SubShader
代码块中使用它可为该子着色器中的所有通道设置渲染状态。
签名 | 示例语法 | 功能 |
---|---|---|
Offset <factor>, <units> |
Offset 1, 1 |
根据给定的值,将几何体绘制得更靠近或更远离摄像机。 |
参数 | 值 | 功能 |
---|---|---|
factor | 浮点数,范围 –1 到 1。 | 缩放最大 Z 斜率,也称为深度斜率,以生成每个多边形的可变深度偏移。 不平行于近剪裁平面和远剪裁平面的多边形具有 Z 斜率。调整此值以避免此类多边形上出现视觉瑕疵。 |
units | 浮点数,范围 –1 到 1。 | 缩放最小可分辨深度缓冲区值,以产生恒定的深度偏移。最小可分辨深度缓冲区值(一个 _unit_)因设备而异。 负值意味着 GPU 将多边形绘制得更靠近摄像机。正值意味着 GPU 将多边形绘制得更远离摄像机。 |
此示例代码演示在 Pass 代码块中使用此命令的语法。
Shader "Examples/CommandExample"
{
SubShader
{
// 此处是定义子着色器的代码的其余部分。
Pass
{
// 设置此几何体的深度偏移,以便 GPU 将此几何图形绘制得更靠近摄像机
// 您通常会这样做以避免深度冲突
Offset -1, -1
// 此处是定义通道的代码的其余部分。
}
}
}
此示例代码演示在 SubShader 代码块中使用此命令的语法。
Shader "Examples/CommandExample"
{
SubShader
{
// 设置此几何体的深度偏移,以便 GPU 将此几何图形绘制得更靠近摄像机
// 您通常会这样做以避免深度冲突
Offset -1, -1
//此处是定义子着色器的代码的其余部分。
Pass
{
// 此处是定义通道的代码的其余部分。
}
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.