From 91d89b4abfdac7a1664854aa008efdc9c19e2c3a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 22 Oct 2026 20:56:08 +0200 Subject: [PATCH] Java shader packs: modf into a vector component works in an initialiser The comma form of modf (`v.y = trunc(x), x - trunc(x)`) printed without brackets in a declaration's initialiser, which naga's GLSL front end then read as a second declarator. A unary + around it has glsl-lang print the brackets. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-shaderpack/src/translate.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/horizon-shaderpack/src/translate.rs b/crates/horizon-shaderpack/src/translate.rs index 184185cdb..e53b4895b 100644 --- a/crates/horizon-shaderpack/src/translate.rs +++ b/crates/horizon-shaderpack/src/translate.rs @@ -1855,7 +1855,9 @@ impl<'a> Legaliser<'a> { && !matches!(args[1].content, ast::ExprData::Variable(_)) { // `modf(x, v.y)` (Photon): WGSL can't point at a vector - // component, so no `out` parameter: `(v.y = trunc(x), x - trunc(x))`. + // component, so no `out` parameter: `+(v.y = trunc(x), x - trunc(x))` + // (the unary `+` has the comma printed in brackets, also in an + // initialiser). let (x, whole) = (args[0].clone(), args[1].clone()); let assign = ast::ExprData::Assignment( Box::new(whole), @@ -1869,7 +1871,9 @@ impl<'a> Legaliser<'a> { Box::new(call("trunc", vec![x])), ) .into_node(); - *e = ast::ExprData::Comma(Box::new(assign), Box::new(fraction)).into_node(); + let comma = ast::ExprData::Comma(Box::new(assign), Box::new(fraction)).into_node(); + *e = ast::ExprData::Unary(ast::UnaryOpData::Add.into_node(), Box::new(comma)) + .into_node(); return; } if let Some((_, new)) = LEGACY_CALLS.iter().find(|(old, _)| *old == name) {