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 | |
5 | #ifndef QSSG_RENDER_DEFAULT_MATERIAL_H |
6 | #define QSSG_RENDER_DEFAULT_MATERIAL_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h> |
20 | |
21 | #include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h> |
22 | |
23 | #include <QtGui/QVector3D> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | struct QSSGRenderImage; |
28 | struct QSSGRenderModel; |
29 | struct QSSGShaderMaterialAdapter; |
30 | |
31 | struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderDefaultMaterial : QSSGRenderGraphObject |
32 | { |
33 | enum class MaterialLighting : quint8 |
34 | { |
35 | NoLighting = 0, |
36 | FragmentLighting |
37 | }; |
38 | enum class MaterialBlendMode : quint8 |
39 | { |
40 | SourceOver = 0, |
41 | Screen, |
42 | Multiply |
43 | }; |
44 | enum class MaterialSpecularModel : quint8 |
45 | { |
46 | Default = 0, |
47 | KGGX |
48 | }; |
49 | enum MaterialAlphaMode : quint8 |
50 | { |
51 | Default = 0, |
52 | Mask, |
53 | Blend, |
54 | Opaque |
55 | }; |
56 | enum TextureChannelMapping : quint8 |
57 | { |
58 | R = 0, |
59 | G, |
60 | B, |
61 | A |
62 | }; |
63 | |
64 | enum VertexColorMask : quint16 |
65 | { |
66 | NoMask = 0, |
67 | RoughnessMask = 1, |
68 | NormalStrengthMask = 2, |
69 | SpecularAmountMask = 4, |
70 | ClearcoatAmountMask = 8, |
71 | ClearcoatRoughnessAmountMask = 16, |
72 | ClearcoatNormalStrengthMask = 32, |
73 | HeightAmountMask = 64, |
74 | MetalnessMask = 128, |
75 | OcclusionAmountMask = 256, |
76 | ThicknessFactorMask = 512, |
77 | TransmissionFactorMask = 1024 |
78 | }; |
79 | Q_DECLARE_FLAGS(VertexColorMaskFlags, VertexColorMask) |
80 | |
81 | QSSGRenderImage *colorMap = nullptr; |
82 | // material section |
83 | QSSGRenderImage *iblProbe = nullptr; |
84 | QSSGRenderImage *emissiveMap = nullptr; |
85 | QSSGRenderImage *specularReflection = nullptr; |
86 | QSSGRenderImage *specularMap = nullptr; |
87 | QSSGRenderImage *roughnessMap = nullptr; |
88 | QSSGRenderImage *opacityMap = nullptr; |
89 | QSSGRenderImage *bumpMap = nullptr; |
90 | QSSGRenderImage *normalMap = nullptr; |
91 | QSSGRenderImage *translucencyMap = nullptr; |
92 | QSSGRenderImage *metalnessMap = nullptr; |
93 | QSSGRenderImage *occlusionMap = nullptr; |
94 | QSSGRenderImage *heightMap = nullptr; |
95 | QSSGRenderImage *clearcoatMap = nullptr; |
96 | QSSGRenderImage *clearcoatRoughnessMap = nullptr; |
97 | QSSGRenderImage *clearcoatNormalMap = nullptr; |
98 | QSSGRenderImage *transmissionMap = nullptr; |
99 | QSSGRenderImage *thicknessMap = nullptr; |
100 | |
101 | // Note that most default values here are irrelevant as the material |
102 | // (Default or Principled) will write its own defaults or actual values |
103 | // during sync. |
104 | QVector3D specularTint{ 1.0f, 1.0f, 1.0f }; |
105 | float ior = 1.45f; // relevant for Default only |
106 | QVector3D emissiveColor = { 1.0f, 1.0f, 1.0f }; |
107 | QVector4D color{ 1.0f, 1.0f, 1.0f, 1.0f }; // colors are 0-1 normalized |
108 | float diffuseLightWrap = 0.0f; // 0 - 1 |
109 | float fresnelScaleBiasEnabled = false; |
110 | float fresnelScale = 1.0f; |
111 | float fresnelBias = 0.0f; |
112 | float fresnelPower = 0.0f; |
113 | float clearcoatFresnelScaleBiasEnabled = false; |
114 | float clearcoatFresnelScale = 1.0f; |
115 | float clearcoatFresnelBias = 0.0f; |
116 | float clearcoatFresnelPower = 5.0f; |
117 | float specularAmount = 1.0f; // 0-1 |
118 | float specularRoughness = 0.0f; // 0-1 |
119 | float metalnessAmount = 0.0f; |
120 | float opacity = 1.0f; // 0-1 |
121 | bool invertOpacityMapValue = false; |
122 | bool baseColorSingleChannelEnabled = false; |
123 | bool specularAmountSingleChannelEnabled = false; |
124 | bool emissiveSingleChannelEnabled = false; |
125 | float bumpAmount = 0.0f; // 0-?? |
126 | float translucentFalloff = 0.0f; // 0 - ?? |
127 | float occlusionAmount = 1.0f; // 0 - 1 |
128 | float alphaCutoff = 0.5f; // 0 - 1 |
129 | float heightAmount = 0.0f; // 0 - 1 |
130 | int minHeightSamples = 8; |
131 | int maxHeightSamples = 32; |
132 | float clearcoatAmount = 0.0f; // 0 - 1 |
133 | float clearcoatRoughnessAmount = 0.0f; // 0 - 1 |
134 | float clearcoatNormalStrength = 1.0f; // 0 - 1 |
135 | float transmissionFactor = 0.0f; // 0 - 1 |
136 | float thicknessFactor = 0.0f; // 0 - 1 |
137 | float attenuationDistance = std::numeric_limits<float>::infinity(); |
138 | QVector3D attenuationColor { 1.0f, 1.0f, 1.0f }; |
139 | |
140 | MaterialLighting lighting = MaterialLighting::FragmentLighting; |
141 | QSSGRenderDefaultMaterial::MaterialBlendMode blendMode = QSSGRenderDefaultMaterial::MaterialBlendMode::SourceOver; |
142 | QSSGRenderDefaultMaterial::MaterialSpecularModel specularModel = QSSGRenderDefaultMaterial::MaterialSpecularModel::Default; |
143 | QSSGRenderDefaultMaterial::MaterialAlphaMode alphaMode = QSSGRenderDefaultMaterial::Default; |
144 | QSSGCullFaceMode cullMode = QSSGCullFaceMode::Back; |
145 | QSSGDepthDrawMode depthDrawMode = QSSGDepthDrawMode::OpaqueOnly; |
146 | bool vertexColorsEnabled = false; |
147 | bool vertexColorsMaskEnabled = false; |
148 | bool dirty = true; |
149 | TextureChannelMapping roughnessChannel = TextureChannelMapping::R; |
150 | TextureChannelMapping opacityChannel = TextureChannelMapping::A; |
151 | TextureChannelMapping translucencyChannel = TextureChannelMapping::A; |
152 | TextureChannelMapping metalnessChannel = TextureChannelMapping::R; |
153 | TextureChannelMapping occlusionChannel = TextureChannelMapping::R; |
154 | TextureChannelMapping heightChannel = TextureChannelMapping::R; |
155 | TextureChannelMapping clearcoatChannel = TextureChannelMapping::R; |
156 | TextureChannelMapping clearcoatRoughnessChannel = TextureChannelMapping::G; |
157 | TextureChannelMapping transmissionChannel = TextureChannelMapping::R; |
158 | TextureChannelMapping thicknessChannel = TextureChannelMapping::G; |
159 | TextureChannelMapping baseColorChannel = TextureChannelMapping::R; |
160 | TextureChannelMapping specularAmountChannel = TextureChannelMapping::R; |
161 | TextureChannelMapping emissiveChannel = TextureChannelMapping::R; |
162 | float pointSize = 1.0f; |
163 | float lineWidth = 1.0f; |
164 | VertexColorMaskFlags vertexColorRedMask = VertexColorMask::NoMask; |
165 | VertexColorMaskFlags vertexColorGreenMask = VertexColorMask::NoMask; |
166 | VertexColorMaskFlags vertexColorBlueMask = VertexColorMask::NoMask; |
167 | VertexColorMaskFlags vertexColorAlphaMask = VertexColorMask::NoMask; |
168 | |
169 | QSSGRenderDefaultMaterial(Type type = Type::DefaultMaterial); |
170 | ~QSSGRenderDefaultMaterial(); |
171 | |
172 | bool isSpecularEnabled() const { return specularAmount > .01f; } |
173 | bool isMetalnessEnabled() const { return metalnessAmount > 0.01f; } |
174 | bool isFresnelScaleBiasEnabled() const { return fresnelScaleBiasEnabled; } |
175 | bool isClearcoatFresnelScaleBiasEnabled() const { return clearcoatFresnelScaleBiasEnabled; } |
176 | bool isFresnelEnabled() const { return fresnelPower > 0.0f; } |
177 | bool isVertexColorsEnabled() const { return vertexColorsEnabled; } |
178 | bool isVertexColorsMaskEnabled() const { return vertexColorsMaskEnabled; } |
179 | bool isInvertOpacityMapValue() const { return invertOpacityMapValue; } |
180 | bool isBaseColorSingleChannelEnabled() const { return baseColorSingleChannelEnabled; } |
181 | bool isSpecularAmountSingleChannelEnabled() const { return specularAmountSingleChannelEnabled; } |
182 | bool isEmissiveSingleChannelEnabled() const { return emissiveSingleChannelEnabled; } |
183 | bool hasLighting() const { return lighting != MaterialLighting::NoLighting; } |
184 | bool isClearcoatEnabled() const { return clearcoatAmount > 0.01f; } |
185 | bool isTransmissionEnabled() const { return transmissionFactor > 0.01f; } |
186 | |
187 | [[nodiscard]] inline bool isDirty() const { return dirty; } |
188 | void clearDirty(); |
189 | |
190 | QSSGShaderMaterialAdapter *adapter = nullptr; |
191 | |
192 | QString debugObjectName; |
193 | }; |
194 | |
195 | QT_END_NAMESPACE |
196 | |
197 | #endif |
198 |
Definitions
- QSSGRenderDefaultMaterial
- MaterialLighting
- MaterialBlendMode
- MaterialSpecularModel
- MaterialAlphaMode
- TextureChannelMapping
- VertexColorMask
- isSpecularEnabled
- isMetalnessEnabled
- isFresnelScaleBiasEnabled
- isClearcoatFresnelScaleBiasEnabled
- isFresnelEnabled
- isVertexColorsEnabled
- isVertexColorsMaskEnabled
- isInvertOpacityMapValue
- isBaseColorSingleChannelEnabled
- isSpecularAmountSingleChannelEnabled
- isEmissiveSingleChannelEnabled
- hasLighting
- isClearcoatEnabled
- isTransmissionEnabled
Start learning QML with our Intro Training
Find out more