我是靠谱客的博主 心灵美棒棒糖,最近开发中收集的这篇文章主要介绍使用基于图像的照明Using Image-Based Lighting使用基于图像的照明,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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.
  • 曝光yac 由光探头发射的光量。
  • 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).
  • “地平线截止”增加该值会将黑暗(黑色)添加到环境的下半部分,迫使照明主要来自图像的顶部(并从下半部分移除特定反射)。
  • 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.
  • 方向当定义光探测器的方向时,此属性。方向定义为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:

例如,假设应用程序使用.hdr图像作为其光探测器或skybox:

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。在这里,不需要在环境上手动运行balsam。不再使用hdr,并且应用程序不需要附带.hdr文件。相反,在构建过程中,balsam将被自动调用,并且是一个应用程序资源文件,地址为:/ibl/environment.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/environment.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/environment.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.

注意:对于文件列表中的每个条目,OUTPUTS中必须有相应的条目。

© 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.

最后

以上就是心灵美棒棒糖为你收集整理的使用基于图像的照明Using Image-Based Lighting使用基于图像的照明的全部内容,希望文章能够帮你解决使用基于图像的照明Using Image-Based Lighting使用基于图像的照明所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部