1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICK3DSPECULARGLOSSYMATERIAL_P_H |
5 | #define QQUICK3DSPECULARGLOSSYMATERIAL_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version toSpecularGlossyMaterial |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtQuick3D/private/qquick3dmaterial_p.h> |
19 | #include <QtQuick3D/private/qquick3dtexture_p.h> |
20 | |
21 | #include <QColor> |
22 | #include <QHash> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class Q_QUICK3D_EXPORT QQuick3DSpecularGlossyMaterial : public QQuick3DMaterial |
27 | { |
28 | Q_OBJECT |
29 | Q_PROPERTY(Lighting lighting READ lighting WRITE setLighting NOTIFY lightingChanged) |
30 | Q_PROPERTY(BlendMode blendMode READ blendMode WRITE setBlendMode NOTIFY blendModeChanged) |
31 | |
32 | Q_PROPERTY(QColor albedoColor READ albedoColor WRITE setAlbedoColor NOTIFY albedoColorChanged) |
33 | Q_PROPERTY(QQuick3DTexture *albedoMap READ albedoMap WRITE setAlbedoMap NOTIFY albedoMapChanged) |
34 | |
35 | Q_PROPERTY(QColor specularColor READ specularColor WRITE setSpecularColor NOTIFY specularColorChanged) |
36 | Q_PROPERTY(QQuick3DTexture *specularMap READ specularMap WRITE setSpecularMap NOTIFY specularMapChanged) |
37 | |
38 | Q_PROPERTY(float glossiness READ glossiness WRITE setGlossiness NOTIFY glossinessChanged) |
39 | Q_PROPERTY(QQuick3DTexture *glossinessMap READ glossinessMap WRITE setGlossinessMap NOTIFY glossinessMapChanged) |
40 | Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping glossinessChannel READ glossinessChannel WRITE setGlossinessChannel NOTIFY glossinessChannelChanged) |
41 | |
42 | Q_PROPERTY(QVector3D emissiveFactor READ emissiveFactor WRITE setEmissiveFactor NOTIFY emissiveFactorChanged) |
43 | Q_PROPERTY(QQuick3DTexture *emissiveMap READ emissiveMap WRITE setEmissiveMap NOTIFY emissiveMapChanged) |
44 | |
45 | Q_PROPERTY(float opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) |
46 | Q_PROPERTY(QQuick3DTexture *opacityMap READ opacityMap WRITE setOpacityMap NOTIFY opacityMapChanged) |
47 | Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping opacityChannel READ opacityChannel WRITE setOpacityChannel NOTIFY opacityChannelChanged) |
48 | |
49 | Q_PROPERTY(QQuick3DTexture *normalMap READ normalMap WRITE setNormalMap NOTIFY normalMapChanged) |
50 | Q_PROPERTY(float normalStrength READ normalStrength WRITE setNormalStrength NOTIFY normalStrengthChanged) |
51 | |
52 | Q_PROPERTY(QQuick3DTexture *occlusionMap READ occlusionMap WRITE setOcclusionMap NOTIFY occlusionMapChanged) |
53 | Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping occlusionChannel READ occlusionChannel WRITE setOcclusionChannel NOTIFY occlusionChannelChanged) |
54 | Q_PROPERTY(float occlusionAmount READ occlusionAmount WRITE setOcclusionAmount NOTIFY occlusionAmountChanged) |
55 | |
56 | Q_PROPERTY(AlphaMode alphaMode READ alphaMode WRITE setAlphaMode NOTIFY alphaModeChanged) |
57 | Q_PROPERTY(float alphaCutoff READ alphaCutoff WRITE setAlphaCutoff NOTIFY alphaCutoffChanged) |
58 | |
59 | Q_PROPERTY(float pointSize READ pointSize WRITE setPointSize NOTIFY pointSizeChanged) |
60 | Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth NOTIFY lineWidthChanged) |
61 | |
62 | Q_PROPERTY(QQuick3DTexture *heightMap READ heightMap WRITE setHeightMap NOTIFY heightMapChanged) |
63 | Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping heightChannel READ heightChannel WRITE setHeightChannel NOTIFY heightChannelChanged) |
64 | Q_PROPERTY(float heightAmount READ heightAmount WRITE setHeightAmount NOTIFY heightAmountChanged) |
65 | Q_PROPERTY(int minHeightMapSamples READ minHeightMapSamples WRITE setMinHeightMapSamples NOTIFY minHeightMapSamplesChanged) |
66 | Q_PROPERTY(int maxHeightMapSamples READ maxHeightMapSamples WRITE setMaxHeightMapSamples NOTIFY maxHeightMapSamplesChanged) |
67 | |
68 | Q_PROPERTY(float clearcoatAmount READ clearcoatAmount WRITE setClearcoatAmount NOTIFY clearcoatAmountChanged) |
69 | Q_PROPERTY(QQuick3DTexture *clearcoatMap READ clearcoatMap WRITE setClearcoatMap NOTIFY clearcoatMapChanged) |
70 | Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping clearcoatChannel READ clearcoatChannel WRITE setClearcoatChannel NOTIFY |
71 | clearcoatChannelChanged) |
72 | Q_PROPERTY(float clearcoatRoughnessAmount READ clearcoatRoughnessAmount WRITE setClearcoatRoughnessAmount NOTIFY |
73 | clearcoatRoughnessAmountChanged) |
74 | Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping clearcoatRoughnessChannel READ clearcoatRoughnessChannel WRITE |
75 | setClearcoatRoughnessChannel NOTIFY clearcoatRoughnessChannelChanged) |
76 | Q_PROPERTY(QQuick3DTexture *clearcoatRoughnessMap READ clearcoatRoughnessMap WRITE setClearcoatRoughnessMap NOTIFY |
77 | clearcoatRoughnessMapChanged) |
78 | Q_PROPERTY(QQuick3DTexture *clearcoatNormalMap READ clearcoatNormalMap WRITE setClearcoatNormalMap NOTIFY |
79 | clearcoatNormalMapChanged) |
80 | |
81 | Q_PROPERTY(float transmissionFactor READ transmissionFactor WRITE setTransmissionFactor NOTIFY transmissionFactorChanged) |
82 | Q_PROPERTY(QQuick3DTexture * transmissionMap READ transmissionMap WRITE setTransmissionMap NOTIFY transmissionMapChanged) |
83 | Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping transmissionChannel READ transmissionChannel WRITE setTransmissionChannel NOTIFY transmissionChannelChanged) |
84 | |
85 | Q_PROPERTY(float thicknessFactor READ thicknessFactor WRITE setThicknessFactor NOTIFY thicknessFactorChanged) |
86 | Q_PROPERTY(QQuick3DTexture *thicknessMap READ thicknessMap WRITE setThicknessMap NOTIFY thicknessMapChanged) |
87 | Q_PROPERTY(QQuick3DMaterial::TextureChannelMapping thicknessChannel READ thicknessChannel WRITE setThicknessChannel NOTIFY |
88 | thicknessChannelChanged) |
89 | Q_PROPERTY(float attenuationDistance READ attenuationDistance WRITE setAttenuationDistance NOTIFY attenuationDistanceChanged) |
90 | Q_PROPERTY(QColor attenuationColor READ attenuationColor WRITE setAttenuationColor NOTIFY attenuationColorChanged) |
91 | |
92 | Q_PROPERTY(bool vertexColorsEnabled READ vertexColorsEnabled WRITE setVertexColorsEnabled NOTIFY vertexColorsEnabledChanged REVISION(6, 5)) |
93 | |
94 | QML_NAMED_ELEMENT(SpecularGlossyMaterial) |
95 | QML_ADDED_IN_VERSION(6, 4) |
96 | |
97 | public: |
98 | enum Lighting { |
99 | NoLighting = 0, |
100 | FragmentLighting |
101 | }; |
102 | Q_ENUM(Lighting) |
103 | |
104 | enum BlendMode { |
105 | SourceOver = 0, |
106 | Screen, |
107 | Multiply |
108 | }; |
109 | Q_ENUM(BlendMode) |
110 | |
111 | enum AlphaMode { |
112 | Default = 0, |
113 | Mask, |
114 | Blend, |
115 | Opaque |
116 | }; |
117 | Q_ENUM(AlphaMode) |
118 | |
119 | explicit QQuick3DSpecularGlossyMaterial(QQuick3DObject *parent = nullptr); |
120 | ~QQuick3DSpecularGlossyMaterial() override; |
121 | |
122 | Lighting lighting() const; |
123 | BlendMode blendMode() const; |
124 | QColor albedoColor() const; |
125 | QQuick3DTexture *albedoMap() const; |
126 | QQuick3DTexture *emissiveMap() const; |
127 | QVector3D emissiveFactor() const; |
128 | float glossiness() const; |
129 | QQuick3DTexture *glossinessMap() const; |
130 | float opacity() const; |
131 | QQuick3DTexture *opacityMap() const; |
132 | QQuick3DTexture *normalMap() const; |
133 | QColor specularColor() const; |
134 | QQuick3DTexture *specularMap() const; |
135 | float normalStrength() const; |
136 | QQuick3DTexture *occlusionMap() const; |
137 | float occlusionAmount() const; |
138 | AlphaMode alphaMode() const; |
139 | float alphaCutoff() const; |
140 | TextureChannelMapping glossinessChannel() const; |
141 | TextureChannelMapping opacityChannel() const; |
142 | TextureChannelMapping occlusionChannel() const; |
143 | float pointSize() const; |
144 | float lineWidth() const; |
145 | QQuick3DTexture *heightMap() const; |
146 | TextureChannelMapping heightChannel() const; |
147 | float heightAmount() const; |
148 | int minHeightMapSamples() const; |
149 | int maxHeightMapSamples() const; |
150 | |
151 | float clearcoatAmount() const; |
152 | QQuick3DTexture *clearcoatMap() const; |
153 | TextureChannelMapping clearcoatChannel() const; |
154 | float clearcoatRoughnessAmount() const; |
155 | TextureChannelMapping clearcoatRoughnessChannel() const; |
156 | QQuick3DTexture *clearcoatRoughnessMap() const; |
157 | QQuick3DTexture *clearcoatNormalMap() const; |
158 | |
159 | float transmissionFactor() const; |
160 | QQuick3DTexture *transmissionMap() const; |
161 | TextureChannelMapping transmissionChannel() const; |
162 | |
163 | float thicknessFactor() const; |
164 | QQuick3DTexture *thicknessMap() const; |
165 | TextureChannelMapping thicknessChannel() const; |
166 | float attenuationDistance() const; |
167 | QColor attenuationColor() const; |
168 | |
169 | Q_REVISION(6, 5) bool vertexColorsEnabled() const; |
170 | |
171 | public Q_SLOTS: |
172 | void setLighting(QQuick3DSpecularGlossyMaterial::Lighting lighting); |
173 | void setBlendMode(QQuick3DSpecularGlossyMaterial::BlendMode blendMode); |
174 | void setAlbedoColor(const QColor &albedo); |
175 | void setAlbedoMap(QQuick3DTexture *albedoMap); |
176 | void setEmissiveMap(QQuick3DTexture *emissiveMap); |
177 | void setEmissiveFactor(const QVector3D &emissiveFactor); |
178 | void setGlossiness(float glossiness); |
179 | void setGlossinessMap(QQuick3DTexture *glossinessMap); |
180 | void setOpacity(float opacity); |
181 | void setOpacityMap(QQuick3DTexture *opacityMap); |
182 | void setNormalMap(QQuick3DTexture *normalMap); |
183 | void setSpecularColor(const QColor &specular); |
184 | void setSpecularMap(QQuick3DTexture *specularMap); |
185 | void setNormalStrength(float normalStrength); |
186 | void setOcclusionMap(QQuick3DTexture *occlusionMap); |
187 | void setOcclusionAmount(float occlusionAmount); |
188 | void setAlphaMode(QQuick3DSpecularGlossyMaterial::AlphaMode alphaMode); |
189 | void setAlphaCutoff(float alphaCutoff); |
190 | void setGlossinessChannel(QQuick3DMaterial::TextureChannelMapping channel); |
191 | void setOpacityChannel(QQuick3DMaterial::TextureChannelMapping channel); |
192 | void setOcclusionChannel(QQuick3DMaterial::TextureChannelMapping channel); |
193 | void setPointSize(float size); |
194 | void setLineWidth(float width); |
195 | void setHeightMap(QQuick3DTexture *heightMap); |
196 | void setHeightChannel(QQuick3DMaterial::TextureChannelMapping channel); |
197 | void setHeightAmount(float heightAmount); |
198 | void setMinHeightMapSamples(int samples); |
199 | void setMaxHeightMapSamples(int samples); |
200 | |
201 | void setClearcoatAmount(float newClearcoatAmount); |
202 | void setClearcoatMap(QQuick3DTexture *newClearcoatMap); |
203 | void setClearcoatChannel(QQuick3DMaterial::TextureChannelMapping newClearcoatChannel); |
204 | void setClearcoatRoughnessAmount(float newClearcoatRoughnessAmount); |
205 | void setClearcoatRoughnessChannel(QQuick3DMaterial::TextureChannelMapping newClearcoatRoughnessChannel); |
206 | void setClearcoatRoughnessMap(QQuick3DTexture *newClearcoatRoughnessMap); |
207 | void setClearcoatNormalMap(QQuick3DTexture *newClearcoatNormalMap); |
208 | |
209 | void setTransmissionFactor(float newTransmissionFactor); |
210 | void setTransmissionMap(QQuick3DTexture *newTransmissionMap); |
211 | void setTransmissionChannel(QQuick3DMaterial::TextureChannelMapping newTransmissionChannel); |
212 | |
213 | void setThicknessFactor(float newThicknessFactor); |
214 | void setThicknessMap(QQuick3DTexture *newThicknessMap); |
215 | void setThicknessChannel(QQuick3DMaterial::TextureChannelMapping newThicknessChannel); |
216 | void setAttenuationDistance(float newAttenuationDistance); |
217 | void setAttenuationColor(const QColor &newAttenuationColor); |
218 | |
219 | Q_REVISION(6, 5) void setVertexColorsEnabled(bool vertexColorsEnabled); |
220 | |
221 | Q_SIGNALS: |
222 | void lightingChanged(); |
223 | void blendModeChanged(); |
224 | void albedoColorChanged(); |
225 | void albedoMapChanged(); |
226 | void emissiveMapChanged(); |
227 | void emissiveFactorChanged(); |
228 | void glossinessChanged(); |
229 | void glossinessMapChanged(); |
230 | void opacityChanged(); |
231 | void opacityMapChanged(); |
232 | void normalMapChanged(); |
233 | void specularColorChanged(); |
234 | void specularMapChanged(); |
235 | void normalStrengthChanged(); |
236 | void occlusionMapChanged(); |
237 | void occlusionAmountChanged(); |
238 | void alphaModeChanged(); |
239 | void alphaCutoffChanged(); |
240 | void glossinessChannelChanged(); |
241 | void opacityChannelChanged(); |
242 | void occlusionChannelChanged(); |
243 | void pointSizeChanged(); |
244 | void lineWidthChanged(); |
245 | void heightMapChanged(); |
246 | void heightChannelChanged(); |
247 | void heightAmountChanged(); |
248 | void minHeightMapSamplesChanged(); |
249 | void maxHeightMapSamplesChanged(); |
250 | |
251 | void clearcoatAmountChanged(); |
252 | void clearcoatMapChanged(); |
253 | void clearcoatChannelChanged(); |
254 | void clearcoatRoughnessAmountChanged(); |
255 | void clearcoatRoughnessChannelChanged(); |
256 | void clearcoatRoughnessMapChanged(); |
257 | void clearcoatNormalMapChanged(); |
258 | |
259 | void transmissionFactorChanged(); |
260 | void transmissionMapChanged(); |
261 | void transmissionChannelChanged(); |
262 | |
263 | void thicknessFactorChanged(); |
264 | void thicknessMapChanged(); |
265 | void thicknessChannelChanged(); |
266 | void attenuationDistanceChanged(); |
267 | void attenuationColorChanged(); |
268 | |
269 | Q_REVISION(6, 5) void vertexColorsEnabledChanged(bool vertexColorsEnabled); |
270 | |
271 | protected: |
272 | QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override; |
273 | void markAllDirty() override; |
274 | void itemChange(ItemChange, const ItemChangeData &) override; |
275 | private: |
276 | |
277 | enum DirtyType { |
278 | LightingModeDirty = 0x00000001, |
279 | BlendModeDirty = 0x00000002, |
280 | AlbedoDirty = 0x00000004, |
281 | EmissiveDirty = 0x00000008, |
282 | SpecularDirty = 0x00000010, |
283 | OpacityDirty = 0x00000020, |
284 | NormalDirty = 0x00000040, |
285 | GlossyDirty = 0x00000080, |
286 | OcclusionDirty = 0x00000100, |
287 | AlphaModeDirty = 0x00000200, |
288 | PointSizeDirty = 0x00000400, |
289 | LineWidthDirty = 0x00000800, |
290 | HeightDirty = 0x00001000, |
291 | ClearcoatDirty = 0x00002000, |
292 | TransmissionDirty = 0x00004000, |
293 | VolumeDirty = 0x00008000, |
294 | VertexColorsDirty = 0x00001000 |
295 | }; |
296 | |
297 | void updateSceneManager(QQuick3DSceneManager *window); |
298 | |
299 | Lighting m_lighting = FragmentLighting; |
300 | BlendMode m_blendMode = SourceOver; |
301 | AlphaMode m_alphaMode = Default; |
302 | QColor m_albedo = Qt::white; |
303 | QQuick3DTexture *m_albedoMap = nullptr; |
304 | QVector3D m_emissiveFactor; |
305 | QQuick3DTexture *m_emissiveMap = nullptr; |
306 | QQuick3DTexture *m_glossinessMap = nullptr; |
307 | QQuick3DTexture *m_opacityMap = nullptr; |
308 | QQuick3DTexture *m_normalMap = nullptr; |
309 | QQuick3DTexture *m_specularMap = nullptr; |
310 | QQuick3DTexture *m_occlusionMap = nullptr; |
311 | float m_glossiness = 1.0f; |
312 | float m_opacity = 1.0f; |
313 | QColor m_specular = Qt::white; |
314 | float m_normalStrength = 1.0f; |
315 | float m_occlusionAmount = 1.0f; |
316 | float m_alphaCutoff = 0.5f; |
317 | TextureChannelMapping m_glossinessChannel = QQuick3DMaterial::A; |
318 | TextureChannelMapping m_opacityChannel = QQuick3DMaterial::A; |
319 | TextureChannelMapping m_occlusionChannel = QQuick3DMaterial::R; |
320 | float m_pointSize = 1.0f; |
321 | float m_lineWidth = 1.0f; |
322 | QQuick3DTexture *m_heightMap = nullptr; |
323 | TextureChannelMapping m_heightChannel = QQuick3DMaterial::R; |
324 | float m_heightAmount = 0.0f; |
325 | int m_minHeightMapSamples = 8; |
326 | int m_maxHeightMapSamples = 32; |
327 | float m_clearcoatAmount = 0.0f; |
328 | QQuick3DTexture *m_clearcoatMap = nullptr; |
329 | TextureChannelMapping m_clearcoatChannel = QQuick3DMaterial::R; |
330 | float m_clearcoatRoughnessAmount = 0.0f; |
331 | TextureChannelMapping m_clearcoatRoughnessChannel = QQuick3DMaterial::G; |
332 | QQuick3DTexture *m_clearcoatRoughnessMap = nullptr; |
333 | QQuick3DTexture *m_clearcoatNormalMap = nullptr; |
334 | float m_transmissionFactor = 0.0f; |
335 | QQuick3DTexture *m_transmissionMap = nullptr; |
336 | TextureChannelMapping m_transmissionChannel = QQuick3DMaterial::R; |
337 | float m_thicknessFactor = 0.0f; |
338 | QQuick3DTexture *m_thicknessMap = nullptr; |
339 | TextureChannelMapping m_thicknessChannel = QQuick3DMaterial::G; |
340 | float m_attenuationDistance = std::numeric_limits<float>::infinity(); |
341 | QColor m_attenuationColor = Qt::white; |
342 | bool m_vertexColorsEnabled = true; |
343 | |
344 | quint32 m_dirtyAttributes = 0xffffffff; // all dirty by default |
345 | void markDirty(DirtyType type); |
346 | }; |
347 | |
348 | QT_END_NAMESPACE |
349 | |
350 | #endif // QQUICK3DSPECULARGLOSSYMATERIAL_P_H |
351 | |