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