60 QString modifiedCode = QString::fromUtf8(shaderCode);
61 for (
auto it = AugmentMacros.constBegin(); it != AugmentMacros.constEnd(); ++it) {
62 QString pattern = QStringLiteral(
"\\b%1\\b").arg(QRegularExpression::escape(QString::fromUtf8(it.key())));
63 QRegularExpression regex(pattern);
64 modifiedCode.replace(regex, QString::fromUtf8(it.value()));
66 return modifiedCode.toUtf8();
69void QSSGRenderUserPass::finalizeShaders(
const QSSGRenderContextInterface &ctx)
73 if (materialMode != AugmentMaterial)
76 if (!isDirty(DirtyFlag::ShaderDirty))
79 clearDirty(DirtyFlag::ShaderDirty);
81 const bool hasShaderCode = (shaderAugmentation.hasUserAugmentation());
84 qCDebug(lcRenderUserPass) <<
"Finalizing shaders for user pass with augment shader code.";
87 shaderAugmentation.preamble = replaceAugmentMacros(shaderAugmentation.preamble);
88 shaderAugmentation.body = replaceAugmentMacros(shaderAugmentation.body);
91 shaderAugmentation.needsBaseColor = shaderAugmentation.body.contains(AugmentMacros[
"BASE_COLOR"]);
92 shaderAugmentation.needsRoughness = shaderAugmentation.body.contains(AugmentMacros[
"ROUGHNESS"]);
93 shaderAugmentation.needsMetalness = shaderAugmentation.body.contains(AugmentMacros[
"METALNESS"]);
94 shaderAugmentation.needsDiffuseLight = shaderAugmentation.body.contains(AugmentMacros[
"DIFFUSE_LIGHT"]);
95 shaderAugmentation.needsSpecularLight = shaderAugmentation.body.contains(AugmentMacros[
"SPECULAR_LIGHT"]);
96 shaderAugmentation.needsEmissiveLight = shaderAugmentation.body.contains(AugmentMacros[
"EMISSIVE_LIGHT"]);
97 shaderAugmentation.needsWorldNormal = shaderAugmentation.body.contains(AugmentMacros[
"WORLD_NORMAL"]);
98 shaderAugmentation.needsWorldTangent = shaderAugmentation.body.contains(AugmentMacros[
"WORLD_TANGENT"]);
99 shaderAugmentation.needsWorldBinormal = shaderAugmentation.body.contains(AugmentMacros[
"WORLD_BINORMAL"]);
100 shaderAugmentation.needsF0 = shaderAugmentation.body.contains(AugmentMacros[
"F0"]);
101 shaderAugmentation.needsF90 = shaderAugmentation.body.contains(AugmentMacros[
"F90"]);
103 m_state = State::Ready;
106 m_state = State::Error;
108 qWarning() <<
"No augment shader code provided for user pass.";
112 qCDebug(lcRenderUserPass) <<
"Finalizing shaders for user pass commands";