unity 光探头_带光探头的静态照明

unity 光探头

In 2019.2, we removed the Lightmap Static Flag, replacing it with the Contribute Global Illumination Flag. We also introduced the ability to choose whether Global Illumination is received from Lightmap or Light Probes. These changes can have a huge impact on your baking performance, quality of Scene lighting, and more! Let’s explore this further.

在2019.2中,我们删除了Lightmap静态标志,将其替换为Contribute Global Illumination Flag。 我们还介绍了选择从Lightmap还是从Light Probes接收全局照明的功能。 这些更改可能会对您的烘焙性能,场景照明的质量等产生巨大影响! 让我们进一步探讨。

光照贴图和光探针 (Lightmapping and Light Probes)

Global illumination involves complex calculations to compute the way light bounces from surface to surface once it leaves its source. This is generally difficult to do accurately without adding costly calculations during run-time. A common approach for solving this problem while achieving the best-quality output is to shift the heavy computation to a precomputation step, which would happen in Edit mode.

全局照明涉及复杂的计算,以计算光离开光源后从一个表面反射到另一个表面的方式。 如果在运行时不添加昂贵的计算,通常很难准确地做到这一点。 在获得最佳质量输出的同时解决此问题的常用方法是将繁重的计算转移到预计算步骤,这将在“编辑”模式下发生。

To do this, we assume that several objects and light sources in a Scene will stay in place relative to one another, will not deform, and will not rotate or change any of their appearance properties. With these assumptions made, light can then be computed using a technique known as lightmapping.

为此,我们假定场景中的多个对象和光源将相对彼此保持在适当的位置,不会变形,也不会旋转或更改其任何外观属性。 在做出这些假设的情况下,可以使用称为光照贴图的技术来计算光。

To mark such objects, Unity provided the Lightmap Static flag. While this feature name made sense when it was created, the name also implied that only static objects were using lightmaps. But static lightmaps are just one of many different ways to store global illumination in a Scene, and they come with certain disadvantages, which we will discuss later. 

为了标记此类对象,Unity提供了Lightmap Static标志。 尽管此功能名称在创建时就很有意义,但该名称还暗示只有静态对象在使用光照贴图。 但是静态光照贴图只是在场景中存储全局照明的许多不同方式之一,它们具有某些缺点,我们将在后面讨论。

Using a lightmapping approach to global illumination, non-static (or dynamic) objects cannot contribute to global illumination because they violate the assumption that they’re static. Computing global illumination for an object that later moves means that lighting would only be valid for the position in which it was initially lit. This is a major limitation of traditional lightmapping. 

使用灯光映射方法进行全局照明时,非静态(或动态)对象无法对全局照明有所帮助,因为它们违反了它们是静态的假设。 计算稍后移动的对象的全局照明意味着照明仅对最初被照明的位置有效。 这是传统光映射的主要限制。

Dynamic objects can still receive global illumination from other static objects via Light Probes. Light Probes are positions in space where a sample of the light coming from all directions is stored. This light is encoded into special values called “spherical harmonics.” During run-time, dynamic objects can then receive values from surrounding Light Probes as the object moves through the world. This allows dynamic objects to receive local lighting in order to appear correctly integrated with surrounding lighting conditions.

动态对象仍可以通过光探测器从其他静态对象接收全局照明。 光探头 是存储来自各个方向的光的样本在空间中的位置。 该光被编码为称为“球谐”的特殊值。 在运行时,动态对象可以随着对象在整个世界中移动而从周围的光探测器接收值。 这允许动态对象接收局部照明,以便与周围的照明条件正确集成。

Technically, nothing would prevent a static object from using Light Probes instead of lightmaps. 

从技术上讲,没有什么可以阻止静态对象使用光探测器而不是光贴图。

Why would you want to do that?

你为什么想这么做?

纹素的成本 (The cost of texels)

Objects that need to be lightmapped must be unwrapped and have space reserved in a lightmap. Depending on the resolution, each object projected into a lightmap will reserve a certain amount of texels

需要进行光照贴图的对象必须被 解包 并在光照贴图中保留空间。 根据分辨率,投影到光照贴图中的每个对象将保留一定数量的 纹理像素

As an example, a unit cube (dimension 1x1x1) at a lightmap resolution of one texel per unit of space will reserve one texel for each side. This would mean six texels in total. For each of these texels, the lightmapper would then need to compute the light arriving at that texel’s world position. This is done by casting rays and bouncing them through the Scene until they find a light source. The more texels used, the more work required to compute the result. In Scenes with many small objects, this adds up to a lot of work. In fact, unwrapping, charting, and lightmapping these types of objects is the most common cause of lightmap bakes failing or taking an unacceptably long time.

