Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3ddefaultmaterial_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
6#ifndef QSSGDEFAULTMATERIAL_H
7#define QSSGDEFAULTMATERIAL_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQuick3D/private/qquick3dmaterial_p.h>
21#include <QtQuick3D/private/qquick3dtexture_p.h>
22
23#include <QColor>
24#include <QHash>
25
27
28class Q_QUICK3D_EXPORT QQuick3DDefaultMaterial : public QQuick3DMaterial
29{
30 Q_OBJECT
31 Q_PROPERTY(Lighting lighting READ lighting WRITE setLighting NOTIFY lightingChanged)
32 Q_PROPERTY(BlendMode blendMode READ blendMode WRITE setBlendMode NOTIFY blendModeChanged)
33
34 Q_PROPERTY(QColor diffuseColor READ diffuseColor WRITE setDiffuseColor NOTIFY diffuseColorChanged)
35 Q_PROPERTY(QQuick3DTexture *diffuseMap READ diffuseMap WRITE setDiffuseMap NOTIFY diffuseMapChanged)
36
37 Q_PROPERTY(QVector3D emissiveFactor READ emissiveFactor WRITE setEmissiveFactor NOTIFY emissiveFactorChanged)
38 Q_PROPERTY(QQuick3DTexture *emissiveMap READ emissiveMap WRITE setEmissiveMap NOTIFY emissiveMapChanged)
39
40 Q_PROPERTY(QQuick3DTexture *specularReflectionMap READ specularReflectionMap WRITE setSpecularReflectionMap NOTIFY specularReflectionMapChanged)
41 Q_PROPERTY(QQuick3DTexture *specularMap READ specularMap WRITE setSpecularMap NOTIFY specularMapChanged)
42 Q_PROPERTY(SpecularModel specularModel READ specularModel WRITE setSpecularModel NOTIFY specularModelChanged)
43 Q_PROPERTY(QColor specularTint READ specularTint WRITE setSpecularTint NOTIFY specularTintChanged)
44
45 Q_PROPERTY(float indexOfRefraction READ indexOfRefraction WRITE setIndexOfRefraction NOTIFY indexOfRefractionChanged)
46 Q_PROPERTY(float fresnelPower READ fresnelPower WRITE setFresnelPower NOTIFY fresnelPowerChanged)
47 Q_PROPERTY(float specularAmount READ specularAmount WRITE setSpecularAmount NOTIFY specularAmountChanged)
48 Q_PROPERTY(float specularRoughness READ specularRoughness WRITE setSpecularRoughness NOTIFY specularRoughnessChanged)
49 Q_PROPERTY(QQuick3DTexture *roughnessMap READ roughnessMap WRITE setRoughnessMap NOTIFY roughnessMapChanged)
50 Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping roughnessChannel READ roughnessChannel WRITE setRoughnessChannel NOTIFY roughnessChannelChanged)
51
52 Q_PROPERTY(float opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
53 Q_PROPERTY(QQuick3DTexture *opacityMap READ opacityMap WRITE setOpacityMap NOTIFY opacityMapChanged)
54 Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping opacityChannel READ opacityChannel WRITE setOpacityChannel NOTIFY opacityChannelChanged)
55
56 Q_PROPERTY(QQuick3DTexture *bumpMap READ bumpMap WRITE setBumpMap NOTIFY bumpMapChanged)
57 Q_PROPERTY(float bumpAmount READ bumpAmount WRITE setBumpAmount NOTIFY bumpAmountChanged)
58
59 Q_PROPERTY(QQuick3DTexture *normalMap READ normalMap WRITE setNormalMap NOTIFY normalMapChanged)
60
61 Q_PROPERTY(QQuick3DTexture *translucencyMap READ translucencyMap WRITE setTranslucencyMap NOTIFY translucencyMapChanged)
62 Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping translucencyChannel READ translucencyChannel WRITE setTranslucencyChannel NOTIFY translucencyChannelChanged)
63 Q_PROPERTY(float translucentFalloff READ translucentFalloff WRITE setTranslucentFalloff NOTIFY translucentFalloffChanged)
64
65 Q_PROPERTY(float diffuseLightWrap READ diffuseLightWrap WRITE setDiffuseLightWrap NOTIFY diffuseLightWrapChanged)
66
67 Q_PROPERTY(bool vertexColorsEnabled READ vertexColorsEnabled WRITE setVertexColorsEnabled NOTIFY vertexColorsEnabledChanged)
68
69 Q_PROPERTY(float pointSize READ pointSize WRITE setPointSize NOTIFY pointSizeChanged)
70 Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth NOTIFY lineWidthChanged)
71
72 QML_NAMED_ELEMENT(DefaultMaterial)
73
74public:
75 enum Lighting { NoLighting = 0, FragmentLighting };
76 Q_ENUM(Lighting)
77
78 enum BlendMode { SourceOver = 0, Screen, Multiply };
79 Q_ENUM(BlendMode)
80
81 enum SpecularModel { Default = 0, KGGX };
82 Q_ENUM(SpecularModel)
83
84 explicit QQuick3DDefaultMaterial(QQuick3DObject *parent = nullptr);
85 ~QQuick3DDefaultMaterial() override;
86
87 Lighting lighting() const;
88 BlendMode blendMode() const;
89 QColor diffuseColor() const;
90 QQuick3DTexture *diffuseMap() const;
91 QVector3D emissiveFactor() const;
92 QQuick3DTexture *emissiveMap() const;
93 QQuick3DTexture *specularReflectionMap() const;
94 QQuick3DTexture *specularMap() const;
95 SpecularModel specularModel() const;
96 QColor specularTint() const;
97 float indexOfRefraction() const;
98 float fresnelPower() const;
99 float specularAmount() const;
100 float specularRoughness() const;
101 QQuick3DTexture *roughnessMap() const;
102 float opacity() const;
103 QQuick3DTexture *opacityMap() const;
104 QQuick3DTexture *bumpMap() const;
105 float bumpAmount() const;
106 QQuick3DTexture *normalMap() const;
107
108 QQuick3DTexture *translucencyMap() const;
109 float translucentFalloff() const;
110 float diffuseLightWrap() const;
111 bool vertexColorsEnabled() const;
112 TextureChannelMapping roughnessChannel() const;
113 TextureChannelMapping opacityChannel() const;
114 TextureChannelMapping translucencyChannel() const;
115
116 float pointSize() const;
117 float lineWidth() const;
118
119public Q_SLOTS:
120
121 void setLighting(QQuick3DDefaultMaterial::Lighting lighting);
122 void setBlendMode(QQuick3DDefaultMaterial::BlendMode blendMode);
123 void setDiffuseColor(QColor diffuseColor);
124 void setDiffuseMap(QQuick3DTexture *diffuseMap);
125 void setEmissiveFactor(QVector3D emissiveFactor);
126 void setEmissiveMap(QQuick3DTexture *emissiveMap);
127
128 void setSpecularReflectionMap(QQuick3DTexture *specularReflectionMap);
129 void setSpecularMap(QQuick3DTexture *specularMap);
130 void setSpecularModel(QQuick3DDefaultMaterial::SpecularModel specularModel);
131 void setSpecularTint(QColor specularTint);
132 void setIndexOfRefraction(float indexOfRefraction);
133 void setFresnelPower(float fresnelPower);
134 void setSpecularAmount(float specularAmount);
135 void setSpecularRoughness(float specularRoughness);
136 void setRoughnessMap(QQuick3DTexture *roughnessMap);
137 void setOpacity(float opacity);
138 void setOpacityMap(QQuick3DTexture *opacityMap);
139 void setBumpMap(QQuick3DTexture *bumpMap);
140 void setBumpAmount(float bumpAmount);
141 void setNormalMap(QQuick3DTexture *normalMap);
142
143 void setTranslucencyMap(QQuick3DTexture *translucencyMap);
144 void setTranslucentFalloff(float translucentFalloff);
145 void setDiffuseLightWrap(float diffuseLightWrap);
146 void setVertexColorsEnabled(bool vertexColorsEnabled);
147
148 void setRoughnessChannel(QQuick3DMaterial::TextureChannelMapping channel);
149 void setOpacityChannel(QQuick3DMaterial::TextureChannelMapping channel);
150 void setTranslucencyChannel(QQuick3DMaterial::TextureChannelMapping channel);
151
152 void setPointSize(float size);
153 void setLineWidth(float width);
154
155Q_SIGNALS:
156 void lightingChanged(QQuick3DDefaultMaterial::Lighting lighting);
157 void blendModeChanged(QQuick3DDefaultMaterial::BlendMode blendMode);
158 void diffuseColorChanged(QColor diffuseColor);
159 void diffuseMapChanged(QQuick3DTexture *diffuseMap);
160 void emissiveFactorChanged(QVector3D emissiveFactor);
161 void emissiveMapChanged(QQuick3DTexture *emissiveMap);
162 void specularReflectionMapChanged(QQuick3DTexture *specularReflectionMap);
163 void specularMapChanged(QQuick3DTexture *specularMap);
164 void specularModelChanged(QQuick3DDefaultMaterial::SpecularModel specularModel);
165 void specularTintChanged(QColor specularTint);
166 void indexOfRefractionChanged(float indexOfRefraction);
167 void fresnelPowerChanged(float fresnelPower);
168 void specularAmountChanged(float specularAmount);
169 void specularRoughnessChanged(float specularRoughness);
170 void roughnessMapChanged(QQuick3DTexture *roughnessMap);
171 void opacityChanged(float opacity);
172 void opacityMapChanged(QQuick3DTexture *opacityMap);
173 void bumpMapChanged(QQuick3DTexture *bumpMap);
174 void bumpAmountChanged(float bumpAmount);
175 void normalMapChanged(QQuick3DTexture *normalMap);
176 void translucencyMapChanged(QQuick3DTexture *translucencyMap);
177 void translucentFalloffChanged(float translucentFalloff);
178 void diffuseLightWrapChanged(float diffuseLightWrap);
179 void vertexColorsEnabledChanged(bool vertexColorsEnabled);
180 void roughnessChannelChanged(QQuick3DMaterial::TextureChannelMapping channel);
181 void opacityChannelChanged(QQuick3DMaterial::TextureChannelMapping channel);
182 void translucencyChannelChanged(QQuick3DMaterial::TextureChannelMapping channel);
183 void pointSizeChanged();
184 void lineWidthChanged();
185
186protected:
187 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
188 void markAllDirty() override;
189 void itemChange(ItemChange, const ItemChangeData &) override;
190private:
191 enum DirtyType {
192 LightingModeDirty = 0x00000001,
193 BlendModeDirty = 0x00000002,
194 DiffuseDirty = 0x00000004,
195 EmissiveDirty = 0x00000008,
196 SpecularDirty = 0x00000010,
197 OpacityDirty = 0x00000020,
198 BumpDirty = 0x00000040,
199 NormalDirty = 0x00000080,
200 TranslucencyDirty = 0x00000100,
201 VertexColorsDirty = 0x00000200,
202 PointSizeDirty = 0x00000400,
203 LineWidthDirty = 0x00000800
204 };
205
206 void updateSceneManager(QQuick3DSceneManager *sceneManager);
207 Lighting m_lighting = FragmentLighting;
208 BlendMode m_blendMode = SourceOver;
209 QColor m_diffuseColor;
210 QQuick3DTexture *m_diffuseMap = nullptr;
211 QVector3D m_emissiveFactor;
212 QQuick3DTexture *m_emissiveMap = nullptr;
213
214 QQuick3DTexture *m_specularReflectionMap = nullptr;
215 QQuick3DTexture *m_specularMap = nullptr;
216 SpecularModel m_specularModel = Default;
217 QColor m_specularTint;
218 float m_indexOfRefraction = 1.45f;
219 float m_fresnelPower = 0.0f;
220 float m_specularAmount = 0.0f;
221 float m_specularRoughness = 0.0f;
222 QQuick3DTexture *m_roughnessMap = nullptr;
223 float m_opacity = 1.0f;
224 QQuick3DTexture *m_opacityMap = nullptr;
225 QQuick3DTexture *m_bumpMap = nullptr;
226 float m_bumpAmount = 0.0f;
227 QQuick3DTexture *m_normalMap = nullptr;
228
229 QQuick3DTexture *m_translucencyMap = nullptr;
230 float m_translucentFalloff = 0.0f;
231 float m_diffuseLightWrap = 0.0f;
232 bool m_vertexColorsEnabled = false;
233
234 TextureChannelMapping m_roughnessChannel = QQuick3DMaterial::R;
235 TextureChannelMapping m_opacityChannel = QQuick3DMaterial::A;
236 TextureChannelMapping m_translucencyChannel = QQuick3DMaterial::A;
237
238 float m_pointSize = 1.0f;
239 float m_lineWidth = 1.0f;
240
241 quint32 m_dirtyAttributes = 0xffffffff; // all dirty by default
242 void markDirty(DirtyType type);
243};
244
245QT_END_NAMESPACE
246
247#endif // QSSGDEFAULTMATERIAL_H
Combined button and popup list for selecting options.