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
qssgrenderdefaultmaterial_p.h
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6
7#ifndef QSSG_RENDER_DEFAULT_MATERIAL_H
8#define QSSG_RENDER_DEFAULT_MATERIAL_H
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
21#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
22
23#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
24
25#include <QtGui/QVector3D>
26
28
29struct QSSGRenderImage;
30struct QSSGRenderModel;
31struct QSSGShaderMaterialAdapter;
32
33struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderDefaultMaterial : QSSGRenderGraphObject
34{
35 enum class MaterialLighting : quint8
36 {
37 NoLighting = 0,
38 FragmentLighting
39 };
40 enum class MaterialBlendMode : quint8
41 {
42 SourceOver = 0,
43 Screen,
44 Multiply
45 };
46 enum class MaterialSpecularModel : quint8
47 {
48 BlinnPhong = 0,
49 SchlickGGX
50 };
51
52 enum class MaterialDiffuseModel : quint8
53 {
54 Burley = 0,
55 Lambert,
56 LambertWrap
57 };
58
59 enum MaterialAlphaMode : quint8
60 {
61 Default = 0,
62 Mask,
63 Blend,
64 Opaque
65 };
66 enum TextureChannelMapping : quint8
67 {
68 R = 0,
69 G,
70 B,
71 A
72 };
73
74 enum VertexColorMask : quint16
75 {
76 NoMask = 0,
77 RoughnessMask = 1,
78 NormalStrengthMask = 2,
79 SpecularAmountMask = 4,
80 ClearcoatAmountMask = 8,
81 ClearcoatRoughnessAmountMask = 16,
82 ClearcoatNormalStrengthMask = 32,
83 HeightAmountMask = 64,
84 MetalnessMask = 128,
85 OcclusionAmountMask = 256,
86 ThicknessFactorMask = 512,
87 TransmissionFactorMask = 1024
88 };
89 Q_DECLARE_FLAGS(VertexColorMaskFlags, VertexColorMask)
90
91 QSSGRenderImage *colorMap = nullptr;
92 // material section
93 QSSGRenderImage *iblProbe = nullptr;
94 QSSGRenderImage *emissiveMap = nullptr;
95 QSSGRenderImage *specularReflection = nullptr;
96 QSSGRenderImage *specularMap = nullptr;
97 QSSGRenderImage *roughnessMap = nullptr;
98 QSSGRenderImage *opacityMap = nullptr;
99 QSSGRenderImage *bumpMap = nullptr;
100 QSSGRenderImage *normalMap = nullptr;
101 QSSGRenderImage *translucencyMap = nullptr;
102 QSSGRenderImage *metalnessMap = nullptr;
103 QSSGRenderImage *occlusionMap = nullptr;
104 QSSGRenderImage *heightMap = nullptr;
105 QSSGRenderImage *clearcoatMap = nullptr;
106 QSSGRenderImage *clearcoatRoughnessMap = nullptr;
107 QSSGRenderImage *clearcoatNormalMap = nullptr;
108 QSSGRenderImage *sheenColorMap = nullptr;
109 QSSGRenderImage *sheenRoughnessMap = nullptr;
110 QSSGRenderImage *anisotropyMap = nullptr;
111 QSSGRenderImage *iridescenceMap = nullptr;
112 QSSGRenderImage *iridescenceThicknessMap = nullptr;
113 QSSGRenderImage *transmissionMap = nullptr;
114 QSSGRenderImage *thicknessMap = nullptr;
115
116 // Note that most default values here are irrelevant as the material
117 // (Default or Principled) will write its own defaults or actual values
118 // during sync.
119 QVector3D specularTint{ 1.0f, 1.0f, 1.0f };
120 float ior = 1.45f; // relevant for Default only
121 QVector3D emissiveColor = { 1.0f, 1.0f, 1.0f };
122 QVector4D color{ 1.0f, 1.0f, 1.0f, 1.0f }; // colors are 0-1 normalized
123 float diffuseLightWrap = 0.0f; // 0 - 1
124 float fresnelScaleBiasEnabled = false;
125 float fresnelScale = 1.0f;
126 float fresnelBias = 0.0f;
127 float fresnelPower = 0.0f;
128 float clearcoatFresnelScaleBiasEnabled = false;
129 float clearcoatFresnelScale = 1.0f;
130 float clearcoatFresnelBias = 0.0f;
131 float clearcoatFresnelPower = 5.0f;
132 float specularAmount = 1.0f; // 0-1
133 float specularRoughness = 0.0f; // 0-1
134 float metalnessAmount = 0.0f;
135 float opacity = 1.0f; // 0-1
136 bool invertOpacityMapValue = false;
137 bool baseColorSingleChannelEnabled = false;
138 bool specularAmountSingleChannelEnabled = false;
139 bool emissiveSingleChannelEnabled = false;
140 float bumpAmount = 0.0f; // 0-??
141 float translucentFalloff = 0.0f; // 0 - ??
142 float occlusionAmount = 1.0f; // 0 - 1
143 float alphaCutoff = 0.5f; // 0 - 1
144 float heightAmount = 0.0f; // 0 - 1
145 int minHeightSamples = 8;
146 int maxHeightSamples = 32;
147 float clearcoatAmount = 0.0f; // 0 - 1
148 float clearcoatRoughnessAmount = 0.0f; // 0 - 1
149 float clearcoatNormalStrength = 1.0f; // 0 - 1
150 QVector3D sheenColor { 0.0f, 0.0f, 0.0f }; // black disables the sheen layer
151 float sheenRoughness = 0.0f; // 0 - 1
152 float anisotropyStrength = 0.0f; // 0 - 1, 0 disables anisotropy
153 float anisotropyRotation = 0.0f; // radians
154 float iridescenceFactor = 0.0f; // 0 - 1, 0 disables iridescence
155 float iridescenceIndexOfRefraction = 1.3f;
156 float iridescenceThicknessMinimum = 100.0f; // nanometers
157 float iridescenceThicknessMaximum = 400.0f; // nanometers
158 float dispersion = 0.0f; // 20 / Abbe number, 0 disables dispersion
159 float transmissionFactor = 0.0f; // 0 - 1
160 float thicknessFactor = 0.0f; // 0 - 1
161 float attenuationDistance = std::numeric_limits<float>::infinity();
162 QVector3D attenuationColor { 1.0f, 1.0f, 1.0f };
163
164 MaterialLighting lighting = MaterialLighting::FragmentLighting;
165 QSSGRenderDefaultMaterial::MaterialBlendMode blendMode = QSSGRenderDefaultMaterial::MaterialBlendMode::SourceOver;
166 QSSGRenderDefaultMaterial::MaterialSpecularModel specularModel = QSSGRenderDefaultMaterial::MaterialSpecularModel::SchlickGGX;
167 QSSGRenderDefaultMaterial::MaterialDiffuseModel diffuseModel = QSSGRenderDefaultMaterial::MaterialDiffuseModel::Burley;
168 QSSGRenderDefaultMaterial::MaterialAlphaMode alphaMode = QSSGRenderDefaultMaterial::Default;
169 QSSGCullFaceMode cullMode = QSSGCullFaceMode::Back;
170 QSSGDepthDrawMode depthDrawMode = QSSGDepthDrawMode::OpaqueOnly;
171 bool vertexColorsEnabled = false;
172 bool vertexColorsMaskEnabled = false;
173 bool dirty = true;
174 TextureChannelMapping roughnessChannel = TextureChannelMapping::R;
175 TextureChannelMapping opacityChannel = TextureChannelMapping::A;
176 TextureChannelMapping translucencyChannel = TextureChannelMapping::A;
177 TextureChannelMapping metalnessChannel = TextureChannelMapping::R;
178 TextureChannelMapping occlusionChannel = TextureChannelMapping::R;
179 TextureChannelMapping heightChannel = TextureChannelMapping::R;
180 TextureChannelMapping clearcoatChannel = TextureChannelMapping::R;
181 TextureChannelMapping clearcoatRoughnessChannel = TextureChannelMapping::G;
182 TextureChannelMapping sheenRoughnessChannel = TextureChannelMapping::A;
183 TextureChannelMapping iridescenceChannel = TextureChannelMapping::R;
184 TextureChannelMapping iridescenceThicknessChannel = TextureChannelMapping::G;
185 TextureChannelMapping transmissionChannel = TextureChannelMapping::R;
186 TextureChannelMapping thicknessChannel = TextureChannelMapping::G;
187 TextureChannelMapping baseColorChannel = TextureChannelMapping::R;
188 TextureChannelMapping specularAmountChannel = TextureChannelMapping::R;
189 TextureChannelMapping emissiveChannel = TextureChannelMapping::R;
190 float pointSize = 1.0f;
191 float lineWidth = 1.0f;
192 VertexColorMaskFlags vertexColorRedMask = VertexColorMask::NoMask;
193 VertexColorMaskFlags vertexColorGreenMask = VertexColorMask::NoMask;
194 VertexColorMaskFlags vertexColorBlueMask = VertexColorMask::NoMask;
195 VertexColorMaskFlags vertexColorAlphaMask = VertexColorMask::NoMask;
196
197 QSSGRenderDefaultMaterial(Type type = Type::DefaultMaterial);
198 ~QSSGRenderDefaultMaterial();
199
200 bool isSpecularEnabled() const { return specularAmount > .01f; }
201 bool isMetalnessEnabled() const { return metalnessAmount > 0.01f; }
202 bool isFresnelScaleBiasEnabled() const { return fresnelScaleBiasEnabled; }
203 bool isClearcoatFresnelScaleBiasEnabled() const { return clearcoatFresnelScaleBiasEnabled; }
204 bool isFresnelEnabled() const { return fresnelPower > 0.0f; }
205 bool isVertexColorsEnabled() const { return vertexColorsEnabled; }
206 bool isVertexColorsMaskEnabled() const { return vertexColorsMaskEnabled; }
207 bool isInvertOpacityMapValue() const { return invertOpacityMapValue; }
208 bool isBaseColorSingleChannelEnabled() const { return baseColorSingleChannelEnabled; }
209 bool isSpecularAmountSingleChannelEnabled() const { return specularAmountSingleChannelEnabled; }
210 bool isEmissiveSingleChannelEnabled() const { return emissiveSingleChannelEnabled; }
211 bool hasLighting() const { return lighting != MaterialLighting::NoLighting; }
212 bool isClearcoatEnabled() const { return clearcoatAmount > 0.01f; }
213 bool isSheenEnabled() const { return sheenColor.x() > 0.01f || sheenColor.y() > 0.01f || sheenColor.z() > 0.01f; }
214 bool isAnisotropyEnabled() const { return anisotropyStrength > 0.01f; }
215 bool isIridescenceEnabled() const { return iridescenceFactor > 0.01f; }
216 bool isTransmissionEnabled() const { return transmissionFactor > 0.01f; }
217 bool isDispersionEnabled() const { return dispersion > 0.01f && isTransmissionEnabled(); }
218
219 [[nodiscard]] inline bool isDirty() const { return dirty; }
220 void clearDirty();
221
222 QSSGShaderMaterialAdapter *adapter = nullptr;
223
224 QString debugObjectName;
225};
226
227QT_END_NAMESPACE
228
229#endif
QSSGPickResultProcessResult(const QSSGRenderPickResult &inSrc, bool consumed)
QSSGPickResultProcessResult(const QSSGRenderPickResult &inSrc)
friend class QSSGRenderContextInterface
Combined button and popup list for selecting options.
static QVector3D closestPointOnTriangle(const QVector3D &p, const QVector3D &a, const QVector3D &b, const QVector3D &c, const Dot &dot, float &u, float &v, float &w)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192
static void cleanupResourcesImpl(const QSSGRenderContextInterface &rci, const Container &resources)
static void getPickableRecursive(const QSSGRenderNode &node, RenderableList &renderables, bool pickEverything=false)
static void dfs(const QSSGRenderNode &node, RenderableList &renderables)
static QByteArray rendererLogPrefix()
static QSSGCullFaceMode mirroredCullMode(QSSGCullFaceMode cullMode)
static QSSGCullFaceMode cullModeForSubset(const QSSGRenderModel &model, int subset)
TShaderMapKey< QSSGShaderParticleMaterialKey > QSSGParticleShaderMapKey