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// Qt-Security score:significant reason:default
5
6
7#ifndef QSSG_RENDER_SHADOW_MAP_H
8#define QSSG_RENDER_SHADOW_MAP_H
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
21#include <QtQuick3DRuntimeRender/private/qtquick3druntimerenderglobal_p.h>
22#include <QtGui/QMatrix4x4>
23#include <QtGui/QVector3D>
24#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
25#include <QtQuick3DRuntimeRender/private/qssgrenderableobjects_p.h>
26
27QT_BEGIN_NAMESPACE
28
29class QSSGRhiContext;
31
32class QRhiRenderBuffer;
33class QRhiTextureRenderTarget;
34class QRhiRenderPassDescriptor;
35class QRhiTexture;
36
38{
40
41 static QSSGShadowMapEntry withAtlas(quint32 lightIdx);
42
44
45 quint32 m_lightIndex; ///< the light index it belongs to
46 quint32 m_depthArrayIndex = 0; ///< shadow map texture array index
47
48 // Owned RHI Resoruces (just for point lights)
49 QRhiTexture *m_rhiDepthCube = nullptr; // shadow cube map
50 QRhiRenderBuffer *m_rhiDepthStencilCube = nullptr;
51 QRhiRenderPassDescriptor *m_rhiRenderPassDescCube = nullptr;
55
56 // Shared RHI Resources
59
60 QMatrix4x4 m_lightViewProjection[4]; ///< light view projection matrix
61 QMatrix4x4 m_lightCubeView[6]; ///< light cubemap view matrices
62 QMatrix4x4 m_lightView; ///< light view transform
64 float m_csmSplits[4] = {};
65 float m_csmActive[4] = {};
66 float m_shadowMapFar = 0.f;
68 QVector4D m_dimensionsInverted[4]; ///< (x, y, z, 0) 4 vec4
69
70 struct AtlasEntry {
71 int layerIndex = 0;
72 float uOffset = 0.0f;
73 float vOffset = 0.0f;
74 float uvScale = 1.0f;
75 } m_atlasInfo[4];
76};
77
78class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderShadowMap
79{
80 Q_DISABLE_COPY(QSSGRenderShadowMap)
81
82public:
83 const QSSGRenderContextInterface &m_context;
84
85 explicit QSSGRenderShadowMap(const QSSGRenderContextInterface &inContext);
86 ~QSSGRenderShadowMap();
87 void releaseCachedResources();
88 void addShadowMaps(const QSSGShaderLightList &renderableLights);
89
91 QRhiTextureRenderTarget *layerRenderTarget(int layerIndex);
92 QRhiRenderPassDescriptor *layerRenderPassDescriptor(int layerIndex);
93 QRhiTexture *shadowMapAtlasTexture() const;
94 QRhiTexture *shadowMapBlueNoiseTexture() const;
95
96 qsizetype shadowMapEntryCount() { return m_shadowMapList.size(); }
97
98 QRhiShaderResourceBindings *shadowClearSrb() const { return m_shadowClearSrb.get(); }
99
100private:
101 QSSGShadowMapEntry *addShadowMap(quint32 lightIdx,
102 QSize size,
103 QVector<QSSGShadowMapEntry::AtlasEntry> atlasEntries,
104 quint32 csmNumSplits,
105 QRhiTexture::Format format,
106 bool isPointLight,
107 const QString &renderNodeObjName);
108
109 QVector<QSSGShadowMapEntry> m_shadowMapList;
110 std::unique_ptr<QRhiTexture> m_shadowMapAtlasTexture;
111 std::unique_ptr<QRhiTexture> m_shadowMapBlueNoiseTexture;
112 std::unique_ptr<QRhiSampler> m_sharedCubeToAtlasSampler;
113 std::unique_ptr<QRhiBuffer> m_sharedFrontCubeToAtlasUniformBuffer;
114 std::unique_ptr<QRhiBuffer> m_sharedBackCubeToAtlasUniformBuffer;
115 std::unique_ptr<QRhiShaderResourceBindings> m_shadowClearSrb;
116 QVector<QRhiRenderBuffer *> m_layerDepthStencilBuffers;
117 QVector<QRhiTextureRenderTarget *> m_layerRenderTargets;
118 QVector<QRhiRenderPassDescriptor *> m_layerRenderPassDescriptors;
119};
120
121using QSSGRenderShadowMapPtr = std::shared_ptr<QSSGRenderShadowMap>;
122
123QT_END_NAMESPACE
124
125#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
QRhiTexture * shadowMapBlueNoiseTexture() 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