阴影级联 (Shadow Cascades) 有助于解决所谓透视锯齿的问题,在这种问题中,从方向光产生的实时阴影在靠近摄像机时会出现像素化。
阴影级联仅对方向光有效。
方向光通常模拟太阳光,单个方向光即可照亮整个场景。这意味着方向光的阴影贴图会覆盖场景的大部分,因此可能会引起称为“透视锯齿”的问题。透视锯齿是指靠近摄像机的阴影贴图像素看起来比那些更远的像素更大块。
发生透视锯齿的原因是按摄像机的视角不成比例地缩放阴影贴图的不同区域。光照阴影贴图只需覆盖摄像机可见场景的一部分;该部分是按摄像机的视锥体定义的。如果想象一种简单情况,方向光直接来自上方,即可看出视锥体和阴影贴图之间的关系。
在这个简化的示例中,视锥体的远端被阴影贴图的 20 个像素覆盖,而近端仅被 4 个像素覆盖。但是,两端都在屏幕上显示为相同大小。结果是,对于靠近摄像机的阴影区域,贴图的分辨率实际上低得多。
使用柔和阴影以及将更高分辨率用于阴影贴图时,透视锯齿不会那么明显。但是,这些解决方案在渲染时会使用更多的内存和带宽。
使用阴影级联时,Unity 可以根据与摄像机的距离将视锥体区域分成两个区域。近端区域使用尺寸减小的单独阴影贴图(但具有相同分辨率)。阴影贴图大小的这些分阶段缩减做法称为级联阴影贴图(有时称为“平行拆分阴影贴图”)。
在项目中配置阴影级联时,可以选择使用 0、2 或 5 个级联。Unity 会计算摄像机视锥体内的级联位置。
使用的级联越多,透视锯齿对阴影的影响就越小。增加级联数量会增加渲染开销。但是,此开销仍然会低于通常在整个阴影中使用高分辨率贴图的情况。
在内置渲染管线中,请在项目的质量设置 (Quality Settings) 中按质量级别属性来配置阴影级联。
在通用渲染管线 (URP) 中,请在通用渲染管线资源中配置阴影级联。
在高清渲染管线 (HDRP) 中,请为每个体积 (Volume) 配置阴影级联。
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.