Qt Quick 3D - カスケードシャドウマップの例

カスケードシャドウマップのデモ

この例では、DirectionalLight 、カスケードシャドウマップを使用する方法を示します。

シーンのQMLコードを見てみましょう:

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

このシーンは、DirectionalLightPerspectiveCamera 、床Model 、円錐と円柱の長い配列Modelsで構成されています。この長い配列は、カスケードがシーンのグラフィカルな忠実度を高めるのに役立つことを示すために、このようにレイアウトされています。シャドウマップが1つだけだとアーティファクトが発生しますが、カスケードがあればこれらを改善できます。DirectionalLight には多くのプロパティがあり、UI の設定ペインで調整できます。

読者は、シャドウマッピングの記事を参照して、さまざまなプロパティの詳細と、それらがどのように相互作用するかを確認するためにサンプルを試してみてください。

サンプルプロジェクト @ code.qt.io

© 2025 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.