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 bool hasActiveCascades() const;
43
45
46 quint32 m_lightIndex; ///< the light index it belongs to
47 quint32 m_depthArrayIndex = 0; ///< shadow map texture array index
48
49 // Owned RHI Resoruces (just for point lights)
50 QRhiTexture *m_rhiDepthCube = nullptr; // shadow cube map
51 QRhiRenderBuffer *m_rhiDepthStencilCube = nullptr;
52 QRhiRenderPassDescriptor *m_rhiRenderPassDescCube = nullptr;
56
57 // Shared RHI Resources
60
61 QMatrix4x4 m_lightViewProjection[4]; ///< light view projection matrix
62 QMatrix4x4 m_lightCubeView[6]; ///< light cubemap view matrices
63 QMatrix4x4 m_lightView; ///< light view transform
65 float m_csmSplits[4] = {};
66 float m_csmActive[4] = {};
67 float m_shadowMapFar = 0.f;
69 QVector4D m_dimensionsInverted[4]; ///< (x, y, z, 0) 4 vec4
70
71 struct AtlasEntry {
72 int layerIndex = 0;
73 float uOffset = 0.0f;
74 float vOffset = 0.0f;
75 float uvScale = 1.0f;
76 } m_atlasInfo[4];
77};
78
79class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderShadowMap
80{
81 Q_DISABLE_COPY(QSSGRenderShadowMap)
82
83public:
84 const QSSGRenderContextInterface &m_context;
85
86 explicit QSSGRenderShadowMap(const QSSGRenderContextInterface &inContext);
87 ~QSSGRenderShadowMap();
88 void releaseCachedResources();
89 void addShadowMaps(const QSSGShaderLightList &renderableLights);
90
92 QRhiTextureRenderTarget *layerRenderTarget(int layerIndex);
93 QRhiRenderPassDescriptor *layerRenderPassDescriptor(int layerIndex);
94 QRhiTexture *shadowMapAtlasTexture() const;
95 QRhiTexture *shadowMapBlueNoiseTexture() const;
96
97 qsizetype shadowMapEntryCount() { return m_shadowMapList.size(); }
98
99 QRhiShaderResourceBindings *shadowClearSrb() const { return m_shadowClearSrb.get(); }
100
101private:
102 QSSGShadowMapEntry *addShadowMap(quint32 lightIdx,
103 QSize size,
104 QVector<QSSGShadowMapEntry::AtlasEntry> atlasEntries,
105 quint32 csmNumSplits,
106 QRhiTexture::Format format,
107 bool isPointLight,
108 const QString &renderNodeObjName);
109
110 QVector<QSSGShadowMapEntry> m_shadowMapList;
111 std::unique_ptr<QRhiTexture> m_shadowMapAtlasTexture;
112 std::unique_ptr<QRhiTexture> m_shadowMapBlueNoiseTexture;
113 std::unique_ptr<QRhiSampler> m_sharedCubeToAtlasSampler;
114 std::unique_ptr<QRhiBuffer> m_sharedFrontCubeToAtlasUniformBuffer;
115 std::unique_ptr<QRhiBuffer> m_sharedBackCubeToAtlasUniformBuffer;
116 std::unique_ptr<QRhiShaderResourceBindings> m_shadowClearSrb;
117 QVector<QRhiRenderBuffer *> m_layerDepthStencilBuffers;
118 QVector<QRhiTextureRenderTarget *> m_layerRenderTargets;
119 QVector<QRhiRenderPassDescriptor *> m_layerRenderPassDescriptors;
120};
121
122using QSSGRenderShadowMapPtr = std::shared_ptr<QSSGRenderShadowMap>;
123
124QT_END_NAMESPACE
125
126#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