1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qquick3ddebugsettings_p.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \qmltype DebugSettings
10 \inherits QtObject
11 \inqmlmodule QtQuick3D
12 \brief Used to configure debug settings.
13
14 The renderer can be configured to output many different views to facilitate
15 debugging. This component is used to configure these debug views.
16
17 In addition to programatic control, properties such as \l materialOverride
18 and \l wireframeEnabled can also be controlled interactively via the \l
19 DebugView item if an instance of that is added to the Qt Quick scene by the
20 application.
21*/
22
23/*!
24 \qmlproperty enumeration QtQuick3D::DebugSettings::materialOverride
25 \since 6.5
26
27 This property changes how all materials are rendered to only reflect a
28 particular aspect of the overall rendering process. This can be used as
29 a debugging tool to get a better understanding of why a material looks
30 the way it does.
31
32 The default value is \c DebugSettings.None
33
34 \value DebugSettings.None
35 Material overriding is bypassed, rendering occurs as normal.
36 \value DebugSettings.BaseColor
37 The BaseColor or Diffuse color of a material is passed through
38 without any lighting.
39 \value DebugSettings.Roughness
40 The Roughness of a material is passed through as an unlit
41 greyscale value.
42 \value DebugSettings.Metalness
43 The Metalness of a material is passed through as an unlit
44 greyscale value.
45 \value DebugSettings.Diffuse
46 Only the diffuse contribution of the material after all lighting.
47 \value DebugSettings.Specular
48 Only the specular contribution of the material after all lighting.
49 \value DebugSettings.ShadowOcclusion
50 The Occlusion caused by shadows as a greyscale value.
51 \value DebugSettings.Emission
52 Only the emissive contribution of the material
53 \value DebugSettings.AmbientOcclusion
54 Only the Ambient Occlusion of the material
55 \value DebugSettings.Normals
56 The interpolated world space Normal value of the material mapped to an
57 RGB color.
58 \value DebugSettings.Tangents
59 The interpolated world space Tangent value of the material mapped to an
60 RGB color. This will only be visible if the Tangent value is used.
61 \value DebugSettings.Binormals
62 The interpolated world space Binormal value of the material mapped to an
63 RGB color. This will only be visible if the Binormal value is used.
64 \value DebugSettings.F0
65 This represents the Fresnel Reflectance at 0 Degrees. This will only be
66 visible for materials that calculate an F0 value.
67
68 As an example, take the following scene with the
69 \l{https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Sponza}{Sponza}
70 model. The scene uses image-based lighting via
71 \l{SceneEnvironment::lightProbe} and also has a directional light.
72
73 \image debugsettings_default.jpg
74
75 Setting \c{DebugSettings.BaseColor}:
76
77 \image debugsettings_basecolor.jpg
78
79 Setting \c{DebugSettings.Roughness}:
80
81 \image debugsettings_roughness.jpg
82
83 Setting \c{DebugSettings.Metalness}:
84
85 \image debugsettings_metalness.jpg
86
87 Setting \c{DebugSettings.Diffuse}:
88
89 \image debugsettings_diffuse.jpg
90
91 Setting \c{DebugSettings.Specular}:
92
93 \image debugsettings_specular.jpg
94
95 Setting \c{DebugSettings.Normals}:
96
97 \image debugsettings_normals.jpg
98*/
99
100
101QQuick3DDebugSettings::QQuick3DDebugSettings(QObject *parent)
102 : QObject(parent)
103{
104
105}
106
107QQuick3DDebugSettings::QQuick3DMaterialOverrides QQuick3DDebugSettings::materialOverride() const
108{
109 return m_materialOverride;
110}
111
112void QQuick3DDebugSettings::setMaterialOverride(QQuick3DMaterialOverrides newMaterialOverride)
113{
114 if (m_materialOverride == newMaterialOverride)
115 return;
116 m_materialOverride = newMaterialOverride;
117 emit materialOverrideChanged();
118 update();
119}
120
121void QQuick3DDebugSettings::update()
122{
123 emit changed();
124}
125
126/*!
127 \qmlproperty bool QtQuick3D::DebugSettings::wireframeEnabled
128 \since 6.5
129
130 This property changes how all materials are rendered by changing the polygon
131 fill mode to be lines instead of filled. This appears as a wireframe, but the
132 shaded color will still reflect the respective materials of the meshes.
133
134 The default value is \c false.
135
136 \image debugsettings_wireframe.jpg
137*/
138
139
140bool QQuick3DDebugSettings::wireframeEnabled() const
141{
142 return m_wireframeEnabled;
143}
144
145void QQuick3DDebugSettings::setWireframeEnabled(bool newWireframeEnabled)
146{
147 if (m_wireframeEnabled == newWireframeEnabled)
148 return;
149 m_wireframeEnabled = newWireframeEnabled;
150 emit wireframeEnabledChanged();
151 update();
152}
153
154/*!
155 \qmlproperty bool QtQuick3D::DebugSettings::drawDirectionalLightShadowBoxes
156 \since 6.8
157
158 When this property is enabled a bounding box is drawn for every directional light's shadowmap.
159
160 The default value is \c false.
161*/
162
163bool QQuick3DDebugSettings::drawDirectionalLightShadowBoxes() const
164{
165 return m_drawDirectionalLightShadowBoxes;
166}
167
168void QQuick3DDebugSettings::setDrawDirectionalLightShadowBoxes(bool newDrawDirectionalLightShadowBoxes)
169{
170 if (m_drawDirectionalLightShadowBoxes == newDrawDirectionalLightShadowBoxes)
171 return;
172 m_drawDirectionalLightShadowBoxes = newDrawDirectionalLightShadowBoxes;
173 emit drawDirectionalLightShadowBoxesChanged();
174 update();
175}
176
177/*!
178 \qmlproperty bool QtQuick3D::DebugSettings::drawShadowCastingBounds
179 \since 6.8
180
181 When this property is enabled a bounding box is drawn for the shadow casting objects.
182
183 The default value is \c false.
184*/
185
186bool QQuick3DDebugSettings::drawShadowCastingBounds() const
187{
188 return m_drawShadowCastingBounds;
189}
190
191void QQuick3DDebugSettings::setDrawShadowCastingBounds(bool newDrawShadowCastingBounds)
192{
193 if (m_drawShadowCastingBounds == newDrawShadowCastingBounds)
194 return;
195 m_drawShadowCastingBounds = newDrawShadowCastingBounds;
196 emit drawShadowCastingBoundsChanged();
197 update();
198}
199
200/*!
201 \qmlproperty bool QtQuick3D::DebugSettings::drawShadowReceivingBounds
202 \since 6.8
203
204 When this property is enabled a bounding box is drawn for the shadow receiving objects.
205
206 The default value is \c false.
207*/
208
209bool QQuick3DDebugSettings::drawShadowReceivingBounds() const
210{
211 return m_drawShadowReceivingBounds;
212}
213
214void QQuick3DDebugSettings::setDrawShadowReceivingBounds(bool newDrawShadowReceivingBounds)
215{
216 if (m_drawShadowReceivingBounds == newDrawShadowReceivingBounds)
217 return;
218 m_drawShadowReceivingBounds = newDrawShadowReceivingBounds;
219 emit drawShadowReceivingBoundsChanged();
220 update();
221}
222
223/*!
224 \qmlproperty bool QtQuick3D::DebugSettings::drawCascades
225 \since 6.8
226
227 When this property is enabled a frustum is drawn with splits indicating where the
228 shadowmap cascades begin and end.
229
230 The default value is \c false.
231*/
232
233bool QQuick3DDebugSettings::drawCascades() const
234{
235 return m_drawCascades;
236}
237
238void QQuick3DDebugSettings::setDrawCascades(bool newDrawCascades)
239{
240 if (m_drawCascades == newDrawCascades)
241 return;
242 m_drawCascades = newDrawCascades;
243 emit drawCascadesChanged();
244 update();
245}
246
247/*!
248 \qmlproperty bool QtQuick3D::DebugSettings::drawSceneCascadeIntersection
249 \since 6.8
250
251 When this property is enabled the intersection of the shadowmap cascades
252 and the casting and receiving objects of the scene is drawn.
253
254 The default value is \c false.
255*/
256
257bool QQuick3DDebugSettings::drawSceneCascadeIntersection() const
258{
259 return m_drawSceneCascadeIntersection;
260}
261
262void QQuick3DDebugSettings::setDrawSceneCascadeIntersection(bool newDrawSceneCascadeIntersection)
263{
264 if (m_drawSceneCascadeIntersection == newDrawSceneCascadeIntersection)
265 return;
266 m_drawSceneCascadeIntersection = newDrawSceneCascadeIntersection;
267 emit drawSceneCascadeIntersectionChanged();
268 update();
269}
270
271/*!
272 \qmlproperty bool QtQuick3D::DebugSettings::disableShadowCameraUpdate
273 \since 6.8
274
275 When this property is enabled the camera update is disabled for the shadowmap.
276 This means that the view frustum will be locked in space just for the shadowmap
277 calculations. This is just a debug tool to be able to view the camera frustum
278 and shadow map from different angles.
279
280 The default value is \c false.
281*/
282
283bool QQuick3DDebugSettings::disableShadowCameraUpdate() const
284{
285 return m_disableShadowCameraUpdate;
286}
287
288void QQuick3DDebugSettings::setDisableShadowCameraUpdate(bool newDisableShadowCameraUpdate)
289{
290 if (m_disableShadowCameraUpdate == newDisableShadowCameraUpdate)
291 return;
292 m_disableShadowCameraUpdate = newDisableShadowCameraUpdate;
293 emit disableShadowCameraUpdateChanged();
294 update();
295}
296
297QT_END_NAMESPACE
298
299

source code of qtquick3d/src/quick3d/qquick3ddebugsettings.cpp