Lightmaps and Global Illumination
光照贴图和全局照明
Introduction
介绍
Baked lightmaps allow pre-generating the direct lighting from lights such as DirectionalLight, PointLight, and SpotLight, including the shadows cast by the lights. At run time, instead of performing the appropriate calculations in the fragment shader, and, in case of shadows, generating the potentially costly shadow maps in real time, the pre-generated image map is sampled instead.
烘焙光照贴图允许从平行光、点光源和聚光灯等灯光预生成直接照明,包括灯光投射的阴影。在运行时,不是在片段着色器中执行适当的计算,而是在阴影情况下实时生成可能代价高昂的阴影贴图,而是对预生成的图像贴图进行采样。
Note: As of Qt 6.4, lightmap baking is in an early technical preview state. Changes to features, quality, and API are likely to happen in future releases.
注:从Qt 6.4开始,光照贴图烘焙处于早期技术预览状态。在未来的版本中,可能会对功能、质量和API进行更改。
A lightmap is generated per Model. Even if a Model has multiple submeshes, and is therefore associated with multiple materials, there will be one single lightmap image generated for the entire model.
将为每个模型生成光照贴图。即使模型有多个子网格,因此与多个材质关联,也会为整个模型生成一个光照贴图图像。
Lightmaps are generated using raytracing, which by nature provides proper occlusion ("light does not travel through walls"), and possibly more realistic shadows than the real-time techniques for lighting and shadow mapping.
光照贴图是使用光线跟踪生成的,光线跟踪本质上提供了适当的遮挡(“光线不会穿过墙”),并且可能比实时照明和阴影贴图技术生成的阴影更逼真。
More importantly, lightmaps also allow baking indirect lighting, providing a solution for global illumination. This takes light rays reflected from other surfaces in the scene into account.
更重要的是,光照贴图还允许烘焙间接照明,为全局照明提供解决方案。这会将场景中其他曲面反射的光线考虑在内。
Below is a simple example. The scene contains four Rectangle and a Sphere model, with a DirectionLight pointing downwards and a PointLight. The rectangle models are rotated 0 and 90 degrees, which exaggerates the limitations of the real-time lighting calculations because they are all either parallel or perpendicular to the DirectionalLight's direction.
下面是一个简单的例子。场景包含四个矩形和一个球体模型,其中一个DirectionLight向下,一个PointLight。矩形模型旋转0度和90度,这夸大了实时照明计算的限制,因为它们都平行或垂直于平行光的方向。
On the right, the scene is rendered with lightmapping enabled, after having lightmaps baked for all five models. Both lights are set to fully baked, meaning both direct and indirect illumination is baked. Indirect lighting uses 256 samples and a maximum of 3 bounces. The resulting lightmaps were then denoised. This gives a significantly more realistic image.
在右侧,为所有五个模型烘焙光照贴图后,场景将在启用光照贴图的情况下渲染。两个灯光都设置为完全烘焙,这意味着直接照明和间接照明都已烘焙。间接照明使用256个采样,最多3次反弹。然后对生成的光照贴图进行去噪。这样可以得到更逼真的图像。
Real-time lighting
实时光源
Fully baked lighting
完全烘焙照明
Below is a snippet that shows how the lightmapped results were achieved. The difference lies in the usedInBakedLighting, bakeMode, and bakedLightmap properties. For this example, the lightmap size has been reduced using the lightmapBaseResolution property, to save disk space and reduce application load times.
下面是一个片段,显示了如何实现光照贴图结果。区别在于usedInBakedLighting、bakeMode和bakedLiightmap属性。对于此示例,已使用lightmapBaseResolution属性减小了光照贴图大小,以节省磁盘空间并减少应用程序加载时间。
DirectionalLight {
bakeMode: Light.BakeModeAll
eulerRotation.x: -90
brightness: 0.5
castsShadow: true
shadowFactor: 75
}
PointLight {
bakeMode: Light.BakeModeAll
y: 200
z: 100
color: "#d9c62b"
castsShadow: true
shadowFactor: 75
}
Model {
usedInBakedLighting: true
lightmapBaseResolution: 256
bakedLightmap: BakedLightmap {
enabled: true
key: "sphere1"
}
source: "#Sphere"
materials: PrincipledMaterial { }
y: 100
}
Model {
usedInBakedLighting: true
lightmapBaseResolution: 256
bakedLightmap: BakedLightmap {
enabled: true
key: "rect1"
}
source: "#Rectangle"
materials: PrincipledMaterial { }
eulerRotation.x: -90
scale: Qt.vector3d(10, 10, 10)
}
// ... three additional Rectangle models, with rotations 0, 90, and -90
The above example used fully baked lights. A light can also be configured to only use baked lighting for indirect illumination, while performing direct lighting and shadow mapping in real time. In the below scene there are 5 point lights, all of which are set to BakeModeIndirect for the right screenshot. While the direct lighting and shadows look identical, the right image looks significantly better due to a degree of global illumination added.
上面的示例使用了完全烘焙的灯光。还可以将灯光配置为仅使用烘焙照明进行间接照明,同时实时执行直接照明和阴影贴图。在下面的场景中,有5个点光源,在右侧屏幕截图中,所有这些点光源都设置为BakeModeIndirect。虽然直接照明和阴影看起来完全相同,但由于添加了一定程度的全局照明,右侧图像看起来更好。
Real-time lighting
实时光源
With baked indirect lighting added
添加烘焙间接照明
Important considerations when working with lightmaps
使用光照贴图时的重要注意事项
Lights contributing to baked lighting have their bakeMode property set to either BakeModeIndirect or BakeModeAll. The latter indicates that both the direct and indirect contribution for that particular light is coming from the lightmap. The direct contribution always includes shadows as well. On the other hand, if the intention with the lightmap is only to add indirect illumination to the scene for a particular light, while still having direct lighting calculated (and perform shadow mapping) in real time, then the light should use BakeModeIndirect instead.
有助于烘焙照明的灯光的bakeMode属性设置为BakeModeIndirect或bakeMode All。后者表示该特定灯光的直接和间接贡献都来自光照贴图。直接贡献总是包括阴影。另一方面,如果光照贴图的目的只是为特定灯光向场景添加间接照明,同时仍实时计算直接照明(并执行阴影贴图),则灯光应改用BakeModeIndirect。
Note: Lightmaps are, generally speaking, suitable for models that are static when it comes to transform, geometry, and materials. The same applies to the lights participating in the baked lighting.
注:通常来说,光照贴图适用于在变换、几何体和材质方面是静态的模型。这同样适用于参与烘焙照明的灯光。
For example, a scene that rotates a Model by animating the eulerRotation property will give visually incorrect results when applying a lightmap to that Model. The rendering results for that particular Model will be incorrect, as the pre-generated lightmap only captures one single rotation state for the object. The same would be true, taking another example, if the material for one of the model's submeshes dynamically changes its baseColor property based on time (animation) or some user interaction. The lightmap can only capture one given material baseColor. The same is true for lights. For example, a DirectionalLight that rotates, changes its brightness, color, etc. over time is not suitable for baked lighting.
例如,通过设置eulerRotation属性的动画来旋转模型的场景在将光照贴图应用于该模型时,将给出视觉上不正确的结果。该特定模型的渲染结果将不正确,因为预生成的光照贴图仅捕获对象的一个旋转状态。再举一个例子,如果模型的一个子网格的材质根据时间(动画)或某些用户交互动态更改其baseColor属性,情况也是如此。光照贴图只能捕获一个给定的材质baseColor。灯光也是如此。例如,随着时间的推移旋转、更改亮度、颜色等的平行光不适用于烘焙照明。
Note: On the other hand, it is always a designer choice when to use lightmapping. Especially with BakeModeIndirect lights, it is likely that there will be scenes where the results are still visually satisfying, even though some of the objects in the lightmapped scene employ dynamic behavior.
注意:另一方面,使用光照贴图总是设计师的选择。特别是使用BakeModeIndirect灯光时,即使光照贴图场景中的某些对象采用动态行为,也可能会有结果在视觉上仍然令人满意的场景。
Lightmapping is a complex engine and tooling feature. It replaces and reimplements several pieces of the engine's rendering pipeline. It works with a fundamentally different rendering model when baking lightmaps, while still consuming and interoperating with the same scene structure, asset data, and engine data structures. The raytracing-based results will often outclass the real-time alternatives, sometimes significantly, which comes at the expense of limitations, such as the mandatory static-ness of the models and lights involved, and, sometimes, quality and rendering artifact issues that are specific to lightmapping.
光照贴图是一个复杂的引擎和工具功能。它替换并重新实现了引擎的几个渲染管道。在烘焙光照贴图时,它使用一种根本不同的渲染模型,同时仍使用相同的场景结构、资源数据和引擎数据结构并与之交互。基于光线跟踪的结果通常会超过实时替代方案,有时会很明显,这是以限制为代价的,例如所涉及的模型和灯光的强制性静态性,有时还会出现特定于光照贴图的质量和渲染伪影问题。
In practice it will be an artistic choice by the designers what type of lighting to use, and when. All three bakeMode settings have their uses, and complex, larger scenes may very well utilize all three for different lights, depending on what is deemed suitable for a given section of the scene, and what sort of models, materials, and dynamic behavior are present. Lightmapping is not a simple on/off type of toggle switch that can be enabled for any scene and application, but a powerful feature that assumes careful evaluation of the lighting needs of a given scene, and often requires the scene contents and behavior to be designed accordingly, combined with a test-and-tune loop where different lightmap baking and quality settings are explored and tested before deciding on the final approach and the related settings.
在实践中,设计师可以选择使用什么类型的照明以及何时使用。所有三种bakeMode设置都有各自的用途,复杂、较大的场景可能会很好地将这三种设置用于不同的灯光,具体取决于场景的给定部分适合使用什么,以及存在什么类型的模型、材质和动态行为。光照贴图不是一种可以为任何场景和应用程序启用的简单开关类型的切换开关,而是一种功能强大的功能,它假定对给定场景的照明需求进行仔细评估,并且通常需要相应地设计场景内容和行为,与测试和调谐循环相结合,在决定最终方法和相关设置之前,将探索和测试不同的光照贴图烘焙和质量设置。
Note: Lightmaps do not support two-sided surfaces. With real time lighting a material with a cull mode of Material.NoCulling automatically inverts the normal as appropriate based on the facing of the fragment. This is not an option for lightmaps since lightmap baking does not operate in view space. Therefore, avoid baked lighting for models that would rely on this.
注意:光照贴图不支持双面曲面。使用“Material.NoCulling”的剔除模式实时照明材质,会根据碎片的面自动反转法线。这不是光照贴图的选项,因为光照贴图烘焙不会在视图空间中操作。因此,对于依赖于烘焙照明的模型,请避免使用烘焙照明。
Baking Lightmaps
烘焙光照贴图
Properties and types relevant for baking lightmaps, meaning the offline process of generating the image maps that capture direct and indirect lighting and can be used by the renderer in subsequent runs of the application:
与烘焙光照贴图相关的属性和类型,这意味着生成捕获直接和间接照明的图像贴图的离线过程,渲染器可以在应用程序的后续运行中使用这些图像贴图:
- Model::usedInBakedLighting
- Model::lightmapBaseResolution,
- Light::bakeMode,
- Lightmapper and SceneEnvironment::lightmapper
- BakedLightmap and Model::bakedLightmap
As of Qt 6.4, the lightmap baking process has to be triggered manually. Whenever the command line argument --bake-lightmaps
is present, or the environment variable QT_QUICK3D_BAKE_LIGHTMAPS
is set to 1
(or another non-zero value), the engine will work in baking mode and exit the application once baking has completed. The steps of the baking process can be followed by checking the messages printed on the debug output. The result is a set of .exr
files written to the current directory, where the filenames each have a qlm_
prefix, followed by the unique key from BakedLightmap::key.
从Qt 6.4开始,光照贴图烘焙过程必须手动触发。只要存在命令行参数--bake-lightmaps
,或环境变量QT_QUICK3D_BAKE_LIGHTMAPS
设置为1(或其他非零值),引擎就会在烘焙模式下工作,并在烘焙完成后退出应用程序。在烘焙过程的步骤之后,可以检查打印在调试输出上的消息。结果是一组.exr文件写入当前目录的,其中每个文件名都有一个qlm_前缀,后跟来自BakedLightmap::key的唯一键。
Preparing a lightmapped scene takes the following main steps:
准备光照贴图场景需要以下主要步骤:
- Identify which models should use a lightmap, and which models should contribute to the lightmap. Models that are part of the lightmapped scene should set Model::usedInBakedLighting to true. Models that are lightmapped (i.e., a lightmap is to be baked for them) should in addition set Model::bakedLightmap to an enabled BakedLightmap object, that provides a unique key that will persistently identify the particular Model object instance. (this is because Qt needs a key to identify the model data in persistent disk storage) Only models with static geometry, transformation, and materials are guaranteed to have correct results when lightmapped at run-time. Most commonly, anything that leads to a non-static world transform over time, such as a dynamically changed or animated position, rotation, or scale, will disqualify the model from participating. Artistic needs can override this, however, especially for models that only contribute to baked indirect lighting but are not themselves lightmapped. For these it may often be visually acceptable to have dynamic transforms, but this always depends on the model and the scene in question.
- 确定哪些模型应该使用光照贴图,哪些模型应该对光照贴图有所贡献。属于光照贴图场景的模型应将Model::usedInBakedLighting设置为true。光照贴图的模型(即要为其烘焙光照贴图)还应将Model::bakedLightmap设置为启用的BakedLight贴图对象,该对象提供一个唯一键,该键将永久标识特定的Model对象实例。(这是因为Qt需要一个密钥来识别持久磁盘存储中的模型数据)只有具有静态几何体、变换和材质的模型才能保证在运行时进行光照贴图时获得正确的结果。最常见的情况是,随着时间的推移,任何导致非静态世界变换的内容,例如动态更改或设置动画的位置、旋转或缩放,都将取消模型参与的资格。但是,艺术需求可以忽略这一点,特别是对于仅有助于烘焙间接照明但本身不是光照贴图的模型。对于这些场景,动态变换通常在视觉上是可以接受的,但这始终取决于所讨论的模型和场景。
- Identify which lights should contribute, and to which degree. Light::bakeMode offers three options:
- 确定哪些灯光应该起作用,以及作用的程度。Light::bakeMode提供三种选项:
- Light.BakeModeDisabled, the default, which effectively makes the light ignored for all lightmapping purposes.
- Light.BakeModeDisabled,默认设置,它有效地使灯光在所有光照贴图中被忽略。
- Light.BakeModeIndirect is often the "safe" choice, if the only goal is to have a level of global illumination (indirect lighting) in the scene, while not affecting the rendering results for the light in other ways. In this mode the renderer will continue to perform all lighting, including diffuse, specular, sky/environment contributions, and shadow mapping for this light using the standard real-time techniques. However, the light will contribute to indirect lighting using the pre-baked data, possibly leading to illuminating surfaces that are otherwise left untouched by the standard real-time lighting calculations.
- Light.BakeModeIndirect 如果唯一的目标是在场景中具有一定的全局照明级别(间接照明),同时不以其他方式影响灯光的渲染结果,则通常是“安全”的选择。在此模式下,渲染器将继续使用标准实时技术执行所有照明,包括漫反射、镜面反射、天空/环境贡献以及该灯光的阴影贴图。但是,灯光将有助于使用预烘焙数据进行间接照明,可能会导致照明曲面不受标准实时照明计算的影响。
- Light.BakeModeAll is an option which will likely be used for certain lights only, based on the designers' evaluation for what is deemed appropriate for a given scene. In this mode all contribution from the light is baked, including shadows. As of Qt 6.4 specular lighting are not supported as part of the baked lighting, so such lights will not have specular contributions. They will, on the other hand generate raytraced, baked shadows and have proper occlusion for the light (will not "pass through walls", for instance) since here all the direct lighting contributions resulting from the light are raytraced at lightmap baking time, instead of being calculated at run time. In addition, indirect lighting is baked, just as with BakeModeIndirect.
- Light.BakeModeAll 是一个选项,可能仅用于某些灯光,这取决于设计师对给定场景的合适评估。在此模式下,将烘焙灯光的所有贡献,包括阴影。从Qt 6.4开始,镜面反射照明不支持作为烘焙照明的一部分,因此此类灯光将不具有镜面反射贡献。另一方面,它们将生成光线跟踪的烘焙阴影,并对灯光具有适当的遮挡(例如,不会“穿过墙”),因为在这里,灯光产生的所有直接照明贡献都在光照贴图烘焙时进行光线跟踪,而不是在运行时计算。此外,间接照明是烘焙的,就像BakeModeIndirect一样。
- Running the scene (application) in baking mode, ensuring lightmaps are successfully generated. As of Qt 6.4, applications are expected to be structured in a way that the lightmapped scene is the first view shown, or that the scene in question can be loaded up with a QML viewer such as the
qml
tool. Once baking completes, the progress of which can be followed on the console/debug output, the application exits. - 在烘焙模式下运行场景(应用程序),确保成功生成光照贴图。从Qt 6.4开始,应用程序的结构应确保光照贴图场景是第一个显示的视图,或者可以使用QML查看器(如QML工具)加载相关场景。烘焙完成后,可以在控制台/调试输出上跟踪其进度,应用程序退出。
- Running the scene (application) normally, to see how it looks with the lightmaps loaded. The tuning can then begin:
- 正常运行场景(应用程序),以查看加载光照贴图后的效果。然后可以开始调谐:
- For some models it will make sense to reduce lightmapBaseResolution from the default 1024 to something smaller. This applies especially to the built-in primitives and anything with simple enough geometry. This leads to smaller lightmaps and faster bake times. When baking the first time, the default should be sufficient, the value can be tuned afterwards.
- 对于某些模型,将lightmapBaseResolution从默认的1024降低到更小的值是有意义的。这尤其适用于内置基本体和任何具有足够简单几何体的对象。这将导致更小的光照贴图和更快的烘焙时间。第一次烘焙时,默认值应该足够了,之后可以调整该值。
- The Lightmapper object exposes numerous settings that have reasonable defaults, but it is not unlikely that some of these will need to be tuned to match the designers' expectation. For example, samples and bounces can be changed to affect the quality of indirect lighting, while indirectLightFactor allows making the indirect contribution more prominent. If artifacts, in particular around shadows, occur, bias can be fine-tuned.
- Lightmapper对象公开了许多具有合理默认值的设置,但其中一些设置不太可能需要调整以符合设计者的期望。例如,可以更改采样和反弹以影响间接照明的质量,而indirectLightFactor允许使间接贡献更加突出。如果出现伪影,尤其是阴影周围的伪影,则可以对偏移进行微调。
- Denoising the generate lightmaps is essential. Indirect lighting is calculated using path tracing, which produces noisy images depending on the number of the samples used. Increasing the sample count reduces noise, but increases the time needed to generate the lightmap. Regardless of the sample count, it will almost always make sense to run a denoiser on the generated lightmaps, which are 32-bit RGBA floating point images stored in as .exr files.
- 对生成的光照贴图进行去噪至关重要。间接照明使用路径跟踪进行计算,路径跟踪根据使用的采样数生成噪波图像。增加采样数会减少噪波,但会增加生成光照贴图所需的时间。无论样本数量如何,对生成的光照贴图(以.exr文件形式存储的32位RGBA浮点图像)运行去噪器几乎总是有意义的。
Denoising
去噪
Below is an example of a Cornell box scene, rendered first using the lightmap baked with 256 samples and a maximum of 3 bounces. In the second example, the generated image file has been run through a denoiser using the Open Image Denoise library. The results look significantly better, with the noise mostly gone.
下面是康奈尔长方体场景的示例,首先使用256个采样烘焙的光照贴图进行渲染,最多反弹3次。在第二个示例中,生成的图像文件已使用Open image Denoise库通过去噪器运行。结果看起来好多了,噪音基本消失了。
Original
原图
Denoised
去噪后
A simple, Qt-based command-line wrapper for OIDN that works with the Qt Quick 3D-generated qlm_*.exr
images is available at Laszlo Agocs / qlmdenoiser · GitLab. It currently needs to be built from source and no pre-built binaries are available.
一个简单的、基于Qt的OIDN命令行包装器,与Qt Quick 3D一起使用,生成的qlm_*.exr
图像可在Laszlo Agocs/qlmdenoiser·GitLab获得。它目前需要从源代码构建,没有预构建的二进制文件可用。
Lightmap UVs
光照贴图UV
Lightmap UV coordinates do not use the same UV data as regular texturing. When rendering with lightmaps, neither the UV0 nor UV1 data is used by the renderer when sampling the lightmap. Instead, there is an additional, dedicated UV channel in the mesh, containing UV charts laid out in a manner that is suitable for the purposes of lightmapping. This involves avoiding overlaps and having padding where appropriate. For regular UV data there are no such requirements, and one may very well want to use the same U and V coordinates for more than one vertex.
光照贴图UV坐标不使用与常规纹理相同的UV数据。使用光照贴图渲染时,渲染器在采样光照贴图时既不使用UV0数据,也不使用UV1数据。相反,网格中有一个额外的专用UV通道,其中包含以适合光照贴图目的的方式布置的UV图表。这包括避免重叠和适当的填充。对于常规UV数据,没有这样的要求,人们可能非常希望对多个顶点使用相同的U和V坐标。
The process of generating a suitable UV set is called lightmap UV unwrapping. Qt is always able to perform this at run (load) time, both when baking lightmaps and also when rendering a scene normally.
生成合适UV集的过程称为光照贴图UV展开。Qt始终能够在运行(加载)时执行此操作,无论是在烘焙光照贴图时还是在正常渲染场景时。
In order to improve mesh load times by avoiding generating lightmap UV data for lightmapped models at run time, there are two options:
为了避免在运行时为光照贴图模型生成光照贴图UV数据,从而缩短网格加载时间,有两个选项:
- For models without lightmap UV data available the lightmap baking process also outputs a set of
qlm_*.mesh
files, the names generated based on the BakedLightmap::key, similarly to the with the.exr
images. If the application wishes to, it can ship these extra.mesh
files together with the.exr
assets. When present, these mesh files will be used in place of the regular model data, with the lightmapping related data readily available. This is completely optional, however. When no qlm_key
.mesh is found at run time, the UV unwrapping is done at run time, transparently to the application. - 对于没有可用光照贴图UV数据的模型,光照贴图烘焙过程还输出一组
qlm_*.mesh
文件,根据BakedLightmap::key生成的名称,类似于带有.exr图像的。如果应用程序愿意,它可以发送这些额外的.mesh
文件和.exr资源。如果存在,这些网格文件将取代常规模型数据,并且光照贴图相关数据随时可用。然而,这是完全可选的。当没有qlm_key
.mesh在运行时找到,UV展开在运行时完成,对应用程序透明。 - Alternatively, the balsam tool offers the option to pre-generate the lightmap UV data at asset import time. This means that the model's
.mesh
file will contain the necessary data right from the start, and no extra meshes will be generated during lightmap baking time, and so there are no extra assets to ship with the application (apart from the lightmap images, of course). To do this, pass--generateLightmapUV
to balsam. - 或者,balsam工具提供了在资源导入时预生成光照贴图UV数据的选项。这意味着模型的
.mesh
文件将从一开始就包含必要的数据,并且在光照贴图烘焙期间不会生成额外的网格,因此应用程序不会附带额外的资源(当然,除了光照贴图图像)。为此,请将--generateLightmapUV传递给balsam。
Lightmap texture size
光照贴图纹理大小
For each model, including all its submeshes, the lightmap baking process will determine a suitable lightmap texture size during the lightmap UV generation phase. This has an impact on quality, performance, and resource usage (both on disk and in memory).
对于每个模型,包括其所有子网格,光照贴图烘焙过程将在光照贴图UV生成阶段确定合适的光照贴图纹理大小。这会影响质量、性能和资源使用(磁盘和内存)。
The default is often suitable and needs no adjustment, especially for models with medium to high complexity.
默认值通常是合适的,不需要调整,特别是对于具有中到高复杂性的模型。
For very simple models it may be desirable to manually reduce the size, however, because a smaller lightmap size could still provide visually good looking results, while reducing the asset (lightmap image) sizes saves both disk space and memory. To do this, set the lightmapBaseResolution to a suitably small number. Common choices are 256, 512, or 1024, but it could be another number as well, with 128 as the minimum. The actual lightmap width and height will likely be different, but in approximately the same ballpark as the specified size.
但是,对于非常简单的模型,可能需要手动减小大小,因为较小的光照贴图大小仍然可以提供外观良好的结果,而减小资源(光照贴图图像)大小可以节省磁盘空间和内存。为此,请将lightmapBaseResolution设置为一个适当小的数字。常见的选择是256、512或1024,但也可以是另一个数字,最小值为128。实际光照贴图的宽度和高度可能不同,但大致与指定的大小相同。
When changing the value, one should always rebake the lightmaps and visually inspect the results in order to evaluate the effects of the changed lightmap size.
更改该值时,应始终重新设置光照贴图的值,并目视检查结果,以评估更改的光照贴图大小的效果。
Using Lightmaps at Run-Time
在运行时使用光照贴图
Properties and types relevant when using the pre-baked lightmaps at run time:
在运行时使用预烘焙光照贴图时相关的属性和类型:
Once the baking has successfully completed, running the application normally (without the command-line argument or environment variable set) will now pick up the generated lightmap images and render correctly, which is not possible until the lightmaps have been baked first. If desired, the application can place those in a different location, or ship them as part of the executable via the Qt Resource System. This is enabled by the BakedLightmap::loadPrefix property.
烘焙成功完成后,正常运行应用程序(不设置命令行参数或环境变量)将拾取生成的光照贴图图像并正确渲染,这在首先烘焙光照贴图之前是不可能的。如果需要,应用程序可以将它们放在不同的位置,或者通过Qt资源系统将它们作为可执行文件的一部分发布。这由BakedLightmap::loadPrefix属性启用。
Taking the example code with the sphere and four rectangles from above, the baking process generates five .exr
files (qlm_sphere1.exr
, qlm_rect1.exr
, qml_rect2.exr
, etc.), and a list file qlm_list.txt
which is useful as input for denoising utilities that support processing multiple files in one go but is not used at runtime otherwise. The application needs to ship the .exr
files, so that they can be found by the engine, either in the current working directory, or in the location specified by the loadPrefix.
以上面的球体和四个矩形的示例代码为例,烘焙过程生成五个.exr文件(qlm_sphere1.exr、qlm_rect1.exr、qml_rect2.exr等)和列表文件qlm_list.txt对于支持一次性处理多个文件的去噪实用程序非常有用,但在运行时不使用它。应用程序需要发送.exr文件,以便引擎可以在当前工作目录或loadPrefix指定的位置找到它们。
The loading rules also apply to the optional .mesh
files, such as qlm_sphere1.mesh
or qlm_rect1.mesh
. If the application wishes to accelerate the scene load times, it should ship these extra .mesh
files next to the .exr
lightmap images.
加载规则也适用于可选的.mesh文件,例如qlm_sphere1.mesh或qlm_rect1.mesh。如果应用程序希望加快场景加载时间,则应把这些额外.mesh
文件传递给.exr光照贴图图像。
See also Qt Quick 3D - Baked Lightmap Example.
另请参见Qt Quick 3D-烘焙光照贴图示例。
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.