烘焙光照贴图

简介

Baked lightmaps are an alternative workflow for adding indirect (or baked) lighting to a scene. Unlike the GI探针 approach, baked lightmaps work fine on low-end PCs and mobile devices, as they consume almost no resources at run-time.

Unlike GIProbes, Baked Lightmaps are completely static. Once baked, they can’t be modified at all. They also don’t provide the scene with reflections, so using 反射探针 together with it on interiors (or using a Sky on exteriors) is a requirement to get good quality.

As they are baked, they have fewer problems than GIProbe regarding light bleeding, and indirect light can look better if using Raytrace mode on high quality setting (but baking can take a while).

In the end, deciding which indirect lighting approach is better depends on your use case. In general, GIProbe looks better and is much easier to set up. For mobile or low-end compatibility, though, Baked Lightmaps are your only choice.

视觉比较

Here are some comparisons of how Baked Lightmaps vs. GIProbe look. Notice that lightmaps are more accurate, but also suffer from the fact that lighting is on an unwrapped texture, so transitions and resolution may not be that good. GIProbe looks less accurate (as it’s an approximation), but smoother overall.

../../_images/baked_light_comparison.png

设置

首先,在光照贴图可以执行任何操作之前,要烘焙的对象需要UV2图层和纹理大小。 UV2图层是一组辅助纹理坐标,可确保对象中的任何面在UV贴图中都有自己的位置。 面不得共享纹理中的像素。

There are a few ways to ensure your object has a unique UV2 layer and texture size:

从3D DCC展开

一种选择是从您最喜欢的3D应用程序中进行。 通常不推荐这种方法,但首先要解释它,以便您知道它存在。 主要的优点是,在您可能想要重新导入很多的复杂对象上,纹理生成过程在Godot中可能非常昂贵,因此在导入之前将其解包可以更快。

只需在第二个UV2层上打开包装即可。

../../_images/baked_light_blender.png

并正常导入。 请记住,导入后需要在网格上设置纹理大小。

../../_images/baked_light_lmsize.png

If you use external meshes on import, the size will be kept. Be wary that most unwrappers in 3D DCCs are not quality oriented, as they are meant to work quickly. You will mostly need to use seams or other techniques to create better unwrapping.

从Godot内部解开

Godot可以选择打开网格并可视化UV通道。 它可以在Mesh菜单中找到:

../../_images/baked_light_mesh_menu.png

这将生成第二组UV2坐标,可用于烘焙,并且还将自动设置纹理大小。

解开场景导入

This is probably the best approach overall. The only downside is that, on large models, unwrapping can take a while on import. Just select the imported scene in the filesystem dock, then go to the Import tab. There, the following option can be modified:

../../_images/baked_light_import.png

** Light Baking 模式需要设置为**``Gen Lightmaps``。 还必须提供世界单位的纹素大小,因为这将确定光照贴图纹理的最终大小(并因此确定地图中的UV填充)。

设置此选项的效果是场景中的所有网格都将正确生成其UV2贴图。

作为警告:当重用场景中的网格时,请记住将为找到的第一个实例生成UV。 如果网格重复使用不同的比例(并且比例大不相同,超过一半或两次),这将导致低效的光照贴图。 如果您计划使用光照贴图,请不要在不同比例下重复使用源网格。

检查UV2

在前面提到的网格菜单中,可以显示UV2纹理坐标。 如果出现问题,请确保检查网格是否具有以下UV2坐标:

../../_images/baked_light_uvchannel.png

设置场景

Before anything is done, a BakedLightmap Node needs to be added to a scene. This will enable light baking on all nodes (and sub-nodes) in that scene, even on instanced scenes.

../../_images/baked_light_scene.png

子场景可以多次实例化,因为这是由面包师支持的,并且每个子场景都将被分配一个自己的光照贴图(只需确保遵守前面提到的缩放规则):

配置边界

