Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(shaders): stop flipping every cooked WGSL twin upside down

esengine2ede6edd3d7e
diff --git a/build-tools/shader-twins/naga-spv2wgsl.wasm b/build-tools/shader-twins/naga-spv2wgsl.wasm
index 0e38c45ab..286552bcd 100644
Binary files a/build-tools/shader-twins/naga-spv2wgsl.wasm and b/build-tools/shader-twins/naga-spv2wgsl.wasm differ
diff --git a/desktop/public/scenes/mat-builtin-lit/lit.esshader b/desktop/public/scenes/mat-builtin-lit/lit.esshader
index e7cc8723f..f4fd0903a 100644
--- a/desktop/public/scenes/mat-builtin-lit/lit.esshader
+++ b/desktop/public/scenes/mat-builtin-lit/lit.esshader
@@ -89,13 +89,11 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_color_1 = a_color;
a_texCoord_1 = a_texCoord;
main_1();
- let _e12 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e12);
- let _e14 = unnamed.gl_Position;
- let _e15 = v_color;
- let _e16 = v_texCoord;
- let _e17 = v_worldPos;
- return VertexOutput(_e14, _e15, _e16, _e17);
+ let _e11 = unnamed.gl_Position;
+ let _e12 = v_color;
+ let _e13 = v_texCoord;
+ let _e14 = v_worldPos;
+ return VertexOutput(_e11, _e12, _e13, _e14);
}
#pragma end
diff --git a/desktop/public/scenes/mat-dissolve/dissolve.esshader b/desktop/public/scenes/mat-dissolve/dissolve.esshader
index 5810c4243..9bc908005 100644
--- a/desktop/public/scenes/mat-dissolve/dissolve.esshader
+++ b/desktop/public/scenes/mat-dissolve/dissolve.esshader
@@ -97,12 +97,10 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_color_1 = a_color;
a_texCoord_1 = a_texCoord;
main_1();
- let _e11 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e11);
- let _e13 = unnamed.gl_Position;
- let _e14 = v_color;
- let _e15 = v_texCoord;
- return VertexOutput(_e13, _e14, _e15);
+ let _e10 = unnamed.gl_Position;
+ let _e11 = v_color;
+ let _e12 = v_texCoord;
+ return VertexOutput(_e10, _e11, _e12);
}
#pragma end
diff --git a/desktop/public/scenes/mat-graph/graph-tint.esshader b/desktop/public/scenes/mat-graph/graph-tint.esshader
index 1eea44c2b..10cc80c71 100644
--- a/desktop/public/scenes/mat-graph/graph-tint.esshader
+++ b/desktop/public/scenes/mat-graph/graph-tint.esshader
@@ -103,12 +103,10 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_texCoord_1 = a_texCoord;
a_texIndex_1 = a_texIndex;
main_1();
- let _e13 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e13);
- let _e15 = unnamed.gl_Position;
- let _e16 = v_color;
- let _e17 = v_texCoord;
- return VertexOutput(_e15, _e16, _e17);
+ let _e12 = unnamed.gl_Position;
+ let _e13 = v_color;
+ let _e14 = v_texCoord;
+ return VertexOutput(_e12, _e13, _e14);
}
#pragma end
diff --git a/desktop/public/scenes/mat-lit-flatnormal/lit-fn.esshader b/desktop/public/scenes/mat-lit-flatnormal/lit-fn.esshader
index 69fc3db76..80a3183b9 100644
--- a/desktop/public/scenes/mat-lit-flatnormal/lit-fn.esshader
+++ b/desktop/public/scenes/mat-lit-flatnormal/lit-fn.esshader
@@ -109,13 +109,11 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_texCoord_1 = a_texCoord;
a_texIndex_1 = a_texIndex;
main_1();
- let _e14 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e14);
- let _e16 = unnamed.gl_Position;
- let _e17 = v_color;
- let _e18 = v_texCoord;
- let _e19 = v_worldPos;
- return VertexOutput(_e16, _e17, _e18, _e19);
+ let _e13 = unnamed.gl_Position;
+ let _e14 = v_color;
+ let _e15 = v_texCoord;
+ let _e16 = v_worldPos;
+ return VertexOutput(_e13, _e14, _e15, _e16);
}
#pragma end
diff --git a/desktop/public/scenes/mat-lit-normal/lit-normal.esshader b/desktop/public/scenes/mat-lit-normal/lit-normal.esshader
index 261c7f5af..8cab30c0e 100644
--- a/desktop/public/scenes/mat-lit-normal/lit-normal.esshader
+++ b/desktop/public/scenes/mat-lit-normal/lit-normal.esshader
@@ -109,13 +109,11 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_texCoord_1 = a_texCoord;
a_texIndex_1 = a_texIndex;
main_1();
- let _e14 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e14);
- let _e16 = unnamed.gl_Position;
- let _e17 = v_color;
- let _e18 = v_texCoord;
- let _e19 = v_worldPos;
- return VertexOutput(_e16, _e17, _e18, _e19);
+ let _e13 = unnamed.gl_Position;
+ let _e14 = v_color;
+ let _e15 = v_texCoord;
+ let _e16 = v_worldPos;
+ return VertexOutput(_e13, _e14, _e15, _e16);
}
#pragma end
diff --git a/desktop/public/scenes/mat-lit/lit.esshader b/desktop/public/scenes/mat-lit/lit.esshader
index 33cb4aacb..4f37ba460 100644
--- a/desktop/public/scenes/mat-lit/lit.esshader
+++ b/desktop/public/scenes/mat-lit/lit.esshader
@@ -104,13 +104,11 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_texCoord_1 = a_texCoord;
a_texIndex_1 = a_texIndex;
main_1();
- let _e14 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e14);
- let _e16 = unnamed.gl_Position;
- let _e17 = v_color;
- let _e18 = v_texCoord;
- let _e19 = v_worldPos;
- return VertexOutput(_e16, _e17, _e18, _e19);
+ let _e13 = unnamed.gl_Position;
+ let _e14 = v_color;
+ let _e15 = v_texCoord;
+ let _e16 = v_worldPos;
+ return VertexOutput(_e13, _e14, _e15, _e16);
}
#pragma end
diff --git a/desktop/public/scenes/mat-tex/masked.esshader b/desktop/public/scenes/mat-tex/masked.esshader
index ee3c12822..06fd9d42c 100644
--- a/desktop/public/scenes/mat-tex/masked.esshader
+++ b/desktop/public/scenes/mat-tex/masked.esshader
@@ -96,12 +96,10 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_texCoord_1 = a_texCoord;
a_texIndex_1 = a_texIndex;
main_1();
- let _e13 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e13);
- let _e15 = unnamed.gl_Position;
- let _e16 = v_color;
- let _e17 = v_texCoord;
- return VertexOutput(_e15, _e16, _e17);
+ let _e12 = unnamed.gl_Position;
+ let _e13 = v_color;
+ let _e14 = v_texCoord;
+ return VertexOutput(_e12, _e13, _e14);
}
#pragma end
diff --git a/desktop/public/scenes/mat-tint/tint.esshader b/desktop/public/scenes/mat-tint/tint.esshader
index 021a763d3..f8d67a899 100644
--- a/desktop/public/scenes/mat-tint/tint.esshader
+++ b/desktop/public/scenes/mat-tint/tint.esshader
@@ -80,3 +80,146 @@ struct VSOut {
return texColor * v.v_color * mc.u_tint;
}
#pragma end
+
+#pragma vertex wgsl full
+// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
+// Regenerate after changing the GLSL stages above.
+// source-hash: 56ecfb04e09e8ec6
+struct gl_PerVertex {
+ @builtin(position) gl_Position: vec4<f32>,
+ gl_PointSize: f32,
+}
+
+struct FrameConstants {
+ u_projection: mat4x4<f32>,
+}
+
+struct TimeConstants {
+ u_time: vec4<f32>,
+ u_viewport: vec4<f32>,
+}
+
+struct MaterialConstants {
+ u_tint: vec4<f32>,
+}
+
+struct VertexOutput {
+ @builtin(position) gl_Position: vec4<f32>,
+ @location(0) member: vec4<f32>,
+ @location(1) member_1: vec2<f32>,
+}
+
+var<private> unnamed: gl_PerVertex = gl_PerVertex(vec4<f32>(0f, 0f, 0f, 1f), 1f);
+@group(0) @binding(0)
+var<uniform> unnamed_1: FrameConstants;
+var<private> a_position_1: vec2<f32>;
+var<private> v_color: vec4<f32>;
+var<private> a_color_1: vec4<f32>;
+var<private> v_texCoord: vec2<f32>;
+var<private> a_texCoord_1: vec2<f32>;
+@group(0) @binding(3)
+var<uniform> unnamed_2: TimeConstants;
+@group(0) @binding(1)
+var<uniform> unnamed_3: MaterialConstants;
+var<private> a_texIndex_1: f32;
+
+fn main_1() {
+ let _e14 = unnamed_1.u_projection;
+ let _e15 = a_position_1;
+ unnamed.gl_Position = (_e14 * vec4<f32>(_e15.x, _e15.y, 0f, 1f));
+ let _e21 = a_color_1;
+ v_color = _e21;
+ let _e22 = a_texCoord_1;
+ v_texCoord = _e22;
+ return;
+}
+
+@vertex
+fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>, @location(3) a_texIndex: f32) -> VertexOutput {
+ a_position_1 = a_position;
+ a_color_1 = a_color;
+ a_texCoord_1 = a_texCoord;
+ a_texIndex_1 = a_texIndex;
+ main_1();
+ let _e12 = unnamed.gl_Position;
+ let _e13 = v_color;
+ let _e14 = v_texCoord;
+ return VertexOutput(_e12, _e13, _e14);
+}
+#pragma end
+
+#pragma fragment wgsl full
+// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
+// Regenerate after changing the GLSL stages above.
+// source-hash: 56ecfb04e09e8ec6
+struct MaterialConstants {
+ u_tint: vec4<f32>,
+}
+
+struct TimeConstants {
+ u_time: vec4<f32>,
+ u_viewport: vec4<f32>,
+}
+
+@group(1) @binding(0)
+var es_bt0_est: texture_2d<f32>;
+@group(1) @binding(8)
+var es_bt0_ess: sampler;
+var<private> v_texCoord_1: vec2<f32>;
+var<private> fragColor: vec4<f32>;
+var<private> v_color_1: vec4<f32>;
+@group(0) @binding(1)
+var<uniform> unnamed: MaterialConstants;
+@group(0) @binding(3)
+var<uniform> unnamed_1: TimeConstants;
+@group(1) @binding(1)
+var es_bt1_est: texture_2d<f32>;
+@group(1) @binding(9)
+var es_bt1_ess: sampler;
+@group(1) @binding(2)
+var es_bt2_est: texture_2d<f32>;
+@group(1) @binding(10)
+var es_bt2_ess: sampler;
+@group(1) @binding(3)
+var es_bt3_est: texture_2d<f32>;
+@group(1) @binding(11)
+var es_bt3_ess: sampler;
+@group(1) @binding(4)
+var es_bt4_est: texture_2d<f32>;
+@group(1) @binding(12)
+var es_bt4_ess: sampler;
+@group(1) @binding(5)
+var es_bt5_est: texture_2d<f32>;
+@group(1) @binding(13)
+var es_bt5_ess: sampler;
+@group(1) @binding(6)
+var es_bt6_est: texture_2d<f32>;
+@group(1) @binding(14)
+var es_bt6_ess: sampler;
+@group(1) @binding(7)
+var es_bt7_est: texture_2d<f32>;
+@group(1) @binding(15)
+var es_bt7_ess: sampler;
+
+fn main_1() {
+ var texColor: vec4<f32>;
+
+ let _e23 = v_texCoord_1;
+ let _e24 = textureSample(es_bt0_est, es_bt0_ess, _e23);
+ texColor = _e24;
+ let _e25 = texColor;
+ let _e26 = v_color_1;
+ let _e29 = unnamed.u_tint;
+ fragColor = ((_e25 * _e26) * _e29);
+ return;
+}
+
+@fragment
+fn fs_main(@location(1) v_texCoord: vec2<f32>, @location(0) v_color: vec4<f32>) -> @location(0) vec4<f32> {
+ v_texCoord_1 = v_texCoord;
+ v_color_1 = v_color;
+ main_1();
+ let _e5 = fragColor;
+ return _e5;
+}
+#pragma end
diff --git a/examples/effects-gallery/assets/materials/dissolve.esshader b/examples/effects-gallery/assets/materials/dissolve.esshader
index 5810c4243..9bc908005 100644
--- a/examples/effects-gallery/assets/materials/dissolve.esshader
+++ b/examples/effects-gallery/assets/materials/dissolve.esshader
@@ -97,12 +97,10 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_color_1 = a_color;
a_texCoord_1 = a_texCoord;
main_1();
- let _e11 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e11);
- let _e13 = unnamed.gl_Position;
- let _e14 = v_color;
- let _e15 = v_texCoord;
- return VertexOutput(_e13, _e14, _e15);
+ let _e10 = unnamed.gl_Position;
+ let _e11 = v_color;
+ let _e12 = v_texCoord;
+ return VertexOutput(_e10, _e11, _e12);
}
#pragma end
diff --git a/examples/effects-gallery/assets/materials/hit-flash.esshader b/examples/effects-gallery/assets/materials/hit-flash.esshader
index ffb62b204..ac5fbde90 100644
--- a/examples/effects-gallery/assets/materials/hit-flash.esshader
+++ b/examples/effects-gallery/assets/materials/hit-flash.esshader
@@ -80,12 +80,10 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_color_1 = a_color;
a_texCoord_1 = a_texCoord;
main_1();
- let _e11 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e11);
- let _e13 = unnamed.gl_Position;
- let _e14 = v_color;
- let _e15 = v_texCoord;
- return VertexOutput(_e13, _e14, _e15);
+ let _e10 = unnamed.gl_Position;
+ let _e11 = v_color;
+ let _e12 = v_texCoord;
+ return VertexOutput(_e10, _e11, _e12);
}
#pragma end
diff --git a/examples/effects-gallery/assets/materials/outline.esshader b/examples/effects-gallery/assets/materials/outline.esshader
index 8abf34dff..98e4d1366 100644
--- a/examples/effects-gallery/assets/materials/outline.esshader
+++ b/examples/effects-gallery/assets/materials/outline.esshader
@@ -89,12 +89,10 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_color_1 = a_color;
a_texCoord_1 = a_texCoord;
main_1();
- let _e11 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e11);
- let _e13 = unnamed.gl_Position;
- let _e14 = v_color;
- let _e15 = v_texCoord;
- return VertexOutput(_e13, _e14, _e15);
+ let _e10 = unnamed.gl_Position;
+ let _e11 = v_color;
+ let _e12 = v_texCoord;
+ return VertexOutput(_e10, _e11, _e12);
}
#pragma end
diff --git a/examples/effects-gallery/assets/materials/pixelate.esshader b/examples/effects-gallery/assets/materials/pixelate.esshader
index 3abd64bec..537419ce9 100644
--- a/examples/effects-gallery/assets/materials/pixelate.esshader
+++ b/examples/effects-gallery/assets/materials/pixelate.esshader
@@ -77,12 +77,10 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_color_1 = a_color;
a_texCoord_1 = a_texCoord;
main_1();
- let _e11 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e11);
- let _e13 = unnamed.gl_Position;
- let _e14 = v_color;
- let _e15 = v_texCoord;
- return VertexOutput(_e13, _e14, _e15);
+ let _e10 = unnamed.gl_Position;
+ let _e11 = v_color;
+ let _e12 = v_texCoord;
+ return VertexOutput(_e10, _e11, _e12);
}
#pragma end
diff --git a/examples/effects-gallery/assets/materials/uv-scroll.esshader b/examples/effects-gallery/assets/materials/uv-scroll.esshader
index b8202a32b..91d7e065c 100644
--- a/examples/effects-gallery/assets/materials/uv-scroll.esshader
+++ b/examples/effects-gallery/assets/materials/uv-scroll.esshader
@@ -78,12 +78,10 @@ fn vs_main(@location(0) a_position: vec2<f32>, @location(1) a_color: vec4<f32>,
a_color_1 = a_color;
a_texCoord_1 = a_texCoord;
main_1();
- let _e11 = unnamed.gl_Position.y;
- unnamed.gl_Position.y = -(_e11);
- let _e13 = unnamed.gl_Position;
- let _e14 = v_color;
- let _e15 = v_texCoord;
- return VertexOutput(_e13, _e14, _e15);
+ let _e10 = unnamed.gl_Position;
+ let _e11 = v_color;
+ let _e12 = v_texCoord;
+ return VertexOutput(_e10, _e11, _e12);
}
#pragma end
diff --git a/tools/naga-spv2wgsl/src/main.rs b/tools/naga-spv2wgsl/src/main.rs
index 58e2438bb..59ffd80fd 100644
--- a/tools/naga-spv2wgsl/src/main.rs
+++ b/tools/naga-spv2wgsl/src/main.rs
@@ -5,8 +5,7 @@
//! A deliberately tiny wrapper over naga's spv-in / wgsl-out so the whole
//! program is stdin → stdout: no filesystem, no arguments — the shape that
//! makes the wasm32-wasip1 build trivially runnable under node:wasi on any
-//! machine, with no cargo/naga-cli install. Options mirror naga-cli defaults
-//! (coordinate-space adjustment on, full validation).
+//! machine, with no cargo/naga-cli install.
//!
//! Build (artifact is committed, see build-tools/shader-twins/README.md):
//! rustup target add wasm32-wasip1
@@ -25,8 +24,12 @@ fn main() {
fail("read stdin", e.to_string());
}
+ // The input is SPIR-V that glslang produced from GLSL ES 300 WITHOUT --invert-y,
+ // so gl_Position still carries the GL clip space — which is WebGPU's. naga-cli's
+ // default assumes Vulkan-authored SPIR-V and emits `pos.y = -pos.y`; applied here
+ // that flip is spurious and every twin came out upside down on a WGSL backend.
let options = naga::front::spv::Options {
- adjust_coordinate_space: true,
+ adjust_coordinate_space: false,
strict_capabilities: false,
..Default::default()
};