Agent Harness · VibeGit
Agent Harness Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
agent-harness / tools / spells-assets / ue / vfx / GroundField.js 710 строк · изменён 6 нояб., 03:45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
import * as THREE from 'three' ;
import { FullscreenQuad , rawPass } from '../engine/fullscreen.js' ;
import { ARENA , COMMON_GLSL , U } from './common.js' ;
x
b b b b
a b a b a b a b
dt tau
renderer
size
partial
opts
size size opts size size opts
size size
maskQuad size
size size opts
cam prev renderer
roundQuad
q maskQuad roundQuad renderer q cam
maskQuad renderer
maskQuad
roundQuad renderer
half
renderer half
roundQuad
half
renderer prev
x z radius heat char wet frost crack acid corruption glow
pattern seed angle x2 x z2 z width lobe
v o
v o x z radius pattern
v o heat char wet frost
v o crack acid corruption glow
v o seed angle x2 z2
w width pattern radius radius
v o w lobe
pattern crack
i
j j j j i i j
i x z radius crack
pattern crack heat w
i m
j j j
a j
j a x a z i j
j m m j
i i m i
i x z x2 z2
i w i crack i seed
p
ext pattern w radius
reach frost p crack p corruption p
life heat p glow p
frost reach p crack reach p
corruption reach p
m ext reach heat
x x2 m z z2 m x x2 m z z2 m life
frost x m z m
life
x radius z radius x radius z radius seconds
r soonest
q
q r q
q soonest soonest q
until seconds
r
r soonest
x0 x0 r z0 z0 r x1 x1 r z1 z1 r
until until r
r x0 r z0 r x1 r z1 r until
dt
cd dt
c c cd
b b cd
n k
band
b b
n n
band
h n
band h n h
i i i i dt
band
k dt
k
n q u s n
nb
r
r
q r s r s r s r s
q n
q q q q
best extra
i i nb i
b i
u b q b q b q b q
e u b q
e nb e extra best i extra e
best nb q
b best
b b q b q b q b q
i i nb i j i j nb j
a i b j
u a b a b a b a b
u a b
a u
b nb nb
j i
nb
p dx adv dt dx
k o dt p p dt dx dx p dt dt p
k o p dt dt p p dt dt p
k o p adv p dx p p
k o p adv p dx dt p dt p
k o p adv p dx dt p dt p
k o p dt dx dx dt p p dt dt
band k o k o k o k o
k o
r u
src dst
u src
u src
u
u
prevTarget r
nb
painting nb
u painting
painting
r
ca r autoClear r
r
r
r
r
r
r autoClear
r ca
dst
i i nb i i dst
i i i i i dst
u dst
dst
dst
r prevTarget
i i nb i i i
nb
u
dst
dst
q q q q
dst q q q q q q
dst
i i i i q
r prev r
cc r ca r
r
t r t r
r cc ca
r prev
c c
b b
q q
gl
gl
points
i i i i points i points i
gl
s
s gl s gl gl
gl s
s
gl gl s
gl gl s
gl gl
s
s
s
r prev r
r
gl gl s
s gl gl gl s
gl gl gl
gl gl
s gl gl
s
r prev
t t
gl
s gl s s gl s
export
const
MAX_SPLATS
=
16
,
MAX_PROBES
=
16
;
const
SPLAT_VEC4
=
5
,
MAX_REGIONS
=
32
,
MAX_BOXES
=
4
,
BANDS
=
32
;
const
PATTERNS
=
{
radial
:
0
,
lichtenberg
:
1
,
ring
:
2
,
noise
:
3
,
line
:
4
}
;
export
const
CRACK_SOURCES
=
Array
.
from
(
{
length
:
4
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
export
const
FISSURE_A
=
Array
.
from
(
{
length
:
4
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
export
const
FISSURE_B
=
Array
.
from
(
{
length
:
4
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
export
const
PAINT_BLENDING
=
{
transparent
:
true
,
depthTest
:
false
,
depthWrite
:
false
,
blending
:
THREE
.
CustomBlending
,
blendEquation
:
THREE
.
AddEquation
,
blendSrc
:
THREE
.
OneFactor
,
blendDst
:
THREE
.
OneFactor
,
blendEquationAlpha
:
THREE
.
AddEquation
,
blendSrcAlpha
:
THREE
.
OneFactor
,
blendDstAlpha
:
THREE
.
OneFactor
,
}
;
export
const
PAINT_FRAG_HEAD
=
`
layout(location = 0) out vec4 gA; // heat, char, wet, frost (added)
layout(location = 1) out vec4 gB; // crack, acid, corruption, glow (added)
`
;
const
f
=
(
x
)
=>
.
toFixed
(
4
)
;
const
area
=
(
b
)
=>
(
.
z
-
.
x
)
*
(
.
w
-
.
y
)
;
const
contains
=
(
a, b
)
=>
.
x
<=
.
x
&&
.
y
<=
.
y
&&
.
z
>=
.
z
&&
.
w
>=
.
w
;
const
decay
=
(
dt, tau
)
=>
Math
.
exp
(
-
/
)
;
const
G
=
ARENA
.
ground
,
P
=
ARENA
.
pool
;
const
FIELD_GLSL
=
`
precision highp float;
precision highp int;
precision highp sampler2D;
${ COMMON_GLSL }
// always 1. Loop bounds read it so ANGLE's D3D compiler (FXC) keeps loops rolled (fast compile)
uniform int uOne;
const vec2 G_MIN = vec2( ${ f ( G . min . x ) } , ${ f ( G . min . y ) } );
const float G_SIZE = ${ f ( G . size ) } ;
vec2 texelWorld(vec2 fragCoord, float n) { return G_MIN + fragCoord / n * G_SIZE; }
bool inPool(vec2 xz) { return all(lessThan(abs(xz - vec2( ${ f ( P . center . x ) } , ${ f ( P . center . y ) } )), vec2( ${ f ( P . half . x ) } , ${ f ( P . half . y ) } ))); }
float vnoise(vec2 x) {
vec2 i = floor(x), u = fract(x);
u = u * u * (3.0 - 2.0 * u);
return mix(mix(hash12(i), hash12(i + vec2(1, 0)), u.x), mix(hash12(i + vec2(0, 1)), hash12(i + vec2(1, 1)), u.x), u.y);
}
float fbm2(vec2 x) { return vnoise(x) * 0.5 + vnoise(x * 2.03 + 17.1) * 0.3 + vnoise(x * 4.11 + 3.7) * 0.2; }
// value noise periodic in x (period per) and optionally y (perY > 0); integer periods only
float vnoiseP(vec2 x, float per, float perY) {
vec2 i = floor(x), u = fract(x);
u = u * u * (3.0 - 2.0 * u);
vec2 i0 = vec2(mod(i.x, per), perY > 0.0 ? mod(i.y, perY) : i.y);
vec2 i1 = vec2(mod(i.x + 1.0, per), perY > 0.0 ? mod(i.y + 1.0, perY) : i.y + 1.0);
return mix(mix(hash12(i0), hash12(vec2(i1.x, i0.y)), u.x), mix(hash12(vec2(i0.x, i1.y)), hash12(i1), u.x), u.y);
}
`
;
const
MASK_FRAG
=
FIELD_GLSL
+
`
uniform float uNeedle; // needles across per metre: 9, fewer on a coarse field (a needle under ~2 texels is noise, and fronts gated on noise grow a maze)
in vec2 vUv;
out vec4 outColor;
// distance to the nearest voronoi edge (F2-F1 bisector distance, Quilez), in cells
float voronoiEdge(vec2 x, float seed) {
vec2 i = floor(x), fr = fract(x), mg, mr;
float md = 8.0;
for (int y = -uOne; y <= uOne; y++) for (int k = -uOne; k <= uOne; k++) {
vec2 g = vec2(k, y), o = hash33(vec3(i + g, seed)).xy, r = g + o - fr;
float d = dot(r, r);
if (d < md) { md = d; mr = r; mg = g; }
}
md = 8.0;
for (int y = -2 * uOne; y <= 2 * uOne; y++) for (int k = -2 * uOne; k <= 2 * uOne; k++) {
vec2 g = mg + vec2(k, y), o = hash33(vec3(i + g, seed)).xy, r = g + o - fr;
if (dot(mr - r, mr - r) > 1e-5) md = min(md, dot(0.5 * (mr + r), normalize(r - mr)));
}
return md;
}
void main() {
vec2 w = G_MIN + vUv * G_SIZE;
// five fbms in one rolled loop: crack warp xy, corruption warp xy, frost wobble
float nv[5];
for (int j = 0; j < 5 * uOne; j++) nv[j] = fbm2(w * (j < 2 ? 0.9 : j < 4 ? 1.7 : 5.0) + float(j) * 9.1);
// ice grows needles along its hexagonal axes: thin ridged streaks at 0/60/120 degrees
// (long along the axis, ~3 cm across), wobbled a little so they aren't ruler-straight
float frost = 0.0;
for (int k = 0; k < 3 * uOne; k++) {
float an = float(k) * 1.0472;
vec2 q = mat2(cos(an), sin(an), -sin(an), cos(an)) * w + vec2(0.0, (nv[4] - 0.5) * 0.25);
frost = max(frost, 1.0 - abs(vnoise(vec2(q.x * 1.3, q.y * uNeedle) + float(k) * 31.7) * 2.0 - 1.0));
}
vec2 wc = w + (vec2(nv[0], nv[1]) - 0.5) * 0.6;
vec2 wv = w + (vec2(nv[2], nv[3]) - 0.5) * 1.4;
// edge distance in metres for: crack plates (~1.4 m), sub-cracks (~0.45 m), and corruption's
// strongly warped ~0.9 m cells (organic tendrils). One rolled loop = one inlined voronoi.
vec3 e;
for (int l = 0; l < 3 * uOne; l++) {
float cell = l == 0 ? 1.4 : l == 1 ? 0.45 : 0.9;
e[l] = voronoiEdge((l == 2 ? wv : wc) / cell, float(l + 1)) * cell;
}
// >= 2 texels wide at 1024^2, so a diagonal vein stays 4-connected for the fronts. Noise
// removes about half the sub-crack edges: cracks fork and dead-end instead of closing cells.
float gaps = vnoise(w * 1.6 + 70.0);
float crack = max((1.0 - smoothstep(0.02, 0.08, e.x)) * smoothstep(0.25, 0.35, gaps),
(1.0 - smoothstep(0.01, 0.06, e.y)) * 0.75 * smoothstep(0.5, 0.6, gaps));
float corr = 1.0 - smoothstep(0.02, 0.08, e.z);
// a: tileable fbm, 60 cells across the field; the sim samples it as splat noise (snoise)
float a = 0.0, amp = 0.5;
for (int o = 0; o < 3 * uOne; o++) { float per = 60.0 * float(1 << o); a += vnoiseP(vUv * per, per, per) * amp; amp *= o == 0 ? 0.6 : 0.67; }
outColor = vec4(frost, crack, corr, clamp((a - 0.5) * 1.6 + 0.5, 0.0, 1.0));
} `
;
const
SIM_FRAG
=
FIELD_GLSL
+
`
uniform sampler2D uA;
uniform sampler2D uB;
uniform sampler2D uMask;
uniform vec4 uSplat[ ${ MAX_SPLATS * SPLAT_VEC4 } ];
uniform int uSplatCount;
uniform float uSeed;
uniform float uRound; // dither offset in ulps: -0.5 if fp16 writes round to nearest, 0 if they truncate
// per-step factors, [0..6] for the fast boxes (this frame's dt), [7..13] for the band (its
// accumulated dt):
// 0 heat decay, heat diffusion alpha, char gain, char decay
// 1 evaporation, wet decay, melt, frost decay
// 2 frost advance p, frost drop/texel, frost threshold, frost drop factor on water
// 3 crack p, crack drop, crack decay, acid decay
// 4 corruption p, corruption drop, corruption decay, glow decay
// 5 acid alpha, pool quench, cleanse, dt
// 6 neighbour decay for the frost, crack, corruption fronts (1 in fast steps), unused
uniform vec4 uK[14];
uniform vec4 uFast[ ${ MAX_BOXES } ]; // texel rects [x0, y0, x1, y1): stepped with uK[0..6] (+ splats) ...
uniform vec4 uBand; // ... or with uK[7..13]; any other drawn texel is copied unchanged
uniform sampler2D uPaintA; // this frame's particle paint (increments), added in fast texels
uniform sampler2D uPaintB;
uniform int uPaintOn;
layout(location = 0) out vec4 oA;
layout(location = 1) out vec4 oB;
// smooth tileable noise from the mask's fbm channel; x in noise cells (60 per field width).
// A fetch instead of inlined value noise: the splat loop compiles ~10x faster under FXC.
float snoise(vec2 x) { return textureLod(uMask, x * (1.0 / 60.0), 0.0).a; }
// coverage of splat i at world xz w (single exit: early returns in this loop slow FXC down)
float splatShape(int i, vec2 w) {
vec4 s0 = uSplat[i * 5], s3 = uSplat[i * 5 + 3], s4 = uSplat[i * 5 + 4];
int pat = int(s0.w);
float R = s0.z, seed = s3.x, m = 0.0;
float ca = cos(s3.y), sa = sin(s3.y);
vec2 nd = mat2(ca, sa, -sa, ca) * (w - s0.xy) / R;
float r = length(nd);
float n = snoise(nd * 3.0 + seed * 7.31);
if (pat == 4) { // line (x, z) -> (x2, z2), half-width s4.x: jagged, tapered at both ends
vec2 ab = s3.zw - s0.xy, q = w - s0.xy;
float L = max(length(ab), 1e-3);
vec2 t = ab / L;
float along = dot(q, t);
float off = dot(q, vec2(-t.y, t.x)) + (snoise(vec2(along * 2.2, seed * 7.31)) - 0.5) * s4.x * 3.0;
float h = clamp(along / L, 0.0, 1.0);
float hw = s4.x * (0.35 + 0.65 * sqrt(clamp(min(h, 1.0 - h) * 6.0, 0.0, 1.0)));
m = smoothstep(hw, hw * 0.2, abs(off)) * (0.7 + 0.3 * snoise(w * 9.0 + seed)) * step(-hw, along) * step(along, L + hw);
} else if (r < 1.6) {
if (pat == 0) m = smoothstep(1.0, 0.35, r + (n - 0.5) * 0.45) * (0.65 + 0.5 * n);
else if (pat == 2) { // ring at R, width s4.x (metres); s4.y > 0: lobed and broken (radius wanders)
vec2 cs = nd / max(r, 1e-3);
float lob = (snoise(cs * 1.4 + seed * 3.7) - 0.5) * 3.0 * s4.y;
float x = (r - 1.0 - lob) * R / s4.x + (n - 0.5) * 1.2;
m = exp(-x * x * 2.0) * (0.6 + 0.6 * n) * mix(1.0, smoothstep(0.3, 0.55, snoise(cs * 2.7 + seed * 1.9)), min(s4.y * 3.0, 1.0));
} else if (pat == 3) m = smoothstep(1.0, 0.6, r) * smoothstep(0.45, 0.62, snoise(nd * 2.2 + seed * 3.1 + 0.5) + (1.0 - r) * 0.15);
else {
// lichtenberg: polar ridged noise stretched along the radius, so ridges run outward.
// Angle is periodic (no seam). Each octave doubles the channels, starts further out,
// wanders more, thins with radius and only shows near its parent channel: a fork.
float th = atan(nd.y, nd.x) / 6.2831853 + 0.5;
float lr = log(max(r, 0.03)), near = 1.0;
for (int o = 0; o < 4 * uOne; o++) {
float fo = float(o), k = 7.0 * float(1 << o);
float warp = (snoise(nd * (1.5 + fo) + seed + fo * 3.3) - 0.5) * (0.25 / k + 0.02); // turns
float ridge = 1.0 - abs(vnoiseP(vec2((th + warp) * k, lr * 0.6 + seed * 13.0 + fo * 5.1), k, 0.0) * 2.0 - 1.0);
float reach = smoothstep(0.05 + fo * 0.12, 0.15 + fo * 0.15, r);
m = max(m, pow(ridge, (30.0 + fo * 12.0) * (0.5 + 1.5 * r)) * near * reach * (1.0 - fo * 0.1));
near *= smoothstep(0.2, 0.6, ridge);
}
float core = smoothstep(0.32, 0.0, r + (n - 0.5) * 0.3);
m = max(core, m) * smoothstep(1.0, 0.55, r + (n - 0.5) * 0.3);
}
}
return m;
}
void main() {
ivec2 p = ivec2(gl_FragCoord.xy), hi = textureSize(uA, 0) - 1;
float n = float(hi.x + 1);
vec4 a = texelFetch(uA, p, 0), b = texelFetch(uB, p, 0);
vec2 fc = gl_FragCoord.xy;
bool fast = false;
for (int i = 0; i < ${ MAX_BOXES } * uOne; i++) fast = fast || (all(greaterThanEqual(fc, uFast[i].xy)) && all(lessThan(fc, uFast[i].zw)));
bool band = all(greaterThanEqual(fc, uBand.xy)) && all(lessThan(fc, uBand.zw));
// copy: keeps both ping-pong targets identical outside what was stepped
if (!fast && !band) { oA = a; oB = b; return; }
vec4 uK0 = fast ? uK[0] : uK[7], uK1 = fast ? uK[1] : uK[8], uK2 = fast ? uK[2] : uK[9];
vec4 uK3 = fast ? uK[3] : uK[10], uK4 = fast ? uK[4] : uK[11], uK5 = fast ? uK[5] : uK[12];
vec4 uK6 = fast ? uK[6] : uK[13];
ivec2 pl = ivec2(max(p.x - 1, 0), p.y), pr = ivec2(min(p.x + 1, hi.x), p.y);
ivec2 pd = ivec2(p.x, max(p.y - 1, 0)), pu = ivec2(p.x, min(p.y + 1, hi.y));
vec4 aL = texelFetch(uA, pl, 0), aR = texelFetch(uA, pr, 0), aD = texelFetch(uA, pd, 0), aU = texelFetch(uA, pu, 0);
vec4 bL = texelFetch(uB, pl, 0), bR = texelFetch(uB, pr, 0), bD = texelFetch(uB, pd, 0), bU = texelFetch(uB, pu, 0);
// diagonals of frost only: an 8-neighbour count tells a dendrite tip (1) from a flat front (3)
float fDL = texelFetch(uA, ivec2(pl.x, pd.y), 0).w, fDR = texelFetch(uA, ivec2(pr.x, pd.y), 0).w;
float fUL = texelFetch(uA, ivec2(pl.x, pu.y), 0).w, fUR = texelFetch(uA, ivec2(pr.x, pu.y), 0).w;
vec4 mask = texelFetch(uMask, p, 0);
vec2 w = texelWorld(gl_FragCoord.xy, n);
vec3 rnd = hash33(vec3(gl_FragCoord.xy, uSeed));
float dt = uK5.w;
float heat = a.x, chr = a.y, wet = a.z, frost = a.w;
float crack = b.x, acid = b.y, corr = b.z, glow = b.w;
float fVis = min(frost, 1.0);
// heat: 5-tap diffusion, decay, water evaporates (latent heat cools), frost melts to wet
heat += (aL.x + aR.x + aD.x + aU.x - 4.0 * heat) * uK0.y;
heat *= uK0.x;
float evap = min(wet, uK1.x * heat);
wet -= evap;
heat -= evap * 0.35;
// branch-free on purpose here and below: FXC (ANGLE/D3D) compile time grows with every if
frost = heat > 0.05 ? min(frost, 1.0) : frost; // heat kills potential: no spreading into fire
float melt = min(frost, uK1.z * heat);
frost -= melt;
wet += melt;
heat = max(heat - melt * 0.5, 0.0);
// char grows where hot and dry, then fades
chr += uK0.z * smoothstep(0.15, 0.7, heat) * (1.0 - min(wet, 1.0));
chr *= uK0.w;
wet *= uK1.y;
// frost front: dendrite tips advance at full rate, flat fronts at a fifth; water freezes
// freely and with a smaller drop, so puddles and the pool ice over in sheets
float frozenN = step(0.2, aL.w) + step(0.2, aR.w) + step(0.2, aD.w) + step(0.2, aU.w)
+ step(0.2, fDL) + step(0.2, fDR) + step(0.2, fUL) + step(0.2, fUR);
float fMax = max(max(max(aL.w, aR.w), max(aD.w, aU.w)), max(max(fDL, fDR), max(fUL, fUR)) - uK2.y * 0.414);
bool onWater = wet > 0.3;
// New frost nucleates by a Packard-style snowflake rule: where exactly one 8-neighbour is
// frozen (a tip), flanks (2-3 neighbours) rarely, so fingers stay thin and fork instead of
// merging into a disc. Inside existing frost the potential flows freely to feed the tips.
float fGate = onWater || frost > 0.2 ? 1.0 : step(uK2.z, mask.r) * (frozenN < 1.5 ? 1.0 : frozenN < 2.5 ? 0.02 : 0.001);
// band steps decay the neighbours too (uK6): over its long dt, undecayed neighbours would
// refill every texel and stall the decay of whole frozen areas. Per frame it's negligible
// and the fast steps keep the reach the look was tuned with.
// the drop per texel (so a front's reach) varies over ~3 m patches, x0.55..1.6: frost reaches
// further where the stone is colder, and a splat's front grows into lobes, never a circle
float fReach = onWater ? uK2.w : 0.55 + 1.05 * textureLod(uMask, w * ${ f ( 1 / 150 ) } , 0.0).a;
float fGrow = fMax * uK6.x - uK2.y * fReach;
float fOld = fVis;
frost *= uK1.w;
frost = max(frost, fGrow * step(rnd.x, uK2.x * fGate) * step(heat, 0.05));
wet += max(fOld - min(frost, 1.0), 0.0) * 0.8 * step(heat, 0.05); // natural thaw -> puddle
// crack front along the vein network
float cMax = max(max(bL.x, bR.x), max(bD.x, bU.x));
crack *= uK3.z;
crack = max(crack, (cMax * uK6.y - uK3.y) * step(rnd.y, uK3.x * step(0.45, mask.g)));
// corruption: spreads as a lobed stain (faster where the fbm is high), falling off with distance
// from its source; the arena material draws the crack network through it, so the field itself
// carries no veins (a vein-gated front read as one even tiling of glowing cells)
float vMax = max(max(bL.z, bR.z), max(bD.z, bU.z));
corr *= uK4.z;
float vGate = 0.15 + 0.85 * mask.a * mask.a;
corr = max(corr, (vMax * uK6.z - uK4.y) * step(rnd.z, uK4.x * vGate));
corr = max(corr - uK5.z * glow, 0.0); // holy light burns corruption away
// acid: slow decay, slight spread; glow: fast decay
acid += (bL.y + bR.y + bD.y + bU.y - 4.0 * acid) * uK5.x;
acid *= uK3.w;
glow *= uK4.w;
// the pool stays full; frost on it is the ice sheet (frost x wet), heat is quenched
float pool = inPool(w) ? 1.0 : 0.0;
wet = max(wet, pool);
heat *= mix(1.0, uK5.y, pool);
vec4 A = vec4(heat, chr, wet, frost), B = vec4(crack, acid, corr, glow);
if (fast && uPaintOn == 1) { A += texelFetch(uPaintA, p, 0); B += texelFetch(uPaintB, p, 0); }
int splats = fast ? uSplatCount : 0; // splats always lie inside the fast boxes
for (int i = 0; i < splats; i++) {
float m = splatShape(i, w);
vec4 s1 = uSplat[i * 5 + 1], s2 = uSplat[i * 5 + 2];
A.xyz += s1.xyz * m;
B.yw += s2.yw * m;
// potential channels take the max (re-splatting doesn't stack reach); negative erases
A.w = s1.w >= 0.0 ? max(A.w, s1.w * m) : A.w + s1.w * m;
B.x = s2.x >= 0.0 ? max(B.x, s2.x * m) : B.x + s2.x * m;
B.z = s2.z >= 0.0 ? max(B.z, s2.z * m) : B.z + s2.z * m;
}
A = clamp(A, vec4(0.0), vec4(2.0, 1.0, 1.0, 4.0));
B = clamp(B, vec4(0.0), vec4(4.0, 1.0, 4.0, 8.0));
// stochastic rounding (1 ulp of dither, placed for how this GPU converts to fp16) keeps the
// tiny per-step decays unbiased; then snap dust to exact zero so idle texels stay 0
vec4 ulpA = exp2(floor(log2(max(A, 6.2e-5))) - 10.0), ulpB = exp2(floor(log2(max(B, 6.2e-5))) - 10.0);
A += (rnd.x + uRound) * ulpA;
B += (fract(rnd.x + 0.618) + uRound) * ulpB;
oA = A * step(1.0 / 1024.0, A);
oB = B * step(1.0 / 1024.0, B);
} `
;
export
class
GroundField
{
constructor
(
renderer, size = 1024 , { partial = true } = { }
)
{
this
.
renderer
=
;
this
.
size
=
;
this
.
partial
=
;
const
=
{
type
:
THREE
.
HalfFloatType
,
format
:
THREE
.
RGBAFormat
,
count
:
2
,
minFilter
:
THREE
.
LinearFilter
,
magFilter
:
THREE
.
LinearFilter
,
wrapS
:
THREE
.
ClampToEdgeWrapping
,
wrapT
:
THREE
.
ClampToEdgeWrapping
,
depthBuffer
:
false
,
generateMipmaps
:
false
,
}
;
this
.
targets
=
[
new
THREE. WebGLRenderTarget
(
,
,
)
,
new
THREE. WebGLRenderTarget
(
,
,
)
]
;
this
.
parity
=
0
;
this
.
params
=
{
heatTau
:
2.5
,
heatDiffusion
:
0.012
,
charRate
:
1.4
,
charTau
:
25
,
evaporation
:
0.9
,
wetTau
:
45
,
melt
:
1.2
,
frostTau
:
7
,
frostSpeed
:
1.6
,
frostDrop
:
0.4
,
frostThreshold
:
0.88
,
frostWaterDrop
:
0.2
,
crackSpeed
:
4
,
crackDrop
:
0.6
,
crackTau
:
9
,
corruptionSpeed
:
1.1
,
corruptionDrop
:
0.4
,
corruptionTau
:
14
,
acidTau
:
14
,
acidSpread
:
0.0015
,
glowTau
:
1
,
poolQuench
:
0.3
,
cleanse
:
1.5
,
}
;
this
.
mask
=
new
THREE. WebGLRenderTarget
(
,
,
{
minFilter
:
THREE
.
LinearFilter
,
magFilter
:
THREE
.
LinearFilter
,
wrapS
:
THREE
.
RepeatWrapping
,
wrapT
:
THREE
.
RepeatWrapping
,
depthBuffer
:
false
,
generateMipmaps
:
false
,
}
)
;
const
=
new
FullscreenQuad
(
rawPass
(
MASK_FRAG
,
{
uOne
:
{
value
:
1
}
,
uNeedle
:
{
value
:
9
*
Math
.
min
(
1
,
/
1024
)
}
}
)
)
;
this
.
splatVecs
=
Array
.
from
(
{
length
:
MAX_SPLATS
*
SPLAT_VEC4
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
this
.
splatCount
=
0
;
this
.
seed
=
0
;
this
.
simMat
=
rawPass
(
SIM_FRAG
,
{
uA
:
{
value
:
null
}
,
uB
:
{
value
:
null
}
,
uMask
:
{
value
:
this
.
mask
.
texture
}
,
uSplat
:
{
value
:
this
.
splatVecs
}
,
uSplatCount
:
{
value
:
0
}
,
uSeed
:
{
value
:
0
}
,
uRound
:
{
value
:
-
0.5
}
,
uOne
:
{
value
:
1
}
,
uK
:
{
value
:
Array
.
from
(
{
length
:
14
}
,
(
)
=>
new
THREE. Vector4
(
)
)
}
,
uFast
:
{
value
:
Array
.
from
(
{
length
:
MAX_BOXES
}
,
(
)
=>
new
THREE. Vector4
(
)
)
}
,
uBand
:
{
value
:
new
THREE. Vector4
(
)
}
,
uPaintA
:
{
value
:
null
}
,
uPaintB
:
{
value
:
null
}
,
uPaintOn
:
{
value
:
0
}
,
}
)
;
this
.
time
=
0
;
this
.
regions
=
Array
.
from
(
{
length
:
MAX_REGIONS
}
,
(
)
=>
(
{
x0
:
0
,
z0
:
0
,
x1
:
0
,
z1
:
0
,
until
:
-
1
}
)
)
;
this
.
boxes
=
this
.
simMat
.
uniforms
.
uFast
.
value
;
this
.
boxCount
=
0
;
this
.
_lastBoxes
=
Array
.
from
(
{
length
:
MAX_BOXES
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
this
.
_lastBoxCount
=
0
;
this
.
_lastBand
=
new
THREE. Vector4
(
)
;
this
.
_q
=
new
THREE. Vector4
(
)
;
this
.
_u
=
new
THREE. Vector4
(
)
;
this
.
band
=
0
;
this
.
bandDt
=
new
Float32Array
(
BANDS
)
;
this
.
_full
=
true
;
this
.
quad
=
new
FullscreenQuad
(
this
.
simMat
)
;
this
.
paintTarget
=
new
THREE. WebGLRenderTarget
(
,
,
{
...
,
minFilter
:
THREE
.
NearestFilter
,
magFilter
:
THREE
.
NearestFilter
}
)
;
this
.
simMat
.
uniforms
.
uPaintA
.
value
=
this
.
paintTarget
.
textures
[
0
]
;
this
.
simMat
.
uniforms
.
uPaintB
.
value
=
this
.
paintTarget
.
textures
[
1
]
;
this
.
_clearColor
=
new
THREE. Color
(
)
;
this
.
paintScene
=
new
THREE. Scene
(
)
;
this
.
paintCamera
=
new
THREE. OrthographicCamera
(
G
.
min
.
x
,
G
.
min
.
x
+
G
.
size
,
G
.
min
.
y
+
G
.
size
,
G
.
min
.
y
,
0
,
200
)
;
this
.
paintCamera
.
position
.
set
(
0
,
-
100
,
0
)
;
this
.
paintCamera
.
up
.
set
(
0
,
0
,
1
)
;
this
.
paintCamera
.
lookAt
(
0
,
0
,
0
)
;
this
.
paintCamera
.
updateMatrixWorld
(
)
;
this
.
_initProbes
(
)
;
const
=
new
THREE. Camera
(
)
,
=
.
getRenderTarget
(
)
;
const
=
new
FullscreenQuad
(
rawPass
(
`
precision highp float;
layout(location = 0) out vec4 o0;
layout(location = 1) out vec4 o1;
void main() { o0 = vec4(1.0 + 0.75 / 1024.0); o1 = vec4(0.0); } `
)
)
;
for
(
const
of
[
,
this
.
quad
,
this
.
probeQuad
,
]
)
.
compile
(
.
mesh
,
)
;
.
render
(
,
this
.
mask
)
;
.
material
.
dispose
(
)
;
.
render
(
,
this
.
paintTarget
)
;
const
=
new
Uint16Array
(
4
)
;
.
readRenderTargetPixels
(
this
.
paintTarget
,
0
,
0
,
1
,
1
,
,
undefined
,
0
)
;
.
material
.
dispose
(
)
;
this
.
fp16Truncates
=
[
0
]
===
0x3c00
;
this
.
simMat
.
uniforms
.
uRound
.
value
=
this
.
fp16Truncates
?
0
:
-
0.5
;
.
setRenderTarget
(
)
;
this
.
clear
(
)
;
}
get
current
(
)
{
return
this
.
targets
[
this
.
parity
]
;
}
splat
(
{
=
0
,
=
0
,
=
1
,
=
0
,
=
0
,
=
0
,
=
0
,
=
0
,
=
0
,
=
0
,
=
0
,
=
'radial'
,
=
Math
.
random
(
)
*
100
,
=
0
,
=
,
=
,
=
0
,
=
0
}
=
{
}
)
{
if
(
this
.
splatCount
>=
MAX_SPLATS
)
return
false
;
const
=
this
.
splatVecs
,
=
this
.
splatCount
*
SPLAT_VEC4
;
[
]
.
set
(
,
,
,
PATTERNS
[
]
??
0
)
;
[
+
1
]
.
set
(
,
,
,
)
;
[
+
2
]
.
set
(
,
,
,
)
;
[
+
3
]
.
set
(
%
100
,
,
,
)
;
const
=
||
(
===
'line'
?
:
*
0.18
)
;
[
+
4
]
.
set
(
,
,
0
,
0
)
;
this
.
splatCount
++
;
if
(
===
'radial'
&&
>=
2
)
{
let
=
0
;
for
(
let
=
1
;
<
4
;
++
)
if
(
CRACK_SOURCES
[
]
.
w
<
CRACK_SOURCES
[
]
.
w
)
=
;
CRACK_SOURCES
[
]
.
set
(
,
,
,
)
;
}
if
(
===
'line'
&&
>=
1.5
&&
>
0.1
&&
>=
0.25
)
{
let
=
-
1
,
=
0
;
for
(
let
=
0
;
<
4
;
++
)
{
const
=
FISSURE_A
[
]
;
if
(
FISSURE_B
[
]
.
y
>
0
&&
Math
.
abs
(
.
x
-
)
<
0.05
&&
Math
.
abs
(
.
y
-
)
<
0.05
)
=
;
if
(
FISSURE_B
[
]
.
y
<
FISSURE_B
[
]
.
y
)
=
;
}
if
(
<
0
)
{
=
;
FISSURE_B
[
]
.
set
(
0
,
0
,
0
,
0
)
;
}
FISSURE_A
[
]
.
set
(
,
,
,
)
;
FISSURE_B
[
]
.
set
(
Math
.
max
(
,
FISSURE_B
[
]
.
x
)
,
Math
.
max
(
,
FISSURE_B
[
]
.
y
)
,
%
97
,
0
)
;
}
const
=
this
.
params
;
const
=
===
'line'
?
*
2.5
:
*
1.6
;
const
=
Math
.
max
(
/
.
frostDrop
,
/
.
crackDrop
,
/
.
corruptionDrop
,
0
)
;
const
=
Math
.
min
(
20
,
Math
.
max
(
>
0
?
3
*
.
heatTau
:
0
,
>
0
?
3
*
.
glowTau
:
0
,
>
0
?
/
.
frostSpeed
*
1.5
+
1
:
0
,
>
0
?
/
.
crackSpeed
*
1.5
+
1
:
0
,
>
0
?
/
.
corruptionSpeed
*
2
+
1
:
0
,
0.5
)
)
;
const
=
+
+
(
>
0
?
0.6
:
0.1
)
;
this
.
_region
(
Math
.
min
(
,
)
-
,
Math
.
min
(
,
)
-
,
Math
.
max
(
,
)
+
,
Math
.
max
(
,
)
+
,
)
;
if
(
>
0
&&
Math
.
abs
(
-
P
.
center
.
x
)
<
P
.
half
.
x
+
&&
Math
.
abs
(
-
P
.
center
.
y
)
<
P
.
half
.
y
+
)
this
.
_region
(
P
.
center
.
x
-
P
.
half
.
x
,
P
.
center
.
y
-
P
.
half
.
y
,
P
.
center
.
x
+
P
.
half
.
x
,
P
.
center
.
y
+
P
.
half
.
y
,
)
;
return
true
;
}
touch
(
x, z, radius, seconds = 1
)
{
this
.
_region
(
-
,
-
,
+
,
+
,
)
;
}
_region
(
x0, z0, x1, z1, seconds
)
{
let
=
null
,
=
this
.
regions
[
0
]
;
for
(
const
of
this
.
regions
)
{
if
(
.
until
<
this
.
time
)
{
=
;
break
;
}
if
(
.
until
<
.
until
)
=
;
}
let
=
this
.
time
+
;
if
(
!
)
{
=
;
=
Math
.
min
(
,
.
x0
)
;
=
Math
.
min
(
,
.
z0
)
;
=
Math
.
max
(
,
.
x1
)
;
=
Math
.
max
(
,
.
z1
)
;
=
Math
.
max
(
,
.
until
)
;
}
.
x0
=
;
.
z0
=
;
.
x1
=
;
.
z1
=
;
.
until
=
;
}
update
(
dt
)
{
this
.
time
+=
;
const
=
decay
(
,
this
.
params
.
crackTau
)
;
for
(
const
of
CRACK_SOURCES
)
.
w
*=
;
for
(
const
of
FISSURE_B
)
.
y
*=
;
const
=
this
.
size
,
=
this
.
simMat
.
uniforms
.
uK
.
value
;
const
=
this
.
simMat
.
uniforms
.
uBand
.
value
;
for
(
const
of
this
.
boxes
)
.
set
(
0
,
0
,
0
,
0
)
;
if
(
this
.
_full
||
!
this
.
partial
)
{
this
.
boxes
[
0
]
.
set
(
0
,
0
,
,
)
;
this
.
boxCount
=
1
;
.
set
(
0
,
0
,
0
,
0
)
;
this
.
_full
=
false
;
}
else
{
this
.
_cluster
(
)
;
const
=
/
BANDS
;
.
set
(
0
,
this
.
band
*
,
,
(
this
.
band
+
1
)
*
)
;
}
for
(
let
=
0
;
<
BANDS
;
++
)
this
.
bandDt
[
]
+=
;
if
(
.
w
===
0
)
this
.
bandDt
.
fill
(
0
)
;
this
.
_factors
(
,
0
,
,
false
)
;
this
.
_factors
(
,
7
,
this
.
bandDt
[
this
.
band
]
,
true
)
;
this
.
bandDt
[
this
.
band
]
=
0
;
this
.
_step
(
)
;
this
.
band
=
(
this
.
band
+
1
)
%
BANDS
;
this
.
_readProbes
(
)
;
}
_cluster
(
)
{
const
=
this
.
size
,
B
=
this
.
boxes
,
=
this
.
_q
,
=
this
.
_u
,
=
/
G
.
size
;
let
=
0
;
for
(
const
of
this
.
regions
)
{
if
(
.
until
<
this
.
time
)
continue
;
.
set
(
Math
.
round
(
(
.
x0
-
G
.
min
.
x
)
*
)
,
Math
.
round
(
(
.
z0
-
G
.
min
.
y
)
*
)
,
Math
.
round
(
(
.
x1
-
G
.
min
.
x
)
*
)
,
Math
.
round
(
(
.
z1
-
G
.
min
.
y
)
*
)
)
;
.
clampScalar
(
0
,
)
;
if
(
.
z
<=
.
x
||
.
w
<=
.
y
)
continue
;
let
=
-
1
,
=
Infinity
;
for
(
let
=
0
;
<
;
++
)
{
const
=
B
[
]
;
.
set
(
Math
.
min
(
.
x
,
.
x
)
,
Math
.
min
(
.
y
,
.
y
)
,
Math
.
max
(
.
z
,
.
z
)
,
Math
.
max
(
.
w
,
.
w
)
)
;
const
=
area
(
)
-
area
(
)
-
area
(
)
;
if
(
(
<
0
||
===
MAX_BOXES
)
&&
<
)
{
=
;
=
;
}
}
if
(
<
0
)
{
B
[
++
]
.
copy
(
)
;
continue
;
}
const
=
B
[
]
;
.
set
(
Math
.
min
(
.
x
,
.
x
)
,
Math
.
min
(
.
y
,
.
y
)
,
Math
.
max
(
.
z
,
.
z
)
,
Math
.
max
(
.
w
,
.
w
)
)
;
}
for
(
let
=
0
;
<
;
++
)
for
(
let
=
+
1
;
<
;
++
)
{
const
=
B
[
]
,
=
B
[
]
;
.
set
(
Math
.
min
(
.
x
,
.
x
)
,
Math
.
min
(
.
y
,
.
y
)
,
Math
.
max
(
.
z
,
.
z
)
,
Math
.
max
(
.
w
,
.
w
)
)
;
if
(
area
(
)
>=
area
(
)
+
area
(
)
)
continue
;
.
copy
(
)
;
.
copy
(
B
[
--
]
)
;
B
[
]
.
set
(
0
,
0
,
0
,
0
)
;
=
;
}
this
.
boxCount
=
;
}
_factors
(
k, o, dt, band
)
{
const
=
this
.
params
,
=
G
.
size
/
this
.
size
,
=
/
;
[
]
.
set
(
decay
(
,
.
heatTau
)
,
Math
.
min
(
0.2
,
.
heatDiffusion
*
/
(
*
)
)
,
.
charRate
*
,
decay
(
,
.
charTau
)
)
;
[
+
1
]
.
set
(
.
evaporation
*
,
decay
(
,
.
wetTau
)
,
.
melt
*
,
decay
(
,
.
frostTau
)
)
;
[
+
2
]
.
set
(
Math
.
min
(
1
,
.
frostSpeed
*
)
,
.
frostDrop
*
,
.
frostThreshold
,
.
frostWaterDrop
)
;
[
+
3
]
.
set
(
Math
.
min
(
1
,
.
crackSpeed
*
)
,
.
crackDrop
*
,
decay
(
,
.
crackTau
)
,
decay
(
,
.
acidTau
)
)
;
[
+
4
]
.
set
(
Math
.
min
(
1
,
.
corruptionSpeed
*
)
,
.
corruptionDrop
*
,
decay
(
,
.
corruptionTau
)
,
decay
(
,
.
glowTau
)
)
;
[
+
5
]
.
set
(
Math
.
min
(
0.2
,
.
acidSpread
*
/
(
*
)
)
,
decay
(
,
.
poolQuench
)
,
.
cleanse
*
,
)
;
if
(
)
[
+
6
]
.
set
(
[
+
1
]
.
w
,
[
+
3
]
.
z
,
[
+
4
]
.
z
,
0
)
;
else
[
+
6
]
.
set
(
1
,
1
,
1
,
0
)
;
}
_step
(
)
{
const
=
this
.
renderer
,
=
this
.
simMat
.
uniforms
;
const
=
this
.
targets
[
this
.
parity
]
,
=
this
.
targets
[
this
.
parity
^
1
]
;
.
uA
.
value
=
.
textures
[
0
]
;
.
uB
.
value
=
.
textures
[
1
]
;
.
uSplatCount
.
value
=
this
.
splatCount
;
.
uSeed
.
value
=
this
.
seed
=
(
this
.
seed
+
1
)
%
4096
;
const
=
.
getRenderTarget
(
)
;
const
B
=
this
.
boxes
,
L
=
this
.
_lastBoxes
,
=
this
.
boxCount
;
const
=
this
.
paintScene
.
children
.
length
>
0
&&
>
0
;
.
uPaintOn
.
value
=
?
1
:
0
;
if
(
)
{
.
getClearColor
(
this
.
_clearColor
)
;
const
=
.
getClearAlpha
(
)
,
=
.
autoClear
;
.
setRenderTarget
(
this
.
paintTarget
)
;
.
setClearColor
(
0x000000
,
0
)
;
.
clear
(
true
,
false
,
false
)
;
.
autoClear
=
false
;
.
render
(
this
.
paintScene
,
this
.
paintCamera
)
;
.
autoClear
=
;
.
setClearColor
(
this
.
_clearColor
,
)
;
}
.
scissorTest
=
true
;
for
(
let
=
0
;
<
;
++
)
this
.
_draw
(
B
[
]
,
)
;
for
(
let
=
0
;
<
this
.
_lastBoxCount
;
++
)
if
(
!
this
.
_covered
(
L
[
]
)
)
this
.
_draw
(
L
[
]
,
)
;
this
.
_draw
(
.
uBand
.
value
,
)
;
if
(
!
this
.
_covered
(
this
.
_lastBand
)
)
this
.
_draw
(
this
.
_lastBand
,
)
;
.
scissorTest
=
false
;
.
setRenderTarget
(
)
;
for
(
let
=
0
;
<
;
++
)
L
[
]
.
copy
(
B
[
]
)
;
this
.
_lastBoxCount
=
;
this
.
_lastBand
.
copy
(
.
uBand
.
value
)
;
this
.
splatCount
=
0
;
this
.
parity
^=
1
;
U
.
uGroundA
.
value
=
.
textures
[
0
]
;
U
.
uGroundB
.
value
=
.
textures
[
1
]
;
}
_draw
(
q, dst
)
{
if
(
.
z
<=
.
x
||
.
w
<=
.
y
)
return
;
.
scissor
.
set
(
.
x
,
.
y
,
.
z
-
.
x
,
.
w
-
.
y
)
;
this
.
quad
.
render
(
this
.
renderer
,
)
;
}
_covered
(
q
)
{
for
(
let
=
0
;
<
this
.
boxCount
;
++
)
if
(
contains
(
this
.
boxes
[
]
,
)
)
return
true
;
return
false
;
}
clear
(
)
{
const
=
this
.
renderer
,
=
.
getRenderTarget
(
)
;
const
=
.
getClearColor
(
new
THREE. Color
(
)
)
,
=
.
getClearAlpha
(
)
;
.
setClearColor
(
0x000000
,
0
)
;
for
(
const
of
this
.
targets
)
{
.
setRenderTarget
(
)
;
.
clear
(
true
,
false
,
false
)
;
}
.
setClearColor
(
,
)
;
.
setRenderTarget
(
)
;
this
.
splatCount
=
0
;
for
(
const
of
CRACK_SOURCES
)
.
set
(
0
,
0
,
0
,
0
)
;
for
(
const
of
FISSURE_B
)
.
set
(
0
,
0
,
0
,
0
)
;
for
(
const
of
this
.
regions
)
.
until
=
-
1
;
this
.
_lastBoxCount
=
0
;
this
.
_lastBand
.
set
(
0
,
0
,
0
,
0
)
;
this
.
_full
=
true
;
U
.
uGroundA
.
value
=
this
.
current
.
textures
[
0
]
;
U
.
uGroundB
.
value
=
this
.
current
.
textures
[
1
]
;
}
_initProbes
(
)
{
this
.
probes
=
new
Float32Array
(
MAX_PROBES
*
8
)
;
this
.
probeCount
=
0
;
this
.
_probeN
=
0
;
this
.
_probeXZ
=
Array
.
from
(
{
length
:
MAX_PROBES
}
,
(
)
=>
new
THREE. Vector2
(
)
)
;
this
.
probeRT
=
new
THREE. WebGLRenderTarget
(
MAX_PROBES
*
2
,
1
,
{
type
:
THREE
.
FloatType
,
minFilter
:
THREE
.
NearestFilter
,
magFilter
:
THREE
.
NearestFilter
,
depthBuffer
:
false
,
generateMipmaps
:
false
,
}
)
;
this
.
probeMat
=
rawPass
(
`
precision highp float;
uniform sampler2D uGroundA;
uniform sampler2D uGroundB;
uniform vec2 uProbe[ ${ MAX_PROBES } ];
out vec4 outColor;
void main() {
int x = int(gl_FragCoord.x);
vec2 uv = (uProbe[x >> 1] - vec2( ${ f ( G . min . x ) } , ${ f ( G . min . y ) } )) / ${ f ( G . size ) } ;
outColor = (x & 1) == 0 ? texture(uGroundA, uv) : texture(uGroundB, uv);
} `
,
{
uGroundA
:
U
.
uGroundA
,
uGroundB
:
U
.
uGroundB
,
uProbe
:
{
value
:
this
.
_probeXZ
}
}
)
;
this
.
probeQuad
=
new
FullscreenQuad
(
this
.
probeMat
)
;
const
=
this
.
renderer
.
getContext
(
)
;
this
.
_pbo
=
[
0
,
1
]
.
map
(
(
)
=>
(
{
buffer
:
.
createBuffer
(
)
,
sync
:
null
,
count
:
0
,
sized
:
false
}
)
)
;
}
setProbes
(
points
)
{
this
.
_probeN
=
Math
.
min
(
.
length
,
MAX_PROBES
)
;
for
(
let
=
0
;
<
this
.
_probeN
;
++
)
this
.
_probeXZ
[
]
.
set
(
[
]
[
0
]
,
[
]
[
1
]
)
;
}
_readProbes
(
)
{
const
=
this
.
renderer
.
getContext
(
)
;
for
(
const
of
this
.
_pbo
)
{
if
(
!
.
sync
||
.
getSyncParameter
(
.
sync
,
.
SYNC_STATUS
)
!==
.
SIGNALED
)
continue
;
.
deleteSync
(
.
sync
)
;
.
sync
=
null
;
.
bindBuffer
(
.
PIXEL_PACK_BUFFER
,
.
buffer
)
;
.
getBufferSubData
(
.
PIXEL_PACK_BUFFER
,
0
,
this
.
probes
,
0
,
.
count
*
8
)
;
.
bindBuffer
(
.
PIXEL_PACK_BUFFER
,
null
)
;
this
.
probeCount
=
.
count
;
}
if
(
!
this
.
_probeN
)
return
;
const
=
!
this
.
_pbo
[
0
]
.
sync
?
this
.
_pbo
[
0
]
:
!
this
.
_pbo
[
1
]
.
sync
?
this
.
_pbo
[
1
]
:
null
;
if
(
!
)
return
;
const
=
this
.
renderer
,
=
.
getRenderTarget
(
)
;
this
.
probeQuad
.
render
(
,
this
.
probeRT
)
;
.
bindBuffer
(
.
PIXEL_PACK_BUFFER
,
.
buffer
)
;
if
(
!
.
sized
)
{
.
bufferData
(
.
PIXEL_PACK_BUFFER
,
MAX_PROBES
*
8
*
4
,
.
STREAM_READ
)
;
.
sized
=
true
;
}
.
readPixels
(
0
,
0
,
this
.
_probeN
*
2
,
1
,
.
RGBA
,
.
FLOAT
,
0
)
;
.
bindBuffer
(
.
PIXEL_PACK_BUFFER
,
null
)
;
.
sync
=
.
fenceSync
(
.
SYNC_GPU_COMMANDS_COMPLETE
,
0
)
;
.
count
=
this
.
_probeN
;
.
setRenderTarget
(
)
;
}
dispose
(
)
{
for
(
const
of
this
.
targets
)
.
dispose
(
)
;
this
.
mask
.
dispose
(
)
;
this
.
probeRT
.
dispose
(
)
;
this
.
paintTarget
.
dispose
(
)
;
this
.
simMat
.
dispose
(
)
;
this
.
probeMat
.
dispose
(
)
;
const
=
this
.
renderer
.
getContext
(
)
;
for
(
const
of
this
.
_pbo
)
{
.
deleteBuffer
(
.
buffer
)
;
if
(
.
sync
)
.
deleteSync
(
.
sync
)
;
}
}
}