1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
2 | // Copyright (C) 2019 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QSSG_RENDER_SHADOW_MAP_H |
6 | #define QSSG_RENDER_SHADOW_MAP_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <QtQuick3DRuntimeRender/private/qtquick3druntimerenderglobal_p.h> |
20 | #include <QtGui/QMatrix4x4> |
21 | #include <QtGui/QVector3D> |
22 | #include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h> |
23 | #include <QtQuick3DRuntimeRender/private/qssgrenderableobjects_p.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class QSSGRhiContext; |
28 | class QSSGRenderContextInterface; |
29 | |
30 | class QRhiRenderBuffer; |
31 | class QRhiTextureRenderTarget; |
32 | class QRhiRenderPassDescriptor; |
33 | class QRhiTexture; |
34 | |
35 | enum class ShadowMapModes |
36 | { |
37 | VSM, ///< variance shadow mapping |
38 | CUBE, ///< cubemap omnidirectional shadows |
39 | }; |
40 | |
41 | struct QSSGShadowMapEntry |
42 | { |
43 | QSSGShadowMapEntry(); |
44 | |
45 | static QSSGShadowMapEntry withRhiDepthMap(quint32 lightIdx, ShadowMapModes mode, QRhiTexture *textureArray); |
46 | |
47 | static QSSGShadowMapEntry withRhiDepthCubeMap(quint32 lightIdx, ShadowMapModes mode, QRhiTexture *depthCube, QRhiRenderBuffer *depthStencil); |
48 | bool isCompatible(QSize mapSize, quint32 layerIndex, quint32 csmNumSplits, ShadowMapModes mapMode); |
49 | void destroyRhiResources(); |
50 | |
51 | quint32 m_lightIndex; ///< the light index it belongs to |
52 | ShadowMapModes m_shadowMapMode; ///< shadow map method |
53 | quint32 m_depthArrayIndex; ///< shadow map texture array index |
54 | |
55 | // RHI resources |
56 | QRhiTexture *m_rhiDepthTextureArray = nullptr; // for shadow map (VSM) (not owned) |
57 | QRhiTexture *m_rhiDepthCube = nullptr; // shadow cube map (CUBE) |
58 | std::array<QRhiRenderBuffer *, 4> m_rhiDepthStencil = {}; // depth/stencil |
59 | std::array<QRhiTextureRenderTarget *, 6> m_rhiRenderTargets = {}; // texture RT |
60 | std::array<QRhiRenderPassDescriptor *, 4> m_rhiRenderPassDesc = {}; // texture RT renderpass descriptor |
61 | |
62 | QMatrix4x4 m_lightViewProjection[4]; ///< light view projection matrix |
63 | QMatrix4x4 m_lightCubeView[6]; ///< light cubemap view matrices |
64 | QMatrix4x4 m_lightView; ///< light view transform |
65 | quint32 m_csmNumSplits = 0; |
66 | float m_csmSplits[4] = {}; |
67 | float m_csmActive[4] = {}; |
68 | float m_shadowMapFar = 0.f; |
69 | }; |
70 | |
71 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderShadowMap |
72 | { |
73 | Q_DISABLE_COPY(QSSGRenderShadowMap) |
74 | |
75 | public: |
76 | const QSSGRenderContextInterface &m_context; |
77 | |
78 | explicit QSSGRenderShadowMap(const QSSGRenderContextInterface &inContext); |
79 | ~QSSGRenderShadowMap(); |
80 | void releaseCachedResources(); |
81 | void addShadowMaps(const QSSGShaderLightList &renderableLights); |
82 | |
83 | QSSGShadowMapEntry *shadowMapEntry(int lightIdx); |
84 | |
85 | qsizetype shadowMapEntryCount() { return m_shadowMapList.size(); } |
86 | |
87 | private: |
88 | QSSGShadowMapEntry *addDirectionalShadowMap(qint32 lightIdx, QSize size, quint32 layerStartIndex, quint32 csmNumSplits, const QString &renderNodeObjName); |
89 | QSSGShadowMapEntry *addCubeShadowMap(qint32 lightIdx, QSize size, const QString &renderNodeObjName); |
90 | |
91 | QVector<QSSGShadowMapEntry> m_shadowMapList; |
92 | QHash<QSize, QRhiTexture *> m_depthTextureArrays; |
93 | }; |
94 | |
95 | using QSSGRenderShadowMapPtr = std::shared_ptr<QSSGRenderShadowMap>; |
96 | |
97 | QT_END_NAMESPACE |
98 | |
99 | #endif |
100 | |