@margoengine/vfx 0.1.0 → 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 -201
- package/NOTICE +4 -4
- package/README.md +2241 -1642
- package/dist/{base-C9upJytz.js → base-LGs65K7K.js} +174 -123
- package/dist/base.d.ts +104 -2
- package/dist/base.js +1 -1
- package/dist/blown-sand.js +3 -3
- package/dist/clouds.d.ts +12 -4
- package/dist/clouds.js +35 -18
- package/dist/compat-BFjXAQuu.js +14 -0
- package/dist/debris.d.ts +43 -0
- package/dist/debris.js +33 -1
- package/dist/dust-current.d.ts +66 -0
- package/dist/dust-current.js +92 -0
- package/dist/fire-front.d.ts +72 -1
- package/dist/fire-front.js +309 -69
- package/dist/fire.d.ts +24 -3
- package/dist/fire.js +114 -93
- package/dist/flame.d.ts +171 -3
- package/dist/flame.js +343 -131
- 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/gunfire.d.ts +52 -6
- package/dist/gunfire.js +108 -98
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/json.js +2 -0
- package/dist/lit-Dx2tNwP-.js +152 -0
- package/dist/lit.d.ts +8 -1
- package/dist/lit.js +1 -105
- package/dist/mesh.d.ts +2 -0
- package/dist/mesh.js +92 -69
- package/dist/over-life.js +16 -15
- package/dist/reactive-mask-B8xbyzlk.js +69 -0
- package/dist/ribbons.d.ts +4 -2
- package/dist/ribbons.js +87 -73
- package/dist/settings.js +1 -1
- package/dist/shader.d.ts +5 -0
- package/dist/shared/fog.d.ts +33 -33
- package/dist/shared/pass.d.ts +53 -53
- package/dist/shared/settings.d.ts +89 -89
- package/dist/smoke.d.ts +72 -4
- package/dist/smoke.js +280 -56
- package/package.json +200 -192
package/dist/over-life.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { MargoError as e } from "@margoengine/math/errors";
|
|
2
2
|
//#region src/over-life.ts
|
|
3
|
-
var t = 27, n = (t, n, r) => {
|
|
3
|
+
var t = 27, n = /var p=Particle\(particles\[at\],particles\[at\+1\],[^;]*\);/, r = (t, n, r) => {
|
|
4
4
|
if (t.split(n).length !== 2) throw new e("unsupported", "VFX over-life needs its simulation shader; update the lifetime edits");
|
|
5
5
|
return t.replace(n, r);
|
|
6
|
-
},
|
|
6
|
+
}, i = (e) => `struct OverLife {counts:vec4u,values:array<vec4f,32>}
|
|
7
7
|
@group(0) @binding(${e}) var<uniform> lifeCurves:OverLife;
|
|
8
8
|
fn lifeValue(channel:u32,t:f32)->f32 {
|
|
9
9
|
let n=lifeCurves.counts[channel];if(n==0u){return select(1.0,0.0,channel==0u);}
|
|
10
10
|
let x=clamp(t,0.0,1.0)*f32(n-1u);let k=min(u32(x),n-2u);let base=channel*8u;
|
|
11
11
|
let a=lifeCurves.values[base+k/4u][k%4u];let j=k+1u;let b=lifeCurves.values[base+j/4u][j%4u];return mix(a,b,x-f32(k));
|
|
12
12
|
}
|
|
13
|
-
`,
|
|
14
|
-
${
|
|
13
|
+
`, a = `@group(0) @binding(26) var<storage,read_write> lifeBirth:array<vec4f>;
|
|
14
|
+
${i(27)}`, o = `${i(t)}fn spinIntegral(t:f32)->f32 {
|
|
15
15
|
let n=lifeCurves.counts.x;if(n<2u){return 0.0;}let end=clamp(t,0.0,1.0);var sum=0.0;
|
|
16
16
|
for(var k=0u;k+1u<n;k++){let a=f32(k)/f32(n-1u);let b=min(end,f32(k+1u)/f32(n-1u));if(b>a){sum+=(lifeValue(0u,a)+lifeValue(0u,b))*(b-a)*0.5;}}
|
|
17
17
|
return sum;
|
|
18
18
|
}
|
|
19
19
|
fn drawnSpin(life:f32,left:f32)->f32 {return select(0.0,life*spinIntegral(1-left/life),life>0);}
|
|
20
|
-
`,
|
|
20
|
+
`, s = "let angle=p.rotation.x+p.rotation.y*(p.rotation.z-p.positionLife.w);", c = {
|
|
21
21
|
validate(e) {
|
|
22
22
|
if (!e || typeof e != "object" || !Object.keys(e).some((e) => [
|
|
23
23
|
"spin",
|
|
@@ -39,11 +39,12 @@ fn drawnSpin(life:f32,left:f32)->f32 {return select(0.0,life*spinIntegral(1-left
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
simulation(e) {
|
|
42
|
-
|
|
42
|
+
let t = n.exec(e)?.[0] ?? "";
|
|
43
|
+
return e = r(e, t, t + "var coldLife=particles[cold+1].z;var birthNow=lifeBirth[i];"), e.includes("var<uniform> space:Space;") && (e = r(e, " p.positionLife.w-=dt;", " if(p.positionLife.w>0 && space.births.w>0){birthNow=vec4f((space.delta*vec4f(birthNow.xyz,0)).xyz,birthNow.w);lifeBirth[i]=birthNow;}\n p.positionLife.w-=dt;")), e = e.replace("fn update(", a + "fn update("), e = r(e, " particles[cold]=p.color;particles[cold+1]=p.rotation;", " lifeBirth[i]=p.velocitySize;birthNow=p.velocitySize;coldLife=p.rotation.z;\n p.velocitySize=vec4f(p.velocitySize.xyz*lifeValue(1u,0.0),p.velocitySize.w);\n particles[cold]=p.color;particles[cold+1]=p.rotation;"), r(e, " p.positionLife=vec4f(p.positionLife.xyz+p.velocitySize.xyz*dt,p.positionLife.w);", " let totalLife=coldLife;let age=clamp(1-p.positionLife.w/totalLife,0.0,1.0);\n let previousAge=max(0.0,age-dt/totalLife);let birth=birthNow;\n var velocity=p.velocitySize.xyz+birth.xyz*(lifeValue(1u,age)-lifeValue(1u,previousAge));\n let cap=lifeValue(3u,age);let speed=length(velocity);\n if(lifeCurves.counts.w>0u && speed>cap){velocity*=cap/max(speed,1e-20);}\n p.velocitySize=vec4f(velocity,birth.w*lifeValue(2u,age));\n p.positionLife=vec4f(p.positionLife.xyz+p.velocitySize.xyz*dt,p.positionLife.w);");
|
|
43
44
|
},
|
|
44
45
|
billboard(t) {
|
|
45
|
-
if (t.split(
|
|
46
|
-
return t.replace(
|
|
46
|
+
if (t.split(s).length !== 2) throw new e("unsupported", "VFX over-life spin needs the billboard angle; update the spin edit");
|
|
47
|
+
return t.replace(s, s.replace(";", "+drawnSpin(p.rotation.z,p.positionLife.w);")).replace("@vertex fn vertex(", o + "@vertex fn vertex(");
|
|
47
48
|
},
|
|
48
49
|
create(e, n, r) {
|
|
49
50
|
let i = e.device.createBuffer({
|
|
@@ -51,17 +52,17 @@ fn drawnSpin(life:f32,left:f32)->f32 {return select(0.0,life*spinIntegral(1-left
|
|
|
51
52
|
usage: 136
|
|
52
53
|
});
|
|
53
54
|
r.push(i);
|
|
54
|
-
let
|
|
55
|
+
let a = e.device.createBuffer({
|
|
55
56
|
size: 528,
|
|
56
57
|
usage: 72
|
|
57
58
|
});
|
|
58
|
-
r.push(
|
|
59
|
+
r.push(a);
|
|
59
60
|
let s = /* @__PURE__ */ new Float32Array(132), c = new Uint32Array(s.buffer, 0, 4), l = {
|
|
60
61
|
binding: t,
|
|
61
|
-
resource: { buffer:
|
|
62
|
+
resource: { buffer: a }
|
|
62
63
|
};
|
|
63
64
|
return e.spin = {
|
|
64
|
-
code:
|
|
65
|
+
code: o,
|
|
65
66
|
entry: l
|
|
66
67
|
}, {
|
|
67
68
|
render: [l],
|
|
@@ -70,7 +71,7 @@ fn drawnSpin(life:f32,left:f32)->f32 {return select(0.0,life*spinIntegral(1-left
|
|
|
70
71
|
resource: { buffer: i }
|
|
71
72
|
}, {
|
|
72
73
|
binding: 27,
|
|
73
|
-
resource: { buffer:
|
|
74
|
+
resource: { buffer: a }
|
|
74
75
|
}],
|
|
75
76
|
write(t) {
|
|
76
77
|
let n = e.options.overLife ?? {};
|
|
@@ -84,10 +85,10 @@ fn drawnSpin(life:f32,left:f32)->f32 {return select(0.0,life*spinIntegral(1-left
|
|
|
84
85
|
let r = n[t], i = typeof r == "number" ? [r, r] : r;
|
|
85
86
|
i && (c[e] = i.length, s.set(i, 4 + e * 32));
|
|
86
87
|
}
|
|
87
|
-
t.device.queue.writeBuffer(
|
|
88
|
+
t.device.queue.writeBuffer(a, 0, s);
|
|
88
89
|
}
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
//#endregion
|
|
93
|
-
export {
|
|
94
|
+
export { c as overLife };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region ../shared/reactive-mask.js
|
|
2
|
+
var e = Symbol.for("margoengine.optional.reactive-mask"), t = Symbol.for("margoengine.optional.reactive-mask.demand"), n = Symbol.for("margoengine.optional.reactive-mask.target"), r = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function i(t, n) {
|
|
4
|
+
let r = t[e];
|
|
5
|
+
r && r.encoder === t.encoder && r.view === t.view ? r.textures.includes(n) || r.textures.push(n) : t[e] = {
|
|
6
|
+
encoder: t.encoder,
|
|
7
|
+
view: t.view,
|
|
8
|
+
textures: [n]
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function a(e, n) {
|
|
12
|
+
let i = e[t], a = r.get(n);
|
|
13
|
+
return a || r.set(n, a = {
|
|
14
|
+
encoder: void 0,
|
|
15
|
+
reads: void 0,
|
|
16
|
+
wanted: !1
|
|
17
|
+
}), a.encoder !== e.encoder && (a.wanted = i !== void 0 && a.reads !== i, a.reads = i, a.encoder = e.encoder), a.wanted;
|
|
18
|
+
}
|
|
19
|
+
function o(e) {
|
|
20
|
+
let t = e.descriptor.multisample?.count ?? 1, r = e[n];
|
|
21
|
+
if (!r || r.device !== e.device || r.width !== e.width || r.height !== e.height || r.samples !== t) {
|
|
22
|
+
r?.mask.destroy(), r?.multi?.destroy();
|
|
23
|
+
let i = GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING, a = [e.width, e.height];
|
|
24
|
+
r = e[n] = {
|
|
25
|
+
device: e.device,
|
|
26
|
+
width: e.width,
|
|
27
|
+
height: e.height,
|
|
28
|
+
samples: t,
|
|
29
|
+
mask: e.device.createTexture({
|
|
30
|
+
label: "reactive particle mask",
|
|
31
|
+
size: a,
|
|
32
|
+
format: "r8unorm",
|
|
33
|
+
usage: i
|
|
34
|
+
}),
|
|
35
|
+
multi: t > 1 ? e.device.createTexture({
|
|
36
|
+
label: "reactive particle mask (multisampled)",
|
|
37
|
+
size: a,
|
|
38
|
+
format: "r8unorm",
|
|
39
|
+
sampleCount: t,
|
|
40
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
41
|
+
}) : void 0,
|
|
42
|
+
encoder: void 0,
|
|
43
|
+
view: void 0
|
|
44
|
+
}, r.maskView = r.mask.createView(), r.multiView = r.multi?.createView();
|
|
45
|
+
}
|
|
46
|
+
let a = r.encoder !== e.encoder || r.view !== e.view;
|
|
47
|
+
return r.encoder = e.encoder, r.view = e.view, i(e, r.mask), {
|
|
48
|
+
view: r.multiView ?? r.maskView,
|
|
49
|
+
resolveTarget: r.multi ? r.maskView : void 0,
|
|
50
|
+
loadOp: a ? "clear" : "load",
|
|
51
|
+
clearValue: [
|
|
52
|
+
0,
|
|
53
|
+
0,
|
|
54
|
+
0,
|
|
55
|
+
0
|
|
56
|
+
],
|
|
57
|
+
storeOp: "store"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
var s = {
|
|
61
|
+
operation: "max",
|
|
62
|
+
srcFactor: "one",
|
|
63
|
+
dstFactor: "one"
|
|
64
|
+
}, c = {
|
|
65
|
+
color: s,
|
|
66
|
+
alpha: s
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { a as n, o as r, c as t };
|
package/dist/ribbons.d.ts
CHANGED
|
@@ -8,13 +8,15 @@ export declare const MAX_RIBBON_POINTS = 4194304;
|
|
|
8
8
|
* so a young particle's ribbon is shorter. A dead slot is moved outside the clip volume. The strip's side is
|
|
9
9
|
* perpendicular to the ribbon (the neighbours' difference, or the next pair's where the newest record is the particle
|
|
10
10
|
* itself) and to the eye, so it shows its face; where neither gives a direction the strip has no width. Alpha falls from the particle's own (with its life
|
|
11
|
-
* fade) at the head to 0 at the tail, and across the width as 1 - e^2 (e from -1 to 1).
|
|
11
|
+
* fade) at the head to 0 at the tail, and across the width as 1 - e^2 (e from -1 to 1). `reactive` writes that alpha
|
|
12
|
+
* as the strip's coverage of TAA's reactive mask.
|
|
12
13
|
*/
|
|
13
14
|
export declare const ribbonShader: string;
|
|
14
15
|
/**
|
|
15
16
|
* The `ribbons` feature: a camera-facing ribbon behind every particle through its last positions (`points`, recorded
|
|
16
17
|
* every `interval` seconds), for smoke and magic trails. Pass it as `{ribbons}` to `VFX` from `@margoengine/vfx/base`;
|
|
17
18
|
* the root `VFX` has it. Ribbons draw after the billboards in their own pass, alpha blended and depth tested, in slot
|
|
18
|
-
* order; `heads: false` leaves the billboards out.
|
|
19
|
+
* order; `heads: false` leaves the billboards out. Like the billboards, the strips draw their coverage into the frame's
|
|
20
|
+
* shared reactive mask while TAA reads masks (the effect's `reactive` option), as they have no motion vectors.
|
|
19
21
|
*/
|
|
20
22
|
export declare const ribbons: VFXExtension<VFXRibbons>;
|
package/dist/ribbons.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { t as e } from "./frame-BuvMFBPp.js";
|
|
2
2
|
import { t } from "./view-rect-DkeiiUtw.js";
|
|
3
|
+
import { n, r, t as i } from "./reactive-mask-B8xbyzlk.js";
|
|
3
4
|
//#region src/ribbons.ts
|
|
4
|
-
var
|
|
5
|
+
var a = 4194304, o = "\nstruct Ribbon {control:vec4u,shape:vec4f,eye:vec4f}\n@group(0) @binding(14) var<uniform> ribbon:Ribbon;\n", s = `
|
|
5
6
|
@group(0) @binding(13) var<storage,read_write> ribbonHistory:array<vec4f>;
|
|
6
|
-
${
|
|
7
|
+
${o}
|
|
7
8
|
@compute @workgroup_size(256) fn ribbonRecord(@builtin(global_invocation_id) id:vec3u){
|
|
8
9
|
if(id.x>=f.control.x){return;}let p=particles[id.x*2];if(p.w<=0){return;}
|
|
9
10
|
ribbonHistory[id.x*ribbon.control.z+(ribbon.control.x-1u)%ribbon.control.z]=vec4f(p.xyz,particles[f.control.x*2+id.x*2+1].x+1);
|
|
10
|
-
}`,
|
|
11
|
+
}`, c = e + `
|
|
11
12
|
@group(0) @binding(1) var<storage,read> particles:array<vec4f>;
|
|
12
13
|
@group(0) @binding(13) var<storage,read> ribbonHistory:array<vec4f>;
|
|
13
|
-
${
|
|
14
|
+
${o}
|
|
14
15
|
struct Out {@builtin(position) clip:vec4f,@location(0) color:vec4f,@location(1) edge:f32}
|
|
15
16
|
fn ribbonPoint(slot:u32,k:u32,head:vec3f)->vec3f {
|
|
16
17
|
if(k==0u){return head;}return ribbonHistory[slot*ribbon.control.z+(ribbon.control.x-k)%ribbon.control.z].xyz;
|
|
@@ -28,35 +29,36 @@ fn ribbonPoint(slot:u32,k:u32,head:vec3f)->vec3f {
|
|
|
28
29
|
o.clip=f.camera*vec4f(p+side*inverseSqrt(max(s,1e-24))*select(0.0,e*ribbon.shape.x*0.5,s>1e-12),1);
|
|
29
30
|
o.color=vec4f(color.rgb,color.a*clamp(head.w/rotation.z,0.0,1.0)*(1-f32(v/2u)/f32(ribbon.control.w-1u)));return o;
|
|
30
31
|
}
|
|
31
|
-
@fragment fn fragment(i:Out)->@location(0) vec4f {return vec4f(i.color.rgb,i.color.a*(1-i.edge*i.edge));}
|
|
32
|
+
@fragment fn fragment(i:Out)->@location(0) vec4f {return vec4f(i.color.rgb,i.color.a*(1-i.edge*i.edge));}
|
|
33
|
+
@fragment fn reactive(i:Out)->@location(0) vec4f {return vec4f(clamp(i.color.a*(1-i.edge*i.edge),0.0,1.0),0,0,1);}`, l = (e) => e.points ?? 16, u = {
|
|
32
34
|
validate(e, t) {
|
|
33
35
|
if (!e || typeof e != "object") throw TypeError("VFX ribbons must be an object; pass e.g. {points: 16, interval: 1 / 60}");
|
|
34
|
-
let
|
|
35
|
-
if (!Number.isInteger(
|
|
36
|
-
if (typeof
|
|
36
|
+
let n = l(e), r = e.interval ?? 1 / 60;
|
|
37
|
+
if (!Number.isInteger(n) || n < 2 || n > 64) throw RangeError(`VFX ribbons points is ${n}; pass a whole number from 2 to 64`);
|
|
38
|
+
if (typeof r != "number" || !(r >= 0 && r <= 1)) throw RangeError("VFX ribbons interval must be 0 to 1 seconds; pass e.g. 1 / 60, or 0 for every frame");
|
|
37
39
|
if (e.width !== void 0 && !(typeof e.width == "number" && Number.isFinite(Math.fround(e.width)) && e.width > 0)) throw RangeError("VFX ribbons width must be a world distance above 0; pass e.g. 0.1");
|
|
38
40
|
if (e.heads !== void 0 && typeof e.heads != "boolean") throw TypeError("VFX ribbons heads must be true or false; pass a boolean");
|
|
39
|
-
if ((t.capacity ?? 1e6) * (
|
|
41
|
+
if ((t.capacity ?? 1e6) * (n - 1) > 4194304) throw RangeError(`VFX ribbons need capacity x (points - 1) at most ${a}; lower capacity or points`);
|
|
40
42
|
},
|
|
41
|
-
simulation: (e) => e +
|
|
42
|
-
create(e,
|
|
43
|
-
let { device:
|
|
44
|
-
size:
|
|
43
|
+
simulation: (e) => e + s,
|
|
44
|
+
create(e, a, o) {
|
|
45
|
+
let { device: s, capacity: u, options: d } = e, f = l(a), p = f - 1, m = s.createBuffer({
|
|
46
|
+
size: u * p * 16,
|
|
45
47
|
usage: GPUBufferUsage.STORAGE
|
|
46
48
|
});
|
|
47
|
-
|
|
48
|
-
let
|
|
49
|
+
o.push(m);
|
|
50
|
+
let h = s.createBuffer({
|
|
49
51
|
size: 48,
|
|
50
52
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
51
53
|
});
|
|
52
|
-
|
|
53
|
-
let
|
|
54
|
+
o.push(h);
|
|
55
|
+
let g = s.createComputePipeline({
|
|
54
56
|
layout: "auto",
|
|
55
57
|
compute: {
|
|
56
58
|
module: e.module,
|
|
57
59
|
entryPoint: "ribbonRecord"
|
|
58
60
|
}
|
|
59
|
-
}),
|
|
61
|
+
}), _ = (t) => s.createBindGroup({
|
|
60
62
|
layout: t,
|
|
61
63
|
entries: [
|
|
62
64
|
{
|
|
@@ -69,83 +71,95 @@ fn ribbonPoint(slot:u32,k:u32,head:vec3f)->vec3f {
|
|
|
69
71
|
},
|
|
70
72
|
{
|
|
71
73
|
binding: 13,
|
|
72
|
-
resource: { buffer:
|
|
74
|
+
resource: { buffer: m }
|
|
73
75
|
},
|
|
74
76
|
{
|
|
75
77
|
binding: 14,
|
|
76
|
-
resource: { buffer:
|
|
78
|
+
resource: { buffer: h }
|
|
77
79
|
}
|
|
78
80
|
]
|
|
79
|
-
}),
|
|
81
|
+
}), v = _(g.getBindGroupLayout(0)), y = /* @__PURE__ */ new Float32Array(12), b = new Uint32Array(y.buffer), x = /* @__PURE__ */ new Map(), S = {
|
|
80
82
|
view: void 0,
|
|
81
83
|
loadOp: "load",
|
|
82
84
|
storeOp: "store"
|
|
83
|
-
},
|
|
85
|
+
}, C = {
|
|
84
86
|
view: void 0,
|
|
85
87
|
depthReadOnly: !0
|
|
86
|
-
},
|
|
87
|
-
colorAttachments: [
|
|
88
|
-
depthStencilAttachment:
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
}, w = {
|
|
89
|
+
colorAttachments: [S],
|
|
90
|
+
depthStencilAttachment: C
|
|
91
|
+
}, T = [], E = {
|
|
92
|
+
colorAttachments: T,
|
|
93
|
+
depthStencilAttachment: C
|
|
94
|
+
}, D = {}, O, k = 0, A = Infinity, j = !1, M = () => {
|
|
95
|
+
let e = d.ribbons;
|
|
96
|
+
if (!e || l(e) !== f) throw TypeError("VFX ribbons and their points are fixed at attach; attach a new VFX to change them");
|
|
92
97
|
return e;
|
|
93
98
|
};
|
|
94
99
|
return {
|
|
95
100
|
reset() {
|
|
96
|
-
|
|
101
|
+
s.queue.writeBuffer(m, 0, new Uint8Array(m.size)), k = 0, A = Infinity;
|
|
97
102
|
},
|
|
98
|
-
hides: () =>
|
|
103
|
+
hides: () => M().heads === !1,
|
|
99
104
|
write(e) {
|
|
100
|
-
let t =
|
|
101
|
-
|
|
105
|
+
let t = M(), n = t.interval ?? 1 / 60;
|
|
106
|
+
A += e.delta, j = A >= n, j && (k++, A = A - n >= n ? 0 : A - n), b[0] = k, b[1] = Math.min(k, p), b[2] = p, b[3] = f, y[4] = t.width ?? d.size ?? .1, y.set(e.camera.position, 8), e.device.queue.writeBuffer(h, 0, y);
|
|
102
107
|
},
|
|
103
108
|
run(e) {
|
|
104
|
-
|
|
109
|
+
j && (e.setPipeline(g), e.setBindGroup(0, v), e.dispatchWorkgroups(Math.ceil(u / 256)));
|
|
105
110
|
},
|
|
106
|
-
draw(
|
|
107
|
-
let
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
111
|
+
draw(a) {
|
|
112
|
+
let o = a.descriptor.depthStencil.format, l = a.descriptor.multisample?.count ?? 1, p = a.format + ":" + o + ":" + l, m = (e) => {
|
|
113
|
+
let t = x.get(p + (e ? ":reactive" : ""));
|
|
114
|
+
if (!t) {
|
|
115
|
+
O ??= s.createShaderModule({ code: c });
|
|
116
|
+
let n = s.createRenderPipeline({
|
|
117
|
+
layout: "auto",
|
|
118
|
+
vertex: {
|
|
119
|
+
module: O,
|
|
120
|
+
entryPoint: "vertex"
|
|
121
|
+
},
|
|
122
|
+
fragment: {
|
|
123
|
+
module: O,
|
|
124
|
+
entryPoint: e ? "reactive" : "fragment",
|
|
125
|
+
targets: [e ? {
|
|
126
|
+
format: "r8unorm",
|
|
127
|
+
blend: i
|
|
128
|
+
} : {
|
|
129
|
+
format: a.format,
|
|
130
|
+
blend: {
|
|
131
|
+
color: {
|
|
132
|
+
srcFactor: "src-alpha",
|
|
133
|
+
dstFactor: "one-minus-src-alpha"
|
|
134
|
+
},
|
|
135
|
+
alpha: {
|
|
136
|
+
srcFactor: "one",
|
|
137
|
+
dstFactor: "one-minus-src-alpha"
|
|
138
|
+
}
|
|
129
139
|
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
}]
|
|
141
|
+
},
|
|
142
|
+
primitive: { topology: "triangle-strip" },
|
|
143
|
+
multisample: a.descriptor.multisample,
|
|
144
|
+
depthStencil: {
|
|
145
|
+
format: o,
|
|
146
|
+
depthWriteEnabled: !1,
|
|
147
|
+
depthCompare: "greater-equal"
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
t = [n, _(n.getBindGroupLayout(0))], x.set(p + (e ? ":reactive" : ""), t);
|
|
151
|
+
}
|
|
152
|
+
return t;
|
|
153
|
+
};
|
|
154
|
+
S.view = a.color, C.view = a.depth, C.stencilReadOnly = o.includes("stencil") ? !0 : void 0;
|
|
155
|
+
let h = (n, [r, i]) => {
|
|
156
|
+
let o = a.encoder.beginRenderPass(n);
|
|
157
|
+
o.setPipeline(r), o.setBindGroup(0, i), t(o, a), o.draw(f * 2, u), o.end(), e.stats.drawCalls++;
|
|
158
|
+
};
|
|
159
|
+
h(w, m(!1)), (d.reactive ?? n(a, D)) && (T[0] = r(a), h(E, m(!0)));
|
|
146
160
|
}
|
|
147
161
|
};
|
|
148
162
|
}
|
|
149
163
|
};
|
|
150
164
|
//#endregion
|
|
151
|
-
export {
|
|
165
|
+
export { a as MAX_RIBBON_POINTS, c as ribbonShader, u as ribbons };
|
package/dist/settings.js
CHANGED
|
@@ -492,7 +492,7 @@ var z = (e, t, n, r, a, o, s, c) => i(e, t, n, r, a, o, s, c, !0), B = [
|
|
|
492
492
|
.12,
|
|
493
493
|
.04
|
|
494
494
|
], 0, 1, "The colour the flame edge ramps to (linear RGB), used while flames.ramp is above 0."),
|
|
495
|
-
z("flames.core", "flames", 2200, 1200, 3e3, 10, "K", "Temperature of the hot core (its blackbody colour, through the
|
|
495
|
+
z("flames.core", "flames", 2200, 1200, 3e3, 10, "K", "Temperature of the hot core (its blackbody colour, through the tonemap of the frame, sets the colour of the core). At 2200 a hearth keeps its own colours."),
|
|
496
496
|
z("flames.edge", "flames", 1e3, 600, 2e3, 10, "K", "Temperature of the cool edge and the tips (deep orange to red). At 1000 a hearth keeps its own colours."),
|
|
497
497
|
z("flames.peak", "flames", 1, .05, 16, .01, "", "The brightest channel a flame pixel may show, scene-linear: 1 is display white on an 8-bit target; raise it under a tonemap so the core blooms."),
|
|
498
498
|
z("flames.flicker", "flames", 1, 0, 3, .01, "x", "Puffing of the flames and flicker of their light as a multiple of the physical (Cetegen and Ahmed 1993); 0 holds them steady."),
|
package/dist/shader.d.ts
CHANGED
|
@@ -34,6 +34,11 @@ export declare const billboardShader: string;
|
|
|
34
34
|
* uv, its screen derivatives and WebGPU's standard 4x sample offsets) lies in the unit square.
|
|
35
35
|
*/
|
|
36
36
|
export declare const multisampled: (billboard: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* A finished billboard shader with a `reactive` entry beside its fragment: the particle's coverage (its alpha) in red,
|
|
39
|
+
* for the frame's reactive mask that TAA reads (KB-TAA-PARTICLEMASK1).
|
|
40
|
+
*/
|
|
41
|
+
export declare const reactiveBillboard: (billboard: string) => string;
|
|
37
42
|
/** A finished billboard shader (fog, softness and texture in place) with its fragment feeding a transparency hook. */
|
|
38
43
|
export declare const transparentBillboard: (billboard: string, declarations: string) => string;
|
|
39
44
|
/**
|
package/dist/shared/fog.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import type { ColorInput } from '@margoengine/math/color';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Fog as `@margoengine/environment`'s `Fog` exposes it: pass that Fog, or any object with these fields. Read every
|
|
5
|
-
* frame, so changing the Fog changes the fog at once. Missing fields take Fog's defaults. A negative or non-finite
|
|
6
|
-
* distance, density or falloff (or a non-finite height) throws a RangeError, a malformed colour a TypeError or
|
|
7
|
-
* RangeError, a non-boolean `enabled` a TypeError.
|
|
8
|
-
*/
|
|
9
|
-
export interface FogLike {
|
|
10
|
-
/** Fog colour: hex is sRGB, `[r, g, b]` linear. Default '#ffffff'. */
|
|
11
|
-
readonly color?: ColorInput;
|
|
12
|
-
/** Linear fog start distance from the camera. Default 1. */
|
|
13
|
-
readonly near?: number;
|
|
14
|
-
/** Linear fog end distance, where fog is full. Default 1000. */
|
|
15
|
-
readonly far?: number;
|
|
16
|
-
/** Above 0 selects exponential-squared fog `1 - exp(-(density * distance)^2)`. Default 0. */
|
|
17
|
-
readonly density?: number;
|
|
18
|
-
/** Height fog: fog thins by `exp(-heightFalloff * (y - height))` above world height `height`. Default 0 (off). */
|
|
19
|
-
readonly heightFalloff?: number;
|
|
20
|
-
/** World height below which fog is at full strength. Default 0. */
|
|
21
|
-
readonly height?: number;
|
|
22
|
-
/** False mixes in no fog; switching never recompiles. Default true. */
|
|
23
|
-
readonly enabled?: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Bytes of the fog uniform: colour and height, near/far/density/falloff, camera position. */
|
|
27
|
-
export const FOG_BYTES: 48;
|
|
28
|
-
/** WGSL: the fog uniform at `@group(group) @binding(binding)` and `fogAmount(world position)`, 0 (clear) to 1. */
|
|
29
|
-
export function fogWgsl(group: number, binding: number): string;
|
|
30
|
-
/** Throws when `fog` is neither null nor an object; `setFog` calls it so a wrong argument fails where it is passed. */
|
|
31
|
-
export function checkFog(fog: FogLike | null): FogLike | null;
|
|
32
|
-
/** Validates `fog` and writes the 12-float fog uniform into `out` (colour sRGB-encoded with `encode`). */
|
|
33
|
-
export function writeFog(fog: FogLike, eye: ArrayLike<number>, out: Float32Array, encode?: boolean): void;
|
|
1
|
+
import type { ColorInput } from '@margoengine/math/color';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fog as `@margoengine/environment`'s `Fog` exposes it: pass that Fog, or any object with these fields. Read every
|
|
5
|
+
* frame, so changing the Fog changes the fog at once. Missing fields take Fog's defaults. A negative or non-finite
|
|
6
|
+
* distance, density or falloff (or a non-finite height) throws a RangeError, a malformed colour a TypeError or
|
|
7
|
+
* RangeError, a non-boolean `enabled` a TypeError.
|
|
8
|
+
*/
|
|
9
|
+
export interface FogLike {
|
|
10
|
+
/** Fog colour: hex is sRGB, `[r, g, b]` linear. Default '#ffffff'. */
|
|
11
|
+
readonly color?: ColorInput;
|
|
12
|
+
/** Linear fog start distance from the camera. Default 1. */
|
|
13
|
+
readonly near?: number;
|
|
14
|
+
/** Linear fog end distance, where fog is full. Default 1000. */
|
|
15
|
+
readonly far?: number;
|
|
16
|
+
/** Above 0 selects exponential-squared fog `1 - exp(-(density * distance)^2)`. Default 0. */
|
|
17
|
+
readonly density?: number;
|
|
18
|
+
/** Height fog: fog thins by `exp(-heightFalloff * (y - height))` above world height `height`. Default 0 (off). */
|
|
19
|
+
readonly heightFalloff?: number;
|
|
20
|
+
/** World height below which fog is at full strength. Default 0. */
|
|
21
|
+
readonly height?: number;
|
|
22
|
+
/** False mixes in no fog; switching never recompiles. Default true. */
|
|
23
|
+
readonly enabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Bytes of the fog uniform: colour and height, near/far/density/falloff, camera position. */
|
|
27
|
+
export const FOG_BYTES: 48;
|
|
28
|
+
/** WGSL: the fog uniform at `@group(group) @binding(binding)` and `fogAmount(world position)`, 0 (clear) to 1. */
|
|
29
|
+
export function fogWgsl(group: number, binding: number): string;
|
|
30
|
+
/** Throws when `fog` is neither null nor an object; `setFog` calls it so a wrong argument fails where it is passed. */
|
|
31
|
+
export function checkFog(fog: FogLike | null): FogLike | null;
|
|
32
|
+
/** Validates `fog` and writes the 12-float fog uniform into `out` (colour sRGB-encoded with `encode`). */
|
|
33
|
+
export function writeFog(fog: FogLike, eye: ArrayLike<number>, out: Float32Array, encode?: boolean): void;
|
package/dist/shared/pass.d.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
/** A reusable pass descriptor drawing over the frame: colour load/store, depth and stencil read only. */
|
|
2
|
-
export function overlayPass(): GPURenderPassDescriptor & {
|
|
3
|
-
colorAttachments: [GPURenderPassColorAttachment];
|
|
4
|
-
depthStencilAttachment: GPURenderPassDepthStencilAttachment;
|
|
5
|
-
};
|
|
6
|
-
/** {@link overlayPass} that also loads and stores depth. */
|
|
7
|
-
export function overlayDepthPass(): GPURenderPassDescriptor & {
|
|
8
|
-
colorAttachments: [GPURenderPassColorAttachment];
|
|
9
|
-
depthStencilAttachment: GPURenderPassDepthStencilAttachment;
|
|
10
|
-
};
|
|
11
|
-
/** Straight (non-premultiplied) alpha blending. */
|
|
12
|
-
export const alphaBlend: GPUBlendState;
|
|
13
|
-
/** Straight alpha blending that leaves the target's alpha channel unchanged: precipitation and other overlays drawn into a frame. */
|
|
14
|
-
export const overlayBlend: GPUBlendState;
|
|
15
|
-
|
|
16
|
-
/** `mesh` when it is null or a core mesh handle (checked live); else a TypeError. */
|
|
17
|
-
export function attachableMesh<M extends { check(): void } | null>(mesh: M): M;
|
|
18
|
-
/**
|
|
19
|
-
* What an order-independent pass offers an effect that is no PBR surface (particles, splats, points), in place of
|
|
20
|
-
* gltf/pbr's transparency hook. Same contract, but `surface` declares `fn margoTransparentAt(color:vec4f,clip:vec4f,
|
|
21
|
-
* depth:f32)->MargoTransparent`: `clip` is the fragment's position builtin, `depth` its view depth.
|
|
22
|
-
*/
|
|
23
|
-
export interface SurfaceTransparency {
|
|
24
|
-
/** Module-scope WGSL: `struct MargoTransparent` (one output per target), `margoTransparentAt` and its bindings in `group`. */
|
|
25
|
-
surface(group: number): string;
|
|
26
|
-
/** Layout of those bindings, for an effect with explicit pipeline layouts. */
|
|
27
|
-
readonly layout: readonly GPUBindGroupLayoutEntry[];
|
|
28
|
-
/** Entries for those bindings. */
|
|
29
|
-
bindings(): GPUBindGroupEntry[];
|
|
30
|
-
/** True: declarations hold `override margoKind:u32`, 0 normal, 1 additive; additive surfaces may draw here. */
|
|
31
|
-
readonly blends?: boolean;
|
|
32
|
-
/** Colour targets of the transparent pass, in `MargoTransparent` location order. */
|
|
33
|
-
readonly targets: readonly GPUColorTargetState[];
|
|
34
|
-
/** This frame's transparent pass, begun on the first draw and ended by the owner. */
|
|
35
|
-
begin(): GPURenderPassEncoder;
|
|
36
|
-
}
|
|
37
|
-
/** The fragment entry `transparent` of an effect under a transparency hook: `inputs` are its parameters, the rest WGSL expressions. */
|
|
38
|
-
export function surfaceEntry(declarations: string, inputs: string, color: string, clip: string, depth: string): string;
|
|
39
|
-
/** Holds an effect's transparency hook: `set` takes it and `released`, and returns the remover. */
|
|
40
|
-
export function transparencySlot(): {
|
|
41
|
-
hook?: SurfaceTransparency;
|
|
42
|
-
released?: () => void;
|
|
43
|
-
set(hook: SurfaceTransparency, released?: () => void): () => void;
|
|
44
|
-
};
|
|
45
|
-
/** `hook`'s pass with `pipeline` set, `group` at group 0 and the hook's bindings at group 1, for an effect with an auto layout. */
|
|
46
|
-
export function surfacePass(
|
|
47
|
-
device: GPUDevice,
|
|
48
|
-
hook: SurfaceTransparency,
|
|
49
|
-
pipeline: GPURenderPipeline,
|
|
50
|
-
group: GPUBindGroup,
|
|
51
|
-
): GPURenderPassEncoder;
|
|
52
|
-
/** The WGSL `make(group)` builds for bind group `group`, made once per group and kept in `cache`. */
|
|
53
|
-
export function groupCode(cache: Map<number, string>, group: number, make: (group: number) => string): string;
|
|
1
|
+
/** A reusable pass descriptor drawing over the frame: colour load/store, depth and stencil read only. */
|
|
2
|
+
export function overlayPass(): GPURenderPassDescriptor & {
|
|
3
|
+
colorAttachments: [GPURenderPassColorAttachment];
|
|
4
|
+
depthStencilAttachment: GPURenderPassDepthStencilAttachment;
|
|
5
|
+
};
|
|
6
|
+
/** {@link overlayPass} that also loads and stores depth. */
|
|
7
|
+
export function overlayDepthPass(): GPURenderPassDescriptor & {
|
|
8
|
+
colorAttachments: [GPURenderPassColorAttachment];
|
|
9
|
+
depthStencilAttachment: GPURenderPassDepthStencilAttachment;
|
|
10
|
+
};
|
|
11
|
+
/** Straight (non-premultiplied) alpha blending. */
|
|
12
|
+
export const alphaBlend: GPUBlendState;
|
|
13
|
+
/** Straight alpha blending that leaves the target's alpha channel unchanged: precipitation and other overlays drawn into a frame. */
|
|
14
|
+
export const overlayBlend: GPUBlendState;
|
|
15
|
+
|
|
16
|
+
/** `mesh` when it is null or a core mesh handle (checked live); else a TypeError. */
|
|
17
|
+
export function attachableMesh<M extends { check(): void } | null>(mesh: M): M;
|
|
18
|
+
/**
|
|
19
|
+
* What an order-independent pass offers an effect that is no PBR surface (particles, splats, points), in place of
|
|
20
|
+
* gltf/pbr's transparency hook. Same contract, but `surface` declares `fn margoTransparentAt(color:vec4f,clip:vec4f,
|
|
21
|
+
* depth:f32)->MargoTransparent`: `clip` is the fragment's position builtin, `depth` its view depth.
|
|
22
|
+
*/
|
|
23
|
+
export interface SurfaceTransparency {
|
|
24
|
+
/** Module-scope WGSL: `struct MargoTransparent` (one output per target), `margoTransparentAt` and its bindings in `group`. */
|
|
25
|
+
surface(group: number): string;
|
|
26
|
+
/** Layout of those bindings, for an effect with explicit pipeline layouts. */
|
|
27
|
+
readonly layout: readonly GPUBindGroupLayoutEntry[];
|
|
28
|
+
/** Entries for those bindings. */
|
|
29
|
+
bindings(): GPUBindGroupEntry[];
|
|
30
|
+
/** True: declarations hold `override margoKind:u32`, 0 normal, 1 additive; additive surfaces may draw here. */
|
|
31
|
+
readonly blends?: boolean;
|
|
32
|
+
/** Colour targets of the transparent pass, in `MargoTransparent` location order. */
|
|
33
|
+
readonly targets: readonly GPUColorTargetState[];
|
|
34
|
+
/** This frame's transparent pass, begun on the first draw and ended by the owner. */
|
|
35
|
+
begin(): GPURenderPassEncoder;
|
|
36
|
+
}
|
|
37
|
+
/** The fragment entry `transparent` of an effect under a transparency hook: `inputs` are its parameters, the rest WGSL expressions. */
|
|
38
|
+
export function surfaceEntry(declarations: string, inputs: string, color: string, clip: string, depth: string): string;
|
|
39
|
+
/** Holds an effect's transparency hook: `set` takes it and `released`, and returns the remover. */
|
|
40
|
+
export function transparencySlot(): {
|
|
41
|
+
hook?: SurfaceTransparency;
|
|
42
|
+
released?: () => void;
|
|
43
|
+
set(hook: SurfaceTransparency, released?: () => void): () => void;
|
|
44
|
+
};
|
|
45
|
+
/** `hook`'s pass with `pipeline` set, `group` at group 0 and the hook's bindings at group 1, for an effect with an auto layout. */
|
|
46
|
+
export function surfacePass(
|
|
47
|
+
device: GPUDevice,
|
|
48
|
+
hook: SurfaceTransparency,
|
|
49
|
+
pipeline: GPURenderPipeline,
|
|
50
|
+
group: GPUBindGroup,
|
|
51
|
+
): GPURenderPassEncoder;
|
|
52
|
+
/** The WGSL `make(group)` builds for bind group `group`, made once per group and kept in `cache`. */
|
|
53
|
+
export function groupCode(cache: Map<number, string>, group: number, make: (group: number) => string): string;
|