例如,光立方分辨率为每单位空间一个texel的单位立方体(尺寸1x1x1)将为每侧保留一个texel。 这将意味着总共六个纹理像素。 对于每个这些纹理像素,光照贴图器将需要计算到达该纹理像素世界位置的光。 这是通过投射光线并使它们在场景中反弹直到它们找到光源来完成的。 使用的纹理像素越多,计算结果所需的工作就越多。 在包含许多小物体的场景中,这需要大量的工作。 实际上,展开,绘制图表和对这些类型的对象进行光照贴图是光照贴图烘烤失败或花费不可接受的长时间的最常见原因。

A unity-cube occupying exactly one texel when lightmap resolution is set to 1.

当光照贴图分辨率设置为1时,一个统一立方体正好占据一个texel。

Small objects, such as pebbles and debris, or thin objects like wires and poles can easily produce “waste texels.” These are texels that don’t contribute significantly to the overall look of an object but still add computation time and consume space in the lightmap. 

小物体(例如鹅卵石和碎屑)或细物体(例如电线和电线杆)很容易产生“废纹素”。 这些纹理像素 对对象的整体外观没有显着影响,但仍会增加计算时间并占用光照贴图中的空间。

Thin objects often produce unwraps in which one or two pixels wrap around an object’s length and therefore have very little impact on the look. Similarly, small objects tend to produce several texels in the lightmap that – given the size of the object on screen – do not contribute much, if anything, to the final look. The end result is that a lot of computation time is lost on texels that do not matter to us visually, but still increase the amount of lightmap space needed.

稀薄的物体通常会产生缠绕现象,其中一个或两个像素围绕物体的长度缠绕,因此对外观的影响很小。 同样,在屏幕上,小物体往往会在光照图中生成多个纹理像素,这些像素在屏幕上会产生一定的影响,如果有的话,它们对最终外观的贡献不大。 最终结果是,在像素上浪费了很多计算时间,这些像素在视觉上对我们并不重要,但仍然会增加所需的光照贴图空间。

A sample selection of small objects which could easily be lit with Light Probes.

可以用光探头轻松点燃的小物体的样本选择。

A good way to optimize the time it takes to produce a lightmap is removing these small objects out of lightmap calculations by making them non-static. This reduces the number of occupied lightmap texels which need to be calculated. However, in some cases these objects may have had a significant influence on lighting in the Scene. Imagine a case where there’s a very brightly colored object, or perhaps one with an emissive material. If these objects aren’t lightmap static, they will not be able to contribute to global illumination in the Scene. Their potentially significant influence on the expected lighting result would be missing.

优化制作光照贴图的时间的一种好方法是通过使这些小对象变为非静态来从光照贴图计算中删除这些小对象。 这减少了需要计算的占用光照贴图纹理像素的数量。 但是,在某些情况下,这些对象可能会对场景中的照明产生重大影响。 想象一下一种情况,其中有一个颜色非常鲜艳的物体,或者是一个带有发光材料的物体。 如果这些对象不是静态的光照贴图,则它们将无法为场景中的全局照明做出贡献。 它们对预期照明结果的潜在重大影响将丢失。

One is now left with two options for how to deal with these types of objects: Lightmap them to include their influence on the rest of the Scene, even though this can make baking times longer and waste space in lightmaps, or drop their influence, at the cost of the overall look and global illumination quality. How do you solve this dilemma?

现在,剩下的两个选项用于处理这些类型的对象:对它们进行光照贴图以包括其对场景其余部分的影响,即使这样做可能会延长烘焙时间并浪费光照图中的空间,也可能降低其影响。整体外观成本和整体照明质量。 您如何解决这个难题?

改用光探头 (Using Light Probes instead)

In 2019.2, we’ve added the ability to make objects receive global illumination from light probes while still contributing lighting to the Scene. This can be enabled using a small dropdown menu added to the Inspector under the Mesh Renderer.

在2019.2中,我们增加了使对象从光探测器接收全局照明的功能,同时仍为场景提供照明。 可以使用添加到“网格渲染器”(Mesh Renderer)下的“检查器”(Inspector)中的小下拉菜单来启用此功能。

The new options to Contribute and Receive Global Illumination.

提供和接收全局照明的新选项。

Here, you can choose whether a Mesh Renderer will Receive Global Illumination from Lightmaps (formerly the only option for static objects) or Light Probes (previously the only option for dynamic objects). 

在这里,您可以选择“网格渲染器”将从“ 光照 贴图”(以前是静态对象的唯一选项)还是从“光探针”(以前是动态对象的唯一选项) 接收全局照明

