import*asTHREEfrom'three';import{COMMON_GLSL,NOISE_GLSL,WORLD_GLSL,LIGHTS_GLSL,U, arenaSDF }from'../vfx/common.js';import{REFRACT_GLSL}from'../vfx/Refraction.js';// Ice (PLAN 3). Glacial Spike: a faceted crystal grows at the focus (vertices clamped behind a// growth front whose cap glows), cold mist sinks off it and ~1k motes stream in. It flies as a// ~190-triangle hexagonal shard in the refract pass (IOR 1.31, analytic ellipsoid thickness,// Beer-Lambert cyan, flat facets, a fake interior of bubbles / veils / cracks from 3 noise taps// along the refracted ray, rime on the crystal edges and a frosty rim), shedding mist and chips.// Impact = Frost Nova: shard debris, a ring of 8 ice spikes, a frost splat of potential 1.8 whose// front crawls out as fern fingers (wet ground freezes to a sheet), a nova shock + hoarfrost// ring, cold mist, frozen dummies. The field then melts the frost into wet; mist lingers on it.// Ice Wall: a frost line races along the floor and a curved, staggered row of large ice spikes// erupts across the caster -> target line (the spikes are occluders, so particles stop at it).
s seed
s s
rand seed
pos ga gb edge
e1 e2 ab
pos
area2 e1 e2
h area2 ab area2 ab area2 ab
off f0 f1 f2
v v v
edgev h off v h off v h off
gacr cr cr cr
gbcr cr cr cr
s axis
u axis s
tw
rings
t tw k rr r
baseaxis hhs t rru t rr
cr base axis tip start
last
i i last i
a i b i ringA i ringB i last
k k k
j k
ak aj bj cr ringA
ak bj bk cr ringB
apex baseaxis tip
k k k lastk lastk apex cr
back k k k base k k cr
i i i
phi i radial phi phi
fwd i
axis radialfwd fwd
base radial
w fwd
base axis w w w
g
g pos
g ga
g gb
g edge
g
g
t x a b a t t t
fx
mist
trailMist
novaMist
lineMist
mote
glint
lineGlint
shard
chip
tint glowCol lightCol white
absorb inscat glowV look
fx
p
tintp glowColp
k p
absorbtint tint tint k
inscattint tint tint tint tint tint
glowVglowCol glowCol glowCol
lookp p p p
absorb
p p p p
glowV
lightColglowColwhite
geo
shards
i i i
m geo
look
absorb inscat glowV
m
m
fxm
shardsm
m shards m m m
m m m
st
_a _b _d _perp
_q _q2 _m4
glowCol
x z radius frost pattern seed
x2 z2 width lobe
fx
pos
r0 r1 dur thick dist
intensity ground
fx
pos dir
height radius delay rise life
crumble seed
fx
outperp sdirH curve s s
mpos
_q dir
_q2 spin
m_q _q2
msize
m_m4m
m size
p d stc
name
d
d d d c
d fx
d d d dlightCol d
d d d d c
name
fx
c
_acc p
glint_a glint glint p
mist_a mist mist p mist p
d d
d fx
t d
t t p t t t t t tlightCol
mistc mistc mist p mist p
name
c
dc c c c
d
d
wd
dc cd wd
cc cd
dc
cc p
name
d d
d d
c c p d c p d
name
d d
d d
d d
d stc
c
dc
step dt rem _dd c
rem step cd d
cd step
cc dt
c c dt
past _dc cc
c c past c c
past c c cc
p d stc d m d
c
k c c grow k
d dt
_acc p
m m _a c d p m grow m k
_bcc p
mist_b mist mist p mist p dt
mote_b mote mote p dt
_b k c
c
c
d d p c c c
lineMistd lineMistc lineMist lineMist lineMist p dt
glintc glint glint p dt
c
d dt
_dc
m m c _d d p m m dt m
_ac_d p
d_a
trailMist_a trailMistc trailMist p trailMist p dt
chip_a chipc chip p dt
glint_a glintc glint p dt
c
d dt
g d
dt
c c
c
d lineMistd lineMistd lineMist lineMist lineMist p d dt
d d d g g p p c g g p
d mistg mist mist mist p d dt
g dc c s p rnd fx
n p a0
i i n i
ang a0 i n r s
_ag ang r g ang r
_bang ang
_a _b s s c i
shardc shard shard p shard p
glintc glint glint p
novaMistg novaMist s novaMist s novaMist p
mistc mist mist s mist p
g g s p c
_ag s
c s
fx g s glowCol
d d d s dcc
fx
fx
fx fx fx
s
i i fx i
dm fxi dist dm g dm g
i c dist
dm dm i c dist
dm_ddm g dist
d dirH d rnd fx
n p half p
c c
_perpdirH dirH
_perp dirH half p d _perp dirH half p d
i i n i
u n i n s u half e u back i
_perp dirH s p _adirH back
h p e e back
_bdirH _perp u
_a _b h h e c i
i _a _a p c i
lineMistd lineMistd lineMistdirH lineMist lineMist p
lineGlintd lineGlintd lineGlint lineGlint p
shard shard shard p shard p
_a
fx half glowCol
d d d d
fx
fx fx
dm fx
_ddm
along _d_perp across _ddirH
along half across p along along dm dm
`
in vec4 aGrowA; // crystal base (local), crystal length
in vec4 aGrowB; // crystal axis (local), growth start 0..1
in vec3 aEdge; // distance to the triangle's 3 edges (local units), +8 on edges that aren't crystal edges
uniform vec4 uShard; // growth 0..1, front glow, seed, inner glow
out vec3 vWorld;
out vec3 vLocal; // deformed (grown) local position
out vec3 vRest; // undeformed: interior noise and frost live here, so they don't swim while growing
out vec3 vEdge;
out float vFront; // local units below this crystal's growth front (0 on the forming cap)
void main() {
vec3 p = position;
float g = clamp((uShard.x - aGrowB.w) / max(1.0 - aGrowB.w, 1e-3), 0.0, 1.0);
// vertices past the front are clamped onto it: the tip triangles fold into a flat cap
float h = dot(p - aGrowA.xyz, aGrowB.xyz), hmax = g * aGrowA.w;
p -= aGrowB.xyz * max(h - hmax, 0.0);
vec3 rad = p - aGrowA.xyz - aGrowB.xyz * min(h, hmax);
p -= rad * (1.0 - mix(0.3, 1.0, sqrt(g))); // thin while young
vFront = hmax - min(h, hmax);
vLocal = p; vRest = position; vEdge = aEdge;
vec4 wp = modelMatrix * vec4(p, 1.0);
vWorld = wp.xyz;
gl_Position = projectionMatrix * viewMatrix * wp;
}`
;
const
SHARD_FRAG
=
COMMON_GLSL
+
NOISE_GLSL
+
WORLD_GLSL
+
LIGHTS_GLSL
+
REFRACT_GLSL
+
/* glsl */
`
uniform vec3 uSunDir;
uniform vec3 uSunColor;
uniform vec3 uAmbient;
uniform vec4 uShard; // growth 0..1, front glow, seed, inner glow
uniform vec4 uLook; // ior, frost, interior, glints
uniform vec4 uLook2; // lens, metres per local unit, rim frost, -
uniform vec3 uAbsorb; // Beer-Lambert sigma per metre
uniform vec3 uInscat; // in-scatter colour of the body
uniform vec3 uGlow; // growth-front / core emission (linear HDR)
uniform mat3 uToLocal; // world -> shard rotation
in vec3 vWorld;
in vec3 vLocal;
in vec3 vRest;
in vec3 vEdge;
in float vFront;
out vec4 fragColor;
// exit distance from o (on or inside) along d through an axis-aligned ellipsoid (centre c, semi-axes ax)
float ellipsoidExit(vec3 o, vec3 d, vec3 c, vec3 ax) {
vec3 oo = (o - c) / ax, dd = d / ax;
float a = dot(dd, dd), b = dot(oo, dd), cc = dot(oo, oo) - 1.0;
return max((-b + sqrt(max(b * b - a * cc, 0.0))) / a, 0.0);
}
void main() {
vec3 N = normalize(cross(dFdx(vWorld), dFdy(vWorld))); // flat facets
vec3 V = normalize(cameraPosition - vWorld);
if (dot(N, V) < 0.0) N = -N;
float NoV = max(dot(N, V), 1e-3);
float ior = uLook.x, S = uLook2.y, g = clamp(uShard.x, 0.05, 1.0), seed = uShard.z;
// --- through the body: analytic convex thickness of the main crystal's ellipsoid (grown with it)
vec3 R = refract(-V, N, 1.0 / ior);
vec3 ld = uToLocal * R;
float sg = mix(0.3, 1.0, sqrt(g));
float tL = max(ellipsoidExit(vLocal, ld, vec3(0.0, 0.0, -1.0 + 0.5 * g), vec3(0.1 * sg, 0.1 * sg, 0.5 * g)), 0.03);
float thick = tL * S;
float behind;
vec3 bg = sceneRefract(vWorld, N, V, ior, thick * uLook2.x, behind);
vec3 Tr = beerLambert(uAbsorb, thick);
// --- light: spell lights (GGX on the flat facet), sun, sky
vec3 sd, ss;
gLightNoShadow = true;
spellLightPBR(vWorld, N, V, 0.03, vec3(0.018), vec3(1.0), sd, ss);
float NoL = max(dot(N, uSunDir), 0.0);
vec3 H = normalize(uSunDir + V);
float sunSpec = spellD_GGX(max(dot(N, H), 0.0), 0.0009) * spellV_Smith(NoV, NoL, 0.0009) * NoL * PI;
vec3 irr = uAmbient + uSunColor * NoL + sd;
vec3 irrOmni = uAmbient + uSunColor * 0.5 + sd;
// --- fake interior: 3 taps along the refracted ray read as bubbles, veils and cracks
float scat = 0.0;
for (int i = 1; i <= 3; i++) {
float f = float(i) * 0.25;
vec3 q = (vRest + ld * tL * f) * S + seed;
vec4 n = noise3v(q * 1.1); // veils (fbm) and cracks (worley iso-sheets)
float b = noise3v(q * 4.5 + 0.37).a; // bubbles: small worley cells
float veil = smoothstep(0.62, 0.9, n.r) * 0.25;
float bubble = smoothstep(0.9, 0.97, b) * 2.2;
float crack = smoothstep(0.025, 0.0, abs(n.g - 0.55)) * smoothstep(0.35, 0.6, n.r) * 1.6;
scat += (veil + bubble + crack) * exp(-uAbsorb.g * thick * f);
}
scat *= uLook.z / 3.0;
// --- frost coat: rime on the crystal edges, a rough white rim at grazing angles, a frosted tail
vec3 fp = vRest * S;
vec4 fe = noise3v(fp * 2.6 + seed * 1.7);
float ed = min(min(vEdge.x, vEdge.y), vEdge.z) * S;
float ew = 0.014 * (0.25 + 1.75 * fe.r * fe.r);
float frost = smoothstep(ew, ew * 0.1, ed - (fe.g - 0.5) * 0.008);
frost = max(frost, pow(1.0 - NoV, 2.5) * smoothstep(0.35, 0.75, fe.b + 0.15) * uLook2.z);
frost = max(frost, smoothstep(-0.6, -0.95, vRest.z + (fe.a - 0.5) * 0.25) * 0.9);
frost = clamp(frost * uLook.y, 0.0, 1.0);
// --- compose: transmitted scene + cyan in-scatter + interior, Fresnel sky + highlights, frost
float F = fresnel(NoV, 0.018);
vec3 refl = envReflect(reflect(-V, N), 0.03);
// in-scatter keeps its own (cyan) colour: weighting it per channel by 1 - Tr would leave only green
vec3 body = bg * Tr + uInscat * irrOmni * 0.5 * (1.0 - dot(Tr, vec3(0.3333))) + vec3(0.8, 0.92, 1.0) * irrOmni * scat * 0.25;
vec3 col = body * (1.0 - F) + (refl * F + ss + uSunColor * F * sunSpec) * (1.0 - frost * 0.8);
col = mix(col, vec3(0.85, 0.93, 1.0) * irr, frost * 0.85);
// glints: random micro-facets whose hash changes with the view, twinkling; faded when sub-pixel
vec3 gq = fp * 42.0;
vec3 gh = hash33(floor(gq) + floor(V * 5.0) * 17.0 + seed);
float tw = pow(0.5 + 0.5 * sin(uTime * 7.0 + gh.y * 60.0), 6.0);
float spot = smoothstep(0.35, 0.0, length(fract(gq) - 0.5 - (gh - 0.5) * 0.4));
float glint = step(0.9, gh.x) * spot * tw * smoothstep(1.2, 0.4, length(fwidth(gq))) * (0.35 + frost);
col += glint * (irr * 6.0 + ss * 0.5) * uLook.w;
// growth front: the forming cap and a band under it glow; a faint cold core in flight
float band = exp(-vFront * 45.0) * uShard.y;
col += uGlow * (band * 5.0 + uShard.w * (0.35 * scat + 0.6 * pow(1.0 - NoV, 3.0) + 0.04));
fragColor = vec4(col, 1.0);
}`
;
function
lcg
(
seed
)
{
let
=
(
>>>
0
)
||
1
;
return
(
)
=>
(
(
=
(
Math
.
imul
(
,
1664525
)
+
1013904223
)
>>>
0
)
/
4294967296
)
;
}
// Glacial spike: a main hexagonal crystal along +z (back point z = -1, tip exactly at the origin,
// so the mesh position is the tip) and 7 small crystals sprouting off its back half. Non-indexed;
// per vertex the crystal's growth axis and the distance to each crystal edge (quad diagonals
// don't count). ~190 triangles.
function
shardGeometry
(
seed
)
{
const
=
lcg
(
)
;
const
=
[
]
,
=
[
]
,
=
[
]
,
=
[
]
;
const
=
new
THREE.Vector3
(
)
,
=
new
THREE.Vector3
(
)
,
=
new
THREE.Vector3
(
)
;
function
tri
(
A,B,C, cr, f0, f1, f2
)
{
// fk: the edge opposite vertex k is a crystal edge
.
push
(
A
.
x
,
A
.
y
,
A
.
z
,
B
.
x
,
B
.
y
,
B
.
z
,
C
.
x
,
C
.
y
,
C
.
z
)
;
const
=
.
subVectors
(
B
,
A
)
.
cross
(
.
subVectors
(
C
,
A
)
)
.
length
(
)
;
const
=
[
/
Math
.
max
(
.
subVectors
(
B
,
C
)
.
length
(
)
,
1e-6
)
,
/
Math
.
max
(
.
subVectors
(
A
,
C
)
.
length
(
)
,
1e-6
)
,
/
Math
.
max
(
.
subVectors
(
A
,
B
)
.
length
(
)
,
1e-6
)
]
;
const
=
[
?
0
:
8
,
?
0
:
8
,
?
0
:
8
]
;
for
(
let
=
0
;
<
3
;
++
)
{
.
push
(
(
===
0
?
[
0
]
:
0
)
+
[
0
]
,
(
===
1
?
[
1
]
:
0
)
+
[
1
]
,
(
===
2
?
[
2
]
:
0
)
+
[
2
]
)
;
.
push
(
.
base
.
x
,
.
base
.
y
,
.
base
.
z
,
.
len
)
;
.
push
(
.
axis
.
x
,
.
axis
.
y
,
.
axis
.
z
,
.
start
)
;
}
}
// rings: [height along the axis, radius]; back: close the base with a point (main crystal)
function
crystal
(
base, axis, rings, tip, start, back
)
{
const
=
new
THREE.Vector3
(
rand
(
)
-
0.5
,
rand
(
)
-
0.5
,
rand
(
)
-
0.5
)
.
cross
(
)
.
normalize
(
)
;
const
=
new
THREE.Vector3
(
)
.
crossVectors
(
,
)
;
const
=
rand
(
)
*
Math
.
PI
*
2
;
const
R
=
.
map
(
(
[hh, r]
)
=>
Array
.
from
(
{
length
:
6
}
,
(
_, k
)
=>
{
const
=
+
*
Math
.
PI
/
3
+
(
rand
(
)
-
0.5
)
*
0.1
,
=
*
(
0.92
+
rand
(
)
*
0.16
)
;
return
.
clone
(
)
.
addScaledVector
(
,
)
.
addScaledVector
(
,
Math
.
cos
(
)
*
)
.
addScaledVector
(
,
Math
.
sin
(
)
*
)
;
}
)
)
;
const
=
{
,
,
len
:
,
}
;
const
=
R
.
length
-
1
;
for
(
let
=
0
;
<
;
++
)
{
const
=
R
[
]
,
=
R
[
+
1
]
,
=
===
0
,
=
+
1
===
;
for
(
let
=
0
;
<
6
;
++
)
{
const
=
(
+
1
)
%
6
;
tri
(
[
]
,
[
]
,
[
]
,
,
true
,
false
,
)
;
tri
(
[
]
,
[
]
,
[
]
,
,
,
true
,
false
)
;
}
}
const
=
.
clone
(
)
.
addScaledVector
(
,
)
;
for
(
let
=
0
;
<
6
;
++
)
tri
(
R
[
]
[
]
,
R
[
]
[
(
+
1
)
%
6
]
,
,
,
true
,
true
,
true
)
;
if
(
)
for
(
let
=
0
;
<
6
;
++
)
tri
(
,
R
[
0
]
[
(
+
1
)
%
6
]
,
R
[
0
]
[
]
,
,
true
,
true
,
true
)
;
}
const
Z
=
new
THREE.Vector3
(
0
,
0
,
1
)
;
crystal
(
new
THREE.Vector3
(
0
,
0
,
-
1
)
,
Z
,
[
[
0.1
,
0.06
]
,
[
0.28
,
0.095
]
,
[
0.48
,
0.1
]
,
[
0.66
,
0.085
]
,
[
0.8
,
0.06
]
]
,
1
,
0
,
true
)
;
for
(
let
=
0
;
<
7
;
++
)
{
const
=
(
/
7
)
*
Math
.
PI
*
2
+
rand
(
)
*
0.6
,
=
new
THREE.Vector3
(
Math
.
cos
(
)
,
Math
.
sin
(
)
,
0
)
;
const
=
%
3
===
2
;
// a few lie along the body, the rest flare backwards
const
=
.
clone
(
)
.
multiplyScalar
(
?
0.4
:
0.8
)
.
add
(
new
THREE.Vector3
(
0
,
0
,
?
0.9
:
-
0.35
-
rand
(
)
*
0.4
)
)
.
normalize
(
)
;
const
=
.
clone
(
)
.
multiplyScalar
(
0.04
)
.
setZ
(
-
0.92
+
rand
(
)
*
0.38
)
;
const
=
0.022
+
rand
(
)
*
0.024
,
L
=
(
?
0.22
:
0.1
)
+
rand
(
)
*
0.12
;
crystal
(
,
,
[
[
0
,
*
1.1
]
,
[
L
,
]
]
,
L
+
*
(
1.3
+
rand
(
)
*
0.9
)
,
0.3
+
rand
(
)
*
0.4
,
false
)
;
}
const
=
new
THREE.BufferGeometry
(
)
;
.
setAttribute
(
'position'
,
new
THREE.Float32BufferAttribute
(
,
3
)
)
;
.
setAttribute
(
'aGrowA'
,
new
THREE.Float32BufferAttribute
(
,
4
)
)
;
.
setAttribute
(
'aGrowB'
,
new
THREE.Float32BufferAttribute
(
,
4
)
)
;
.
setAttribute
(
'aEdge'
,
new
THREE.Float32BufferAttribute
(
,
3
)
)
;
.
computeBoundingSphere
(
)
;
return
;
}
const
MAX_SHARDS
=
3
;
const
ZAXIS
=
new
THREE.Vector3
(
0
,
0
,
1
)
;
const
smooth
=
(
a, b, x
)
=>
{
const
=
Math
.
min
(
1
,
Math
.
max
(
0
,
(
-
)
/
(
-
)
)
)
;
return
*
*
(
3
-
2
*
)
;
}
;
export
default
{
id
:
'ice'
,
name
:
'Ice'
,
key
:
'4'
,
hue
:
'#9ff0ff'
,
shape
:
'projectile'
,
forms
:
[
'Glacial Spike'
,
'Ice Wall'
]
,
radius
:
0.12
,
params
:
{
size
:
1
,
speed
:
24
,
ior
:
1.31
,
clarity
:
1
,
frost
:
1
,
interior
:
1
,
glints
:
1
,
mist
:
1
,
motes
:
1
,
shards
:
1
,
nova
:
1
,
spikes
:
8
,
wallSpikes
:
11
,
wallHeight
:
3
,
wallWidth
:
7.5
,
wallCurve
:
1
,
tint
:
'#a8dcff'
,
glow
:
'#5fd0ff'
,
}
,
ranges
:
{
size
:
[
0.4
,
2.5
,
0.01
]
,
speed
:
[
6
,
50
,
0.1
]
,
ior
:
[
1
,
2.4
,
0.01
]
,
clarity
:
[
0.2
,
4
,
0.01
]
,
frost
:
[
0
,
2
,
0.01
]
,
interior
:
[
0
,
3
,
0.01
]
,
glints
:
[
0
,
3
,
0.01
]
,
mist
:
[
0
,
3
,
0.01
]
,
motes
:
[
0
,
3
,
0.01
]
,
shards
:
[
0
,
3
,
0.01
]
,
nova
:
[
0.4
,
2
,
0.01
]
,
spikes
:
[
0
,
8
,
1
]
,
wallSpikes
:
[
3
,
15
,
1
]
,
wallHeight
:
[
1
,
4.5
,
0.01
]
,
wallWidth
:
[
3
,
12
,
0.1
]
,
wallCurve
:
[
-
1
,
2
,
0.01
]
,
}
,
presets
:
{
glacier
:
{
tint
:
'#3fa6ff'
,
clarity
:
1.8
,
glow
:
'#3f86ff'
,
frost
:
0.7
}
,
rime
:
{
tint
:
'#d2f2ff'
,
clarity
:
0.6
,
frost
:
1.8
,
interior
:
1.8
,
mist
:
1.7
,
glow
:
'#bfefff'
}
,
'black ice'
:
{
tint
:
'#2f7d8f'
,
clarity
:
3
,
glints
:
2.2
,
frost
:
0.4
,
mist
:
0.6
,
glow
:
'#6ff6ff'
}
,
}
,
timing
:
{
charge
:
0.8
,
impact
:
0.3
,
linger
:
6.5
}
,
kinds
:
{
// sinking cold mist: negative buoyancy, slides along the floor (restitution 0, no friction)
mist
:
{
style
:
'media'
,
drag
:
1.8
,
buoyancy
:
-
0.9
,
curl
:
0.5
,
curlScale
:
0.22
,
restitution
:
0
,
friction
:
0.02
,
life
:
[
1.6
,
2.8
]
,
size
:
[
0.3
,
1.2
]
,
sizePow
:
0.6
,
color
:
[
'#e2f5ff'
,
'#bcd9ec'
]
,
alpha
:
[
0.05
,
0
]
,
density
:
1.1
,
erosion
:
0.6
,
fadeIn
:
0.2
,
fadeOut
:
0.45
,
forceResponse
:
0.5
,
lightResponse
:
1.6
}
,
groundmist
:
{
style
:
'media'
,
drag
:
2.2
,
buoyancy
:
-
0.12
,
curl
:
0.45
,
curlScale
:
0.2
,
life
:
[
2
,
3.6
]
,
size
:
[
0.6
,
1.9
]
,
color
:
[
'#e8f7ff'
,
'#c4dfef'
]
,
alpha
:
[
0.025
,
0
]
,
density
:
0.9
,
erosion
:
0.55
,
fadeIn
:
0.35
,
fadeOut
:
0.45
,
forceResponse
:
0.8
,
lightResponse
:
1.4
}
,
mote
:
{
style
:
'glow'
,
drag
:
0.25
,
curl
:
0.8
,
curlScale
:
0.5
,
life
:
[
0.5
,
0.75
]
,
size
:
[
0.012
,
0.006
]
,
stretch
:
0.008
,
emissive
:
9
,
color
:
[
'#ffffff'
,
'#8fe6ff'
]
,
alpha
:
[
0.25
,
1
]
,
fadeIn
:
0.35
,
fadeOut
:
0.12
,
forceResponse
:
0
}
,
glint
:
{
style
:
'glow'
,
drag
:
0.6
,
gravity
:
6.5
,
restitution
:
0.3
,
friction
:
0.45
,
life
:
[
0.6
,
1.6
]
,
size
:
[
0.02
,
0.006
]
,
stretch
:
0.02
,
emissive
:
7
,
color
:
[
'#ffffff'
,
'#86ddff'
]
,
alpha
:
[
1
,
0
]
}
,
shard
:
{
style
:
'debris'
,
mesh
:
'shard'
,
drag
:
0.25
,
gravity
:
9.8
,
restitution
:
0.3
,
friction
:
0.55
,
life
:
[
3.2
,
5.5
]
,
size
:
[
0.3
,
0.1
]
,
sizePow
:
1.6
,
spin
:
9
,
color
:
[
'#e6f8ff'
,
'#1d5f86'
]
,
alpha
:
[
1
,
0.04
]
,
fadeOut
:
0.25
}
,
chip
:
{
style
:
'debris'
,
mesh
:
'shard'
,
drag
:
0.4
,
gravity
:
9.8
,
restitution
:
0.25
,
friction
:
0.5
,
life
:
[
0.8
,
1.6
]
,
size
:
[
0.09
,
0.03
]
,
spin
:
14
,
color
:
[
'#e6f8ff'
,
'#1d5f86'
]
,
alpha
:
[
1
,
0.04
]
,
fadeOut
:
0.3
}
,
}
,
create
(
fx
)
{
const
S
=
this
,
P
=
.
particles
;
const
=
P
.
emitter
(
'ice.mist'
,
{
shape
:
'sphere'
,
radius
:
0.25
,
spread
:
0.25
}
)
;
const
=
P
.
emitter
(
'ice.mist'
,
{
shape
:
'sphere'
,
radius
:
0.1
,
spread
:
0.35
}
)
;
const
=
P
.
emitter
(
'ice.mist'
,
{
shape
:
'ring'
,
radius
:
0.7
,
spread
:
0.35
,
radial
:
2.4
}
)
;
const
=
P
.
emitter
(
'ice.mist'
,
{
shape
:
'line'
,
radius
:
0.35
,
spread
:
0.6
}
)
;
const
=
P
.
emitter
(
'ice.mote'
,
{
shape
:
'shell'
,
radius
:
1.3
,
spread
:
0.1
,
radial
:
-
2.2
}
)
;
const
=
P
.
emitter
(
'ice.glint'
,
{
shape
:
'sphere'
,
radius
:
0.25
,
spread
:
4.5
,
radial
:
3
}
)
;
const
=
P
.
emitter
(
'ice.glint'
,
{
shape
:
'line'
,
radius
:
0.3
,
spread
:
2.5
}
)
;
const
=
P
.
emitter
(
'ice.shard'
,
{
shape
:
'sphere'
,
radius
:
0.25
,
spread
:
2
,
radial
:
4
}
)
;
const
=
P
.
emitter
(
'ice.chip'
,
{
shape
:
'sphere'
,
radius
:
0.05
,
spread
:
1.4
}
)
;
// GPU-driven: frost on the floor breathes mist until it melts (also frost left by combos)
P
.
fieldEmitter
(
'ice.groundmist'
,
{
slots
:
768
,
a
:
[
0
,
0
,
0
,
1
]
,
threshold
:
0.3
,
rate
:
6
,
up
:
0.15
}
)
;
// --- look, shared by every shard (and pushed to the ice spikes) ---
const
=
new
THREE.Color
(
)
,
=
new
THREE.Color
(
)
,
=
new
THREE.Color
(
)
,
=
new
THREE.Color
(
1
,
1
,
1
)
;
const
=
new
THREE.Vector3
(
)
,
=
new
THREE.Vector3
(
)
,
=
new
THREE.Vector3
(
)
,
=
new
THREE.Vector4
(
)
;
const
SP
=
.
spikes
.
uniforms
;
function
applyLook
(
)
{
const
=
S
.
params
;
.
set
(
.
tint
)
;
.
set
(
.
glow
)
;
const
=
6
*
.
clarity
;
// tint = transmittance through ~17 cm of shard
.
set
(
-
Math
.
log
(
Math
.
max
(
.
r
,
0.01
)
)
,
-
Math
.
log
(
Math
.
max
(
.
g
,
0.01
)
)
,
-
Math
.
log
(
Math
.
max
(
.
b
,
0.01
)
)
)
.
multiplyScalar
(
)
;
.
set
(
.
r
*
.
r
,
.
g
*
.
g
,
.
b
*
.
b
)
.
multiplyScalar
(
0.6
)
;
.
set
(
.
r
,
.
g
,
.
b
)
.
multiplyScalar
(
3
)
;
.
set
(
.
ior
,
.
frost
,
.
interior
,
.
glints
)
;
SP
.
uIceAbsorb
.
value
.
copy
(
)
.
multiplyScalar
(
0.35
)
;
// spikes: a much thicker body
SP
.
uIceLook
.
value
.
set
(
.
ior
,
.
frost
,
.
interior
,
.
glints
)
;
SP
.
uIceGlow
.
value
.
copy
(
)
.
multiplyScalar
(
0.87
)
;
.
copy
(
)
.
lerp
(
,
0.35
)
;
}
applyLook
(
)
;
// --- shard meshes: one program (identical source), per-mesh uniforms ---
const
=
shardGeometry
(
4242
)
;
const
=
[
]
;
for
(
let
=
0
;
<
MAX_SHARDS
;
++
)
{
const
=
new
THREE.Mesh
(
,
new
THREE.ShaderMaterial
(
{
glslVersion
:
THREE
.
GLSL3
,
vertexShader
:
SHARD_VERT
,
fragmentShader
:
SHARD_FRAG
,
uniforms
:
{
...
U
,
uShard
:
{
value
:
new
THREE.Vector4
(
)
}
,
uLook
:
{
value
:
}
,
uLook2
:
{
value
:
new
THREE.Vector4
(
3
,
1
,
1
,
0
)
}
,
uAbsorb
:
{
value
:
}
,
uInscat
:
{
value
:
}
,
uGlow
:
{
value
:
}
,
uToLocal
:
{
value
:
new
THREE.Matrix3
(
)
}
,
}
,
}
)
)
;
.
visible
=
false
;
.
userData
.
free
=
true
;
.
scenes
.
refract
.
add
(
)
;
.
push
(
)
;
}
const
takeShard
=
(
)
=>
{
for
(
const
of
)
if
(
.
userData
.
free
)
{
.
userData
.
free
=
false
;
return
;
}
return
null
;
}
;
const
dropShard
=
(
m
)
=>
{
if
(
)
{
.
visible
=
false
;
.
userData
.
free
=
true
;
}
}
;
// per-cast state by cast index (the cast pool is 16): nothing allocated per cast
const
=
Array
.
from
(
{
length
:
16
}
,
(
)
=>
(
{
shard
:
null
,
light
:
null
,
trail
:
null
,
spin
:
0
,
boom
:
0
,
ring
:
false
,
ground
:
new
THREE.Vector3
(
)
,
last
:
new
THREE.Vector3
(
)
,
wallC
:
new
THREE.Vector3
(
)
,
wallA
:
new
THREE.Vector3
(
)
,
wallB
:
new
THREE.Vector3
(
)
,
dirH
:
new
THREE.Vector3
(
)
,
}
)
)
;
const
=
new
THREE.Vector3
(
)
,
=
new
THREE.Vector3
(
)
,
=
new
THREE.Vector3
(
)
,
=
new
THREE.Vector3
(
)
;
const
=
new
THREE.Quaternion
(
)
,
=
new
THREE.Quaternion
(
)
,
=
new
THREE.Matrix4
(
)
;
// reused option objects (every field set on every call)