@threenative/core 0.3.11 → 0.3.12
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/capabilities.json +1096 -26
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-CWuFRT7G.d.ts} +1 -1
- package/dist/chunk-2Z44XSI2.js +35 -0
- package/dist/chunk-5O73CDMR.js +1849 -0
- package/dist/chunk-6KLNISRJ.js +153 -0
- package/dist/chunk-7UUT3TY5.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DBELTTTM.js +615 -0
- package/dist/chunk-GMHATRPW.js +7701 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-N5LRP4BR.js +220 -0
- package/dist/chunk-OKXUCASC.js +2238 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-VAZM36TV.js +497 -0
- package/dist/{game-DzMcitDO.d.ts → game-D7pAzZUY.d.ts} +15 -3
- package/dist/hot.d.ts +3 -3
- package/dist/hot.js +2 -46
- package/dist/index.d.ts +329 -302
- package/dist/index.js +10566 -22552
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-B6BMqS1r.d.ts} +33 -3
- package/dist/playtest.d.ts +3 -3
- package/dist/playtest.js +24 -75
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-DvFVoAgj.d.ts} +13 -4
- 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 +5 -384
- package/dist/worker.js +4 -41
- package/dist/world.d.ts +725 -259
- package/dist/world.js +16714 -18284
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +142 -47
- package/mcp/servers.mjs +9 -2
- package/mcp/terrain.mjs +8 -0
- package/package.json +14 -6
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/assets.ts +9 -2
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/frame-budget.ts +31 -20
- package/src/game-dev-tools.ts +93 -0
- package/src/game-frame-loop.ts +995 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1001 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +253 -1935
- package/src/index.ts +27 -2
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +24 -0
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quality.ts +10 -5
- package/src/look/world-environment.ts +76 -9
- package/src/loop.ts +29 -0
- package/src/model-lod.ts +42 -3
- package/src/particle-kinds.ts +515 -0
- package/src/picking.ts +17 -3
- package/src/playtest.ts +27 -1
- package/src/projection-apply.ts +4 -1
- package/src/projection-plan.ts +9 -6
- package/src/render/mesh-pool.ts +1 -1
- 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.ts +213 -992
- package/src/render/world-impostor-surface.ts +293 -34
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer.ts +92 -37
- package/src/snow-field.ts +1 -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-readiness.ts +128 -34
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/world-bundle-safety.ts +401 -0
- package/src/world-cell-batches.ts +1216 -0
- package/src/world-cell-chunks.ts +1132 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1449 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +189 -0
- package/src/world-cell-placements.ts +694 -0
- package/src/world-cell-prewarm.ts +557 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +714 -0
- package/src/world-cell-render-main-cull.ts +484 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +246 -0
- package/src/world-cell-render.ts +1493 -0
- package/src/world-cell-residency.ts +745 -0
- package/src/world-cells.ts +1318 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +163 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +510 -0
- package/src/world-gpu-scene.ts +214 -2264
- package/src/world-gpu-shadow.ts +190 -0
- package/src/world-gpu-types.ts +381 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +106 -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-terrain-splat.ts +365 -149
- package/src/world-tile-budget.ts +256 -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 +170 -1745
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +35 -741
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// Ported from Ultra Elements src/main.js @698b720 (MIT, Copyright (c) 2026 Humpalumps). JavaScript copied verbatim; GLSL transliterated to TSL.
|
|
2
|
+
//
|
|
3
|
+
// Only the part of main.js every spell depends on: the shared `fx` world (main.js ~line 94) and the
|
|
4
|
+
// CPU half of renderFrame (clock, casts, packWorld, systems). Upstream's renderer, arena, sky,
|
|
5
|
+
// PostFX, GUI and capture are not ported: the game's scene, its lights and WorldEnvironment replace
|
|
6
|
+
// them. The services later slices port (particles, trails, ground, shocks, fluid, rig, arena focus)
|
|
7
|
+
// are typed seams below; until a slice lands, each is an inert stand-in that keeps the spell code verbatim.
|
|
8
|
+
import {
|
|
9
|
+
type Camera,
|
|
10
|
+
type Color,
|
|
11
|
+
type Object3D,
|
|
12
|
+
PointLight,
|
|
13
|
+
type Scene,
|
|
14
|
+
type Vector3,
|
|
15
|
+
} from "three";
|
|
16
|
+
import { CameraRig } from "./engine/camera.js";
|
|
17
|
+
import { Q } from "./engine/quality.js";
|
|
18
|
+
import { Casts, type ICast, type ISpell } from "./spells/cast.js";
|
|
19
|
+
import { FluidVolume } from "./vfx/FluidVolume.js";
|
|
20
|
+
import { FxTarget } from "./vfx/FxTarget.js";
|
|
21
|
+
import { GroundField, type IFieldRenderer } from "./vfx/GroundField.js";
|
|
22
|
+
import { type IParticleGround, Particles } from "./vfx/Particles.js";
|
|
23
|
+
import { TrailRibbons } from "./vfx/Ribbons.js";
|
|
24
|
+
import { Shockwaves } from "./vfx/Shockwaves.js";
|
|
25
|
+
import { Volumes } from "./vfx/Volumes.js";
|
|
26
|
+
import {
|
|
27
|
+
ARENA,
|
|
28
|
+
U,
|
|
29
|
+
forces,
|
|
30
|
+
impacts,
|
|
31
|
+
lights,
|
|
32
|
+
mirrorLights,
|
|
33
|
+
occluders,
|
|
34
|
+
packWorld,
|
|
35
|
+
} from "./vfx/common.js";
|
|
36
|
+
|
|
37
|
+
// --- service seams (Ribbons.js, GroundField.js, Shockwaves.js, FluidVolume.js, camera.js, arena.js) ---
|
|
38
|
+
export interface ITrail {
|
|
39
|
+
width: number;
|
|
40
|
+
intensity: number;
|
|
41
|
+
glow: number;
|
|
42
|
+
glowIntensity: number;
|
|
43
|
+
fadeTime: number;
|
|
44
|
+
distortion: number;
|
|
45
|
+
color: Color;
|
|
46
|
+
push(p: Vector3): void;
|
|
47
|
+
release(): void;
|
|
48
|
+
}
|
|
49
|
+
export interface ITrails {
|
|
50
|
+
acquire(): ITrail | null;
|
|
51
|
+
}
|
|
52
|
+
export interface IShocks {
|
|
53
|
+
spawn(shock: object): void;
|
|
54
|
+
}
|
|
55
|
+
export interface IGround {
|
|
56
|
+
splat(splat: object): void;
|
|
57
|
+
}
|
|
58
|
+
export interface IFluidDomain {
|
|
59
|
+
position: Vector3;
|
|
60
|
+
size: Vector3;
|
|
61
|
+
h: number;
|
|
62
|
+
heat: number;
|
|
63
|
+
tint: Color;
|
|
64
|
+
sootColor: Color;
|
|
65
|
+
detailCenter: Vector3;
|
|
66
|
+
obstacle: { set(x: number, y: number, z: number, r: number): void };
|
|
67
|
+
emit(source: object): void;
|
|
68
|
+
release(): void;
|
|
69
|
+
[field: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
export interface IFluid {
|
|
72
|
+
res: number;
|
|
73
|
+
acquire(options: { size: number[]; res?: number }): IFluidDomain | null;
|
|
74
|
+
}
|
|
75
|
+
export interface IRig {
|
|
76
|
+
shake(amount: number, frequency: number): void;
|
|
77
|
+
punch(amount: number, seconds: number): void;
|
|
78
|
+
hitstop(seconds: number): void;
|
|
79
|
+
/** main multiplies the simulation dt by this (hitstop) */
|
|
80
|
+
readonly timeScale: number;
|
|
81
|
+
/** after the game's camera update: adds the shake and FOV punch; restore() takes them back */
|
|
82
|
+
apply(camera: Camera, dt: number): void;
|
|
83
|
+
restore(camera: Camera): void;
|
|
84
|
+
}
|
|
85
|
+
export interface IArena {
|
|
86
|
+
focus: { color: Color };
|
|
87
|
+
setFocus(color: Color, intensity: number): void;
|
|
88
|
+
}
|
|
89
|
+
export interface IDummy {
|
|
90
|
+
pos: Vector3;
|
|
91
|
+
status: { burn: number };
|
|
92
|
+
hit(dir: Vector3, amount: number): void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const NULL_GROUND: IGround = { splat() {} };
|
|
96
|
+
const NULL_FLUID: IFluid = { res: 0, acquire: () => null };
|
|
97
|
+
|
|
98
|
+
export interface IFxOptions {
|
|
99
|
+
camera: Camera;
|
|
100
|
+
/** compiles each spell's pipelines before its first cast (warmSpell); upstream: renderer.compileAsync */
|
|
101
|
+
renderer?: {
|
|
102
|
+
compileAsync(object: Object3D, camera: Camera, scene?: Scene): Promise<unknown>;
|
|
103
|
+
compute(node: unknown): unknown; // runs the particle sim kernel (Particles.ts)
|
|
104
|
+
};
|
|
105
|
+
/** drawing-buffer size in pixels (upstream: renderer.getDrawingBufferSize) */
|
|
106
|
+
size: () => { width: number; height: number };
|
|
107
|
+
seed?: number;
|
|
108
|
+
/** PointLights the spell lights drive (common.ts mirrorLights); parked at 0 when idle */
|
|
109
|
+
pointLights?: number;
|
|
110
|
+
trails?: ITrails;
|
|
111
|
+
ground?: IGround;
|
|
112
|
+
shocks?: IShocks;
|
|
113
|
+
fluid?: IFluid;
|
|
114
|
+
rig?: IRig;
|
|
115
|
+
arena?: IArena;
|
|
116
|
+
dummies?: IDummy[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// the shared world every spell gets (PLAN 2.4). Spells only touch what's in here.
|
|
120
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream main.js's world, one function
|
|
121
|
+
export function createFx(o: IFxOptions) {
|
|
122
|
+
let seed = o.seed ?? 1;
|
|
123
|
+
const fxTarget = new FxTarget();
|
|
124
|
+
const volumes = new Volumes();
|
|
125
|
+
const flashes: number[] = [];
|
|
126
|
+
// upstream main.js: GroundField, TrailRibbons, Shockwaves and CameraRig, shared by every spell.
|
|
127
|
+
// The field draws its sim passes with the raw renderer; it is built first, before any material
|
|
128
|
+
// that reads U.uGroundA/B (common.ts setGroundTexture). A game passes its own to override one.
|
|
129
|
+
const raw = (o.renderer as { raw?: unknown } | undefined)?.raw ?? o.renderer;
|
|
130
|
+
const groundField =
|
|
131
|
+
o.ground === undefined && raw !== undefined
|
|
132
|
+
? new GroundField(raw as IFieldRenderer, Q.groundSize)
|
|
133
|
+
: undefined;
|
|
134
|
+
const trailRibbons =
|
|
135
|
+
o.trails === undefined ? new TrailRibbons({ max: 64, points: 48 }) : undefined;
|
|
136
|
+
const shockwaves = o.shocks === undefined ? new Shockwaves() : undefined;
|
|
137
|
+
const fx = {
|
|
138
|
+
camera: o.camera,
|
|
139
|
+
scenes: { fx: fxTarget.scene },
|
|
140
|
+
U,
|
|
141
|
+
Q,
|
|
142
|
+
ARENA,
|
|
143
|
+
arena: o.arena ?? { focus: { color: { r: 1, g: 1, b: 1 } as Color }, setFocus() {} },
|
|
144
|
+
ground: o.ground ?? groundField ?? NULL_GROUND,
|
|
145
|
+
particles: null as unknown as Particles,
|
|
146
|
+
trails: (o.trails ?? trailRibbons) as ITrails,
|
|
147
|
+
volumes,
|
|
148
|
+
shocks: (o.shocks ?? shockwaves) as IShocks | undefined,
|
|
149
|
+
// the shared combustion fluid (upstream FluidVolume.get(fx)): built on first use, inside the spell's
|
|
150
|
+
// create(), so its box meshes count as that spell's objects and warmSpell compiles them
|
|
151
|
+
get fluid(): IFluid {
|
|
152
|
+
return o.fluid ?? (fx.renderer ? FluidVolume.get(fx) : NULL_FLUID);
|
|
153
|
+
},
|
|
154
|
+
fluidVolume: undefined as FluidVolume | undefined,
|
|
155
|
+
// the raw renderer the GPU systems draw their passes with (ctx.renderer.raw on ThreeNative)
|
|
156
|
+
renderer: ((o.renderer as { raw?: unknown } | undefined)?.raw ?? o.renderer) as
|
|
157
|
+
| ConstructorParameters<typeof FluidVolume>[0]["renderer"]
|
|
158
|
+
| undefined,
|
|
159
|
+
rig: o.rig ?? (new CameraRig() as IRig),
|
|
160
|
+
lights,
|
|
161
|
+
forces,
|
|
162
|
+
impacts,
|
|
163
|
+
occluders,
|
|
164
|
+
fxTarget,
|
|
165
|
+
dummies: o.dummies ?? [],
|
|
166
|
+
spells: {} as Record<string, ISpell>,
|
|
167
|
+
reduced: false,
|
|
168
|
+
systems: [] as { update(dt: number, camera: Camera): void }[], // extra GPU systems: { update(dt, camera) }, run in the timed sim section every frame
|
|
169
|
+
flashAmount: 0, // upstream: post.params.flash; the game's post reads it
|
|
170
|
+
rand() {
|
|
171
|
+
seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
|
|
172
|
+
return seed / 4294967296;
|
|
173
|
+
},
|
|
174
|
+
// reduced-motion aware flash (WCAG 2.3.1: at most 3 flashes per second)
|
|
175
|
+
flash(amount: number) {
|
|
176
|
+
const now = globalThis.performance?.now() ?? Date.now();
|
|
177
|
+
while (flashes.length > 0 && now - (flashes[0] as number) >= 1000) flashes.shift();
|
|
178
|
+
// biome-ignore lint/style/noParameterAssign: upstream Ultra Elements code, copied verbatim
|
|
179
|
+
if (fx.reduced && (flashes.length >= 3 || amount > 0.3)) amount = Math.min(amount, 0.15);
|
|
180
|
+
flashes.push(now);
|
|
181
|
+
fx.flashAmount = Math.min(2, Math.max(fx.flashAmount, amount));
|
|
182
|
+
},
|
|
183
|
+
casts: null as unknown as Casts,
|
|
184
|
+
};
|
|
185
|
+
fxTarget.scene.add(volumes.group);
|
|
186
|
+
// shared meshes go in first, so what each spell's create() adds can be told apart
|
|
187
|
+
// (upstream: trails.lines in the lines scene, trails.fx and shocks.mesh in the fx scene)
|
|
188
|
+
if (trailRibbons) fxTarget.scene.add(trailRibbons.lines, trailRibbons.fx);
|
|
189
|
+
if (shockwaves) fxTarget.scene.add(shockwaves.mesh);
|
|
190
|
+
const points = Array.from({ length: o.pointLights ?? 4 }, (_, i) => {
|
|
191
|
+
const l = new PointLight(0xffffff, 0, 8, 2);
|
|
192
|
+
l.name = `ultra-spell-light-${i}`;
|
|
193
|
+
fxTarget.scene.add(l);
|
|
194
|
+
return l;
|
|
195
|
+
});
|
|
196
|
+
const casts = new Casts(fx);
|
|
197
|
+
fx.casts = casts;
|
|
198
|
+
// one GPU particle pool for every spell (upstream main.js: new Particles(renderer, { ground }))
|
|
199
|
+
const particles = new Particles(o.renderer ?? null, { ground: fx.ground as IParticleGround });
|
|
200
|
+
fx.particles = particles;
|
|
201
|
+
// upstream builds once every spell has registered: here, before the first warm-up or frame.
|
|
202
|
+
// Engine: one world scene, so glow (upstream: lines scene) and debris (opaque scene) join the fx group
|
|
203
|
+
function buildParticles(): void {
|
|
204
|
+
if (particles.built) return;
|
|
205
|
+
particles.build();
|
|
206
|
+
fxTarget.scene.add(particles.glow, particles.media, ...particles.debris);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let simTime = 0;
|
|
210
|
+
let w = 0;
|
|
211
|
+
let h = 0;
|
|
212
|
+
// the CPU half of upstream's renderFrame(dt). dt: real seconds; the sim runs at the rig's time
|
|
213
|
+
// scale (hitstop), upstream's sdt
|
|
214
|
+
function renderFrame(realDt: number): void {
|
|
215
|
+
const dt = realDt * fx.rig.timeScale;
|
|
216
|
+
const s = o.size();
|
|
217
|
+
if (s.width !== w || s.height !== h) {
|
|
218
|
+
w = s.width;
|
|
219
|
+
h = s.height;
|
|
220
|
+
fxTarget.setSize(w, h, Q.fxScale);
|
|
221
|
+
}
|
|
222
|
+
simTime += dt;
|
|
223
|
+
U.uTime.value = simTime % 3600;
|
|
224
|
+
U.uDt.value = dt;
|
|
225
|
+
U.uFrame.value++;
|
|
226
|
+
const cam = o.camera as Camera & { near?: number; far?: number };
|
|
227
|
+
if (cam.near !== undefined && cam.far !== undefined) U.uNearFar.value.set(cam.near, cam.far);
|
|
228
|
+
|
|
229
|
+
// CPU: casts emit, lights/forces/impacts pack into the world texture
|
|
230
|
+
casts.update(dt);
|
|
231
|
+
for (const sp of Object.values(fx.spells))
|
|
232
|
+
(sp.inst as { tick?(dt: number): void } | undefined)?.tick?.(dt);
|
|
233
|
+
packWorld(dt, { maxLights: Q.maxLights, maxShadowed: Q.shadowLights });
|
|
234
|
+
mirrorLights(points);
|
|
235
|
+
|
|
236
|
+
buildParticles();
|
|
237
|
+
particles.update(dt, simTime);
|
|
238
|
+
groundField?.update(dt);
|
|
239
|
+
trailRibbons?.update(dt);
|
|
240
|
+
volumes.update(o.camera);
|
|
241
|
+
shockwaves?.update(dt);
|
|
242
|
+
for (const sys of fx.systems) sys.update(dt, o.camera);
|
|
243
|
+
fxTarget.render();
|
|
244
|
+
fx.flashAmount = Math.max(0, fx.flashAmount - dt * 6);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// spell modules: create() once each (upstream: the SPELLS loop in main.js). Remember the scene
|
|
248
|
+
// objects it added: its programs are compiled and warmed on their own (warmSpell).
|
|
249
|
+
const sceneObjects = () => {
|
|
250
|
+
const set = new Set<Object3D>();
|
|
251
|
+
fxTarget.scene.traverse((o) => set.add(o));
|
|
252
|
+
return set;
|
|
253
|
+
};
|
|
254
|
+
const spellObjects = new Map<ISpell, Object3D[]>();
|
|
255
|
+
const warming = new Map<ISpell, Promise<void>>();
|
|
256
|
+
function addSpell<S extends ISpell & { create(fx: Fx): NonNullable<ISpell["inst"]> }>(s: S): S {
|
|
257
|
+
(s as { defaults?: object }).defaults = { ...s.params };
|
|
258
|
+
s.params = { ...s.params };
|
|
259
|
+
if (particles.built)
|
|
260
|
+
throw new Error(`addSpell(${s.id}): add every spell before the first frame`);
|
|
261
|
+
for (const [k, def] of Object.entries((s as { kinds?: object }).kinds ?? {}))
|
|
262
|
+
particles.addKind(`${s.id}.${k}`, def);
|
|
263
|
+
const before = sceneObjects();
|
|
264
|
+
s.inst = s.create(fx);
|
|
265
|
+
spellObjects.set(
|
|
266
|
+
s,
|
|
267
|
+
[...sceneObjects()].filter((o) => !before.has(o)),
|
|
268
|
+
);
|
|
269
|
+
fx.spells[s.id] = s;
|
|
270
|
+
return s;
|
|
271
|
+
}
|
|
272
|
+
// per-spell warm-up (upstream warmSpell): compile its pipelines with its objects forced on, so the
|
|
273
|
+
// first cast does not compile mid-frame. Engine: the compile reads the scene when it is called, so
|
|
274
|
+
// the objects are on for that call only and no presented frame draws them with unset uniforms.
|
|
275
|
+
// Upstream's second step, one draw into a 4x4 target, has no engine route: the Wasm renderer's
|
|
276
|
+
// setRenderTarget refuses any target (three-native browser-renderer.ts setRenderTarget).
|
|
277
|
+
function warmSpell(s: ISpell): Promise<void> {
|
|
278
|
+
let job = warming.get(s);
|
|
279
|
+
if (job === undefined) {
|
|
280
|
+
buildParticles();
|
|
281
|
+
particles.warm(true); // the particle draws compile with the first spell's warm-up
|
|
282
|
+
const objects = spellObjects.get(s) ?? [];
|
|
283
|
+
const saved = objects.map((obj) => obj.visible);
|
|
284
|
+
for (const obj of objects) obj.visible = true;
|
|
285
|
+
let root: Object3D = fxTarget.scene;
|
|
286
|
+
while (root.parent !== null) root = root.parent; // upstream sceneOf: the scene's lights pick the variant
|
|
287
|
+
try {
|
|
288
|
+
job = (
|
|
289
|
+
o.renderer?.compileAsync(fxTarget.scene, o.camera, root as Scene) ?? Promise.resolve()
|
|
290
|
+
).then(() => undefined);
|
|
291
|
+
} finally {
|
|
292
|
+
objects.forEach((obj, i) => {
|
|
293
|
+
obj.visible = saved[i] as boolean;
|
|
294
|
+
});
|
|
295
|
+
particles.warm(false);
|
|
296
|
+
}
|
|
297
|
+
warming.set(s, job);
|
|
298
|
+
}
|
|
299
|
+
return job;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return { fx, casts, renderFrame, addSpell, warmSpell, pointLights: points };
|
|
303
|
+
}
|
|
304
|
+
export type Fx = ReturnType<typeof createFx>["fx"];
|
|
305
|
+
export type { ICast };
|
|
@@ -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
|
+
}
|