Qt Quick 3D - Principled 材质范例

演示 Principled 材质的用法。

This example demonstrates how to use the principled material in two different ways in an application.

设置场景

Light Probe

We want to use a light probe , as we're going to use reflective metallic materials. We need to enable light probe and adjust its settings to get the result we want.

environment: SceneEnvironment {
    probeBrightness: 100
    clearColor: "#848895"
    backgroundMode: SceneEnvironment.Color
    lightProbe: Texture {
        source: "maps/OpenfootageNET_garage-1024.hdr"
    }
}
					
					
旋转光

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

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

Principled Materials

基本

We will apply a basic principled material on to the sphere on the left. By basic we mean just using the non-texture properties of the material.

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
            indexOfRefraction: materialCtrl.ior
            specularTint: materialCtrl.specularTint
            opacity: materialCtrl.opacityValue
        }
    ]
}
					
					
纹理

We will apply a textured principled material on to the sphere on the right. When using textures for metalness , roughness , bumpiness ,和 color the basic property values are applied as multipliers for the values gotten 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
            indexOfRefraction: materialCtrl.ior
            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 some sliders for adjusting the values of the different basic properties.

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

文件:

图像: