Qt Quick 3D - 自定义材质范例

演示某些材质库材质的用法。

This example demonstrates using four different Material Library custom materials in an application.

设置场景环境

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

environment: SceneEnvironment {
    clearColor: "#848895"
    backgroundMode: SceneEnvironment.Color
    probeBrightness: 1000
    lightProbe: Texture {
        source: "maps/OpenfootageNET_garage-1024.hdr"
    }
    antialiasingMode: SceneEnvironment.SSAA
    antialiasingQuality: SceneEnvironment.VeryHigh
}
					

材质库自定义材质

凹凸铝

We're applying AluminumMaterial WeirdShape model we have created in WeirdShape.qml . We'll adjust its bumpiness to make it look battered or cast, instead of smooth and polished.

WeirdShape {
    customMaterial: AluminumMaterial {
        bump_amount: 5.0
    }
    position: Qt.vector3d(150, 150, -100)
}
					

Next we apply unmodified CopperMaterial for another WeirdShape .

WeirdShape {
    customMaterial: CopperMaterial {}
    position: Qt.vector3d(-150, -150, -100)
}
					
磨砂玻璃

We'll apply FrostedGlassSinglePassMaterial for one of the spheres, and adjust its roughness, reflectivity, index of refraction, and color a little bit.

Model {
    position: Qt.vector3d(-300, 0, 100)
    scale: Qt.vector3d(2.5, 2.5, 2.5)
    source: "#Sphere"
    materials: [ FrostedGlassSinglePassMaterial {
            roughness: 0.1
            reflectivity_amount: 0.9
            glass_ior: 1.9
            glass_color: Qt.vector3d(0.85, 0.85, 0.9)
        }
    ]
}
					
塑料

For the other sphere we'll apply PlasticStructuredRedMaterial , and adjust its index of refraction and bumpiness a bit.

Model {
    position: Qt.vector3d(300, 0, 100)
    scale: Qt.vector3d(2.5, 2.5, 2.5)
    source: "#Sphere"
    materials: [ PlasticStructuredRedMaterial {
            material_ior: 1.55
            bump_factor: 0.1
        }
    ]
}
					

文件: