Qt Quick 3D - Principled Material Example | Qt Quick 3D 6.2.2

- Qt 6.2
- Qt Quick 3D
- Qt Quick 3D Examples and Tutorials
- Qt Quick 3D - Principled Material Example
- Qt Quick 3D | Commercial or GPLv3

# Qt Quick 3D - Principled Material Example

Demonstrates the use of Principled Material.

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

#### Setting Up the Scene

##### 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)
     }

##### Rotating Light

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

##### Basic

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
             }
         ]
     }

##### Textured

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

Note: When using textures for metalness, roughness, bumpiness, and 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
             }
         ]

#### Controlling the Property Values

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

Note: If `Metalness` has a non-zero value, adjusting `Specular Power` or `Specular Tint` has no effect.

Files:

- principledmaterial/CMakeLists.txt
- principledmaterial/Example/MaterialControl.qml
- principledmaterial/Example/main.qml
- principledmaterial/Example/qmldir
- principledmaterial/MaterialControl.qml
- principledmaterial/main.cpp
- principledmaterial/main.qml
- principledmaterial/materials.qrc
- principledmaterial/principledmaterial.pro
- principledmaterial/qml.qrc

Images:

- principledmaterial/Example/maps/metallic/basecolor.jpg
- principledmaterial/Example/maps/metallic/metallic.jpg
- principledmaterial/Example/maps/metallic/normal.jpg
- principledmaterial/Example/maps/metallic/roughness.jpg
- principledmaterial/maps/metallic/basecolor.jpg
- principledmaterial/maps/metallic/metallic.jpg
- principledmaterial/maps/metallic/normal.jpg
- principledmaterial/maps/metallic/roughness.jpg