@flare-engine/postfx 0.4.11 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +14 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +14 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +293 -291
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +293 -291
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -58,7 +58,12 @@ var EffectChain = class {
|
|
|
58
58
|
return true;
|
|
59
59
|
}
|
|
60
60
|
get(id) {
|
|
61
|
-
|
|
61
|
+
const effects = this._effects;
|
|
62
|
+
for (let i = 0; i < effects.length; i++) {
|
|
63
|
+
const e = effects[i];
|
|
64
|
+
if (e !== void 0 && e.id === id) return e;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
62
67
|
}
|
|
63
68
|
setEnabled(id, enabled) {
|
|
64
69
|
const e = this.get(id);
|
|
@@ -205,26 +210,18 @@ half4 main(float2 coord) {
|
|
|
205
210
|
return half4(result, scene.a);
|
|
206
211
|
}
|
|
207
212
|
`;
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
float hash(float2 p) { return fract(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }
|
|
222
|
-
|
|
223
|
-
half4 main(float2 coord) {
|
|
224
|
-
half4 scene = src.eval(coord);
|
|
225
|
-
float2 uv = coord / resolution;
|
|
226
|
-
float aspect = resolution.x / resolution.y;
|
|
227
|
-
float rad = direction * 3.14159 / 180.0;
|
|
213
|
+
const HASH_FN_SKSL = "float hash(float2 p) { return fract(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }";
|
|
214
|
+
const CLOUD_NOISE_FNS_SKSL = `float vnoise(float2 p) {
|
|
215
|
+
float2 i = floor(p); float2 f = fract(p);
|
|
216
|
+
float2 u = f * f * (3.0 - 2.0 * f);
|
|
217
|
+
return mix(mix(hash(i), hash(i + float2(1.0, 0.0)), u.x),
|
|
218
|
+
mix(hash(i + float2(0.0, 1.0)), hash(i + float2(1.0, 1.0)), u.x), u.y);
|
|
219
|
+
}
|
|
220
|
+
float fbm(float2 p) { return vnoise(p) * 0.6 + vnoise(p * 2.3) * 0.4; }`;
|
|
221
|
+
/** Indents a 2-space fragment to the depth of a composite weather branch. */
|
|
222
|
+
const nest = (fragment) => fragment.replace(/^(?=.)/gm, " ");
|
|
223
|
+
const rainBody = (n) => ` float aspect = resolution.x / resolution.y;
|
|
224
|
+
float rad = ${n.direction} * 3.14159 / 180.0;
|
|
228
225
|
float sinA = sin(rad);
|
|
229
226
|
float cosA = cos(rad);
|
|
230
227
|
// aspect-corrected rotated axes: fallAxis along drop travel, perpAxis across
|
|
@@ -240,12 +237,12 @@ half4 main(float2 coord) {
|
|
|
240
237
|
float brightness = 1.0;
|
|
241
238
|
float cid = floor(perpAxis * COLS);
|
|
242
239
|
float colHash = hash(float2(cid, 0.0));
|
|
243
|
-
if (colHash < density) {
|
|
240
|
+
if (colHash < ${n.density}) {
|
|
244
241
|
float phase = hash(float2(cid, 1.0));
|
|
245
242
|
float colBright = brightness * (0.6 + hash(float2(cid, 2.0)) * 0.4);
|
|
246
243
|
float center = 0.5 + (hash(float2(cid, 3.0)) - 0.5) * 0.4;
|
|
247
|
-
float seg = fract(fallAxis * tiling -
|
|
248
|
-
float coverageY = smoothstep(streakLen, 0.0, seg);
|
|
244
|
+
float seg = fract(fallAxis * tiling - ${n.scrollY} + phase);
|
|
245
|
+
float coverageY = smoothstep(${n.streakLen}, 0.0, seg);
|
|
249
246
|
float width = 0.04;
|
|
250
247
|
float xMask = smoothstep(width, 0.0, abs(fract(perpAxis * COLS) - center));
|
|
251
248
|
coverage = max(coverage, coverageY * xMask * colBright);
|
|
@@ -259,19 +256,87 @@ half4 main(float2 coord) {
|
|
|
259
256
|
float brightness = 0.5;
|
|
260
257
|
float cid = floor(perpAxis * COLS);
|
|
261
258
|
float colHash = hash(float2(cid, 10.0));
|
|
262
|
-
if (colHash < density) {
|
|
259
|
+
if (colHash < ${n.density}) {
|
|
263
260
|
float phase = hash(float2(cid, 11.0));
|
|
264
261
|
float colBright = brightness * (0.6 + hash(float2(cid, 12.0)) * 0.4);
|
|
265
262
|
float center = 0.5 + (hash(float2(cid, 13.0)) - 0.5) * 0.4;
|
|
266
|
-
float seg = fract(fallAxis * tiling -
|
|
267
|
-
float coverageY = smoothstep(streakLen, 0.0, seg);
|
|
263
|
+
float seg = fract(fallAxis * tiling - ${n.scrollY} + phase);
|
|
264
|
+
float coverageY = smoothstep(${n.streakLen}, 0.0, seg);
|
|
268
265
|
float width = 0.03;
|
|
269
266
|
float xMask = smoothstep(width, 0.0, abs(fract(perpAxis * COLS) - center));
|
|
270
267
|
coverage = max(coverage, coverageY * xMask * colBright);
|
|
271
268
|
}
|
|
272
|
-
}
|
|
269
|
+
}`;
|
|
270
|
+
const rainBlend = (rgb, color, intensity) => `mix(${rgb}, half3(${color}), half(coverage * ${intensity}))`;
|
|
271
|
+
const sunShaftBody = (direction, intensity) => ` float rad = ${direction} * 3.14159 / 180.0;
|
|
272
|
+
float2 src_point = float2(0.5 + sin(rad) * 0.3, -0.05);
|
|
273
|
+
float2 toFrag = uv - src_point;
|
|
274
|
+
float angle = atan(toFrag.x, toFrag.y);
|
|
275
|
+
float shafts = 0.5 + 0.5 * sin(angle * 8.0);
|
|
276
|
+
float dist = length(toFrag);
|
|
277
|
+
float falloff = 1.0 - smoothstep(0.0, 1.2, dist);
|
|
278
|
+
half shaft = half(shafts * falloff * ${intensity} * 0.35);`;
|
|
279
|
+
const sunShaftBlend = (rgb) => `${rgb} + half3(shaft * 0.95, shaft * 0.9, shaft * 0.6)`;
|
|
280
|
+
const darkVignetteBody = (centered, uvExpr, intensity) => ` float2 ${centered} = ${uvExpr} - 0.5;
|
|
281
|
+
float d = length(${centered});
|
|
282
|
+
float v = smoothstep(0.3, 0.85, d);
|
|
283
|
+
half dark = half(v * ${intensity});`;
|
|
284
|
+
const darkVignetteBlend = (rgb) => `${rgb} * (1.0 - dark)`;
|
|
285
|
+
const cloudsBody = (n) => ` // ${n.direction}=0 → pure horizontal scroll (cos=1, sin=0), matching the pre-${n.direction} default.
|
|
286
|
+
float rad = ${n.direction} * 3.14159 / 180.0;
|
|
287
|
+
float2 scrollDir = float2(cos(rad), sin(rad));
|
|
288
|
+
float2 cloudUv = float2(
|
|
289
|
+
uv.x + ${n.scrollX} * scrollDir.x / resolution.x,
|
|
290
|
+
uv.y * 0.5 + ${n.scrollX} * scrollDir.y / resolution.y
|
|
291
|
+
);
|
|
292
|
+
float cloud = fbm(cloudUv * 3.0);
|
|
293
|
+
float heightFade = smoothstep(0.6, 0.2, uv.y);
|
|
294
|
+
float alpha = cloud * heightFade * ${n.intensity} * 0.5;
|
|
295
|
+
half3 cloudColor = half3(0.9, 0.9, 0.95);`;
|
|
296
|
+
const cloudsBlend = (rgb) => `mix(${rgb}, cloudColor, half(alpha))`;
|
|
297
|
+
const RAIN_STANDALONE = {
|
|
298
|
+
direction: "direction",
|
|
299
|
+
scrollY: "scrollOffsetY",
|
|
300
|
+
density: "density",
|
|
301
|
+
streakLen: "streakLen"
|
|
302
|
+
};
|
|
303
|
+
const RAIN_COMPOSITE = {
|
|
304
|
+
direction: "weatherDirection",
|
|
305
|
+
scrollY: "weatherScrollY",
|
|
306
|
+
density: "weatherDensity",
|
|
307
|
+
streakLen: "weatherStreakLen"
|
|
308
|
+
};
|
|
309
|
+
const CLOUDS_STANDALONE = {
|
|
310
|
+
direction: "direction",
|
|
311
|
+
scrollX: "scrollOffsetX",
|
|
312
|
+
intensity: "intensity"
|
|
313
|
+
};
|
|
314
|
+
const CLOUDS_COMPOSITE = {
|
|
315
|
+
direction: "weatherDirection",
|
|
316
|
+
scrollX: "weatherScrollX",
|
|
317
|
+
intensity: "weatherIntensity"
|
|
318
|
+
};
|
|
319
|
+
const WEATHER_RAIN_SKSL = `
|
|
320
|
+
uniform shader src;
|
|
321
|
+
uniform float2 resolution;
|
|
322
|
+
uniform float intensity;
|
|
323
|
+
uniform float direction;
|
|
324
|
+
uniform float scrollOffsetY;
|
|
325
|
+
uniform float3 color;
|
|
326
|
+
uniform float density;
|
|
327
|
+
uniform float streakLen;
|
|
328
|
+
|
|
329
|
+
// scrollOffsetY is a normalized fall phase in [0,1). Increase it each tick
|
|
330
|
+
// by (speed * dt / screenHeight) and wrap with fract() on the game side.
|
|
273
331
|
|
|
274
|
-
|
|
332
|
+
${HASH_FN_SKSL}
|
|
333
|
+
|
|
334
|
+
half4 main(float2 coord) {
|
|
335
|
+
half4 scene = src.eval(coord);
|
|
336
|
+
float2 uv = coord / resolution;
|
|
337
|
+
${rainBody(RAIN_STANDALONE)}
|
|
338
|
+
|
|
339
|
+
half3 mixed = ${rainBlend("scene.rgb", "color", "intensity")};
|
|
275
340
|
return half4(mixed, scene.a);
|
|
276
341
|
}
|
|
277
342
|
`;
|
|
@@ -284,15 +349,8 @@ uniform float direction;
|
|
|
284
349
|
half4 main(float2 coord) {
|
|
285
350
|
half4 scene = src.eval(coord);
|
|
286
351
|
float2 uv = coord / resolution;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
float2 toFrag = uv - src_point;
|
|
290
|
-
float angle = atan(toFrag.x, toFrag.y);
|
|
291
|
-
float shafts = 0.5 + 0.5 * sin(angle * 8.0);
|
|
292
|
-
float dist = length(toFrag);
|
|
293
|
-
float falloff = 1.0 - smoothstep(0.0, 1.2, dist);
|
|
294
|
-
half shaft = half(shafts * falloff * intensity * 0.35);
|
|
295
|
-
return half4(scene.rgb + half3(shaft * 0.95, shaft * 0.9, shaft * 0.6), scene.a);
|
|
352
|
+
${sunShaftBody("direction", "intensity")}
|
|
353
|
+
return half4(${sunShaftBlend("scene.rgb")}, scene.a);
|
|
296
354
|
}
|
|
297
355
|
`;
|
|
298
356
|
const WEATHER_DARK_VIGNETTE_SKSL = `
|
|
@@ -302,11 +360,8 @@ uniform float intensity;
|
|
|
302
360
|
|
|
303
361
|
half4 main(float2 coord) {
|
|
304
362
|
half4 scene = src.eval(coord);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
float v = smoothstep(0.3, 0.85, d);
|
|
308
|
-
half dark = half(v * intensity);
|
|
309
|
-
return half4(scene.rgb * (1.0 - dark), scene.a);
|
|
363
|
+
${darkVignetteBody("uv", "coord / resolution", "intensity")}
|
|
364
|
+
return half4(${darkVignetteBlend("scene.rgb")}, scene.a);
|
|
310
365
|
}
|
|
311
366
|
`;
|
|
312
367
|
const WEATHER_CLOUDS_SKSL = `
|
|
@@ -316,30 +371,14 @@ uniform float intensity;
|
|
|
316
371
|
uniform float scrollOffsetX;
|
|
317
372
|
uniform float direction;
|
|
318
373
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
float2 i = floor(p); float2 f = fract(p);
|
|
322
|
-
float2 u = f * f * (3.0 - 2.0 * f);
|
|
323
|
-
return mix(mix(hash(i), hash(i + float2(1.0, 0.0)), u.x),
|
|
324
|
-
mix(hash(i + float2(0.0, 1.0)), hash(i + float2(1.0, 1.0)), u.x), u.y);
|
|
325
|
-
}
|
|
326
|
-
float fbm(float2 p) { return vnoise(p) * 0.6 + vnoise(p * 2.3) * 0.4; }
|
|
374
|
+
${HASH_FN_SKSL}
|
|
375
|
+
${CLOUD_NOISE_FNS_SKSL}
|
|
327
376
|
|
|
328
377
|
half4 main(float2 coord) {
|
|
329
378
|
half4 scene = src.eval(coord);
|
|
330
379
|
float2 uv = coord / resolution;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
float2 scrollDir = float2(cos(rad), sin(rad));
|
|
334
|
-
float2 cloudUv = float2(
|
|
335
|
-
uv.x + scrollOffsetX * scrollDir.x / resolution.x,
|
|
336
|
-
uv.y * 0.5 + scrollOffsetX * scrollDir.y / resolution.y
|
|
337
|
-
);
|
|
338
|
-
float cloud = fbm(cloudUv * 3.0);
|
|
339
|
-
float heightFade = smoothstep(0.6, 0.2, uv.y);
|
|
340
|
-
float alpha = cloud * heightFade * intensity * 0.5;
|
|
341
|
-
half3 cloudColor = half3(0.9, 0.9, 0.95);
|
|
342
|
-
return half4(mix(scene.rgb, cloudColor, half(alpha)), scene.a);
|
|
380
|
+
${cloudsBody(CLOUDS_STANDALONE)}
|
|
381
|
+
return half4(${cloudsBlend("scene.rgb")}, scene.a);
|
|
343
382
|
}
|
|
344
383
|
`;
|
|
345
384
|
const COMPOSITE_SKSL = `
|
|
@@ -365,14 +404,8 @@ uniform float3 weatherColor;
|
|
|
365
404
|
uniform float weatherDensity;
|
|
366
405
|
uniform float weatherStreakLen;
|
|
367
406
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
float2 i = floor(p); float2 f = fract(p);
|
|
371
|
-
float2 u = f * f * (3.0 - 2.0 * f);
|
|
372
|
-
return mix(mix(hash(i), hash(i + float2(1.0, 0.0)), u.x),
|
|
373
|
-
mix(hash(i + float2(0.0, 1.0)), hash(i + float2(1.0, 1.0)), u.x), u.y);
|
|
374
|
-
}
|
|
375
|
-
float fbm(float2 p) { return vnoise(p) * 0.6 + vnoise(p * 2.3) * 0.4; }
|
|
407
|
+
${HASH_FN_SKSL}
|
|
408
|
+
${CLOUD_NOISE_FNS_SKSL}
|
|
376
409
|
|
|
377
410
|
half4 main(float2 coord) {
|
|
378
411
|
// --- chromatic aberration ---
|
|
@@ -411,85 +444,21 @@ half4 main(float2 coord) {
|
|
|
411
444
|
if (wk >= 0.5 && wk < 1.5) {
|
|
412
445
|
// rain — falling sawtooth streaks, 2 parallax layers, alpha-over blend
|
|
413
446
|
// weatherScrollY is normalized [0,1) fall phase (increment speed*dt/screenH each tick)
|
|
414
|
-
|
|
415
|
-
float sinA = sin(rad);
|
|
416
|
-
float cosA = cos(rad);
|
|
417
|
-
float aspect = resolution.x / resolution.y;
|
|
418
|
-
float perpAxis = (cosA * uv.x - sinA * uv.y) * aspect;
|
|
419
|
-
float fallAxis = sinA * uv.x + cosA * uv.y;
|
|
420
|
-
|
|
421
|
-
float coverage = 0.0;
|
|
422
|
-
|
|
423
|
-
// near layer — COLS=45, tiling=6, brightness=1.0
|
|
424
|
-
{
|
|
425
|
-
float COLS = 45.0;
|
|
426
|
-
float tiling = 6.0;
|
|
427
|
-
float brightness = 1.0;
|
|
428
|
-
float cid = floor(perpAxis * COLS);
|
|
429
|
-
float colHash = hash(float2(cid, 0.0));
|
|
430
|
-
if (colHash < weatherDensity) {
|
|
431
|
-
float phase = hash(float2(cid, 1.0));
|
|
432
|
-
float colBright = brightness * (0.6 + hash(float2(cid, 2.0)) * 0.4);
|
|
433
|
-
float center = 0.5 + (hash(float2(cid, 3.0)) - 0.5) * 0.4;
|
|
434
|
-
float seg = fract(fallAxis * tiling - weatherScrollY + phase);
|
|
435
|
-
float coverageY = smoothstep(weatherStreakLen, 0.0, seg);
|
|
436
|
-
float width = 0.04;
|
|
437
|
-
float xMask = smoothstep(width, 0.0, abs(fract(perpAxis * COLS) - center));
|
|
438
|
-
coverage = max(coverage, coverageY * xMask * colBright);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
// far layer — COLS=85, tiling=11, brightness=0.5
|
|
443
|
-
{
|
|
444
|
-
float COLS = 85.0;
|
|
445
|
-
float tiling = 11.0;
|
|
446
|
-
float brightness = 0.5;
|
|
447
|
-
float cid = floor(perpAxis * COLS);
|
|
448
|
-
float colHash = hash(float2(cid, 10.0));
|
|
449
|
-
if (colHash < weatherDensity) {
|
|
450
|
-
float phase = hash(float2(cid, 11.0));
|
|
451
|
-
float colBright = brightness * (0.6 + hash(float2(cid, 12.0)) * 0.4);
|
|
452
|
-
float center = 0.5 + (hash(float2(cid, 13.0)) - 0.5) * 0.4;
|
|
453
|
-
float seg = fract(fallAxis * tiling - weatherScrollY + phase);
|
|
454
|
-
float coverageY = smoothstep(weatherStreakLen, 0.0, seg);
|
|
455
|
-
float width = 0.03;
|
|
456
|
-
float xMask = smoothstep(width, 0.0, abs(fract(perpAxis * COLS) - center));
|
|
457
|
-
coverage = max(coverage, coverageY * xMask * colBright);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
447
|
+
${nest(rainBody(RAIN_COMPOSITE))}
|
|
460
448
|
|
|
461
|
-
c =
|
|
449
|
+
c = ${rainBlend("c", "weatherColor", "weatherIntensity")};
|
|
462
450
|
} else if (wk >= 1.5 && wk < 2.5) {
|
|
463
451
|
// sun-shaft
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
float2 toFrag = uv - srcPoint;
|
|
467
|
-
float angle = atan(toFrag.x, toFrag.y);
|
|
468
|
-
float shafts = 0.5 + 0.5 * sin(angle * 8.0);
|
|
469
|
-
float dist = length(toFrag);
|
|
470
|
-
float falloff = 1.0 - smoothstep(0.0, 1.2, dist);
|
|
471
|
-
half shaft = half(shafts * falloff * weatherIntensity * 0.35);
|
|
472
|
-
c = c + half3(shaft * 0.95, shaft * 0.9, shaft * 0.6);
|
|
452
|
+
${nest(sunShaftBody("weatherDirection", "weatherIntensity"))}
|
|
453
|
+
c = ${sunShaftBlend("c")};
|
|
473
454
|
} else if (wk >= 2.5 && wk < 3.5) {
|
|
474
455
|
// dark-vignette
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
float vd = smoothstep(0.3, 0.85, d2);
|
|
478
|
-
half dark = half(vd * weatherIntensity);
|
|
479
|
-
c = c * (1.0 - dark);
|
|
456
|
+
${nest(darkVignetteBody("uvShift", "uv", "weatherIntensity"))}
|
|
457
|
+
c = ${darkVignetteBlend("c")};
|
|
480
458
|
} else if (wk >= 3.5) {
|
|
481
|
-
// clouds
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
float2 cloudUv = float2(
|
|
485
|
-
uv.x + weatherScrollX * scrollDir.x / resolution.x,
|
|
486
|
-
uv.y * 0.5 + weatherScrollX * scrollDir.y / resolution.y
|
|
487
|
-
);
|
|
488
|
-
float cloud = fbm(cloudUv * 3.0);
|
|
489
|
-
float heightFade = smoothstep(0.6, 0.2, uv.y);
|
|
490
|
-
float alpha = cloud * heightFade * weatherIntensity * 0.5;
|
|
491
|
-
half3 cloudColor = half3(0.9, 0.9, 0.95);
|
|
492
|
-
c = mix(c, cloudColor, half(alpha));
|
|
459
|
+
// clouds
|
|
460
|
+
${nest(cloudsBody(CLOUDS_COMPOSITE))}
|
|
461
|
+
c = ${cloudsBlend("c")};
|
|
493
462
|
}
|
|
494
463
|
}
|
|
495
464
|
|
|
@@ -567,6 +536,7 @@ function createPostFxRuntime(skia, opts) {
|
|
|
567
536
|
const _loggedCompileFailures = /* @__PURE__ */ new Set();
|
|
568
537
|
const _loggedCompileSuccesses = /* @__PURE__ */ new Set();
|
|
569
538
|
const supported = skia !== null && typeof skia.RuntimeEffect?.Make === "function";
|
|
539
|
+
const passes = [];
|
|
570
540
|
return {
|
|
571
541
|
supported,
|
|
572
542
|
compile(kind) {
|
|
@@ -593,150 +563,177 @@ function createPostFxRuntime(skia, opts) {
|
|
|
593
563
|
return compiled;
|
|
594
564
|
},
|
|
595
565
|
packUniforms(effect, width, height) {
|
|
596
|
-
|
|
566
|
+
const out = new Float32Array(UNIFORM_FLOAT_COUNT[effect.uniforms.kind]);
|
|
567
|
+
packUniformsInto(effect.uniforms, width, height, out);
|
|
568
|
+
return out;
|
|
597
569
|
},
|
|
598
570
|
buildPass(chain, width, height) {
|
|
599
|
-
|
|
600
|
-
if (
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
571
|
+
let count = 0;
|
|
572
|
+
if (supported) {
|
|
573
|
+
const effects = chain.all();
|
|
574
|
+
const scale = chain.globalIntensity;
|
|
575
|
+
for (let i = 0; i < effects.length; i++) {
|
|
576
|
+
const effect = effects[i];
|
|
577
|
+
if (effect === void 0 || !effect.enabled) continue;
|
|
578
|
+
const u = effect.uniforms;
|
|
579
|
+
const compiled = this.compile(u.kind);
|
|
580
|
+
if (!compiled) continue;
|
|
581
|
+
const floats = UNIFORM_FLOAT_COUNT[u.kind];
|
|
582
|
+
let pass = passes[count];
|
|
583
|
+
if (pass === void 0) {
|
|
584
|
+
pass = {
|
|
585
|
+
id: effect.id,
|
|
586
|
+
kind: u.kind,
|
|
587
|
+
shader: compiled.effect,
|
|
588
|
+
uniforms: new Float32Array(floats),
|
|
589
|
+
children: EMPTY_CHILDREN
|
|
590
|
+
};
|
|
591
|
+
passes[count] = pass;
|
|
592
|
+
} else {
|
|
593
|
+
pass.id = effect.id;
|
|
594
|
+
pass.kind = u.kind;
|
|
595
|
+
pass.shader = compiled.effect;
|
|
596
|
+
if (pass.uniforms.length !== floats) pass.uniforms = new Float32Array(floats);
|
|
597
|
+
}
|
|
598
|
+
packUniformsInto(u, width, height, pass.uniforms);
|
|
599
|
+
if (scale !== 1) scaleIntensity(u.kind, pass.uniforms, scale);
|
|
600
|
+
if (u.kind !== "color-grading-lut") pass.children = EMPTY_CHILDREN;
|
|
601
|
+
else if (pass.children.length !== 1 || pass.children[0] !== u.lut) pass.children = [u.lut];
|
|
602
|
+
count++;
|
|
603
|
+
}
|
|
615
604
|
}
|
|
616
|
-
|
|
605
|
+
if (passes.length !== count) passes.length = count;
|
|
606
|
+
return passes;
|
|
617
607
|
},
|
|
618
608
|
reset() {
|
|
619
609
|
cache.clear();
|
|
620
610
|
}
|
|
621
611
|
};
|
|
622
612
|
}
|
|
623
|
-
|
|
613
|
+
/** Length of the packed uniform buffer per effect kind — the float count its SkSL declares. */
|
|
614
|
+
const UNIFORM_FLOAT_COUNT = {
|
|
615
|
+
vignette: 7,
|
|
616
|
+
"grayscale-flash": 1,
|
|
617
|
+
"chromatic-aberration": 3,
|
|
618
|
+
crt: 4,
|
|
619
|
+
bloom: 4,
|
|
620
|
+
"god-rays": 12,
|
|
621
|
+
"color-grading-lut": 1,
|
|
622
|
+
"weather-rain": 10,
|
|
623
|
+
"weather-sun-shaft": 4,
|
|
624
|
+
"weather-dark-vignette": 3,
|
|
625
|
+
"weather-clouds": 5,
|
|
626
|
+
composite: 24
|
|
627
|
+
};
|
|
628
|
+
/** Write `u` into `out`, which holds `UNIFORM_FLOAT_COUNT[u.kind]` floats, in shader declaration order. */
|
|
629
|
+
function packUniformsInto(u, width, height, out) {
|
|
624
630
|
switch (u.kind) {
|
|
625
631
|
case "vignette": {
|
|
626
|
-
const col = u.color
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
];
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
u.radius,
|
|
636
|
-
col[0],
|
|
637
|
-
col[1],
|
|
638
|
-
col[2]
|
|
639
|
-
]);
|
|
640
|
-
}
|
|
641
|
-
case "grayscale-flash": return new Float32Array([u.intensity]);
|
|
642
|
-
case "chromatic-aberration": return new Float32Array([
|
|
643
|
-
width,
|
|
644
|
-
height,
|
|
645
|
-
u.amount
|
|
646
|
-
]);
|
|
647
|
-
case "crt": return new Float32Array([
|
|
648
|
-
width,
|
|
649
|
-
height,
|
|
650
|
-
u.scanlineIntensity,
|
|
651
|
-
u.curvature
|
|
652
|
-
]);
|
|
653
|
-
case "bloom": return new Float32Array([
|
|
654
|
-
width,
|
|
655
|
-
height,
|
|
656
|
-
u.threshold,
|
|
657
|
-
u.intensity
|
|
658
|
-
]);
|
|
659
|
-
case "god-rays": {
|
|
660
|
-
const samples = Math.max(1, Math.min(64, Math.round(u.samples)));
|
|
661
|
-
return new Float32Array([
|
|
662
|
-
width,
|
|
663
|
-
height,
|
|
664
|
-
u.lightX,
|
|
665
|
-
u.lightY,
|
|
666
|
-
u.color[0],
|
|
667
|
-
u.color[1],
|
|
668
|
-
u.color[2],
|
|
669
|
-
u.intensity,
|
|
670
|
-
u.decay,
|
|
671
|
-
u.density,
|
|
672
|
-
u.weight,
|
|
673
|
-
samples
|
|
674
|
-
]);
|
|
632
|
+
const col = u.color;
|
|
633
|
+
out[0] = width;
|
|
634
|
+
out[1] = height;
|
|
635
|
+
out[2] = u.intensity;
|
|
636
|
+
out[3] = u.radius;
|
|
637
|
+
out[4] = col === void 0 ? 0 : col[0];
|
|
638
|
+
out[5] = col === void 0 ? 0 : col[1];
|
|
639
|
+
out[6] = col === void 0 ? 0 : col[2];
|
|
640
|
+
return;
|
|
675
641
|
}
|
|
676
|
-
case "
|
|
642
|
+
case "grayscale-flash":
|
|
643
|
+
out[0] = u.intensity;
|
|
644
|
+
return;
|
|
645
|
+
case "chromatic-aberration":
|
|
646
|
+
out[0] = width;
|
|
647
|
+
out[1] = height;
|
|
648
|
+
out[2] = u.amount;
|
|
649
|
+
return;
|
|
650
|
+
case "crt":
|
|
651
|
+
out[0] = width;
|
|
652
|
+
out[1] = height;
|
|
653
|
+
out[2] = u.scanlineIntensity;
|
|
654
|
+
out[3] = u.curvature;
|
|
655
|
+
return;
|
|
656
|
+
case "bloom":
|
|
657
|
+
out[0] = width;
|
|
658
|
+
out[1] = height;
|
|
659
|
+
out[2] = u.threshold;
|
|
660
|
+
out[3] = u.intensity;
|
|
661
|
+
return;
|
|
662
|
+
case "god-rays":
|
|
663
|
+
out[0] = width;
|
|
664
|
+
out[1] = height;
|
|
665
|
+
out[2] = u.lightX;
|
|
666
|
+
out[3] = u.lightY;
|
|
667
|
+
out[4] = u.color[0];
|
|
668
|
+
out[5] = u.color[1];
|
|
669
|
+
out[6] = u.color[2];
|
|
670
|
+
out[7] = u.intensity;
|
|
671
|
+
out[8] = u.decay;
|
|
672
|
+
out[9] = u.density;
|
|
673
|
+
out[10] = u.weight;
|
|
674
|
+
out[11] = Math.max(1, Math.min(64, Math.round(u.samples)));
|
|
675
|
+
return;
|
|
676
|
+
case "color-grading-lut":
|
|
677
|
+
out[0] = u.intensity;
|
|
678
|
+
return;
|
|
677
679
|
case "weather-rain": {
|
|
678
|
-
const col = u.color
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
];
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
col[1],
|
|
691
|
-
col[2],
|
|
692
|
-
u.density ?? .5,
|
|
693
|
-
u.streakLen ?? .15
|
|
694
|
-
]);
|
|
680
|
+
const col = u.color;
|
|
681
|
+
out[0] = width;
|
|
682
|
+
out[1] = height;
|
|
683
|
+
out[2] = u.intensity;
|
|
684
|
+
out[3] = u.direction;
|
|
685
|
+
out[4] = u.scrollOffsetY;
|
|
686
|
+
out[5] = col === void 0 ? 1 : col[0];
|
|
687
|
+
out[6] = col === void 0 ? 1 : col[1];
|
|
688
|
+
out[7] = col === void 0 ? 1 : col[2];
|
|
689
|
+
out[8] = u.density ?? .5;
|
|
690
|
+
out[9] = u.streakLen ?? .15;
|
|
691
|
+
return;
|
|
695
692
|
}
|
|
696
|
-
case "weather-sun-shaft":
|
|
697
|
-
width
|
|
698
|
-
height
|
|
699
|
-
u.intensity
|
|
700
|
-
u.direction
|
|
701
|
-
|
|
702
|
-
case "weather-dark-vignette":
|
|
703
|
-
width
|
|
704
|
-
height
|
|
705
|
-
u.intensity
|
|
706
|
-
|
|
707
|
-
case "weather-clouds":
|
|
708
|
-
width
|
|
709
|
-
height
|
|
710
|
-
u.intensity
|
|
711
|
-
u.scrollOffsetX
|
|
712
|
-
u.direction
|
|
713
|
-
|
|
714
|
-
case "composite":
|
|
715
|
-
width
|
|
716
|
-
height
|
|
717
|
-
u.vignetteIntensity
|
|
718
|
-
u.vignetteRadius
|
|
719
|
-
u.vignetteColor[0]
|
|
720
|
-
u.vignetteColor[1]
|
|
721
|
-
u.vignetteColor[2]
|
|
722
|
-
u.bloomThreshold
|
|
723
|
-
u.bloomIntensity
|
|
724
|
-
u.flashIntensity
|
|
725
|
-
u.chromaAmount
|
|
726
|
-
u.crtScanlineIntensity
|
|
727
|
-
u.crtCurvature
|
|
728
|
-
u.crtEnabled ? 1 : 0
|
|
729
|
-
u.weatherKind
|
|
730
|
-
u.weatherIntensity
|
|
731
|
-
u.weatherDirection
|
|
732
|
-
u.weatherScrollX
|
|
733
|
-
u.weatherScrollY
|
|
734
|
-
u.weatherColor[0]
|
|
735
|
-
u.weatherColor[1]
|
|
736
|
-
u.weatherColor[2]
|
|
737
|
-
u.weatherDensity
|
|
738
|
-
u.weatherStreakLen
|
|
739
|
-
|
|
693
|
+
case "weather-sun-shaft":
|
|
694
|
+
out[0] = width;
|
|
695
|
+
out[1] = height;
|
|
696
|
+
out[2] = u.intensity;
|
|
697
|
+
out[3] = u.direction;
|
|
698
|
+
return;
|
|
699
|
+
case "weather-dark-vignette":
|
|
700
|
+
out[0] = width;
|
|
701
|
+
out[1] = height;
|
|
702
|
+
out[2] = u.intensity;
|
|
703
|
+
return;
|
|
704
|
+
case "weather-clouds":
|
|
705
|
+
out[0] = width;
|
|
706
|
+
out[1] = height;
|
|
707
|
+
out[2] = u.intensity;
|
|
708
|
+
out[3] = u.scrollOffsetX;
|
|
709
|
+
out[4] = u.direction;
|
|
710
|
+
return;
|
|
711
|
+
case "composite":
|
|
712
|
+
out[0] = width;
|
|
713
|
+
out[1] = height;
|
|
714
|
+
out[2] = u.vignetteIntensity;
|
|
715
|
+
out[3] = u.vignetteRadius;
|
|
716
|
+
out[4] = u.vignetteColor[0];
|
|
717
|
+
out[5] = u.vignetteColor[1];
|
|
718
|
+
out[6] = u.vignetteColor[2];
|
|
719
|
+
out[7] = u.bloomThreshold;
|
|
720
|
+
out[8] = u.bloomIntensity;
|
|
721
|
+
out[9] = u.flashIntensity;
|
|
722
|
+
out[10] = u.chromaAmount;
|
|
723
|
+
out[11] = u.crtScanlineIntensity;
|
|
724
|
+
out[12] = u.crtCurvature;
|
|
725
|
+
out[13] = u.crtEnabled ? 1 : 0;
|
|
726
|
+
out[14] = u.weatherKind;
|
|
727
|
+
out[15] = u.weatherIntensity;
|
|
728
|
+
out[16] = u.weatherDirection;
|
|
729
|
+
out[17] = u.weatherScrollX;
|
|
730
|
+
out[18] = u.weatherScrollY;
|
|
731
|
+
out[19] = u.weatherColor[0];
|
|
732
|
+
out[20] = u.weatherColor[1];
|
|
733
|
+
out[21] = u.weatherColor[2];
|
|
734
|
+
out[22] = u.weatherDensity;
|
|
735
|
+
out[23] = u.weatherStreakLen;
|
|
736
|
+
return;
|
|
740
737
|
}
|
|
741
738
|
}
|
|
742
739
|
/**
|
|
@@ -805,41 +802,46 @@ function createPostFxController(options) {
|
|
|
805
802
|
let flashIntensity = 0;
|
|
806
803
|
const timedRemaining = /* @__PURE__ */ new Map();
|
|
807
804
|
const timedRestore = /* @__PURE__ */ new Map();
|
|
805
|
+
const expired = [];
|
|
806
|
+
let stepMs = 0;
|
|
807
|
+
const stepTimed = (remaining, id) => {
|
|
808
|
+
const next = remaining - stepMs;
|
|
809
|
+
if (next <= 0) expired.push(id);
|
|
810
|
+
else timedRemaining.set(id, next);
|
|
811
|
+
};
|
|
812
|
+
const flashUniforms = {
|
|
813
|
+
kind: "grayscale-flash",
|
|
814
|
+
intensity: 0
|
|
815
|
+
};
|
|
808
816
|
return {
|
|
809
817
|
chain,
|
|
810
818
|
runtime,
|
|
811
819
|
triggerHitFlash() {
|
|
812
820
|
if (!flashCfg) return;
|
|
813
821
|
flashIntensity = 1;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
intensity: 1
|
|
817
|
-
});
|
|
822
|
+
flashUniforms.intensity = 1;
|
|
823
|
+
chain.setUniforms(flashCfg.id, flashUniforms);
|
|
818
824
|
},
|
|
819
825
|
triggerTimed(effectId, decayMs) {
|
|
820
826
|
const effect = chain.get(effectId);
|
|
821
827
|
if (!effect) return;
|
|
822
|
-
timedRestore.set(effectId, { ...effect.uniforms });
|
|
828
|
+
if (!timedRemaining.has(effectId)) timedRestore.set(effectId, { ...effect.uniforms });
|
|
823
829
|
chain.setEnabled(effectId, true);
|
|
824
830
|
timedRemaining.set(effectId, decayMs);
|
|
825
831
|
},
|
|
826
832
|
update(dt) {
|
|
827
833
|
if (flashCfg && flashIntensity > 0) {
|
|
828
834
|
flashIntensity = Math.max(0, flashIntensity - dt * flashDecay);
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
intensity: flashIntensity
|
|
832
|
-
});
|
|
835
|
+
flashUniforms.intensity = flashIntensity;
|
|
836
|
+
chain.setUniforms(flashCfg.id, flashUniforms);
|
|
833
837
|
}
|
|
834
838
|
if (timedRemaining.size > 0) {
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
}
|
|
842
|
-
if (expired.length > 0) for (const id of expired) {
|
|
839
|
+
stepMs = dt * 1e3;
|
|
840
|
+
expired.length = 0;
|
|
841
|
+
timedRemaining.forEach(stepTimed);
|
|
842
|
+
for (let i = 0; i < expired.length; i++) {
|
|
843
|
+
const id = expired[i];
|
|
844
|
+
if (id === void 0) continue;
|
|
843
845
|
const snapshot = timedRestore.get(id);
|
|
844
846
|
if (snapshot !== void 0) chain.setUniforms(id, snapshot);
|
|
845
847
|
chain.setEnabled(id, false);
|