Using Image-Based Lighting
使用基于图像的照明
Introduction
介绍
Qt Quick 3D supports IBL (Image-Based Lighting) to illuminate scenes or individual materials.
Qt Quick 3D支持IBL(基于图像的照明)来照明场景或单个材质。
IBL is a lighting technique that allows scenes to be illuminated with images. This is especially useful when you want to create realistic lighting and reflections in indoor and outdoor scenes.
IBL是一种允许使用图像照亮场景的照明技术。当希望在室内和室外场景中创建逼真的照明和反射时,这一点尤其有用。
You can use any image file for IBL, but it is recommended to use 360º HDR (High Dynamic Range) images. HDR images have a much higher dynamic range than for example JPEG or PNG images. A higher dynamic range provides more realistic lighting through a great range of luminance levels from very bright to very dark.
IBL可以使用任何图像文件,但建议使用360ºHDR(高动态范围)图像。HDR图像具有比例如JPEG或PNG图像高得多的动态范围。更高的动态范围通过从非常亮到非常暗的大范围的亮度级别提供更逼真的照明。
The following example demonstrates the lighting effect on an object using an HDR image vs a single directional light:
以下示例演示了使用HDR图像与单方向光对对象的照明效果:
| Light 灯光 | Smooth Dielectric material 光滑电介质材料 | Rough Dielectric material 粗糙电介质材料 | Smooth Metallic material 光滑金属材料 | Rough Metallic material 粗糙金属材料 |
|---|---|---|---|---|
| Single directional light 单向灯光 | ![]() | ![]() | ![]() | ![]() |
| Image-based light 基于图像的灯光 | ![]() | ![]() | ![]() | ![]() |
Scene Lighting
场景照明
To illuminate a scene using an image you'll add the image as a Texture to the lightProbe property.
若要使用图像照亮场景,您将把图像作为纹理添加到lightProbe属性中。
lightProbe: Texture {
source: "maps/OpenfootageNET_garage-1024.hdr"
}
Once you have selected an image, IBL is set up for your scene. All models in the scene are illuminated by the light probe by default.
选择图像后,将为场景设置IBL。默认情况下,场景中的所有模型都由灯光探测器照亮。
Note: You can also combine IBL with any other light source to compliment the lighting effect on an object.
注意:也可以将IBL与任何其他光源组合,以补充对象上的照明效果。
Now that you have IBL set up for your scene, let us have a look at the different properties for the probe. In many cases the default values provide a satisfying result, but you can tweak the following property values depending on the image and desired result:
现在已经为场景设置了IBL,让我们来看看探测器的不同属性。在许多情况下,默认值会提供令人满意的结果,但您可以根据图像和所需结果调整以下特性值:
- Exposure The amount of light emitted by the light probe.
- Exposure 光探测器发出的光量。
- Horizon Cut-Off Increasing the value adds darkness (black) to the bottom half of the environment, forcing the lighting to come predominantly from the top of the image (and removing specific reflections from the lower half).
- Horizon Cut Off增加该值会给环境的下半部分增加黑暗(黑色),迫使照明主要来自图像的顶部(并从下半部分移除特定反射)。
- Orientation This property when defines the orientation of the light probe. Orientation is defined in terms of euler angles in degrees over the x, y, and z axes.
- Orientation 此属性用于定义光探测器的方向。方向是根据x、y和z轴上以度为单位的欧拉角来定义的。
| Property 属性 | Metallic material 金属材质 | Dielectric material 介电材质 |
|---|---|---|
| Default settings 默认设置 | ![]() | ![]() |
| Exposure 曝光 | ![]() | ![]() |
| Horizon Cut-off | ![]() | ![]() |
| Orientation | ![]() | ![]() |
Material Lighting
材质照明
To use image-based lighting only on one material instead of a whole scene, or use a separate light probe for a model already illuminated by image-based lighting, set the image as the light probe for the material.
若要仅对一种材质而不是整个场景使用基于图像的光源,或者对已由基于图像的照明照亮的模型使用单独的光探测器,请将图像设置为材质的光探测器。
Once you have followed the steps above, you have a separate light probe set for the material. This light probe overrides the scene light probe if there is one specified.
完成上述步骤后,将为材质设置一个单独的光探测器。如果指定了场景灯光探测器,则此灯光探测器将覆盖场景灯光探测器。
Pre-generating IBL cubemap
预生成IBL立方体图
When IBL is used, a cubemap for the IBL image needs to be generated by the application. By default this happens during application startup and can be quite slow, especially on embedded and mobile devices. It is therefore possible to pre-generate this cubemap using Balsam. Simply run Balsam with the .hdr file as input and it will output a cubemap file with the same name as the input but with a ktx file extension. One can then reference this file in the lightProbe property's associated Texture, and Qt will then load the pregenerated cubemap without any costly processing at run time.
使用IBL时,应用程序需要生成IBL图像的立方体映射。默认情况下,这种情况发生在应用程序启动期间,速度可能相当慢,尤其是在嵌入式和移动设备上。因此,可以使用Balsam预先生成此立方体贴图。只需以.hdr文件作为输入运行Balsam,它就会输出一个与输入名称相同但扩展名为ktx的cubemap文件。然后可以在lightProbe属性的关联纹理中引用该文件,然后Qt将加载预生成的立方体映射,而无需在运行时进行任何昂贵的处理。
Manual baking
手动烘焙
As an example, let's assume the application uses a .hdr image for its light probes or the skybox:
举个例子,假设应用程序为其光探测器或skybox使用.hdr图像:
View3D {
environment: SceneEnvironment {
backgroundMode: SceneEnvironment.SkyBox
lightProbe: Texture {
source: "environment.hdr"
}
probeOrientation: Qt.vector3d(0, -90, 0)
}
// ...
}
This is fully functional, assuming environment.hdr is available at run time. However, loading the .hdr image involves expensive pre-processing. This can be avoided by running:
假设environment.hdr在运行时可用,这是完全功能性的。然而,加载.hdr图像需要进行昂贵的预处理。这可以通过运行以下程序来避免:
balsam environment.hdr
The result is a new file environment.ktx. Shipping this instead of the .hdr file and changing the Texture source provides significantly faster loading times.
结果是一个新的文件environment.ktx。运送这个文件而不是.hdr文件并更改纹理源可以显著加快加载速度。
lightProbe: Texture {
source: "environment.ktx"
}
Build time baking via CMake
通过CMake构建时间烘焙
Manually running balsam on assets is not always ideal. Therefore, applications are recommended to rely on CMake to automatically perform the same task at application build time.
在资产上手动运行balsam并不总是理想的。因此,建议应用程序在应用程序构建时依靠CMake自动执行相同的任务。
This is done by using the qt6_add_lightprobe_images CMake function provided by the Quick3D component of the Qt6 package:
这是通过使用qt6软件包的Quick3D组件提供的qt6_add_lightprobe_images CMake函数来完成的:
...
find_package(Qt6 COMPONENTS Quick3D)
...
qt6_add_lightprobe_images(application_target "ibl_assets"
PREFIX
"/ibl"
FILES
"environment.hdr"
)
Replace application_target with the appropriate target. Here, there is no need to run balsam manually on environment.hdr anymore, and the .hdr file does not need to be shipped with the application. Rather, during the build balsam will be invoked automatically, and an environment.ktx will be added to the application resources at :/ibl/environment.ktx. The lightProbe's Texture needs to then reference this file.
将application_target替换为相应的目标。在这里,不再需要在environment.hdr上手动运行balsam,也不需要随应用程序一起提供.hdr文件。相反,在构建过程中,balsam将被自动调用,environment.ktx将被添加到应用程序资源中:/ibl/enenvironment/ktx。然后,lightProbe的纹理需要引用此文件。
lightProbe: Texture {
source: "qrc:/ibl/environment.ktx"
}
Note: Setting PREFIX so that the final name in the resource system has a path matching the .qml file's location allows using a relative source path instead of having to provide an absolute path with the qrc scheme.
注意:设置PREFIX,使资源系统中的最终名称具有与.qml文件位置匹配的路径,这允许使用相对源路径,而不必使用qrc方案提供绝对路径。
In addition to PREFIX, the keyword BASE is also available. The behavior follows that of qt6_add_resources. For example, the following leads to generating :/ibl/maps/environment.ktx:
除了PREFIX,关键字BASE也可用。行为遵循qt6_add_resources的行为。例如,以下操作将导致生成:/ibl/maps/enenvironment.ktx:
qt6_add_lightprobe_images(application_target "ibl_assets"
PREFIX
"/ibl"
BASE
"../data/shared"
FILES
"../data/shared/maps/environment.hdr"
)
Like in qt6_add_shaders, the OUTPUTS keyword is available to allow specifying a completely custom name for the file in the resource system. For example, the following also generates :/ibl/maps/environment.ktx:
与qt6_add_shaders中一样,OUTPUTS关键字可用于在资源系统中为文件指定完全自定义的名称。例如,以下还会生成:/ibl/maps/enenvironment.ktx:
qt6_add_lightprobe_images(application_target "ibl_assets"
PREFIX
"/ibl"
FILES
"../data/shared/maps/environment.hdr"
OUTPUTS
"maps/environment.ktx"
)
Note: For each entry in the FILES list, there must be a corresponding entry in OUTPUTS.
注意:对于FILES列表中的每个条目,OUTPUTS中都必须有相应的条目。
© 2024 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.

















884

被折叠的 条评论
为什么被折叠?



