Qt Quick 3D - Esempio di mappe d'ombra in cascata
Dimostra il funzionamento delle mappe ombra a cascata.

Questo esempio illustra come utilizzare un oggetto " DirectionalLight " con le mappe delle ombre a cascata.
Diamo un'occhiata al codice QML della scena:
View3D {
id: view
x: settings.viewX
y: 0
width: parent.width - settings.viewX
height: parent.height
camera: camera
environment: SceneEnvironment {
clearColor: "lightblue"
backgroundMode: SceneEnvironment.Color
antialiasingMode: SceneEnvironment.MSAA
antialiasingQuality: SceneEnvironment.High
}
PerspectiveCamera {
id: camera
position: Qt.vector3d(458, 300, 515)
eulerRotation: Qt.vector3d(-14, 19, 0)
clipFar: settings.clipFar
}
DirectionalLight {
visible: true
castsShadow: true
shadowFactor: settings.shadowFactor
eulerRotation: settings.eulerRotation
csmSplit1: settings.csmSplit1
csmSplit2: settings.csmSplit2
csmSplit3: settings.csmSplit3
csmNumSplits: settings.csmNumSplits
shadowMapQuality: settings.shadowMapQuality
csmBlendRatio: settings.csmBlendRatio
shadowBias: settings.shadowBias
pcfFactor: settings.pcfFactor
softShadowQuality: settings.softShadowQuality
shadowMapFar: settings.shadowMapFar
lockShadowmapTexels: settings.lockShadowmapTexels
}
Model {
id: ground
source: "#Cube"
scale: Qt.vector3d(25, 0.01, 135)
z: -5500
materials: PrincipledMaterial {
baseColor: "gray"
}
castsShadows: false
}
Node {
id: shapeSpawner
Component.onCompleted: {
var conesAndCylinderTrio = Qt.createComponent("ConesAndCylinderTrio.qml")
var z_pos = 0
for (var i = 0; i < 25; i++) {
conesAndCylinderTrio.incubateObject(shapeSpawner, {
"z_positions": [
z_pos,
z_pos - 125,
z_pos - 250
]})
z_pos -= 450
}
}
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton
propagateComposedEvents: true
onClicked: {
settings.drawerVisible = false
wasd.forceActiveFocus() // focus WASD controller for keyboard input
}
}
}La scena è composta da un " DirectionalLight", un " PerspectiveCamera", un "floor" Model e una lunga serie di coni e cilindri Model. Questa lunga serie è disposta in questo modo per mostrare come le cascate possano aiutare ad aumentare la fedeltà grafica della scena. Con una sola mappa delle ombre si verificherebbero degli artefatti, ma con le cascate questi possono essere corretti. L’ DirectionalLight contiene numerose proprietà modificabili tramite un pannello delle impostazioni nell’interfaccia utente.
Si invita il lettore a consultare l’articolo sul Shadow Mapping per ulteriori informazioni sulle diverse proprietà e a provare l’esempio per vedere come interagiscono.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.