@margoengine/vfx 0.0.0-stage → 1.0.0
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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +2240 -2
- package/dist/base-LGs65K7K.js +709 -0
- package/dist/base.d.ts +869 -0
- package/dist/base.js +1 -0
- package/dist/blown-sand.d.ts +218 -0
- package/dist/blown-sand.js +700 -0
- package/dist/clouds.d.ts +237 -0
- package/dist/clouds.js +583 -0
- package/dist/compat-BFjXAQuu.js +14 -0
- package/dist/compat-CVSEj1Bp.js +217 -0
- package/dist/compat.d.ts +59 -0
- package/dist/curves.d.ts +11 -0
- package/dist/curves.js +59 -0
- package/dist/debris.d.ts +154 -0
- package/dist/debris.js +290 -0
- package/dist/depth-collide.d.ts +7 -0
- package/dist/depth-collide.js +96 -0
- package/dist/dust-current.d.ts +66 -0
- package/dist/dust-current.js +92 -0
- package/dist/emitter.d.ts +10 -0
- package/dist/emitter.js +125 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +131 -0
- package/dist/extra-CgGjbojB.js +4 -0
- package/dist/extra.d.ts +2 -0
- package/dist/fields.d.ts +11 -0
- package/dist/fields.js +95 -0
- package/dist/fire-front.d.ts +610 -0
- package/dist/fire-front.js +1080 -0
- package/dist/fire.d.ts +140 -0
- package/dist/fire.js +194 -0
- package/dist/flame-ramp-VoBKpYnM.js +75 -0
- package/dist/flame-ramp.d.ts +61 -0
- package/dist/flame.d.ts +428 -0
- package/dist/flame.js +817 -0
- package/dist/flipbook.d.ts +7 -0
- package/dist/flipbook.js +23 -0
- package/dist/flocking-shaders.d.ts +48 -0
- package/dist/flocking-sim.d.ts +623 -0
- package/dist/flocking.d.ts +145 -0
- package/dist/flocking.js +1846 -0
- package/dist/fog-B-kBv7g0.js +32 -0
- package/dist/frame-BuvMFBPp.js +4 -0
- package/dist/frame.d.ts +7 -0
- package/dist/gunfire.d.ts +742 -0
- package/dist/gunfire.js +1214 -0
- package/dist/hash-Btsp6fGK.js +7 -0
- package/dist/hash.d.ts +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +60 -0
- package/dist/json.d.ts +53 -0
- package/dist/json.js +239 -0
- package/dist/lit-Dx2tNwP-.js +152 -0
- package/dist/lit.d.ts +18 -0
- package/dist/lit.js +1 -0
- package/dist/mesh.d.ts +16 -0
- package/dist/mesh.js +248 -0
- package/dist/node-system.d.ts +315 -0
- package/dist/node-system.js +384 -0
- package/dist/nodes.d.ts +14 -0
- package/dist/nodes.js +293 -0
- package/dist/obstacles.d.ts +3 -0
- package/dist/obstacles.js +25 -0
- package/dist/over-life.d.ts +14 -0
- package/dist/over-life.js +94 -0
- package/dist/reactive-mask-B8xbyzlk.js +69 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/ribbons.d.ts +22 -0
- package/dist/ribbons.js +165 -0
- package/dist/schedule.d.ts +29 -0
- package/dist/schedule.js +47 -0
- package/dist/settings.d.ts +362 -0
- package/dist/settings.js +707 -0
- package/dist/shader.d.ts +49 -0
- package/dist/shadows.d.ts +26 -0
- package/dist/shadows.js +182 -0
- package/dist/shapes.d.ts +34 -0
- package/dist/shapes.js +81 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/pass.d.ts +53 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/skinned.d.ts +11 -0
- package/dist/skinned.js +104 -0
- package/dist/smoke.d.ts +283 -0
- package/dist/smoke.js +504 -0
- package/dist/soft.d.ts +17 -0
- package/dist/soft.js +55 -0
- package/dist/solid.d.ts +168 -0
- package/dist/solid.js +403 -0
- package/dist/sort.d.ts +3 -0
- package/dist/sort.js +58 -0
- package/dist/space.d.ts +14 -0
- package/dist/space.js +88 -0
- package/dist/stretch.d.ts +7 -0
- package/dist/stretch.js +40 -0
- package/dist/texture.d.ts +8 -0
- package/dist/texture.js +45 -0
- package/dist/view-RKprOPAy.js +30 -0
- package/dist/view-rect-DkeiiUtw.js +13 -0
- package/dist/wrap.d.ts +3 -0
- package/dist/wrap.js +5 -0
- package/package.json +198 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VFXExtension, VFXFlipbook } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `flipbook` feature: blends each lifetime atlas frame into the next instead of stepping. Pass it as `{flipbook}`
|
|
4
|
+
* to `VFX` from `@margoengine/vfx/base`; the root `VFX` has it. Needs `texture` with an atlas whose frames are
|
|
5
|
+
* `'lifetime'`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const flipbook: VFXExtension<VFXFlipbook>;
|
package/dist/flipbook.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MargoError as e } from "@margoengine/math/errors";
|
|
2
|
+
//#region src/flipbook.ts
|
|
3
|
+
function t(t, n, r) {
|
|
4
|
+
if (t.split(n).length !== 2) throw new e("unsupported", "VFX flipbook needs the atlas billboard it was written for; update the flipbook edits");
|
|
5
|
+
return t.replace(n, r);
|
|
6
|
+
}
|
|
7
|
+
var n = /o\.uv=corner;let atlasFrame=min\(u32\(max\(1-p\.positionLife\.w\/p\.rotation\.z,0\.0\)\*(\d+)\.0\),(\d+)u\);o\.cell=vec2f\(f32\(atlasFrame%(\d+)u\),f32\(atlasFrame\/\3u\)\);/, r = "mix(flipbookSample(i.cell,i.uv),flipbookSample(i.nextCell,i.uv),i.blend)", i = {
|
|
8
|
+
validate(t, n) {
|
|
9
|
+
if (!t || typeof t != "object") throw TypeError("VFX flipbook must be an object; pass {}");
|
|
10
|
+
let r = n.texture?.atlas;
|
|
11
|
+
if (!n.texture || !r || r.frames !== "lifetime") throw new e("state", "VFX flipbook needs a texture with an atlas whose frames are 'lifetime'; pass texture and {texture: textureFeature} from @margoengine/vfx/texture");
|
|
12
|
+
},
|
|
13
|
+
billboard: (i) => {
|
|
14
|
+
let a = i.match(n);
|
|
15
|
+
if (!a || Number(a[2]) !== Number(a[1]) - 1) throw new e("unsupported", "VFX flipbook needs the atlas billboard it was written for; update the flipbook edits");
|
|
16
|
+
let o = a[1], s = a[2], c = a[3], l = t(i, a[0], `o.uv=corner;let atlasPos=max(1.0-p.positionLife.w/p.rotation.z,0.0)*${o}.0;let atlasFrame=min(u32(atlasPos),${s}u);let atlasNext=min(atlasFrame+1u,${s}u);o.cell=vec2f(f32(atlasFrame%${c}u),f32(atlasFrame/${c}u));o.nextCell=vec2f(f32(atlasNext%${c}u),f32(atlasNext/${c}u));o.blend=atlasPos-f32(atlasFrame);`), u = "let t=textureSample(sprite,spriteSampler,(i.cell+", d = l.indexOf(u), f = l.indexOf("));if(t.a", d);
|
|
17
|
+
if (d < 0 || f < 0 || l.indexOf(u, d + 1) >= 0) throw new e("unsupported", "VFX flipbook needs the atlas billboard it was written for; update the flipbook edits");
|
|
18
|
+
let p = l.slice(d + 49, f).replaceAll("i.uv", "uv"), m = l.slice(0, d) + `let t=${r};` + l.slice(f + 3), h = `fn flipbookSample(cell:vec2f,uv:vec2f)->vec4f{return textureSample(sprite,spriteSampler,(cell+${p}));}\n`;
|
|
19
|
+
return t(t(m, "@location(2) @interpolate(flat) cell:vec2f}", "@location(2) @interpolate(flat) cell:vec2f,@location(4) @interpolate(flat) nextCell:vec2f,@location(5) @interpolate(flat) blend:f32}"), "@fragment fn fragment", h + "@fragment fn fragment");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { i as flipbook };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Floats of the simulation uniform: ten vec4 of parameters, then 32 attractor, 32 predator and 64 obstacle vec4, then
|
|
3
|
+
* the high tier's vec4, then the flow lattice: origin, spacing with an on flag and 64 velocities, then 4 field
|
|
4
|
+
* obstacles of five vec4 each, then wander's vec4, then the path: two vec4 of parameters and 16 points.
|
|
5
|
+
*/
|
|
6
|
+
export declare const FLOCK_SIM_FLOATS: number;
|
|
7
|
+
/** First float of wander's vec4 in the simulation uniform. */
|
|
8
|
+
export declare const FLOCK_SIM_WANDER_AT: number;
|
|
9
|
+
/** First float of the path in the simulation uniform: two vec4 of parameters, then 16 points. */
|
|
10
|
+
export declare const FLOCK_SIM_PATH_AT: number;
|
|
11
|
+
/** First float of the field obstacles in the simulation uniform: five vec4 a field. */
|
|
12
|
+
export declare const FLOCK_SIM_FIELDS_AT: number;
|
|
13
|
+
/** Pass 1: clears the bucket counts. */
|
|
14
|
+
export declare const FLOCK_CLEAR_WGSL: string;
|
|
15
|
+
/** Pass 2: hashes each boid into its bucket and takes a slot there by an atomic add (in any order). */
|
|
16
|
+
export declare const FLOCK_COUNT_WGSL: string;
|
|
17
|
+
/** Pass 3: Blelloch (1990) exclusive scan of each 256-bucket block of counts into bucket starts and block sums. */
|
|
18
|
+
export declare const FLOCK_SCAN_BLOCKS_WGSL: string;
|
|
19
|
+
/** Pass 4: one workgroup scans the block sums (at most 256 blocks, so 65,536 buckets) into block starts. */
|
|
20
|
+
export declare const FLOCK_SCAN_SUMS_WGSL: string;
|
|
21
|
+
/** Pass 5: adds each block's start to its buckets' starts. */
|
|
22
|
+
export declare const FLOCK_ADD_OFFSETS_WGSL: string;
|
|
23
|
+
/** Pass 6: writes each boid's index at its bucket start plus its slot (an order that varies run to run). */
|
|
24
|
+
export declare const FLOCK_SCATTER_WGSL: string;
|
|
25
|
+
/**
|
|
26
|
+
* Pass 7: ranks each boid among its bucket by index and copies it there, so a bucket lists its boids by ascending
|
|
27
|
+
* index on every run: the step then visits neighbours in one fixed order and its result is the same every time.
|
|
28
|
+
*/
|
|
29
|
+
export declare const FLOCK_RANK_WGSL: string;
|
|
30
|
+
/** Pass 8: the rules over the 3 x 3 x 3 cell neighbourhood, attractors, predators, obstacles, bounds and integration. */
|
|
31
|
+
export declare const FLOCK_STEP_WGSL: string;
|
|
32
|
+
/** Instanced boid draw: each instance reads its boid, faces its velocity, banks, and flaps or swims by vertex weight. */
|
|
33
|
+
export declare const FLOCK_RENDER_WGSL = "\nstruct Boid {\n pos: vec4f,\n vel: vec4f,\n}\nstruct RenderUniform {\n camera: mat4x4f,\n\n eyeScale: vec4f,\n\n lightDirAmb: vec4f,\n\n primaryFlap: vec4f,\n\n accentMode: vec4f,\n\n lightColorEncode: vec4f,\n\n ambientLit: vec4f,\n}\n@group(0) @binding(0) var<uniform> r: RenderUniform;\n@group(0) @binding(1) var<storage, read> boids: array<Boid>;\n\n@group(0) @binding(2) var<storage, read> meshCorners: array<vec4f>;\nstruct Out {\n @builtin(position) clip: vec4f,\n @location(0) normal: vec3f,\n @location(1) color: vec3f,\n @location(2) world: vec3f,\n}\n\nfn boidHash(v: u32) -> f32 {\n var x = v * 747796405u + 2891336453u;\n x = ((x >> ((x >> 28u) + 4u)) ^ x) * 277803737u;\n x = (x >> 22u) ^ x;\n return f32(x & 0xffffu) / 65535.0;\n}\nfn encodeSrgb(c: vec3f) -> vec3f {\n let k = max(c, vec3f(0.0));\n return select(1.055 * pow(k, vec3f(1.0 / 2.4)) - 0.055, k * 12.92, k <= vec3f(0.0031308));\n}\n@vertex\nfn vertex(@builtin(vertex_index) corner: u32, @builtin(instance_index) instance: u32) -> Out {\n let b = boids[instance];\n let cPos = meshCorners[corner * 2u];\n let cNrm = meshCorners[corner * 2u + 1u];\n var lp = cPos.xyz;\n var ln = cNrm.xyz;\n let w = cPos.w;\n let phase = b.pos.w;\n let amp = r.primaryFlap.w;\n if (r.accentMode.w < 0.5) {\n\n let flap = sin(phase) * amp * w;\n lp.y = lp.y + flap * abs(lp.x);\n let tilt = flap * select(-1.0, 1.0, lp.x >= 0.0) * 0.45;\n ln = normalize(vec3f(ln.x - tilt, ln.y + 0.1, ln.z));\n } else {\n\n let wave = sin(phase + lp.z * 3.5) * amp * w;\n lp.x = lp.x + wave * 0.55;\n let twist = cos(phase + lp.z * 3.5) * amp * w * 0.35;\n ln = normalize(vec3f(ln.x, ln.y, ln.z - twist));\n }\n\n let spd = length(b.vel.xyz);\n let fwd = select(vec3f(0.0, 0.0, 1.0), b.vel.xyz / max(spd, 1e-5), spd > 1e-5);\n let upHint = select(vec3f(0.0, 1.0, 0.0), vec3f(1.0, 0.0, 0.0), abs(fwd.y) > 0.96);\n let right0 = normalize(cross(upHint, fwd));\n let up0 = cross(fwd, right0);\n let cb = cos(b.vel.w);\n let sb = sin(b.vel.w);\n let right = right0 * cb + up0 * sb;\n let up = -right0 * sb + up0 * cb;\n let world = b.pos.xyz + (right * lp.x + up * lp.y + fwd * lp.z) * r.eyeScale.w;\n var o: Out;\n o.clip = r.camera * vec4f(world, 1.0);\n o.normal = normalize(right * ln.x + up * ln.y + fwd * ln.z);\n o.color = mix(r.primaryFlap.rgb, r.accentMode.rgb, clamp(cNrm.w * 0.72 + boidHash(instance) * 0.28, 0.0, 1.0));\n o.world = world;\n return o;\n}\n@fragment\nfn fragment(i: Out) -> @location(0) vec4f {\n\n let n = normalize(i.normal);\n let v = normalize(r.eyeScale.xyz - i.world);\n let ndl = max(dot(n, r.lightDirAmb.xyz), 0.0);\n let hemi = 0.5 + 0.5 * n.y;\n let amb = r.lightDirAmb.w;\n let rim = pow(1.0 - max(dot(n, v), 0.0), 2.5) * 0.22;\n let lit = amb * (0.65 + 0.35 * hemi) + (1.0 - amb) * ndl;\n let rgb = i.color * r.lightColorEncode.rgb * lit + r.accentMode.rgb * rim;\n return vec4f(select(rgb, encodeSrgb(rgb), r.lightColorEncode.w > 0.5), 1.0);\n}\n";
|
|
34
|
+
/**
|
|
35
|
+
* The boid draw lit by the scene (`GPUFlockOptions.lit`): the engine's sun as core's Lambert term (colour times
|
|
36
|
+
* intensity, n.l / pi), through `shadowLit` of `Shadows` when given; the ambient split into the light from above and
|
|
37
|
+
* from below by the view factors (1 + n_y) / 2 and (1 - n_y) / 2 with the ground sending back its albedo g, 2A / (1 + g)
|
|
38
|
+
* from above and g times that from below, which keeps the ambient's mean over every normal (as `lit` of
|
|
39
|
+
* `@margoengine/vfx`); and `clusterLighting` of `Clustered` at roughness 1, no metal. `declarations` are the light and
|
|
40
|
+
* shadow sources' WGSL at bind group 1.
|
|
41
|
+
*/
|
|
42
|
+
export declare function flockRenderWGSL(declarations: string, lights: boolean, shadows: boolean): string;
|
|
43
|
+
/** Vertices of the inspected boid's overlay in {@link FLOCK_DEBUG_WGSL} (274 line segments). */
|
|
44
|
+
export declare const FLOCK_DEBUG_VERTEX_COUNT = 548;
|
|
45
|
+
/** Debug overlay, every boid: a line along its velocity, blue when slow and red at max speed. */
|
|
46
|
+
export declare const FLOCK_VELOCITY_WGSL: string;
|
|
47
|
+
/** Debug overlay, the inspected boid: bounds, its grid cell and neighbourhood, vision cone, radii and steering vectors. */
|
|
48
|
+
export declare const FLOCK_DEBUG_WGSL: string;
|