@threenative/core 0.3.11 → 0.3.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/README.md +1 -1
- package/capabilities.json +1988 -204
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/chunk-4SRAQFTU.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DIPIJICH.js +8916 -0
- package/dist/chunk-EEABDLUC.js +2237 -0
- package/dist/chunk-EFWZWLPY.js +1895 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-GYUZJQ7U.js +280 -0
- package/dist/chunk-H4J6IAJE.js +504 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-SV4QVUTQ.js +31 -0
- package/dist/chunk-U4YHUKKL.js +615 -0
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/chunk-XDTZ4QMO.js +160 -0
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -52
- package/dist/index.d.ts +633 -1351
- package/dist/index.js +12873 -23068
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +25 -75
- package/dist/quality-BYqKGAwo.d.ts +868 -0
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +3 -2
- package/dist/render-environment.d.ts +170 -0
- package/dist/render-environment.js +352 -0
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
- package/dist/spells/index.d.ts +643 -0
- package/dist/spells/index.js +1558 -0
- package/dist/spells/ultra/index.d.ts +1600 -0
- package/dist/spells/ultra/index.js +6804 -0
- package/dist/terrain-jobs-worker.js +1 -123
- package/dist/two-sided-foliage-W523J3UM.js +1 -0
- package/dist/ui-layer.js +6 -384
- package/dist/worker.js +13 -43
- package/dist/world.d.ts +988 -268
- package/dist/world.js +17464 -18290
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +245 -52
- package/mcp/servers.mjs +10 -3
- package/mcp/terrain.mjs +8 -0
- package/package.json +19 -7
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/animation-batch.ts +193 -0
- package/src/animation-layers.ts +7 -3
- package/src/animation.ts +209 -29
- package/src/asset-cache.ts +3 -3
- package/src/asset-memo.ts +202 -0
- package/src/assets.ts +437 -125
- package/src/auto-batch.ts +190 -44
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +103 -22
- package/src/dev-global.ts +54 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +50 -23
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +86 -0
- package/src/game-frame-loop.ts +958 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1076 -0
- package/src/game-ui.ts +84 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +198 -2264
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +13 -0
- package/src/geometry-capture.ts +28 -4
- package/src/gpu-readings.ts +98 -0
- package/src/gpu-scene-bvh.ts +149 -36
- package/src/hot.ts +4 -7
- package/src/index.ts +141 -9
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +25 -0
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/local-exposure.ts +2 -7
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +14 -5
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +113 -103
- package/src/loop.ts +29 -0
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +139 -17
- package/src/particle-kinds.ts +515 -0
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/picking.ts +17 -3
- package/src/platform.ts +23 -4
- package/src/playtest.ts +27 -1
- package/src/profiling/FrameStages.ts +5 -6
- package/src/profiling/Spans.ts +3 -17
- package/src/profiling/debug-telemetry.ts +2 -6
- package/src/profiling/render-list-validate.ts +6 -15
- package/src/projection-apply.ts +4 -1
- package/src/projection-marker.ts +2 -1
- package/src/projection-plan.ts +9 -6
- package/src/quiet-markers.ts +3 -10
- package/src/render/cpu-bvh.ts +100 -0
- package/src/render/depth-pyramid.ts +6 -14
- package/src/render/environment/environmentContribution.ts +202 -0
- package/src/render/environment/environmentRadiance.ts +44 -0
- package/src/render/environment/environmentSampleCache.ts +56 -0
- package/src/render/environment/environmentSampling.ts +201 -0
- package/src/render/environment/environmentSnapshot.ts +71 -0
- package/src/render/environment/gate.ts +57 -0
- package/src/render/mesh-pool.ts +4 -20
- package/src/render/probe-trace.ts +872 -0
- package/src/render/probe-volume.ts +780 -34
- package/src/render/radiance-cache.ts +17 -0
- package/src/render/resolution-subrect.ts +2 -0
- package/src/render/rough-diffuse.ts +46 -12
- package/src/render/soft-shadow.ts +27 -12
- package/src/render/virtual-shadow-adaptive.ts +55 -0
- package/src/render/virtual-shadow-casters.ts +175 -0
- package/src/render/virtual-shadow-layers.ts +76 -0
- package/src/render/virtual-shadow-level.ts +224 -0
- package/src/render/virtual-shadow-markers.ts +193 -0
- package/src/render/virtual-shadow-options.ts +370 -0
- package/src/render/virtual-shadow-pages.ts +5 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +231 -1008
- package/src/render/world-impostor-surface.ts +402 -40
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +98 -3
- package/src/render-environment.ts +41 -0
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +144 -65
- package/src/resolution-scaler.ts +3 -2
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +2 -1
- package/src/spells/cast-pool.ts +361 -0
- package/src/spells/index.ts +177 -0
- package/src/spells/mechanisms.ts +295 -0
- package/src/spells/reaction-field.ts +415 -0
- package/src/spells/spell-lights.ts +139 -0
- package/src/spells/spell-world.ts +187 -0
- package/src/spells/spell.ts +397 -0
- package/src/spells/spells.ts +283 -0
- package/src/spells/ultra/engine/camera.ts +184 -0
- package/src/spells/ultra/engine/quality.ts +96 -0
- package/src/spells/ultra/index.ts +52 -0
- package/src/spells/ultra/main.ts +305 -0
- package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
- package/src/spells/ultra/spells/cast.ts +233 -0
- package/src/spells/ultra/spells/fire.ts +1267 -0
- package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
- package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
- package/src/spells/ultra/vfx/FxTarget.ts +61 -0
- package/src/spells/ultra/vfx/GroundField.ts +1399 -0
- package/src/spells/ultra/vfx/Particles.ts +1475 -0
- package/src/spells/ultra/vfx/Ribbons.ts +645 -0
- package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
- package/src/spells/ultra/vfx/Volumes.ts +489 -0
- package/src/spells/ultra/vfx/common.ts +1195 -0
- package/src/spells/ultra/vfx/noise.ts +441 -0
- package/src/startup-offscreen-bytes.ts +78 -0
- package/src/startup-readiness.ts +128 -34
- package/src/static-transform.ts +25 -19
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +446 -0
- package/src/world-cell-batches.ts +1178 -0
- package/src/world-cell-chunks.ts +1128 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1461 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +177 -0
- package/src/world-cell-placements.ts +798 -0
- package/src/world-cell-prewarm.ts +592 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +710 -0
- package/src/world-cell-render-main-cull.ts +540 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +259 -0
- package/src/world-cell-render.ts +1501 -0
- package/src/world-cell-residency.ts +754 -0
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +1335 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +131 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +524 -0
- package/src/world-gpu-scene.ts +256 -2286
- package/src/world-gpu-shadow.ts +203 -0
- package/src/world-gpu-types.ts +409 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +111 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-noise.ts +241 -0
- package/src/world-package.ts +42 -0
- package/src/world-region.ts +1 -1
- package/src/world-river-ribbon.ts +282 -0
- package/src/world-root-frame.ts +39 -0
- package/src/world-shore-field.ts +91 -0
- package/src/world-static-pose.ts +163 -0
- package/src/world-surface-sampler.ts +48 -0
- package/src/world-terrain-splat.ts +361 -153
- package/src/world-tile-budget.ts +249 -0
- package/src/world-tile-geometry.ts +469 -0
- package/src/world-tile-lod.ts +408 -0
- package/src/world-tile-observation.ts +566 -0
- package/src/world-tile-stitch.ts +166 -0
- package/src/world-tiles.ts +247 -1755
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +48 -741
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// Ported from Ultra Elements src/scene/arenaMaterial.js @698b720 (MIT, Copyright (c) 2026 Humpalumps). JavaScript copied verbatim; GLSL transliterated to TSL.
|
|
2
|
+
//
|
|
3
|
+
// Only the ground-field half of the arena floor: the baked stone noise, the STATE block (impacts and
|
|
4
|
+
// the ground field) and the RESPONSES a fire spell leaves (char, wet, heat glow, holy glow). The
|
|
5
|
+
// arena's own surfaces, lighting, frost, acid, electric, corruption and crack responses are not
|
|
6
|
+
// ported: a game's floor material keeps its own surface and the engine's lighting, and takes the
|
|
7
|
+
// albedo, roughness, metalness and emission groundShade() returns.
|
|
8
|
+
import {
|
|
9
|
+
DataTexture,
|
|
10
|
+
LinearFilter,
|
|
11
|
+
LinearMipmapLinearFilter,
|
|
12
|
+
RGBAFormat,
|
|
13
|
+
RepeatWrapping,
|
|
14
|
+
} from "three";
|
|
15
|
+
import {
|
|
16
|
+
Break,
|
|
17
|
+
Fn,
|
|
18
|
+
If,
|
|
19
|
+
Loop,
|
|
20
|
+
clamp,
|
|
21
|
+
dot,
|
|
22
|
+
float,
|
|
23
|
+
fwidth,
|
|
24
|
+
int,
|
|
25
|
+
length,
|
|
26
|
+
max,
|
|
27
|
+
mix,
|
|
28
|
+
pow,
|
|
29
|
+
select,
|
|
30
|
+
smoothstep,
|
|
31
|
+
step,
|
|
32
|
+
texture,
|
|
33
|
+
vec2,
|
|
34
|
+
vec3,
|
|
35
|
+
vec4,
|
|
36
|
+
} from "three/tsl";
|
|
37
|
+
import type { Node } from "three/webgpu";
|
|
38
|
+
import {
|
|
39
|
+
MAX_IMPACTS,
|
|
40
|
+
U,
|
|
41
|
+
blackbody,
|
|
42
|
+
groundA,
|
|
43
|
+
groundB,
|
|
44
|
+
groundUV,
|
|
45
|
+
worldTexel,
|
|
46
|
+
} from "../vfx/common.js";
|
|
47
|
+
|
|
48
|
+
type F = Node<"float">;
|
|
49
|
+
type V2 = Node<"vec2">;
|
|
50
|
+
type V3 = Node<"vec3">;
|
|
51
|
+
type V4 = Node<"vec4">;
|
|
52
|
+
|
|
53
|
+
// --- baked noise: 256^2 RGBA8, tileable, mipmapped ---------------------------------------
|
|
54
|
+
// r, g: value-noise fbm (two seeds), b: voronoi F2-F1 (0 on cell edges, 12 cells per tile;
|
|
55
|
+
// cracks, veins), a: fine fbm (grain, specks). Generated once in JS (~30 ms), no assets.
|
|
56
|
+
function hashi(x: number, y: number, s: number): number {
|
|
57
|
+
let h = (Math.imul(x, 374761393) + Math.imul(y, 668265263) + Math.imul(s, 1274126177)) | 0;
|
|
58
|
+
h = Math.imul(h ^ (h >>> 13), 1274126177);
|
|
59
|
+
return ((h ^ (h >>> 16)) >>> 0) / 4294967296;
|
|
60
|
+
}
|
|
61
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
|
|
62
|
+
function bakeStoneNoise(N = 256): DataTexture {
|
|
63
|
+
const data = new Uint8Array(N * N * 4);
|
|
64
|
+
const vnoise = (x: number, y: number, P: number, s: number) => {
|
|
65
|
+
const xi = Math.floor(x);
|
|
66
|
+
const yi = Math.floor(y);
|
|
67
|
+
const fx = x - xi;
|
|
68
|
+
const fy = y - yi;
|
|
69
|
+
const ux = fx * fx * (3 - 2 * fx);
|
|
70
|
+
const uy = fy * fy * (3 - 2 * fy);
|
|
71
|
+
const x0 = ((xi % P) + P) % P;
|
|
72
|
+
const y0 = ((yi % P) + P) % P;
|
|
73
|
+
const x1 = (x0 + 1) % P;
|
|
74
|
+
const y1 = (y0 + 1) % P;
|
|
75
|
+
const a = hashi(x0, y0, s);
|
|
76
|
+
const b = hashi(x1, y0, s);
|
|
77
|
+
const c = hashi(x0, y1, s);
|
|
78
|
+
const d = hashi(x1, y1, s);
|
|
79
|
+
return a + (b - a) * ux + (c - a) * uy + (a - b - c + d) * ux * uy;
|
|
80
|
+
};
|
|
81
|
+
const fbm = (u: number, v: number, base: number, oct: number, s: number) => {
|
|
82
|
+
let sum = 0;
|
|
83
|
+
let amp = 0.5;
|
|
84
|
+
let norm = 0;
|
|
85
|
+
for (let o = 0; o < oct; o++) {
|
|
86
|
+
const f = base << o;
|
|
87
|
+
sum += amp * vnoise(u * f, v * f, f, s + o * 31);
|
|
88
|
+
norm += amp;
|
|
89
|
+
amp *= 0.5;
|
|
90
|
+
}
|
|
91
|
+
return sum / norm;
|
|
92
|
+
};
|
|
93
|
+
const C = 12;
|
|
94
|
+
const pts: number[] = [];
|
|
95
|
+
for (let j = 0; j < C; j++)
|
|
96
|
+
for (let i = 0; i < C; i++)
|
|
97
|
+
pts.push(i + 0.1 + 0.8 * hashi(i, j, 91), j + 0.1 + 0.8 * hashi(i, j, 92));
|
|
98
|
+
for (let y = 0; y < N; y++)
|
|
99
|
+
for (let x = 0; x < N; x++) {
|
|
100
|
+
const u = x / N;
|
|
101
|
+
const v = y / N;
|
|
102
|
+
const o = (y * N + x) * 4;
|
|
103
|
+
const cx = u * C;
|
|
104
|
+
const cy = v * C;
|
|
105
|
+
const ix = Math.floor(cx);
|
|
106
|
+
const iy = Math.floor(cy);
|
|
107
|
+
let f1 = 9;
|
|
108
|
+
let f2 = 9;
|
|
109
|
+
for (let dj = -1; dj <= 1; dj++)
|
|
110
|
+
for (let di = -1; di <= 1; di++) {
|
|
111
|
+
const gi = ix + di;
|
|
112
|
+
const gj = iy + dj;
|
|
113
|
+
const wi = ((gi % C) + C) % C;
|
|
114
|
+
const wj = ((gj % C) + C) % C;
|
|
115
|
+
const px = (pts[(wj * C + wi) * 2] as number) + (gi - wi);
|
|
116
|
+
const py = (pts[(wj * C + wi) * 2 + 1] as number) + (gj - wj);
|
|
117
|
+
const d = Math.hypot(px - cx, py - cy);
|
|
118
|
+
if (d < f1) {
|
|
119
|
+
f2 = f1;
|
|
120
|
+
f1 = d;
|
|
121
|
+
} else if (d < f2) f2 = d;
|
|
122
|
+
}
|
|
123
|
+
data[o] = fbm(u, v, 4, 5, 1) * 255;
|
|
124
|
+
data[o + 1] = fbm(u, v, 4, 5, 7) * 255;
|
|
125
|
+
data[o + 2] = Math.min(f2 - f1, 1) * 255;
|
|
126
|
+
data[o + 3] = fbm(u, v, 32, 2, 13) * 255;
|
|
127
|
+
}
|
|
128
|
+
const t = new DataTexture(data, N, N, RGBAFormat);
|
|
129
|
+
t.wrapS = t.wrapT = RepeatWrapping;
|
|
130
|
+
t.minFilter = LinearMipmapLinearFilter;
|
|
131
|
+
t.magFilter = LinearFilter;
|
|
132
|
+
t.generateMipmaps = true;
|
|
133
|
+
t.anisotropy = 2; // low-frequency taps: 8x bought ~0.02 ms of nothing at 3.3 MP
|
|
134
|
+
t.needsUpdate = true;
|
|
135
|
+
return t;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Shared by every arena material: the stone noise (the rest of upstream's arenaUniforms belongs to
|
|
139
|
+
// the arena's own surfaces and lighting, not ported)
|
|
140
|
+
let stoneNoise: ReturnType<typeof texture> | undefined;
|
|
141
|
+
const uStoneNoise = (uv: V2): V4 => {
|
|
142
|
+
stoneNoise ??= texture(bakeStoneNoise());
|
|
143
|
+
return stoneNoise.sample(uv) as unknown as V4;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// IMPACT_FN_GLSL: spherical impact "volume decals", weights per type at p. wa, wb, glowColor: var
|
|
147
|
+
// nodes it assigns. ENGINE-GAP: a TSL Fn cannot assign its `out` arguments (common.ts impactWeights
|
|
148
|
+
// is that Fn), so this is plain JS inlined at the call. The bit-mask prefilter (NEXT_BIT) is one loop.
|
|
149
|
+
function arenaImpacts(p: V3, wa: V4, wb: V4, glowColor: V3): void {
|
|
150
|
+
wa.assign(vec4(0.0));
|
|
151
|
+
wb.assign(vec4(0.0));
|
|
152
|
+
glowColor.assign(vec3(0.0));
|
|
153
|
+
const n = int(U.uWorldCounts.z);
|
|
154
|
+
Loop({ start: 0, end: MAX_IMPACTS, type: "int", condition: "<" }, ({ i }: { i: Node<"int"> }) => {
|
|
155
|
+
If(i.greaterThanEqual(n), () => {
|
|
156
|
+
Break();
|
|
157
|
+
});
|
|
158
|
+
const a = worldTexel(int(2), i.mul(4)) as unknown as V4;
|
|
159
|
+
const d = p.sub(a.xyz);
|
|
160
|
+
If(dot(d, d).lessThan(a.w.mul(a.w)), () => {
|
|
161
|
+
const b = worldTexel(int(2), i.mul(4).add(1)) as unknown as V4;
|
|
162
|
+
const w = b.z.mul(smoothstep(1.0, 0.55, length(d).div(a.w)));
|
|
163
|
+
const t = b.x;
|
|
164
|
+
const lane = (k: number) => select(t.equal(k), float(1.0), float(0.0));
|
|
165
|
+
wa.addAssign(vec4(lane(0), lane(1), lane(2), lane(3)).mul(w));
|
|
166
|
+
wb.addAssign(vec4(lane(4), lane(5), lane(6), lane(7)).mul(w));
|
|
167
|
+
glowColor.addAssign((worldTexel(int(2), i.mul(4).add(2)) as unknown as V4).rgb.mul(w));
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface IGroundSurface {
|
|
173
|
+
albedo: V3;
|
|
174
|
+
rough: F;
|
|
175
|
+
metal: F;
|
|
176
|
+
/** 0..1: grout, grooves, cracks the heat glows through */
|
|
177
|
+
crevice?: F;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// STATE (ARENA_FLOOR) then the char, wet, heat and holy-glow RESPONSES, at world position wp.
|
|
181
|
+
// Upstream gates RESPONSES behind "anything there?" so most pixels skip it; so does this.
|
|
182
|
+
function shade(wp: V3, s: IGroundSurface) {
|
|
183
|
+
const albedo = vec3(s.albedo).toVar();
|
|
184
|
+
const rough = float(s.rough).toVar();
|
|
185
|
+
const metal = float(s.metal).toVar();
|
|
186
|
+
const crevice = (s.crevice ?? float(0.0)).toVar();
|
|
187
|
+
const emit = vec3(0.0).toVar();
|
|
188
|
+
const sp2 = wp.xz;
|
|
189
|
+
const fwp = fwidth(wp);
|
|
190
|
+
const px = max(max(fwp.x, fwp.y), fwp.z);
|
|
191
|
+
const gHeatOpen = -1.0; // where heat glows through (>= 0 overrides crevice: the floor's grout barely glows)
|
|
192
|
+
const gVent = 0.0; // craterNear(): no crater or fissure source drawn by this floor
|
|
193
|
+
|
|
194
|
+
// STATE: impacts, mapped onto the field's channels so one set of responses serves both
|
|
195
|
+
const wa = vec4(0.0).toVar();
|
|
196
|
+
const wb = vec4(0.0).toVar();
|
|
197
|
+
const gc = vec3(0.0).toVar();
|
|
198
|
+
arenaImpacts(wp, wa, wb, gc);
|
|
199
|
+
const wsum = dot(wa, vec4(1.0)).add(dot(wb, vec4(1.0)));
|
|
200
|
+
const stGlow = gc.div(max(wsum, 1e-4)).toVar();
|
|
201
|
+
// scorch: char + a little heat while fresh; magma: heat in fresh cracks
|
|
202
|
+
const stA = vec4(wa.x.mul(wa.x).mul(0.3).add(wa.w), wa.x, wa.z, wa.y).toVar();
|
|
203
|
+
const stB = vec4(wa.w.mul(0.6), wb.x, wb.z, wb.y).toVar();
|
|
204
|
+
const stElec = wb.w;
|
|
205
|
+
const guv = groundUV(sp2);
|
|
206
|
+
const gw = guv.x
|
|
207
|
+
.greaterThan(0.0)
|
|
208
|
+
.and(guv.y.greaterThan(0.0))
|
|
209
|
+
.and(guv.x.lessThan(1.0))
|
|
210
|
+
.and(guv.y.lessThan(1.0));
|
|
211
|
+
If(gw, () => {
|
|
212
|
+
stA.assign(max(stA, groundA(sp2)));
|
|
213
|
+
stB.assign(max(stB, groundB(sp2)));
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// RESPONSES (responses to the state (a = heat, char, wet, frost; b = crack, acid, corruption,
|
|
217
|
+
// glow); at most two noise taps on top of the surface's)
|
|
218
|
+
If(
|
|
219
|
+
stA.x
|
|
220
|
+
.greaterThan(0.004)
|
|
221
|
+
.or(stA.y.greaterThan(0.004))
|
|
222
|
+
.or(stA.z.greaterThan(0.004))
|
|
223
|
+
.or(stB.y.greaterThan(0.004))
|
|
224
|
+
.or(stB.w.greaterThan(0.004))
|
|
225
|
+
.or(stElec.greaterThan(0.004)),
|
|
226
|
+
() => {
|
|
227
|
+
const nS = uStoneNoise(sp2.mul(0.11).add(0.31));
|
|
228
|
+
// char: soot, uneven
|
|
229
|
+
const ch = clamp(stA.y.mul(nS.r.mul(0.5).add(0.75)), 0.0, 1.0);
|
|
230
|
+
albedo.mulAssign(float(1.0).sub(ch.mul(0.85)));
|
|
231
|
+
rough.assign(mix(rough, 0.9, ch));
|
|
232
|
+
metal.mulAssign(float(1.0).sub(ch));
|
|
233
|
+
// wet: darker, glossy film; on the floor it pools where the noise is low
|
|
234
|
+
const wt = clamp(stA.z, 0.0, 1.0);
|
|
235
|
+
const puddle = smoothstep(0.35, 0.7, wt.mul(nS.g.mul(0.8).add(0.6))); // flat_: the floor
|
|
236
|
+
albedo.mulAssign(float(1.0).sub(wt.mul(0.4)));
|
|
237
|
+
rough.assign(mix(rough, 0.04, max(wt.mul(0.75), puddle)));
|
|
238
|
+
crevice.mulAssign(float(1.0).sub(puddle));
|
|
239
|
+
// heat: hot stone glows only where it is open (thermal cracks that open with heat, the field's
|
|
240
|
+
// own cracks, pores) through a dark char crust; grout barely. Temperature follows the field
|
|
241
|
+
// heat, radiance ~T^4 above the Draper point, so the glow dies off well inside the hot area
|
|
242
|
+
// instead of ending in a disc; the crust itself only goes dull red right at the centre.
|
|
243
|
+
const ht = clamp(stA.x, 0.0, 1.0);
|
|
244
|
+
If(ht.greaterThan(0.01), () => {
|
|
245
|
+
const nH = uStoneNoise(sp2.mul(0.55).add(vec2(0.71, 0.23))); // 1.8 m tile: ~15 cm crack cells, 6 cm pores
|
|
246
|
+
const crust = smoothstep(0.04, 0.45, ht);
|
|
247
|
+
albedo.mulAssign(float(1.0).sub(crust.mul(0.8)));
|
|
248
|
+
rough.assign(mix(rough, 0.88, crust));
|
|
249
|
+
metal.mulAssign(float(1.0).sub(crust));
|
|
250
|
+
// local temperature: the field heat broken into hot and cooler patches (a plateau of saturated
|
|
251
|
+
// field heat must not read as one uniform disc)
|
|
252
|
+
const hl = clamp(
|
|
253
|
+
ht.mul(nH.r.mul(0.55).add(0.6)).mul(nS.g.mul(0.3).add(0.85)),
|
|
254
|
+
0.0,
|
|
255
|
+
1.0,
|
|
256
|
+
).toVar();
|
|
257
|
+
// fractures across the slabs (~75 cm cells, the tap the responses already made), segment by
|
|
258
|
+
// segment as the heat rises; a fine crackle (~15 cm) only in the hottest patches
|
|
259
|
+
// (thin and coverage-preserving: a crack narrower than a pixel dims instead of aliasing; width and
|
|
260
|
+
// glow vary along each crack, which also breaks the network into segments)
|
|
261
|
+
const bw = hl.mul(0.014).add(0.005).mul(nH.r.mul(1.2).add(0.4));
|
|
262
|
+
const fb = fwidth(nS.b);
|
|
263
|
+
const big = float(1.0)
|
|
264
|
+
.sub(smoothstep(bw.mul(0.3), bw.add(fb), nS.b))
|
|
265
|
+
.mul(bw.div(bw.add(fb.mul(0.75))))
|
|
266
|
+
.mul(smoothstep(0.25, 0.55, hl))
|
|
267
|
+
.mul(smoothstep(0.42, 0.62, nH.g.add(hl.mul(0.12))));
|
|
268
|
+
const fw = hl.mul(0.012).add(0.006);
|
|
269
|
+
const ff = fwidth(nH.b);
|
|
270
|
+
const fine = float(1.0)
|
|
271
|
+
.sub(smoothstep(fw.mul(0.3), fw.add(ff), nH.b))
|
|
272
|
+
.mul(fw.div(fw.add(ff.mul(0.75))))
|
|
273
|
+
.mul(smoothstep(0.72, 0.95, hl))
|
|
274
|
+
.mul(smoothstep(0.45, 0.6, nH.g));
|
|
275
|
+
const tc = max(big, fine.mul(0.7))
|
|
276
|
+
.mul(1.0 - gVent)
|
|
277
|
+
.toVar(); // round a crater the glow comes out of its fractures (gHeatOpen) alone
|
|
278
|
+
const op = max(tc, gHeatOpen >= 0.0 ? float(gHeatOpen) : crevice);
|
|
279
|
+
albedo.mulAssign(float(1.0).sub(tc.mul(0.7)));
|
|
280
|
+
const pore = smoothstep(0.8, 0.86, nH.a).mul(smoothstep(0.55, 0.9, hl)); // a few open vesicles, hottest patches only
|
|
281
|
+
const Tc = hl.mul(1250.0).add(620.0);
|
|
282
|
+
const Ts = Tc.sub(200.0);
|
|
283
|
+
const Rc = pow(Tc.div(1500.0), 4.0).mul(smoothstep(760.0, 1050.0, Tc));
|
|
284
|
+
const Rs = pow(Ts.div(1500.0), 4.0).mul(smoothstep(760.0, 1100.0, Ts));
|
|
285
|
+
emit.addAssign(
|
|
286
|
+
blackbody(Tc)
|
|
287
|
+
.mul(Rc.mul(3.2).mul(op))
|
|
288
|
+
.add(
|
|
289
|
+
blackbody(Ts).mul(
|
|
290
|
+
Rs.mul(
|
|
291
|
+
pore
|
|
292
|
+
.mul(0.35)
|
|
293
|
+
.add(smoothstep(0.75, 1.0, hl).mul(0.08))
|
|
294
|
+
.add(tc.mul(tc).mul(0.12)),
|
|
295
|
+
),
|
|
296
|
+
),
|
|
297
|
+
),
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
// holy glow: gold-white light pouring out of the joints, a soft sheen on the surface
|
|
301
|
+
const gl = clamp(stB.w, 0.0, 1.0);
|
|
302
|
+
const gcol = mix(vec3(1.0, 0.8, 0.48), stGlow, step(1e-3, dot(stGlow, stGlow)).mul(0.5));
|
|
303
|
+
emit.addAssign(gcol.mul(gl).mul(crevice.mul(3.0).add(0.35)).mul(2.5));
|
|
304
|
+
},
|
|
305
|
+
);
|
|
306
|
+
return { albedo, rough, metal, emit };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* The arena floor's response to the ground field and the impacts, for a game's own floor material:
|
|
311
|
+
* `{ color, roughness, metalness, emissive }` nodes from the surface's own albedo / roughness /
|
|
312
|
+
* metalness, at world position `wp`. Build the GroundField first (common.ts setGroundTexture).
|
|
313
|
+
*/
|
|
314
|
+
export function groundShade(wp: V3, surface: IGroundSurface) {
|
|
315
|
+
// two calls, each packing what one material slot set reads (a TSL Fn returns one value)
|
|
316
|
+
const a = Fn(() => {
|
|
317
|
+
const r = shade(wp, surface);
|
|
318
|
+
return vec4(r.albedo, r.rough);
|
|
319
|
+
})() as unknown as V4;
|
|
320
|
+
const b = Fn(() => {
|
|
321
|
+
const r = shade(wp, surface);
|
|
322
|
+
return vec4(r.emit, r.metal);
|
|
323
|
+
})() as unknown as V4;
|
|
324
|
+
return { color: a.xyz, roughness: a.w, metalness: b.w, emissive: b.xyz };
|
|
325
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// Ported from Ultra Elements src/spells/cast.js @698b720 (MIT, Copyright (c) 2026 Humpalumps). JavaScript copied verbatim; GLSL transliterated to TSL.
|
|
2
|
+
import { Vector3 } from "three";
|
|
3
|
+
import { ARENA, arenaSDFJS as arenaSDF } from "../vfx/common.js";
|
|
4
|
+
|
|
5
|
+
// Cast pool + phase clock (PLAN 2.4). One record per live cast; spells keep per-cast state in
|
|
6
|
+
// c.data (reused, so they reset it in phase 'charge'). Phases:
|
|
7
|
+
// charge -> release (instant) -> travel (projectile flight / beam sustain) -> impact -> linger -> done
|
|
8
|
+
// shape decides travel: projectile integrates until it hits the arena or reaches the target,
|
|
9
|
+
// beam sustains while held (or timing.sustain), strike/area/self skip it. A spell may override
|
|
10
|
+
// shape per form with formShapes: { 'Form name': 'strike' }.
|
|
11
|
+
const MAX_CASTS = 16;
|
|
12
|
+
const _d = new Vector3();
|
|
13
|
+
|
|
14
|
+
export type Phase = "charge" | "release" | "travel" | "impact" | "linger" | "done";
|
|
15
|
+
|
|
16
|
+
// what a spell's create(fx) returns (upstream: `s.inst`)
|
|
17
|
+
export interface ISpellInstance {
|
|
18
|
+
phase?(c: ICast, name: Phase): void;
|
|
19
|
+
update?(c: ICast, dt: number): void;
|
|
20
|
+
travel?(c: ICast, dt: number): boolean;
|
|
21
|
+
onParam?(k: string): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// a spell module (upstream: one default export per src/spells/<element>.js)
|
|
25
|
+
export interface ISpell {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
shape?: string;
|
|
29
|
+
forms?: string[];
|
|
30
|
+
formShapes?: Record<string, string>;
|
|
31
|
+
radius?: number;
|
|
32
|
+
speed?: number;
|
|
33
|
+
lob?: number;
|
|
34
|
+
params?: Record<string, number | string>;
|
|
35
|
+
timing?: { charge?: number; impact?: number; linger?: number; sustain?: number };
|
|
36
|
+
inst?: ISpellInstance;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ICast {
|
|
40
|
+
index: number;
|
|
41
|
+
alive: boolean;
|
|
42
|
+
spell: ISpell | null;
|
|
43
|
+
inst: ISpellInstance | null;
|
|
44
|
+
form: string;
|
|
45
|
+
shape: string;
|
|
46
|
+
phase: Phase;
|
|
47
|
+
t: number;
|
|
48
|
+
age: number;
|
|
49
|
+
seed: number;
|
|
50
|
+
from: Vector3;
|
|
51
|
+
to: Vector3;
|
|
52
|
+
pos: Vector3;
|
|
53
|
+
vel: Vector3;
|
|
54
|
+
dir: Vector3;
|
|
55
|
+
held: boolean;
|
|
56
|
+
travelled: number;
|
|
57
|
+
target: number;
|
|
58
|
+
data: Record<string, unknown>;
|
|
59
|
+
durations: { charge: number; travel: number; impact: number; linger: number };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function record(i: number): ICast {
|
|
63
|
+
return {
|
|
64
|
+
index: i,
|
|
65
|
+
alive: false,
|
|
66
|
+
spell: null,
|
|
67
|
+
inst: null,
|
|
68
|
+
form: "",
|
|
69
|
+
shape: "projectile",
|
|
70
|
+
phase: "done",
|
|
71
|
+
t: 0,
|
|
72
|
+
age: 0,
|
|
73
|
+
seed: 0,
|
|
74
|
+
from: new Vector3(),
|
|
75
|
+
to: new Vector3(),
|
|
76
|
+
pos: new Vector3(),
|
|
77
|
+
vel: new Vector3(),
|
|
78
|
+
dir: new Vector3(),
|
|
79
|
+
held: false,
|
|
80
|
+
travelled: 0,
|
|
81
|
+
target: -1,
|
|
82
|
+
data: {},
|
|
83
|
+
durations: { charge: 0, travel: 0, impact: 0, linger: 0 },
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class Casts {
|
|
88
|
+
fx: { rand(): number };
|
|
89
|
+
list: ICast[];
|
|
90
|
+
last: ICast | null;
|
|
91
|
+
|
|
92
|
+
constructor(fx: { rand(): number }) {
|
|
93
|
+
this.fx = fx;
|
|
94
|
+
this.list = Array.from({ length: MAX_CASTS }, (_, i) => record(i));
|
|
95
|
+
this.last = null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// spell: module from SPELLS (with .inst set at load). to: world point. target: dummy index or -1.
|
|
99
|
+
cast(
|
|
100
|
+
spell: ISpell,
|
|
101
|
+
to: Vector3,
|
|
102
|
+
{
|
|
103
|
+
form = spell.forms?.[0] ?? "",
|
|
104
|
+
from = ARENA.focus,
|
|
105
|
+
target = -1,
|
|
106
|
+
held = false,
|
|
107
|
+
seed,
|
|
108
|
+
}: { form?: string; from?: Vector3; target?: number; held?: boolean; seed?: number } = {},
|
|
109
|
+
): ICast {
|
|
110
|
+
let c = this.list.find((x) => !x.alive);
|
|
111
|
+
if (!c) {
|
|
112
|
+
// pool full: recycle the oldest
|
|
113
|
+
c = this.list.reduce((a, b) => (b.age > a.age ? b : a));
|
|
114
|
+
this.enter(c, "done");
|
|
115
|
+
}
|
|
116
|
+
Object.assign(c, {
|
|
117
|
+
alive: true,
|
|
118
|
+
spell,
|
|
119
|
+
inst: spell.inst,
|
|
120
|
+
form,
|
|
121
|
+
shape: spell.formShapes?.[form] ?? spell.shape ?? "projectile",
|
|
122
|
+
t: 0,
|
|
123
|
+
age: 0,
|
|
124
|
+
held,
|
|
125
|
+
travelled: 0,
|
|
126
|
+
target,
|
|
127
|
+
});
|
|
128
|
+
c.seed = seed ?? Math.floor(this.fx.rand() * 1e6);
|
|
129
|
+
c.from.copy(from);
|
|
130
|
+
c.to.copy(to);
|
|
131
|
+
c.pos.copy(from);
|
|
132
|
+
c.dir.subVectors(to, from).normalize();
|
|
133
|
+
c.vel.set(0, 0, 0);
|
|
134
|
+
const T = spell.timing ?? {};
|
|
135
|
+
c.durations.charge = T.charge ?? 0.5;
|
|
136
|
+
c.durations.travel = T.sustain ?? 4;
|
|
137
|
+
c.durations.impact = T.impact ?? 0.2;
|
|
138
|
+
c.durations.linger = T.linger ?? 2;
|
|
139
|
+
this.enter(c, "charge");
|
|
140
|
+
this.last = c;
|
|
141
|
+
return c;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
enter(c: ICast, phase: Phase): void {
|
|
145
|
+
c.phase = phase;
|
|
146
|
+
c.t = 0;
|
|
147
|
+
c.inst?.phase?.(c, phase);
|
|
148
|
+
if (phase === "done") c.alive = false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
releaseHeld(): void {
|
|
152
|
+
for (const c of this.list) c.held = false;
|
|
153
|
+
}
|
|
154
|
+
clear(): void {
|
|
155
|
+
for (const c of this.list) if (c.alive) this.enter(c, "done");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
|
|
159
|
+
update(dt: number): void {
|
|
160
|
+
for (const c of this.list) {
|
|
161
|
+
if (!c.alive) continue;
|
|
162
|
+
c.t += dt;
|
|
163
|
+
c.age += dt;
|
|
164
|
+
const s = c.spell as ISpell;
|
|
165
|
+
const d = c.durations;
|
|
166
|
+
const inst = c.inst as ISpellInstance;
|
|
167
|
+
if (c.phase === "charge") {
|
|
168
|
+
c.pos.copy(c.from);
|
|
169
|
+
if (c.t >= d.charge) {
|
|
170
|
+
this.enter(c, "release");
|
|
171
|
+
const shape = c.shape;
|
|
172
|
+
if (shape === "projectile") {
|
|
173
|
+
c.vel
|
|
174
|
+
.copy(c.dir)
|
|
175
|
+
.multiplyScalar((s.params?.speed as number | undefined) ?? s.speed ?? 15);
|
|
176
|
+
if (s.lob) c.vel.y += s.lob; // lobbed: initial upward speed, gravity below
|
|
177
|
+
this.enter(c, "travel");
|
|
178
|
+
} else if (shape === "beam") this.enter(c, "travel");
|
|
179
|
+
else {
|
|
180
|
+
if (shape !== "self") c.pos.copy(c.to);
|
|
181
|
+
this.enter(c, "impact");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} else if (c.phase === "travel") {
|
|
185
|
+
if (c.shape === "projectile") {
|
|
186
|
+
// the spell may steer (homing) by editing c.vel in its update; integrate here
|
|
187
|
+
if (inst.travel) {
|
|
188
|
+
if (inst.travel(c, dt)) {
|
|
189
|
+
this.enter(c, "impact");
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
if (s.lob) c.vel.y -= 9.81 * dt;
|
|
194
|
+
c.pos.addScaledVector(c.vel, dt);
|
|
195
|
+
c.travelled += c.vel.length() * dt;
|
|
196
|
+
const r = s.radius ?? 0.3;
|
|
197
|
+
const hit =
|
|
198
|
+
(c.travelled > 1 && arenaSDF(c.pos) < r) ||
|
|
199
|
+
(!s.lob && _d.subVectors(c.to, c.pos).dot(c.dir) <= 0) ||
|
|
200
|
+
c.t > d.travel;
|
|
201
|
+
if (hit) {
|
|
202
|
+
if (!s.lob && c.t <= d.travel && _d.subVectors(c.to, c.pos).dot(c.dir) <= 0)
|
|
203
|
+
c.pos.copy(c.to);
|
|
204
|
+
this.enter(c, "impact");
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} else if (!c.held && c.t >= (s.timing?.sustain ?? 0)) {
|
|
209
|
+
this.enter(c, "impact");
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
} else if (c.phase === "impact") {
|
|
213
|
+
if (c.t >= d.impact) this.enter(c, "linger");
|
|
214
|
+
} else if (c.phase === "linger") {
|
|
215
|
+
if (c.t >= d.linger) {
|
|
216
|
+
this.enter(c, "done");
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (c.alive) inst.update?.(c, dt);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// for the HUD phase strip: the newest live cast
|
|
225
|
+
active(): ICast | null {
|
|
226
|
+
return this.last?.alive ? this.last : null;
|
|
227
|
+
}
|
|
228
|
+
count(): number {
|
|
229
|
+
let n = 0;
|
|
230
|
+
for (const c of this.list) n += c.alive ? 1 : 0;
|
|
231
|
+
return n;
|
|
232
|
+
}
|
|
233
|
+
}
|