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

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton
        propagateComposedEvents: true
        onClicked: {
            settings.drawerVisible = false
            wasd.forceActiveFocus() // focus WASD controller for keyboard input
        }
    }
}

このシーンは、DirectionalLight 、PerspectiveCamera 、床のModel 、そして円錐と円柱のModelからなる長い配列で構成されています。この長い配列は、カスケードがシーンのグラフィック品質を向上させるのにどのように役立つかを示すために、このように配置されています。シャドウマップが1つだけではアーティファクトが発生しますが、カスケードを使用することでこれを解消できます。DirectionalLight には、UIの設定パネルを通じて調整可能なプロパティが多数含まれています。

各プロパティの詳細については、「シャドウマッピング」の記事を参照し、サンプルを試してそれらの相互作用を確認することをお勧めします。

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

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