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 | QSSGRenderImage *colorMap = nullptr; |
65 | // material section |
66 | QSSGRenderImage *iblProbe = nullptr; |
67 | QSSGRenderImage *emissiveMap = nullptr; |
68 | QSSGRenderImage *specularReflection = nullptr; |
69 | QSSGRenderImage *specularMap = nullptr; |
70 | QSSGRenderImage *roughnessMap = nullptr; |
71 | QSSGRenderImage *opacityMap = nullptr; |
72 | QSSGRenderImage *bumpMap = nullptr; |
73 | QSSGRenderImage *normalMap = nullptr; |
74 | QSSGRenderImage *translucencyMap = nullptr; |
75 | QSSGRenderImage *metalnessMap = nullptr; |
76 | QSSGRenderImage *occlusionMap = nullptr; |
77 | QSSGRenderImage *heightMap = nullptr; |
78 | QSSGRenderImage *clearcoatMap = nullptr; |
79 | QSSGRenderImage *clearcoatRoughnessMap = nullptr; |
80 | QSSGRenderImage *clearcoatNormalMap = nullptr; |
81 | QSSGRenderImage *transmissionMap = nullptr; |
82 | QSSGRenderImage *thicknessMap = nullptr; |
83 | |
84 | // Note that most default values here are irrelevant as the material |
85 | // (Default or Principled) will write its own defaults or actual values |
86 | // during sync. |
87 | QVector3D specularTint{ 1.0f, 1.0f, 1.0f }; |
88 | float ior = 1.45f; // relevant for Default only |
89 | QVector3D emissiveColor = { 1.0f, 1.0f, 1.0f }; |
90 | QVector4D color{ 1.0f, 1.0f, 1.0f, 1.0f }; // colors are 0-1 normalized |
91 | float diffuseLightWrap = 0.0f; // 0 - 1 |
92 | float fresnelPower = 0.0f; |
93 | float specularAmount = 1.0f; // 0-1 |
94 | float specularRoughness = 0.0f; // 0-1 |
95 | float metalnessAmount = 0.0f; |
96 | float opacity = 1.0f; // 0-1 |
97 | float bumpAmount = 0.0f; // 0-?? |
98 | float translucentFalloff = 0.0f; // 0 - ?? |
99 | float occlusionAmount = 1.0f; // 0 - 1 |
100 | float alphaCutoff = 0.5f; // 0 - 1 |
101 | float heightAmount = 0.0f; // 0 - 1 |
102 | int minHeightSamples = 8; |
103 | int maxHeightSamples = 32; |
104 | float clearcoatAmount = 0.0f; // 0 - 1 |
105 | float clearcoatRoughnessAmount = 0.0f; // 0 - 1 |
106 | float transmissionFactor = 0.0f; // 0 - 1 |
107 | float thicknessFactor = 0.0f; // 0 - 1 |
108 | float attenuationDistance = std::numeric_limits<float>::infinity(); |
109 | QVector3D attenuationColor { 1.0f, 1.0f, 1.0f }; |
110 | |
111 | MaterialLighting lighting = MaterialLighting::FragmentLighting; |
112 | QSSGRenderDefaultMaterial::MaterialBlendMode blendMode = QSSGRenderDefaultMaterial::MaterialBlendMode::SourceOver; |
113 | QSSGRenderDefaultMaterial::MaterialSpecularModel specularModel = QSSGRenderDefaultMaterial::MaterialSpecularModel::Default; |
114 | QSSGRenderDefaultMaterial::MaterialAlphaMode alphaMode = QSSGRenderDefaultMaterial::Default; |
115 | QSSGCullFaceMode cullMode = QSSGCullFaceMode::Back; |
116 | QSSGDepthDrawMode depthDrawMode = QSSGDepthDrawMode::OpaqueOnly; |
117 | bool vertexColorsEnabled = false; |
118 | bool dirty = true; |
119 | TextureChannelMapping roughnessChannel = TextureChannelMapping::R; |
120 | TextureChannelMapping opacityChannel = TextureChannelMapping::A; |
121 | TextureChannelMapping translucencyChannel = TextureChannelMapping::A; |
122 | TextureChannelMapping metalnessChannel = TextureChannelMapping::R; |
123 | TextureChannelMapping occlusionChannel = TextureChannelMapping::R; |
124 | TextureChannelMapping heightChannel = TextureChannelMapping::R; |
125 | TextureChannelMapping clearcoatChannel = TextureChannelMapping::R; |
126 | TextureChannelMapping clearcoatRoughnessChannel = TextureChannelMapping::G; |
127 | TextureChannelMapping transmissionChannel = TextureChannelMapping::R; |
128 | TextureChannelMapping thicknessChannel = TextureChannelMapping::G; |
129 | float pointSize = 1.0f; |
130 | float lineWidth = 1.0f; |
131 | |
132 | QSSGRenderDefaultMaterial(Type type = Type::DefaultMaterial); |
133 | ~QSSGRenderDefaultMaterial(); |
134 | |
135 | bool isSpecularEnabled() const { return specularAmount > .01f; } |
136 | bool isMetalnessEnabled() const { return metalnessAmount > 0.01f; } |
137 | bool isFresnelEnabled() const { return fresnelPower > 0.0f; } |
138 | bool isVertexColorsEnabled() const { return vertexColorsEnabled; } |
139 | bool hasLighting() const { return lighting != MaterialLighting::NoLighting; } |
140 | bool isClearcoatEnabled() const { return clearcoatAmount > 0.01f; } |
141 | bool isTransmissionEnabled() const { return transmissionFactor > 0.01f; } |
142 | |
143 | [[nodiscard]] inline bool isDirty() const { return dirty; } |
144 | void clearDirty(); |
145 | |
146 | QSSGShaderMaterialAdapter *adapter = nullptr; |
147 | |
148 | QString debugObjectName; |
149 | }; |
150 | |
151 | QT_END_NAMESPACE |
152 | |
153 | #endif |
154 | |