Qt6 QML Book/Qt Quick 3D/材料和灯光

Materials and Light

材料和灯光

Up until now, we've only worked with basic materials. To create a convincing 3D scene, proper materials and more advanced lighting is needed. Qt Quick 3D supports a number of techniques to achieve this, and in this section we will look at a few of them.

到目前为止,我们只研究了基本材料。为了创建令人信服的3D场景,需要适当的材料和更先进的照明。Qt Quick 3D支持多种技术来实现这一点,在本节中,我们将介绍其中的一些技术。

The Built-in Materials

内置材质

First up, we will look at the built in materials. Qt Quick 3D comes with three material types: DefaultMaterialPrincipledMaterial, and CustomMaterial. In this chapter we will touch on the two first, while the latter allows you to create truly custom material by providing your own vertex and fragment shaders.

首先,我们来看一下内置材料。Qt Quick 3D提供了三种材质类型:DefaultMaterial、PrincipledMaterial和CustomMaterial。在本章中,我们将首先讨论这两种材质,而后者允许您通过提供自己的顶点和片段着色器来创建真正的自定义材质。

The DefaultMaterial lets you control the appearance of the material through the specularroughness, and diffuseColor properties. The PrincipledMaterial lets you control the appearache through the metalnessroughness, and baseColor properties.

DefaultMaterial允许您通过镜面反射、粗糙度和漫反射颜色属性控制材质的外观。PrincipledMaterial允许您通过金属度、粗糙度和基色属性来控制外观。

Examples of the two material types can be seen below, with the PrincipledMaterial to the left, and the DefaultMaterial to the right.

下面可以看到两种材质类型的示例,PrincipledMaterial位于左侧,DefaultMaterial位于右侧。

Comparing the two Suzannes, we can see how the two materials are set up.

比较这两种,我们可以看到这两种材料是如何建立的。

For the DefaultMaterial, we use the diffuseColorspecularTint, and specularAmount properties. We will look at how variations of these properties affect the appearance of the objects later in this section.

对于DefaultMaterial,我们使用diffuseColor、specularTint和specularAmount属性。在本节后面,我们将研究这些属性的变化如何影响对象的外观。

Model {
    source: "meshes/suzanne.mesh"

    position: Qt.vector3d(5, 4, 0)
    scale: Qt.vector3d(2, 2, 2)
    rotation: Quaternion.fromEulerAngles(Qt.vector3d(-80, 30, 0))

    materials: [ DefaultMaterial {
            diffuseColor: "yellow";
            specularTint: "red";
            specularAmount: 0.7
        } ]
}

For the PrincipledMaterial, we tune the baseColormetalness, and roughnessproperties. Again, we will look at how variations of these properties affect the appearance later in this section.

对于PrincipledMaterial,我们调整基色、金属度和粗糙度属性。在本节后面,我们将再次研究这些特性的变化如何影响外观。

Model {
    source: "meshes/suzanne.mesh"

    position: Qt.vector3d(-5, 4, 0)
    scale: Qt.vector3d(2, 2, 2)
    rotation: Quaternion.fromEulerAngles(Qt.vector3d(-80, 30, 0))

    materials: [ PrincipledMaterial {
            baseColor: "yellow";
            metalness: 0.8
            roughness: 0.3
        } ]
}

Default Material Properties

默认材质属性

The figure below shows the default material with various values for the specularAmount and the specularRoughness properties.

 下图显示了默认材质,其镜面反射量specularAmount和镜面反射粗糙度specularRoughness属性具有各种值。

The specularAmount varies from 0.8 (left-most), through 0.5 (center), to 0.2 (right-most).

镜面值specularAmount从0.8(最左侧)、0.5(中心)到0.2(最右侧)不等。

The specularRoughness varies from 0.0 (top), through 0.4 (middle), to 0.8 (bottom).

镜面粗糙度specularRoughness从0.0(顶部)、0.4(中间)到0.8(底部)不等。

The code for the middle Model is shown below.

中间模型的代码如下所示。

Model {
    source: "meshes/suzanne.mesh"

    position: Qt.vector3d(0, 0, 0)
    scale: Qt.vector3d(2, 2, 2)
    rotation: Quaternion.fromEulerAngles(Qt.vector3d(-80, 30, 0))

    materials: [ DefaultMaterial {
            diffuseColor: "yellow";
            specularTint: "red";
            specularAmount: 0.5
            specularRoughness: 0.4
        } ]
}

Principled Material Properties

Principled材质属性

The figure below shows the principled material with various values for the metalness and roughness properties.

下图显示了具有不同金属度和粗糙度属性值的原理材料。

 The metalness varies from 0.8 (left-most), through 0.5 (center), to 0.2 (right-most).

金属度metalness从0.8(最左侧)、0.5(中心)到0.2(最右侧)不等。

The roughness varies from 0.9 (top), through 0.6 (middle), to 0.3 (bottom).

粗糙度roughness从0.9(顶部)、0.6(中间)到0.3(底部)不等。

Model {
    source: "meshes/suzanne.mesh"

    position: Qt.vector3d(0, 0, 0)
    scale: Qt.vector3d(2, 2, 2)
    rotation: Quaternion.fromEulerAngles(Qt.vector3d(-80, 30, 0))

    materials: [ PrincipledMaterial {
            baseColor: "yellow";
            metalness: 0.5
            roughness: 0.6
        } ]
}

Image-based Lighting

基于图像的光照

One final detail in the main example in this section is the skybox. For this example, we are using an image as skybox, instead of a single colour background.

本节主要示例中的最后一个细节是skybox。在本例中,我们使用图像作为skybox,而不是单色背景。

To provide a skybox, assign a Texture to the lightProbe property of the SceneEnvironment as shown in the code below. This means that the scene receives image-based light, i.e. that the skybox is used to light the scene. We also adjust the probeExposure which is used to control how much light is exposed through the probe, i.e. how brightly the scene will be lit. In this scene, we combine the light probe with a DirectionalLight for the final lighting.

要提供skybox,请将纹理Texture指定给SceneEnvironment的lightProbe属性,如下面的代码所示。这意味着场景接收基于图像的光,即skybox用于照亮场景。我们还调整probeExposure,它用于控制通过探头暴露的光线量,即场景的照明亮度。在这个场景中,我们将光探测器与方向光相结合,以获得最终照明。

environment: SceneEnvironment {
    clearColor: "#222222"
    backgroundMode: SceneEnvironment.SkyBox
    lightProbe: Texture {
        source: "maps/skybox.jpg"
    }
    probeExposure: 0.75
}

In addition to what we show, the orientation of the light probe can be adjusted using the probeOrientation vector, and the probeHorizon property can be used to darken the bottom half of the environment, simulating that the light comes from above, i.e. from the sky, rather than from all around.

除了我们所展示的之外,可以使用probeOrientation向量调整光探测器的方向,probeHorizon属性可以用于使环境的下半部分变暗,模拟光来自上方,即来自天空,而不是来自周围。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值