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