Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qssgrendershadowmap_p.h
Go to the documentation of this file.
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
25QT_BEGIN_NAMESPACE
26
27class QSSGRhiContext;
29
30class QRhiRenderBuffer;
31class QRhiTextureRenderTarget;
32class QRhiRenderPassDescriptor;
33class QRhiTexture;
34
36{
38
39 static QSSGShadowMapEntry withAtlas(quint32 lightIdx);
40
42
43 quint32 m_lightIndex; ///< the light index it belongs to
44 quint32 m_depthArrayIndex = 0; ///< shadow map texture array index
45
46 // Owned RHI Resoruces (just for point lights)
47 QRhiTexture *m_rhiDepthCube = nullptr; // shadow cube map
48 QRhiRenderBuffer *m_rhiDepthStencilCube = nullptr;
49 QRhiRenderPassDescriptor *m_rhiRenderPassDescCube = nullptr;
53
54 // Shared RHI Resources
57
58 QMatrix4x4 m_lightViewProjection[4]; ///< light view projection matrix
59 QMatrix4x4 m_lightCubeView[6]; ///< light cubemap view matrices
60 QMatrix4x4 m_lightView; ///< light view transform
62 float m_csmSplits[4] = {};
63 float m_csmActive[4] = {};
64 float m_shadowMapFar = 0.f;
66 QVector4D m_dimensionsInverted[4]; ///< (x, y, z, 0) 4 vec4
67
68 struct AtlasEntry {
69 int layerIndex = 0;
70 float uOffset = 0.0f;
71 float vOffset = 0.0f;
72 float uvScale = 1.0f;
73 } m_atlasInfo[4];
74};
75
76class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderShadowMap
77{
78 Q_DISABLE_COPY(QSSGRenderShadowMap)
79
80public:
81 const QSSGRenderContextInterface &m_context;
82
83 explicit QSSGRenderShadowMap(const QSSGRenderContextInterface &inContext);
84 ~QSSGRenderShadowMap();
85 void releaseCachedResources();
86 void addShadowMaps(const QSSGShaderLightList &renderableLights);
87
89 QRhiTextureRenderTarget *layerRenderTarget(int layerIndex);
90 QRhiRenderPassDescriptor *layerRenderPassDescriptor(int layerIndex);
91 QRhiTexture *shadowMapAtlasTexture() const;
92
93 qsizetype shadowMapEntryCount() { return m_shadowMapList.size(); }
94
95 QRhiShaderResourceBindings *shadowClearSrb() const { return m_shadowClearSrb.get(); }
96
97private:
98 QSSGShadowMapEntry *addShadowMap(quint32 lightIdx,
99 QSize size,
100 QVector<QSSGShadowMapEntry::AtlasEntry> atlasEntries,
101 quint32 csmNumSplits,
102 QRhiTexture::Format format,
103 bool isPointLight,
104 const QString &renderNodeObjName);
105
106 QVector<QSSGShadowMapEntry> m_shadowMapList;
107 std::unique_ptr<QRhiTexture> m_shadowMapAtlasTexture;
108 std::unique_ptr<QRhiSampler> m_sharedCubeToAtlasSampler;
109 std::unique_ptr<QRhiBuffer> m_sharedFrontCubeToAtlasUniformBuffer;
110 std::unique_ptr<QRhiBuffer> m_sharedBackCubeToAtlasUniformBuffer;
111 std::unique_ptr<QRhiShaderResourceBindings> m_shadowClearSrb;
112 QVector<QRhiRenderBuffer *> m_layerDepthStencilBuffers;
113 QVector<QRhiTextureRenderTarget *> m_layerRenderTargets;
114 QVector<QRhiRenderPassDescriptor *> m_layerRenderPassDescriptors;
115};
116
117using QSSGRenderShadowMapPtr = std::shared_ptr<QSSGRenderShadowMap>;
118
119QT_END_NAMESPACE
120
121#endif
QSSGRenderShadowMap(const QSSGRenderContextInterface &inContext)
QRhiShaderResourceBindings * shadowClearSrb() const
QRhiRenderPassDescriptor * layerRenderPassDescriptor(int layerIndex)
QRhiTextureRenderTarget * layerRenderTarget(int layerIndex)
QSSGShadowMapEntry * shadowMapEntry(int lightIdx)
void addShadowMaps(const QSSGShaderLightList &renderableLights)
friend class QSSGRenderContextInterface
QRhiTexture * shadowMapAtlasTexture() const
std::array< QRhiRenderPassDescriptor *, 4 > m_rhiRenderPassDesc
std::array< QRhiTextureRenderTarget *, 6 > m_rhiRenderTargetCube
quint32 m_depthArrayIndex
shadow map texture array index
QRhiRenderBuffer * m_rhiDepthStencilCube
QMatrix4x4 m_fixedScaleBiasMatrix[4]
QMatrix4x4 m_lightViewProjection[4]
light view projection matrix
QRhiShaderResourceBindings * m_cubeToAtlasFrontSrb
std::array< QRhiTextureRenderTarget *, 4 > m_rhiRenderTargets
QRhiShaderResourceBindings * m_cubeToAtlasBackSrb
QMatrix4x4 m_lightCubeView[6]
light cubemap view matrices
static QSSGShadowMapEntry withAtlas(quint32 lightIdx)
QRhiRenderPassDescriptor * m_rhiRenderPassDescCube
QVector4D m_dimensionsInverted[4]
(x, y, z, 0) 4 vec4
quint32 m_lightIndex
the light index it belongs to
QMatrix4x4 m_lightView
light view transform