当场景中的某个游戏对象距离摄像机很远时,与距离摄像机很近的游戏对象相比,细节的可见程度将大大降低。即使无法看到远处游戏对象上的细节,Unity 也会使用相同数量的三角形来渲染两个远近不同距离的游戏对象。
要优化渲染,可使用_细节级别_ (LOD) 技术。使用此技术可以随着某个游戏对象与摄像机的距离增加而减少渲染对象的三角形数量。您可以使用多个网格以及可选的公告牌资源,它们都表示同一个游戏对象,但在几何体中的细节递减。每个网格都包含一个 Mesh Renderer 组件并表示“网格 LOD 级别”,而公告牌资源有一个 Billboard Renderer 组件并表示“公告牌 LOD 级别”。
只要全部的游戏对象不是同时靠近摄像机,LOD 便能降低硬件的负载并提高渲染性能。
在 Unity 中,可使用 LOD Group 组件为游戏对象设置 LOD 渲染。下图显示了 LOD 级别如何根据与摄像机的距离而变化。
图 1 显示的是第一个级别:LOD 0。此级别最接近摄像机,因此是细节级别最高 LOD 级别。例如,当游戏对象的高度占据 50% 或更多的屏幕高度时,许多第一级 LOD 都处于活动状态。
图 2 显示的是下一个级别:LOD 1。此级别距离摄像机更远,因此 LOD 级别更低。例如,许多 LOD 组使用三个级别:当游戏对象占据 25% 到 49% 之间的屏幕高度时,LOD 1 处于活动状态,而当游戏对象占据小于 25% 的屏幕高度时,LOD 2 处于活动状态。
由于 LOD 级别的设置取决于目标平台和可用的渲染性能,因此您可以在 Unity 中设置最高 LOD 级别和 Lod Bias 质量设置。Lod Bias 决定了处于阈值距离时提高还是降低 LOD 级别。
导入一组 LOD 网格时,如果遵循以下命名规则,Unity 会使用适当的设置自动为游戏对象创建一个 LOD 组:
_LOD
结尾,数字从 0
到 LOD 级别总数减 1。例如,如果网格的基本名称是 _Player_,则可以将文件命名为 Player_LOD0
、Player_LOD1
和 Player_LOD2
,以生成具有三个 LOD 级别的 Player 游戏对象。_LOD0
。可根据需要使用任意数量的 LOD 级别。
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.