QtQuick 3D附带三种材质类型:
DefaultMaterial 通过镜面反射,粗糙度和漫反射颜色属性控制外观(冯氏)
PrincipledMaterial 通过金属度,粗糙度,和基础颜色属性控制外观(PBR)
CustomMaterial 允许通过提供自己的顶点和片段着色器来创建真正的自定义材质
import QtQuick
import QtQuick.Window
import QtQuick3D
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
View3D{
anchors.fill: parent
environment: SceneEnvironment{
clearColor: "darkgreen"
backgroundMode: SceneEnvironment.SkyBox
lightProbe: Texture{
source:"maps/skybox.jpg"
}
}
Model{
source:"meshes/suzanne.mesh"
position:Qt.vector3d(5,4,0)
scale: Qt.vector3d(2,2,2)
eulerRotation:Qt.vector3d(-80,30,0)
materials:[
DefaultMaterial{
diffuseColor:"yellow" //漫反射
specularTint:"red" //镜面反射颜色
specularAmount:0.75
}
]
}
Model{
source:"#Sphere"
scale:Qt.vector3d(0.05,0.05,0.05)
position:Qt.vector3d(5,-4,0)
materials: [
DefaultMaterial{
diffuseColor: "blue"
specularTint: "red"
specularAmount: 0.75
}
]
}
Model{
source:"meshes/suzanne.mesh"
position:Qt.vector3d(-5,4,0)
scale: Qt.vector3d(2,2,2)
eulerRotation:Qt.vector3d(-80,30,0)
materials:[
PrincipledMaterial{
baseColor:"yellow" //漫反射
metalness: 0.9
roughness: 0.2
}
]
}
Model{
source:"#Sphere"
scale:Qt.vector3d(0.05,0.05,0.05)
position:Qt.vector3d(-5,-4,0)
materials: [
PrincipledMaterial{
baseColor: "blue"
metalness: 0.75
roughness: 0.5
}
]
}
PerspectiveCamera{
position:Qt.vector3d(0,0,15)
Component.onCompleted:lookAt(Qt.vector3d(0,0,0))
}
DirectionalLight{
eulerRotation.x:-20
eulerRotation.y:110
castsShadow: true
}
}
}
显示效果图