aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick3d/qquick3ddebugsettings.cpp
blob: 52d540f1960d2b10c4a241b61b72a981b7c9a629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "qquick3ddebugsettings_p.h"

QT_BEGIN_NAMESPACE

/*!
    \qmltype DebugSettings
    \inherits QtObject
    \inqmlmodule QtQuick3D
    \brief Used to configure debug settings.

    The renderer can be configured to output many different views to facilitate
    debugging. This component is used to configure these debug views.

    In addition to programatic control, properties such as \l materialOverride
    and \l wireframeEnabled can also be controlled interactively via the \l
    DebugView item if an instance of that is added to the Qt Quick scene by the
    application.
*/

/*!
    \qmlproperty enumeration QtQuick3D::DebugSettings::materialOverride
    \since 6.5

    This property changes how all materials are rendered to only reflect a
    particular aspect of the overall rendering process. This can be used as
    a debugging tool to get a better understanding of why a material looks
    the way it does.

    The default value is \c DebugSettings.None

    \value DebugSettings.None
        Material overriding is bypassed, rendering occurs as normal.
    \value DebugSettings.BaseColor
        The BaseColor or Diffuse color of a material is passed through
        without any lighting.
    \value DebugSettings.Roughness
        The Roughness of a material is passed through as an unlit
        greyscale value.
    \value DebugSettings.Metalness
        The Metalness of a material is passed through as an unlit
        greyscale value.
    \value DebugSettings.Diffuse
        Only the diffuse contribution of the material after all lighting.
    \value DebugSettings.Specular
        Only the specular contribution of the material after all lighting.
    \value DebugSettings.ShadowOcclusion
        The Occlusion caused by shadows as a greyscale value.
    \value DebugSettings.Emission
        Only the emissive contribution of the material
    \value DebugSettings.AmbientOcclusion
        Only the Ambient Occlusion of the material
    \value DebugSettings.Normals
        The interpolated world space Normal value of the material mapped to an
        RGB color.
    \value DebugSettings.Tangents
        The interpolated world space Tangent value of the material mapped to an
        RGB color. This will only be visible if the Tangent value is used.
    \value DebugSettings.Binormals
        The interpolated world space Binormal value of the material mapped to an
        RGB color. This will only be visible if the Binormal value is used.
    \value DebugSettings.F0
        This represents the Fresnel Reflectance at 0 Degrees. This will only be
        visible for materials that calculate an F0 value.

    As an example, take the following scene with the
    \l{https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Sponza}{Sponza}
    model. The scene uses image-based lighting via
    \l{SceneEnvironment::lightProbe} and also has a directional light.

    \image debugsettings_default.jpg

    Setting \c{DebugSettings.BaseColor}:

    \image debugsettings_basecolor.jpg

    Setting \c{DebugSettings.Roughness}:

    \image debugsettings_roughness.jpg

    Setting \c{DebugSettings.Metalness}:

    \image debugsettings_metalness.jpg

    Setting \c{DebugSettings.Diffuse}:

    \image debugsettings_diffuse.jpg

    Setting \c{DebugSettings.Specular}:

    \image debugsettings_specular.jpg

    Setting \c{DebugSettings.Normals}:

    \image debugsettings_normals.jpg
*/


QQuick3DDebugSettings::QQuick3DDebugSettings(QObject *parent)
    : QObject(parent)
{

}

QQuick3DDebugSettings::QQuick3DMaterialOverrides QQuick3DDebugSettings::materialOverride() const
{
    return m_materialOverride;
}

void QQuick3DDebugSettings::setMaterialOverride(QQuick3DMaterialOverrides newMaterialOverride)
{
    if (m_materialOverride == newMaterialOverride)
        return;
    m_materialOverride = newMaterialOverride;
    emit materialOverrideChanged();
    update();
}

void QQuick3DDebugSettings::update()
{
    emit changed();
}

/*!
    \qmlproperty bool QtQuick3D::DebugSettings::wireframeEnabled
    \since 6.5

    This property changes how all materials are rendered by changing the polygon
    fill mode to be lines instead of filled. This appears as a wireframe, but the
    shaded color will still reflect the respective materials of the meshes.

    The default value is \c false.

    \image debugsettings_wireframe.jpg
*/


bool QQuick3DDebugSettings::wireframeEnabled() const
{
    return m_wireframeEnabled;
}

void QQuick3DDebugSettings::setWireframeEnabled(bool newWireframeEnabled)
{
    if (m_wireframeEnabled == newWireframeEnabled)
        return;
    m_wireframeEnabled = newWireframeEnabled;
    emit wireframeEnabledChanged();
    update();
}

/*!
    \qmlproperty bool QtQuick3D::DebugSettings::drawDirectionalLightShadowBoxes
    \since 6.8

    When this property is enabled a bounding box is drawn for every directional light's shadowmap.

    The default value is \c false.
*/

bool QQuick3DDebugSettings::drawDirectionalLightShadowBoxes() const
{
    return m_drawDirectionalLightShadowBoxes;
}

