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
5#ifndef QSSG_RENDER_LAYER_H
6#define QSSG_RENDER_LAYER_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick3DRuntimeRender/private/qssgrendernode_p.h>
20#include <QtCore/qvarlengtharray.h>
21#include <QtCore/qlist.h>
22#include <QMutex>
23#include <ssg/qssglightmapper.h>
24
25QT_BEGIN_NAMESPACE
26class QSSGRenderContextInterface;
27struct QSSGRenderPresentation;
28struct QSSGRenderEffect;
29struct QSSGRenderImage;
30class QSSGLayerRenderData;
31struct QSSGRenderResourceLoader;
32
33class QQuick3DObject;
34class QSSGRenderExtension;
35
36class QRhiShaderResourceBindings;
37
38// A layer is a special node. It *always* presents its global transform
39// to children as the identity. It also can optionally have a width or height
40// different than the overlying context. You can think of layers as the transformation
41// between a 3d scene graph and a 2D texture.
42struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderLayer : public QSSGRenderNode
43{
44 enum class AAMode : quint8
45 {
46 NoAA = 0,
47 SSAA,
48 MSAA,
49 ProgressiveAA
50 };
51
52 enum class TAAMode : quint8
53 {
54 Off,
55 On
56 };
57
58 enum class AAQuality : quint8
59 {
60 Normal = 2,
61 High = 4,
62 VeryHigh = 8
63 };
64
65 enum class HorizontalField : quint8
66 {
67 LeftWidth = 0,
68 LeftRight,
69 WidthRight
70 };
71
72 enum class VerticalField : quint8
73 {
74 TopHeight = 0,
75 TopBottom,
76 HeightBottom
77 };
78
79 enum class UnitType : quint8
80 {
81 Percent = 0,
82 Pixels
83 };
84
85 enum class Background : quint8
86 {
87 Transparent = 0,
88 Unspecified,
89 Color,
90 SkyBox,
91 SkyBoxCubeMap
92 };
93
94 enum class TonemapMode : quint8
95 {
96 None = 0, // Bypass mode
97 Linear,
98 Aces,
99 HejlDawson,
100 Filmic,
101 Custom
102 };
103 static size_t constexpr TonemapModeCount = 6;
104
105 enum class LayerFlag
106 {
107 EnableDepthTest = 0x1,
108 EnableDepthPrePass = 0x2, ///< True when we render a depth pass before
109 RenderToTarget = 0x3 ///< Does this layer render to the normal render target,
110 };
111 Q_DECLARE_FLAGS(LayerFlags, LayerFlag)
112
113 enum class MaterialDebugMode : quint8
114 {
115 None = 0, // Bypass
116 BaseColor = 1,
117 Roughness,
118 Metalness,
119 Diffuse,
120 Specular,
121 ShadowOcclusion,
122 Emission,
123 AmbientOcclusion,
124 Normal,
125 Tangent,
126 Binormal,
127 F0
128 };
129
130 // First effect in a list of effects.
131 QSSGRenderEffect *firstEffect;
132 QSSGLayerRenderData *renderData = nullptr;
133 enum class RenderExtensionStage { Underlay, Overlay, Count };
134 QList<QSSGRenderExtension *> renderExtensions[size_t(RenderExtensionStage::Count)];
135
136 QSSGRenderLayer::AAMode antialiasingMode;
137 QSSGRenderLayer::AAQuality antialiasingQuality;
138
139 QSSGRenderLayer::Background background;
140 QVector3D clearColor;
141
142 quint8 viewCount = 1;
143
144 // Ambient occlusion
145 float aoStrength = 0.0f;
146 float aoDistance = 5.0f;
147 float aoSoftness = 50.0f;
148 float aoBias = 0.0f;
149 qint32 aoSamplerate = 2;
150 bool aoDither = false;
151 bool aoEnabled = false;
152
153 constexpr bool ssaoEnabled() const { return aoEnabled && (aoStrength > 0.0f && aoDistance > 0.0f); }
154
155 // IBL
156 QSSGRenderImage *lightProbe { nullptr };
157 struct LightProbeSettings {
158 float probeExposure { 1.0f };
159 float probeHorizon { -1.0f };
160 QMatrix3x3 probeOrientation;
161 QVector3D probeOrientationAngles;
162 } lightProbeSettings;
163
164 QSSGRenderImage *skyBoxCubeMap = nullptr;
165
166 TAAMode temporalAAMode { TAAMode::Off };
167 float temporalAAStrength;
168 float ssaaMultiplier;
169 bool specularAAEnabled;
170
171 //TODO: move render state somewhere more suitable
172 bool temporalAAIsActive;
173 bool progressiveAAIsActive;
174 uint tempAAPassIndex;
175 uint progAAPassIndex;
176
177 // The camera explicitly set on the view by the user. (backend node can be null)
178 QVarLengthArray<QSSGRenderCamera *, 2> explicitCameras;
179 // The camera used for rendering, multiple ones with multiview.
180 QVarLengthArray<QSSGRenderCamera *, 2> renderedCameras;
181 QMutex renderedCamerasMutex;
182
183 // Tonemapping
184 TonemapMode tonemapMode;
185
186 LayerFlags layerFlags { LayerFlag::RenderToTarget,
187 LayerFlag::EnableDepthTest,
188 LayerFlag::EnableDepthPrePass };
189
190 // references to objects owned by the QSSGRhiContext
191 QRhiShaderResourceBindings *skyBoxSrb = nullptr;
192 QVarLengthArray<QRhiShaderResourceBindings *, 4> item2DSrbs;
193 bool skyBoxIsRgbe8 = false;
194
195 // Skybox
196 float skyboxBlurAmount = 0.0f;
197
198 // Grid
199 bool gridEnabled = false;
200 float gridScale = 1.0f;
201 quint32 gridFlags = 0;
202 QRhiShaderResourceBindings *gridSrb = nullptr;
203
204 // Lightmapper config
205 QSSGLightmapperOptions lmOptions;
206
207 // Scissor
208 QRect scissorRect;
209
210 // Fog
211 struct FogOptions {
212 bool enabled = false;
213 QVector3D color = QVector3D(0.5f, 0.6f, 0.7f);
214 float density = 1.0f;
215 bool depthEnabled = false;
216 float depthBegin = 10.0f;
217 float depthEnd = 1000.0f;
218 float depthCurve = 1.0f;
219 bool heightEnabled = false;
220 float heightMin = 10.0f;
221 float heightMax = 0.0f;
222 float heightCurve = 1.0f;
223 bool transmitEnabled = false;
224 float transmitCurve = 1.0f;
225 } fog;
226
227 QVector<QSSGRenderGraphObject *> resourceLoaders;
228
229 MaterialDebugMode debugMode = MaterialDebugMode::None;
230
231 bool wireframeMode = false;
232 bool drawDirectionalLightShadowBoxes = false;
233 bool drawShadowCastingBounds = false;
234 bool drawShadowReceivingBounds = false;
235 bool drawCascades = false;
236 bool drawSceneCascadeIntersection = false;
237 bool disableShadowCameraUpdate = false;
238
239 QSSGRenderLayer();
240 ~QSSGRenderLayer();
241
242 void setProbeOrientation(const QVector3D &angles);
243
244 void addEffect(QSSGRenderEffect &inEffect);
245 bool hasEffect(QSSGRenderEffect *inEffect) const;
246
247 QSSGRenderNode *importSceneNode = nullptr;
248
249 // Special function(s) for importScene
250 void setImportScene(QSSGRenderNode &rootNode);
251 void removeImportScene(QSSGRenderNode &rootNode);
252
253 [[nodiscard]] bool isMsaaEnabled() const { return antialiasingMode == AAMode::MSAA; }
254 [[nodiscard]] bool isSsaaEnabled() const { return antialiasingMode == AAMode::SSAA; }
255 [[nodiscard]] bool isProgressiveAAEnabled() const { return antialiasingMode == AAMode::ProgressiveAA; }
256 // NOTE: Temporal AA is not enabled when MSAA is enabled.
257 [[nodiscard]] bool isTemporalAAEnabled() const { return (temporalAAMode == TAAMode::On) && !isMsaaEnabled(); }
258
259 static constexpr float ssaaMultiplierForQuality(QSSGRenderLayer::AAQuality quality)
260 {
261 switch (quality) {
262 case QSSGRenderLayer::AAQuality::Normal:
263 return 1.2f;
264 case QSSGRenderLayer::AAQuality::High:
265 return 1.5f;
266 case QSSGRenderLayer::AAQuality::VeryHigh:
267 return 2.0f;
268 }
269
270 return 1.5f; // QSSGRenderLayer::AAQuality::High
271 }
272};
273QT_END_NAMESPACE
274
275#endif
276

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtquick3d/src/runtimerender/graphobjects/qssgrenderlayer_p.h