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_SHADER_MATERIAL_ADAPTER_H
6#define QSSG_SHADER_MATERIAL_ADAPTER_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/qssgrendermaterialshadergenerator_p.h>
20#include <QtQuick3DRuntimeRender/private/qssgrendershadercodegenerator_p.h>
21#include <QtQuick3DRuntimeRender/private/qssgrendershadowmap_p.h>
22#include <QtQuick3DRuntimeRender/private/qssgrenderlight_p.h>
23#include <QtQuick3DRuntimeRender/private/qssgrenderableimage_p.h>
24#include <QtQuick3DRuntimeRender/private/qssgrendershaderlibrarymanager_p.h>
25
26QT_BEGIN_NAMESPACE
27
28struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGShaderMaterialAdapter
29{
30 static QSSGShaderMaterialAdapter *create(const QSSGRenderGraphObject &materialNode);
31 virtual ~QSSGShaderMaterialAdapter();
32
33 virtual bool isPrincipled() = 0;
34 virtual bool isSpecularGlossy() = 0;
35 virtual bool isMetalnessEnabled() = 0;
36 virtual bool isSpecularEnabled() = 0;
37 virtual bool isVertexColorsEnabled() = 0;
38 virtual bool isClearcoatEnabled() = 0;
39 virtual bool isTransmissionEnabled() = 0;
40 virtual bool hasLighting() = 0;
41 virtual bool usesCustomSkinning() = 0;
42 virtual bool usesCustomMorphing() = 0;
43 virtual QSSGRenderDefaultMaterial::MaterialSpecularModel specularModel() = 0;
44 virtual QSSGRenderDefaultMaterial::MaterialAlphaMode alphaMode() = 0;
45
46 virtual QSSGRenderImage *iblProbe() = 0;
47 virtual QVector3D emissiveColor() = 0;
48 virtual QVector4D color() = 0;
49 virtual QVector3D specularTint() = 0;
50 virtual float ior() = 0;
51 virtual float fresnelPower() = 0;
52 virtual float metalnessAmount() = 0;
53 virtual float specularAmount() = 0;
54 virtual float specularRoughness() = 0;
55 virtual float bumpAmount() = 0;
56 virtual float translucentFallOff() = 0;
57 virtual float diffuseLightWrap() = 0;
58 virtual float occlusionAmount() = 0;
59 virtual float alphaCutOff() = 0;
60 virtual float pointSize() = 0;
61 virtual float lineWidth() = 0;
62 virtual float heightAmount() = 0;
63 virtual float minHeightSamples() = 0;
64 virtual float maxHeightSamples() = 0;
65 virtual float clearcoatAmount() = 0;
66 virtual float clearcoatRoughnessAmount() = 0;
67 virtual float transmissionFactor() = 0;
68 virtual float thicknessFactor() = 0;
69 virtual float attenuationDistance() = 0;
70 virtual QVector3D attenuationColor() = 0;
71
72 virtual bool isUnshaded();
73 virtual bool hasCustomShaderSnippet(QSSGShaderCache::ShaderType type);
74 virtual QByteArray customShaderSnippet(QSSGShaderCache::ShaderType type,
75 QSSGShaderLibraryManager &shaderLibraryManager);
76 virtual bool hasCustomShaderFunction(QSSGShaderCache::ShaderType shaderType,
77 const QByteArray &funcName,
78 QSSGShaderLibraryManager &shaderLibraryManager);
79 virtual void setCustomPropertyUniforms(char *ubufData,
80 QSSGRhiShaderPipeline &shaderPipeline,
81 const QSSGRenderContextInterface &context);
82 virtual bool usesSharedVariables();
83};
84
85struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGShaderDefaultMaterialAdapter final : public QSSGShaderMaterialAdapter
86{
87 QSSGShaderDefaultMaterialAdapter(const QSSGRenderDefaultMaterial &material);
88
89 bool isPrincipled() override;
90 bool isSpecularGlossy() override;
91 bool isMetalnessEnabled() override;
92 bool isSpecularEnabled() override;
93 bool isVertexColorsEnabled() override;
94 bool isClearcoatEnabled() override;
95 bool isTransmissionEnabled() override;
96 bool hasLighting() override;
97 bool usesCustomSkinning() override;
98 bool usesCustomMorphing() override;
99 QSSGRenderDefaultMaterial::MaterialSpecularModel specularModel() override;
100 QSSGRenderDefaultMaterial::MaterialAlphaMode alphaMode() override;
101
102 QSSGRenderImage *iblProbe() override;
103 QVector3D emissiveColor() override;
104 QVector4D color() override;
105 QVector3D specularTint() override;
106 float ior() override;
107 float fresnelPower() override;
108 float metalnessAmount() override;
109 float specularAmount() override;
110 float specularRoughness() override;
111 float bumpAmount() override;
112 float translucentFallOff() override;
113 float diffuseLightWrap() override;
114 float occlusionAmount() override;
115 float alphaCutOff() override;
116 float pointSize() override;
117 float lineWidth() override;
118 float heightAmount() override;
119 float minHeightSamples() override;
120 float maxHeightSamples() override;
121 float clearcoatAmount() override;
122 float clearcoatRoughnessAmount() override;
123 float transmissionFactor() override;
124 float thicknessFactor() override;
125 float attenuationDistance() override;
126 QVector3D attenuationColor() override;
127
128private:
129 const QSSGRenderDefaultMaterial &m_material;
130};
131
132struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGShaderCustomMaterialAdapter final : public QSSGShaderMaterialAdapter
133{
134 QSSGShaderCustomMaterialAdapter(const QSSGRenderCustomMaterial &material);
135
136 bool isPrincipled() override;
137 bool isSpecularGlossy() override;
138 bool isMetalnessEnabled() override;
139 bool isSpecularEnabled() override;
140 bool isVertexColorsEnabled() override;
141 bool isClearcoatEnabled() override;
142 bool isTransmissionEnabled() override;
143 bool hasLighting() override;
144 bool usesCustomSkinning() override;
145 bool usesCustomMorphing() override;
146 QSSGRenderDefaultMaterial::MaterialSpecularModel specularModel() override;
147 QSSGRenderDefaultMaterial::MaterialAlphaMode alphaMode() override;
148
149 QSSGRenderImage *iblProbe() override;
150 QVector3D emissiveColor() override;
151 QVector4D color() override;
152 QVector3D specularTint() override;
153 float ior() override;
154 float fresnelPower() override;
155 float metalnessAmount() override;
156 float specularAmount() override;
157 float specularRoughness() override;
158 float bumpAmount() override;
159 float translucentFallOff() override;
160 float diffuseLightWrap() override;
161 float occlusionAmount() override;
162 float alphaCutOff() override;
163 float pointSize() override;
164 float lineWidth() override;
165 float heightAmount() override;
166 float minHeightSamples() override;
167 float maxHeightSamples() override;
168 float clearcoatAmount() override;
169 float clearcoatRoughnessAmount() override;
170 float transmissionFactor() override;
171 float thicknessFactor() override;
172 float attenuationDistance() override;
173 QVector3D attenuationColor() override;
174
175 bool isUnshaded() override;
176 bool hasCustomShaderSnippet(QSSGShaderCache::ShaderType type) override;
177 QByteArray customShaderSnippet(QSSGShaderCache::ShaderType type,
178 QSSGShaderLibraryManager &shaderLibraryManager) override;
179 bool hasCustomShaderFunction(QSSGShaderCache::ShaderType shaderType,
180 const QByteArray &funcName,
181 QSSGShaderLibraryManager &shaderLibraryManager) override;
182 void setCustomPropertyUniforms(char *ubufData,
183 QSSGRhiShaderPipeline &shaderPipeline,
184 const QSSGRenderContextInterface &context) override;
185 bool usesSharedVariables() override;
186
187 using StringPair = QPair<QByteArray, QByteArray>;
188 using StringPairList = QVarLengthArray<StringPair, 16>;
189 using ShaderCodeAndMetaData = QPair<QByteArray, QSSGCustomShaderMetaData>;
190 static ShaderCodeAndMetaData prepareCustomShader(QByteArray &dst,
191 const QByteArray &shaderCode,
192 QSSGShaderCache::ShaderType type,
193 const StringPairList &baseUniforms,
194 const StringPairList &baseInputs = StringPairList(),
195 const StringPairList &baseOutputs = StringPairList());
196
197private:
198 const QSSGRenderCustomMaterial &m_material;
199};
200
201struct QSSGCustomMaterialVariableSubstitution
202{
203 QByteArrayView builtin;
204 QByteArrayView actualName;
205};
206
207namespace QtQuick3DEditorHelpers {
208// NOTE: Returns a copy of the actual list, cache as needed!
209namespace CustomMaterial {
210[[nodiscard]] Q_QUICK3DRUNTIMERENDER_EXPORT QList<QByteArrayView> preprocessorVars();
211}
212}
213
214QT_END_NAMESPACE
215
216#endif
217

source code of qtquick3d/src/runtimerender/qssgshadermaterialadapter_p.h