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 Object
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
154QT_END_NAMESPACE
155
156

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