Lightmap needs an approximate volume of the area affected because it uses it to transfer light to dynamic objects inside it (more on that later). Just cover the scene with the volume as you do with GIProbe:

../../_images/baked_light_bounds.png

设置网格

要使** MeshInstance **节点参与烘焙过程,需要启用``在烘焙灯中使用``属性。

../../_images/baked_light_use.png

在场景导入时自动生成光照贴图时,会自动启用此功能。

设置灯

默认情况下,灯光采用间接灯光烘焙。 这意味着阴影贴图和光照仍然是动态的并影响移动的物体,但是光线反射的光将被烘焙。

灯可以禁用(不烘焙)或完全烘焙(直接和间接)。 这可以通过灯光中的 烘焙模式 菜单进行控制:

../../_images/baked_light_bake_mode.png

模式是:

  • 禁用: 烘焙时忽略灯光。 请记住隐藏灯光对烘焙没有影响,因此必须使用此灯泡。
  • 间接: 这是默认模式。 只会间接照明。
  • 全部: 间接和直接照明都将被烘焙。 如果您不希望灯光出现两次(动态和静态),只需将其隐藏即可。

烘焙质量

BakedLightmap uses, for simplicity, a voxelized version of the scene to compute lighting. Voxel size can be adjusted with the Bake Subdiv parameter. More subdivision results in more detail, but also takes more time to bake.

In general, the defaults are good enough. There is also a Capture Subdivision (that must always be equal to or less than the main subdivision), which is used for capturing light in dynamic objects (more on that later). Its default value is also good enough for most cases.

../../_images/baked_light_capture.png

除捕获大小外,还可以通过设置 烘焙模式 来修改质量。 提供了两种间接捕获模式:

../../_images/baked_light_mode.png
  • Voxel Cone: Trace: Is the default one; it’s less precise, but faster. Looks similar to (but slightly better than) GIProbe.
  • Ray Tracing: This method is more precise, but can take considerably longer to bake. If used in low or medium quality, some scenes may produce grain.

烘焙

To begin the bake process, just push the big Bake Lightmaps button on top when selecting the BakedLightmap node:

../../_images/baked_light_bake.png

这可能需要几秒到几分钟(或几小时),具体取决于场景大小,烘焙方法和所选质量。

配置烘焙

烘焙还有几种选择:

  • Bake Subdiv: The Godot lightmapper uses a grid to transfer light information around; the default value is fine and should work for most cases. Increase it in case you want better lighting on small details or your scene is large.
  • ** Capture Subdiv**: 这是用于实时捕获信息的网格(照明动态对象)。 默认值通常是OK,它通常小于Bake Subdiv并且不能大于它。
  • 烘焙质量:提供三种烘焙质量模式,低,中和高。 更高的质量需要更多的时间。
  • Bake Mode: The baker can use two different techniques: Voxel Cone Tracing (fast, but approximate), or RayTracing (slow, but accurate).
  • Propagation: Used for the Voxel Cone Trace mode. Works just like in GIProbe.
  • HDR: If disabled, lightmaps are smaller, but can’t capture any light over white (1.0).
  • 图像路径:将保存光照贴图的位置。 默认情况下,在与场景相同的目录()上,但可以进行调整。
  • 范围:受影响区域的大小(可以直观地编辑)
  • Light Data: Contains the light baked data after baking. Textures are saved to disk, but this also contains the capture data for dynamic objects, which can be a bit heavy. If you are using .tscn formats (instead of .scn), you can save it to disk.

动态对象

在其他引擎或lightmapper实现中,您需要手动在该级别周围放置称为``lightprobes``的小对象以生成* capture *数据。 然后,这用于将光传输到在场景中移动的动态对象。

但是,这种光照贴图的实现使用了不同的方法。 这个过程是自动的,所以您不必做任何事情。 只需移动物体,它们就会相应点亮。 当然,您必须确保相应地设置场景边界,否则它将无法工作。

../../_images/baked_light_indirect.gif