void QQuick3DDebugSettings::setDrawDirectionalLightShadowBoxes(bool newDrawDirectionalLightShadowBoxes)
{
    if (m_drawDirectionalLightShadowBoxes == newDrawDirectionalLightShadowBoxes)
        return;
    m_drawDirectionalLightShadowBoxes = newDrawDirectionalLightShadowBoxes;
    emit drawDirectionalLightShadowBoxesChanged();
    update();
}

/*!
    \qmlproperty bool QtQuick3D::DebugSettings::drawShadowCastingBounds
    \since 6.8

    When this property is enabled a bounding box is drawn for the shadow casting objects.

    The default value is \c false.
*/

bool QQuick3DDebugSettings::drawShadowCastingBounds() const
{
    return m_drawShadowCastingBounds;
}

void QQuick3DDebugSettings::setDrawShadowCastingBounds(bool newDrawShadowCastingBounds)
{
    if (m_drawShadowCastingBounds == newDrawShadowCastingBounds)
        return;
    m_drawShadowCastingBounds = newDrawShadowCastingBounds;
    emit drawShadowCastingBoundsChanged();
    update();
}

/*!
    \qmlproperty bool QtQuick3D::DebugSettings::drawPointLightShadowBoxes
    \since 6.9

    When this property is enabled a bounding box is drawn for every point light's shadowmap.

    The default value is \c false.
*/

bool QQuick3DDebugSettings::drawPointLightShadowBoxes() const
{
    return m_drawPointLightShadowBoxes;
}

void QQuick3DDebugSettings::setDrawPointLightShadowBoxes(bool newDrawPointLightShadowBoxes)
{
    if (m_drawPointLightShadowBoxes == newDrawPointLightShadowBoxes)
        return;
    m_drawPointLightShadowBoxes = newDrawPointLightShadowBoxes;
    emit drawPointLightShadowBoxesChanged();
    update();
}

/*!
    \qmlproperty bool QtQuick3D::DebugSettings::drawShadowReceivingBounds
    \since 6.8

    When this property is enabled a bounding box is drawn for the shadow receiving objects.

    The default value is \c false.
*/

bool QQuick3DDebugSettings::drawShadowReceivingBounds() const
{
    return m_drawShadowReceivingBounds;
}

void QQuick3DDebugSettings::setDrawShadowReceivingBounds(bool newDrawShadowReceivingBounds)
{
    if (m_drawShadowReceivingBounds == newDrawShadowReceivingBounds)
        return;
    m_drawShadowReceivingBounds = newDrawShadowReceivingBounds;
    emit drawShadowReceivingBoundsChanged();
    update();
}

/*!
    \qmlproperty bool QtQuick3D::DebugSettings::drawCascades
    \since 6.8

    When this property is enabled a frustum is drawn with splits indicating where the
    shadowmap cascades begin and end.

    The default value is \c false.
*/

bool QQuick3DDebugSettings::drawCascades() const
{
    return m_drawCascades;
}

void QQuick3DDebugSettings::setDrawCascades(bool newDrawCascades)
{
    if (m_drawCascades == newDrawCascades)
        return;
    m_drawCascades = newDrawCascades;
    emit drawCascadesChanged();
    update();
}

/*!
    \qmlproperty bool QtQuick3D::DebugSettings::drawSceneCascadeIntersection
    \since 6.8

    When this property is enabled the intersection of the shadowmap cascades
    and the casting and receiving objects of the scene is drawn.

    The default value is \c false.
*/

bool QQuick3DDebugSettings::drawSceneCascadeIntersection() const
{
    return m_drawSceneCascadeIntersection;
}

void QQuick3DDebugSettings::setDrawSceneCascadeIntersection(bool newDrawSceneCascadeIntersection)
{
    if (m_drawSceneCascadeIntersection == newDrawSceneCascadeIntersection)
        return;
    m_drawSceneCascadeIntersection = newDrawSceneCascadeIntersection;
    emit drawSceneCascadeIntersectionChanged();
    update();
}

/*!
    \qmlproperty bool QtQuick3D::DebugSettings::disableShadowCameraUpdate
    \since 6.8

    When this property is enabled the camera update is disabled for the shadowmap.
    This means that the view frustum will be locked in space just for the shadowmap
    calculations. This is just a debug tool to be able to view the camera frustum
    and shadow map from different angles.

    The default value is \c false.
*/

bool QQuick3DDebugSettings::disableShadowCameraUpdate() const
{
    return m_disableShadowCameraUpdate;
}

void QQuick3DDebugSettings::setDisableShadowCameraUpdate(bool newDisableShadowCameraUpdate)
{
    if (m_disableShadowCameraUpdate == newDisableShadowCameraUpdate)
        return;
    m_disableShadowCameraUpdate = newDisableShadowCameraUpdate;
    emit disableShadowCameraUpdateChanged();
    update();
}

QT_END_NAMESPACE