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(render): a material that writes only its fragment draws on a mesh under WebGPU

esengine92d4903d6b9c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef4069038..c4958ba7b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -355,6 +355,13 @@ published separately; it ships inside the editor.
### Fixed
+- **A material that writes only its fragment stage draws on a mesh under WebGPU and on
+ devices.** Its generated WebGPU twin carried a copy of the vertex stage made for
+ sprites, so on a mesh the device rejected the pipeline and the surface never drew —
+ `physics-3d`'s decal target on Android among them. Twins for such materials now
+ carry only the fragment stage, and the engine supplies the vertex stage for every
+ source; an older twin is regenerated when the project is opened or exported.
+
- **Opening a project from inside the editor no longer leaves the loading screen up.**
An agent's `open_project` while a project was already open — once that project had
finished loading — put the loading screen back over the editor with nothing left to
diff --git a/examples/effects-gallery/assets/materials/dissolve.esshader b/examples/effects-gallery/assets/materials/dissolve.esshader
index 92d87fcfb..f3af38905 100644
--- a/examples/effects-gallery/assets/materials/dissolve.esshader
+++ b/examples/effects-gallery/assets/materials/dissolve.esshader
@@ -36,91 +36,6 @@ void main() {
}
#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: 0a687499da49fe50
-// assembled-hash: 3b7c3069a5e2ac75
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct MaterialConstants {
- u_progress: f32,
- u_edgeColor: vec4<f32>,
- u_edgeWidth: f32,
- u_noiseScale: f32,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(0) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(1) member_1: vec2<f32>,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> 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;
-@group(0) @binding(4)
-var<uniform> unnamed_4: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e15 = a_position_1;
- world = vec4<f32>(_e15.x, _e15.y, _e15.z, 1f);
- let _e20 = a_color_1;
- v_color = _e20;
- let _e22 = unnamed_1.u_projection;
- let _e23 = world;
- unnamed.gl_Position = (_e22 * _e23);
- let _e26 = a_texCoord_1;
- v_texCoord = _e26;
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- main_1();
- let _e10 = v_color;
- let _e11 = unnamed.gl_Position;
- let _e12 = v_texCoord;
- return VertexOutput(_e10, _e11, _e12);
-}
-#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.
diff --git a/examples/effects-gallery/assets/materials/hit-flash.esshader b/examples/effects-gallery/assets/materials/hit-flash.esshader
index 439ff4d28..0d325ccd7 100644
--- a/examples/effects-gallery/assets/materials/hit-flash.esshader
+++ b/examples/effects-gallery/assets/materials/hit-flash.esshader
@@ -21,89 +21,6 @@ void main() {
}
#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: 674537b45fb865fb
-// assembled-hash: 51a5fa5bc7072ae0
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct MaterialConstants {
- u_flash: f32,
- u_flashColor: vec4<f32>,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(0) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(1) member_1: vec2<f32>,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> 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;
-@group(0) @binding(4)
-var<uniform> unnamed_4: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e15 = a_position_1;
- world = vec4<f32>(_e15.x, _e15.y, _e15.z, 1f);
- let _e20 = a_color_1;
- v_color = _e20;
- let _e22 = unnamed_1.u_projection;
- let _e23 = world;
- unnamed.gl_Position = (_e22 * _e23);
- let _e26 = a_texCoord_1;
- v_texCoord = _e26;
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- main_1();
- let _e10 = v_color;
- let _e11 = unnamed.gl_Position;
- let _e12 = v_texCoord;
- return VertexOutput(_e10, _e11, _e12);
-}
-#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.
diff --git a/examples/effects-gallery/assets/materials/outline.esshader b/examples/effects-gallery/assets/materials/outline.esshader
index f3dd29fcd..6aa505ca4 100644
--- a/examples/effects-gallery/assets/materials/outline.esshader
+++ b/examples/effects-gallery/assets/materials/outline.esshader
@@ -30,89 +30,6 @@ void main() {
}
#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: 7ed4f4686c6bfd8d
-// assembled-hash: 659232dd4e620239
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct MaterialConstants {
- u_outlineColor: vec4<f32>,
- u_outlineWidth: f32,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(0) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(1) member_1: vec2<f32>,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> 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;
-@group(0) @binding(4)
-var<uniform> unnamed_4: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e15 = a_position_1;
- world = vec4<f32>(_e15.x, _e15.y, _e15.z, 1f);
- let _e20 = a_color_1;
- v_color = _e20;
- let _e22 = unnamed_1.u_projection;
- let _e23 = world;
- unnamed.gl_Position = (_e22 * _e23);
- let _e26 = a_texCoord_1;
- v_texCoord = _e26;
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- main_1();
- let _e10 = v_color;
- let _e11 = unnamed.gl_Position;
- let _e12 = v_texCoord;
- return VertexOutput(_e10, _e11, _e12);
-}
-#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.
diff --git a/examples/effects-gallery/assets/materials/pixelate.esshader b/examples/effects-gallery/assets/materials/pixelate.esshader
index 1bee84001..00edc2805 100644
--- a/examples/effects-gallery/assets/materials/pixelate.esshader
+++ b/examples/effects-gallery/assets/materials/pixelate.esshader
@@ -19,88 +19,6 @@ void main() {
}
#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: 0c2fb4b31599ec7a
-// assembled-hash: aa5efc32d552a8db
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct MaterialConstants {
- u_pixels: f32,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(0) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(1) member_1: vec2<f32>,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> 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;
-@group(0) @binding(4)
-var<uniform> unnamed_4: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e15 = a_position_1;
- world = vec4<f32>(_e15.x, _e15.y, _e15.z, 1f);
- let _e20 = a_color_1;
- v_color = _e20;
- let _e22 = unnamed_1.u_projection;
- let _e23 = world;
- unnamed.gl_Position = (_e22 * _e23);
- let _e26 = a_texCoord_1;
- v_texCoord = _e26;
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- main_1();
- let _e10 = v_color;
- let _e11 = unnamed.gl_Position;
- let _e12 = v_texCoord;
- return VertexOutput(_e10, _e11, _e12);
-}
-#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.
diff --git a/examples/effects-gallery/assets/materials/uv-scroll.esshader b/examples/effects-gallery/assets/materials/uv-scroll.esshader
index aabefe441..49ae3f581 100644
--- a/examples/effects-gallery/assets/materials/uv-scroll.esshader
+++ b/examples/effects-gallery/assets/materials/uv-scroll.esshader
@@ -20,88 +20,6 @@ void main() {
}
#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: 301c5b2b73d966f3
-// assembled-hash: 31e405ee96a6823e
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct MaterialConstants {
- u_scrollSpeed: vec2<f32>,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(0) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(1) member_1: vec2<f32>,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> 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;
-@group(0) @binding(4)
-var<uniform> unnamed_4: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e15 = a_position_1;
- world = vec4<f32>(_e15.x, _e15.y, _e15.z, 1f);
- let _e20 = a_color_1;
- v_color = _e20;
- let _e22 = unnamed_1.u_projection;
- let _e23 = world;
- unnamed.gl_Position = (_e22 * _e23);
- let _e26 = a_texCoord_1;
- v_texCoord = _e26;
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- main_1();
- let _e10 = v_color;
- let _e11 = unnamed.gl_Position;
- let _e12 = v_texCoord;
- return VertexOutput(_e10, _e11, _e12);
-}
-#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.
diff --git a/examples/physics-3d/assets/materials/decal-target.esshader b/examples/physics-3d/assets/materials/decal-target.esshader
index fdaa12647..5df96f7c0 100644
--- a/examples/physics-3d/assets/materials/decal-target.esshader
+++ b/examples/physics-3d/assets/materials/decal-target.esshader
@@ -23,100 +23,6 @@ void main() {
}
#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: 144f76db1f5f521a
-// assembled-hash: 463a3c498ff3f527
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct MaterialConstants {
- u_tint: vec4<f32>,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(1) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(2) member_1: vec2<f32>,
- @location(6) member_2: vec2<f32>,
- @location(0) @interpolate(flat) member_3: f32,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> v_texCoord: vec2<f32>;
-var<private> a_texCoord_1: vec2<f32>;
-var<private> v_worldPos: vec2<f32>;
-var<private> v_probeSlot: f32;
-var<private> gl_InstanceIndex_1: i32;
-@group(0) @binding(3)
-var<uniform> unnamed_2: TimeConstants;
-@group(0) @binding(1)
-var<uniform> unnamed_3: MaterialConstants;
-@group(0) @binding(8)
-var<uniform> unnamed_4: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e18 = a_position_1;
- world = vec4<f32>(_e18.x, _e18.y, _e18.z, 1f);
- let _e23 = a_color_1;
- v_color = _e23;
- let _e25 = unnamed_1.u_projection;
- let _e26 = world;
- unnamed.gl_Position = (_e25 * _e26);
- let _e29 = a_texCoord_1;
- v_texCoord = _e29;
- let _e30 = world;
- v_worldPos = _e30.xy;
- let _e32 = gl_InstanceIndex_1;
- v_probeSlot = f32(_e32);
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>, @builtin(instance_index) gl_InstanceIndex: u32) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- gl_InstanceIndex_1 = i32(gl_InstanceIndex);
- main_1();
- let _e15 = v_color;
- let _e16 = unnamed.gl_Position;
- let _e17 = v_texCoord;
- let _e18 = v_worldPos;
- let _e19 = v_probeSlot;
- return VertexOutput(_e15, _e16, _e17, _e18, _e19);
-}
-#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.
@@ -216,7 +122,7 @@ fn main_1() {
}
@fragment
-fn fs_main(@location(2) v_texCoord: vec2<f32>, @location(0) @interpolate(flat) v_probeSlot: f32, @location(1) v_color: vec4<f32>) -> @location(0) vec4<f32> {
+fn fs_main(@location(1) v_texCoord: vec2<f32>, @location(6) @interpolate(flat) v_probeSlot: f32, @location(0) v_color: vec4<f32>) -> @location(0) vec4<f32> {
v_texCoord_1 = v_texCoord;
v_probeSlot_1 = v_probeSlot;
v_color_1 = v_color;
diff --git a/fixtures/scenes/depth-layers/opaque.esshader b/fixtures/scenes/depth-layers/opaque.esshader
index 08673f0ad..1cc21c854 100644
--- a/fixtures/scenes/depth-layers/opaque.esshader
+++ b/fixtures/scenes/depth-layers/opaque.esshader
@@ -20,82 +20,6 @@ void main() {
}
#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: 930787555114ce9c
-// assembled-hash: cab87529431e525a
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(0) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(1) member_1: vec2<f32>,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> v_texCoord: vec2<f32>;
-var<private> a_texCoord_1: vec2<f32>;
-@group(0) @binding(3)
-var<uniform> unnamed_2: TimeConstants;
-@group(0) @binding(4)
-var<uniform> unnamed_3: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e14 = a_position_1;
- world = vec4<f32>(_e14.x, _e14.y, _e14.z, 1f);
- let _e19 = a_color_1;
- v_color = _e19;
- let _e21 = unnamed_1.u_projection;
- let _e22 = world;
- unnamed.gl_Position = (_e21 * _e22);
- let _e25 = a_texCoord_1;
- v_texCoord = _e25;
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- main_1();
- let _e10 = v_color;
- let _e11 = unnamed.gl_Position;
- let _e12 = v_texCoord;
- return VertexOutput(_e10, _e11, _e12);
-}
-#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.
diff --git a/fixtures/scenes/mat-builtin-lit/lit.esshader b/fixtures/scenes/mat-builtin-lit/lit.esshader
index 7f6a96f99..f275ca366 100644
--- a/fixtures/scenes/mat-builtin-lit/lit.esshader
+++ b/fixtures/scenes/mat-builtin-lit/lit.esshader
@@ -23,104 +23,6 @@ void main() {
}
#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: 5330079245724fa2
-// assembled-hash: 361c412eb703196f
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct MaterialConstants {
- u_tint: vec4<f32>,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(1) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(2) member_1: vec2<f32>,
- @location(6) member_2: vec2<f32>,
- @location(0) @interpolate(flat) member_3: f32,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> v_texCoord: vec2<f32>;
-var<private> a_texCoord_1: vec2<f32>;
-var<private> v_worldPos: vec2<f32>;
-var<private> v_probeSlot: f32;
-var<private> gl_InstanceIndex_1: i32;
-@group(0) @binding(3)
-var<uniform> unnamed_2: TimeConstants;
-@group(0) @binding(1)
-var<uniform> unnamed_3: MaterialConstants;
-@group(1) @binding(16)
-var u_normalMap_est: texture_2d<f32>;
-@group(1) @binding(24)
-var u_normalMap_ess: sampler;
-@group(0) @binding(8)
-var<uniform> unnamed_4: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e20 = a_position_1;
- world = vec4<f32>(_e20.x, _e20.y, _e20.z, 1f);
- let _e25 = a_color_1;
- v_color = _e25;
- let _e27 = unnamed_1.u_projection;
- let _e28 = world;
- unnamed.gl_Position = (_e27 * _e28);
- let _e31 = a_texCoord_1;
- v_texCoord = _e31;
- let _e32 = world;
- v_worldPos = _e32.xy;
- let _e34 = gl_InstanceIndex_1;
- v_probeSlot = f32(_e34);
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>, @builtin(instance_index) gl_InstanceIndex: u32) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- gl_InstanceIndex_1 = i32(gl_InstanceIndex);
- main_1();
- let _e15 = v_color;
- let _e16 = unnamed.gl_Position;
- let _e17 = v_texCoord;
- let _e18 = v_worldPos;
- let _e19 = v_probeSlot;
- return VertexOutput(_e15, _e16, _e17, _e18, _e19);
-}
-#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.
@@ -1213,7 +1115,7 @@ fn main_1() {
}
@fragment
-fn fs_main(@location(0) @interpolate(flat) v_probeSlot: f32, @location(2) v_texCoord: vec2<f32>, @location(1) v_color: vec4<f32>, @location(6) v_worldPos: vec2<f32>) -> @location(0) vec4<f32> {
+fn fs_main(@location(6) @interpolate(flat) v_probeSlot: f32, @location(1) v_texCoord: vec2<f32>, @location(0) v_color: vec4<f32>, @location(2) v_worldPos: vec2<f32>) -> @location(0) vec4<f32> {
v_probeSlot_1 = v_probeSlot;
v_texCoord_1 = v_texCoord;
v_color_1 = v_color;
diff --git a/fixtures/scenes/mat-dissolve/dissolve.esshader b/fixtures/scenes/mat-dissolve/dissolve.esshader
index 92d87fcfb..f3af38905 100644
--- a/fixtures/scenes/mat-dissolve/dissolve.esshader
+++ b/fixtures/scenes/mat-dissolve/dissolve.esshader
@@ -36,91 +36,6 @@ void main() {
}
#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: 0a687499da49fe50
-// assembled-hash: 3b7c3069a5e2ac75
-struct gl_PerVertex {
- @builtin(position) gl_Position: vec4<f32>,
- gl_PointSize: f32,
-}
-
-struct FrameConstants {
- u_projection: mat4x4<f32>,
- u_camera: vec4<f32>,
- u_inverseViewProjection: mat4x4<f32>,
-}
-
-struct TimeConstants {
- u_time: vec4<f32>,
- u_viewport: vec4<f32>,
-}
-
-struct MaterialConstants {
- u_progress: f32,
- u_edgeColor: vec4<f32>,
- u_edgeWidth: f32,
- u_noiseScale: f32,
-}
-
-struct InstanceConstants {
- u_instanceBase: vec4<u32>,
-}
-
-struct VertexOutput {
- @location(0) member: vec4<f32>,
- @builtin(position) gl_Position: vec4<f32>,
- @location(1) member_1: vec2<f32>,
-}
-
-var<private> a_position_1: vec3<f32>;
-var<private> v_color: vec4<f32>;
-var<private> a_color_1: vec4<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> 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;
-@group(0) @binding(4)
-var<uniform> unnamed_4: InstanceConstants;
-@group(1) @binding(23)
-var u_instanceData_est: texture_2d<f32>;
-@group(1) @binding(31)
-var u_instanceData_ess: sampler;
-
-fn main_1() {
- var world: vec4<f32>;
-
- let _e15 = a_position_1;
- world = vec4<f32>(_e15.x, _e15.y, _e15.z, 1f);
- let _e20 = a_color_1;
- v_color = _e20;
- let _e22 = unnamed_1.u_projection;
- let _e23 = world;
- unnamed.gl_Position = (_e22 * _e23);
- let _e26 = a_texCoord_1;
- v_texCoord = _e26;
- return;
-}
-
-@vertex
-fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>, @location(2) a_texCoord: vec2<f32>) -> VertexOutput {
- a_position_1 = a_position;
- a_color_1 = a_color;
- a_texCoord_1 = a_texCoord;
- main_1();
- let _e10 = v_color;
- let _e11 = unnamed.gl_Position;
- let _e12 = v_texCoord;
- return VertexOutput(_e10, _e11, _e12);
-}
-#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.
diff --git a/fixtures/scenes/mat-generated-mesh.esscene b/fixtures/scenes/mat-generated-mesh.esscene
new file mode 100644
index 000000000..f67531973
--- /dev/null
+++ b/fixtures/scenes/mat-generated-mesh.esscene
@@ -0,0 +1,78 @@
+{
+ "version": 4,
+ "name": "Main",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 400
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 200,
+ "nearPlane": 1,
+ "farPlane": 2000,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Panel",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ },
+ "scale": {
+ "x": 3.0,
+ "y": 3.0,
+ "z": 0.2
+ }
+ }
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "builtin:cube",
+ "opaque": true,
+ "lit": false,
+ "cullBackfaces": true,
+ "material": "/scenes/mat-generated-mesh/split.esmaterial",
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "layer": 0,
+ "enabled": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/mat-generated-mesh/split.esmaterial b/fixtures/scenes/mat-generated-mesh/split.esmaterial
new file mode 100644
index 000000000..451f14510
--- /dev/null
+++ b/fixtures/scenes/mat-generated-mesh/split.esmaterial
@@ -0,0 +1,11 @@
+{
+ "version": "1.0",
+ "type": "material",
+ "shader": "split.esshader",
+ "blendMode": 0,
+ "depthTest": true,
+ "depthWrite": true,
+ "properties": {
+ "u_tint": { "r": 0, "g": 1, "b": 0, "a": 1 }
+ }
+}
diff --git a/fixtures/scenes/mat-generated-mesh/split.esshader b/fixtures/scenes/mat-generated-mesh/split.esshader
new file mode 100644
index 000000000..58027cb26
--- /dev/null
+++ b/fixtures/scenes/mat-generated-mesh/split.esshader
@@ -0,0 +1,108 @@
+#pragma shader "GeneratedOnMesh"
+#pragma version 300 es
+#pragma domain Lit
+#pragma param u_tint color default(0,1,0,1)
+
+// Fragment only and no hand-written twin, drawn on a mesh: the WGSL twin is
+// generated, and the halves prove it reads the varyings where the mesh wrote them.
+#pragma fragment
+precision mediump float;
+
+in vec4 v_color;
+in vec2 v_texCoord;
+
+out vec4 fragColor;
+
+void main() {
+ fragColor = vec4(mix(vec3(1.0, 0.0, 0.0), u_tint.rgb, step(0.5, v_texCoord.x)), 1.0);
+}
+#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: 7af6948ea05e1a30
+// assembled-hash: 369dd74391d82e21
+struct MaterialConstants {
+ u_tint: vec4<f32>,
+}
+
+struct FrameConstants {
+ u_projection: mat4x4<f32>,
+ u_camera: vec4<f32>,
+ u_inverseViewProjection: mat4x4<f32>,
+}
+
+struct TimeConstants {
+ u_time: vec4<f32>,
+ u_viewport: vec4<f32>,
+}
+
+struct Light {
+ posDir: vec4<f32>,
+ color: vec4<f32>,
+ spot: vec4<f32>,
+ shadow: vec4<f32>,
+ shadowMap: vec4<f32>,
+ falloff: vec4<f32>,
+}
+
+struct LightConstants {
+ u_ambient: vec4<f32>,
+ u_lights: array<Light, 16>,
+ u_mask2DRect: vec4<f32>,
+ u_shadowMatrix: array<mat4x4<f32>, 16>,
+ u_shadowTile: array<vec4<f32>, 16>,
+ u_shadowParams: vec4<f32>,
+ u_envIrradiance: array<vec4<f32>, 9>,
+ u_envParams: vec4<f32>,
+ u_envTint: vec4<f32>,
+ u_reflParams: vec4<f32>,
+ u_reflBox: array<vec4<f32>, 30>,
+}
+
+struct ProbeConstants {
+ u_probeIrradiance: array<vec4<f32>, 1000>,
+}
+
+var<private> fragColor: vec4<f32>;
+@group(0) @binding(1)
+var<uniform> unnamed: MaterialConstants;
+var<private> v_texCoord_1: vec2<f32>;
+@group(0) @binding(0)
+var<uniform> unnamed_1: FrameConstants;
+@group(0) @binding(3)
+var<uniform> unnamed_2: TimeConstants;
+@group(0) @binding(2)
+var<uniform> unnamed_3: LightConstants;
+@group(0) @binding(7)
+var<uniform> unnamed_4: ProbeConstants;
+var<private> v_probeSlot_1: f32;
+@group(1) @binding(7)
+var u_shadow2D_est: texture_2d<f32>;
+@group(1) @binding(15)
+var u_shadow2D_ess: sampler;
+@group(1) @binding(6)
+var u_lightShape2D_est: texture_2d<f32>;
+@group(1) @binding(14)
+var u_lightShape2D_ess: sampler;
+var<private> v_color_1: vec4<f32>;
+
+fn main_1() {
+ let _e25 = unnamed.u_tint;
+ let _e28 = v_texCoord_1[0u];
+ let _e31 = mix(vec3<f32>(1f, 0f, 0f), _e25.xyz, vec3(step(0.5f, _e28)));
+ fragColor = vec4<f32>(_e31.x, _e31.y, _e31.z, 1f);
+ return;
+}
+
+@fragment
+fn fs_main(@location(1) v_texCoord: vec2<f32>, @location(6) @interpolate(flat) v_probeSlot: f32, @location(0) v_color: vec4<f32>) -> @location(0) vec4<f32> {
+ v_texCoord_1 = v_texCoord;
+ v_probeSlot_1 = v_probeSlot;
+ v_color_1 = v_color;
+ main_1();
+ let _e7 = fragColor;
+ return _e7;
+}
+#pragma end
diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cpp
index 2617e9f8f..279f8364a 100644
--- a/src/esengine/bindings/WebSDKEntry.cpp
+++ b/src/esengine/bindings/WebSDKEntry.cpp
@@ -124,6 +124,7 @@ emscripten::val esshader_cookInfo(const std::string& source, const std::string&
out.set("hasWgslVertex", parsed.wgslStages.count(resource::ShaderStage::Vertex) != 0);
out.set("hasWgslFragment", parsed.wgslStages.count(resource::ShaderStage::Fragment) != 0);
out.set("hasSwitches", !parsed.switches.empty());
+ out.set("canonicalVaryings", resource::ShaderParser::canonicalVaryingsWGSL(parsed));
// The switch/feature NAMES, so a cook can enumerate the permutations it has
// to emit a twin for — WGSL resolves them at assembly time (preprocessConditionals),
// which needs every branch present in the body.
diff --git a/src/esengine/renderer/store/MaterialStore.cpp b/src/esengine/renderer/store/MaterialStore.cpp
index d263b9679..bf02dec7d 100644
--- a/src/esengine/renderer/store/MaterialStore.cpp
+++ b/src/esengine/renderer/store/MaterialStore.cpp
@@ -105,6 +105,17 @@ u32 MaterialStore::variantProgram(u32 materialId, resource::ResourceManager& res
mesh_programs_[key] = 0;
return 0;
}
+ // A full WGSL vertex twin is a translation of the BATCH vertex stage, frozen
+ // into the file: compiled for this source it reads attributes the layout does
+ // not have, and the device rejects the pipeline.
+ const auto fullVertex = parsed.wgslStageFull.find(resource::ShaderStage::Vertex);
+ if (target == resource::ShaderTargetLanguage::WGSL
+ && fullVertex != parsed.wgslStageFull.end() && fullVertex->second) {
+ ES_LOG_WARN("MaterialStore: material {} carries a generated WGSL vertex stage, so it "
+ "cannot draw {} — regenerate its twin", materialId, what);
+ mesh_programs_[key] = 0;
+ return 0;
+ }
if (!parsed.valid || vert.empty() || frag.empty()) {
ES_LOG_WARN("MaterialStore: no {} variant for material {} ({})",
what, materialId, parsed.valid ? "stage assembly failed" : parsed.errorMessage);
diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cpp
index a7a05101b..86f601808 100644
--- a/src/esengine/resource/ShaderParser.cpp
+++ b/src/esengine/resource/ShaderParser.cpp
@@ -1652,6 +1652,11 @@ ShaderParser::AssembledStage assembleWGSLStage(const ParsedShader& parsed,
bool ShaderParser::s_linearColor = false;
+std::string ShaderParser::canonicalVaryingsWGSL(const ParsedShader& parsed) {
+ if (!parsed.valid || !parsed.vertexIsCanonical) return {};
+ return wgslCanonicalVSOut(parsed.domain == "Lit");
+}
+
void ShaderParser::setLinearColorSpace(bool linear) { s_linearColor = linear; }
bool ShaderParser::linearColorSpace() { return s_linearColor; }
diff --git a/src/esengine/resource/ShaderParser.hpp b/src/esengine/resource/ShaderParser.hpp
index 6fe55fab9..2862526b3 100644
--- a/src/esengine/resource/ShaderParser.hpp
+++ b/src/esengine/resource/ShaderParser.hpp
@@ -281,6 +281,15 @@ public:
const std::vector<std::string>& features = {},
ShaderTargetLanguage target = ShaderTargetLanguage::GLSL_ES300);
+ /**
+ * @brief The WGSL varying struct the engine's vertex stage emits for @p parsed,
+ * or empty when the shader writes its own vertex stage.
+ * @details A fragment twin generated for a shader on the engine's vertex stage
+ * reads its inputs at these locations, so every vertex source the
+ * engine retargets the material to feeds the same fragment.
+ */
+ static std::string canonicalVaryingsWGSL(const ParsedShader& parsed);
+
/**
* @brief Stable cache key for a feature set (order-independent), e.g. "GRAYSCALE|TINT".
* Consumers key their compiled-variant cache on (shader, variantKey(features)).
diff --git a/tools/gen-shader-twins.mjs b/tools/gen-shader-twins.mjs
index ea5057901..fc0c071f4 100644
--- a/tools/gen-shader-twins.mjs
+++ b/tools/gen-shader-twins.mjs
@@ -264,32 +264,42 @@ function rewriteCalls(src, fname, mapArgs) {
return result + src.slice(last);
}
+const VARYING_DECL = /^([ \t]*)(flat\s+)?(out|in)\s+((?:highp\s+)?(?:float|int|uint|[iu]?vec[234]|mat[234]))\s+(\w+)\s*;/gm;
+
/**
* Assign explicit, name-stable varying locations across both stages: glslang's
* --auto-map-locations numbers each stage independently by declaration order,
* which silently mismatches when the fragment lists varyings in another order.
*/
function assignVaryingLocations(vert, frag) {
- const varyingDecl = /^([ \t]*)(flat\s+)?(out|in)\s+((?:highp\s+)?(?:float|int|uint|[iu]?vec[234]|mat[234]))\s+(\w+)\s*;/gm;
const order = [];
- const vertOut = vert.replace(varyingDecl, (m, ws, flat, dir, type, name) => {
+ const vertOut = vert.replace(VARYING_DECL, (m, ws, flat, dir, type, name) => {
if (dir !== 'out') return m;
order.push(name);
return `${ws}layout(location = ${order.length - 1}) ${flat ?? ''}out ${type} ${name};`;
});
- const fragIn = frag.replace(varyingDecl, (m, ws, flat, dir, type, name) => {
+ return { vert: vertOut, frag: locateFragmentVaryings(frag, new Map(order.map((n, i) => [n, i]))) };
+}
+
+/** The locations of the engine's WGSL varying struct, by name. */
+export function varyingLocations(struct) {
+ return new Map([...struct.matchAll(/@location\((\d+)\)\s*(?:@interpolate\([^)]*\)\s*)?(\w+)\s*:/g)]
+ .map((m) => [m[2], Number(m[1])]));
+}
+
+function locateFragmentVaryings(frag, locations) {
+ const fragIn = frag.replace(VARYING_DECL, (m, ws, flat, dir, type, name) => {
if (dir !== 'in') return m;
- const loc = order.indexOf(name);
- if (loc < 0) throw new Error(`fragment varying '${name}' has no matching vertex output`);
+ const loc = locations.get(name);
+ if (loc === undefined) throw new Error(`fragment varying '${name}' has no matching vertex output`);
return `${ws}layout(location = ${loc}) ${flat ?? ''}in ${type} ${name};`;
});
// Fragment outputs: sequential locations (single fragColor = location 0).
let fragLoc = 0;
- const fragOut = fragIn.replace(varyingDecl, (m, ws, flat, dir, type, name) => {
+ return fragIn.replace(VARYING_DECL, (m, ws, flat, dir, type, name) => {
if (dir !== 'out') return m;
return `${ws}layout(location = ${fragLoc++}) ${flat ?? ''}out ${type} ${name};`;
});
- return { vert: vertOut, frag: fragOut };
}
/** GLSL (adapted) → WGSL via the vendored glslang + naga wasm, renaming the entry. */
@@ -403,7 +413,12 @@ export async function processFile(module, file, opts) {
const info = module.esshader_cookInfo(source, '');
if (!info.valid) throw new Error(`parse failed: ${info.error}`);
const assembled = assembledHash(info);
- if (!opts.force && !needsTwin(original)
+ // On the engine's vertex stage, the engine keeps that stage in every language: a
+ // translated copy is frozen at the batch source and cannot follow a material to
+ // a mesh. Only the fragment is generated, reading the engine's varying locations.
+ const engineVertex = info.canonicalVaryings !== '';
+ const staleVertex = engineVertex && /#pragma vertex wgsl full\b/.test(original);
+ if (!opts.force && !needsTwin(original) && !staleVertex
&& original.match(STORED_ASSEMBLED_RE)?.[1] === assembled) {
return { file, status: 'has-twin' };
}
@@ -425,21 +440,26 @@ export async function processFile(module, file, opts) {
if (!cooked.valid) throw new Error(`parse failed for [${key}]: ${cooked.error}`);
const textures = [];
for (let i = 0; i < cooked.textures.length; i++) textures.push(cooked.textures[i]);
+ // The stage tag is what glslang reads the shader stage from; the
+ // permutations reuse it in turn rather than each taking a name of its own.
+ if (engineVertex) {
+ const located = locateFragmentVaryings(
+ adaptGlsl(cooked.fragGlsl, textures), varyingLocations(info.canonicalVaryings));
+ frag.set(key, await glslToWgsl(located, 'frag', 'fs_main', workDir));
+ continue;
+ }
const adapted = assignVaryingLocations(
adaptGlsl(cooked.vertGlsl, textures),
adaptGlsl(cooked.fragGlsl, textures),
);
- // The stage tag is what glslang reads the shader stage from; the
- // permutations reuse it in turn rather than each taking a name of its own.
vert.set(key, await glslToWgsl(adapted.vert, 'vert', 'vs_main', workDir));
frag.set(key, await glslToWgsl(adapted.frag, 'frag', 'fs_main', workDir));
}
const banner = bannerFor(sourceHash(source), assembled);
- const vertBody = composePermutations(toggles, vert);
const fragBody = composePermutations(toggles, frag);
const twin =
- `\n#pragma vertex wgsl full\n${banner}\n${vertBody}\n#pragma end\n` +
+ (engineVertex ? '' : `\n#pragma vertex wgsl full\n${banner}\n${composePermutations(toggles, vert)}\n#pragma end\n`) +
`\n#pragma fragment wgsl full\n${banner}\n${fragBody}\n#pragma end\n`;
if (opts.check) return { file, status: 'would-generate' };
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index d565429bc..3420ed827 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,9 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(render): a material that writes only its fragment draws on a mesh under WebGPU':
+ { note: 'A material that writes only its fragment stage draws on a mesh under WebGPU and on' },
+
'fix(gates): an Electron download the host refuses is retried, and third-person says when no game ran':
{ internal: 'Verifier tooling; no creator runs it.' },
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 181a83b6d..2fec52454 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -576,6 +576,9 @@ export const SCENES = [
// twin without it shows wall throughout. The decal's layer fixes it second,
// since a material-id tie follows load order.
{ id: "mat-decal", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mat-decal.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.25,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40}]" } },
+ // A GENERATED twin on a mesh. A generated vertex stage is frozen at the batch
+ // source, so WebGPU refused the pipeline; the two halves read the uv varying.
+ { id: "mat-generated-mesh", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mat-generated-mesh.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.3,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.7,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40}]" } },
{ id: "mat-decal-flat", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mat-decal-flat.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.25,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40}]" } },
{ id: "mesh-material", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_MESH_ASSET: "/scenes/white-triangles.esmesh", ESTELLA_VERIFY_MESH_MATERIAL: "/scenes/mesh-material/tintonly.esmaterial", ESTELLA_VERIFY_SCENE: "/scenes/mesh-material.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-material.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.30,\"y\":0.556,\"rgb\":[0,0,255],\"tol\":40},{\"x\":0.70,\"y\":0.556,\"rgb\":[0,0,255],\"tol\":40},{\"x\":0.5,\"y\":0.12,\"rgb\":[0,0,0],\"tol\":30}]" } },
// What a normal is FOR: two coplanar triangles, one white colour, normals
diff --git a/tools/tests/shader-twin-permutations.test.ts b/tools/tests/shader-twin-permutations.test.ts
index 5ce7b8e33..123b10f3e 100644
--- a/tools/tests/shader-twin-permutations.test.ts
+++ b/tools/tests/shader-twin-permutations.test.ts
@@ -7,7 +7,7 @@
*/
import { describe, it, expect } from 'vitest';
// @ts-expect-error — a repo tool, shipped as .mjs with no declarations
-import { needsTwin, permutationsOf, composePermutations } from '../gen-shader-twins.mjs';
+import { needsTwin, permutationsOf, composePermutations, varyingLocations } from '../gen-shader-twins.mjs';
const GLSL_ONLY = '#pragma shader "X"\n#pragma switch USE_GREEN default(off)\n#pragma fragment\nvoid main() {}\n#pragma end\n';
@@ -52,3 +52,12 @@ describe('composePermutations', () => {
expect((out.match(/#ifdef/g) ?? []).length).toBe((out.match(/#endif/g) ?? []).length);
});
});
+
+describe('varyingLocations', () => {
+ it('reads every location of the engine varying struct, flat and conditional ones included', () => {
+ const struct = 'struct VSOut {\n @builtin(position) pos : vec4f,\n @location(0) v_color : vec4f,\n'
+ + '#ifdef MESH_NORMALS\n @location(3) v_worldNormal : vec3f,\n#endif\n'
+ + ' @location(6) @interpolate(flat) v_probeSlot : f32,\n};\n';
+ expect([...varyingLocations(struct)]).toEqual([['v_color', 0], ['v_worldNormal', 3], ['v_probeSlot', 6]]);
+ });
+});