Qt Quick 3D - Principled 材质范例

演示 Principled 材质的用法。

This example demonstrates two different ways to use PrincipledMaterial in an application.

设置场景

Light Probe

We specify a light probe , since we are using reflective metallic materials in the scene. We need to enable the light probe and adjust its settings to get the result we want.

environment: SceneEnvironment {
    clearColor: window.color
    backgroundMode: SceneEnvironment.SkyBox
    lightProbe: Texture {
        source: "maps/OpenfootageNET_garage-1024.hdr"
    }
    probeOrientation: Qt.vector3d(0, -90, 0)
}
					
旋转光

Then we add DirectionalLight and add a rotation for it, to better demonstrate the effect that the metalness and roughness properties have on the materials.

// Rotate the light direction
DirectionalLight {
    eulerRotation.y: -100
    brightness: 1
    SequentialAnimation on eulerRotation.y {
        loops: Animation.Infinite
        PropertyAnimation {
            duration: 5000
            to: 360
            from: 0
        }
    }
}
					

Principled Materials

基本

We apply a basic principled material onto the sphere on the left. By this we mean a material that only uses the basic, numeric properties without any texture properties.

Model {
    position: Qt.vector3d(-250, -30, 0)
    scale: Qt.vector3d(4, 4, 4)
    source: "#Sphere"
    materials: [ PrincipledMaterial {
            baseColor: "#41cd52"
            metalness: materialCtrl.metalness
            roughness: materialCtrl.roughness
            specularAmount: materialCtrl.specular
            specularTint: materialCtrl.specularTint
            opacity: materialCtrl.opacityValue
        }
    ]
}
					
纹理

We apply a textured principled material onto the sphere on the right.

注意: When using textures for metalness , roughness , bumpiness ,和 color , the basic property values are applied as multipliers for the values from the textures.

Model {
    position: Qt.vector3d(250, -30, 0)
    scale: Qt.vector3d(4, 4, 4)
    source: "#Sphere"
    materials: [ PrincipledMaterial {
            metalness: materialCtrl.metalness
            roughness: materialCtrl.roughness
            specularAmount: materialCtrl.specular
            opacity: materialCtrl.opacityValue
            baseColorMap: Texture { source: "maps/metallic/basecolor.jpg" }
            metalnessMap: Texture { source: "maps/metallic/metallic.jpg" }
            roughnessMap: Texture { source: "maps/metallic/roughness.jpg" }
            normalMap: Texture { source: "maps/metallic/normal.jpg" }
            metalnessChannel: Material.R
            roughnessChannel: Material.R
        }
    ]
					

控制特性值

There are sliders for adjusting the values of the different basic properties.

注意: 金属性 has a non-zero value, adjusting Specular Power or Specular Tint 不起作用。

文件:

图像: