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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(shader): Phase 4 lands - user .esshader gets auto-generated WGSL twins (glslang + naga)
yhhefbfec640cbf
diff --git a/desktop/public/scenes/mat-builtin-lit/lit.esshader b/desktop/public/scenes/mat-builtin-lit/lit.esshaderindex 2a794dc89..8a8f92832 100644--- a/desktop/public/scenes/mat-builtin-lit/lit.esshader+++ b/desktop/public/scenes/mat-builtin-lit/lit.esshader@@ -22,3 +22,628 @@ void main() {fragColor = vec4(applyLighting2D(base.rgb, N, v_worldPos), base.a);}#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.+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>,+ @location(2) member_2: 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>;+var<private> v_worldPos: vec2<f32>;+@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;++fn main_1() {+ let _e16 = unnamed_1.u_projection;+ let _e17 = a_position_1;+ unnamed.gl_Position = (_e16 * vec4<f32>(_e17.x, _e17.y, 0f, 1f));+ let _e23 = a_color_1;+ v_color = _e23;+ let _e24 = a_texCoord_1;+ v_texCoord = _e24;+ let _e25 = a_position_1;+ v_worldPos = _e25;+ return;+}++@vertex+fn vs_main(@location(0) a_position: vec2<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 _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);+}+#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.+struct Light2D {+ posDir: vec4<f32>,+ color: vec4<f32>,+ spot: vec4<f32>,+ shadow: vec4<f32>,+}++struct LightConstants {+ u_ambient: vec4<f32>,+ u_lights: array<Light2D, 16>,+ u_occluderCount: vec4<f32>,+ u_occluders: array<vec4<f32>, 8>,+}++struct MaterialConstants {+ u_tint: vec4<f32>,+}++struct TimeConstants {+ u_time: vec4<f32>,+ u_viewport: vec4<f32>,+}++@group(0) @binding(2)+var<uniform> unnamed: LightConstants;+@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> v_color_1: vec4<f32>;+@group(0) @binding(1)+var<uniform> unnamed_1: MaterialConstants;+@group(1) @binding(16)+var u_normalMap_est: texture_2d<f32>;+@group(1) @binding(24)+var u_normalMap_ess: sampler;+var<private> fragColor: vec4<f32>;+var<private> v_worldPos_1: vec2<f32>;+@group(0) @binding(3)+var<uniform> unnamed_2: 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 segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b(p0_: ptr<function, vec2<f32>>, p1_: ptr<function, vec2<f32>>, box: ptr<function, vec4<f32>>) -> f32 {+ var d: vec2<f32>;+ var tmin: f32;+ var tmax: f32;+ var a: i32;+ var da: f32;+ var local: f32;+ var p0a: f32;+ var local_1: f32;+ var lo: f32;+ var local_2: f32;+ var hi: f32;+ var local_3: f32;+ var t1_: f32;+ var t2_: f32;+ var phi_73_: bool;+ var phi_82_: bool;+ var phi_91_: bool;++ let _e69 = (*p0_)[0u];+ let _e71 = (*box)[0u];+ let _e72 = (_e69 >= _e71);+ phi_73_ = _e72;+ if _e72 {+ let _e74 = (*p0_)[1u];+ let _e76 = (*box)[1u];+ phi_73_ = (_e74 >= _e76);+ }+ let _e79 = phi_73_;+ phi_82_ = _e79;+ if _e79 {+ let _e81 = (*p0_)[0u];+ let _e83 = (*box)[2u];+ phi_82_ = (_e81 <= _e83);+ }+ let _e86 = phi_82_;+ phi_91_ = _e86;+ if _e86 {+ let _e88 = (*p0_)[1u];+ let _e90 = (*box)[3u];+ phi_91_ = (_e88 <= _e90);+ }+ let _e93 = phi_91_;+ if _e93 {+ return 0f;+ }+ let _e94 = (*p1_);+ let _e95 = (*p0_);+ d = (_e94 - _e95);+ tmin = 0f;+ tmax = 1f;+ a = 0i;+ loop {+ let _e97 = a;+ if (_e97 < 2i) {+ let _e99 = a;+ if (_e99 == 0i) {+ let _e102 = d[0u];+ local = _e102;+ } else {+ let _e104 = d[1u];+ local = _e104;+ }+ let _e105 = local;+ da = _e105;+ let _e106 = a;+ if (_e106 == 0i) {+ let _e109 = (*p0_)[0u];+ local_1 = _e109;+ } else {+ let _e111 = (*p0_)[1u];+ local_1 = _e111;+ }+ let _e112 = local_1;+ p0a = _e112;+ let _e113 = a;+ if (_e113 == 0i) {+ let _e116 = (*box)[0u];+ local_2 = _e116;+ } else {+ let _e118 = (*box)[1u];+ local_2 = _e118;+ }+ let _e119 = local_2;+ let _e120 = p0a;+ lo = (_e119 - _e120);+ let _e122 = a;+ if (_e122 == 0i) {+ let _e125 = (*box)[2u];+ local_3 = _e125;+ } else {+ let _e127 = (*box)[3u];+ local_3 = _e127;+ }+ let _e128 = local_3;+ let _e129 = p0a;+ hi = (_e128 - _e129);+ let _e131 = da;+ if (abs(_e131) < 0.00001f) {+ let _e134 = lo;+ let _e136 = hi;+ if ((_e134 > 0f) || (_e136 < 0f)) {+ return 0f;+ }+ } else {+ let _e139 = lo;+ let _e140 = da;+ t1_ = (_e139 / _e140);+ let _e142 = hi;+ let _e143 = da;+ t2_ = (_e142 / _e143);+ let _e145 = tmin;+ let _e146 = t1_;+ let _e147 = t2_;+ tmin = max(_e145, min(_e146, _e147));+ let _e150 = tmax;+ let _e151 = t1_;+ let _e152 = t2_;+ tmax = min(_e150, max(_e151, _e152));+ let _e155 = tmin;+ let _e156 = tmax;+ if (_e155 > _e156) {+ return 0f;+ }+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e158 = a;+ a = (_e158 + 1i);+ }+ }+ return 1f;+}++fn shadowFactor2D_u0028_vf2_u003b_vf2_u003b_f1_u003b(worldPos: ptr<function, vec2<f32>>, target_: ptr<function, vec2<f32>>, softness: ptr<function, f32>) -> f32 {+ var n: i32;+ var i: i32;+ var param: vec2<f32>;+ var param_1: vec2<f32>;+ var param_2: vec4<f32>;+ var dir: vec2<f32>;+ var dl: f32;+ var perp: vec2<f32>;+ var local_4: vec2<f32>;+ var blocked: f32;+ var s: i32;+ var t: f32;+ var tp: vec2<f32>;+ var i_1: i32;+ var param_3: vec2<f32>;+ var param_4: vec2<f32>;+ var param_5: vec4<f32>;++ let _e73 = unnamed.u_occluderCount[0u];+ n = i32(_e73);+ let _e75 = n;+ if (_e75 <= 0i) {+ return 1f;+ }+ let _e77 = (*softness);+ if (_e77 < 0.0001f) {+ i = 0i;+ loop {+ let _e79 = i;+ if (_e79 < 8i) {+ let _e81 = i;+ let _e82 = n;+ if (_e81 >= _e82) {+ break;+ }+ let _e84 = i;+ let _e85 = (*worldPos);+ param = _e85;+ let _e86 = (*target_);+ param_1 = _e86;+ let _e89 = unnamed.u_occluders[_e84];+ param_2 = _e89;+ let _e90 = segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b((¶m), (¶m_1), (¶m_2));+ if (_e90 > 0.5f) {+ return 0f;+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e92 = i;+ i = (_e92 + 1i);+ }+ }+ return 1f;+ }+ let _e94 = (*target_);+ let _e95 = (*worldPos);+ dir = (_e94 - _e95);+ let _e97 = dir;+ dl = length(_e97);+ let _e99 = dl;+ if (_e99 > 0.0001f) {+ let _e102 = dir[1u];+ let _e105 = dir[0u];+ let _e107 = dl;+ local_4 = (vec2<f32>(-(_e102), _e105) / vec2(_e107));+ } else {+ local_4 = vec2<f32>(1f, 0f);+ }+ let _e110 = local_4;+ perp = _e110;+ blocked = 0f;+ s = 0i;+ loop {+ let _e111 = s;+ if (_e111 < 5i) {+ let _e113 = s;+ t = (((f32(_e113) / 4f) * 2f) - 1f);+ let _e118 = (*target_);+ let _e119 = perp;+ let _e120 = t;+ let _e121 = (*softness);+ tp = (_e118 + (_e119 * (_e120 * _e121)));+ i_1 = 0i;+ loop {+ let _e125 = i_1;+ if (_e125 < 8i) {+ let _e127 = i_1;+ let _e128 = n;+ if (_e127 >= _e128) {+ break;+ }+ let _e130 = i_1;+ let _e131 = (*worldPos);+ param_3 = _e131;+ let _e132 = tp;+ param_4 = _e132;+ let _e135 = unnamed.u_occluders[_e130];+ param_5 = _e135;+ let _e136 = segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b((¶m_3), (¶m_4), (¶m_5));+ if (_e136 > 0.5f) {+ let _e138 = blocked;+ blocked = (_e138 + 1f);+ break;+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e140 = i_1;+ i_1 = (_e140 + 1i);+ }+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e142 = s;+ s = (_e142 + 1i);+ }+ }+ let _e144 = blocked;+ return (1f - (_e144 / 5f));+}++fn applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b(albedo: ptr<function, vec3<f32>>, N: ptr<function, vec3<f32>>, worldPos_1: ptr<function, vec2<f32>>) -> vec3<f32> {+ var lit: vec3<f32>;+ var i_2: i32;+ var pd: vec4<f32>;+ var col: vec4<f32>;+ var sh: vec4<f32>;+ var target_1: vec2<f32>;+ var castShadow: bool;+ var d_1: vec2<f32>;+ var dist: f32;+ var atten: f32;+ var L: vec3<f32>;+ var toLight: vec2<f32>;+ var local_5: vec2<f32>;+ var sp: vec4<f32>;+ var d_2: vec2<f32>;+ var dist_1: f32;+ var toFrag: vec2<f32>;+ var local_6: vec2<f32>;+ var param_6: vec2<f32>;+ var param_7: vec2<f32>;+ var param_8: f32;+ var ndotl: f32;+ var phi_458_: bool;+ var phi_525_: bool;++ let _e77 = unnamed.u_ambient;+ lit = _e77.xyz;+ i_2 = 0i;+ loop {+ let _e79 = i_2;+ if (_e79 < 16i) {+ let _e81 = i_2;+ let _e85 = unnamed.u_lights[_e81].posDir;+ pd = _e85;+ let _e86 = i_2;+ let _e90 = unnamed.u_lights[_e86].color;+ col = _e90;+ let _e91 = i_2;+ let _e95 = unnamed.u_lights[_e91].shadow;+ sh = _e95;+ let _e96 = pd;+ target_1 = _e96.xy;+ castShadow = true;+ let _e99 = pd[2u];+ if (_e99 < 0.5f) {+ let _e101 = pd;+ let _e103 = (*worldPos_1);+ d_1 = (_e101.xy - _e103);+ let _e105 = d_1;+ dist = length(_e105);+ let _e107 = dist;+ let _e109 = pd[3u];+ atten = max(0f, (1f - (_e107 / max(_e109, 0.0001f))));+ let _e114 = d_1;+ let _e116 = pd[3u];+ L = normalize(vec3<f32>(_e114.x, _e114.y, max(_e116, 1f)));+ } else {+ let _e123 = pd[2u];+ if (_e123 < 1.5f) {+ atten = 1f;+ let _e125 = pd;+ let _e127 = -(_e125.xy);+ L = normalize(vec3<f32>(_e127.x, _e127.y, 1f));+ let _e132 = pd;+ let _e134 = pd;+ if (dot(_e132.xy, _e134.xy) > 0.00000001f) {+ let _e138 = pd;+ local_5 = normalize(-(_e138.xy));+ } else {+ local_5 = vec2<f32>(0f, 0f);+ }+ let _e142 = local_5;+ toLight = _e142;+ let _e144 = sh[1u];+ let _e145 = (_e144 > 0f);+ phi_458_ = _e145;+ if _e145 {+ let _e146 = toLight;+ let _e147 = toLight;+ phi_458_ = (dot(_e146, _e147) > 0.5f);+ }+ let _e151 = phi_458_;+ castShadow = _e151;+ let _e152 = (*worldPos_1);+ let _e153 = toLight;+ let _e155 = sh[1u];+ target_1 = (_e152 + (_e153 * _e155));+ } else {+ let _e158 = i_2;+ let _e162 = unnamed.u_lights[_e158].spot;+ sp = _e162;+ let _e163 = pd;+ let _e165 = (*worldPos_1);+ d_2 = (_e163.xy - _e165);+ let _e167 = d_2;+ dist_1 = length(_e167);+ let _e169 = dist_1;+ let _e171 = pd[3u];+ atten = max(0f, (1f - (_e169 / max(_e171, 0.0001f))));+ let _e176 = d_2;+ let _e178 = pd[3u];+ L = normalize(vec3<f32>(_e176.x, _e176.y, max(_e178, 1f)));+ let _e184 = dist_1;+ if (_e184 > 0.0001f) {+ let _e186 = d_2;+ let _e188 = dist_1;+ local_6 = (-(_e186) / vec2(_e188));+ } else {+ let _e191 = sp;+ local_6 = _e191.xy;+ }+ let _e193 = local_6;+ toFrag = _e193;+ let _e195 = sp[3u];+ let _e197 = sp[2u];+ let _e198 = sp;+ let _e200 = toFrag;+ let _e203 = atten;+ atten = (_e203 * smoothstep(_e195, _e197, dot(_e198.xy, _e200)));+ }+ }+ let _e205 = castShadow;+ phi_525_ = _e205;+ if _e205 {+ let _e207 = col[3u];+ phi_525_ = (_e207 > 0f);+ }+ let _e210 = phi_525_;+ let _e211 = atten;+ if (_e210 && (_e211 > 0f)) {+ let _e214 = (*worldPos_1);+ param_6 = _e214;+ let _e215 = target_1;+ param_7 = _e215;+ let _e217 = sh[0u];+ param_8 = _e217;+ let _e218 = shadowFactor2D_u0028_vf2_u003b_vf2_u003b_f1_u003b((¶m_6), (¶m_7), (¶m_8));+ let _e219 = atten;+ atten = (_e219 * _e218);+ }+ let _e221 = (*N);+ let _e222 = L;+ ndotl = max(dot(_e221, _e222), 0f);+ let _e225 = col;+ let _e228 = col[3u];+ let _e229 = ndotl;+ let _e231 = atten;+ let _e234 = lit;+ lit = (_e234 + (_e225.xyz * ((_e228 * _e229) * _e231)));+ continue;+ } else {+ break;+ }+ continuing {+ let _e236 = i_2;+ i_2 = (_e236 + 1i);+ }+ }+ let _e238 = (*albedo);+ let _e239 = lit;+ return (_e238 * _e239);+}++fn sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(map_est: texture_2d<f32>, map_ess: sampler, uv: ptr<function, vec2<f32>>) -> vec3<f32> {+ let _e54 = (*uv);+ let _e55 = textureSample(map_est, map_ess, _e54);+ return normalize(((_e55.xyz * 2f) - vec3(1f)));+}++fn main_1() {+ var base: vec4<f32>;+ var N_1: vec3<f32>;+ var param_9: vec2<f32>;+ var param_10: vec3<f32>;+ var param_11: vec3<f32>;+ var param_12: vec2<f32>;++ let _e57 = v_texCoord_1;+ let _e58 = textureSample(es_bt0_est, es_bt0_ess, _e57);+ let _e59 = v_color_1;+ let _e62 = unnamed_1.u_tint;+ base = ((_e58 * _e59) * _e62);+ let _e64 = v_texCoord_1;+ param_9 = _e64;+ let _e65 = sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(u_normalMap_est, u_normalMap_ess, (¶m_9));+ N_1 = _e65;+ let _e66 = base;+ param_10 = _e66.xyz;+ let _e68 = N_1;+ param_11 = _e68;+ let _e69 = v_worldPos_1;+ param_12 = _e69;+ let _e70 = applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b((¶m_10), (¶m_11), (¶m_12));+ let _e72 = base[3u];+ fragColor = vec4<f32>(_e70.x, _e70.y, _e70.z, _e72);+ return;+}++@fragment+fn fs_main(@location(1) v_texCoord: vec2<f32>, @location(0) v_color: vec4<f32>, @location(2) v_worldPos: vec2<f32>) -> @location(0) vec4<f32> {+ v_texCoord_1 = v_texCoord;+ v_color_1 = v_color;+ v_worldPos_1 = v_worldPos;+ main_1();+ let _e7 = fragColor;+ return _e7;+}+#pragma enddiff --git a/desktop/public/scenes/mat-dissolve/dissolve.esshader b/desktop/public/scenes/mat-dissolve/dissolve.esshaderindex f3527269c..dca1b762d 100644--- a/desktop/public/scenes/mat-dissolve/dissolve.esshader+++ b/desktop/public/scenes/mat-dissolve/dissolve.esshader@@ -35,3 +35,219 @@ void main() {fragColor = vec4(rgb, base.a);}#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.+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_progress: f32,+ u_edgeColor: vec4<f32>,+ u_edgeWidth: f32,+ u_noiseScale: 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;++fn main_1() {+ let _e13 = unnamed_1.u_projection;+ let _e14 = a_position_1;+ unnamed.gl_Position = (_e13 * vec4<f32>(_e14.x, _e14.y, 0f, 1f));+ let _e20 = a_color_1;+ v_color = _e20;+ let _e21 = a_texCoord_1;+ v_texCoord = _e21;+ return;+}++@vertex+fn vs_main(@location(0) a_position: vec2<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 _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);+}+#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.+struct MaterialConstants {+ u_progress: f32,+ u_edgeColor: vec4<f32>,+ u_edgeWidth: f32,+ u_noiseScale: 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> v_color_1: vec4<f32>;+@group(0) @binding(1)+var<uniform> unnamed: MaterialConstants;+var<private> fragColor: vec4<f32>;+@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 hash2d_u0028_vf2_u003b(p: ptr<function, vec2<f32>>) -> f32 {+ let _e40 = (*p);+ return fract((sin(dot(_e40, vec2<f32>(127.1f, 311.7f))) * 43758.547f));+}++fn noise2d_u0028_vf2_u003b(p_1: ptr<function, vec2<f32>>) -> f32 {+ var i: vec2<f32>;+ var f: vec2<f32>;+ var param: vec2<f32>;+ var param_1: vec2<f32>;+ var param_2: vec2<f32>;+ var param_3: vec2<f32>;++ let _e46 = (*p_1);+ i = floor(_e46);+ let _e48 = (*p_1);+ f = fract(_e48);+ let _e50 = f;+ let _e51 = f;+ let _e53 = f;+ f = ((_e50 * _e51) * (vec2(3f) - (_e53 * 2f)));+ let _e58 = i;+ param = _e58;+ let _e59 = hash2d_u0028_vf2_u003b((¶m));+ let _e60 = i;+ param_1 = (_e60 + vec2<f32>(1f, 0f));+ let _e62 = hash2d_u0028_vf2_u003b((¶m_1));+ let _e64 = f[0u];+ let _e66 = i;+ param_2 = (_e66 + vec2<f32>(0f, 1f));+ let _e68 = hash2d_u0028_vf2_u003b((¶m_2));+ let _e69 = i;+ param_3 = (_e69 + vec2<f32>(1f, 1f));+ let _e71 = hash2d_u0028_vf2_u003b((¶m_3));+ let _e73 = f[0u];+ let _e76 = f[1u];+ return mix(mix(_e59, _e62, _e64), mix(_e68, _e71, _e73), _e76);+}++fn main_1() {+ var base: vec4<f32>;+ var n: f32;+ var param_4: vec2<f32>;+ var cut: f32;+ var rgb: vec3<f32>;+ var local: vec3<f32>;++ let _e45 = v_texCoord_1;+ let _e46 = textureSample(es_bt0_est, es_bt0_ess, _e45);+ let _e47 = v_color_1;+ base = (_e46 * _e47);+ let _e49 = v_texCoord_1;+ let _e51 = unnamed.u_noiseScale;+ param_4 = (_e49 * _e51);+ let _e53 = noise2d_u0028_vf2_u003b((¶m_4));+ n = _e53;+ let _e55 = unnamed.u_progress;+ let _e57 = unnamed.u_edgeWidth;+ cut = (_e55 * (1f + _e57));+ let _e60 = n;+ let _e61 = cut;+ let _e63 = unnamed.u_edgeWidth;+ if (_e60 < (_e61 - _e63)) {+ discard;+ }+ let _e66 = n;+ let _e67 = cut;+ if (_e66 < _e67) {+ let _e70 = unnamed.u_edgeColor;+ local = _e70.xyz;+ } else {+ let _e72 = base;+ local = _e72.xyz;+ }+ let _e74 = local;+ rgb = _e74;+ let _e75 = rgb;+ let _e77 = base[3u];+ fragColor = vec4<f32>(_e75.x, _e75.y, _e75.z, _e77);+ 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 enddiff --git a/desktop/public/scenes/mat-graph/graph-tint.esshader b/desktop/public/scenes/mat-graph/graph-tint.esshaderindex 2dd0e9467..5044570a7 100644--- a/desktop/public/scenes/mat-graph/graph-tint.esshader+++ b/desktop/public/scenes/mat-graph/graph-tint.esshader@@ -38,3 +38,124 @@ void main() {fragColor = n1;}#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.+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;+@group(1) @binding(16)+var u_albedo_est: texture_2d<f32>;+@group(1) @binding(24)+var u_albedo_ess: sampler;+var<private> a_texIndex_1: f32;++fn main_1() {+ let _e16 = unnamed_1.u_projection;+ let _e17 = a_position_1;+ unnamed.gl_Position = (_e16 * vec4<f32>(_e17.x, _e17.y, 0f, 1f));+ let _e23 = a_color_1;+ v_color = _e23;+ let _e24 = a_texCoord_1;+ v_texCoord = _e24;+ 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 _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);+}+#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.+struct MaterialConstants {+ u_tint: vec4<f32>,+}++struct TimeConstants {+ u_time: vec4<f32>,+ u_viewport: vec4<f32>,+}++@group(1) @binding(16)+var u_albedo_est: texture_2d<f32>;+@group(1) @binding(24)+var u_albedo_ess: sampler;+var<private> v_texCoord_1: vec2<f32>;+@group(0) @binding(1)+var<uniform> unnamed: MaterialConstants;+var<private> fragColor: vec4<f32>;+@group(0) @binding(3)+var<uniform> unnamed_1: TimeConstants;+var<private> v_color_1: vec4<f32>;++fn main_1() {+ var n0_: vec4<f32>;+ var n1_: vec4<f32>;++ let _e10 = v_texCoord_1;+ let _e11 = textureSample(u_albedo_est, u_albedo_ess, _e10);+ n0_ = _e11;+ let _e12 = n0_;+ let _e14 = unnamed.u_tint;+ n1_ = (_e12 * _e14);+ let _e16 = n1_;+ fragColor = _e16;+ 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 enddiff --git a/desktop/public/scenes/mat-lit-flatnormal/lit-fn.esshader b/desktop/public/scenes/mat-lit-flatnormal/lit-fn.esshaderindex d8c67c136..9e04a3fe6 100644--- a/desktop/public/scenes/mat-lit-flatnormal/lit-fn.esshader+++ b/desktop/public/scenes/mat-lit-flatnormal/lit-fn.esshader@@ -46,3 +46,620 @@ void main() {fragColor = vec4(lit, base.a);}#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.+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 VertexOutput {+ @builtin(position) gl_Position: vec4<f32>,+ @location(0) member: vec4<f32>,+ @location(1) member_1: vec2<f32>,+ @location(2) member_2: 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>;+var<private> v_worldPos: vec2<f32>;+@group(0) @binding(3)+var<uniform> unnamed_2: TimeConstants;+@group(1) @binding(16)+var u_normal_est: texture_2d<f32>;+@group(1) @binding(24)+var u_normal_ess: sampler;+var<private> a_texIndex_1: f32;++fn main_1() {+ let _e16 = unnamed_1.u_projection;+ let _e17 = a_position_1;+ unnamed.gl_Position = (_e16 * vec4<f32>(_e17.x, _e17.y, 0f, 1f));+ let _e23 = a_color_1;+ v_color = _e23;+ let _e24 = a_texCoord_1;+ v_texCoord = _e24;+ let _e25 = a_position_1;+ v_worldPos = _e25;+ 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 _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);+}+#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.+struct Light2D {+ posDir: vec4<f32>,+ color: vec4<f32>,+ spot: vec4<f32>,+ shadow: vec4<f32>,+}++struct LightConstants {+ u_ambient: vec4<f32>,+ u_lights: array<Light2D, 16>,+ u_occluderCount: vec4<f32>,+ u_occluders: array<vec4<f32>, 8>,+}++struct TimeConstants {+ u_time: vec4<f32>,+ u_viewport: vec4<f32>,+}++@group(0) @binding(2)+var<uniform> unnamed: LightConstants;+@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> v_color_1: vec4<f32>;+@group(1) @binding(16)+var u_normal_est: texture_2d<f32>;+@group(1) @binding(24)+var u_normal_ess: sampler;+var<private> v_worldPos_1: vec2<f32>;+var<private> fragColor: vec4<f32>;+@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 segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b(p0_: ptr<function, vec2<f32>>, p1_: ptr<function, vec2<f32>>, box: ptr<function, vec4<f32>>) -> f32 {+ var d: vec2<f32>;+ var tmin: f32;+ var tmax: f32;+ var a: i32;+ var da: f32;+ var local: f32;+ var p0a: f32;+ var local_1: f32;+ var lo: f32;+ var local_2: f32;+ var hi: f32;+ var local_3: f32;+ var t1_: f32;+ var t2_: f32;+ var phi_73_: bool;+ var phi_82_: bool;+ var phi_91_: bool;++ let _e68 = (*p0_)[0u];+ let _e70 = (*box)[0u];+ let _e71 = (_e68 >= _e70);+ phi_73_ = _e71;+ if _e71 {+ let _e73 = (*p0_)[1u];+ let _e75 = (*box)[1u];+ phi_73_ = (_e73 >= _e75);+ }+ let _e78 = phi_73_;+ phi_82_ = _e78;+ if _e78 {+ let _e80 = (*p0_)[0u];+ let _e82 = (*box)[2u];+ phi_82_ = (_e80 <= _e82);+ }+ let _e85 = phi_82_;+ phi_91_ = _e85;+ if _e85 {+ let _e87 = (*p0_)[1u];+ let _e89 = (*box)[3u];+ phi_91_ = (_e87 <= _e89);+ }+ let _e92 = phi_91_;+ if _e92 {+ return 0f;+ }+ let _e93 = (*p1_);+ let _e94 = (*p0_);+ d = (_e93 - _e94);+ tmin = 0f;+ tmax = 1f;+ a = 0i;+ loop {+ let _e96 = a;+ if (_e96 < 2i) {+ let _e98 = a;+ if (_e98 == 0i) {+ let _e101 = d[0u];+ local = _e101;+ } else {+ let _e103 = d[1u];+ local = _e103;+ }+ let _e104 = local;+ da = _e104;+ let _e105 = a;+ if (_e105 == 0i) {+ let _e108 = (*p0_)[0u];+ local_1 = _e108;+ } else {+ let _e110 = (*p0_)[1u];+ local_1 = _e110;+ }+ let _e111 = local_1;+ p0a = _e111;+ let _e112 = a;+ if (_e112 == 0i) {+ let _e115 = (*box)[0u];+ local_2 = _e115;+ } else {+ let _e117 = (*box)[1u];+ local_2 = _e117;+ }+ let _e118 = local_2;+ let _e119 = p0a;+ lo = (_e118 - _e119);+ let _e121 = a;+ if (_e121 == 0i) {+ let _e124 = (*box)[2u];+ local_3 = _e124;+ } else {+ let _e126 = (*box)[3u];+ local_3 = _e126;+ }+ let _e127 = local_3;+ let _e128 = p0a;+ hi = (_e127 - _e128);+ let _e130 = da;+ if (abs(_e130) < 0.00001f) {+ let _e133 = lo;+ let _e135 = hi;+ if ((_e133 > 0f) || (_e135 < 0f)) {+ return 0f;+ }+ } else {+ let _e138 = lo;+ let _e139 = da;+ t1_ = (_e138 / _e139);+ let _e141 = hi;+ let _e142 = da;+ t2_ = (_e141 / _e142);+ let _e144 = tmin;+ let _e145 = t1_;+ let _e146 = t2_;+ tmin = max(_e144, min(_e145, _e146));+ let _e149 = tmax;+ let _e150 = t1_;+ let _e151 = t2_;+ tmax = min(_e149, max(_e150, _e151));+ let _e154 = tmin;+ let _e155 = tmax;+ if (_e154 > _e155) {+ return 0f;+ }+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e157 = a;+ a = (_e157 + 1i);+ }+ }+ return 1f;+}++fn shadowFactor2D_u0028_vf2_u003b_vf2_u003b_f1_u003b(worldPos: ptr<function, vec2<f32>>, target_: ptr<function, vec2<f32>>, softness: ptr<function, f32>) -> f32 {+ var n: i32;+ var i: i32;+ var param: vec2<f32>;+ var param_1: vec2<f32>;+ var param_2: vec4<f32>;+ var dir: vec2<f32>;+ var dl: f32;+ var perp: vec2<f32>;+ var local_4: vec2<f32>;+ var blocked: f32;+ var s: i32;+ var t: f32;+ var tp: vec2<f32>;+ var i_1: i32;+ var param_3: vec2<f32>;+ var param_4: vec2<f32>;+ var param_5: vec4<f32>;++ let _e72 = unnamed.u_occluderCount[0u];+ n = i32(_e72);+ let _e74 = n;+ if (_e74 <= 0i) {+ return 1f;+ }+ let _e76 = (*softness);+ if (_e76 < 0.0001f) {+ i = 0i;+ loop {+ let _e78 = i;+ if (_e78 < 8i) {+ let _e80 = i;+ let _e81 = n;+ if (_e80 >= _e81) {+ break;+ }+ let _e83 = i;+ let _e84 = (*worldPos);+ param = _e84;+ let _e85 = (*target_);+ param_1 = _e85;+ let _e88 = unnamed.u_occluders[_e83];+ param_2 = _e88;+ let _e89 = segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b((¶m), (¶m_1), (¶m_2));+ if (_e89 > 0.5f) {+ return 0f;+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e91 = i;+ i = (_e91 + 1i);+ }+ }+ return 1f;+ }+ let _e93 = (*target_);+ let _e94 = (*worldPos);+ dir = (_e93 - _e94);+ let _e96 = dir;+ dl = length(_e96);+ let _e98 = dl;+ if (_e98 > 0.0001f) {+ let _e101 = dir[1u];+ let _e104 = dir[0u];+ let _e106 = dl;+ local_4 = (vec2<f32>(-(_e101), _e104) / vec2(_e106));+ } else {+ local_4 = vec2<f32>(1f, 0f);+ }+ let _e109 = local_4;+ perp = _e109;+ blocked = 0f;+ s = 0i;+ loop {+ let _e110 = s;+ if (_e110 < 5i) {+ let _e112 = s;+ t = (((f32(_e112) / 4f) * 2f) - 1f);+ let _e117 = (*target_);+ let _e118 = perp;+ let _e119 = t;+ let _e120 = (*softness);+ tp = (_e117 + (_e118 * (_e119 * _e120)));+ i_1 = 0i;+ loop {+ let _e124 = i_1;+ if (_e124 < 8i) {+ let _e126 = i_1;+ let _e127 = n;+ if (_e126 >= _e127) {+ break;+ }+ let _e129 = i_1;+ let _e130 = (*worldPos);+ param_3 = _e130;+ let _e131 = tp;+ param_4 = _e131;+ let _e134 = unnamed.u_occluders[_e129];+ param_5 = _e134;+ let _e135 = segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b((¶m_3), (¶m_4), (¶m_5));+ if (_e135 > 0.5f) {+ let _e137 = blocked;+ blocked = (_e137 + 1f);+ break;+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e139 = i_1;+ i_1 = (_e139 + 1i);+ }+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e141 = s;+ s = (_e141 + 1i);+ }+ }+ let _e143 = blocked;+ return (1f - (_e143 / 5f));+}++fn applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b(albedo: ptr<function, vec3<f32>>, N: ptr<function, vec3<f32>>, worldPos_1: ptr<function, vec2<f32>>) -> vec3<f32> {+ var lit: vec3<f32>;+ var i_2: i32;+ var pd: vec4<f32>;+ var col: vec4<f32>;+ var sh: vec4<f32>;+ var target_1: vec2<f32>;+ var castShadow: bool;+ var d_1: vec2<f32>;+ var dist: f32;+ var atten: f32;+ var L: vec3<f32>;+ var toLight: vec2<f32>;+ var local_5: vec2<f32>;+ var sp: vec4<f32>;+ var d_2: vec2<f32>;+ var dist_1: f32;+ var toFrag: vec2<f32>;+ var local_6: vec2<f32>;+ var param_6: vec2<f32>;+ var param_7: vec2<f32>;+ var param_8: f32;+ var ndotl: f32;+ var phi_458_: bool;+ var phi_525_: bool;++ let _e76 = unnamed.u_ambient;+ lit = _e76.xyz;+ i_2 = 0i;+ loop {+ let _e78 = i_2;+ if (_e78 < 16i) {+ let _e80 = i_2;+ let _e84 = unnamed.u_lights[_e80].posDir;+ pd = _e84;+ let _e85 = i_2;+ let _e89 = unnamed.u_lights[_e85].color;+ col = _e89;+ let _e90 = i_2;+ let _e94 = unnamed.u_lights[_e90].shadow;+ sh = _e94;+ let _e95 = pd;+ target_1 = _e95.xy;+ castShadow = true;+ let _e98 = pd[2u];+ if (_e98 < 0.5f) {+ let _e100 = pd;+ let _e102 = (*worldPos_1);+ d_1 = (_e100.xy - _e102);+ let _e104 = d_1;+ dist = length(_e104);+ let _e106 = dist;+ let _e108 = pd[3u];+ atten = max(0f, (1f - (_e106 / max(_e108, 0.0001f))));+ let _e113 = d_1;+ let _e115 = pd[3u];+ L = normalize(vec3<f32>(_e113.x, _e113.y, max(_e115, 1f)));+ } else {+ let _e122 = pd[2u];+ if (_e122 < 1.5f) {+ atten = 1f;+ let _e124 = pd;+ let _e126 = -(_e124.xy);+ L = normalize(vec3<f32>(_e126.x, _e126.y, 1f));+ let _e131 = pd;+ let _e133 = pd;+ if (dot(_e131.xy, _e133.xy) > 0.00000001f) {+ let _e137 = pd;+ local_5 = normalize(-(_e137.xy));+ } else {+ local_5 = vec2<f32>(0f, 0f);+ }+ let _e141 = local_5;+ toLight = _e141;+ let _e143 = sh[1u];+ let _e144 = (_e143 > 0f);+ phi_458_ = _e144;+ if _e144 {+ let _e145 = toLight;+ let _e146 = toLight;+ phi_458_ = (dot(_e145, _e146) > 0.5f);+ }+ let _e150 = phi_458_;+ castShadow = _e150;+ let _e151 = (*worldPos_1);+ let _e152 = toLight;+ let _e154 = sh[1u];+ target_1 = (_e151 + (_e152 * _e154));+ } else {+ let _e157 = i_2;+ let _e161 = unnamed.u_lights[_e157].spot;+ sp = _e161;+ let _e162 = pd;+ let _e164 = (*worldPos_1);+ d_2 = (_e162.xy - _e164);+ let _e166 = d_2;+ dist_1 = length(_e166);+ let _e168 = dist_1;+ let _e170 = pd[3u];+ atten = max(0f, (1f - (_e168 / max(_e170, 0.0001f))));+ let _e175 = d_2;+ let _e177 = pd[3u];+ L = normalize(vec3<f32>(_e175.x, _e175.y, max(_e177, 1f)));+ let _e183 = dist_1;+ if (_e183 > 0.0001f) {+ let _e185 = d_2;+ let _e187 = dist_1;+ local_6 = (-(_e185) / vec2(_e187));+ } else {+ let _e190 = sp;+ local_6 = _e190.xy;+ }+ let _e192 = local_6;+ toFrag = _e192;+ let _e194 = sp[3u];+ let _e196 = sp[2u];+ let _e197 = sp;+ let _e199 = toFrag;+ let _e202 = atten;+ atten = (_e202 * smoothstep(_e194, _e196, dot(_e197.xy, _e199)));+ }+ }+ let _e204 = castShadow;+ phi_525_ = _e204;+ if _e204 {+ let _e206 = col[3u];+ phi_525_ = (_e206 > 0f);+ }+ let _e209 = phi_525_;+ let _e210 = atten;+ if (_e209 && (_e210 > 0f)) {+ let _e213 = (*worldPos_1);+ param_6 = _e213;+ let _e214 = target_1;+ param_7 = _e214;+ let _e216 = sh[0u];+ param_8 = _e216;+ let _e217 = shadowFactor2D_u0028_vf2_u003b_vf2_u003b_f1_u003b((¶m_6), (¶m_7), (¶m_8));+ let _e218 = atten;+ atten = (_e218 * _e217);+ }+ let _e220 = (*N);+ let _e221 = L;+ ndotl = max(dot(_e220, _e221), 0f);+ let _e224 = col;+ let _e227 = col[3u];+ let _e228 = ndotl;+ let _e230 = atten;+ let _e233 = lit;+ lit = (_e233 + (_e224.xyz * ((_e227 * _e228) * _e230)));+ continue;+ } else {+ break;+ }+ continuing {+ let _e235 = i_2;+ i_2 = (_e235 + 1i);+ }+ }+ let _e237 = (*albedo);+ let _e238 = lit;+ return (_e237 * _e238);+}++fn sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(map_est: texture_2d<f32>, map_ess: sampler, uv: ptr<function, vec2<f32>>) -> vec3<f32> {+ let _e53 = (*uv);+ let _e54 = textureSample(map_est, map_ess, _e53);+ return normalize(((_e54.xyz * 2f) - vec3(1f)));+}++fn main_1() {+ var base: vec4<f32>;+ var N_1: vec3<f32>;+ var param_9: vec2<f32>;+ var lit_1: vec3<f32>;+ var param_10: vec3<f32>;+ var param_11: vec3<f32>;+ var param_12: vec2<f32>;++ let _e57 = v_texCoord_1;+ let _e58 = textureSample(es_bt0_est, es_bt0_ess, _e57);+ let _e59 = v_color_1;+ base = (_e58 * _e59);+ let _e61 = v_texCoord_1;+ param_9 = _e61;+ let _e62 = sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(u_normal_est, u_normal_ess, (¶m_9));+ N_1 = _e62;+ let _e63 = base;+ param_10 = _e63.xyz;+ let _e65 = N_1;+ param_11 = _e65;+ let _e66 = v_worldPos_1;+ param_12 = _e66;+ let _e67 = applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b((¶m_10), (¶m_11), (¶m_12));+ lit_1 = _e67;+ let _e68 = lit_1;+ let _e70 = base[3u];+ fragColor = vec4<f32>(_e68.x, _e68.y, _e68.z, _e70);+ return;+}++@fragment+fn fs_main(@location(1) v_texCoord: vec2<f32>, @location(0) v_color: vec4<f32>, @location(2) v_worldPos: vec2<f32>) -> @location(0) vec4<f32> {+ v_texCoord_1 = v_texCoord;+ v_color_1 = v_color;+ v_worldPos_1 = v_worldPos;+ main_1();+ let _e7 = fragColor;+ return _e7;+}+#pragma enddiff --git a/desktop/public/scenes/mat-lit-normal/lit-normal.esshader b/desktop/public/scenes/mat-lit-normal/lit-normal.esshaderindex 031b1e3f3..d853b13c0 100644--- a/desktop/public/scenes/mat-lit-normal/lit-normal.esshader+++ b/desktop/public/scenes/mat-lit-normal/lit-normal.esshader@@ -46,3 +46,620 @@ void main() {fragColor = vec4(lit, base.a);}#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.+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 VertexOutput {+ @builtin(position) gl_Position: vec4<f32>,+ @location(0) member: vec4<f32>,+ @location(1) member_1: vec2<f32>,+ @location(2) member_2: 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>;+var<private> v_worldPos: vec2<f32>;+@group(0) @binding(3)+var<uniform> unnamed_2: TimeConstants;+@group(1) @binding(16)+var u_normal_est: texture_2d<f32>;+@group(1) @binding(24)+var u_normal_ess: sampler;+var<private> a_texIndex_1: f32;++fn main_1() {+ let _e16 = unnamed_1.u_projection;+ let _e17 = a_position_1;+ unnamed.gl_Position = (_e16 * vec4<f32>(_e17.x, _e17.y, 0f, 1f));+ let _e23 = a_color_1;+ v_color = _e23;+ let _e24 = a_texCoord_1;+ v_texCoord = _e24;+ let _e25 = a_position_1;+ v_worldPos = _e25;+ 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 _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);+}+#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.+struct Light2D {+ posDir: vec4<f32>,+ color: vec4<f32>,+ spot: vec4<f32>,+ shadow: vec4<f32>,+}++struct LightConstants {+ u_ambient: vec4<f32>,+ u_lights: array<Light2D, 16>,+ u_occluderCount: vec4<f32>,+ u_occluders: array<vec4<f32>, 8>,+}++struct TimeConstants {+ u_time: vec4<f32>,+ u_viewport: vec4<f32>,+}++@group(0) @binding(2)+var<uniform> unnamed: LightConstants;+@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> v_color_1: vec4<f32>;+@group(1) @binding(16)+var u_normal_est: texture_2d<f32>;+@group(1) @binding(24)+var u_normal_ess: sampler;+var<private> v_worldPos_1: vec2<f32>;+var<private> fragColor: vec4<f32>;+@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 segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b(p0_: ptr<function, vec2<f32>>, p1_: ptr<function, vec2<f32>>, box: ptr<function, vec4<f32>>) -> f32 {+ var d: vec2<f32>;+ var tmin: f32;+ var tmax: f32;+ var a: i32;+ var da: f32;+ var local: f32;+ var p0a: f32;+ var local_1: f32;+ var lo: f32;+ var local_2: f32;+ var hi: f32;+ var local_3: f32;+ var t1_: f32;+ var t2_: f32;+ var phi_73_: bool;+ var phi_82_: bool;+ var phi_91_: bool;++ let _e68 = (*p0_)[0u];+ let _e70 = (*box)[0u];+ let _e71 = (_e68 >= _e70);+ phi_73_ = _e71;+ if _e71 {+ let _e73 = (*p0_)[1u];+ let _e75 = (*box)[1u];+ phi_73_ = (_e73 >= _e75);+ }+ let _e78 = phi_73_;+ phi_82_ = _e78;+ if _e78 {+ let _e80 = (*p0_)[0u];+ let _e82 = (*box)[2u];+ phi_82_ = (_e80 <= _e82);+ }+ let _e85 = phi_82_;+ phi_91_ = _e85;+ if _e85 {+ let _e87 = (*p0_)[1u];+ let _e89 = (*box)[3u];+ phi_91_ = (_e87 <= _e89);+ }+ let _e92 = phi_91_;+ if _e92 {+ return 0f;+ }+ let _e93 = (*p1_);+ let _e94 = (*p0_);+ d = (_e93 - _e94);+ tmin = 0f;+ tmax = 1f;+ a = 0i;+ loop {+ let _e96 = a;+ if (_e96 < 2i) {+ let _e98 = a;+ if (_e98 == 0i) {+ let _e101 = d[0u];+ local = _e101;+ } else {+ let _e103 = d[1u];+ local = _e103;+ }+ let _e104 = local;+ da = _e104;+ let _e105 = a;+ if (_e105 == 0i) {+ let _e108 = (*p0_)[0u];+ local_1 = _e108;+ } else {+ let _e110 = (*p0_)[1u];+ local_1 = _e110;+ }+ let _e111 = local_1;+ p0a = _e111;+ let _e112 = a;+ if (_e112 == 0i) {+ let _e115 = (*box)[0u];+ local_2 = _e115;+ } else {+ let _e117 = (*box)[1u];+ local_2 = _e117;+ }+ let _e118 = local_2;+ let _e119 = p0a;+ lo = (_e118 - _e119);+ let _e121 = a;+ if (_e121 == 0i) {+ let _e124 = (*box)[2u];+ local_3 = _e124;+ } else {+ let _e126 = (*box)[3u];+ local_3 = _e126;+ }+ let _e127 = local_3;+ let _e128 = p0a;+ hi = (_e127 - _e128);+ let _e130 = da;+ if (abs(_e130) < 0.00001f) {+ let _e133 = lo;+ let _e135 = hi;+ if ((_e133 > 0f) || (_e135 < 0f)) {+ return 0f;+ }+ } else {+ let _e138 = lo;+ let _e139 = da;+ t1_ = (_e138 / _e139);+ let _e141 = hi;+ let _e142 = da;+ t2_ = (_e141 / _e142);+ let _e144 = tmin;+ let _e145 = t1_;+ let _e146 = t2_;+ tmin = max(_e144, min(_e145, _e146));+ let _e149 = tmax;+ let _e150 = t1_;+ let _e151 = t2_;+ tmax = min(_e149, max(_e150, _e151));+ let _e154 = tmin;+ let _e155 = tmax;+ if (_e154 > _e155) {+ return 0f;+ }+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e157 = a;+ a = (_e157 + 1i);+ }+ }+ return 1f;+}++fn shadowFactor2D_u0028_vf2_u003b_vf2_u003b_f1_u003b(worldPos: ptr<function, vec2<f32>>, target_: ptr<function, vec2<f32>>, softness: ptr<function, f32>) -> f32 {+ var n: i32;+ var i: i32;+ var param: vec2<f32>;+ var param_1: vec2<f32>;+ var param_2: vec4<f32>;+ var dir: vec2<f32>;+ var dl: f32;+ var perp: vec2<f32>;+ var local_4: vec2<f32>;+ var blocked: f32;+ var s: i32;+ var t: f32;+ var tp: vec2<f32>;+ var i_1: i32;+ var param_3: vec2<f32>;+ var param_4: vec2<f32>;+ var param_5: vec4<f32>;++ let _e72 = unnamed.u_occluderCount[0u];+ n = i32(_e72);+ let _e74 = n;+ if (_e74 <= 0i) {+ return 1f;+ }+ let _e76 = (*softness);+ if (_e76 < 0.0001f) {+ i = 0i;+ loop {+ let _e78 = i;+ if (_e78 < 8i) {+ let _e80 = i;+ let _e81 = n;+ if (_e80 >= _e81) {+ break;+ }+ let _e83 = i;+ let _e84 = (*worldPos);+ param = _e84;+ let _e85 = (*target_);+ param_1 = _e85;+ let _e88 = unnamed.u_occluders[_e83];+ param_2 = _e88;+ let _e89 = segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b((¶m), (¶m_1), (¶m_2));+ if (_e89 > 0.5f) {+ return 0f;+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e91 = i;+ i = (_e91 + 1i);+ }+ }+ return 1f;+ }+ let _e93 = (*target_);+ let _e94 = (*worldPos);+ dir = (_e93 - _e94);+ let _e96 = dir;+ dl = length(_e96);+ let _e98 = dl;+ if (_e98 > 0.0001f) {+ let _e101 = dir[1u];+ let _e104 = dir[0u];+ let _e106 = dl;+ local_4 = (vec2<f32>(-(_e101), _e104) / vec2(_e106));+ } else {+ local_4 = vec2<f32>(1f, 0f);+ }+ let _e109 = local_4;+ perp = _e109;+ blocked = 0f;+ s = 0i;+ loop {+ let _e110 = s;+ if (_e110 < 5i) {+ let _e112 = s;+ t = (((f32(_e112) / 4f) * 2f) - 1f);+ let _e117 = (*target_);+ let _e118 = perp;+ let _e119 = t;+ let _e120 = (*softness);+ tp = (_e117 + (_e118 * (_e119 * _e120)));+ i_1 = 0i;+ loop {+ let _e124 = i_1;+ if (_e124 < 8i) {+ let _e126 = i_1;+ let _e127 = n;+ if (_e126 >= _e127) {+ break;+ }+ let _e129 = i_1;+ let _e130 = (*worldPos);+ param_3 = _e130;+ let _e131 = tp;+ param_4 = _e131;+ let _e134 = unnamed.u_occluders[_e129];+ param_5 = _e134;+ let _e135 = segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b((¶m_3), (¶m_4), (¶m_5));+ if (_e135 > 0.5f) {+ let _e137 = blocked;+ blocked = (_e137 + 1f);+ break;+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e139 = i_1;+ i_1 = (_e139 + 1i);+ }+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e141 = s;+ s = (_e141 + 1i);+ }+ }+ let _e143 = blocked;+ return (1f - (_e143 / 5f));+}++fn applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b(albedo: ptr<function, vec3<f32>>, N: ptr<function, vec3<f32>>, worldPos_1: ptr<function, vec2<f32>>) -> vec3<f32> {+ var lit: vec3<f32>;+ var i_2: i32;+ var pd: vec4<f32>;+ var col: vec4<f32>;+ var sh: vec4<f32>;+ var target_1: vec2<f32>;+ var castShadow: bool;+ var d_1: vec2<f32>;+ var dist: f32;+ var atten: f32;+ var L: vec3<f32>;+ var toLight: vec2<f32>;+ var local_5: vec2<f32>;+ var sp: vec4<f32>;+ var d_2: vec2<f32>;+ var dist_1: f32;+ var toFrag: vec2<f32>;+ var local_6: vec2<f32>;+ var param_6: vec2<f32>;+ var param_7: vec2<f32>;+ var param_8: f32;+ var ndotl: f32;+ var phi_458_: bool;+ var phi_525_: bool;++ let _e76 = unnamed.u_ambient;+ lit = _e76.xyz;+ i_2 = 0i;+ loop {+ let _e78 = i_2;+ if (_e78 < 16i) {+ let _e80 = i_2;+ let _e84 = unnamed.u_lights[_e80].posDir;+ pd = _e84;+ let _e85 = i_2;+ let _e89 = unnamed.u_lights[_e85].color;+ col = _e89;+ let _e90 = i_2;+ let _e94 = unnamed.u_lights[_e90].shadow;+ sh = _e94;+ let _e95 = pd;+ target_1 = _e95.xy;+ castShadow = true;+ let _e98 = pd[2u];+ if (_e98 < 0.5f) {+ let _e100 = pd;+ let _e102 = (*worldPos_1);+ d_1 = (_e100.xy - _e102);+ let _e104 = d_1;+ dist = length(_e104);+ let _e106 = dist;+ let _e108 = pd[3u];+ atten = max(0f, (1f - (_e106 / max(_e108, 0.0001f))));+ let _e113 = d_1;+ let _e115 = pd[3u];+ L = normalize(vec3<f32>(_e113.x, _e113.y, max(_e115, 1f)));+ } else {+ let _e122 = pd[2u];+ if (_e122 < 1.5f) {+ atten = 1f;+ let _e124 = pd;+ let _e126 = -(_e124.xy);+ L = normalize(vec3<f32>(_e126.x, _e126.y, 1f));+ let _e131 = pd;+ let _e133 = pd;+ if (dot(_e131.xy, _e133.xy) > 0.00000001f) {+ let _e137 = pd;+ local_5 = normalize(-(_e137.xy));+ } else {+ local_5 = vec2<f32>(0f, 0f);+ }+ let _e141 = local_5;+ toLight = _e141;+ let _e143 = sh[1u];+ let _e144 = (_e143 > 0f);+ phi_458_ = _e144;+ if _e144 {+ let _e145 = toLight;+ let _e146 = toLight;+ phi_458_ = (dot(_e145, _e146) > 0.5f);+ }+ let _e150 = phi_458_;+ castShadow = _e150;+ let _e151 = (*worldPos_1);+ let _e152 = toLight;+ let _e154 = sh[1u];+ target_1 = (_e151 + (_e152 * _e154));+ } else {+ let _e157 = i_2;+ let _e161 = unnamed.u_lights[_e157].spot;+ sp = _e161;+ let _e162 = pd;+ let _e164 = (*worldPos_1);+ d_2 = (_e162.xy - _e164);+ let _e166 = d_2;+ dist_1 = length(_e166);+ let _e168 = dist_1;+ let _e170 = pd[3u];+ atten = max(0f, (1f - (_e168 / max(_e170, 0.0001f))));+ let _e175 = d_2;+ let _e177 = pd[3u];+ L = normalize(vec3<f32>(_e175.x, _e175.y, max(_e177, 1f)));+ let _e183 = dist_1;+ if (_e183 > 0.0001f) {+ let _e185 = d_2;+ let _e187 = dist_1;+ local_6 = (-(_e185) / vec2(_e187));+ } else {+ let _e190 = sp;+ local_6 = _e190.xy;+ }+ let _e192 = local_6;+ toFrag = _e192;+ let _e194 = sp[3u];+ let _e196 = sp[2u];+ let _e197 = sp;+ let _e199 = toFrag;+ let _e202 = atten;+ atten = (_e202 * smoothstep(_e194, _e196, dot(_e197.xy, _e199)));+ }+ }+ let _e204 = castShadow;+ phi_525_ = _e204;+ if _e204 {+ let _e206 = col[3u];+ phi_525_ = (_e206 > 0f);+ }+ let _e209 = phi_525_;+ let _e210 = atten;+ if (_e209 && (_e210 > 0f)) {+ let _e213 = (*worldPos_1);+ param_6 = _e213;+ let _e214 = target_1;+ param_7 = _e214;+ let _e216 = sh[0u];+ param_8 = _e216;+ let _e217 = shadowFactor2D_u0028_vf2_u003b_vf2_u003b_f1_u003b((¶m_6), (¶m_7), (¶m_8));+ let _e218 = atten;+ atten = (_e218 * _e217);+ }+ let _e220 = (*N);+ let _e221 = L;+ ndotl = max(dot(_e220, _e221), 0f);+ let _e224 = col;+ let _e227 = col[3u];+ let _e228 = ndotl;+ let _e230 = atten;+ let _e233 = lit;+ lit = (_e233 + (_e224.xyz * ((_e227 * _e228) * _e230)));+ continue;+ } else {+ break;+ }+ continuing {+ let _e235 = i_2;+ i_2 = (_e235 + 1i);+ }+ }+ let _e237 = (*albedo);+ let _e238 = lit;+ return (_e237 * _e238);+}++fn sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(map_est: texture_2d<f32>, map_ess: sampler, uv: ptr<function, vec2<f32>>) -> vec3<f32> {+ let _e53 = (*uv);+ let _e54 = textureSample(map_est, map_ess, _e53);+ return normalize(((_e54.xyz * 2f) - vec3(1f)));+}++fn main_1() {+ var base: vec4<f32>;+ var N_1: vec3<f32>;+ var param_9: vec2<f32>;+ var lit_1: vec3<f32>;+ var param_10: vec3<f32>;+ var param_11: vec3<f32>;+ var param_12: vec2<f32>;++ let _e57 = v_texCoord_1;+ let _e58 = textureSample(es_bt0_est, es_bt0_ess, _e57);+ let _e59 = v_color_1;+ base = (_e58 * _e59);+ let _e61 = v_texCoord_1;+ param_9 = _e61;+ let _e62 = sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(u_normal_est, u_normal_ess, (¶m_9));+ N_1 = _e62;+ let _e63 = base;+ param_10 = _e63.xyz;+ let _e65 = N_1;+ param_11 = _e65;+ let _e66 = v_worldPos_1;+ param_12 = _e66;+ let _e67 = applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b((¶m_10), (¶m_11), (¶m_12));+ lit_1 = _e67;+ let _e68 = lit_1;+ let _e70 = base[3u];+ fragColor = vec4<f32>(_e68.x, _e68.y, _e68.z, _e70);+ return;+}++@fragment+fn fs_main(@location(1) v_texCoord: vec2<f32>, @location(0) v_color: vec4<f32>, @location(2) v_worldPos: vec2<f32>) -> @location(0) vec4<f32> {+ v_texCoord_1 = v_texCoord;+ v_color_1 = v_color;+ v_worldPos_1 = v_worldPos;+ main_1();+ let _e7 = fragColor;+ return _e7;+}+#pragma enddiff --git a/desktop/public/scenes/mat-lit/lit.esshader b/desktop/public/scenes/mat-lit/lit.esshaderindex 927b9238a..a4644ce0f 100644--- a/desktop/public/scenes/mat-lit/lit.esshader+++ b/desktop/public/scenes/mat-lit/lit.esshader@@ -45,3 +45,602 @@ void main() {fragColor = vec4(lit, base.a);}#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.+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 VertexOutput {+ @builtin(position) gl_Position: vec4<f32>,+ @location(0) member: vec4<f32>,+ @location(1) member_1: vec2<f32>,+ @location(2) member_2: 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>;+var<private> v_worldPos: vec2<f32>;+@group(0) @binding(3)+var<uniform> unnamed_2: TimeConstants;+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;+ let _e23 = a_position_1;+ v_worldPos = _e23;+ 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 _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);+}+#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.+struct Light2D {+ posDir: vec4<f32>,+ color: vec4<f32>,+ spot: vec4<f32>,+ shadow: vec4<f32>,+}++struct LightConstants {+ u_ambient: vec4<f32>,+ u_lights: array<Light2D, 16>,+ u_occluderCount: vec4<f32>,+ u_occluders: array<vec4<f32>, 8>,+}++struct TimeConstants {+ u_time: vec4<f32>,+ u_viewport: vec4<f32>,+}++@group(0) @binding(2)+var<uniform> unnamed: LightConstants;+@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> v_color_1: vec4<f32>;+var<private> v_worldPos_1: vec2<f32>;+var<private> fragColor: vec4<f32>;+@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 segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b(p0_: ptr<function, vec2<f32>>, p1_: ptr<function, vec2<f32>>, box: ptr<function, vec4<f32>>) -> f32 {+ var d: vec2<f32>;+ var tmin: f32;+ var tmax: f32;+ var a: i32;+ var da: f32;+ var local: f32;+ var p0a: f32;+ var local_1: f32;+ var lo: f32;+ var local_2: f32;+ var hi: f32;+ var local_3: f32;+ var t1_: f32;+ var t2_: f32;+ var phi_48_: bool;+ var phi_57_: bool;+ var phi_66_: bool;++ let _e67 = (*p0_)[0u];+ let _e69 = (*box)[0u];+ let _e70 = (_e67 >= _e69);+ phi_48_ = _e70;+ if _e70 {+ let _e72 = (*p0_)[1u];+ let _e74 = (*box)[1u];+ phi_48_ = (_e72 >= _e74);+ }+ let _e77 = phi_48_;+ phi_57_ = _e77;+ if _e77 {+ let _e79 = (*p0_)[0u];+ let _e81 = (*box)[2u];+ phi_57_ = (_e79 <= _e81);+ }+ let _e84 = phi_57_;+ phi_66_ = _e84;+ if _e84 {+ let _e86 = (*p0_)[1u];+ let _e88 = (*box)[3u];+ phi_66_ = (_e86 <= _e88);+ }+ let _e91 = phi_66_;+ if _e91 {+ return 0f;+ }+ let _e92 = (*p1_);+ let _e93 = (*p0_);+ d = (_e92 - _e93);+ tmin = 0f;+ tmax = 1f;+ a = 0i;+ loop {+ let _e95 = a;+ if (_e95 < 2i) {+ let _e97 = a;+ if (_e97 == 0i) {+ let _e100 = d[0u];+ local = _e100;+ } else {+ let _e102 = d[1u];+ local = _e102;+ }+ let _e103 = local;+ da = _e103;+ let _e104 = a;+ if (_e104 == 0i) {+ let _e107 = (*p0_)[0u];+ local_1 = _e107;+ } else {+ let _e109 = (*p0_)[1u];+ local_1 = _e109;+ }+ let _e110 = local_1;+ p0a = _e110;+ let _e111 = a;+ if (_e111 == 0i) {+ let _e114 = (*box)[0u];+ local_2 = _e114;+ } else {+ let _e116 = (*box)[1u];+ local_2 = _e116;+ }+ let _e117 = local_2;+ let _e118 = p0a;+ lo = (_e117 - _e118);+ let _e120 = a;+ if (_e120 == 0i) {+ let _e123 = (*box)[2u];+ local_3 = _e123;+ } else {+ let _e125 = (*box)[3u];+ local_3 = _e125;+ }+ let _e126 = local_3;+ let _e127 = p0a;+ hi = (_e126 - _e127);+ let _e129 = da;+ if (abs(_e129) < 0.00001f) {+ let _e132 = lo;+ let _e134 = hi;+ if ((_e132 > 0f) || (_e134 < 0f)) {+ return 0f;+ }+ } else {+ let _e137 = lo;+ let _e138 = da;+ t1_ = (_e137 / _e138);+ let _e140 = hi;+ let _e141 = da;+ t2_ = (_e140 / _e141);+ let _e143 = tmin;+ let _e144 = t1_;+ let _e145 = t2_;+ tmin = max(_e143, min(_e144, _e145));+ let _e148 = tmax;+ let _e149 = t1_;+ let _e150 = t2_;+ tmax = min(_e148, max(_e149, _e150));+ let _e153 = tmin;+ let _e154 = tmax;+ if (_e153 > _e154) {+ return 0f;+ }+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e156 = a;+ a = (_e156 + 1i);+ }+ }+ return 1f;+}++fn shadowFactor2D_u0028_vf2_u003b_vf2_u003b_f1_u003b(worldPos: ptr<function, vec2<f32>>, target_: ptr<function, vec2<f32>>, softness: ptr<function, f32>) -> f32 {+ var n: i32;+ var i: i32;+ var param: vec2<f32>;+ var param_1: vec2<f32>;+ var param_2: vec4<f32>;+ var dir: vec2<f32>;+ var dl: f32;+ var perp: vec2<f32>;+ var local_4: vec2<f32>;+ var blocked: f32;+ var s: i32;+ var t: f32;+ var tp: vec2<f32>;+ var i_1: i32;+ var param_3: vec2<f32>;+ var param_4: vec2<f32>;+ var param_5: vec4<f32>;++ let _e71 = unnamed.u_occluderCount[0u];+ n = i32(_e71);+ let _e73 = n;+ if (_e73 <= 0i) {+ return 1f;+ }+ let _e75 = (*softness);+ if (_e75 < 0.0001f) {+ i = 0i;+ loop {+ let _e77 = i;+ if (_e77 < 8i) {+ let _e79 = i;+ let _e80 = n;+ if (_e79 >= _e80) {+ break;+ }+ let _e82 = i;+ let _e83 = (*worldPos);+ param = _e83;+ let _e84 = (*target_);+ param_1 = _e84;+ let _e87 = unnamed.u_occluders[_e82];+ param_2 = _e87;+ let _e88 = segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b((¶m), (¶m_1), (¶m_2));+ if (_e88 > 0.5f) {+ return 0f;+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e90 = i;+ i = (_e90 + 1i);+ }+ }+ return 1f;+ }+ let _e92 = (*target_);+ let _e93 = (*worldPos);+ dir = (_e92 - _e93);+ let _e95 = dir;+ dl = length(_e95);+ let _e97 = dl;+ if (_e97 > 0.0001f) {+ let _e100 = dir[1u];+ let _e103 = dir[0u];+ let _e105 = dl;+ local_4 = (vec2<f32>(-(_e100), _e103) / vec2(_e105));+ } else {+ local_4 = vec2<f32>(1f, 0f);+ }+ let _e108 = local_4;+ perp = _e108;+ blocked = 0f;+ s = 0i;+ loop {+ let _e109 = s;+ if (_e109 < 5i) {+ let _e111 = s;+ t = (((f32(_e111) / 4f) * 2f) - 1f);+ let _e116 = (*target_);+ let _e117 = perp;+ let _e118 = t;+ let _e119 = (*softness);+ tp = (_e116 + (_e117 * (_e118 * _e119)));+ i_1 = 0i;+ loop {+ let _e123 = i_1;+ if (_e123 < 8i) {+ let _e125 = i_1;+ let _e126 = n;+ if (_e125 >= _e126) {+ break;+ }+ let _e128 = i_1;+ let _e129 = (*worldPos);+ param_3 = _e129;+ let _e130 = tp;+ param_4 = _e130;+ let _e133 = unnamed.u_occluders[_e128];+ param_5 = _e133;+ let _e134 = segHitsBox_u0028_vf2_u003b_vf2_u003b_vf4_u003b((¶m_3), (¶m_4), (¶m_5));+ if (_e134 > 0.5f) {+ let _e136 = blocked;+ blocked = (_e136 + 1f);+ break;+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e138 = i_1;+ i_1 = (_e138 + 1i);+ }+ }+ continue;+ } else {+ break;+ }+ continuing {+ let _e140 = s;+ s = (_e140 + 1i);+ }+ }+ let _e142 = blocked;+ return (1f - (_e142 / 5f));+}++fn applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b(albedo: ptr<function, vec3<f32>>, N: ptr<function, vec3<f32>>, worldPos_1: ptr<function, vec2<f32>>) -> vec3<f32> {+ var lit: vec3<f32>;+ var i_2: i32;+ var pd: vec4<f32>;+ var col: vec4<f32>;+ var sh: vec4<f32>;+ var target_1: vec2<f32>;+ var castShadow: bool;+ var d_1: vec2<f32>;+ var dist: f32;+ var atten: f32;+ var L: vec3<f32>;+ var toLight: vec2<f32>;+ var local_5: vec2<f32>;+ var sp: vec4<f32>;+ var d_2: vec2<f32>;+ var dist_1: f32;+ var toFrag: vec2<f32>;+ var local_6: vec2<f32>;+ var param_6: vec2<f32>;+ var param_7: vec2<f32>;+ var param_8: f32;+ var ndotl: f32;+ var phi_435_: bool;+ var phi_502_: bool;++ let _e75 = unnamed.u_ambient;+ lit = _e75.xyz;+ i_2 = 0i;+ loop {+ let _e77 = i_2;+ if (_e77 < 16i) {+ let _e79 = i_2;+ let _e83 = unnamed.u_lights[_e79].posDir;+ pd = _e83;+ let _e84 = i_2;+ let _e88 = unnamed.u_lights[_e84].color;+ col = _e88;+ let _e89 = i_2;+ let _e93 = unnamed.u_lights[_e89].shadow;+ sh = _e93;+ let _e94 = pd;+ target_1 = _e94.xy;+ castShadow = true;+ let _e97 = pd[2u];+ if (_e97 < 0.5f) {+ let _e99 = pd;+ let _e101 = (*worldPos_1);+ d_1 = (_e99.xy - _e101);+ let _e103 = d_1;+ dist = length(_e103);+ let _e105 = dist;+ let _e107 = pd[3u];+ atten = max(0f, (1f - (_e105 / max(_e107, 0.0001f))));+ let _e112 = d_1;+ let _e114 = pd[3u];+ L = normalize(vec3<f32>(_e112.x, _e112.y, max(_e114, 1f)));+ } else {+ let _e121 = pd[2u];+ if (_e121 < 1.5f) {+ atten = 1f;+ let _e123 = pd;+ let _e125 = -(_e123.xy);+ L = normalize(vec3<f32>(_e125.x, _e125.y, 1f));+ let _e130 = pd;+ let _e132 = pd;+ if (dot(_e130.xy, _e132.xy) > 0.00000001f) {+ let _e136 = pd;+ local_5 = normalize(-(_e136.xy));+ } else {+ local_5 = vec2<f32>(0f, 0f);+ }+ let _e140 = local_5;+ toLight = _e140;+ let _e142 = sh[1u];+ let _e143 = (_e142 > 0f);+ phi_435_ = _e143;+ if _e143 {+ let _e144 = toLight;+ let _e145 = toLight;+ phi_435_ = (dot(_e144, _e145) > 0.5f);+ }+ let _e149 = phi_435_;+ castShadow = _e149;+ let _e150 = (*worldPos_1);+ let _e151 = toLight;+ let _e153 = sh[1u];+ target_1 = (_e150 + (_e151 * _e153));+ } else {+ let _e156 = i_2;+ let _e160 = unnamed.u_lights[_e156].spot;+ sp = _e160;+ let _e161 = pd;+ let _e163 = (*worldPos_1);+ d_2 = (_e161.xy - _e163);+ let _e165 = d_2;+ dist_1 = length(_e165);+ let _e167 = dist_1;+ let _e169 = pd[3u];+ atten = max(0f, (1f - (_e167 / max(_e169, 0.0001f))));+ let _e174 = d_2;+ let _e176 = pd[3u];+ L = normalize(vec3<f32>(_e174.x, _e174.y, max(_e176, 1f)));+ let _e182 = dist_1;+ if (_e182 > 0.0001f) {+ let _e184 = d_2;+ let _e186 = dist_1;+ local_6 = (-(_e184) / vec2(_e186));+ } else {+ let _e189 = sp;+ local_6 = _e189.xy;+ }+ let _e191 = local_6;+ toFrag = _e191;+ let _e193 = sp[3u];+ let _e195 = sp[2u];+ let _e196 = sp;+ let _e198 = toFrag;+ let _e201 = atten;+ atten = (_e201 * smoothstep(_e193, _e195, dot(_e196.xy, _e198)));+ }+ }+ let _e203 = castShadow;+ phi_502_ = _e203;+ if _e203 {+ let _e205 = col[3u];+ phi_502_ = (_e205 > 0f);+ }+ let _e208 = phi_502_;+ let _e209 = atten;+ if (_e208 && (_e209 > 0f)) {+ let _e212 = (*worldPos_1);+ param_6 = _e212;+ let _e213 = target_1;+ param_7 = _e213;+ let _e215 = sh[0u];+ param_8 = _e215;+ let _e216 = shadowFactor2D_u0028_vf2_u003b_vf2_u003b_f1_u003b((¶m_6), (¶m_7), (¶m_8));+ let _e217 = atten;+ atten = (_e217 * _e216);+ }+ let _e219 = (*N);+ let _e220 = L;+ ndotl = max(dot(_e219, _e220), 0f);+ let _e223 = col;+ let _e226 = col[3u];+ let _e227 = ndotl;+ let _e229 = atten;+ let _e232 = lit;+ lit = (_e232 + (_e223.xyz * ((_e226 * _e227) * _e229)));+ continue;+ } else {+ break;+ }+ continuing {+ let _e234 = i_2;+ i_2 = (_e234 + 1i);+ }+ }+ let _e236 = (*albedo);+ let _e237 = lit;+ return (_e236 * _e237);+}++fn main_1() {+ var base: vec4<f32>;+ var N_1: vec3<f32>;+ var lit_1: vec3<f32>;+ var param_9: vec3<f32>;+ var param_10: vec3<f32>;+ var param_11: vec2<f32>;++ let _e55 = v_texCoord_1;+ let _e56 = textureSample(es_bt0_est, es_bt0_ess, _e55);+ let _e57 = v_color_1;+ base = (_e56 * _e57);+ N_1 = vec3<f32>(0f, 0f, 1f);+ let _e59 = base;+ param_9 = _e59.xyz;+ let _e61 = N_1;+ param_10 = _e61;+ let _e62 = v_worldPos_1;+ param_11 = _e62;+ let _e63 = applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b((¶m_9), (¶m_10), (¶m_11));+ lit_1 = _e63;+ let _e64 = lit_1;+ let _e66 = base[3u];+ fragColor = vec4<f32>(_e64.x, _e64.y, _e64.z, _e66);+ return;+}++@fragment+fn fs_main(@location(1) v_texCoord: vec2<f32>, @location(0) v_color: vec4<f32>, @location(2) v_worldPos: vec2<f32>) -> @location(0) vec4<f32> {+ v_texCoord_1 = v_texCoord;+ v_color_1 = v_color;+ v_worldPos_1 = v_worldPos;+ main_1();+ let _e7 = fragColor;+ return _e7;+}+#pragma enddiff --git a/desktop/public/scenes/mat-tex/masked.esshader b/desktop/public/scenes/mat-tex/masked.esshaderindex 330024d04..4ec42a511 100644--- a/desktop/public/scenes/mat-tex/masked.esshader+++ b/desktop/public/scenes/mat-tex/masked.esshader@@ -37,3 +37,105 @@ void main() {fragColor = texture(u_mask, v_texCoord) * v_color;}#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.+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 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(1) @binding(16)+var u_mask_est: texture_2d<f32>;+@group(1) @binding(24)+var u_mask_ess: sampler;+var<private> a_texIndex_1: f32;++fn main_1() {+ let _e15 = unnamed_1.u_projection;+ let _e16 = a_position_1;+ unnamed.gl_Position = (_e15 * vec4<f32>(_e16.x, _e16.y, 0f, 1f));+ let _e22 = a_color_1;+ v_color = _e22;+ let _e23 = a_texCoord_1;+ v_texCoord = _e23;+ 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 _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);+}+#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.+struct TimeConstants {+ u_time: vec4<f32>,+ u_viewport: vec4<f32>,+}++var<private> fragColor: vec4<f32>;+@group(1) @binding(16)+var u_mask_est: texture_2d<f32>;+@group(1) @binding(24)+var u_mask_ess: sampler;+var<private> v_texCoord_1: vec2<f32>;+var<private> v_color_1: vec4<f32>;+@group(0) @binding(3)+var<uniform> unnamed: TimeConstants;++fn main_1() {+ let _e6 = v_texCoord_1;+ let _e7 = textureSample(u_mask_est, u_mask_ess, _e6);+ let _e8 = v_color_1;+ fragColor = (_e7 * _e8);+ 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 enddiff --git a/docs/REARCHITECTURE.md b/docs/REARCHITECTURE.mdindex ce7cc7dbb..b1ab992af 100644--- a/docs/REARCHITECTURE.md+++ b/docs/REARCHITECTURE.md@@ -190,7 +190,8 @@ TS 驱动的主 pass clear 退出边界,`clear` 家族退出公共 RHI:**SDK 启动 + resize(campaign coda)**:web 变体带 WebGPU 后端(wechat/playable 保持 GL 零胶水体积)、`WebAppOptions.backend`、`ESTELLA_VERIFY_BACKEND=webgpu` 场景断言像素精确相等、`GfxDevice::resizeBackbuffer` 每帧契约(WebGPU swapchain 重配)。**Custom-draw/Draw API 现代化(2026-07-08,最后一个 GL-only 通路闭合)**:新绑定 `draw_meshWithMaterial`——反射材质(compileEsshader)经 `MaterialStore::bindForDraw` 走 MaterialConstants(binding 1)+ 材质记录供给全部管线态,两后端同路零散装 uniform;TS 侧 18 名字 loose 表退为 raw-GLSL `createShader` 兼容路径。编辑器网格迁双语 `.esshader`(`u_model`→`u_rect` 参数 + authored vertex 声明 FrameConstants)——**WebGPU 下编辑器网格首次渲染**,GL/WebGPU 帧一致;`ESTELLA_VERIFY_GRID` 双后端 on/off 像素 diff 断言入 harness。**WebGPU 异步 readback seam(2026-07-08,后端不对称性收口)**:同步 `readPixels` 退出 RHI,全接口统一为异步四段 `requestReadback / pollReadback / takeReadback / discardReadback`(GL = 请求时同步读、首 poll 即 Ready;WebGPU = `copyTextureToBuffer` → 256 对齐 staging + `mapAsync(AllowSpontaneous)`,跨事件循环 turn 落地;行序统一 bottom-up 契约在 take 时翻转)。RenderFrame 的两个消费者(材质预览 renderToTarget、帧调试器 replayToDrawCall)改为 pass 关闭后请求 + `pollPreview/SnapshotReadback` 落地(顺带修 snapshot 尺寸 getter 读当前帧而非快照时尺寸的隐患);TS 侧 `Material.renderPreview`/`Renderer.getSnapshotImageData` 转 Promise(`readback.ts` 单一 poll 循环,双后端同码)。离屏色纹理补 `CopySrc` usage。**材质预览断言在 WebGPU 下点亮**:mat-tint 场景(补了手写 WGSL 孪生的用户 `.esshader` 资产)双后端 EXPECT + PREVIEW 像素精确 PASS——顺带证明场景资产 shader 带孪生即可整链上 WebGPU。-**剩余**:Phase 4 用户手写 `.esshader` 的 cook 期 naga 转换(归 RC6 资产管线;无孪生的场景资产 shader 在 WebGPU 下按设计描述性跳过);CI 无 WebGPU 适配器(webgpu verify 仅本地)。+**Phase 4 转换管线(2026-07-08)**:用户 `.esshader` 的 GLSL→WGSL 自动孪生落地——`tools/gen-shader-twins.mjs`:引擎 wasm 新绑定 `esshader_cookInfo`(web glue 可在纯 Node 加载)吐出与运行时逐字节一致的装配后 GLSL + 纹理单元反射(零漂移),经方言适配(310 es、precision 全 highp、显式引擎绑定注入、combined sampler 拆对、函数采样器参数/实参拆分、varying location 按名对齐)→ `glslangValidator -V` → `naga` → 自包含 `#pragma vertex|fragment wgsl full` 孪生段(ShaderParser 新语义:full 段跳过全部注入头)。9 个 fixture shader 批量生成后,mat-lit 系/mat-tex/mat-dissolve/mat-graph/mat-builtin-lit/mat-instance **在 WebGPU 全部从全黑转绿,lit 像素与 GL 逐点一致**(15 场景 battery)。带 `#pragma switch` 的 shader 跳过(排列需逐集合,手写孪生)。+**剩余**:cook 管线集成(cookAssets 挂钩 + 转换器 vendored wasm 交付,前置 = RC6 资产依赖图两个存量缺口:assetDb 不扫 .esmaterial 引用、collectRefs 只认 @uuid: 不认路径引用);CI 无 WebGPU 适配器(webgpu verify 仅本地)。见 `REARCH_WGSL.md`(本地 gitignore,同 RC6/2D_PARITY 约定):着色器版图盘点(uniform 数据已全后端中立,剩程序文本)、岔路拍板(有限集人工孪生 / 图材质 AST 双发射 / 用户材质 cook 期转换——拒绝运行时翻译器的 MB 级体积代价)、四期计划(源语言接缝 → WebGPUDevice 原型 → 双语发射 → cook 期用户材质)。**Phase 0 已落地**:最后 3 个 GLSL ES 1.00 残留(SDK outline/drop-shadow/color-matrix 滤镜)重写为 fragment-only `.esshader` 反射路径——顺带修复其设计性破损(raw 形态无 `u_projection` 来源、无属性绑定、mat4 超 `setMaterialUniform` 的 vec4 上限**从未能传入**;色彩矩阵改为 4×vec4 行 + 偏移列,新增 `Filters.colorMatrixUniforms` 助手)。全仓每个程序自此都在现代缝上(300 es + UBO 反射)。**Phase 1(源语言接缝)已落地**:RHI 补上最后一块后端中立拼图——`createProgram` 收语言标签的 `GfxShaderSource`,新增 `supportsShaderLanguage` 能力查询(GL = 仅 GLSL ES 300;`Shader::compile` 在任何 GPU 调用前对不支持的语言快速失败);语言贯穿 Shader/ResourceManager(DrawParams 重写仅对 GLSL 生效);`ShaderParser::assembleStage` 获得 `ShaderTargetLanguage` 参数(WGSL 发射 = Phase 3)。MockGfxDevice 新增 `wgslSupported` 开关 + 语言门用例;行为零变化(8 harness + 场景抽样等价)。**Phase 2 切片 1(WebGPU 后端启动)已落地**:emdawnwebgpu 端口(Dawn)集成为测试目标独立依赖(主构建零影响);`renderer/webgpu/` 新增纯映射层(GfxEnums→WGPU 全翻译,blend/模板表镜像 GLDevice 语义,load-op 规则与 RenderPassDesc 契约一致)+ 空设备安全的 `WebGPUDevice` 骨架(缓冲/纹理/WGSL 模块真实现,布局/管线描述符保留待惰性构建,pass/draw 为切片 2 结构化桩);`test_webgpu_device` 用真 Dawn 头编译验证全部描述符拼写,入 CI。diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.tsindex bcc1f28ea..5230b2901 100644--- a/sdk/src/wasm.ts+++ b/sdk/src/wasm.ts@@ -238,6 +238,15 @@ export interface ESEngineModule {/** Reflected-material mesh draw (MaterialConstants UBO); false = shader has no* #pragma-param layout, caller falls back to the loose uniform stream. */draw_meshWithMaterial(geometryHandle: number, materialId: number): boolean;+ /** Cook-time introspection (tools/gen-shader-twins.mjs): assembles both GLSL+ * stages exactly as the runtime + the texture-unit reflection a GLSL→WGSL+ * converter needs. Not called by the SDK itself. */+ esshader_cookInfo(source: string, featuresCsv: string): {+ valid: boolean; error?: string; name: string; domain: string;+ hasWgslVertex: boolean; hasWgslFragment: boolean; hasSwitches: boolean;+ vertGlsl: string; fragGlsl: string;+ textures: Array<{ name: string; unit: number }>;+ };// Geometry APIgeometry_create(): number;diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex f5c5c47ae..6b29d1d25 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -130,14 +130,8 @@ static MaterialUniformLayout buildMaterialLayout(const resource::ParsedShader& p// `#pragma switch` set (comma-separated), so a material's static switches select a permutation;// the SDK loader caches one compiled program per (shader, switch-set). Returns the shader// resource handle (0 on failure). Reflection-aware replacement for the loader's old regex.-u32 compileEsshader(const std::string& source, const std::string& featuresCsv) {- auto* rm = g_resourceManager;- if (!rm) return 0;- resource::ParsedShader parsed = resource::ShaderParser::parse(source);- if (!parsed.valid) {- ES_LOG_ERROR("compileEsshader: parse failed: {}", parsed.errorMessage);- return 0;- }+// Split a comma-separated feature list into trimmed, non-empty entries.+static std::vector<std::string> splitFeaturesCsv(const std::string& featuresCsv) {std::vector<std::string> features;for (usize start = 0; start <= featuresCsv.size();) {const usize comma = featuresCsv.find(',', start);@@ -150,6 +144,18 @@ u32 compileEsshader(const std::string& source, const std::string& featuresCsv) {if (comma == std::string::npos) break;start = comma + 1;}+ return features;+}++u32 compileEsshader(const std::string& source, const std::string& featuresCsv) {+ auto* rm = g_resourceManager;+ if (!rm) return 0;+ resource::ParsedShader parsed = resource::ShaderParser::parse(source);+ if (!parsed.valid) {+ ES_LOG_ERROR("compileEsshader: parse failed: {}", parsed.errorMessage);+ return 0;+ }+ std::vector<std::string> features = splitFeaturesCsv(featuresCsv);// Assemble both stages for the backend's language — a material .esshader// carries its WGSL twin in-file, and a missing twin surfaces here as a// descriptive assembly error rather than a backend compile failure.@@ -185,6 +191,48 @@ u32 compileEsshader(const std::string& source, const std::string& featuresCsv) {return handle.id();}+// Cook-time introspection: assembles both GLSL stages exactly as the runtime would+// (same parser + injected headers), plus the reflection a GLSL→WGSL converter needs+// (texture params → sampler units). The export cook feeds the assembled stages through+// glslang+naga and appends the result as `#pragma vertex|fragment wgsl full` twins,+// so twin-less user .esshader assets run on WebGPU (REARCH_WGSL Phase 4). Runs under+// plain Node (the web glue loads there), so the cook needs no browser context.+emscripten::val esshader_cookInfo(const std::string& source, const std::string& featuresCsv) {+ emscripten::val out = emscripten::val::object();+ resource::ParsedShader parsed = resource::ShaderParser::parse(source);+ out.set("valid", parsed.valid);+ if (!parsed.valid) {+ out.set("error", parsed.errorMessage);+ return out;+ }+ const std::vector<std::string> features = splitFeaturesCsv(featuresCsv);+ const std::string vert = resource::ShaderParser::assembleStage(+ parsed, resource::ShaderStage::Vertex, "", features,+ resource::ShaderTargetLanguage::GLSL_ES300);+ const std::string frag = resource::ShaderParser::assembleStage(+ parsed, resource::ShaderStage::Fragment, "", features,+ resource::ShaderTargetLanguage::GLSL_ES300);+ out.set("name", parsed.name);+ out.set("domain", parsed.domain);+ 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("vertGlsl", vert);+ out.set("fragGlsl", frag);+ emscripten::val textures = emscripten::val::array();+ u32 count = 0;+ for (const auto& p : parsed.properties) {+ if (p.fromParam && p.type == resource::ShaderPropertyType::Texture && p.textureUnit >= 0) {+ emscripten::val tex = emscripten::val::object();+ tex.set("name", p.name);+ tex.set("unit", p.textureUnit);+ textures.set(count++, tex);+ }+ }+ out.set("textures", textures);+ return out;+}+// Materials are engine-side data: the SDK pushes a material's resolved render state here when// it is created or edited, and the render path reads it by the handle a component carries// (Sprite::material, etc.). `shaderHandle` is the SDK shader resource handle, translated here@@ -489,6 +537,7 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {emscripten::function("mesh2d_setGeometry", &esengine::mesh2d_setGeometry);emscripten::function("compileEsshader", &esengine::compileEsshader);+ emscripten::function("esshader_cookInfo", &esengine::esshader_cookInfo);emscripten::function("defineMaterial", &esengine::defineMaterial);emscripten::function("setMaterialUniform", &esengine::setMaterialUniform);emscripten::function("setMaterialTexture", &esengine::setMaterialTexture);diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cppindex a11514fad..f04e459e8 100644--- a/src/esengine/resource/ShaderParser.cpp+++ b/src/esengine/resource/ShaderParser.cpp@@ -264,6 +264,7 @@ ParsedShader ShaderParser::parse(const std::string& source, const ShaderIncludeRstd::ostringstream currentSection;std::vector<SourceLine> currentSectionMap;bool currentSectionIsWGSL = false;+ bool currentSectionIsFullWGSL = false;u32 lineNumber = 0;while (std::getline(stream, line)) {@@ -349,15 +350,18 @@ ParsedShader ShaderParser::parse(const std::string& source, const ShaderIncludeRreturn result;}// Optional language tag: `#pragma fragment wgsl` opens the stage's- // WGSL twin section; no tag is the GLSL stage.- if (!argument.empty() && argument != "wgsl") {+ // WGSL twin section; `wgsl full` marks a SELF-CONTAINED twin whose+ // assembly skips every injected header (the cook-generated shape);+ // no tag is the GLSL stage.+ if (!argument.empty() && argument != "wgsl" && argument != "wgsl full") {result.errorMessage = "Unknown stage language '" + argument +"' at line " + std::to_string(lineNumber) +- " (expected no tag for GLSL, or 'wgsl')";+ " (expected no tag for GLSL, 'wgsl', or 'wgsl full')";return result;}state = (directive == "vertex") ? ParseState::Vertex : ParseState::Fragment;- currentSectionIsWGSL = (argument == "wgsl");+ currentSectionIsWGSL = !argument.empty();+ currentSectionIsFullWGSL = (argument == "wgsl full");currentSection.str("");currentSection.clear();currentSectionMap.clear();@@ -389,8 +393,12 @@ ParsedShader ShaderParser::parse(const std::string& source, const ShaderIncludeRauto& maps = currentSectionIsWGSL ? result.wgslStageLineMaps : result.stageLineMaps;stages[s] = currentSection.str();maps[s] = std::move(currentSectionMap);+ if (currentSectionIsWGSL && currentSectionIsFullWGSL) {+ result.wgslStageFull[s] = true;+ }currentSectionMap.clear();currentSectionIsWGSL = false;+ currentSectionIsFullWGSL = false;break;}case ParseState::Variant:@@ -774,6 +782,16 @@ ShaderParser::AssembledStage assembleWGSLStage(const ParsedShader& parsed,return result;}+ // A `wgsl full` twin is a self-contained program (the cook-generated shape):+ // it carries its own declarations at the engine's binding conventions, so+ // injecting the shared headers would double-declare them.+ auto fullIt = parsed.wgslStageFull.find(stage);+ if (fullIt != parsed.wgslStageFull.end() && fullIt->second) {+ result.source = preprocessWGSL(bodyIt->second, features);+ result.headerLineCount = 0;+ return result;+ }+std::ostringstream assembled;u32 headerLines = 0;auto inject = [&](const std::string& s) {diff --git a/src/esengine/resource/ShaderParser.hpp b/src/esengine/resource/ShaderParser.hppindex ab4d590ff..2ca36288e 100644--- a/src/esengine/resource/ShaderParser.hpp+++ b/src/esengine/resource/ShaderParser.hpp@@ -187,6 +187,16 @@ struct ParsedShader {/** @brief Line maps for wgslStages, same convention as stageLineMaps. */std::unordered_map<ShaderStage, std::vector<SourceLine>> wgslStageLineMaps;+ /**+ * @brief Stages whose WGSL twin is a SELF-CONTAINED program (`#pragma vertex+ * wgsl full` / `#pragma fragment wgsl full`): assembly skips every+ * injected header — the body carries its own declarations at the+ * engine's binding conventions (group 0 UBO slots, group-1+ * texture/sampler unit map). The shape a cook-time GLSL→WGSL+ * conversion emits, since a translator returns whole programs.+ */+ std::unordered_map<ShaderStage, bool> wgslStageFull;+/*** @brief True when the WGSL vertex stage is the injected canonical one.* The WGSL fragment assembly then also injects the matching VSOutdiff --git a/tests/renderer/test_shader_variant.cpp b/tests/renderer/test_shader_variant.cppindex cbc792004..2e48efbe5 100644--- a/tests/renderer/test_shader_variant.cpp+++ b/tests/renderer/test_shader_variant.cpp@@ -292,6 +292,44 @@ static void testWGSLEmission() {CHECK(!badTag.valid && badTag.errorMessage.find("Unknown stage language") != std::string::npos,"unknown stage language tag is a parse error");+ // `wgsl full` twins are self-contained programs (the cook-generated shape):+ // assembly skips every injected header — no tc/mc/canonical prelude — and+ // returns the body as-is, features resolved.+ ParsedShader full = ShaderParser::parse(+ "#pragma shader \"Full\"\n#pragma domain Unlit2D\n"+ "#pragma param u_a float default(0)\n"+ "#pragma vertex\nvoid main() { gl_Position = vec4(0.0); }\n#pragma end\n"+ "#pragma fragment\nvoid main() {}\n#pragma end\n"+ "#pragma vertex wgsl full\n"+ "@group(0) @binding(0) var<uniform> f : mat4x4<f32>;\n"+ "@vertex fn vs_main() -> @builtin(position) vec4<f32> { return f[0]; }\n#pragma end\n"+ "#pragma fragment wgsl full\n"+ "struct MC { u_a: f32 }\n@group(0) @binding(1) var<uniform> m : MC;\n"+ "@fragment fn fs_main() -> @location(0) vec4<f32> { return vec4<f32>(m.u_a); }\n#pragma end\n");+ CHECK(full.valid && !full.wgslVertexIsCanonical, "wgsl full twin pair parses");+ const std::string fullVs = wgsl(full, ShaderStage::Vertex);+ const std::string fullFs = wgsl(full, ShaderStage::Fragment);+ CHECK(fullVs.find("var<uniform> f :") != std::string::npos &&+ fullVs.find("TimeConstants") == std::string::npos,+ "full vertex twin skips the injected headers");+ CHECK(fullFs.find("var<uniform> m :") != std::string::npos &&+ fullFs.find("var<uniform> mc") == std::string::npos &&+ fullFs.find("var t0") == std::string::npos,+ "full fragment twin carries its own declarations, no tc/mc/texture injection");++ // A full twin on one stage composes with a normal twin on the other.+ ParsedShader mixed = ShaderParser::parse(+ "#pragma shader \"Mixed\"\n#pragma domain Unlit2D\n"+ "#pragma fragment\nvoid main() {}\n#pragma end\n"+ "#pragma fragment wgsl full\n"+ "@fragment fn fs_main() -> @location(0) vec4<f32> { return vec4<f32>(1.0); }\n#pragma end\n");+ CHECK(mixed.valid && mixed.wgslVertexIsCanonical,+ "fragment-only full twin still gets the canonical WGSL vertex");+ const std::string mixedFs = wgsl(mixed, ShaderStage::Fragment);+ CHECK(mixedFs.find("struct VSOut") == std::string::npos &&+ mixedFs.find("fn fs_main") != std::string::npos,+ "full fragment twin skips the canonical prelude even beside a canonical vertex");+// std140 offsets == WGSL uniform layout for the param type set: the two// backends read one buffer. float, vec3 (align 16), float (packs at 28).ParsedShader layout = ShaderParser::parse(diff --git a/tools/gen-shader-twins.mjs b/tools/gen-shader-twins.mjsnew file mode 100644index 000000000..8e9d5d274--- /dev/null+++ b/tools/gen-shader-twins.mjs@@ -0,0 +1,346 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * gen-shader-twins — cook-time GLSL→WGSL twin generation (REARCH_WGSL Phase 4).+ *+ * For each user-authored .esshader that lacks a WGSL twin, this appends+ * self-contained `#pragma vertex wgsl full` / `#pragma fragment wgsl full`+ * sections so the shader runs on the WebGPU backend, via the pipeline:+ *+ * engine wasm (esshader_cookInfo) — assemble both GLSL stages EXACTLY as the+ * runtime does (zero drift) + reflection+ * dialect adaptation (this file) — 300 es → 310 es, precision → highp,+ * engine UBO bindings, combined samplers+ * split into texture/sampler pairs at the+ * group-1 unit map, explicit varying+ * locations+ * glslangValidator -V — GLSL ES 310 → SPIR-V (Vulkan semantics)+ * naga — SPIR-V → WGSL+ * post (this file) — entry rename to vs_main/fs_main+ *+ * The emitted twins are FULL programs: ShaderParser skips its injected headers+ * for `wgsl full` sections, so the translated header declarations don't clash.+ * The engine's bind conventions ride explicit GLSL layout qualifiers:+ * group 0 = FrameConstants 0 / MaterialConstants 1 / LightConstants 2 /+ * TimeConstants 3; group 1 = texture unit u at binding (u<8 ? u : u+8) with its+ * sampler at (u<8 ? u+8 : u+16) — mirrors WebGPUMappings.+ *+ * Usage: node tools/gen-shader-twins.mjs [--check] [--force] <file.esshader ...>+ * --check report what would change, write nothing (exit 1 if any)+ * --force regenerate even when a twin exists (replaces generated sections)+ *+ * Requires: a built engine (pnpm build:web), glslangValidator and naga on PATH.+ * Shaders using `#pragma switch` are skipped (permutations need per-set twins;+ * hand-author those) — the tool says so per file.+ */+import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';+import { tmpdir } from 'node:os';+import { execFile } from 'node:child_process';+import { promisify } from 'node:util';+import path from 'node:path';+import { fileURLToPath, pathToFileURL } from 'node:url';++const execFileP = promisify(execFile);+const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');+const WASM_GLUE = path.join(ROOT, 'desktop', 'public', 'wasm', 'esengine.js');++// Engine group-0 UBO slots (Shader::compile / WebGPU bind conventions).+const BLOCK_BINDINGS = {+ FrameConstants: 0,+ MaterialConstants: 1,+ LightConstants: 2,+ TimeConstants: 3,+};++// Group-1 unit map — mirrors WebGPUMappings textureBindingForUnit/samplerBindingForUnit.+const textureBindingForUnit = (u) => (u < 8 ? u : u + 8);+const samplerBindingForUnit = (u) => (u < 8 ? u + 8 : u + 16);++const GENERATED_BANNER =+ '// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.\n' ++ '// Regenerate after changing the GLSL stages above.';++/**+ * Adapt an assembled GLSL ES 300 stage to the dialect glslang -V + naga accept,+ * with the engine's binding conventions made explicit.+ */+function adaptGlsl(glsl, textures) {+ let out = glsl;++ // Strip comments first: GLSL has no string literals, so this is always safe,+ // and it keeps the rewrites below from matching declaration text quoted in+ // comments (a real fixture hit this).+ out = out.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\n]*/g, '');++ // 310 es: the minimum ES version glslang emits SPIR-V for; a superset of the+ // authored 300 es dialect.+ out = out.replace(/#version\s+300\s+es/, '#version 310 es');++ // Precision: force highp everywhere. mediump/lowp emit RelaxedPrecision+ // SPIR-V decorations naga rejects; raising precision is semantically safe.+ out = out.replace(/precision\s+(lowp|mediump)\s+float\s*;/g, 'precision highp float;');+ out = out.replace(/\b(lowp|mediump)\s+/g, 'highp ');+ if (!/precision\s+highp\s+float\s*;/.test(out)) {+ out = out.replace(/(#version[^\n]*\n)/, '$1precision highp float;\n');+ }++ // Engine UBO slots as explicit bindings (SPIR-V descriptor set 0 = WGSL group 0).+ out = out.replace(+ /layout\s*\(\s*std140\s*\)\s*uniform\s+(FrameConstants|MaterialConstants|LightConstants|TimeConstants)\b/g,+ (m, name) => `layout(std140, binding = ${BLOCK_BINDINGS[name]}) uniform ${name}`,+ );++ // Combined samplers → split texture/sampler pairs (naga's SPIR-V frontend has+ // no combined-image-sampler support; WebGPU has no such object either).+ // Vulkan GLSL only allows the sampler2D(t, s) constructor DIRECTLY at a+ // sampling call, so every use form is rewritten explicitly:+ // - sampling builtins: texture(N, ..) → texture(sampler2D(N_est, N_ess), ..)+ // - functions taking sampler2D params: the param splits into a+ // texture2D/sampler pair, and call sites pass both halves.+ const combined = new Set(); // names that split into <name>_est / <name>_ess+ const splitUniformDecl = (name, unit) =>+ `layout(set = 1, binding = ${textureBindingForUnit(unit)}) uniform highp texture2D ${name}_est;\n` ++ `layout(set = 1, binding = ${samplerBindingForUnit(unit)}) uniform highp sampler ${name}_ess;`;++ // Batch texture contract: `uniform sampler2D u_textures[8];` = engine units 0..7.+ out = out.replace(/uniform\s+(?:highp\s+)?sampler2D\s+u_textures\s*\[\s*8\s*\]\s*;/g, () => {+ const decls = [];+ for (let u = 0; u < 8; u++) {+ decls.push(splitUniformDecl(`es_bt${u}`, u));+ combined.add(`es_bt${u}`);+ }+ return decls.join('\n');+ });+ // Constant-indexed accesses (the only legal ES 3.00 form) become unit names,+ // handled by the generic use rewrites below.+ out = out.replace(/\bu_textures\s*\[\s*(\d)\s*\]/g, (m, d) => `es_bt${d}`);+ if (/\bu_textures\b/.test(out)) {+ throw new Error('u_textures indexed with a non-literal expression - cannot split for WGSL');+ }++ // Reflected texture params (assembled as `uniform highp sampler2D <name>;`)+ // at their reflected material units.+ for (const { name, unit } of textures) {+ const declRe = new RegExp(`uniform\\s+(?:highp\\s+)?sampler2D\\s+${name}\\s*;`);+ if (!declRe.test(out)) continue;+ out = out.replace(declRe, splitUniformDecl(name, unit));+ combined.add(name);+ }++ // Any remaining combined sampler DECLARATION (not a function param) has no+ // known unit - refuse loudly rather than emit colliding bindings.+ const leftover = out.match(/uniform\s+(?:highp\s+)?sampler2D\s+(\w+)/);+ if (leftover) {+ throw new Error(`sampler '${leftover[1]}' has no reflected unit - declare it via #pragma param`);+ }++ // Functions taking sampler2D parameters: split the param into a pair and+ // remember which argument positions carry samplers, so call sites can pass+ // both halves (constructors are not legal as call arguments).+ const samplerFns = new Map(); // fname → [param indices]+ out = out.replace(/\b(\w+)\s*\(([^()]*\bsampler2D\b[^()]*)\)/g, (m, fname, params) => {+ if (fname === 'sampler2D') return m;+ const parts = params.split(',');+ const positions = [];+ const rewritten = parts.map((p, i) => {+ const pm = p.match(/^(\s*)(?:in\s+)?(?:highp\s+)?sampler2D\s+(\w+)\s*$/);+ if (!pm) return p;+ positions.push(i);+ combined.add(pm[2]);+ return `${pm[1]}in highp texture2D ${pm[2]}_est, in highp sampler ${pm[2]}_ess`;+ });+ samplerFns.set(fname, positions);+ return `${fname}(${rewritten.join(',')})`;+ });++ // Call sites of those functions: split each sampler-position argument (a+ // combined name after the rewrites above) into its two halves.+ for (const [fname, positions] of samplerFns) {+ out = rewriteCalls(out, fname, (args) => {+ for (const i of positions) {+ const name = (args[i] ?? '').trim();+ if (combined.has(name)) args[i] = ` ${name}_est, ${name}_ess`;+ }+ return args;+ });+ }++ // Sampling builtins: the constructor at point of use (the one legal form).+ const builtins = 'texture|textureLod|textureProj|textureGrad|textureOffset|texelFetch|textureSize';+ for (const name of combined) {+ out = out.replace(+ new RegExp(`\\b(${builtins})\\s*\\(\\s*${name}\\s*,`, 'g'),+ (m, fn) => `${fn}(sampler2D(${name}_est, ${name}_ess),`,+ );+ }++ return out;+}++/**+ * Rewrite every call of @p fname (skipping its definition, which was already+ * rewritten) by mapping its paren-balanced argument list through @p mapArgs.+ */+function rewriteCalls(src, fname, mapArgs) {+ const re = new RegExp(`\\b${fname}\\s*\\(`, 'g');+ let result = '';+ let last = 0;+ let m;+ while ((m = re.exec(src)) !== null) {+ const open = m.index + m[0].length - 1;+ // Find the balanced closing paren.+ let depth = 1;+ let i = open + 1;+ while (i < src.length && depth > 0) {+ if (src[i] === '(') depth++;+ else if (src[i] === ')') depth--;+ i++;+ }+ const inner = src.slice(open + 1, i - 1);+ // A definition/prototype (already handled) declares types - skip anything+ // whose argument list still contains a type keyword pair pattern.+ if (/\b(?:in|out|inout)\s+\w|texture2D\s+\w|sampler\s+\w/.test(inner)) {+ result += src.slice(last, i);+ last = i;+ continue;+ }+ // Split top-level commas.+ const args = [];+ let depth2 = 0;+ let start = 0;+ for (let k = 0; k < inner.length; k++) {+ if (inner[k] === '(') depth2++;+ else if (inner[k] === ')') depth2--;+ else if (inner[k] === ',' && depth2 === 0) {+ args.push(inner.slice(start, k));+ start = k + 1;+ }+ }+ args.push(inner.slice(start));+ result += src.slice(last, m.index) + `${fname}(${mapArgs(args).join(',')})`;+ last = i;+ }+ return result + src.slice(last);+}++/**+ * 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) => {+ 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) => {+ if (dir !== 'in') return m;+ const loc = order.indexOf(name);+ if (loc < 0) 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) => {+ if (dir !== 'out') return m;+ return `${ws}layout(location = ${fragLoc++}) ${flat ?? ''}out ${type} ${name};`;+ });+ return { vert: vertOut, frag: fragOut };+}++/** GLSL (adapted) → WGSL via glslangValidator -V + naga, renaming the entry point. */+async function glslToWgsl(glsl, stage, entryName, workDir) {+ const src = path.join(workDir, `stage.${stage}`);+ const spv = path.join(workDir, `stage.${stage}.spv`);+ const wgsl = path.join(workDir, `stage.${stage}.wgsl`);+ await writeFile(src, glsl, 'utf8');+ try {+ await execFileP('glslangValidator', ['-V', '--auto-map-locations', '-o', spv, src]);+ } catch (e) {+ throw new Error(`glslang failed for ${stage} stage:\n${e.stdout ?? ''}${e.stderr ?? ''}`);+ }+ try {+ await execFileP('naga', [spv, wgsl]);+ } catch (e) {+ throw new Error(`naga failed for ${stage} stage:\n${e.stdout ?? ''}${e.stderr ?? ''}`);+ }+ const text = await readFile(wgsl, 'utf8');+ // naga emits `fn main(` as the entry (the inner body lands in main_1) - the+ // engine's twin contract names entries vs_main/fs_main.+ return text.replace(/\bfn main\(/, `fn ${entryName}(`);+}++/** Strip previously generated `wgsl full` sections (for --force regeneration). */+function stripGeneratedTwins(source) {+ return source.replace(/\n?#pragma (?:vertex|fragment) wgsl full\n[\s\S]*?#pragma end\n?/g, '\n');+}++async function processFile(module, file, opts) {+ let source = await readFile(file, 'utf8');+ const hadGenerated = /#pragma (?:vertex|fragment) wgsl full/.test(source);+ if (opts.force && hadGenerated) source = stripGeneratedTwins(source);++ if (/#pragma fragment wgsl/.test(source)) {+ return { file, status: 'has-twin' };+ }++ const info = module.esshader_cookInfo(source, '');+ if (!info.valid) throw new Error(`parse failed: ${info.error}`);+ if (info.hasSwitches) return { file, status: 'skipped-switches' };++ const textures = [];+ for (let i = 0; i < info.textures.length; i++) textures.push(info.textures[i]);++ const adapted = assignVaryingLocations(+ adaptGlsl(info.vertGlsl, textures),+ adaptGlsl(info.fragGlsl, textures),+ );++ const workDir = await mkdtemp(path.join(tmpdir(), 'esshader-twin-'));+ try {+ const vertWgsl = await glslToWgsl(adapted.vert, 'vert', 'vs_main', workDir);+ const fragWgsl = await glslToWgsl(adapted.frag, 'frag', 'fs_main', workDir);++ const twin =+ `\n#pragma vertex wgsl full\n${GENERATED_BANNER}\n${vertWgsl.trimEnd()}\n#pragma end\n` ++ `\n#pragma fragment wgsl full\n${GENERATED_BANNER}\n${fragWgsl.trimEnd()}\n#pragma end\n`;++ if (opts.check) return { file, status: 'would-generate' };+ await writeFile(file, source.trimEnd() + '\n' + twin, 'utf8');+ return { file, status: 'generated' };+ } finally {+ await rm(workDir, { recursive: true, force: true });+ }+}++async function main() {+ const args = process.argv.slice(2);+ const opts = { check: args.includes('--check'), force: args.includes('--force') };+ const files = args.filter((a) => !a.startsWith('--'));+ if (files.length === 0) {+ console.error('usage: node tools/gen-shader-twins.mjs [--check] [--force] <file.esshader ...>');+ process.exit(2);+ }++ const { default: createModule } = await import(pathToFileURL(WASM_GLUE).href);+ const module = await createModule();++ let pending = 0;+ let failed = 0;+ for (const file of files) {+ try {+ const r = await processFile(module, file, opts);+ console.log(`[twin] ${r.status}: ${file}`);+ if (r.status === 'would-generate') pending++;+ } catch (e) {+ failed++;+ console.error(`[twin] FAIL: ${file}\n ${e.message.replace(/\n/g, '\n ')}`);+ }+ }+ process.exit(failed > 0 ? 1 : pending > 0 ? 1 : 0);+}++await main();