By enabling the Contribute Global Illumination flag, an object will be included in the global illumination computation of the lightmapper. While the assumption that objects will always be static remains, now you can explicitly control whether objects use Light Probes or lightmaps, depending on the fidelity of lighting required. Objects that Contribute Global Illumination but then Receive Global Illumination from Light Probes will still influence their surroundings. A tall lamp post will still throw a shadow that will be computed for the lightmaps around it, while an emissive material on this lamp post would still illuminate the surrounding Scene.

通过启用“ 贡献全局照明” 标记,对象将包含在光照贴图的全局照明计算中。 尽管仍然保留对象始终是静态的假设,但是现在您可以根据所需照明的保真度来明确控制对象是使用光探测器还是使用光照贴图。 产生 全局照明 但随后 从光探测器 接收全局照明的 对象 仍会影响其周围环境。 高高的灯柱仍会投射阴影,该阴影将根据周围的光照图进行计算,而此灯柱上的发光材料仍会照亮周围的场景。

使用功能 (Using the feature)

With this newly available functionality in Unity, optimizing away problematic small objects and thin objects is straightforward: Simply set the Receive Global Illumination field on Mesh Renderers to Light Probes. With this setting, the objects will no longer take up space in your lightmaps, meaning these texels will no longer make the lightmapper busy unnecessarily. 

借助Unity中新提供的功能, 可以 轻松 地优化有问题的小物体和薄物体:只需将“ 网格渲染器”上 的“ 接收全局照明” 字段 设置 为“ 光探测器”即可 。 使用此设置,对象将不再占用光照贴图中的空间,这意味着这些纹理像素将不再使光照贴图程序变得不必要。

A key beneficial side effect of using Light Probes is that they don’t need proper UVs, which can be time-consuming to unwrap. If you have a dynamic object that looks great with Light Probes but that never actually moves, rotates, or is otherwise modified, you can now choose to flag it with Contribute Global Illumination. The object can then influence surrounding lightmapped objects without increasing the bake time. This speed means an increase in productivity while reducing memory usage.

使用光探头的一个关键的有益副作用是,它们不需要适当的紫外线,这可能会很费时。 如果您有一个动态对象,看起来很适合“光探针”,但是从不实际移动,旋转或进行其他修改,则可以选择使用“ 贡献全局照明” 进行标记 然后,对象可以影响周围的光照贴图对象,而不会增加烘焙时间。 这种速度意味着在减少内存使用的同时提高生产率。

结论 (Conclusion)

With this innovation, dynamic (or non-Static) objects can be lit with Light Probes. This lets you specify whether the objects included in your global illumination calculations receive indirect lighting from Light Probes or lightmaps, giving you the ability to decrease texel usage in Lightmaps. Overall, this change could substantially reduce the computation time for lightmaps, lower memory usage, and offer better run time performance.

通过这种创新,可以用光探头照亮动态(或非静态)对象。 这使您可以指定包含在全局照度计算中的对象是从光照探测器还是从光照贴图接收间接光照,从而使您能够减少光照贴图中的纹素使用。 总体而言,此更改可以大大减少光照贴图的计算时间,降低内存使用量,并提供更好的运行时性能。

If you are interested in more ways to optimize global illumination in your project, you can watch this talk from Unite 2018.

如果您对优化项目中全局照明的更多方法感兴趣,可以观看 Unite 2018的演讲

团结哥本哈根是下个月 (Unite Copenhagen is next month)

Want to learn more? Meet us at Unite Copenhagen, which takes place September 23–26. It’s a unique opportunity to engage with thousands of talented creators and top developers from around the world!

想了解更多? 在 9月23日至26日 于 哥本哈根 举行的 团结 大会上与我们会面 。 这是与世界各地成千上万的才华横溢的创作者和顶尖开发者互动的独特机会!

学习,交流,参与 (Learn, network, participate)

  • Get ahead with the latest Unity features, tips & tricks, and cool reveals in dozens of tech sessions, pop-up talks, and a keynote presentation.

    在数十个技术会议,弹出式对话和主题演讲中,获得Unity的最新功能,技巧和窍门以及炫酷的内容,以取得成功。

  • Meet industry leaders and make new friends at fun networking events and “Unite at Night” gatherings. 

    在有趣的社交活动和“夜间团结”聚会中与行业领导者见面并结交新朋友。

  • Uplevel your Unity skills and make career-advancing connections in workshops, Q&A sessions, and community events.

    提升您的Unity技能,并在研讨会,问答环节和社区活动中建立职业发展联系。

Learn more about Unite Copenhagen on our website, and don’t forget to follow us on Twitter and Facebook for the latest news.

在我们的 网站 上了解有关Unite Copenhagen的更多信息 ,不要忘记在 TwitterFacebook 上关注我们以 获取最新消息。

翻译自: https://blogs.unity3d.com/2019/08/28/static-lighting-with-light-probes/

unity 光探头