diff --git a/src/Nazara/Shader/Ast/SanitizeVisitor.cpp b/src/Nazara/Shader/Ast/SanitizeVisitor.cpp index f197274dc..64cf87fb7 100644 --- a/src/Nazara/Shader/Ast/SanitizeVisitor.cpp +++ b/src/Nazara/Shader/Ast/SanitizeVisitor.cpp @@ -1428,6 +1428,7 @@ namespace Nz::ShaderAst } auto multi = std::make_unique(); + multi->sourceLocation = node.sourceLocation; auto Unroll = [&](auto dummy) { @@ -1442,6 +1443,7 @@ namespace Nz::ShaderAst PushScope(); auto innerMulti = std::make_unique(); + innerMulti->sourceLocation = node.sourceLocation; auto constant = ShaderBuilder::Constant(counter); constant->sourceLocation = node.sourceLocation; @@ -1603,14 +1605,23 @@ namespace Nz::ShaderAst for (UInt32 i = 0; i < arrayType.length; ++i) { + PushScope(); + + auto innerMulti = std::make_unique(); + innerMulti->sourceLocation = node.sourceLocation; + auto accessIndex = ShaderBuilder::AccessIndex(CloneExpression(expr), ShaderBuilder::Constant(i)); Validate(*accessIndex); auto elementVariable = ShaderBuilder::DeclareVariable(node.varName, std::move(accessIndex)); Validate(*elementVariable); - multi->statements.emplace_back(std::move(elementVariable)); - multi->statements.emplace_back(Unscope(CloneStatement(node.statement))); + innerMulti->statements.emplace_back(std::move(elementVariable)); + innerMulti->statements.emplace_back(Unscope(CloneStatement(node.statement))); + + multi->statements.emplace_back(ShaderBuilder::Scoped(std::move(innerMulti))); + + PopScope(); } } diff --git a/tests/Engine/Shader/ConstTests.cpp b/tests/Engine/Shader/ConstTests.cpp index ee3f80e51..d70833f1a 100644 --- a/tests/Engine/Shader/ConstTests.cpp +++ b/tests/Engine/Shader/ConstTests.cpp @@ -159,16 +159,31 @@ fn main() fn main() { let color: vec4[f32] = (0.000000).xxxx; - let i: i32 = 0; - color += data.lights[i].color; - let i: i32 = 2; - color += data.lights[i].color; - let i: i32 = 4; - color += data.lights[i].color; - let i: i32 = 6; - color += data.lights[i].color; - let i: i32 = 8; - color += data.lights[i].color; + { + let i: i32 = 0; + color += data.lights[i].color; + } + + { + let i: i32 = 2; + color += data.lights[i].color; + } + + { + let i: i32 = 4; + color += data.lights[i].color; + } + + { + let i: i32 = 6; + color += data.lights[i].color; + } + + { + let i: i32 = 8; + color += data.lights[i].color; + } + } )"); } @@ -219,12 +234,21 @@ fn main() fn main() { let color: vec4[f32] = (0.000000).xxxx; - let light: Light = data.lights[0]; - color += light.color; - let light: Light = data.lights[1]; - color += light.color; - let light: Light = data.lights[2]; - color += light.color; + { + let light: Light = data.lights[0]; + color += light.color; + } + + { + let light: Light = data.lights[1]; + color += light.color; + } + + { + let light: Light = data.lights[2]; + color += light.color; + } + } )"); }