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 <QtQuick3DRuntimeRender/private/qssglightmapper_p.h>
21#include <QtCore/qvarlengtharray.h>
22#include <QtCore/qlist.h>
23
24QT_BEGIN_NAMESPACE
25class QSSGRenderContextInterface;
26struct QSSGRenderPresentation;
27struct QSSGRenderEffect;
28struct QSSGRenderImage;
29class QSSGLayerRenderData;
30struct QSSGRenderResourceLoader;
31
32class QQuick3DObject;
33class QSSGRenderExtension;
34
35class QRhiShaderResourceBindings;
36
37// A layer is a special node. It *always* presents its global transform
38// to children as the identity. It also can optionally have a width or height
39// different than the overlying context. You can think of layers as the transformation
40// between a 3d scene graph and a 2D texture.
41struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderLayer : public QSSGRenderNode
42{
43 enum class AAMode : quint8
44 {
45 NoAA = 0,
46 SSAA,
47 MSAA,
48 ProgressiveAA
49 };
50
51 enum class AAQuality : quint8
52 {
53 Normal = 2,
54 High = 4,
55 VeryHigh = 8
56 };
57
58 enum class HorizontalField : quint8
59 {
60 LeftWidth = 0,
61 LeftRight,
62 WidthRight
63 };
64
65 enum class VerticalField : quint8
66 {
67 TopHeight = 0,
68 TopBottom,
69 HeightBottom
70 };
71
72 enum class UnitType : quint8
73 {
74 Percent = 0,
75 Pixels
76 };
77
78 enum class Background : quint8
79 {
80 Transparent = 0,
81 Unspecified,
82 Color,
83 SkyBox,
84 SkyBoxCubeMap
85 };
86
87 enum class TonemapMode : quint8
88 {
89 None = 0, // Bypass mode
90 Linear,
91 Aces,
92 HejlDawson,
93 Filmic
94 };
95
96 enum class LayerFlag
97 {
98 EnableDepthTest = 0x1,
99 EnableDepthPrePass = 0x2, ///< True when we render a depth pass before
100 RenderToTarget = 0x3 ///< Does this layer render to the normal render target,
101 };
102 Q_DECLARE_FLAGS(LayerFlags, LayerFlag)
103
104 enum class MaterialDebugMode : quint8
105 {
106 None = 0, // Bypass
107 BaseColor = 1,
108 Roughness,
109 Metalness,
110 Diffuse,
111 Specular,
112 ShadowOcclusion,
113 Emission,
114 AmbientOcclusion,
115 Normal,
116 Tangent,
117 Binormal,
118 F0
119 };
120
121 // First effect in a list of effects.
122 QSSGRenderEffect *firstEffect;
123 QSSGLayerRenderData *renderData = nullptr;
124 enum RenderExtensionMode { Underlay, Overlay, Count };
125 QList<QSSGRenderExtension *> renderExtensions[RenderExtensionMode::Count];
126
127 QSSGRenderLayer::AAMode antialiasingMode;
128 QSSGRenderLayer::AAQuality antialiasingQuality;
129
130 QSSGRenderLayer::Background background;
131 QVector3D clearColor;
132
133 // Ambient occlusion
134 float aoStrength = 0.0f;
135 float aoDistance = 5.0f;
136 float aoSoftness = 50.0f;
137 float aoBias = 0.0f;
138 qint32 aoSamplerate = 2;
139 bool aoDither = false;
140 bool aoEnabled = false;
141
142 constexpr bool ssaoEnabled() const { return aoEnabled && (aoStrength > 0.0f && aoDistance > 0.0f); }
143
144 // IBL
145 QSSGRenderImage *lightProbe;
146 float probeExposure;
147 float probeHorizon;
148 QMatrix3x3 probeOrientation;
149 QVector3D probeOrientationAngles;
150
151 QSSGRenderImage *skyBoxCubeMap = nullptr;
152
153 bool temporalAAEnabled;
154 float temporalAAStrength;
155 bool ssaaEnabled;
156 float ssaaMultiplier;
157 bool specularAAEnabled;
158
159 //TODO: move render state somewhere more suitable
160 bool temporalAAIsActive;
161 bool progressiveAAIsActive;
162 uint tempAAPassIndex;
163 uint progAAPassIndex;
164
165 // The camera explicitly set on the view by the user.
166 QSSGRenderCamera *explicitCamera;
167 // The camera used for rendering (explicitCamera, nullptr or first usable camera).
168 QSSGRenderCamera *renderedCamera;
169
170 // Tonemapping
171 TonemapMode tonemapMode;
172
173 LayerFlags layerFlags { LayerFlag::RenderToTarget,
174 LayerFlag::EnableDepthTest,
175 LayerFlag::EnableDepthPrePass };
176
177 // references to objects owned by the QSSGRhiContext
178 QRhiShaderResourceBindings *skyBoxSrb = nullptr;
179 QVarLengthArray<QRhiShaderResourceBindings *, 4> item2DSrbs;
180 bool skyBoxIsRgbe8 = false;
181
182 // Skybox
183 float skyboxBlurAmount = 0.0f;
184
185 // Grid
186 bool gridEnabled = false;
187 float gridScale = 1.0f;
188 quint32 gridFlags = 0;
189 QRhiShaderResourceBindings *gridSrb = nullptr;
190
191 // Lightmapper config
192 QSSGLightmapperOptions lmOptions;
193
194 // Scissor
195 QRect scissorRect;
196
197 // Fog
198 struct FogOptions {
199 bool enabled = false;
200 QVector3D color = QVector3D(0.5f, 0.6f, 0.7f);
201 float density = 1.0f;
202 bool depthEnabled = false;
203 float depthBegin = 10.0f;
204 float depthEnd = 1000.0f;
205 float depthCurve = 1.0f;
206 bool heightEnabled = false;
207 float heightMin = 10.0f;
208 float heightMax = 0.0f;
209 float heightCurve = 1.0f;
210 bool transmitEnabled = false;
211 float transmitCurve = 1.0f;
212 } fog;
213
214 QVector<QSSGRenderGraphObject *> resourceLoaders;
215
216 MaterialDebugMode debugMode = MaterialDebugMode::None;
217
218 bool wireframeMode = false;
219
220 QSSGRenderLayer();
221 ~QSSGRenderLayer();
222
223 void setProbeOrientation(const QVector3D &angles);
224
225 void addEffect(QSSGRenderEffect &inEffect);
226 bool hasEffect(QSSGRenderEffect *inEffect) const;
227
228 QSSGRenderNode *importSceneNode = nullptr;
229
230 // Special function(s) for importScene
231 void setImportScene(QSSGRenderNode &rootNode);
232 void removeImportScene(QSSGRenderNode &rootNode);
233
234};
235QT_END_NAMESPACE
236
237#endif
238

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