“遮挡剔除”过程可防止 Unity 为那些被其他游戏对象完全挡住(遮挡)的游戏对象执行渲染计算。
摄像机在每一帧中执行剔除操作,这些操作会检查场景中的渲染器,并排除(剔除)那些不需要绘制的渲染器。默认情况下,摄像机执行视锥体剔除,这一过程将排除所有不在摄像机视锥体范围内的渲染器。但是,视锥体剔除不会检查渲染器是否被其他游戏对象遮挡,因此 Unity 仍会浪费 CPU 和 GPU 时间进行在最终帧中不可见的渲染器的渲染操作。遮挡剔除将阻止 Unity 执行这些徒劳的操作。
要确定遮挡剔除是否有可能改善项目的运行时性能,请考虑以下事项:
遮挡剔除会在 Unity Editor 中生成有关场景的数据,然后在运行时使用该数据来确定摄像机可以看到的内容。这种生成数据的过程称为烘焙。
在对遮挡剔除数据进行烘焙时,Unity 将场景划分为多个单元,并生成描述单元内几何体以及相邻单元之间可见性的数据。然后,Unity 尽可能合并单元,以减小生成的数据的大小。要配置烘焙过程,可以在 Occlusion Culling 窗口中更改参数,并在场景中使用遮挡区域。
在运行时,Unity 会将这些烘焙的数据加载到内存中,并且对于每个启用了 Occlusion Culling 属性的摄像机,将会对数据执行查询以确定该摄像机可以看到的内容。请注意,启用遮挡剔除后,摄像机将执行视锥体剔除和遮挡剔除。
Unity 使用 Umbra 库来执行遮挡剔除。有关详细介绍 Umbra 的文章的链接,请参阅“其他资源”页面。
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.