Agent Harness · VibeGit
Agent Harness Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
agent-harness / tools / spells-assets / ue / vfx / FluidVolume.js 585 строк · изменён 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
import * as THREE from 'three' ;
import { FullscreenQuad , rawPass } from '../engine/fullscreen.js' ;
import { U , FX_BLENDING } from './common.js' ;
import { Q } from '../engine/quality.js' ;
import * as BASE from './FluidVolume.glsl.js' ;
function patch ( src, from , to ) {
if ( ! src
src to
pairs out to src
bodyAt
bodyAt
bodyAt
tx nx ty ny
tx ty
tilesX tx nz tilesY nz tilesX
tilesY ty tilesX tilesY
t t t
w h
count format
sys
cW cH
cW cH
nx ny nz
tiles tiles
cn cn cn
ctiles ctiles
h
nx h ny h nz h
t t tiles nx tiles ny
ctiles cn ctiles cn
i v s burst s
i s s s s
i s s s s
i v v v v v v s
i burst s s s
r s vol r r r s k burst
s vol k
s vol k
_c _v
quadCam
fx
fx fx fx fx fx
fx
fx
fx
tier
tier
tier
tier
tier
cW cH
su
frag su own
cW cH
p p quadCam
box
slots tier
i i slots i
d cW cH
d
d
d d
d d cW cH
d
d
d box d
d
d
fx d
d
d0
d0
d0
d0
d0
d0
d0
big size size size
r res r r
h big r
nx size h ny size h nz size h
cx nx cy ny cz nz
t nx ny nz d d ct cx cy cz d d
t ct
d nx ny nz t cx cy cz ct h
d x
d d size res
d
d
d
d
d
position d position
d
d
d d d
d
d
r prev r alpha r
r _c
r
t d r t r
r d r
r _c alpha
r prev
d d d
p name
p out
p
su
d d d
su d su d
su d su d su dt
su d d d
d d
ob d
su ob d d ob d d ob d d ob d
d d d d
u
u u u
d
u u u u d u d
su
d
u
u u u d
u d
i i d i
u i d i u i d i u i d i u i d i
u d d d d
u d d d d
u d d d d
u d d
u d d d d
u
u u u d d
d d
d d
i i i
d d
d d
d d
u
u u u d d
d d
burned d d dt
d burned
d d burned d d d dt
u d d d d
u d d d
u d d d
dt
r prev r
fxH mPerPx fxH camera
d
d d d
d
d d d d d d d
dt d
d
d d d
su
su d su d su d su d
d d d
d d
d d
d
d
m d
m d d
m d
d m
auto steps steps auto
dist _v camera d
dtm d d auto dist mPerPx d steps
m dtm steps d d d dtm
m d mPerPx d d d
m d d dtm d d dtm
m d d d
m d d d
d d
d d
d
r prev
.
includes
(
from
)
)
throw
new
Error
(
` FluidVolume: shader anchor not found: ${ from . slice ( 0 , 60 ) } `
)
;
return
.
replace
(
from
,
(
)
=>
)
;
}
const
edit
=
(
src, ... pairs
)
=>
.
reduce
(
(
out, [ from , to]
)
=>
patch
(
,
from
,
)
,
)
;
const
REACT
=
edit
(
BASE
.
REACT
,
[
'uniform vec4 uFlow; // external force coupling, damping 1/s, -, -'
,
'uniform vec4 uFlow; // external force coupling, damping 1/s, -, -\nuniform vec4 uTurb; // turbulence m/s2, turbulence frequency tiles/m, soot erosion units/s, soot radiative cooling'
]
,
[
'th /= pow(1.0 + 3.0 * uDecay.y * dt * th * th * th, 1.0 / 3.0);'
,
'th /= pow(1.0 + 3.0 * uDecay.y * dt * th * th * th * (1.0 + uTurb.w * soot), 1.0 / 3.0);'
]
,
[
'soot *= exp(-uDecay.z * dt);'
,
'soot = max(soot * exp(-uDecay.z * dt) - uTurb.z * dt, 0.0);'
]
,
[
' // the shared force field (wind, vortices, shocks...)'
,
' if (uTurb.x > 0.0) acc += curl3(pw * uTurb.y + vec3(0.0, -uTime * 0.6 * uTurb.y, 0.0)) * (uTurb.x * min(th, 1.0));\n // the shared force field (wind, vortices, shocks...)'
]
,
)
;
const
RENDER_BODY
=
`
uniform vec4 uDetail; // soot erosion (units), cell pattern frequency (tiles/m, 0 = off), heat chill 0..1, largest empty-space stride
uniform vec3 uDetailC; // pattern centre: it rides the gas
float gSunPh;
float gMs; // multiple-scattering weight from the albedo
vec3 gFire; // fire-light colour (blackbody at a typical flame-edge temperature) x gain
vec3 gKc; // per-channel extinction scale of the light on its way in (coloured gas)
// per metre: extinction, in-scattered radiance (soot only), emitted radiance
// returns false in empty space (nothing within ~3 voxels)
bool sampleAt(vec3 pw, out float sg, out vec3 sc, out vec3 em) {
sg = 0.0; sc = vec3(0.0); em = vec3(0.0);
vec3 p = (pw - uOrigin) / uH;
vec4 l0 = gridSample(uL0, CG(), p * 0.5);
if (l0.b <= 0.0) return false;
// sub-grid detail (in the spirit of wavelet turbulence): displace the lookup with band-limited
// curl noise drifting up with the gas, strongest where the resolved flow is turbulent
vec3 n = curl3(pw * uMarch.w + vec3(0.0, -uTime * 0.28, 0.0));
vec4 s = gridSample(uS, G(), p + n * (uMarch.z * clamp(0.2 + max(l0.b - 1.0, 0.0) * 0.06, 0.2, 1.0)));
// fade out towards the open faces so the box never shows
vec3 e = min(p, uDim - p);
float ed = min(min(e.x, e.z), uMarch2.z > 0.5 ? min(e.y, uDim.y - p.y) : uDim.y - p.y);
// (the fade distance is jittered by the same noise, so a cloud that reaches a face frays
// into wisps instead of showing a straight cut)
float fade = smoothstep(0.5, uMarch2.x, ed + 1.6 * (n.x + n.z));
s.rgb *= fade * fade;
if (uDetail.y > 0.0) {
// Worley fbm from one fetch: f2 cells (big billows), f4 (the lobes on them), f8 (the
// cauliflower on those). Thin gas erodes harder than the core, so billows keep firm tops
// while their trailing edges tear into ragged wisps
vec3 wv = texture(uNoise3D, (pw - uDetailC) * uDetail.y + n * 0.05).gba;
float crease = 1.0 - dot(wv, vec3(0.45, 0.35, 0.2));
float thin = exp(-s.b / max(uDetail.x, 1e-3));
s.b = max(s.b - uDetail.x * crease * (1.0 + thin), 0.0);
s.r *= 1.0 - uDetail.z * crease;
}
sg = sigmaOf(s);
em = emitOf(s);
float ss = uLook0.y * max(s.b, 0.0);
if (ss < 1e-4) return true;
// sun: single scattering through the precomputed optical depth, plus two wider, weaker octaves
// standing in for multiple scattering (Wrenninge 2015); sky through the optical depth above
float t = l0.r;
// multiple-scattering octaves scale with albedo: dark soot barely scatters twice, so it keeps
// its form shading (lit tops, near-black undersides) instead of glowing flat
vec3 tc = t * gKc;
vec3 sun = uSunColor * uLit.y * (exp(-tc) * gSunPh + gMs * (0.4 * exp(-0.5 * tc) + 0.15 * exp(-0.25 * tc)));
vec3 sky = uAmbient * uLit.z * (0.04 + 0.96 * exp(-0.7 * l0.g * gKc)); // deep cores go near black
sc = ss * uSootColor * (sun + sky + gFire * l0.a);
return true;
}
vec3 gRd;
// a sample on the ray, with the near fade applied (all three outputs are linear in density)
bool tap(float t, out float sg, out vec3 sc, out vec3 em) {
bool o = sampleAt(cameraPosition + gRd * t, sg, sc, em);
float k = clamp(t * uMarch2.w, 0.0, 1.0);
k *= k * (3.0 - 2.0 * k);
sg *= k; sc *= k; em *= k;
return o;
}
// the integrator state, and one trapezoid slab (energy conserving) from ta over L
float gT, gZs, gWs;
vec3 gScat, gEmit;
void slab(float ta, float L, float sa, vec3 ca, vec3 ea, float sb, vec3 cb, vec3 eb) {
float s = 0.5 * (sa + sb);
vec3 S = 0.5 * (ca + cb), E = 0.5 * (ea + eb);
if (s > 1e-5) {
float tr = exp(-s * L), a = gT * (1.0 - tr);
gScat += S * (a / s);
gEmit += E * (a / s);
gZs += a * (ta + 0.5 * L); gWs += a;
gT *= tr;
} else gEmit += gT * E * L;
}
void main() {
vec3 rd = normalize(vWorld - cameraPosition);
gRd = rd;
vec3 dd = mix(rd, vec3(1e-6), lessThan(abs(rd), vec3(1e-6)));
vec3 bmin = uOrigin, bmax = uOrigin + uDim * uH;
vec3 ta = (bmin - cameraPosition) / dd, tb = (bmax - cameraPosition) / dd;
vec3 lo = min(ta, tb), hi = max(ta, tb);
float t0 = max(max(max(lo.x, lo.y), lo.z), 0.0), t1 = min(min(hi.x, hi.y), hi.z);
float cosV = dot(rd, -vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]));
t1 = min(t1, sceneViewZ() / cosV);
if (t1 <= t0) discard;
float dt = uMarch.x;
float mu = dot(uSunDir, rd);
// soot: forward lobe + a weak back lobe, normalised so isotropic = 1
gSunPh = mix(hgPhase(mu, uLit.x), hgPhase(mu, -0.25), 0.25) * 4.0 * PI;
gFire = blackbody(kelvinOf(0.75)) * uTint * uLit.w;
gMs = clamp(dot(uSootColor, vec3(1.0)), 0.0, 1.0);
// chroma > 0: a coloured gas (chlorine) takes its colour from depth, not from its albedo alone.
// The channels it absorbs (where the albedo is below its brightest) fade faster on the way in,
// so thin gas scatters near white and deep gas goes yellow-green; 0 = grey extinction
gKc = 1.0 + uLook1.w * (1.0 - uSootColor / max(max(uSootColor.r, uSootColor.g), max(uSootColor.b, 1e-3)));
gT = 1.0; gZs = 0.0; gWs = 0.0; gScat = vec3(0.0); gEmit = vec3(0.0);
// the lattice: t0 + i dt, ending in a partial step at t1 (continuous in t0, t1 and dt)
float t = t0, sgP; vec3 scP, emP;
bool occP = tap(t, sgP, scP, emP);
float empties = occP ? 0.0 : 1.0;
for (int n = 0; n < 256; n++) {
if (gT < 0.03 || t >= t1) break;
// stride over empty space (the occupancy is dilated ~3 voxels, so skipped points are empty)
float stride = clamp(empties - 1.0, 1.0, uDetail.w);
float tn = min(t + dt * stride, t1), sg; vec3 sc, em;
bool occ = tap(tn, sg, sc, em);
if (occ && stride > 1.0) { // landed in gas: back onto the next lattice point
tn = min(t + dt, t1);
occ = tap(tn, sg, sc, em);
empties = 0.0;
}
float L = tn - t, w = smoothstep(0.8, 1.6, 0.5 * (sg + sgP) * L);
if (w > 0.0) {
// optically thick (a surface): also integrate it as two half slabs through the midpoint, and
// blend the two estimates by thickness, so the surface sits where it is, not on the lattice
float T0 = gT, z0 = gZs, w0 = gWs; vec3 s0 = gScat, e0 = gEmit;
float sgM; vec3 scM, emM;
tap(t + 0.5 * L, sgM, scM, emM);
slab(t, 0.5 * L, sgP, scP, emP, sgM, scM, emM);
slab(t + 0.5 * L, 0.5 * L, sgM, scM, emM, sg, sc, em);
float T2 = gT, z2 = gZs, w2 = gWs; vec3 s2 = gScat, e2 = gEmit;
gT = T0; gZs = z0; gWs = w0; gScat = s0; gEmit = e0;
if (w < 1.0) slab(t, L, sgP, scP, emP, sg, sc, em);
gT = mix(gT, T2, w); gZs = mix(gZs, z2, w); gWs = mix(gWs, w2, w); gScat = mix(gScat, s2, w); gEmit = mix(gEmit, e2, w);
} else slab(t, L, sgP, scP, emP, sg, sc, em);
sgP = sg; scP = sc; emP = em; t = tn;
empties = occ ? 0.0 : empties + 1.0;
}
// stopped on opacity: the unmarched rest is more of the same gas, so renormalise to opaque
// (else the last 3% lets a bright HDR sky print its clouds through thick dark smoke)
if (gT < 0.03) { float k = 1.0 / (1.0 - gT); gScat *= k; gEmit *= k; gT = 0.0; }
float alpha = 1.0 - gT;
if (alpha < 0.002 && dot(gEmit, gEmit) < 1e-6) discard;
float z = (gWs > 0.0 ? gZs / gWs : t0) * cosV;
fxOut(gScat / max(alpha, 1e-4), alpha, gEmit, vec2(0.0), z);
} `
;
const
=
BASE
.
RENDER_FRAG
.
indexOf
(
'float gSunPh;'
)
;
if
(
<
0
)
throw
new
Error
(
'FluidVolume: render body anchor not found'
)
;
const
RENDER_FRAG
=
BASE
.
RENDER_FRAG
.
slice
(
0
,
)
+
RENDER_BODY
;
const
GL
=
{
...
BASE
,
REACT
,
RENDER_FRAG
}
;
const
TIER_RES
=
{
low
:
32
,
medium
:
48
,
high
:
64
,
ultra
:
96
}
;
const
TIER_SLOTS
=
{
low
:
1
,
medium
:
2
,
high
:
2
,
ultra
:
2
}
;
const
TIER_ITERS
=
{
low
:
12
,
medium
:
14
,
high
:
16
,
ultra
:
20
}
;
const
TIER_STEP
=
{
low
:
1.3
,
medium
:
1.15
,
high
:
1.0
,
ultra
:
0.8
}
;
const
TIER_MAXSTEPS
=
{
low
:
56
,
medium
:
80
,
high
:
112
,
ultra
:
160
}
;
const
DEFAULTS
=
{
ignition
:
0.3
,
burnRate
:
3
,
heatPerFuel
:
0.8
,
sootYield
:
0.5
,
expansion
:
1
,
cooling
:
0.5
,
radiative
:
0.25
,
sootDecay
:
0.12
,
fuelDecay
:
0.3
,
buoyancy
:
5
,
sootWeight
:
0.4
,
vorticity
:
6
,
forceCoupling
:
1
,
damping
:
0.15
,
emission
:
4
,
temperature
:
1900
,
sootDensity
:
3
,
flameDensity
:
0.35
,
fuelDensity
:
0
,
absorb
:
0
,
g
:
0.45
,
sun
:
1
,
sky
:
1
,
fireLight
:
0.5
,
upres
:
1.4
,
upresScale
:
4
,
edgeFade
:
5
,
visible
:
true
,
turbulence
:
0
,
turbulenceFreq
:
0.5
,
sootCool
:
0
,
sootErode
:
0
,
detailFreq
:
0
,
detailErode
:
0
,
detailHeat
:
0
,
nearFade
:
0.4
,
emptyBelow
:
0
,
stepScale
:
1
,
chroma
:
0
,
}
;
function
tileLayout
(
nx, ny, nz, W , H
)
{
const
=
Math
.
floor
(
W
/
)
,
=
Math
.
floor
(
H
/
)
;
if
(
<
1
||
<
1
)
return
null
;
const
=
Math
.
min
(
,
)
,
=
Math
.
ceil
(
/
)
;
return
<=
?
[
,
]
:
null
;
}
const
atlasSize
=
(
N
)
=>
{
const
=
Math
.
ceil
(
Math
.
sqrt
(
N
)
)
;
return
[
*
N
,
Math
.
ceil
(
N
/
)
*
N
]
;
}
;
function
target
(
w, h, count, format = THREE . RGBAFormat
)
{
return
new
THREE. WebGLRenderTarget
(
,
,
{
,
type
:
THREE
.
HalfFloatType
,
,
minFilter
:
THREE
.
LinearFilter
,
magFilter
:
THREE
.
LinearFilter
,
wrapS
:
THREE
.
ClampToEdgeWrapping
,
wrapT
:
THREE
.
ClampToEdgeWrapping
,
depthBuffer
:
false
,
stencilBuffer
:
false
,
generateMipmaps
:
false
,
}
)
;
}
class
FluidDomain
{
constructor
(
sys, W , H , cW, cH
)
{
this
.
sys
=
;
this
.
W
=
W
;
this
.
H
=
H
;
this
.
cW
=
;
this
.
cH
=
;
this
.
state
=
[
target
(
W
,
H
,
2
)
,
target
(
W
,
H
,
2
)
]
;
this
.
tmp
=
target
(
W
,
H
,
2
)
;
this
.
curl
=
target
(
W
,
H
,
1
)
;
this
.
press
=
[
target
(
W
,
H
,
1
,
THREE
.
RGFormat
)
,
target
(
W
,
H
,
1
,
THREE
.
RGFormat
)
]
;
this
.
light
=
target
(
,
,
1
)
;
this
.
all
=
[
...
this
.
state
,
this
.
tmp
,
this
.
curl
,
...
this
.
press
]
;
this
.
dim
=
new
THREE. Vector3
(
8
,
8
,
8
)
;
this
.
tiles
=
new
THREE. Vector2
(
1
,
1
)
;
this
.
cdim
=
new
THREE. Vector3
(
4
,
4
,
4
)
;
this
.
ctiles
=
new
THREE. Vector2
(
1
,
1
)
;
this
.
h
=
0.1
;
this
.
size
=
new
THREE. Vector3
(
)
;
this
.
position
=
new
THREE. Vector3
(
)
;
this
.
origin
=
new
THREE. Vector3
(
)
;
this
.
lastOrigin
=
new
THREE. Vector3
(
)
;
this
.
tint
=
new
THREE. Color
(
1
,
1
,
1
)
;
this
.
sootColor
=
new
THREE. Color
(
0.13
,
0.12
,
0.11
)
;
this
.
detailCenter
=
new
THREE. Vector3
(
)
;
this
.
obstacle
=
new
THREE. Vector4
(
)
;
this
.
srcP
=
Array
.
from
(
{
length
:
GL
.
MAX_SRC
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
this
.
srcA
=
Array
.
from
(
{
length
:
GL
.
MAX_SRC
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
this
.
srcV
=
Array
.
from
(
{
length
:
GL
.
MAX_SRC
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
this
.
srcB
=
Array
.
from
(
{
length
:
GL
.
MAX_SRC
}
,
(
)
=>
new
THREE. Vector4
(
)
)
;
this
.
nSrc
=
0
;
this
.
active
=
false
;
this
.
cur
=
0
;
this
.
pc
=
0
;
this
.
fresh
=
true
;
this
.
heat
=
0
;
this
.
fuelPool
=
0
;
Object
.
assign
(
this
,
DEFAULTS
)
;
}
setGrid
(
nx, ny, nz, tiles, cn, ctiles, h
)
{
this
.
dim
.
set
(
,
,
)
;
this
.
tiles
.
set
(
[
0
]
,
[
1
]
)
;
this
.
cdim
.
set
(
[
0
]
,
[
1
]
,
[
2
]
)
;
this
.
ctiles
.
set
(
[
0
]
,
[
1
]
)
;
this
.
h
=
;
this
.
size
.
set
(
*
,
*
,
*
)
;
for
(
const
of
this
.
all
)
.
viewport
.
set
(
0
,
0
,
[
0
]
*
,
[
1
]
*
)
;
this
.
light
.
viewport
.
set
(
0
,
0
,
[
0
]
*
[
0
]
,
[
1
]
*
[
1
]
)
;
}
emit
(
s
)
{
if
(
!
this
.
active
||
this
.
nSrc
>=
GL
.
MAX_SRC
)
return
;
const
=
this
.
nSrc
++
,
=
.
vel
,
=
.
burst
?
1
:
0
;
this
.
srcP
[
]
.
set
(
.
pos
.
x
,
.
pos
.
y
,
.
pos
.
z
,
.
radius
??
0.5
)
;
this
.
srcA
[
]
.
set
(
.
fuel
??
0
,
.
temp
??
0
,
.
soot
??
0
,
.
noise
??
0
)
;
this
.
srcV
[
]
.
set
(
?
.
x
:
0
,
?
.
y
:
0
,
?
.
z
:
0
,
.
radial
??
0
)
;
this
.
srcB
[
]
.
set
(
,
.
noiseScale
??
1
,
.
seed
??
0
,
.
coupling
??
0
)
;
const
=
.
radius
??
0.5
,
=
1.6
*
*
*
*
(
1
-
0.5
*
(
.
noise
??
0
)
)
,
=
?
1
:
this
.
sys
.
dt
;
this
.
fuelPool
+=
(
.
fuel
??
0
)
*
*
;
this
.
heat
+=
(
.
temp
??
0
)
*
*
*
0.5
;
}
clear
(
)
{
this
.
fresh
=
true
;
}
release
(
)
{
this
.
active
=
false
;
this
.
mesh
.
visible
=
false
;
this
.
nSrc
=
0
;
}
}
const
=
new
THREE. Color
(
)
,
=
new
THREE. Vector3
(
)
;
const
=
new
THREE. Camera
(
)
;
export
class
FluidVolume
{
static
get
(
)
{
if
(
!
.
fluid
)
{
.
fluid
=
new
FluidVolume
(
)
;
.
systems
.
push
(
.
fluid
)
;
}
return
.
fluid
;
}
constructor
(
fx
)
{
this
.
fx
=
;
this
.
renderer
=
.
renderer
;
const
=
Q
.
tier
;
this
.
res
=
Q
.
fluidRes
??
TIER_RES
[
]
??
64
;
this
.
iterations
=
Q
.
fluidIterations
??
TIER_ITERS
[
]
??
20
;
this
.
stepVox
=
TIER_STEP
[
]
??
0.85
;
this
.
maxSteps
=
TIER_MAXSTEPS
[
]
??
112
;
this
.
dt
=
1
/
60
;
const
[
W
,
H
]
=
atlasSize
(
this
.
res
)
,
[
,
]
=
atlasSize
(
Math
.
ceil
(
this
.
res
/
2
)
)
;
const
=
this
.
su
=
{
uDim
:
{
value
:
new
THREE. Vector3
(
)
}
,
uTiles
:
{
value
:
new
THREE. Vector2
(
)
}
,
uInv
:
{
value
:
new
THREE. Vector2
(
1
/
W
,
1
/
H
)
}
,
uOrigin
:
{
value
:
new
THREE. Vector3
(
)
}
,
uH
:
{
value
:
0.1
}
,
uSimDt
:
{
value
:
1
/
60
}
,
uShift
:
{
value
:
new
THREE. Vector3
(
)
}
,
uObst
:
{
value
:
new
THREE. Vector4
(
)
}
,
}
;
const
tex
=
(
)
=>
(
{
value
:
null
}
)
;
const
pass
=
(
frag, own
)
=>
new
FullscreenQuad
(
rawPass
(
,
{
...
U
,
...
,
...
}
)
)
;
const
v4s
=
(
)
=>
(
{
value
:
Array
.
from
(
{
length
:
GL
.
MAX_SRC
}
,
(
)
=>
new
THREE. Vector4
(
)
)
}
)
;
this
.
look
=
{
uLook0
:
{
value
:
new
THREE. Vector4
(
)
}
,
uLook1
:
{
value
:
new
THREE. Vector4
(
)
}
,
uTint
:
{
value
:
new
THREE. Vector3
(
1
,
1
,
1
)
}
,
}
;
this
.
passes
=
{
advect
:
pass
(
GL
.
ADVECT
,
{
uV
:
tex
(
)
,
uS
:
tex
(
)
}
)
,
correct
:
pass
(
GL
.
CORRECT
,
{
uV
:
tex
(
)
,
uS
:
tex
(
)
,
uVf
:
tex
(
)
,
uSf
:
tex
(
)
,
uMacCormack
:
{
value
:
1
}
}
)
,
curl
:
pass
(
GL
.
CURL
,
{
uV
:
tex
(
)
}
)
,
react
:
pass
(
GL
.
REACT
,
{
uV
:
tex
(
)
,
uS
:
tex
(
)
,
uC
:
tex
(
)
,
uSrcP
:
v4s
(
)
,
uSrcA
:
v4s
(
)
,
uSrcV
:
v4s
(
)
,
uSrcB
:
v4s
(
)
,
uSrcN
:
{
value
:
0
}
,
uBurn
:
{
value
:
new
THREE. Vector4
(
)
}
,
uDecay
:
{
value
:
new
THREE. Vector4
(
)
}
,
uForce
:
{
value
:
new
THREE. Vector4
(
)
}
,
uFlow
:
{
value
:
new
THREE. Vector4
(
)
}
,
uTurb
:
{
value
:
new
THREE. Vector4
(
)
}
,
}
)
,
diverge
:
pass
(
GL
.
DIVERGE
,
{
uV
:
tex
(
)
,
uS
:
tex
(
)
,
uP
:
tex
(
)
,
uWarm
:
{
value
:
0.9
}
}
)
,
jacobi
:
pass
(
GL
.
JACOBI
,
{
uP
:
tex
(
)
}
)
,
project
:
pass
(
GL
.
PROJECT
,
{
uV
:
tex
(
)
,
uS
:
tex
(
)
,
uP
:
tex
(
)
}
)
,
light
:
pass
(
GL
.
LIGHT
,
{
...
this
.
look
,
uS
:
tex
(
)
,
uC
:
tex
(
)
,
uCDim
:
{
value
:
new
THREE. Vector3
(
)
}
,
uCTiles
:
{
value
:
new
THREE. Vector2
(
)
}
,
uCInv
:
{
value
:
new
THREE. Vector2
(
1
/
,
1
/
)
}
,
uLightP
:
{
value
:
new
THREE. Vector4
(
2.5
,
3
,
1
,
0
)
}
,
}
)
,
}
;
for
(
const
of
Object
.
values
(
this
.
passes
)
)
this
.
renderer
.
compile
(
.
mesh
,
)
;
const
=
new
THREE. BoxGeometry
(
1
,
1
,
1
)
;
const
=
Q
.
fluidDomains
??
TIER_SLOTS
[
]
??
2
;
this
.
domains
=
[
]
;
for
(
let
=
0
;
<
;
++
)
{
const
=
new
FluidDomain
(
this
,
W
,
H
,
,
)
;
.
material
=
new
THREE. RawShaderMaterial
(
{
glslVersion
:
THREE
.
GLSL3
,
vertexShader
:
GL
.
RENDER_VERT
,
fragmentShader
:
GL
.
RENDER_FRAG
,
...
FX_BLENDING
,
depthTest
:
false
,
side
:
THREE
.
BackSide
,
uniforms
:
{
...
U
,
uS
:
tex
(
)
,
uL0
:
{
value
:
.
light
.
texture
}
,
uDim
:
{
value
:
.
dim
}
,
uTiles
:
{
value
:
.
tiles
}
,
uInv
:
{
value
:
new
THREE. Vector2
(
1
/
W
,
1
/
H
)
}
,
uCDim
:
{
value
:
.
cdim
}
,
uCTiles
:
{
value
:
.
ctiles
}
,
uCInv
:
{
value
:
new
THREE. Vector2
(
1
/
,
1
/
)
}
,
uOrigin
:
{
value
:
.
origin
}
,
uH
:
{
value
:
0.1
}
,
uMarch
:
{
value
:
new
THREE. Vector4
(
)
}
,
uMarch2
:
{
value
:
new
THREE. Vector4
(
)
}
,
uLit
:
{
value
:
new
THREE. Vector4
(
)
}
,
uSootColor
:
{
value
:
new
THREE. Vector3
(
)
}
,
uDetail
:
{
value
:
new
THREE. Vector4
(
)
}
,
uDetailC
:
{
value
:
.
detailCenter
}
,
uLook0
:
{
value
:
new
THREE. Vector4
(
)
}
,
uLook1
:
{
value
:
new
THREE. Vector4
(
)
}
,
uTint
:
{
value
:
new
THREE. Vector3
(
1
,
1
,
1
)
}
,
}
,
}
)
;
.
mesh
=
new
THREE. Mesh
(
,
.
material
)
;
.
mesh
.
visible
=
false
;
.
mesh
.
frustumCulled
=
false
;
.
scenes
.
fx
.
add
(
.
mesh
)
;
this
.
domains
.
push
(
)
;
}
const
=
this
.
domains
[
0
]
;
this
.
layout
(
,
[
1
,
1
,
1
]
,
8
)
;
.
active
=
true
;
this
.
clearDomain
(
)
;
this
.
step
(
,
1
/
60
)
;
.
active
=
false
;
.
fresh
=
true
;
}
layout
(
d, size, res
)
{
const
=
Math
.
max
(
[
0
]
,
[
1
]
,
[
2
]
)
;
for
(
let
=
Math
.
max
(
8
,
Math
.
round
(
)
)
;
>=
8
;
-=
2
)
{
const
=
/
;
const
=
Math
.
max
(
4
,
Math
.
round
(
[
0
]
/
)
)
,
=
Math
.
max
(
4
,
Math
.
round
(
[
1
]
/
)
)
,
=
Math
.
max
(
4
,
Math
.
round
(
[
2
]
/
)
)
;
const
=
Math
.
ceil
(
/
2
)
,
=
Math
.
ceil
(
/
2
)
,
=
Math
.
ceil
(
/
2
)
;
const
=
tileLayout
(
,
,
,
.
W
,
.
H
)
,
=
tileLayout
(
,
,
,
.
cW
,
.
cH
)
;
if
(
!
||
!
)
continue
;
.
setGrid
(
,
,
,
,
[
,
,
]
,
,
)
;
return
true
;
}
return
false
;
}
acquire
(
{ size = [ 4 , 4 , 4 ] , res = this . res , position = null } = { }
)
{
const
=
this
.
domains
.
find
(
(
x
)
=>
!
.
active
)
;
if
(
!
||
!
this
.
layout
(
,
,
)
)
return
null
;
Object
.
assign
(
,
DEFAULTS
)
;
.
tint
.
setRGB
(
1
,
1
,
1
)
;
.
sootColor
.
setRGB
(
0.13
,
0.12
,
0.11
)
;
.
detailCenter
.
set
(
0
,
0
,
0
)
;
.
obstacle
.
set
(
0
,
0
,
0
,
0
)
;
if
(
)
.
position
.
copy
(
)
;
.
active
=
true
;
.
fresh
=
true
;
.
nSrc
=
0
;
.
heat
=
0
;
.
fuelPool
=
0
;
return
;
}
get
active
(
)
{
return
this
.
domains
.
some
(
(
d
)
=>
.
active
)
;
}
clearDomain
(
d
)
{
const
=
this
.
renderer
,
=
.
getRenderTarget
(
)
,
=
.
getClearAlpha
(
)
;
.
getClearColor
(
)
;
.
setClearColor
(
0x000000
,
0
)
;
for
(
const
of
.
all
)
{
.
setRenderTarget
(
)
;
.
clear
(
true
,
false
,
false
)
;
}
.
setRenderTarget
(
.
light
)
;
.
clear
(
true
,
false
,
false
)
;
.
setClearColor
(
,
)
;
.
setRenderTarget
(
)
;
.
cur
=
0
;
.
pc
=
0
;
.
fresh
=
false
;
}
draw
(
name, out
)
{
const
=
this
.
passes
[
]
;
.
render
(
this
.
renderer
,
)
;
return
.
material
.
uniforms
;
}
step
(
d, dt
)
{
const
=
this
.
su
,
P
=
this
.
passes
;
.
origin
.
copy
(
.
position
)
.
addScaledVector
(
.
size
,
-
0.5
)
;
.
uDim
.
value
.
copy
(
.
dim
)
;
.
uTiles
.
value
.
copy
(
.
tiles
)
;
.
uOrigin
.
value
.
copy
(
.
origin
)
;
.
uH
.
value
=
.
h
;
.
uSimDt
.
value
=
;
.
uShift
.
value
.
subVectors
(
.
origin
,
.
lastOrigin
)
.
divideScalar
(
.
h
)
;
.
lastOrigin
.
copy
(
.
origin
)
;
const
=
.
obstacle
;
.
uObst
.
value
.
set
(
(
.
x
-
.
origin
.
x
)
/
.
h
-
0.5
,
(
.
y
-
.
origin
.
y
)
/
.
h
-
0.5
,
(
.
z
-
.
origin
.
z
)
/
.
h
-
0.5
,
.
w
/
.
h
)
;
const
A
=
.
state
[
.
cur
]
,
B
=
.
state
[
1
-
.
cur
]
;
let
;
=
P
.
advect
.
material
.
uniforms
;
.
uV
.
value
=
A
.
textures
[
0
]
;
.
uS
.
value
=
A
.
textures
[
1
]
;
this
.
draw
(
'advect'
,
.
tmp
)
;
=
P
.
correct
.
material
.
uniforms
;
.
uV
.
value
=
A
.
textures
[
0
]
;
.
uS
.
value
=
A
.
textures
[
1
]
;
.
uVf
.
value
=
.
tmp
.
textures
[
0
]
;
.
uSf
.
value
=
.
tmp
.
textures
[
1
]
;
this
.
draw
(
'correct'
,
B
)
;
.
uShift
.
value
.
set
(
0
,
0
,
0
)
;
P
.
curl
.
material
.
uniforms
.
uV
.
value
=
B
.
textures
[
0
]
;
this
.
draw
(
'curl'
,
.
curl
)
;
=
P
.
react
.
material
.
uniforms
;
.
uV
.
value
=
B
.
textures
[
0
]
;
.
uS
.
value
=
B
.
textures
[
1
]
;
.
uC
.
value
=
.
curl
.
texture
;
.
uSrcN
.
value
=
.
nSrc
;
for
(
let
=
0
;
<
.
nSrc
;
++
)
{
.
uSrcP
.
value
[
]
.
copy
(
.
srcP
[
]
)
;
.
uSrcA
.
value
[
]
.
copy
(
.
srcA
[
]
)
;
.
uSrcV
.
value
[
]
.
copy
(
.
srcV
[
]
)
;
.
uSrcB
.
value
[
]
.
copy
(
.
srcB
[
]
)
;
}
.
uBurn
.
value
.
set
(
.
ignition
,
.
burnRate
,
.
heatPerFuel
,
.
sootYield
)
;
.
uDecay
.
value
.
set
(
.
cooling
,
.
radiative
,
.
sootDecay
,
.
fuelDecay
)
;
.
uForce
.
value
.
set
(
.
buoyancy
,
.
sootWeight
,
.
vorticity
,
.
expansion
)
;
.
uFlow
.
value
.
set
(
.
forceCoupling
,
.
damping
,
0
,
0
)
;
.
uTurb
.
value
.
set
(
.
turbulence
,
.
turbulenceFreq
,
.
sootErode
,
.
sootCool
)
;
this
.
draw
(
'react'
,
A
)
;
=
P
.
diverge
.
material
.
uniforms
;
.
uV
.
value
=
A
.
textures
[
0
]
;
.
uS
.
value
=
A
.
textures
[
1
]
;
.
uP
.
value
=
.
press
[
.
pc
]
.
texture
;
this
.
draw
(
'diverge'
,
.
press
[
1
-
.
pc
]
)
;
.
pc
=
1
-
.
pc
;
const
J
=
P
.
jacobi
.
material
.
uniforms
;
for
(
let
=
0
;
<
this
.
iterations
;
++
)
{
J
.
uP
.
value
=
.
press
[
.
pc
]
.
texture
;
this
.
draw
(
'jacobi'
,
.
press
[
1
-
.
pc
]
)
;
.
pc
=
1
-
.
pc
;
}
=
P
.
project
.
material
.
uniforms
;
.
uV
.
value
=
A
.
textures
[
0
]
;
.
uS
.
value
=
A
.
textures
[
1
]
;
.
uP
.
value
=
.
press
[
.
pc
]
.
texture
;
this
.
draw
(
'project'
,
B
)
;
.
cur
=
1
-
.
cur
;
const
=
.
fuelPool
*
(
1
-
Math
.
exp
(
-
.
burnRate
*
)
)
;
.
fuelPool
-=
;
.
heat
=
(
.
heat
+
*
.
heatPerFuel
)
*
Math
.
exp
(
-
(
.
cooling
+
0.6
*
.
radiative
)
*
)
;
}
setLook
(
d, u
)
{
.
uLook0
.
value
.
set
(
.
emission
,
.
sootDensity
,
.
flameDensity
,
.
absorb
)
;
.
uLook1
.
value
.
set
(
.
temperature
,
300
,
.
fuelDensity
,
.
chroma
)
;
.
uTint
.
value
.
set
(
.
tint
.
r
,
.
tint
.
g
,
.
tint
.
b
)
;
}
update
(
dt, camera
)
{
this
.
dt
=
Math
.
min
(
,
1
/
30
)
;
const
=
this
.
renderer
,
=
.
getRenderTarget
(
)
;
const
=
U
.
uFxResolution
.
value
.
y
,
=
1
/
(
0.5
*
*
.
projectionMatrix
.
elements
[
5
]
)
;
for
(
const
of
this
.
domains
)
{
.
mesh
.
visible
=
.
active
&&
.
visible
;
if
(
!
.
active
)
continue
;
if
(
.
fresh
)
{
this
.
clearDomain
(
)
;
.
origin
.
copy
(
.
position
)
.
addScaledVector
(
.
size
,
-
0.5
)
;
.
lastOrigin
.
copy
(
.
origin
)
;
}
if
(
>
0
)
this
.
step
(
,
this
.
dt
)
;
.
nSrc
=
0
;
.
origin
.
copy
(
.
position
)
.
addScaledVector
(
.
size
,
-
0.5
)
;
const
=
this
.
su
,
L
=
this
.
passes
.
light
.
material
.
uniforms
;
.
uDim
.
value
.
copy
(
.
dim
)
;
.
uTiles
.
value
.
copy
(
.
tiles
)
;
.
uOrigin
.
value
.
copy
(
.
origin
)
;
.
uH
.
value
=
.
h
;
L
.
uS
.
value
=
.
state
[
.
cur
]
.
textures
[
1
]
;
L
.
uC
.
value
=
.
curl
.
texture
;
L
.
uCDim
.
value
.
copy
(
.
cdim
)
;
L
.
uCTiles
.
value
.
copy
(
.
ctiles
)
;
L
.
uLightP
.
value
.
set
(
2.5
,
2
,
.
fireLight
,
.
emptyBelow
)
;
this
.
setLook
(
,
this
.
look
)
;
this
.
draw
(
'light'
,
.
light
)
;
const
=
.
material
.
uniforms
;
.
uS
.
value
=
.
state
[
.
cur
]
.
textures
[
1
]
;
.
uH
.
value
=
.
h
;
this
.
setLook
(
,
)
;
const
=
Math
.
min
(
1
,
Q
.
auto
?.
??
1
)
,
=
Math
.
max
(
8
,
Math
.
floor
(
this
.
maxSteps
*
)
)
;
const
=
.
subVectors
(
.
position
,
.
position
)
.
length
(
)
;
const
=
Math
.
max
(
this
.
stepVox
*
.
stepScale
*
.
h
/
,
*
,
.
size
.
length
(
)
/
)
;
.
uMarch
.
value
.
set
(
,
,
.
upres
,
Math
.
min
(
1
/
(
4
*
.
upresScale
*
.
h
)
,
1
/
(
16
*
)
)
)
;
.
uMarch2
.
value
.
set
(
.
edgeFade
,
,
.
origin
.
y
>
-
0.5
*
.
h
?
1
:
0
,
1
/
Math
.
max
(
.
nearFade
,
0.01
)
)
;
.
uDetail
.
value
.
set
(
.
detailErode
,
Math
.
min
(
.
detailFreq
,
1
/
(
12
*
)
)
,
.
detailHeat
,
Math
.
max
(
1
,
Math
.
floor
(
3
*
.
h
/
)
)
)
;
.
uLit
.
value
.
set
(
.
g
,
.
sun
,
.
sky
,
1
)
;
.
uSootColor
.
value
.
set
(
.
sootColor
.
r
,
.
sootColor
.
g
,
.
sootColor
.
b
)
;
.
mesh
.
position
.
copy
(
.
position
)
;
.
mesh
.
scale
.
copy
(
.
size
)
;
.
mesh
.
updateMatrixWorld
(
)
;
}
.
setRenderTarget
(
)
;
}
}