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