Version: 2022.2
光照探针和网格渲染器
Light Probe Proxy Volume component

光照探针和场景加载

Unity 会根据您加载或卸载场景的方式而以不同方式更新其光照探针数据。

Unity 使用 LightProbes C# 对象为所有当前加载的场景存储光照探针数据。LightProbes 对象包含一个内部数据结构,称为四面体曲面细分。Unity 在其计算中使用四面体曲面细分来确定光照探针照亮游戏对象的方式。

加载或卸载场景时,Unity 会自动更新 LightProbes 对象,以包含所有当前加载的场景中所有光照探针的位置和系数。但是,Unity 是否更新四面体曲面细分取决于加载或卸载场景的方式。

When you load a Scene with LoadSceneMode.Single, Unity updates the tetrahedral tessellation automatically as part of the load process, because the new light probe data completely replaces the previous light probe data.

When you load a Scene with LoadSceneMode.Additive, or unload a Scene with UnloadSceneAsync, Unity does not automatically update the tetrahedral tessellation, because the new or removed light probe data needs to be recalculated - which is a computationally expensive operation, and there may be subsequent scenes to be loaded or unloaded after this operation.

Therefore Unity provides you with the needsRetetrahedralization event to allow you to decide when to retetrahedralize the new light probe data. For example, if you are additively loading five new scenes, you would not want to retetrahedralize the data five times, once after each scene loads. Instead, you would only want to retetrahedralize the data after all five scenes have loaded and all the new light probe data is ready.

如果 Unity 使用过时的四面体曲面细分来执行计算,则结果将不会考虑任何新加载或卸载的光照探针。这意味着光照探针可能无法按预期照亮游戏对象,而且对 LightProbes.CalculateInterpolatedLightAndOcclusionProbes()LightProbes.GetInterpolatedProbe() 的调用可能会返回意外结果。

要强制 Unity 更新四面体曲面细分,可以调用 LightProbes.TetrahedralizeLightProbes.TetrahedralizeAsync()。这些函数使 Unity 使用所有当前加载的场景的所有光照探针中的数据来更新四面体曲面细分。

更新四面体曲面细分是一项 CPU 密集型操作,并且随着光照探针数量的增加,CPU 的负载也会增加。如果要加载和卸载多个场景,并且由于更新四面体细分而对性能产生了影响,那么最好是延迟更新:等到加载或卸载了一定量的内容或者等到 CPU 负载不太可能影响应用程序性能时,再进行更新。

光照探针和网格渲染器
Light Probe Proxy Volume component