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 };
153 using FlagT = std::underlying_type_t<DirtyFlag>;
154
155 static constexpr DirtyFlag DirtyMask { std::numeric_limits<FlagT>::max() };
156
157 [[nodiscard]] bool isDirty(DirtyFlag dirtyFlag = DirtyMask) const
158 {
159 return ((m_layerDirtyFlags & FlagT(dirtyFlag)) != 0)
160 || ((dirtyFlag == DirtyMask) && QSSGRenderNode::isDirty());
161 }
162 void markDirty(DirtyFlag dirtyFlag);
163 void clearDirty(DirtyFlag dirtyFlag);
164
165 void ref(QSSGRenderRoot *inRootNode)
166 {
167 rootNode = inRootNode;
168 rootNodeRef = &rootNode;
169 }
170
171 QSSGRenderRoot *rootNode = nullptr;
172
173 QSSGRenderLayerHandle lh;
174
175 // First effect in a list of effects.
176 QSSGRenderEffect *firstEffect;
177 QSSGLayerRenderData *renderData = nullptr;
178 enum class RenderExtensionStage { TextureProviders, Underlay, Overlay, Count };
179 QList<QSSGRenderExtension *> renderExtensions[size_t(RenderExtensionStage::Count)];
180
181 QSSGRenderLayer::AAMode antialiasingMode;
182 QSSGRenderLayer::AAQuality antialiasingQuality;
183 QVector4D currentAndLastJitter;
184
185 QSSGRenderLayer::Background background;
186 QVector3D clearColor;
187
188 FlagT m_layerDirtyFlags = FlagT(DirtyFlag::TreeDirty);
189 quint8 viewCount = 1;
190
191 // Ambient occlusion
192 float aoStrength = 0.0f;
193 float aoDistance = 5.0f;
194 float aoSoftness = 50.0f;
195 float aoBias = 0.0f;
196 qint32 aoSamplerate = 2;
197 bool aoDither = false;
198 bool aoEnabled = false;
199
200 constexpr bool ssaoEnabled() const { return aoEnabled && (aoStrength > 0.0f && aoDistance > 0.0f); }
201
202 // IBL
203 QSSGRenderImage *lightProbe { nullptr };
204 struct LightProbeSettings {
205 float probeExposure { 1.0f };
206 float probeHorizon { -1.0f };
207 QMatrix3x3 probeOrientation;
208 QVector3D probeOrientationAngles;
209 } lightProbeSettings;
210
211 QSSGRenderSkyMaterial *skyMaterial = nullptr;
212
213 QSSGRenderImage *skyBoxCubeMap = nullptr;
214
215 TAAMode temporalAAMode { TAAMode::Off };
216 float temporalAAStrength;
217 float ssaaMultiplier;
218 bool specularAAEnabled;
219 OITMethod oitMethod;
220 bool oitMethodDirty;
221 int oitNodeCount;
222
223 //TODO: move render state somewhere more suitable
224 bool temporalAAIsActive;
225 bool progressiveAAIsActive;
226 uint tempAAPassIndex;
227 uint progAAPassIndex;
228
229 RenderOverridesT renderOverrides { RenderOverridesT(RenderOverrides::None) };
230
231 // The camera explicitly set on the view by the user. (backend node can be null)
232 QVarLengthArray<QSSGRenderCamera *, 2> explicitCameras;
233 // The camera used for rendering, multiple ones with multiview.
234 QVarLengthArray<QSSGRenderCamera *, 2> renderedCameras;
235 QMutex renderedCamerasMutex;
236
237 // Tonemapping
238 TonemapMode tonemapMode;
239
240 LayerFlags layerFlags { LayerFlag::RenderToTarget,
241 LayerFlag::EnableDepthTest,
242 LayerFlag::EnableDepthPrePass };
243
244 // references to objects owned by the QSSGRhiContext
245 QRhiShaderResourceBindings *skyBoxSrb = nullptr;
246 QVarLengthArray<QRhiShaderResourceBindings *, 4> item2DSrbs;
247 bool skyBoxIsRgbe8 = false;
248 bool skyBoxIsSrgb = false;
249
250 // Skybox
251 float skyboxBlurAmount = 0.0f;
252
253 // Grid
254 bool gridEnabled = false;
255 float gridScale = 1.0f;
256 quint32 gridFlags = 0;
257 QRhiShaderResourceBindings *gridSrb = nullptr;
258
259 // Scissor
260 QRect scissorRect;
261
262 // Fog
263 struct FogOptions {
264 bool enabled = false;
265 QVector3D color = QVector3D(0.5f, 0.6f, 0.7f);
266 float density = 1.0f;
267 bool depthEnabled = false;
268 float depthBegin = 10.0f;
269 float depthEnd = 1000.0f;
270 float depthCurve = 1.0f;
271 bool heightEnabled = false;
272 float heightMin = 10.0f;
273 float heightMax = 0.0f;
274 float heightCurve = 1.0f;
275 bool transmitEnabled = false;
276 float transmitCurve = 1.0f;
277 } fog;
278
279 QVector<QSSGRenderGraphObject *> resourceLoaders;
280
281 MaterialDebugMode debugMode = MaterialDebugMode::None;
282
283 bool wireframeMode = false;
284 bool drawDirectionalLightShadowBoxes = false;
285 bool drawPointLightShadowBoxes = false;
286 bool drawShadowCastingBounds = false;
287 bool drawShadowReceivingBounds = false;
288 bool drawCascades = false;
289 bool drawSceneCascadeIntersection = false;
290 bool disableShadowCameraUpdate = false;
291 bool drawCulledObjects = false;
292
293 // Would ideally be in QSSGLayerRenderData but it is created too late
294 // so needs to be set here.
295 QString lightmapSource;
296
297 QSSGRenderLayer();
298 ~QSSGRenderLayer();
299
300 void setProbeOrientation(const QVector3D &angles);
301
302 void addEffect(QSSGRenderEffect &inEffect);
303 bool hasEffect(QSSGRenderEffect *inEffect) const;
304
305 QSSGRenderNode *importSceneNode = nullptr;
306
307 // Special function(s) for importScene
308 void setImportScene(QSSGRenderNode &rootNode);
309 void removeImportScene(QSSGRenderNode &rootNode);
310
311 [[nodiscard]] bool isMsaaEnabled() const { return antialiasingMode == AAMode::MSAA; }
312 [[nodiscard]] bool isSsaaEnabled() const { return antialiasingMode == AAMode::SSAA; }
313 // NOTE: Progressive AA is not enabled when temporalAA mode is MotionVector.
314 [[nodiscard]] bool isProgressiveAAEnabled() const { return antialiasingMode == AAMode::ProgressiveAA && temporalAAMode != TAAMode::MotionVector; }
315 // NOTE: Temporal AA is not enabled when MSAA is enabled.
316 [[nodiscard]] bool isTemporalAAEnabled() const { return (temporalAAMode != TAAMode::Off) && !isMsaaEnabled(); }
317
318 static constexpr float ssaaMultiplierForQuality(QSSGRenderLayer::AAQuality quality)
319 {
320 switch (quality) {
321 case QSSGRenderLayer::AAQuality::Normal:
322 return 1.2f;
323 case QSSGRenderLayer::AAQuality::High:
324 return 1.5f;
325 case QSSGRenderLayer::AAQuality::VeryHigh:
326 return 2.0f;
327 }
328
329 return 1.5f; // QSSGRenderLayer::AAQuality::High
330 }
331};
332QT_END_NAMESPACE
333
334#endif
friend class QSSGRenderContextInterface
Combined button and popup list for selecting options.