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
qssgrenderlayer_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_LAYER_H
8#define QSSG_RENDER_LAYER_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/qssgrendernode_p.h>
22#include <QtCore/qvarlengtharray.h>
23#include <QtCore/qlist.h>
24#include <QMutex>
25#include <ssg/qssglightmapper.h>
26
29struct QSSGRenderPresentation;
30struct QSSGRenderEffect;
31struct QSSGRenderImage;
33struct QSSGRenderResourceLoader;
34
35class QQuick3DObject;
36class QSSGRenderExtension;
37
38class QRhiShaderResourceBindings;
39
40// A layer is a special node. It *always* presents its global transform
41// to children as the identity. It also can optionally have a width or height
42// different than the overlying context. You can think of layers as the transformation
43// between a 3d scene graph and a 2D texture.
44struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderLayer : public QSSGRenderNode
45{
46 enum class AAMode : quint8
47 {
48 NoAA = 0,
49 SSAA,
50 MSAA,
51 ProgressiveAA
52 };
53
54 enum class TAAMode : quint8
55 {
56 Off = 0,
57 Default,
58 MotionVector
59 };
60
61 enum class AAQuality : quint8
62 {
63 Normal = 2,
64 High = 4,
65 VeryHigh = 8
66 };
67
68 enum class HorizontalField : quint8
69 {
70 LeftWidth = 0,
71 LeftRight,
72 WidthRight
73 };
74
75 enum class VerticalField : quint8
76 {
77 TopHeight = 0,
78 TopBottom,
79 HeightBottom
80 };
81
82 enum class UnitType : quint8
83 {
84 Percent = 0,
85 Pixels
86 };
87
88 enum class Background : quint8
89 {
90 Transparent = 0,
91 Unspecified,
92 Color,
93 SkyBox,
94 SkyBoxCubeMap
95 };
96
97 enum class TonemapMode : quint8
98 {
99 None = 0, // Bypass mode
100 Linear,
101 Aces,
102 HejlDawson,
103 Filmic,
104 Custom
105 };
106 static size_t constexpr TonemapModeCount = 6;
107
108 enum class LayerFlag
109 {
110 EnableDepthTest = 0x1,
111 EnableDepthPrePass = 0x2, ///< True when we render a depth pass before
112 RenderToTarget = 0x3 ///< Does this layer render to the normal render target,
113 };
114 Q_DECLARE_FLAGS(LayerFlags, LayerFlag)
115
116 enum class MaterialDebugMode : quint8
117 {
118 None = 0, // Bypass
119 BaseColor = 1,
120 Roughness,
121 Metalness,
122 Diffuse,
123 Specular,
124 ShadowOcclusion,
125 Emission,
126 AmbientOcclusion,
127 Normal,
128 Tangent,
129 Binormal,
130 F0
131 };
132
133 enum class OITMethod : quint8
134 {
135 None = 0,
136 WeightedBlended,
137 LinkedList
138 };
139
140 enum class RenderOverrides : quint8
141 {
142 None = 0,
143 DisableInternalPasses = 0x1,
144 };
145 using RenderOverridesT = std::underlying_type_t<RenderOverrides>;
146
147 enum class DirtyFlag : quint8
148 {
149 TreeDirty = 0x1
150 };
151 using FlagT = std::underlying_type_t<DirtyFlag>;
152
153 static constexpr DirtyFlag DirtyMask { std::numeric_limits<FlagT>::max() };
154
155 [[nodiscard]] bool isDirty(DirtyFlag dirtyFlag = DirtyMask) const
156 {
157 return ((m_layerDirtyFlags & FlagT(dirtyFlag)) != 0)
158 || ((dirtyFlag == DirtyMask) && QSSGRenderNode::isDirty());
159 }
160 void markDirty(DirtyFlag dirtyFlag);
161 void clearDirty(DirtyFlag dirtyFlag);
162
163 void ref(QSSGRenderRoot *inRootNode)
164 {
165 rootNode = inRootNode;
166 rootNodeRef = &rootNode;
167 }
168
169 QSSGRenderRoot *rootNode = nullptr;
170
171 QSSGRenderLayerHandle lh;
172
173 // First effect in a list of effects.
174 QSSGRenderEffect *firstEffect;
175 QSSGLayerRenderData *renderData = nullptr;
176 enum class RenderExtensionStage { TextureProviders, Underlay, Overlay, Count };
177 QList<QSSGRenderExtension *> renderExtensions[size_t(RenderExtensionStage::Count)];
178
179 QSSGRenderLayer::AAMode antialiasingMode;
180 QSSGRenderLayer::AAQuality antialiasingQuality;
181 QVector4D currentAndLastJitter;
182
183 QSSGRenderLayer::Background background;
184 QVector3D clearColor;
185
186 FlagT m_layerDirtyFlags = FlagT(DirtyFlag::TreeDirty);
187 quint8 viewCount = 1;
188
189 // Ambient occlusion
190 float aoStrength = 0.0f;
191 float aoDistance = 5.0f;
192 float aoSoftness = 50.0f;
193 float aoBias = 0.0f;
194 qint32 aoSamplerate = 2;
195 bool aoDither = false;
196 bool aoEnabled = false;
197
198 constexpr bool ssaoEnabled() const { return aoEnabled && (aoStrength > 0.0f && aoDistance > 0.0f); }
199
200 // IBL
201 QSSGRenderImage *lightProbe { nullptr };
202 struct LightProbeSettings {
203 float probeExposure { 1.0f };
204 float probeHorizon { -1.0f };
205 QMatrix3x3 probeOrientation;
206 QVector3D probeOrientationAngles;
207 } lightProbeSettings;
208
209 QSSGRenderImage *skyBoxCubeMap = nullptr;
210
211 TAAMode temporalAAMode { TAAMode::Off };
212 float temporalAAStrength;
213 float ssaaMultiplier;
214 bool specularAAEnabled;
215 OITMethod oitMethod;
216 bool oitMethodDirty;
217 int oitNodeCount;
218
219 //TODO: move render state somewhere more suitable
220 bool temporalAAIsActive;
221 bool progressiveAAIsActive;
222 uint tempAAPassIndex;
223 uint progAAPassIndex;
224
225 RenderOverridesT renderOverrides { RenderOverridesT(RenderOverrides::None) };
226
227 // The camera explicitly set on the view by the user. (backend node can be null)
228 QVarLengthArray<QSSGRenderCamera *, 2> explicitCameras;
229 // The camera used for rendering, multiple ones with multiview.
230 QVarLengthArray<QSSGRenderCamera *, 2> renderedCameras;
231 QMutex renderedCamerasMutex;
232
233 // Tonemapping
234 TonemapMode tonemapMode;
235
236 LayerFlags layerFlags { LayerFlag::RenderToTarget,
237 LayerFlag::EnableDepthTest,
238 LayerFlag::EnableDepthPrePass };
239
240 // references to objects owned by the QSSGRhiContext
241 QRhiShaderResourceBindings *skyBoxSrb = nullptr;
242 QVarLengthArray<QRhiShaderResourceBindings *, 4> item2DSrbs;
243 bool skyBoxIsRgbe8 = false;
244 bool skyBoxIsSrgb = false;
245
246 // Skybox
247 float skyboxBlurAmount = 0.0f;
248
249 // Grid
250 bool gridEnabled = false;
251 float gridScale = 1.0f;
252 quint32 gridFlags = 0;
253 QRhiShaderResourceBindings *gridSrb = nullptr;
254
255 // Scissor
256 QRect scissorRect;
257
258 // Fog
259 struct FogOptions {
260 bool enabled = false;
261 QVector3D color = QVector3D(0.5f, 0.6f, 0.7f);
262 float density = 1.0f;
263 bool depthEnabled = false;
264 float depthBegin = 10.0f;
265 float depthEnd = 1000.0f;
266 float depthCurve = 1.0f;
267 bool heightEnabled = false;
268 float heightMin = 10.0f;
269 float heightMax = 0.0f;
270 float heightCurve = 1.0f;
271 bool transmitEnabled = false;
272 float transmitCurve = 1.0f;
273 } fog;
274
275 QVector<QSSGRenderGraphObject *> resourceLoaders;
276
277 MaterialDebugMode debugMode = MaterialDebugMode::None;
278
279 bool wireframeMode = false;
280 bool drawDirectionalLightShadowBoxes = false;
281 bool drawPointLightShadowBoxes = false;
282 bool drawShadowCastingBounds = false;
283 bool drawShadowReceivingBounds = false;
284 bool drawCascades = false;
285 bool drawSceneCascadeIntersection = false;
286 bool disableShadowCameraUpdate = false;
287 bool drawCulledObjects = false;
288
289 // Would ideally be in QSSGLayerRenderData but it is created too late
290 // so needs to be set here.
291 QString lightmapSource;
292
293 QSSGRenderLayer();
294 ~QSSGRenderLayer();
295
296 void setProbeOrientation(const QVector3D &angles);
297
298 void addEffect(QSSGRenderEffect &inEffect);
299 bool hasEffect(QSSGRenderEffect *inEffect) const;
300
301 QSSGRenderNode *importSceneNode = nullptr;
302
303 // Special function(s) for importScene
304 void setImportScene(QSSGRenderNode &rootNode);
305 void removeImportScene(QSSGRenderNode &rootNode);
306
307 [[nodiscard]] bool isMsaaEnabled() const { return antialiasingMode == AAMode::MSAA; }
308 [[nodiscard]] bool isSsaaEnabled() const { return antialiasingMode == AAMode::SSAA; }
309 // NOTE: Progressive AA is not enabled when temporalAA mode is MotionVector.
310 [[nodiscard]] bool isProgressiveAAEnabled() const { return antialiasingMode == AAMode::ProgressiveAA && temporalAAMode != TAAMode::MotionVector; }
311 // NOTE: Temporal AA is not enabled when MSAA is enabled.
312 [[nodiscard]] bool isTemporalAAEnabled() const { return (temporalAAMode != TAAMode::Off) && !isMsaaEnabled(); }
313
314 static constexpr float ssaaMultiplierForQuality(QSSGRenderLayer::AAQuality quality)
315 {
316 switch (quality) {
317 case QSSGRenderLayer::AAQuality::Normal:
318 return 1.2f;
319 case QSSGRenderLayer::AAQuality::High:
320 return 1.5f;
321 case QSSGRenderLayer::AAQuality::VeryHigh:
322 return 2.0f;
323 }
324
325 return 1.5f; // QSSGRenderLayer::AAQuality::High
326 }
327};
328QT_END_NAMESPACE
329
330#endif
void releaseRenderData(const QSSGRenderItem2D &item)
void updateItem2DData(QSSGItem2DsView &items, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData)
Item2DRenderer getItem2DRenderer(const QSSGRenderItem2D &item) const
ModelViewProjections getModelViewProjection(QSSGRenderItem2DHandle h) const
ModelViewProjections getModelViewProjection(const QSSGRenderItem2D &item) const
void updateModelData(QSSGModelsView &models, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData)
QMatrix3x3 getNormalMatrix(QSSGRenderModelHandle h, QMatrix3x3 defaultValue) const
QSSGRenderMesh * getMesh(QSSGRenderModelHandle h) const
MaterialList getMaterials(QSSGRenderModelHandle h) const
ModelViewProjections getModelViewProjection(QSSGRenderModelHandle h) const
friend class QSSGRenderContextInterface
Combined button and popup list for selecting options.
#define qssgTryWaitForDone()
static bool calcGlobalNodeDataIndexedImpl(QSSGRenderNode *node, const quint32 version, QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms, QSSGGlobalRenderNodeData::GlobalOpacityStore &globalOpacities)
static void collectLayerChildNodes(QSSGRenderLayer *layer, QSSGGlobalRenderNodeData::NodeStore &outList, size_t &idx)
static void collectChildNodesFirst(QSSGRenderNode &node, QSSGGlobalRenderNodeData::NodeStore &outList, size_t &idx)
#define qssgTryThreadedStart(func)
static void collectChildNodesSecond(QSSGRenderNode &node, QSSGGlobalRenderNodeData::NodeStore &outList, size_t &idx)