https://docs.unity3d.com/Manual/LightMode-Realtime.html unity 文档
实时照明
Real-time lighting
Real-time Lights are Light components which have their Mode property set to Realtime.
Use Realtime mode for Lights that need to change their properties or which are spawned via scripts
during gameplay. Unity calculates and updates the lighting of these Lights every frame at run time. They can change in response to actions taken by the player, or events which take place in the Scene
. For example, you can set them to switch on and off (like a flickering light), change their Transforms (like a torch being carried through a dark room), or change their visual properties, like their color and intensity.
Real-time Lights illuminate and cast realistic shadows on both static and dynamic GameObjects. They cast shadows up to the Shadow Distance (defined in Edit > Project Settings
, then select the Quality category).
You can also combine real-time Lights with Realtime Global Illumination (Realtime GI), so that they contribute indirect lighting to static and dynamic GameObjects
.
实时照明
实时光源是将其Mode属性设置为Realtime的光源组件。
将实时模式用于需要更改其属性或通过脚本
生成的灯光在游戏过程中,。Unity在运行时每帧计算并更新这些灯光的照明。它们可以根据玩家的动作或场景中发生的事件而改变
。例如,您可以将它们设置为打开和关闭(如闪烁的灯光),更改其“变形”(如在暗室中手持火炬),或更改其视觉属性,例如其颜色和强度。
实时灯光可在静态和动态GameObjects上照亮并投射逼真的阴影。他们投下的阴影到阴影距离(定义编辑 > 项目设置
,然后选择质量类别)。
您还可以将实时光源与实时全局照明(Realtime GI)结合使用,以便它们为静态和动态GameObjects
贡献间接照明。Unity。
Using real-time lighting with Realtime GI
The combination of real-time lighting with Realtime GI is the most flexible and realistic lighting option in Unity. To enable Realtime GI, open the Lighting window (menu: Window > Rendering
> Lighting Settings) and tick Realtime Global Illumination.
When Realtime GI is enabled, real-time Lights contribute indirect lighting into the Scene, as well as direct lighting. Use this combination for light sources which change slowly and have a high visual impact on your Scene, such as the sun moving across the sky, or a slowly pulsating light in a closed corridor. You don’t need to use Realtime GI for Lights that change quickly, or for special effects, because the latency of the system does not make it worth the overhead.
Note that Realtime GI uses significant system resources compared to the less complex Baked GI. Global Illumination is managed in Unity by a piece of middleware called Enlighten
, which has its own overheads (system memory and CPU cycles). See documentation on Global Illumination for more information.
Realtime GI is suitable for games targeting mid-level to high-end PC systems, and games targeting current-gen consoles such as the PS4 and Xbox One
. Some high-end mobile devices might also be powerful enough to make use of this feature, but you should keep Scenes small and the resolution for real-time light maps low to conserve system resources.
To disable the effect of Realtime GI on a specific light, select the Light GameObject and, in the Light component, set the Indirect Multiplier to 0. This means that the Light does not contribute any indirect light. To disable Realtime GI altogether, open the Lighting window (menu: Window > Lighting > Settings) and untick Realtime Global Illumination.
在Realtime GI中使用实时照明
实时照明与Realtime GI的结合是Unity中最灵活,最现实的照明选项。要启用实时GI,打开照明窗口(菜单:窗口 > 渲染
> 照明设置)并勾选实时全局照明。
当实时GI启用,实时灯有助于间接照明到场景,以及直接照明。将此组合用于变化缓慢且对场景具有强烈视觉影响的光源,例如太阳在天空中移动,或在封闭的走廊中缓慢发出脉动的光。您不需要将Realtime GI用于快速变化的灯光或特殊效果,因为系统的延迟使其不值得开销。
请注意,与不太复杂的烘焙GI相比,实时GI使用了大量的系统资源。在Unity中,全局照明由一个名为Enlighten的中间件,该有其自身的开销(系统内存和CPU周期)。有关更多信息,请参见有关全局照明的文档。
Realtime GI适用于以中高端PC系统为目标的游戏,以及以PS4和Xbox One
。某些高端移动设备可能也足够强大,可以使用此功能,但您应保持较小的场景,并降低实时光照贴图的分辨率,以节省系统资源。
要禁用实时GI对特定灯光的效果,请选择“灯光游戏对象”,然后在“灯光”组件中将“ 间接倍增”设置为0。这意味着“灯光”不提供任何间接灯光。要完全禁用实时GI,请打开“照明”窗口(菜单:“ 窗口” >“ 照明” > “设置”),然后取消选中“ 实时全局照明”。
Disadvantages of using real-time lighting with Realtime GI
-
Increased memory requirements, due to the additional set of low resolution real-time light maps used to store the real-time indirect bounces computed by the Enlighten lighting system.
-
Increased shader
calculation requirements, due to sampling of the additional set of real-time light maps and probes used to store the real-time indirect bounces computed by the Enlighten lighting system. -
Indirect lighting converges over time, so property changes cannot be too abrupt. Adaptive HDR
tone mapping might help you hide this; to learn more, see the Unity Post Processing Stack (Asset Store
). -
在Realtime GI中使用实时照明的缺点
-
由于用于存储由Enlighten照明系统计算的实时间接反射的附加的一组低分辨率实时光照贴图,增加了内存需求。
-
增加的着色器
计算要求,这是由于对一组附加的实时光照贴图和探针进行了采样,这些探针用于存储由Enlighten照明系统计算的实时间接反射。 -
间接照明随着时间会聚,因此属性更改不会太突然。自适应HDR
色调映射可能会帮助您隐藏它。要了解更多信息,请参见Unity Post Processing Stack(资产存储),这是
)。
Technical details
In the case of real-time Lights (that is, Light components with their Mode set to Realtime), the last emission (or path segment) from the surface to the Light is not precomputed. This means that Lights can move around the Scene, and change visual properties like color and intensity. See documentation on Using Enlighten in Unity for more information on path segments.
If the Light also casts shadows, both dynamic and static GameObjects in the Scene are rendered into the Light’s shadow map. This shadow map is sampled by the Material Shaders of both static and dynamic GameObjects, so that they cast real-time shadows on each other. The Shadow Distance (menu: Edit > Project Settings, then select the Quality category, and navigate to the Shadows
section) controls the maximum distance at which shadows start to fade out and disappear entirely, which in turn affects performance and image quality.
If Realtime GI is not enabled, real-time Lights only calculate direct lighting on dynamic and static GameObjects. If Realtime GI is enabled, Unity uses Enlighten to precompute the surface-to-surface light paths for static GameObjects.
技术细节
对于实时光源(即,其“ 模式”设置为实时的光源组件),不会预先计算从曲面到光源的最后一个发射(或路径段)。这意味着灯光可以在场景中移动,并可以更改视觉属性,例如颜色和强度。有关路径段的更多信息,请参见有关在Unity中使用Enlighten的文档。
如果Light也投射阴影,则场景中的动态和静态GameObject都将渲染到Light的阴影贴图中。该阴影贴图由静态和动态GameObjects 的材质着色器采样,以便它们彼此之间投射实时阴影。的阴影距离(菜单:编辑 > 项目设置,然后选择质量类别,并导航到阴影
部分)控制阴影开始逐渐消失并完全消失的最大距离,从而影响性能和图像质量。
如果未启用“ 实时GI”,则“实时光照”仅计算动态和静态GameObjects上的直接光照。如果启用了实时GI,Unity将使用Enlighten预先计算静态GameObjects的表面到表面光路径。
Precomputed Realtime GI mode: Unity only precomputes surface-to-surface information
The last path segment (that is, the segment from the surface to the Light emitter) is not part of the precomputation. The only information stored is that if the surface is illuminated, then the following surfaces and probes are also illuminated, and the intensities of the various illuminations. There is a separate set of low-resolution real-time light maps, which Enlighten iteratively updates on the CPU at run time with the information of real-time Lights. Because this iterative process is computationally intensive, it is split across several frames. In other words, it takes a couple of frames until the light has fully bounced across the static elements in the Scene, and the real-time light maps and Light Probes
have converged to the final result.
For Lights with properties that change slowly (such as a light-emitting sun moving across the sky), this does not pose a problem. However, for Lights with properties that change quickly (such as a flickering lightbulb), the iterative nature of Realtime GI may prove unsuitable. Fast property changes do not register significantly with the bounced light system, so there is no point in including them in the calculations.
There are several ways to address this problem. One way is to reduce the real-time light map resolution. Because this results in less calculation at run time, the lighting converges faster. Another option is to increase the CPU Usage setting for the Realtime GI runtime. By dedicating more CPU time, the runtime converges faster. The tradeoff is of course that other systems receive less CPU time to do their work. Whether this is acceptable depends on each individual project. Note that as this is a per-Scene setting, you can dedicate more or less CPU time based on the complexity of each individual Scene in the project.
Even though Realtime GI is enabled on a per-Scene basis for all real-time Lights, it is still possible to prevent individual real-time Lights from being considered by Realtime GI. To achieve this, set the Light component’s Mode to Realtime and its indirect multiplier to 0, removing all indirect light contributions.
预先计算的实时GI模式:Unity仅预先计算地对面信息
最后的路径段(即从曲面到发光器的段)不是预计算的一部分。所存储的唯一信息是,如果表面被照亮,则随后的表面和探针也被照亮,以及各种照度的强度。还有一组单独的低分辨率实时光照贴图,Enlighten在运行时使用实时光照信息在CPU上迭代更新。由于此迭代过程的计算量很大,因此将其分为几个帧。换句话说,它需要几帧,直到光线在场景中的静态元素,实时光照贴图和光照探测器上完全反弹为止
它们已收敛到最终结果。
对于特性变化缓慢的灯光(例如发光的太阳在天空中移动),这不会造成问题。但是,对于具有快速变化的属性的灯光(例如闪烁的灯泡),实时GI的迭代特性可能不适合。快速的属性变化不会在反射光系统中显着显示,因此将它们包括在计算中没有意义。
有几种方法可以解决此问题。一种方法是降低实时光图分辨率。由于这会导致运行时的计算量减少,因此照明收敛更快。另一个选择是增加Realtime GI运行时的CPU使用率设置。通过投入更多的CPU时间,运行时收敛更快。折衷当然是其他系统获得较少的CPU时间来完成其工作。是否可以接受取决于每个单独的项目。请注意,由于这是每个场景的设置,因此您可以根据项目中每个单独场景的复杂性来分配更多或更少的CPU时间。
即使为所有实时灯光均按场景启用了实时GI,仍然有可能阻止实时GI考虑单个实时灯光。为此,请将“灯光”组件的“ 模式”设置为“ 实时”,并将其间接乘数设置为0,以消除所有间接的灯光影响。
混合照明
https://docs.unity3d.com/Manual/LightMode-Mixed.html
Backed照明
https://docs.unity3d.com/Manual/LightMode-Baked.html
Baked lighting
Baked Lights are Light components which have their Mode property set to Baked.
Use Baked mode for Lights used for local ambience, rather than fully featured Lights. Unity pre-calculates the illumination from these Lights before run time, and does not include them in any run-time lighting calculations. This means that there is no run-time overhead for baked Lights.
Unity bakes direct and indirect lighting from baked Lights into light maps (to illuminate static GameObjects) and Light Probes
(to illuminate dynamic Light GameObjects). Baked Lights cannot emit specular lighting, even on dynamic GameObjects
(see Wikipedia: Specular highlight for more information). Baked Lights do not change in response to actions taken by the player, or events which take place in the Scene
. They are mainly useful for increasing brightness in dark areas without needing to adjust all of the lighting within a Scene.
Baked Lights are also the only Light type for which dynamic GameObjects cannot cast shadows on other dynamic GameObjects.
烤灯
烘焙光是将其Mode属性设置为Baked的光源组件。
对于用于局部环境的灯光(而不是功能齐全的灯光),请使用“ 烘焙”模式。Unity会在运行前从这些Lights预先计算照明度,并且不将它们包含在任何运行时照明计算中。这意味着对于烘焙的Lights没有运行时开销。
Unity将直接或间接的光照从烘焙的Lights烘焙到光照贴图中(以照亮静态GameObjects)和Light Probes
(以阐明动态Light GameObjects)。即使在动态GameObjects上,Baked Lights也无法发出镜面照明。Unity
(有关更多信息,请参见Wikipedia:高光亮点)。烤光不会随着玩家的动作或场景中
发生的事件而改变。它们主要用于增加黑暗区域的亮度,而无需调整场景中的所有照明。
烘焙光还是动态游戏对象无法在其他动态游戏对象上投射阴影的唯一光源类型。
Advantages of baked lighting
-
High-quality shadows from statics GameObjects on statics GameObjects in the light map at no additional cost.
-
Offers indirect lighting.
-
All lighting for static GameObjects can be just one Texture fetched from the light map in the Shader
烤灯的优点
-
光照图中静态游戏对象上的静态游戏对象上的高质量阴影,而无需额外付费。
-
提供间接照明。
-
静态GameObjects的所有光照只能是从“ 着色器”中
的光照贴图获取的一个纹理。
Disadvantages of baked lighting
-
No real-time direct lighting (that is, no specular lighting effects).
-
No shadows from dynamic GameObjects on static GameObjects.
-
You only get low-resolution shadows from static GameObjects on dynamic GameObjects using Light Probes.
-
Increased memory requirements compared to real-time lighting for the light map texture set, because light maps need to be more detailed to contain direct lighting information.
烤灯的缺点
-
没有实时的直接照明(即没有镜面照明效果)。
-
静态GameObjects上的动态GameObjects没有阴影。
-
使用“光探针”只能从动态GameObjects上的静态GameObjects获得低分辨率阴影。
-
与光照贴图集的实时光照相比,内存需求增加了,因为光照贴图需要更详细地包含直接光照信息。
Technical details
For baked Lights, Unity precomputes the entire light path, except for the path segment from the Camera
to the Surface. See documentation on Light Modes
for more information about light paths.
对于烘焙的光源,Unity会预先计算整个光路,除了来自Camera
路段表面。请参阅有关灯光模式
文档。灯光信息有关光路的。
Baked Mode: All light paths are precomputed
烘焙模式:所有光路均已预先计算
Unity also precomputes direct baked lighting, which means that light direction information is not available to Unity at run time. Instead, a small number of Texture operations handle all light calculations for baked Lights in the Scene area. Without this information, Unity cannot carry out calculations for specular and glossy reflections. If you need specular reflections, use Reflection Probes
or use Mixed or Realtime lights. See documentation on directional light maps for more information.
Baked Lights never illuminate dynamic GameObjects at run time. The only way for dynamic GameObjects to receive light from baked Lights is via Light Probes. This is also the only difference between Baked Lights and any Subtractive mode Mixed Lights (except the main directional Light) which compute direct lighting on dynamic GameObjects at run time.
Unity还可以预先计算直接烘焙的照明,这意味着在运行时Unity无法使用光的方向信息。取而代之的是,少量的“纹理”操作处理“场景”区域中烘焙光的所有光计算。没有这些信息,Unity无法对镜面反射和光泽反射进行计算。如果需要镜面反射,请使用“ 反射探针
Reflection Probes)或使用混合或实时光。请参阅有关的文档定向光图以获取更多信息。
烤灯永远不会在运行时照亮动态GameObject。动态GameObjects从烘焙的Lights接收光的唯一方法是通过Light Probes。这也是Baked Lights和任何减法模式混合光(主定向光除外)之间唯一的区别,后者在运行时计算动态GameObjects上的直接照明。