5inline constexpr const char*
BATCH = R
"esshader(#pragma shader "Batch"
17#pragma feature ALPHA_CLIP
20#pragma feature PREMULTIPLIED_COLOR
26#pragma feature INSTANCED
29layout(location = 0) in vec3 a_position;
30layout(location = 1) in vec4 a_color;
31layout(location = 2) in vec2 a_texCoord;
32layout(location = 3) in float a_texIndex;
33layout(location = 4) in float a_sdfBias;
36layout(location = 5) in vec4 a_xform;
37layout(location = 6) in vec2 a_offset;
38layout(location = 7) in vec4 a_tint;
43flat out int v_texIndex;
45out highp vec2 v_worldPos;
46flat out highp float v_lightLayer;
53 vec3 position = vec3(a_xform.xy * a_position.x + a_xform.zw * a_position.y + a_offset, a_position.z);
54 v_color = a_color * a_tint;
56 vec3 position = a_position;
59 gl_Position = u_projection * vec4(position, 1.0);
60 v_texCoord = a_texCoord;
61 v_texIndex = int(a_texIndex);
63 v_worldPos = position.xy;
64 v_lightLayer = a_sdfBias;
66 v_sdfBias = a_sdfBias;
78flat in int v_texIndex;
80in highp vec2 v_worldPos;
81flat in highp float v_lightLayer;
89uniform sampler2D u_textures[8];
96 if ((v_texIndex & 256) != 0 && ((int(gl_FragCoord.x) + int(gl_FragCoord.y)) & 1) != ((v_texIndex >> 9) & 1)) discard;
97 int slot = v_texIndex & 7;
99 if (slot == 0) texColor = texture(u_textures[0], v_texCoord);
100 else if (slot == 1) texColor = texture(u_textures[1], v_texCoord);
101 else if (slot == 2) texColor = texture(u_textures[2], v_texCoord);
102 else if (slot == 3) texColor = texture(u_textures[3], v_texCoord);
103 else if (slot == 4) texColor = texture(u_textures[4], v_texCoord);
104 else if (slot == 5) texColor = texture(u_textures[5], v_texCoord);
105 else if (slot == 6) texColor = texture(u_textures[6], v_texCoord);
106 else texColor = texture(u_textures[7], v_texCoord);
110 vec4 tint = vec4(srgbToLinear(v_color.rgb), v_color.a);
114#ifdef PREMULTIPLIED_COLOR
118 vec4 base = texColor * tint;
119 fragColor = vec4(applyLighting2DLayer(base.rgb, vec3(0.0, 0.0, 1.0), v_worldPos, v_lightLayer), base.a);
121 int mode = (v_texIndex >> 3) & 31;
122 vec2 duvx = dFdx(v_texCoord);
123 vec2 duvy = dFdy(v_texCoord);
124 float distWidth = fwidth(texColor.a);
127 if (slot == 0) page = textureSize(u_textures[0], 0);
128 else if (slot == 1) page = textureSize(u_textures[1], 0);
129 else if (slot == 2) page = textureSize(u_textures[2], 0);
130 else if (slot == 3) page = textureSize(u_textures[3], 0);
131 else if (slot == 4) page = textureSize(u_textures[4], 0);
132 else if (slot == 5) page = textureSize(u_textures[5], 0);
133 else if (slot == 6) page = textureSize(u_textures[6], 0);
134 else page = textureSize(u_textures[7], 0);
135 vec2 acrossX = duvx * vec2(page);
136 vec2 acrossY = duvy * vec2(page);
137 float texelsPerPixel = sqrt(0.5 * (dot(acrossX, acrossX) + dot(acrossY, acrossY)));
138 float dist = texColor.a;
139 float pixelsPerUnit = min(1.0 / max(distWidth, 1e-6), texColor.r * 255.0 / max(texelsPerPixel, 1e-6));
140 float screenPxDist = (dist - 0.5 + v_sdfBias) * pixelsPerUnit;
141 float coverage = v_sdfBias < -1.0 ? dist : clamp(screenPxDist + 0.5, 0.0, 1.0);
142 fragColor = vec4(tint.rgb, tint.a * coverage);
143 } else if (mode == 2) {
144 fragColor = vec4(tint.rgb, tint.a * texColor.a);
145 } else if (mode == 3) {
146 fragColor = vec4(tint.rgb, tint.a * texColor.r * texColor.a);
149 if (texColor.a < 0.5) discard;
151 fragColor = texColor * tint;
155 #ifdef DISPLAY_OUTPUT
156 #ifdef PREMULTIPLIED_COLOR
157 fragColor.rgb = linearToSrgb(fragColor.rgb / max(fragColor.a, 1e-5)) * fragColor.a;
159 fragColor.rgb = linearToSrgb(fragColor.rgb);
168 @location(0) a_position : vec3f,
169 @location(1) a_color : vec4f,
170 @location(2) a_texCoord : vec2f,
171 @location(3) a_texIndex : f32,
172 @location(4) a_sdfBias : f32,
174 @location(5) a_xform : vec4f,
175 @location(6) a_offset : vec2f,
176 @location(7) a_tint : vec4f,
180 @builtin(position) pos : vec4f,
181 @location(0) v_color : vec4f,
182 @location(1) v_texCoord : vec2f,
183 @location(2) v_texIndex : f32,
185 @location(3) v_worldPos : vec2f,
186 @location(5) @interpolate(flat) v_lightLayer : f32,
188 @location(4) v_sdfBias : f32,
192@vertex fn vs_main(v : VSIn) -> VSOut {
195 let position = vec3f(v.a_xform.xy * v.a_position.x + v.a_xform.zw * v.a_position.y + v.a_offset, v.a_position.z);
196 out.v_color = v.a_color * v.a_tint;
198 let position = v.a_position;
199 out.v_color = v.a_color;
201 out.pos = frame.projection * vec4f(position, 1.0);
202 out.v_texCoord = v.a_texCoord;
203 out.v_texIndex = v.a_texIndex;
205 out.v_worldPos = position.xy;
206 out.v_lightLayer = v.a_sdfBias;
208 out.v_sdfBias = v.a_sdfBias;
211 out.pos.y = -out.pos.y;
217@group(1) @binding(0) var t0 : texture_2d<f32>;
218@group(1) @binding(1) var t1 : texture_2d<f32>;
219@group(1) @binding(2) var t2 : texture_2d<f32>;
220@group(1) @binding(3) var t3 : texture_2d<f32>;
221@group(1) @binding(4) var t4 : texture_2d<f32>;
222@group(1) @binding(5) var t5 : texture_2d<f32>;
223@group(1) @binding(6) var t6 : texture_2d<f32>;
224@group(1) @binding(7) var t7 : texture_2d<f32>;
225@group(1) @binding(8) var s0 : sampler;
226@group(1) @binding(9) var s1 : sampler;
227@group(1) @binding(10) var s2 : sampler;
228@group(1) @binding(11) var s3 : sampler;
229@group(1) @binding(12) var s4 : sampler;
230@group(1) @binding(13) var s5 : sampler;
231@group(1) @binding(14) var s6 : sampler;
232@group(1) @binding(15) var s7 : sampler;
235 @builtin(position) pos : vec4f,
236 @location(0) v_color : vec4f,
237 @location(1) v_texCoord : vec2f,
238 @location(2) v_texIndex : f32,
240 @location(3) v_worldPos : vec2f,
241 @location(5) @interpolate(flat) v_lightLayer : f32,
243 @location(4) v_sdfBias : f32,
247@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
248 let idx = i32(v.v_texIndex + 0.5);
250 if ((idx & 256) != 0 && ((i32(v.pos.x) + i32(v.pos.y)) & 1) != ((idx >> 9u) & 1)) { discard; }
252 let duvx = dpdx(v.v_texCoord);
253 let duvy = dpdy(v.v_texCoord);
254 var texColor : vec4f;
255 if (slot == 0) { texColor = textureSampleGrad(t0, s0, v.v_texCoord, duvx, duvy); }
256 else if (slot == 1) { texColor = textureSampleGrad(t1, s1, v.v_texCoord, duvx, duvy); }
257 else if (slot == 2) { texColor = textureSampleGrad(t2, s2, v.v_texCoord, duvx, duvy); }
258 else if (slot == 3) { texColor = textureSampleGrad(t3, s3, v.v_texCoord, duvx, duvy); }
259 else if (slot == 4) { texColor = textureSampleGrad(t4, s4, v.v_texCoord, duvx, duvy); }
260 else if (slot == 5) { texColor = textureSampleGrad(t5, s5, v.v_texCoord, duvx, duvy); }
261 else if (slot == 6) { texColor = textureSampleGrad(t6, s6, v.v_texCoord, duvx, duvy); }
262 else { texColor = textureSampleGrad(t7, s7, v.v_texCoord, duvx, duvy); }
264 var tint = vec4f(srgbToLinear(v.v_color.rgb), v.v_color.a);
266 var tint = v.v_color;
268#ifdef PREMULTIPLIED_COLOR
269 tint = vec4f(tint.rgb * tint.a, tint.a);
272 let base = texColor * tint;
273 let shown = vec4f(applyLighting2DLayer(base.rgb, vec3f(0.0, 0.0, 1.0), v.v_worldPos, v.v_lightLayer), base.a);
275 let mode = (idx >> 3u) & 31;
276 let distWidth = fwidth(texColor.a);
280 if (slot == 0) { page = textureDimensions(t0); }
281 else if (slot == 1) { page = textureDimensions(t1); }
282 else if (slot == 2) { page = textureDimensions(t2); }
283 else if (slot == 3) { page = textureDimensions(t3); }
284 else if (slot == 4) { page = textureDimensions(t4); }
285 else if (slot == 5) { page = textureDimensions(t5); }
286 else if (slot == 6) { page = textureDimensions(t6); }
287 else { page = textureDimensions(t7); }
288 let acrossX = duvx * vec2f(page);
289 let acrossY = duvy * vec2f(page);
290 let texelsPerPixel = sqrt(0.5 * (dot(acrossX, acrossX) + dot(acrossY, acrossY)));
291 let dist = texColor.a;
292 let pixelsPerUnit = min(1.0 / max(distWidth, 1e-6), texColor.r * 255.0 / max(texelsPerPixel, 1e-6));
293 let screenPxDist = (dist - 0.5 + v.v_sdfBias) * pixelsPerUnit;
294 let coverage = select(clamp(screenPxDist + 0.5, 0.0, 1.0), dist, v.v_sdfBias < -1.0);
295 shown = vec4f(tint.rgb, tint.a * coverage);
296 } else if (mode == 2) {
297 shown = vec4f(tint.rgb, tint.a * texColor.a);
298 } else if (mode == 3) {
299 shown = vec4f(tint.rgb, tint.a * texColor.r * texColor.a);
302 if (texColor.a < 0.5) { discard; }
304 shown = texColor * tint;
308 #ifdef DISPLAY_OUTPUT
309 #ifdef PREMULTIPLIED_COLOR
310 return vec4f(linearToSrgb(shown.rgb / max(shown.a, 1e-5)) * shown.a, shown.a);
312 return vec4f(linearToSrgb(shown.rgb), shown.a);
324inline constexpr const char*
BLIT = R
"esshader(#pragma shader "Blit"
325#pragma version 300 es
326#pragma domain PostProcess
329#pragma param u_displayLut texture default(white)
330#pragma param u_displayLutAmount float default(0)
333precision highp float;
336uniform sampler2D u_texture;
337#if defined(ES_COPY_DEPTH) || defined(ES_SELECTION_SCENE_DEPTH)
338uniform highp sampler2D u_sceneDepth;
340#ifdef ES_SELECTION_OUTLINE
343uniform highp sampler2D u_selectionMask;
351vec4 upscale(vec2 uv) {
352 vec2 size = vec2(textureSize(u_texture, 0));
353 vec2 pos = uv * size;
354 vec2 centre = floor(pos - 0.5) + 0.5;
355 vec2 f = pos - centre;
358 vec2 w0 = f2 - 0.5 * (f3 + f);
359 vec2 w1 = 1.5 * f3 - 2.5 * f2 + 1.0;
360 vec2 w3 = 0.5 * (f3 - f2);
361 vec2 w2 = 1.0 - w0 - w1 - w3;
363 vec2 t0 = (centre - 1.0) / size;
364 vec2 t3 = (centre + 2.0) / size;
365 vec2 t12 = (centre + w2 / w12) / size;
366 vec4 sum = texture(u_texture, vec2(t12.x, t0.y)) * (w12.x * w0.y)
367 + texture(u_texture, vec2(t0.x, t12.y)) * (w0.x * w12.y)
368 + texture(u_texture, t12) * (w12.x * w12.y)
369 + texture(u_texture, vec2(t3.x, t12.y)) * (w3.x * w12.y)
370 + texture(u_texture, vec2(t12.x, t3.y)) * (w12.x * w3.y);
371 sum /= (w12.x * w0.y + w0.x * w12.y + w12.x * w12.y + w3.x * w12.y + w12.x * w3.y);
372 ivec2 base = ivec2(centre - 0.5);
373 ivec2 hi = ivec2(size) - 1;
374 vec4 a = texelFetch(u_texture, clamp(base, ivec2(0), hi), 0);
375 vec4 b = texelFetch(u_texture, clamp(base + ivec2(1, 0), ivec2(0), hi), 0);
376 vec4 d = texelFetch(u_texture, clamp(base + ivec2(0, 1), ivec2(0), hi), 0);
377 vec4 e = texelFetch(u_texture, clamp(base + ivec2(1, 1), ivec2(0), hi), 0);
378 return clamp(sum, min(min(a, b), min(d, e)), max(max(a, b), max(d, e)));
383vec3 displayLookup(vec3 c) {
384 const float size = 32.0;
385 float b = clamp(c.b, 0.0, 1.0) * (size - 1.0);
386 float slice0 = floor(b);
387 float slice1 = min(slice0 + 1.0, size - 1.0);
388 float u = (clamp(c.r, 0.0, 1.0) * (size - 1.0) + 0.5) / (size * size);
389 float v = (clamp(c.g, 0.0, 1.0) * (size - 1.0) + 0.5) / size;
390 vec3 a = texture(u_displayLut, vec2(u + slice0 / size, v)).rgb;
391 vec3 d = texture(u_displayLut, vec2(u + slice1 / size, v)).rgb;
392 return mix(a, d, b - slice0);
397#ifdef ES_SELECTION_OUTLINE
402 ivec2 maskSize = textureSize(u_selectionMask, 0);
403 ivec2 at = clamp(ivec2(v_texCoord * vec2(maskSize)), ivec2(0), maskSize - ivec2(1));
404 vec4 here = texelFetch(u_selectionMask, at, 0);
405 if (here.a > 0.5) discard;
408 for (int y = -2; y <= 2; ++y) {
409 for (int x = -2; x <= 2; ++x) {
410 if (x * x + y * y > 5) continue;
411 ivec2 q = clamp(at + ivec2(x, y), ivec2(0), maskSize - ivec2(1));
412 vec4 m = texelFetch(u_selectionMask, q, 0);
413 if (m.a < 0.5) continue;
415 vec3 selected = worldFromDepth(v_texCoord, m.z);
416 float selectedDistance = u_camera.w > 0.5 ? length(selected - u_camera.xyz) : -dot(selected, u_camera.xyz);
417 if (here.g >= selectedDistance * 0.97) seen = true;
422 float strength = seen ? 1.0 : 0.4;
423 fragColor = vec4(vec3(0.961, 0.533, 0.122) * strength, strength);
426#ifdef ES_SELECTION_SCENE_DEPTH
429 ivec2 sceneSize = textureSize(u_sceneDepth, 0);
430 float sceneZ = texelFetch(u_sceneDepth, clamp(ivec2(v_texCoord * vec2(sceneSize)), ivec2(0), sceneSize - ivec2(1)), 0).r;
431 vec3 scenePoint = worldFromDepth(v_texCoord, sceneZ);
432 float sceneDistance = u_camera.w > 0.5 ? length(scenePoint - u_camera.xyz) : -dot(scenePoint, u_camera.xyz);
433 fragColor = vec4(0.0, sceneZ >= 1.0 ? 1e30 : sceneDistance, 0.0, 0.0);
442 ivec2 depthSize = textureSize(u_sceneDepth, 0);
443 float rawDepth = texelFetch(u_sceneDepth, clamp(ivec2(v_texCoord * vec2(depthSize)), ivec2(0), depthSize - ivec2(1)), 0).r;
444 vec3 scenePoint = worldFromDepth(v_texCoord, rawDepth);
445 float eyeDistance = u_camera.w > 0.5 ? length(scenePoint - u_camera.xyz) : -dot(scenePoint, u_camera.xyz);
446 bool sky = rawDepth >= 1.0;
447 fragColor = vec4(sky ? 65504.0 : min(eyeDistance, 65504.0), sky ? 1.0 : 0.0, sky ? 65504.0 : min(eyeDistance / 1024.0, 65504.0), 0.5);
451 vec4 c = upscale(v_texCoord);
453 vec4 c = texture(u_texture, v_texCoord);
466 fragColor = vec4(c.rgb, 0.5);
472 if (c.a <= 0.001) { fragColor = vec4(0.0); return; }
473 vec3 h = clamp(c.rgb, vec3(0.0), vec3(8.0));
474 float m = clamp(max(max(h.r, h.g), max(h.b, 1e-6)) / 8.0, 1.0 / 255.0, 1.0);
475 m = ceil(m * 255.0) / 255.0;
476 fragColor = vec4(h / (m * 8.0), m);
479 c = vec4(c.rgb * exp2(u_time.z), c.a);
484 c = vec4(acesFilmic(c.rgb), c.a);
486#ifdef ES_TONEMAP_NEUTRAL
487 c = vec4(pbrNeutral(c.rgb), c.a);
492 vec3 shown = linearToSrgb(c.rgb);
498 shown = mix(shown, displayLookup(shown), clamp(u_displayLutAmount, 0.0, 1.0));
500 fragColor = vec4(shown, c.a);
506fn upscale(uv : vec2f) -> vec4f {
507 let size = vec2f(textureDimensions(t0, 0));
509 let centre = floor(pos - vec2f(0.5)) + vec2f(0.5);
510 let f = pos - centre;
513 let w0 = f2 - 0.5 * (f3 + f);
514 let w1 = 1.5 * f3 - 2.5 * f2 + vec2f(1.0);
515 let w3 = 0.5 * (f3 - f2);
516 let w2 = vec2f(1.0) - w0 - w1 - w3;
518 let tapLo = (centre - vec2f(1.0)) / size;
519 let tapHi = (centre + vec2f(2.0)) / size;
520 let tapMid = (centre + w2 / w12) / size;
521 var sum = textureSampleLevel(t0, s0, vec2f(tapMid.x, tapLo.y), 0.0) * (w12.x * w0.y)
522 + textureSampleLevel(t0, s0, vec2f(tapLo.x, tapMid.y), 0.0) * (w0.x * w12.y)
523 + textureSampleLevel(t0, s0, tapMid, 0.0) * (w12.x * w12.y)
524 + textureSampleLevel(t0, s0, vec2f(tapHi.x, tapMid.y), 0.0) * (w3.x * w12.y)
525 + textureSampleLevel(t0, s0, vec2f(tapMid.x, tapHi.y), 0.0) * (w12.x * w3.y);
526 sum = sum / (w12.x * w0.y + w0.x * w12.y + w12.x * w12.y + w3.x * w12.y + w12.x * w3.y);
527 let base = vec2i(centre - vec2f(0.5));
528 let hi = vec2i(size) - vec2i(1);
529 let a = textureLoad(t0, clamp(base, vec2i(0), hi), 0);
530 let b = textureLoad(t0, clamp(base + vec2i(1, 0), vec2i(0), hi), 0);
531 let d = textureLoad(t0, clamp(base + vec2i(0, 1), vec2i(0), hi), 0);
532 let e = textureLoad(t0, clamp(base + vec2i(1, 1), vec2i(0), hi), 0);
533 return clamp(sum, min(min(a, b), min(d, e)), max(max(a, b), max(d, e)));
538fn displayLookup(c : vec3f) -> vec3f {
540 let b = clamp(c.b, 0.0, 1.0) * (size - 1.0);
541 let slice0 = floor(b);
542 let slice1 = min(slice0 + 1.0, size - 1.0);
543 let u = (clamp(c.r, 0.0, 1.0) * (size - 1.0) + 0.5) / (size * size);
544 let v = (clamp(c.g, 0.0, 1.0) * (size - 1.0) + 0.5) / size;
545 let a = textureSampleLevel(u_displayLut, u_displayLut_s, vec2f(u + slice0 / size, v), 0.0).rgb;
546 let d = textureSampleLevel(u_displayLut, u_displayLut_s, vec2f(u + slice1 / size, v), 0.0).rgb;
547 return mix(a, d, b - slice0);
551@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
552#ifdef ES_SELECTION_OUTLINE
554 let maskSize = vec2i(textureDimensions(t15, 0));
555 let at = clamp(vec2i(v.v_texCoord * vec2f(maskSize)), vec2i(0), maskSize - vec2i(1));
556 let here = textureLoad(t15, at, 0);
557 if (here.a > 0.5) { discard; }
560 for (var y = -2; y <= 2; y++) {
561 for (var x = -2; x <= 2; x++) {
562 if (x * x + y * y > 5) { continue; }
563 let q = clamp(at + vec2i(x, y), vec2i(0), maskSize - vec2i(1));
564 let m = textureLoad(t15, q, 0);
565 if (m.a < 0.5) { continue; }
567 let selected = worldFromDepth(v.v_texCoord, m.z);
568 var selectedDistance = -dot(selected, frame.camera.xyz);
569 if (frame.camera.w > 0.5) { selectedDistance = length(selected - frame.camera.xyz); }
570 if (here.g >= selectedDistance * 0.97) { seen = true; }
573 if (!ring) { discard; }
574 let strength = select(0.4, 1.0, seen);
575 return vec4f(vec3f(0.961, 0.533, 0.122) * strength, strength);
577#ifdef ES_SELECTION_SCENE_DEPTH
578 let sceneSize = vec2i(textureDimensions(t7, 0));
579 let sceneZ = textureLoad(t7, clamp(vec2i(v.v_texCoord * vec2f(sceneSize)), vec2i(0), sceneSize - vec2i(1)), 0);
580 let scenePoint = worldFromDepth(v.v_texCoord, sceneZ);
581 var sceneDistance = -dot(scenePoint, frame.camera.xyz);
582 if (frame.camera.w > 0.5) { sceneDistance = length(scenePoint - frame.camera.xyz); }
583 return vec4f(0.0, select(sceneDistance, 1e30, sceneZ >= 1.0), 0.0, 0.0);
586 let depthSize = vec2i(textureDimensions(t7, 0));
587 let rawDepth = textureLoad(t7, clamp(vec2i(v.v_texCoord * vec2f(depthSize)), vec2i(0), depthSize - vec2i(1)), 0);
588 let scenePoint = worldFromDepth(v.v_texCoord, rawDepth);
589 var eyeDistance = -dot(scenePoint, frame.camera.xyz);
590 if (frame.camera.w > 0.5) { eyeDistance = length(scenePoint - frame.camera.xyz); }
591 let sky = rawDepth >= 1.0;
592 return vec4f(select(min(eyeDistance, 65504.0), 65504.0, sky), select(0.0, 1.0, sky), select(min(eyeDistance / 1024.0, 65504.0), 65504.0, sky), 0.5);
595 var c = upscale(v.v_texCoord);
597 var c = textureSampleLevel(t0, s0, v.v_texCoord, 0.0);
603 return vec4f(c.rgb, 0.5);
606 if (c.a <= 0.001) { return vec4f(0.0); }
607 let h = clamp(c.rgb, vec3f(0.0), vec3f(8.0));
608 var m = clamp(max(max(h.r, h.g), max(h.b, 1e-6)) / 8.0, 1.0 / 255.0, 1.0);
609 m = ceil(m * 255.0) / 255.0;
610 return vec4f(h / (m * 8.0), m);
612 c = vec4f(c.rgb * exp2(tc.u_time.z), c.a);
614 c = vec4f(acesFilmic(c.rgb), c.a);
616#ifdef ES_TONEMAP_NEUTRAL
617 c = vec4f(pbrNeutral(c.rgb), c.a);
620 var shown = linearToSrgb(c.rgb);
625 shown = mix(shown, displayLookup(shown), clamp(mc.u_displayLutAmount, 0.0, 1.0));
627 return vec4f(shown, c.a);
632inline constexpr const char*
LIGHTSHAPE2D = R
"esshader(#pragma shader "LightShape2D"
633#pragma version 300 es
643layout(location = 0) in vec2 a_position;
644layout(location = 1) in vec2 a_texCoord;
645layout(location = 2) in vec4 a_channel;
651 gl_Position = u_projection * vec4(a_position, 0.0, 1.0);
652 v_texCoord = a_texCoord;
653 v_channel = a_channel;
658precision highp float;
663uniform sampler2D u_cookie;
670 fragColor = v_channel * texture(u_cookie, v_texCoord).a;
676 @location(0) a_position : vec2f,
677 @location(1) a_texCoord : vec2f,
678 @location(2) a_channel : vec4f,
681 @builtin(position) pos : vec4f,
682 @location(0) v_texCoord : vec2f,
683 @location(1) v_channel : vec4f,
686@vertex fn vs_main(v : VSIn) -> VSOut {
688 out.pos = frame.projection * vec4f(v.a_position, 0.0, 1.0);
689 out.v_texCoord = v.a_texCoord;
690 out.v_channel = v.a_channel;
692 out.pos.y = -out.pos.y;
699 @builtin(position) pos : vec4f,
700 @location(0) v_texCoord : vec2f,
701 @location(1) v_channel : vec4f,
704@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
705 return v.v_channel * textureSample(t0, s0, v.v_texCoord).a;
710inline constexpr const char*
MESH = R
"esshader(#pragma shader "Mesh"
711#pragma version 300 es
722#pragma feature MESH_NORMALS
732#pragma feature SKINNED
737#pragma feature NORMAL_MAP
743#pragma feature MESH_LIGHTMAP
746#pragma feature MESH_TANGENTS
752#pragma feature SHADOW_DEPTH
757#pragma feature SHADOW_ALPHA
761#pragma feature PREPASS_COVERAGE
768#pragma feature WEIGHT_HEAT
776layout(location = 0) in vec3 a_position;
777layout(location = 1) in vec4 a_color;
778layout(location = 2) in vec2 a_texCoord;
780layout(location = 3) in vec3 a_normal;
783layout(location = 5) in uvec4 a_joints;
784layout(location = 6) in vec4 a_weights;
787layout(location = 7) in vec2 a_texCoord1;
790layout(location = 4) in vec4 a_tangent;
800layout(std140) uniform SkinConstants {
814invariant gl_Position;
826out highp vec3 v_lightmap;
829out highp vec3 v_worldNormal;
832out highp vec3 v_worldPos;
834out highp vec4 v_worldTangent;
844out highp vec4 v_shadowClip;
851out highp vec4 v_velCur;
852out highp vec4 v_velPrev;
858#ifdef ES_MATERIAL_VERTEX
860highp vec4 es_vertexColor;
862highp vec2 es_vertexUv1;
866#if defined(ES_VELOCITY) && defined(SKINNED)
868highp mat4 esPrevBone(uint joint) {
869 int at = 8 + int(joint) * 3;
870 highp vec4 r0 = esInstanceTexel(at);
871 highp vec4 r1 = esInstanceTexel(at + 1);
872 highp vec4 r2 = esInstanceTexel(at + 2);
873 return mat4(vec4(r0.x, r1.x, r2.x, 0.0), vec4(r0.y, r1.y, r2.y, 0.0),
874 vec4(r0.z, r1.z, r2.z, 0.0), vec4(r0.w, r1.w, r2.w, 1.0));
879 vec3 local = a_position;
881 vec3 localNormal = a_normal;
883 vec3 localNormal = vec3(0.0, 0.0, 1.0);
885 esApplyMorph(local, localNormal);
886#ifdef ES_MATERIAL_VERTEX
887 es_vertexColor = a_color;
889 es_vertexUv1 = a_texCoord1;
891 es_vertexUv1 = vec2(0.0);
893 esMaterialVertex(local, localNormal, a_texCoord);
898 mat4 skin = a_weights.x * u_bones[a_joints.x]
899 + a_weights.y * u_bones[a_joints.y]
900 + a_weights.z * u_bones[a_joints.z]
901 + a_weights.w * u_bones[a_joints.w];
902 vec4 world = skin * vec4(local, 1.0);
904 mat4 model = esInstanceModel();
905 vec4 world = model * vec4(local, 1.0);
907 gl_Position = u_projection * world;
908 v_texCoord = a_texCoord;
910#ifdef ES_MATERIAL_VERTEX
911 v_color = es_vertexColor * esInstanceTint();
913 v_color = a_color * esInstanceTint();
915#if defined(WEIGHT_HEAT) && defined(SKINNED)
917 uint chosen = uint(esInstanceTint().x);
918 vec4 own = vec4(equal(a_joints, uvec4(chosen)));
919 float heat = dot(own, a_weights);
921 v_color = vec4(heat < 0.01 ? vec3(0.1) : mix(vec3(0.2, 0.4, 1.0), vec3(1.0, 0.25, 0.2), clamp(heat, 0.0, 1.0)), 1.0);
925 highp vec4 lmRect = esInstanceLightmapRect();
926 v_lightmap = vec3(a_texCoord1 * lmRect.xy + lmRect.zw,
927 lmRect.x > 0.0 ? 1.0 : 0.0);
930 v_shadowClip = gl_Position;
938 highp mat4 prevSkin = a_weights.x * esPrevBone(a_joints.x) + a_weights.y * esPrevBone(a_joints.y)
939 + a_weights.z * esPrevBone(a_joints.z) + a_weights.w * esPrevBone(a_joints.w);
940 highp vec4 L = prevSkin * vec4(local, 1.0);
942 highp vec4 L = vec4(local, 1.0);
944 highp vec4 before = esInstanceTint();
945 v_velCur = gl_Position;
946 highp vec4 prev = vec4(dot(esInstanceTexel(4), L), dot(esInstanceTexel(5), L),
947 dot(esInstanceTexel(6), L), dot(esInstanceTexel(7), L));
948 v_velPrev = vec4(prev.xy + before.xy * prev.w, prev.zw);
953 v_probeSlot = float(ES_INSTANCE_ID);
955#if defined(MESH_NORMALS) && defined(SKINNED)
956 v_worldNormal = mat3(skin) * localNormal;
957#elif defined(MESH_NORMALS)
958 v_worldNormal = esInstanceNormalMatrix() * localNormal;
961 v_worldNormal = vec3(0.0, 0.0, 1.0);
963 v_worldPos = world.xyz;
966 v_worldTangent = vec4(mat3(skin) * a_tangent.xyz, a_tangent.w);
968 mat3 tangentModel = mat3(esInstanceModel());
970 v_worldTangent = vec4(tangentModel * a_tangent.xyz, determinant(tangentModel) < 0.0 ? -a_tangent.w : a_tangent.w);
978precision mediump float;
983in highp vec3 v_worldNormal;
984in highp vec3 v_worldPos;
987in highp vec4 v_shadowClip;
990in highp vec4 v_velCur;
991in highp vec4 v_velPrev;
994uniform sampler2D u_texture;
996uniform sampler2D u_normalMap;
1004layout(location = 0) out vec4 fragColor;
1005layout(location = 1) out vec4 fragSurface;
1007layout(location = 2) out vec4 fragAlbedo;
1009vec2 packNormal(vec3 n) {
1010 n /= (abs(n.x) + abs(n.y) + abs(n.z));
1011 vec2 sgn = vec2(n.x >= 0.0 ? 1.0 : -1.0, n.y >= 0.0 ? 1.0 : -1.0);
1012 vec2 e = n.z >= 0.0 ? n.xy : (1.0 - abs(n.yx)) * sgn;
1013 return e * 0.5 + 0.5;
1021highp vec2 coverageUv() {
1022#ifdef ES_UV_TRANSFORM
1023 highp vec2 uv = v_texCoord * u_uvTiling;
1024 if (u_uvRotation != 0.0) {
1025 float c = cos(u_uvRotation), sn = sin(u_uvRotation);
1026 uv = vec2(c * uv.x + sn * uv.y, -sn * uv.x + c * uv.y);
1028 return uv + u_uvOffset;
1039 highp vec2 now = v_velCur.xy / v_velCur.w;
1040 highp vec2 was = v_velPrev.xy / max(v_velPrev.w, 1e-6);
1041 fragColor = vec4((was - now) * 0.5, gl_FragCoord.z, v_velPrev.w > 1e-6 ? 1.0 : 0.0);
1042#elif defined(SHADOW_DEPTH)
1043#ifdef PREPASS_COVERAGE
1046 highp float baseAlpha = texture(u_texture, coverageUv()).a * v_color.a * u_tint.a;
1047 highp float coverage = (baseAlpha - u_alphaCutoff) / max(fwidth(baseAlpha), 1e-4) + 0.5;
1048 if (coverage <= 0.0) discard;
1049 fragColor = vec4(0.0, 0.0, 0.0, min(coverage, 1.0));
1054 if (texture(u_texture, coverageUv()).a * v_color.a < u_alphaCutoff) discard;
1059 fragColor = vec4(packDepth(clamp(v_shadowClip.z / v_shadowClip.w * 0.5 + 0.5,
1063 vec4 base = texture(u_texture, v_texCoord) * v_color;
1065 highp vec3 N = normalize(v_worldNormal);
1067 N = perturbNormal(N, v_worldPos, v_texCoord, sampleNormal(u_normalMap, v_texCoord));
1070 if (!gl_FrontFacing) N = -N;
1077 vec3 shaded = applyLightingPBR(base.rgb, N, v_worldPos, viewDirection(v_worldPos),
1078 0.0, 1.0, 1.0, 1.0);
1079 fragColor = vec4(shaded, base.a);
1081 fragSurface = vec4(packNormal(normalize(N)), 1.0, 0.75);
1082 fragAlbedo = vec4(base.rgb, 1.0);
1089 fragColor = vec4(base.rgb * mix(vec3(1.0), bakedIrradiance(), v_lightmap.z), base.a);
1096 fragSurface = vec4(packNormal(vec3(0.0, 1.0, 0.0)), 1.0, 0.75);
1097 fragAlbedo = vec4(base.rgb, 1.0);
1106struct SkinConstants { bones : array<mat4x4f, 256> };
1107@group(0) @binding(5) var<uniform> skin : SkinConstants;
1114 @location(0) a_position : vec3f,
1115 @location(1) a_color : vec4f,
1116 @location(2) a_texCoord : vec2f,
1118 @location(3) a_normal : vec3f,
1121 @location(5) a_joints : vec4u,
1122 @location(6) a_weights : vec4f,
1125 @location(7) a_texCoord1 : vec2f,
1128 @location(4) a_tangent : vec4f,
1131 @builtin(vertex_index) vertexIndex : u32,
1134 @builtin(position) @invariant pos : vec4f,
1135 @location(0) v_texCoord : vec2f,
1136 @location(1) v_color : vec4f,
1138 @location(2) v_worldNormal : vec3f,
1139 @location(3) v_worldPos : vec3f,
1141 @location(8) v_worldTangent : vec4f,
1146 @location(4) v_shadowClip : vec4f,
1149 @location(4) v_velCur : vec4f,
1150 @location(7) v_velPrev : vec4f,
1153 @location(5) v_lightmap : vec3f,
1157 @location(6) @interpolate(flat) v_probeSlot : f32,
1160#ifdef ES_MATERIAL_VERTEX
1161var<private> es_vertexColor : vec4f;
1162var<private> es_vertexUv1 : vec2f;
1169fn esPrevBone(joint : u32) -> mat4x4f {
1170 let at = 8 + i32(joint) * 3;
1171 let r0 = esInstanceTexel(at);
1172 let r1 = esInstanceTexel(at + 1);
1173 let r2 = esInstanceTexel(at + 2);
1174 return mat4x4f(vec4f(r0.x, r1.x, r2.x, 0.0), vec4f(r0.y, r1.y, r2.y, 0.0),
1175 vec4f(r0.z, r1.z, r2.z, 0.0), vec4f(r0.w, r1.w, r2.w, 1.0));
1180@vertex fn vs_main(v : VSIn, @builtin(instance_index) inst : u32) -> VSOut {
1181 g_instanceId = i32(inst);
1182 var local = v.a_position;
1184 var localNormal = v.a_normal;
1186 var localNormal = vec3f(0.0, 0.0, 1.0);
1190 esApplyMorph(&local, &localNormal, v.vertexIndex);
1191#ifdef ES_MATERIAL_VERTEX
1192 es_vertexColor = v.a_color;
1194 es_vertexUv1 = v.a_texCoord1;
1196 es_vertexUv1 = vec2f(0.0);
1198 esMaterialVertex(&local, &localNormal, v.a_texCoord);
1203 let pose = v.a_weights.x * skin.bones[v.a_joints.x]
1204 + v.a_weights.y * skin.bones[v.a_joints.y]
1205 + v.a_weights.z * skin.bones[v.a_joints.z]
1206 + v.a_weights.w * skin.bones[v.a_joints.w];
1207 let world = pose * vec4f(local, 1.0);
1209 let world = esInstanceModel() * vec4f(local, 1.0);
1213 out.pos = frame.projection * world;
1214 out.v_texCoord = v.a_texCoord;
1215#ifdef ES_MATERIAL_VERTEX
1216 out.v_color = es_vertexColor * esInstanceTint();
1218 out.v_color = v.a_color * esInstanceTint();
1223 let chosen = u32(esInstanceTint().x);
1224 let own = vec4f(v.a_joints == vec4u(chosen));
1225 let heat = dot(own, v.a_weights);
1226 out.v_color = vec4f(select(mix(vec3f(0.2, 0.4, 1.0), vec3f(1.0, 0.25, 0.2), clamp(heat, 0.0, 1.0)),
1227 vec3f(0.1), heat < 0.01), 1.0);
1232 let lmRect = esInstanceLightmapRect();
1233 out.v_lightmap = vec3f(v.a_texCoord1 * lmRect.xy + lmRect.zw,
1234 select(0.0, 1.0, lmRect.x > 0.0));
1237 out.v_shadowClip = out.pos;
1244 let prevSkin = v.a_weights.x * esPrevBone(v.a_joints.x) + v.a_weights.y * esPrevBone(v.a_joints.y)
1245 + v.a_weights.z * esPrevBone(v.a_joints.z) + v.a_weights.w * esPrevBone(v.a_joints.w);
1246 let L = prevSkin * vec4f(local, 1.0);
1248 let L = vec4f(local, 1.0);
1250 let before = esInstanceTint();
1251 out.v_velCur = out.pos;
1252 let prev = vec4f(dot(esInstanceTexel(4), L), dot(esInstanceTexel(5), L),
1253 dot(esInstanceTexel(6), L), dot(esInstanceTexel(7), L));
1254 out.v_velPrev = vec4f(prev.xy + before.xy * prev.w, prev.zw);
1258 out.v_probeSlot = f32(inst);
1262 out.v_worldNormal = mat3x3f(pose[0].xyz, pose[1].xyz, pose[2].xyz) * localNormal;
1264 out.v_worldNormal = esInstanceNormalMatrix() * localNormal;
1269 R"esshader( out.v_worldNormal = vec3f(0.0, 0.0, 1.0);
1271 out.v_worldPos = world.xyz;
1274 out.v_worldTangent = vec4f(mat3x3f(pose[0].xyz, pose[1].xyz, pose[2].xyz) * v.a_tangent.xyz, v.a_tangent.w);
1276 let tangentModel = mat3x3f(esInstanceModel()[0].xyz, esInstanceModel()[1].xyz, esInstanceModel()[2].xyz);
1277 out.v_worldTangent = vec4f(tangentModel * v.a_tangent.xyz,
1278 select(v.a_tangent.w, -v.a_tangent.w, determinant(tangentModel) < 0.0));
1283 out.pos.y = -out.pos.y;
1288#pragma fragment wgsl
1289@group(1) @binding(0) var t0 : texture_2d<f32>;
1290@group(1) @binding(8) var s0 : sampler;
1292@group(1) @binding(1) var t1 : texture_2d<f32>;
1293@group(1) @binding(9) var s1 : sampler;
1295#ifdef ES_RECEIVE_SHADOW
1298@group(1) @binding(2) var t2 : texture_2d<f32>;
1299@group(1) @binding(10) var s2 : sampler;
1305@group(1) @binding(3) var t3 : texture_2d<f32>;
1306@group(1) @binding(11) var s3 : sampler;
1310@group(1) @binding(5) var t5 : texture_2d<f32>;
1311@group(1) @binding(13) var s5 : sampler;
1315@group(1) @binding(7) var t7 : texture_2d<f32>;
1316@group(1) @binding(15) var s7 : sampler;
1319 @builtin(position) pos : vec4f,
1320 @location(0) v_texCoord : vec2f,
1321 @location(1) v_color : vec4f,
1323 @location(2) v_worldNormal : vec3f,
1324 @location(3) v_worldPos : vec3f,
1326 @location(8) v_worldTangent : vec4f,
1330 @location(4) v_shadowClip : vec4f,
1333 @location(4) v_velCur : vec4f,
1334 @location(7) v_velPrev : vec4f,
1337 @location(5) v_lightmap : vec3f,
1341 @location(6) @interpolate(flat) v_probeSlot : f32,
1345fn coverageUv(uv0 : vec2f) -> vec2f {
1346#ifdef ES_UV_TRANSFORM
1347 var uv = uv0 * mc.u_uvTiling;
1348 if (mc.u_uvRotation != 0.0) {
1349 let c = cos(mc.u_uvRotation);
1350 let sn = sin(mc.u_uvRotation);
1351 uv = vec2f(c * uv.x + sn * uv.y, -sn * uv.x + c * uv.y);
1353 return uv + mc.u_uvOffset;
1362 @location(0) color : vec4f,
1363 @location(1) surface : vec4f,
1364 @location(2) albedo : vec4f,
1367fn packNormal(n : vec3f) -> vec2f {
1368 let a = n / (abs(n.x) + abs(n.y) + abs(n.z));
1369 let sgn = vec2f(select(-1.0, 1.0, a.x >= 0.0), select(-1.0, 1.0, a.y >= 0.0));
1371 if (a.z < 0.0) { e = (vec2f(1.0) - abs(a.yx)) * sgn; }
1372 return e * 0.5 + 0.5;
1375@fragment fn fs_main(v : VSOut, @builtin(front_facing) front : bool) -> FragOut {
1377@fragment fn fs_main(v : VSOut, @builtin(front_facing) front : bool) -> @location(0) vec4f {
1381 g_probeSlot = v.v_probeSlot;
1383 g_lightmap = v.v_lightmap;
1387 g_worldTangent = v.v_worldTangent;
1392 let now = v.v_velCur.xy / v.v_velCur.w;
1393 let was = v.v_velPrev.xy / max(v.v_velPrev.w, 1e-6);
1394 return vec4f((was - now) * 0.5, v.pos.z, select(0.0, 1.0, v.v_velPrev.w > 1e-6));
1395#elif defined(SHADOW_DEPTH)
1396#ifdef PREPASS_COVERAGE
1398 let cuv = coverageUv(v.v_texCoord);
1399 let duvx = dpdx(cuv);
1400 let duvy = dpdy(cuv);
1401 let baseAlpha = textureSampleGrad(t0, s0, cuv, duvx, duvy).a * v.v_color.a * mc.u_tint.a;
1402 let edge = max(fwidth(baseAlpha), 1e-4);
1403 let coverage = (baseAlpha - mc.u_alphaCutoff) / max(edge, 1e-4) + 0.5;
1404 if (coverage <= 0.0) { discard; }
1405 return vec4f(0.0, 0.0, 0.0, min(coverage, 1.0));
1409 let cuv = coverageUv(v.v_texCoord);
1410 let duvx = dpdx(cuv);
1411 let duvy = dpdy(cuv);
1412 if (textureSampleGrad(t0, s0, cuv, duvx, duvy).a * v.v_color.a < mc.u_alphaCutoff) { discard; }
1417 return vec4f(packDepth(clamp(v.v_shadowClip.z / v.v_shadowClip.w * 0.5 + 0.5,
1423 let duvx = dpdx(v.v_texCoord);
1424 let duvy = dpdy(v.v_texCoord);
1425 let base = textureSampleGrad(t0, s0, v.v_texCoord, duvx, duvy) * v.v_color;
1427 var N = normalize(v.v_worldNormal);
1429 N = perturbNormal(N, v.v_worldPos, v.v_texCoord, sampleNormalGrad(t1, s1, v.v_texCoord, duvx, duvy));
1431 if (!front) { N = -N; }
1436 let shaded = applyLightingPBR(base.rgb, N, v.v_worldPos, viewDirection(v.v_worldPos),
1437 0.0, 1.0, 1.0, 1.0);
1440 frag.color = vec4f(shaded, base.a);
1441 frag.surface = vec4f(packNormal(normalize(N)), 1.0, 0.75);
1442 frag.albedo = vec4f(base.rgb, 1.0);
1445 return vec4f(shaded, base.a);
1450 let unlit = vec4f(base.rgb * mix(vec3f(1.0), bakedIrradiance(), vec3f(v.v_lightmap.z)), base.a);
1458 frag.surface = vec4f(packNormal(vec3f(0.0, 1.0, 0.0)), 1.0, 0.75);
1459 frag.albedo = vec4f(base.rgb, 1.0);
1470inline constexpr const char*
PARTICLE = R
"esshader(#pragma shader "ParticleInstance"
1471#pragma version 300 es
1478precision mediump float;
1483uniform sampler2D u_textures[8];
1488 vec4 texColor = texture(u_textures[0], v_texCoord);
1489 fragColor = texColor * v_color;
1495#pragma fragment wgsl
1496@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
1498 let texColor = textureSampleGrad(t0, s0, v.v_texCoord, dpdx(v.v_texCoord), dpdy(v.v_texCoord));
1499 return texColor * v.v_color;
1504inline constexpr const char*
SHADOW2D = R
"esshader(#pragma shader "Shadow2D"
1505#pragma version 300 es
1517layout(location = 0) in vec2 a_position;
1518layout(location = 1) in float a_shadow;
1519layout(location = 2) in vec4 a_channel;
1525 gl_Position = u_projection * vec4(a_position, 0.0, 1.0);
1526 v_shadow = a_shadow;
1527 v_channel = a_channel;
1532precision highp float;
1540 fragColor = v_channel * v_shadow;
1546 @location(0) a_position : vec2f,
1547 @location(1) a_shadow : f32,
1548 @location(2) a_channel : vec4f,
1551 @builtin(position) pos : vec4f,
1552 @location(0) v_shadow : f32,
1553 @location(1) v_channel : vec4f,
1556@vertex fn vs_main(v : VSIn) -> VSOut {
1558 out.pos = frame.projection * vec4f(v.a_position, 0.0, 1.0);
1559 out.v_shadow = v.a_shadow;
1560 out.v_channel = v.a_channel;
1562 out.pos.y = -out.pos.y;
1567#pragma fragment wgsl
1569 @builtin(position) pos : vec4f,
1570 @location(0) v_shadow : f32,
1571 @location(1) v_channel : vec4f,
1574@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
1575 return v.v_channel * v.v_shadow;
1580inline constexpr const char*
SHAPE = R
"esshader(#pragma shader "Shape"
1581#pragma version 300 es
1584layout(location = 0) in vec2 a_position;
1585layout(location = 1) in vec2 a_texCoord;
1586layout(location = 2) in vec4 a_color;
1587layout(location = 3) in vec4 a_shapeInfo;
1591out vec4 v_shapeInfo;
1594 gl_Position = u_projection * vec4(a_position, 0.0, 1.0);
1597 v_shapeInfo = a_shapeInfo;
1602precision mediump float;
1611 vec2 halfSize = v_shapeInfo.yz;
1612 float cornerRadius = v_shapeInfo.w;
1613 vec2 p = v_uv * halfSize;
1616 float shapeType = v_shapeInfo.x;
1618 if (shapeType < 0.5) {
1619 float r = min(halfSize.x, halfSize.y);
1620 dist = length(p) - r;
1621 } else if (shapeType < 1.5) {
1622 float r = min(halfSize.x, halfSize.y);
1623 vec2 elongation = halfSize - vec2(r);
1624 vec2 q = abs(p) - elongation;
1625 dist = length(max(q, 0.0)) - r;
1627 float r = min(cornerRadius, min(halfSize.x, halfSize.y));
1628 vec2 q = abs(p) - halfSize + vec2(r);
1629 dist = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
1632 float fw = fwidth(dist);
1633 float alpha = 1.0 - smoothstep(-fw, fw, dist);
1634 if (alpha < 0.001) discard;
1635 fragColor = vec4(v_color.rgb, v_color.a * alpha);
1641 @location(0) a_position : vec2f,
1642 @location(1) a_texCoord : vec2f,
1643 @location(2) a_color : vec4f,
1644 @location(3) a_shapeInfo : vec4f,
1647 @builtin(position) pos : vec4f,
1648 @location(0) v_uv : vec2f,
1649 @location(1) v_color : vec4f,
1650 @location(2) v_shapeInfo : vec4f,
1653@vertex fn vs_main(v : VSIn) -> VSOut {
1655 out.pos = frame.projection * vec4f(v.a_position, 0.0, 1.0);
1656 out.v_uv = v.a_texCoord;
1657 out.v_color = v.a_color;
1658 out.v_shapeInfo = v.a_shapeInfo;
1660 out.pos.y = -out.pos.y;
1665#pragma fragment wgsl
1667 @builtin(position) pos : vec4f,
1668 @location(0) v_uv : vec2f,
1669 @location(1) v_color : vec4f,
1670 @location(2) v_shapeInfo : vec4f,
1673@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
1674 let halfSize = v.v_shapeInfo.yz;
1675 let cornerRadius = v.v_shapeInfo.w;
1676 let p = v.v_uv * halfSize;
1677 let shapeType = v.v_shapeInfo.x;
1680 if (shapeType < 0.5) {
1681 let r = min(halfSize.x, halfSize.y);
1682 dist = length(p) - r;
1683 } else if (shapeType < 1.5) {
1684 let r = min(halfSize.x, halfSize.y);
1685 let elongation = halfSize - vec2f(r, r);
1686 let q = abs(p) - elongation;
1687 dist = length(max(q, vec2f(0.0, 0.0))) - r;
1689 let r = min(cornerRadius, min(halfSize.x, halfSize.y));
1690 let q = abs(p) - halfSize + vec2f(r, r);
1691 dist = length(max(q, vec2f(0.0, 0.0))) + min(max(q.x, q.y), 0.0) - r;
1694 let fw = fwidth(dist);
1695 let alpha = 1.0 - smoothstep(-fw, fw, dist);
1696 if (alpha < 0.001) { discard; }
1697 return vec4f(v.v_color.rgb, v.v_color.a * alpha);
1702inline constexpr const char*
SKY = R
"esshader(#pragma shader "Sky"
1703#pragma version 300 es
1715layout(location = 0) in vec3 a_position;
1717out highp vec3 v_worldPos;
1720 gl_Position = u_projection * vec4(a_position, 1.0);
1721 v_worldPos = a_position;
1726precision highp float;
1728in highp vec3 v_worldPos;
1731#ifdef ES_SKY_PANORAMA
1732uniform sampler2D u_texture;
1736highp vec3 skyTexel(in ivec2 p, in ivec2 size) {
1737 ivec2 q = ivec2(((p.x % size.x) + size.x) % size.x, clamp(p.y, 0, size.y - 1));
1738 highp vec4 t = texelFetch(u_texture, q, 0);
1739 return t.rgb * t.rgb * (t.a * t.a * u_envParams.y);
1744highp vec3 skyPanorama(in highp vec3 d) {
1745 ivec2 size = textureSize(u_texture, 0);
1746 highp float u = 0.5 - atan(d.x, d.z) / 6.28318530718;
1747 highp float v = acos(clamp(d.y, -1.0, 1.0)) / 3.14159265359;
1748 highp vec2 f = vec2(u * float(size.x), v * float(size.y)) - 0.5;
1749 ivec2 i = ivec2(floor(f));
1750 highp vec2 t = f - floor(f);
1751 return mix(mix(skyTexel(i, size), skyTexel(i + ivec2(1, 0), size), t.x),
1752 mix(skyTexel(i + ivec2(0, 1), size), skyTexel(i + ivec2(1, 1), size), t.x), t.y);
1757#ifdef ES_SKY_PANORAMA
1758 fragColor = vec4(skyPanorama(envDirection(-viewDirection(v_worldPos))), 1.0);
1762 fragColor = vec4(envSampleMip(-viewDirection(v_worldPos), 0.0), 1.0);
1769 @location(0) a_position : vec3f,
1772 @builtin(position) pos : vec4f,
1773 @location(0) v_worldPos : vec3f,
1776@vertex fn vs_main(v : VSIn) -> VSOut {
1778 out.pos = frame.projection * vec4f(v.a_position, 1.0);
1779 out.v_worldPos = v.a_position;
1781 out.pos.y = -out.pos.y;
1786#pragma fragment wgsl
1791@group(1) @binding(0) var t0 : texture_2d<f32>;
1792@group(1) @binding(8) var s0 : sampler;
1793@group(1) @binding(3) var t3 : texture_2d<f32>;
1794@group(1) @binding(11) var s3 : sampler;
1796@group(1) @binding(7) var t7 : texture_2d<f32>;
1797@group(1) @binding(15) var s7 : sampler;
1803 @builtin(position) pos : vec4f,
1804 @location(0) v_worldPos : vec3f,
1807#ifdef ES_SKY_PANORAMA
1808fn skyTexel(p : vec2i, size : vec2i) -> vec3f {
1809 let q = vec2i(((p.x % size.x) + size.x) % size.x, clamp(p.y, 0, size.y - 1));
1810 let t = textureLoad(t0, q, 0);
1811 return t.rgb * t.rgb * (t.a * t.a * lc.u_envParams.y);
1814fn skyPanorama(d : vec3f) -> vec3f {
1815 let size = vec2i(textureDimensions(t0, 0));
1816 let u = 0.5 - atan2(d.x, d.z) / 6.28318530718;
1817 let v = acos(clamp(d.y, -1.0, 1.0)) / 3.14159265359;
1818 let f = vec2f(u * f32(size.x), v * f32(size.y)) - 0.5;
1819 let i = vec2i(floor(f));
1820 let t = f - floor(f);
1821 return mix(mix(skyTexel(i, size), skyTexel(i + vec2i(1, 0), size), t.x),
1822 mix(skyTexel(i + vec2i(0, 1), size), skyTexel(i + vec2i(1, 1), size), t.x), t.y);
1826@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
1827#ifdef ES_SKY_PANORAMA
1828 return vec4f(skyPanorama(envDirection(-viewDirection(v.v_worldPos))), 1.0);
1830 return vec4f(envSampleMip(-viewDirection(v.v_worldPos), 0.0), 1.0);
constexpr const char * LIGHTSHAPE2D
constexpr const char * PARTICLE
constexpr const char * SKY
constexpr const char * BLIT
constexpr const char * MESH
constexpr const char * SHADOW2D
constexpr const char * BATCH
constexpr const char * SHAPE