@margoengine/shader 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 +1920 -1771
- package/dist/attribute.d.ts +28 -0
- package/dist/black-hole.js +3 -3
- package/dist/clock-BLGNexlt.js +3 -3
- package/dist/{compute-D-BghbXj.js → compute-CXGG9qvI.js} +76 -70
- package/dist/compute-texture.js +3 -3
- package/dist/compute-volume.js +3 -3
- package/dist/compute.d.ts +8 -2
- package/dist/{control-DvjfV7R0.js → control-CFjkGPBk.js} +1 -1
- package/dist/deform.js +2 -2
- package/dist/editor-pass.js +17 -17
- package/dist/effects.js +2 -2
- package/dist/glsl-material.js +2 -2
- package/dist/glsl-pass.js +5 -5
- package/dist/glsl.js +18 -18
- package/dist/gpu-DQJk2xAv.js +55 -0
- package/dist/graph.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +103 -8
- package/dist/{lighting-Dx8_RsBz.js → lighting-JU9yQPfM.js} +2 -2
- package/dist/lighting.js +1 -1
- package/dist/{material-CU7p-Q8u.js → material-C6bpqlnE.js} +1 -1
- package/dist/{material-REzUrXtu.js → material-CZ8V1FeA.js} +95 -71
- package/dist/material.d.ts +9 -4
- package/dist/{node-DzKv9CF2.js → node-B6yoIC9V.js} +126 -126
- package/dist/node.d.ts +7 -1
- package/dist/noise.js +1 -1
- package/dist/pass.d.ts +1 -0
- package/dist/pass.js +24 -21
- package/dist/{post-DC62ZleD.js → post-DLpZ110L.js} +17 -17
- package/dist/{raw-D0W8U3Qa.js → raw-0AYej3Ak.js} +422 -273
- package/dist/raw.d.ts +125 -15
- package/dist/raw.js +1 -1
- package/dist/readback.js +13 -12
- package/dist/serialization.js +12 -12
- package/dist/shadertoy.js +6 -6
- package/dist/shared/caster.d.ts +159 -152
- package/dist/shared/fog.d.ts +33 -33
- package/dist/shared/fractal.d.ts +9 -9
- package/dist/shared/msaa.d.ts +30 -25
- package/dist/shared/stack.d.ts +22 -22
- package/dist/subgroups.js +4 -4
- package/dist/{texture-D6vy0bam.js → texture-BawKO_h9.js} +1 -1
- package/dist/texture-array.js +2 -2
- package/dist/utils.js +32 -32
- package/package.json +151 -151
- package/dist/gpu-DQ5Jmggz.js +0 -31
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MaterialMeshData, MeshGeometry, VertexAttributeType } from '@margoengine/materials';
|
|
2
|
+
import { Node, type Host, type Resource } from './node.js';
|
|
3
|
+
/** @internal The attributes one program reads, in first-read order: its one storage binding. */
|
|
4
|
+
export declare class AttributeReads implements Resource {
|
|
5
|
+
readonly prefix = "ndat";
|
|
6
|
+
readonly bindings = 1;
|
|
7
|
+
private readonly list;
|
|
8
|
+
/** Words a vertex takes: one per component of every attribute read. */
|
|
9
|
+
private stride;
|
|
10
|
+
/** The word offset of `name` in a vertex, adding it on first read. */
|
|
11
|
+
add(name: string, t: VertexAttributeType): void;
|
|
12
|
+
declare(name: string, group: number, binding: number): string;
|
|
13
|
+
entries(_device: GPUDevice, host: Host): GPUBindingResource[];
|
|
14
|
+
/** The data of one mesh: `geometry`'s attributes, checked and interleaved. */
|
|
15
|
+
read(geometry: MeshGeometry): MaterialMeshData;
|
|
16
|
+
/** Vertices `from` to `from + count` of `geometry` as this program's interleaved words; throws when they do not fit. */
|
|
17
|
+
pack(geometry: MeshGeometry, from: number, count: number): Uint32Array;
|
|
18
|
+
/** The words one vertex takes. */
|
|
19
|
+
get words(): number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A per-vertex value of the mesh being drawn, by name: `createMesh(engine, {positions, normals, attributes: {heat:
|
|
23
|
+
* {data, type: 'f32'}}}, new NodeMaterial({colorNode: mix(vec3(0, 0, 1), vec3(1, 0, 0), attribute('heat', 'f32'))}))`.
|
|
24
|
+
* In `positionNode` and `normalNode`'s vertex work it reads the vertex; in the other slots it is interpolated across the
|
|
25
|
+
* triangle (integer types take the first vertex's value). Every pass that draws the material reads it, shadows included,
|
|
26
|
+
* and `mesh.setGeometry` updates it. NodeMaterial nodes only.
|
|
27
|
+
*/
|
|
28
|
+
export declare function attribute<T extends VertexAttributeType>(name: string, as: T): Node<T>;
|
package/dist/black-hole.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
3
|
|
|
4
|
-
import { i as e, r as t, t as n } from "./raw-
|
|
4
|
+
import { i as e, r as t, t as n } from "./raw-0AYej3Ak.js";
|
|
5
5
|
//#region src/black-hole.ts
|
|
6
6
|
var r = [
|
|
7
7
|
"beauty",
|
|
@@ -228,7 +228,7 @@ function M(e, t, n) {
|
|
|
228
228
|
return Math.min(Math.max(e, t), n);
|
|
229
229
|
}
|
|
230
230
|
var N = "\nstruct Out { @builtin(position) clip:vec4f, @location(0) ndc:vec2f }\n@vertex fn vertex(@builtin(vertex_index) i:u32)->Out {\n let p = vec2f(f32((i << 1u) & 2u), f32(i & 2u)) * 2.0 - 1.0;\n return Out(vec4f(p, 0.0, 1.0), p);\n}\n\nfn bhHash3(p:vec3f)->f32 {\n var q = fract(p * vec3f(0.1031, 0.1030, 0.0973));\n q += dot(q, q.yxz + 33.33);\n return fract((q.x + q.y) * q.z);\n}\nfn bhHash2(p:vec2f)->f32 { return bhHash3(vec3f(p, 7.13)); }\nfn bhNoise(p:vec3f)->f32 {\n let i = floor(p);\n var f = fract(p);\n f = f * f * (3.0 - 2.0 * f);\n return mix(\n mix(mix(bhHash3(i), bhHash3(i + vec3f(1,0,0)), f.x), mix(bhHash3(i + vec3f(0,1,0)), bhHash3(i + vec3f(1,1,0)), f.x), f.y),\n mix(mix(bhHash3(i + vec3f(0,0,1)), bhHash3(i + vec3f(1,0,1)), f.x), mix(bhHash3(i + vec3f(0,1,1)), bhHash3(i + vec3f(1,1,1)), f.x), f.y),\n f.z) - 0.5;\n}\n\n\nfn bhFbm(p:vec3f, foot:f32)->f32 {\n var v = 0.0;\n var a = 0.55;\n var q = p;\n var f = foot;\n for (var k = 0; k < 6; k++) {\n v += a * bhNoise(q) * (1.0 - smoothstep(0.25, 0.5, f));\n q = q * 2.0 + vec3f(17.1, 9.3, 23.7);\n f *= 2.0;\n a *= 0.5;\n }\n return v;\n}\n\nfn bhBlackbody(kelvin:f32)->vec3f {\n let T = clamp(kelvin, 1667.0, 25000.0);\n let i = 1000.0 / T;\n var x = -3.0258469 * i * i * i + 2.1070379 * i * i + 0.2226347 * i + 0.24039;\n if (T <= 4000.0) { x = -0.2661239 * i * i * i - 0.2343589 * i * i + 0.8776956 * i + 0.17991; }\n var y = 3.081758 * x * x * x - 5.8733867 * x * x + 3.75112997 * x - 0.37001483;\n if (T <= 4000.0) { y = -0.9549476 * x * x * x - 1.37418593 * x * x + 2.09137015 * x - 0.16748867; }\n if (T <= 2222.0) { y = -1.1063814 * x * x * x - 1.3481102 * x * x + 2.18555832 * x - 0.20219683; }\n let X = x / y;\n let Z = (1.0 - x - y) / y;\n return max(vec3f(3.2406 * X - 1.5372 - 0.4986 * Z, -0.9689 * X + 1.8758 + 0.0415 * Z, 0.0557 * X - 0.204 + 1.057 * Z), vec3f(0.0));\n}\n\n\nfn bhFlux(r:f32)->f32 {\n let a = max(uniforms.spin, 1e-6);\n let x = sqrt(r);\n let x0 = uniforms.x0;\n if (x <= x0) { return 0.0; }\n let x1 = uniforms.x1; let x2 = uniforms.x2; let x3 = uniforms.x3;\n let t1 = 3.0 * (x1 - a) * (x1 - a) / (x1 * (x1 - x2) * (x1 - x3)) * log((x - x1) / (x0 - x1));\n let t2 = 3.0 * (x2 - a) * (x2 - a) / (x2 * (x2 - x1) * (x2 - x3)) * log((x - x2) / (x0 - x2));\n let t3 = 3.0 * (x3 - a) * (x3 - a) / (x3 * (x3 - x1) * (x3 - x2)) * log((x - x3) / (x0 - x3));\n let b = x - x0 - 1.5 * a * log(x / x0) - t1 - t2 - t3;\n return max(0.11936621 * b / (x * x * x * x * (x * x * x - 3.0 * x + 2.0 * a)), 0.0);\n}\n\n\nfn bhDiskAlpha(r:f32)->f32 {\n return smoothstep(uniforms.isco * 0.985, uniforms.isco, r) * (1.0 - smoothstep(uniforms.outer * 0.9, uniforms.outer, r));\n}\n\n\nfn bhPhase(k:f32)->vec2f {\n let period = 24.0;\n let clock = select(camera.time, uniforms.diskTime, uniforms.diskClock > 0.5);\n let u = fract(clock / period + 0.5 * k);\n return vec2f(u * period, 1.0 - abs(2.0 * u - 1.0));\n}\n\n\nfn bhDiskAdvection(r:f32, age:f32)->vec2f {\n let past = r + uniforms.diskInflow * age;\n if (uniforms.spin == 0.0) {\n let now = sqrt(r);\n let previous = sqrt(past);\n return vec2f(past, (2.0 * age) / (now * previous * (now + previous)));\n }\n let mid = 0.5 * (r + past);\n let offset = (past - r) / (2.0 * sqrt(3.0));\n let a = mid - offset;\n let b = mid + offset;\n let phase = 0.5 * age * (1.0 / (a * sqrt(a) + uniforms.spin) + 1.0 / (b * sqrt(b) + uniforms.spin));\n return vec2f(past, phase);\n}\n\nfn bhDiskCoord(p:vec3f, age:f32, k:f32)->vec3f {\n let rM = sqrt(max(4.0 * dot(p.xz, p.xz) - uniforms.spin * uniforms.spin, 1e-4));\n let previous = bhDiskAdvection(rM, age * uniforms.timeScale);\n let phi = atan2(p.z, p.x) + previous.y;\n return vec3f(cos(phi) * 3.0, sin(phi) * 3.0, log(previous.x) * 6.0 + k * 31.7);\n}\n\n\n\nfn bhDisk(p:vec3f, bk:f32, turb:f32, order:f32)->vec3f {\n let rM = sqrt(max(4.0 * dot(p.xz, p.xz) - uniforms.spin * uniforms.spin, 1e-4));\n let rS = rM * 0.5;\n var f = bhFlux(rM) * uniforms.fluxNorm;\n\n let age = camera.time - uniforms.flareStart;\n if (age >= 0.0 && age < 14.0) {\n let fr = mix(4.2, uniforms.isco * 1.15, clamp(age / 8.0, 0.0, 1.0));\n let fphi = -age * 3.0 - 4.5 * log(max(rS, 0.35));\n let dr = (rS - fr) / 0.42;\n let dphi = sin((atan2(p.z, p.x) - fphi) * 0.5);\n f *= 1.0 + 2.5 * exp(-dr * dr - dphi * dphi * 5.0) * exp(-max(age - 6.0, 0.0) * 0.45);\n }\n\n\n let emitterGain = exp(5.0 * uniforms.turbulence * turb);\n f *= emitterGain;\n\n let s = sqrt(rM);\n let ut = (rM * s + uniforms.spin) / (pow(rM, 0.75) * sqrt(max(rM * s - 3.0 * s + 2.0 * uniforms.spin, 1e-5)));\n let g = 1.0 / (ut * (1.0 - bk / (rM * s + uniforms.spin)));\n let tEm = uniforms.tPeak * pow(max(f, 0.0), 0.25);\n let v = uniforms.view;\n if (v > 3.5) {\n let tint = select(select(vec3f(0.9, 0.25, 1.0), vec3f(0.2, 0.85, 1.0), order < 1.5), vec3f(1.0, 0.62, 0.25), order < 0.5);\n return tint * (0.25 + 0.75 * sqrt(f));\n }\n if (v > 2.5) { return bhBlackbody(tEm) * select(0.0, 1.0, f > 0.0); }\n if (v > 1.5) {\n let e = clamp(log2(g * g * g * g) / 3.0, -1.0, 1.0);\n return mix(vec3f(0.35, 0.35, 0.35), select(vec3f(0.15, 0.3, 1.0), vec3f(1.0, 0.95, 0.4), e > 0.0) * 1.6, abs(e)) * select(0.0, emitterGain, f > 0.0);\n }\n if (v > 0.5) {\n let e = clamp((g - 1.0) * 2.5, -1.0, 1.0);\n return mix(vec3f(0.8), select(vec3f(1.0, 0.18, 0.1), vec3f(0.2, 0.45, 1.0), e > 0.0), abs(e)) * select(0.0, 1.0, f > 0.0);\n }\n return bhBlackbody(g * tEm) * (g * g * g * g * f * uniforms.accretion * 0.8);\n}\n\n\nfn bhLapse(p:vec3f)->f32 {\n let a = uniforms.spin;\n let m = p * 2.0;\n let w = dot(m, m) - a * a;\n let r = sqrt(0.5 * (w + sqrt(w * w + 4.0 * a * a * m.y * m.y)));\n let c = clamp(m.y / max(r, 1e-4), -1.0, 1.0);\n let dl = max(r * r - 2.0 * r + a * a, 0.0);\n let rho2 = r * r + a * a * c * c;\n let sig2 = (r * r + a * a) * (r * r + a * a) - a * a * dl * (1.0 - c * c);\n return sqrt(rho2 * dl / sig2);\n}\n\n\n\n\n\nfn bhJet(p:vec3f, rd:vec3f)->f32 {\n let ay = abs(p.y);\n if (ay < 1.2 || ay > 40.0) { return 0.0; }\n let R = 0.28 * pow(ay, 0.58);\n let q = length(p.xz) / R;\n if (q > 3.0) { return 0.0; }\n let gamma = uniforms.jetGamma;\n let beta = sqrt(1.0 - 1.0 / (gamma * gamma));\n let cosT = dot(vec3f(0.0, sign(p.y), 0.0), -rd);\n let D = 1.0 / (gamma * (1.0 - beta * cosT));\n let knots = 0.75 + 0.5 * bhNoise(vec3f(p.x * 2.0, ay * 0.8 - camera.time * 1.5 * sign(p.y), p.z * 2.0));\n\n\n\n let lapse = bhLapse(p);\n return exp(-q * q * 1.5) * smoothstep(1.2, 3.0, ay) / (ay * ay * R * R) * min(pow(lapse * D, 2.7), 60.0) * knots * 0.02;\n}\n\n\n\n\n\nconst BH_PLANE = vec3f(-0.4198, 0.8996, 0.12);\nconst BH_CENTRE = vec3f(0.1948, 0.2185, -0.9562);\nstruct BhFrame { e1:vec3f, e2:vec3f, inv:mat2x2f, det:f32, mu:f32, pixel:f32 }\n\nfn bhStarFill(d:vec3f)->f32 {\n let z = abs(dot(d, BH_PLANE));\n return 0.05 + 0.11 * exp(-z * 6.0) + 0.05 * exp(-(1.0 - dot(d, BH_CENTRE)) * 6.0);\n}\nfn bhStarCell(d:vec3f, band:f32, dlat:f32, dlon:f32, bands:f32, seed:f32, fr:BhFrame)->vec3f {\n let lat = band + dlat;\n if (lat < 0.0 || lat >= bands) { return vec3f(0.0); }\n let latC = (lat + 0.5) / bands * 3.14159265 - 1.5707963;\n let lonBins = max(floor(cos(latC) * bands * 2.0), 6.0);\n let phi = atan2(d.z, d.x);\n let lon = floor((phi + 3.14159265) / 6.2831853 * lonBins) + dlon;\n let cell = vec2f(lon - floor(lon / lonBins) * lonBins + seed * 17.0, lat + seed * 31.0);\n let rnd = bhHash2(cell);\n if (rnd < 1.0 - bhStarFill(d)) { return vec3f(0.0); }\n let sLat = latC + (bhHash2(cell + vec2f(11.3, 5.9)) - 0.5) * 0.9 * 3.14159265 / bands;\n let sLon = (lon + 0.5 + (bhHash2(cell + vec2f(3.1, 7.7)) - 0.5) * 0.9) / lonBins * 6.2831853 - 3.14159265;\n let s = vec3f(cos(sLat) * cos(sLon), sin(sLat), cos(sLat) * sin(sLon));\n let delta = s - d;\n let px = fr.inv * vec2f(dot(delta, fr.e1), dot(delta, fr.e2));\n\n let u = bhHash2(cell + vec2f(5.7, 2.3));\n let flux = (0.2 + 4.8 * pow(u, 5.0)) * fr.mu;\n\n let tint = bhBlackbody(3000.0 + 12000.0 * pow(bhHash2(cell + vec2f(9.1, 1.7)), 2.2));\n if (dot(s, d) < 0.0) { return vec3f(0.0); }\n return tint * flux * exp(-dot(px, px) / (2.0 * 0.36)) * 0.44;\n}\nfn bhStars(d:vec3f, bands:f32, seed:f32, fr:BhFrame)->vec3f {\n let band = floor((asin(clamp(d.y, -1.0, 1.0)) + 1.5707963) / 3.14159265 * bands);\n var c = vec3f(0.0);\n for (var i = -1; i <= 1; i++) {\n for (var j = -1; j <= 1; j++) {\n c += bhStarCell(d, band, f32(i), f32(j), bands, seed, fr);\n }\n }\n\n\n\n let cellAngle = 3.14159265 / bands;\n let w = smoothstep(0.3, 0.7, sqrt(fr.det) / cellAngle);\n return mix(c, vec3f(0.85, 0.82, 0.8) * bhStarFill(d) * fr.pixel * fr.pixel / (cellAngle * cellAngle), w);\n}\n\n\nfn bhGalaxy(d:vec3f, foot:f32)->vec3f {\n let z = dot(d, BH_PLANE);\n let thin = exp(-abs(z) * 7.0);\n let thick = exp(-abs(z) * 2.2);\n let toward = dot(d, BH_CENTRE);\n let bulge = exp(-(1.0 - toward) * 9.0) * exp(-abs(z) * 3.0);\n let clumps = bhFbm(d * 6.0 + vec3f(1.4, -0.8, 2.1), foot * 6.0) + 0.5;\n let lanes = smoothstep(0.38, 0.7, bhFbm(d * 11.0 + vec3f(4.2, 0.3, -1.9), foot * 11.0) + 0.5) * exp(-abs(z + 0.012) * 26.0);\n let disk = (thin * (0.35 + 0.9 * clumps) + 0.25 * thick) * (0.55 + 0.45 * max(toward, 0.0));\n let light = vec3f(0.62, 0.68, 0.85) * disk + vec3f(1.0, 0.72, 0.45) * bulge * 1.4;\n return light * (1.0 - 0.85 * lanes) * 0.02;\n}\n\n\n\nstruct BhKD { d:vec4f, dphi:f32 }\nfn bhKerr(y:vec4f, a:f32, b:f32, q:f32, band:f32)->BhKD {\n let r = y.x; let pr = y.z; let pt = y.w;\n let s = max(sin(y.y), 1e-6); let inBand = s < band; let S2 = select(s * s, band * band, inBand); let c = cos(y.y); let a2 = a * a;\n let dl = r * r - 2.0 * r + a2; let dlp = 2.0 * r - 2.0;\n let rho2 = r * r + a2 * c * c;\n let P = r * r + a2 - a * b; let bq = (b - a) * (b - a) + q;\n let R = P * P - dl * bq; let Rp = 4.0 * r * P - dlp * bq;\n let Th = q - c * c * (b * b / S2 - a2);\n let barrier = select(2.0 * b * b * c / (s * s * s), 2.0 * b * b * c * s / S2, inBand);\n let A = -dl * pr * pr - pt * pt + Th;\n let B = R / dl; let Bp = (Rp * dl - R * dlp) / (dl * dl);\n let inv = 1.0 / (2.0 * rho2);\n let k = A + B;\n let d = vec4f(dl * pr / rho2, pt / rho2,\n (-dlp * pr * pr + Bp) * inv - k * r / (rho2 * rho2),\n (barrier - 2.0 * a2 * c * s) * inv + k * a2 * c * s / (rho2 * rho2));\n let dphi = select(-2.0, 0.0, inBand) * b * c * c / S2 * inv + (-2.0 * a * P - 2.0 * dl * (b - a)) * inv / dl;\n return BhKD(-d, -dphi);\n}\n\nfn bhCaptured(r:f32, rH:f32, a:f32, b:f32, q:f32)->bool {\n let bq = (b - a) * (b - a) + q;\n for (var i = 1; i <= 32; i++) {\n let x = rH + (r - rH) * f32(i) / 32.0;\n let P = x * x + a * a - a * b;\n if (P * P - (x * x - 2.0 * x + a * a) * bq < 0.0) { return false; }\n }\n return true;\n}\nfn bhCart(y:vec4f, phi:f32, a:f32, cp:f32, sp:f32)->vec3f {\n let rho = sqrt(y.x * y.x + a * a) * sin(y.y);\n let c = cp * cos(phi) - sp * sin(phi);\n let s = sp * cos(phi) + cp * sin(phi);\n return 0.5 * vec3f(rho * c, y.x * cos(y.y), -rho * s);\n}\n\n\n\n@diagnostic(off, derivative_uniformity) @fragment fn fragment(i:Out)->@location(0) vec4f {\n let v = camera.view;\n let right = vec3f(v[0][0], v[1][0], v[2][0]);\n let up = vec3f(v[0][1], v[1][1], v[2][1]);\n let back = vec3f(v[0][2], v[1][2], v[2][2]);\n let proj = camera.projection;\n var rd = normalize(right * i.ndc.x / proj[0][0] + up * i.ndc.y / proj[1][1] - back);\n let horizon = uniforms.horizon;\n\n var accum = vec3f(0.0);\n var trans = 1.0;\n\n var escaped = false;\n var falling = false;\n var crossings = 0;\n var hp = array<vec3f, 3>(vec3f(0.0), vec3f(0.0), vec3f(0.0));\n var hb = array<f32, 3>(0.0, 0.0, 0.0);\n var hw = array<f32, 3>(0.0, 0.0, 0.0);\n let steps = i32(uniforms.steps);\n let a = uniforms.spin;\n let rH = horizon * 2.0;\n\n\n let cm = camera.position * 2.0;\n let w0 = dot(cm, cm) - a * a;\n let r0 = sqrt(0.5 * (w0 + sqrt(w0 * w0 + 4.0 * a * a * cm.y * cm.y)));\n let th0 = acos(clamp(cm.y / r0, -1.0, 1.0));\n\n\n var phi = 0.0;\n let rc = length(cm.xz);\n let cp = select(1.0, cm.x / rc, rc > 1e-6);\n let sp = select(0.0, -cm.z / rc, rc > 1e-6);\n let s0 = max(sin(th0), 1e-6);\n let c0 = cos(th0);\n let ra = sqrt(r0 * r0 + a * a);\n let er = normalize(vec3f(r0 / ra * s0 * cp, c0, -r0 / ra * s0 * sp));\n let et = normalize(vec3f(ra * c0 * cp, -r0 * s0, -ra * c0 * sp));\n let ep = vec3f(-sp, 0.0, -cp);\n let n = -normalize(vec3f(dot(rd, er), dot(rd, et), dot(rd, ep)));\n let dl0 = r0 * r0 - 2.0 * r0 + a * a;\n let rho0 = sqrt(r0 * r0 + a * a * c0 * c0);\n let sig = sqrt((r0 * r0 + a * a) * (r0 * r0 + a * a) - a * a * dl0 * s0 * s0);\n let alpha = rho0 * sqrt(max(dl0, 1e-6)) / sig;\n let omega = 2.0 * a * r0 / (sig * sig);\n let varpi = sig * s0 / rho0;\n let E = 1.0 / (alpha + omega * varpi * n.z);\n let bk = E * varpi * n.z;\n var y = vec4f(r0, th0, E * rho0 * n.x / sqrt(max(dl0, 1e-6)), E * rho0 * n.y);\n let qk = y.w * y.w + c0 * c0 * (bk * bk / (s0 * s0) - a * a);\n let kq = sqrt(max(qk + a * a, 1e-9));\n let tMin = abs(bk) / kq;\n\n let band = select(0.0, 0.001, tMin <= 0.00033333);\n\n let axisTurn = select(3.14159265, sign(bk) * 2.0 * acos(min(tMin / 0.001, 1.0)), band > 0.0);\n let turnAt = select(tMin, 0.001, band > 0.0);\n\n for (var step = 0; step < steps; step++) {\n let r = y.x;\n if (r <= rH * 1.02) { break; }\n let k1 = bhKerr(y, a, bk, qk, band);\n if (r > 160.0 && k1.d.x > 0.0) { escaped = true; break; }\n\n if (k1.d.x < 0.0 && r < 4.0 && (falling || bhCaptured(r, rH, a, bk, qk))) {\n falling = true;\n if (r < uniforms.isco * 2.0) { break; }\n }\n var dt = 2.0 * min(max(0.028 * max(0.5 * r - horizon * 0.9, 0.035) + 0.00105 * r * r, 0.012), max(0.65, 0.1 * r)) *\n clamp(4.0 * (r * r - 2.0 * r + a * a) / (r * r), 0.1, 1.0) * clamp(sin(y.y) * 10.0, 0.05, 1.0);\n\n let sa = abs(sin(y.y));\n if (sa < 0.2) {\n let dTheta = select(0.25 * max(sa - turnAt, 0.4 * turnAt), 0.0005, sa < band);\n dt = min(dt, dTheta * (r * r + a * a * cos(y.y) * cos(y.y)) / kq);\n }\n let k2 = bhKerr(y + k1.d * (0.5 * dt), a, bk, qk, band);\n let k3 = bhKerr(y + k2.d * (0.5 * dt), a, bk, qk, band);\n let k4 = bhKerr(y + k3.d * dt, a, bk, qk, band);\n let yn = y + (k1.d + 2.0 * k2.d + 2.0 * k3.d + k4.d) * (dt / 6.0);\n let phin = phi + (k1.dphi + 2.0 * k2.dphi + 2.0 * k3.dphi + k4.dphi) * (dt / 6.0);\n\n var ynn = yn;\n var phn = phin;\n if (ynn.y < 0.0) { ynn = vec4f(ynn.x, -ynn.y, ynn.z, -ynn.w); phn += axisTurn; }\n if (ynn.y > 3.14159265) { ynn = vec4f(ynn.x, 6.2831853 - ynn.y, ynn.z, -ynn.w); phn += axisTurn; }\n let p0 = bhCart(y, phi, a, cp, sp);\n let p1 = bhCart(ynn, phn, a, cp, sp);\n let seg = p1 - p0;\n let segLen = length(seg);\n let dir = seg / max(segLen, 1e-6);\n\n\n let mid = 0.5 * (p0 + p1);\n if (uniforms.jet > 0.0 && abs(mid.y) > 0.5 && length(mid.xz) < 0.9 * pow(abs(mid.y), 0.58) + segLen) {\n var j = 0.0;\n for (var s = 0; s < 4; s++) { j += bhJet(p0 + seg * ((f32(s) + 0.5) * 0.25), dir); }\n accum += trans * vec3f(0.55, 0.72, 1.0) * j * 0.25 * segLen * uniforms.jet;\n }\n\n\n\n if ((y.y < 1.5707963) != (yn.y < 1.5707963)) {\n let t = (y.y - 1.5707963) / (y.y - yn.y);\n let hit = mix(p0, p1, t);\n let opacity = bhDiskAlpha(0.5 * mix(y.x, yn.x, t));\n if (opacity > 0.0) {\n if (crossings < 3) {\n hp[crossings] = hit;\n hb[crossings] = bk;\n hw[crossings] = trans * opacity;\n } else {\n accum += trans * opacity * bhDisk(hit, bk, 0.0, 3.0);\n }\n trans *= 1.0 - opacity;\n crossings += 1;\n }\n }\n y = ynn;\n phi = phn;\n rd = dir;\n if (trans < 0.004) { break; }\n }\n\n if (uniforms.view > 4.5) { return vec4f(select(0.0,1.0,escaped), f32(crossings)/3.0, y.x/400.0, 1.0); }\n\n\n let pf = uniforms.prefilter;\n var turb = array<f32, 3>(0.0, 0.0, 0.0);\n let ph0 = bhPhase(0.0);\n let ph1 = bhPhase(1.0);\n let q00 = bhDiskCoord(hp[0], ph0.x, 0.0); let q01 = bhDiskCoord(hp[0], ph1.x, 1.0);\n let q10 = bhDiskCoord(hp[1], ph0.x, 0.0); let q11 = bhDiskCoord(hp[1], ph1.x, 1.0);\n let q20 = bhDiskCoord(hp[2], ph0.x, 0.0); let q21 = bhDiskCoord(hp[2], ph1.x, 1.0);\n let f00 = max(length(dpdx(q00)), length(dpdy(q00))) * pf; let f01 = max(length(dpdx(q01)), length(dpdy(q01))) * pf;\n let f10 = max(length(dpdx(q10)), length(dpdy(q10))) * pf; let f11 = max(length(dpdx(q11)), length(dpdy(q11))) * pf;\n let f20 = max(length(dpdx(q20)), length(dpdy(q20))) * pf; let f21 = max(length(dpdx(q21)), length(dpdy(q21))) * pf;\n turb[0] = ph0.y * bhFbm(q00, f00) + ph1.y * bhFbm(q01, f01);\n turb[1] = ph0.y * bhFbm(q10, f10) + ph1.y * bhFbm(q11, f11);\n turb[2] = ph0.y * bhFbm(q20, f20) + ph1.y * bhFbm(q21, f21);\n let dx = dpdx(rd);\n let dy = dpdy(rd);\n\n\n\n\n\n\n for (var k = 0; k < 3; k++) {\n accum += hw[k] * bhDisk(hp[k], hb[k], turb[k], f32(k));\n }\n\n {\n let sky = select(0.0, trans, escaped);\n\n let d = select(vec3f(0.0, 0.0, 1.0), normalize(rd), dot(rd, rd) > 0.0);\n var e1 = cross(vec3f(0.0, 1.0, 0.0), d);\n if (dot(e1, e1) < 1e-8) { e1 = vec3f(1.0, 0.0, 0.0); }\n e1 = normalize(e1);\n let e2 = cross(d, e1);\n let pixel = 2.0 / (camera.resolution.y * proj[1][1]);\n\n let jx = mix(vec2f(pixel, 0.0), vec2f(dot(dx, e1), dot(dx, e2)), pf);\n let jy = mix(vec2f(0.0, pixel), vec2f(dot(dy, e1), dot(dy, e2)), pf);\n let det = max(abs(jx.x * jy.y - jy.x * jx.y), 1e-14);\n let inv = mat2x2f(vec2f(jy.y, -jx.y), vec2f(-jy.x, jx.x)) * (1.0 / det);\n let mu = min(pixel * pixel / det, 40.0);\n let fr = BhFrame(e1, e2, inv, det, mu, pixel);\n let foot = sqrt(det) * pf;\n let starLight = bhStars(d, 140.0, 1.0, fr) + bhStars(d, 300.0, 2.0, fr) * 0.6;\n accum += sky * (starLight * uniforms.stars + bhGalaxy(d, foot) * uniforms.galaxy * select(1.0, 0.25, uniforms.view > 0.5));\n }\n return margoDisplay(vec4f(accum * uniforms.exposure, 1.0));\n}\n", P = N, F = class o {
|
|
231
|
-
static attach(t, n = {}) {__margoAssertCore(t,__margoCoreRequirement("
|
|
231
|
+
static attach(t, n = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
232
232
|
return new o(e.attach(t, { name: "shader:black-hole" }), n, !0);
|
|
233
233
|
}
|
|
234
234
|
constructor(e, r = {}, i = !1) {
|
package/dist/clock-BLGNexlt.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
3
|
|
|
4
4
|
//#region src/clock.ts
|
|
5
|
-
var e = /* @__PURE__ */ new WeakMap(), t = class t {coreRequirement=__margoCoreRequirement("
|
|
5
|
+
var e = /* @__PURE__ */ new WeakMap(), t = class t {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
6
6
|
constructor() {
|
|
7
7
|
this.name = "shader:clock", this.seconds = 0, this.step = 0, this.hosts = /* @__PURE__ */ new Set();
|
|
8
8
|
}
|
|
9
|
-
static attach(e) {__margoAssertCore(e,__margoCoreRequirement("
|
|
9
|
+
static attach(e) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
10
10
|
return t.hold(e, t);
|
|
11
11
|
}
|
|
12
12
|
static hold(n, r) {
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
-
const
|
|
4
|
-
import { Ht as e, It as t, Pt as n, T as r, b as i, gn as a, l as o, o as s, tn as c } from "./node-
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
7
|
-
import {
|
|
8
|
-
import { MargoError as
|
|
3
|
+
const _=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { Ht as e, It as t, Pt as n, T as r, b as i, gn as a, l as o, o as s, tn as c } from "./node-B6yoIC9V.js";
|
|
5
|
+
import { i as l, t as u } from "./gpu-DQJk2xAv.js";
|
|
6
|
+
import { t as d } from "./clock-BLGNexlt.js";
|
|
7
|
+
import { d as f, f as p, i as m, p as h } from "./control-CFjkGPBk.js";
|
|
8
|
+
import { MargoError as g } from "@margoengine/math/errors";
|
|
9
9
|
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
10
10
|
//#region src/compute.ts
|
|
11
|
-
var
|
|
12
|
-
function
|
|
13
|
-
let t =
|
|
11
|
+
var v = (e) => e instanceof s && (e.type === "u32" || e.type === "i32") ? e : r(e, "u32", "storage index"), y = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
function b(e) {
|
|
13
|
+
let t = y.get(e);
|
|
14
14
|
if (!t) {
|
|
15
|
-
t = /* @__PURE__ */ new Set(),
|
|
15
|
+
t = /* @__PURE__ */ new Set(), y.set(e, t);
|
|
16
16
|
let n = t;
|
|
17
17
|
e.lost.then((t) => {
|
|
18
18
|
let r = [...n];
|
|
19
|
-
n.clear(),
|
|
19
|
+
n.clear(), y.delete(e);
|
|
20
20
|
for (let e of r) e(t);
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
return t;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function x(e, t) {
|
|
26
26
|
if (!e.lost) return () => {};
|
|
27
|
-
let n =
|
|
27
|
+
let n = b(e);
|
|
28
28
|
return n.add(t), () => n.delete(t);
|
|
29
29
|
}
|
|
30
|
-
var
|
|
30
|
+
var S = (e, t, n, r, i) => {
|
|
31
31
|
let o = new s(t, "a" + c(), [r, ...i], (t, r) => {
|
|
32
32
|
if (t.stage.kind !== "compute") throw TypeError(`${n} is only available in ComputePass nodes`);
|
|
33
33
|
let [i, ...a] = r.args.map((e) => t.expr(e)), o = t.name();
|
|
34
34
|
return t.line(`let ${o} = ${n}(&${t.resource(e)}[${i}]${a.map((e) => ", " + e).join("")});`), o;
|
|
35
35
|
}, 28);
|
|
36
36
|
return a.list?.push(o), o;
|
|
37
|
-
},
|
|
37
|
+
}, C = (e) => ({
|
|
38
38
|
old: new s(e.type, ".old", [e], (e, t) => `${e.expr(t.args[0])}.old_value`),
|
|
39
39
|
exchanged: new s("bool", ".exchanged", [e], (e, t) => `${e.expr(t.args[0])}.exchanged`)
|
|
40
|
-
}),
|
|
40
|
+
}), w = class {
|
|
41
41
|
constructor(n, r, i = !1) {
|
|
42
42
|
this.data = n, this.type = r, this.atomic = i, this.prefix = "ndb", this.bindings = 1, this.id = c(), this.version = 0, this.buffers = /* @__PURE__ */ new Map(), this.lossSubscriptions = /* @__PURE__ */ new Map();
|
|
43
43
|
let a = {
|
|
@@ -64,15 +64,21 @@ var x = (e, t, n, r, i) => {
|
|
|
64
64
|
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC | GPUBufferUsage.VERTEX | GPUBufferUsage.INDIRECT
|
|
65
65
|
}),
|
|
66
66
|
version: -1
|
|
67
|
-
}, this.buffers.set(e, t), this.lossSubscriptions.set(e,
|
|
67
|
+
}, this.buffers.set(e, t), this.lossSubscriptions.set(e, x(e, () => {
|
|
68
68
|
this.buffers.delete(e), this.lossSubscriptions.delete(e);
|
|
69
69
|
}))), t.version !== this.version && (e.queue.writeBuffer(t.buffer, 0, this.data), t.version = this.version), t.buffer;
|
|
70
70
|
}
|
|
71
|
-
update() {
|
|
72
|
-
|
|
71
|
+
update(t) {
|
|
72
|
+
if (!t) {
|
|
73
|
+
this.version++;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
let { start: n, count: r } = t, i = e(this.type);
|
|
77
|
+
if (!Number.isInteger(n) || !Number.isInteger(r) || n < 0 || r < 1 || n + r > this.count) throw RangeError("Storage update range must be whole elements inside the buffer; pass start and count");
|
|
78
|
+
for (let [e, t] of this.buffers) t.version === this.version && e.queue.writeBuffer(t.buffer, n * i * 4, this.data, n * i, r * i);
|
|
73
79
|
}
|
|
74
80
|
element(e) {
|
|
75
|
-
return new s(this.type, "e" + this.id, [
|
|
81
|
+
return new s(this.type, "e" + this.id, [v(e)], (e, t) => {
|
|
76
82
|
let n = `${e.resource(this)}[${e.expr(t.args[0])}]`;
|
|
77
83
|
return this.atomic && e.stage.kind === "compute" ? `atomicLoad(&${n})` : n;
|
|
78
84
|
}, 32);
|
|
@@ -80,7 +86,7 @@ var x = (e, t, n, r, i) => {
|
|
|
80
86
|
store(e, t) {
|
|
81
87
|
let n = {
|
|
82
88
|
buffer: this,
|
|
83
|
-
index:
|
|
89
|
+
index: v(e),
|
|
84
90
|
value: r(t, this.type, "stored value")
|
|
85
91
|
};
|
|
86
92
|
return a.store?.(n), n;
|
|
@@ -110,7 +116,7 @@ var x = (e, t, n, r, i) => {
|
|
|
110
116
|
return this.rmw("atomicExchange", e, t);
|
|
111
117
|
}
|
|
112
118
|
atomicCompareExchange(e, t, n) {
|
|
113
|
-
return
|
|
119
|
+
return C(this.rmw("atomicCompareExchangeWeak", e, t, n));
|
|
114
120
|
}
|
|
115
121
|
atomicLoad(e) {
|
|
116
122
|
return this.rmw("atomicLoad", e);
|
|
@@ -120,27 +126,27 @@ var x = (e, t, n, r, i) => {
|
|
|
120
126
|
}
|
|
121
127
|
rmw(e, t, ...n) {
|
|
122
128
|
if (!this.atomic) throw TypeError(`${e} needs storage(data, '${this.type}', {atomic: true})`);
|
|
123
|
-
return
|
|
129
|
+
return S(this, this.type, e, v(t), n.map((t) => r(t, this.type, e + " value")));
|
|
124
130
|
}
|
|
125
131
|
dispose() {
|
|
126
132
|
for (let e of this.lossSubscriptions.values()) e();
|
|
127
133
|
this.lossSubscriptions.clear();
|
|
128
|
-
for (let e of this.buffers
|
|
134
|
+
for (let [e, t] of this.buffers) l(e, t.buffer);
|
|
129
135
|
this.buffers.clear();
|
|
130
136
|
}
|
|
131
137
|
[Symbol.dispose ?? Symbol()]() {
|
|
132
138
|
this.dispose();
|
|
133
139
|
}
|
|
134
140
|
};
|
|
135
|
-
function
|
|
141
|
+
function T(n, r, { atomic: i = !1 } = {}) {
|
|
136
142
|
let a = t(r), o = e(r);
|
|
137
|
-
return new
|
|
143
|
+
return new w(typeof n == "number" ? new {
|
|
138
144
|
f32: Float32Array,
|
|
139
145
|
i32: Int32Array,
|
|
140
146
|
u32: Uint32Array
|
|
141
147
|
}[a](n * o) : n, r, i);
|
|
142
148
|
}
|
|
143
|
-
var
|
|
149
|
+
var E = /*@__PURE__*/ i("instanceIndex", "u32"), D = /*@__PURE__*/ i("globalId", "vec3u"), O = /*@__PURE__*/ i("localId", "vec3u"), k = /*@__PURE__*/ i("localIndex", "u32"), A = /*@__PURE__*/ i("workgroupId", "vec3u"), j = /*@__PURE__*/ i("workgroupCount", "vec3u"), M = {
|
|
144
150
|
localId: [
|
|
145
151
|
"lid",
|
|
146
152
|
"local_invocation_id",
|
|
@@ -171,20 +177,20 @@ var T = /*@__PURE__*/ i("instanceIndex", "u32"), E = /*@__PURE__*/ i("globalId",
|
|
|
171
177
|
"subgroup_invocation_id",
|
|
172
178
|
"u32"
|
|
173
179
|
]
|
|
174
|
-
},
|
|
180
|
+
}, N = /* @__PURE__ */ new WeakSet(), P = (e) => void N.add(e), F = (e) => f(p([], (t) => {
|
|
175
181
|
if (t.stage.kind !== "compute") throw TypeError(`${e} is only available in ComputePass nodes; move it into a ComputePass body`);
|
|
176
|
-
|
|
182
|
+
N.add(t.program), t.line(`${e}();`), t.epoch++;
|
|
177
183
|
}), e);
|
|
178
|
-
function F() {
|
|
179
|
-
a.flush?.(), P("workgroupBarrier");
|
|
180
|
-
}
|
|
181
184
|
function I() {
|
|
182
|
-
a.flush?.(),
|
|
185
|
+
a.flush?.(), F("workgroupBarrier");
|
|
183
186
|
}
|
|
184
187
|
function L() {
|
|
185
|
-
a.flush?.(),
|
|
188
|
+
a.flush?.(), F("storageBarrier");
|
|
189
|
+
}
|
|
190
|
+
function R() {
|
|
191
|
+
a.flush?.(), F("textureBarrier");
|
|
186
192
|
}
|
|
187
|
-
var
|
|
193
|
+
var z = class {
|
|
188
194
|
constructor(e, t, n = !1) {
|
|
189
195
|
if (this.count = e, this.type = t, this.atomic = n, this.prefix = "ndg", this.bindings = 0, this.id = c(), !Number.isInteger(e) || e < 1) throw RangeError("Workgroup memory needs a whole count of at least 1");
|
|
190
196
|
if (n && t !== "u32" && t !== "i32") throw TypeError("Atomic workgroup memory must be u32 or i32; pass one of those types or drop {atomic: true}.");
|
|
@@ -196,26 +202,26 @@ var R = class {
|
|
|
196
202
|
return [];
|
|
197
203
|
}
|
|
198
204
|
element(e) {
|
|
199
|
-
return new s(this.type, "g" + this.id, [
|
|
205
|
+
return new s(this.type, "g" + this.id, [v(e)], (e, t) => {
|
|
200
206
|
if (e.stage.kind !== "compute") throw TypeError("Workgroup memory is only available in ComputePass nodes; move it into a ComputePass body");
|
|
201
207
|
let n = `${e.resource(this)}[${e.expr(t.args[0])}]`;
|
|
202
208
|
return this.atomic ? `atomicLoad(&${n})` : n;
|
|
203
209
|
}, 32);
|
|
204
210
|
}
|
|
205
211
|
store(e, t) {
|
|
206
|
-
|
|
212
|
+
h({
|
|
207
213
|
buffer: this,
|
|
208
|
-
index:
|
|
214
|
+
index: v(e),
|
|
209
215
|
value: r(t, this.type, "stored value")
|
|
210
216
|
});
|
|
211
217
|
}
|
|
212
218
|
uniformLoad(e) {
|
|
213
219
|
if (this.atomic) throw TypeError("uniformLoad reads plain workgroup memory; use element() on atomic memory");
|
|
214
|
-
return
|
|
220
|
+
return m(new s(this.type, "g" + c(), [v(e)], (e, t) => (N.add(e.program), `workgroupUniformLoad(&${e.resource(this)}[${e.expr(t.args[0])}])`)));
|
|
215
221
|
}
|
|
216
222
|
rmw(e, t, ...n) {
|
|
217
223
|
if (!this.atomic) throw TypeError(`${e} needs workgroup(n, '${this.type}', {atomic: true})`);
|
|
218
|
-
return
|
|
224
|
+
return S(this, this.type, e, v(t), n.map((t) => r(t, this.type, e + " value")));
|
|
219
225
|
}
|
|
220
226
|
atomicAdd(e, t) {
|
|
221
227
|
return this.rmw("atomicAdd", e, t);
|
|
@@ -242,7 +248,7 @@ var R = class {
|
|
|
242
248
|
return this.rmw("atomicExchange", e, t);
|
|
243
249
|
}
|
|
244
250
|
atomicCompareExchange(e, t, n) {
|
|
245
|
-
return
|
|
251
|
+
return C(this.rmw("atomicCompareExchangeWeak", e, t, n));
|
|
246
252
|
}
|
|
247
253
|
atomicLoad(e) {
|
|
248
254
|
return this.rmw("atomicLoad", e);
|
|
@@ -250,14 +256,14 @@ var R = class {
|
|
|
250
256
|
atomicStore(e, t) {
|
|
251
257
|
this.store(e, t);
|
|
252
258
|
}
|
|
253
|
-
},
|
|
259
|
+
}, B = (e, t, { atomic: n = !1 } = {}) => new z(e, t, n), V = 0, H = (e) => {
|
|
254
260
|
let [t, n = 1, r = 1] = typeof e == "number" ? [e] : e;
|
|
255
261
|
return [
|
|
256
262
|
t,
|
|
257
263
|
n,
|
|
258
264
|
r
|
|
259
265
|
];
|
|
260
|
-
},
|
|
266
|
+
}, U = (e) => typeof e == "number" ? 1 : e.length, W = class e {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
261
267
|
constructor(e, t, { workgroupSize: n = [
|
|
262
268
|
64,
|
|
263
269
|
[8, 8],
|
|
@@ -266,50 +272,50 @@ var R = class {
|
|
|
266
272
|
4,
|
|
267
273
|
4
|
|
268
274
|
]
|
|
269
|
-
][
|
|
275
|
+
][U(e) - 1], order: r = -100, name: i = "shader:compute:" + V++, indirect: c, indirectOffset: l = 0 } = {}) {
|
|
270
276
|
this.count = e, this.program = new o(0, !0), this.last = [];
|
|
271
|
-
let u =
|
|
272
|
-
if (u.some((e) => !Number.isInteger(e) || e < 1) || d.some((e) => !Number.isInteger(e) || e < 1) || d[0] * d[1] * d[2] > 256 || d[2] > 64 || !c &&
|
|
277
|
+
let u = H(e), d = H(n), f = u.map((e, t) => Math.ceil(e / d[t]));
|
|
278
|
+
if (u.some((e) => !Number.isInteger(e) || e < 1) || d.some((e) => !Number.isInteger(e) || e < 1) || d[0] * d[1] * d[2] > 256 || d[2] > 64 || !c && f.some((e) => e > 65535) || !Number.isFinite(r)) throw RangeError("ComputePass needs a whole count of at least 1 on each axis, a workgroup size of at most 256 invocations and 64 along z that dispatches at most 65535 groups per axis, and a finite order; adjust count or workgroupSize.");
|
|
273
279
|
if (c && (c.type !== "u32" || !(l >= 0) || l + 3 > c.count)) throw RangeError("indirect needs a u32 storage buffer with three elements at indirectOffset");
|
|
274
|
-
let { list:
|
|
280
|
+
let { list: p, store: m, flush: g } = a, _ = a.list = [], v = [], y = /* @__PURE__ */ new Set();
|
|
275
281
|
a.store = (e) => v.push(e), a.flush = () => {
|
|
276
|
-
for (let e of v.splice(0)) y.add(e),
|
|
282
|
+
for (let e of v.splice(0)) y.add(e), h(e);
|
|
277
283
|
};
|
|
278
284
|
let b;
|
|
279
285
|
try {
|
|
280
|
-
b = t(
|
|
286
|
+
b = t(E);
|
|
281
287
|
} finally {
|
|
282
|
-
a.list =
|
|
288
|
+
a.list = p, a.store = m, a.flush = g;
|
|
283
289
|
}
|
|
284
290
|
let x = [b ?? []].flat(), S = x.filter((e) => !(e instanceof s));
|
|
285
|
-
if (!x.length && !_.length && !v.length || S.some((e) => !(e?.buffer instanceof
|
|
286
|
-
let
|
|
291
|
+
if (!x.length && !_.length && !v.length || S.some((e) => !(e?.buffer instanceof w))) throw TypeError("A ComputePass body must make storage.store(...) writes, statements or atomic operations; add one to the body.");
|
|
292
|
+
let C = [.../* @__PURE__ */ new Set([...S, ...v])].filter((e) => !y.has(e)), T = [..._, ...x.filter((e) => e instanceof s)], D = this.program, O = U(e), k = /* @__PURE__ */ new Set(), A = {
|
|
287
293
|
instanceIndex: O === 1 ? "gid.x" : O === 2 ? `(gid.y * ${u[0]}u + gid.x)` : `((gid.z * ${u[1]}u + gid.y) * ${u[0]}u + gid.x)`,
|
|
288
294
|
globalId: "gid"
|
|
289
295
|
};
|
|
290
|
-
for (let e in
|
|
291
|
-
let
|
|
296
|
+
for (let e in M) A[e] = (t) => (k.add(e), t.local(M[e][0]));
|
|
297
|
+
let j = this.program.stage({
|
|
292
298
|
kind: "compute",
|
|
293
299
|
builtins: A
|
|
294
|
-
}, [...
|
|
295
|
-
if (
|
|
300
|
+
}, [...T, ...C.flatMap((e) => [e.index, e.value])]), P = T.length, F = [], I = (e) => {
|
|
301
|
+
if (C.length < 2 || !/\bnd[bg]\d|textureLoad/.test(e)) return e;
|
|
296
302
|
let t = D.name();
|
|
297
303
|
return F.push(` let ${t} = ${e};\n`), t;
|
|
298
|
-
}, L =
|
|
299
|
-
let n = `${D.resource(e.buffer)}[${I(
|
|
304
|
+
}, L = C.map((e, t) => {
|
|
305
|
+
let n = `${D.resource(e.buffer)}[${I(j.values[P + t * 2])}]`, r = I(j.values[P + t * 2 + 1]);
|
|
300
306
|
return ` ${e.buffer.atomic ? `atomicStore(&${n}, ${r})` : `${n} = ${r}`};\n`;
|
|
301
|
-
}).join(""), R =
|
|
307
|
+
}).join(""), R = N.has(D);
|
|
302
308
|
if (R && !c && u.some((e, t) => e % d[t])) throw RangeError("A ComputePass with a barrier runs whole workgroups, so its count must be a multiple of workgroupSize; adjust either one.");
|
|
303
|
-
let z = O === 1 ? `gid.x >= ${u[0]}u` : O === 2 ? `any(gid.xy >= vec2u(${u[0]}u, ${u[1]}u))` : `any(gid >= vec3u(${u[0]}u, ${u[1]}u, ${u[2]}u))`,
|
|
304
|
-
this.name = i, this.order = r, this.groups =
|
|
309
|
+
let z = O === 1 ? `gid.x >= ${u[0]}u` : O === 2 ? `any(gid.xy >= vec2u(${u[0]}u, ${u[1]}u))` : `any(gid >= vec3u(${u[0]}u, ${u[1]}u, ${u[2]}u))`, B = R ? "" : ` if (${z}) { return; }\n`, W = [...k].map((e) => `, @builtin(${M[e][1]}) ${M[e][0]}:${M[e][2]}`).join(""), G = typeof n == "number" ? n : n.join(", ");
|
|
310
|
+
this.name = i, this.order = r, this.groups = f, this.indirect = c, this.indirectOffset = l, this.code = `${D.declare(0)}\n@compute @workgroup_size(${G}) fn main(@builtin(global_invocation_id) gid:vec3u${W}) {\n${B}${j.lines.map((e) => " " + e + "\n").join("")}${F.join("")}${L}}\n`;
|
|
305
311
|
}
|
|
306
|
-
static attach(t, n, r, i) {__margoAssertCore(t,__margoCoreRequirement("
|
|
312
|
+
static attach(t, n, r, i) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
307
313
|
let a = new e(n, r, i);
|
|
308
|
-
return
|
|
314
|
+
return _(t).use(a), a;
|
|
309
315
|
}
|
|
310
316
|
setup(e) {
|
|
311
|
-
if (!e.gpu) throw new
|
|
312
|
-
this.engine = e,
|
|
317
|
+
if (!e.gpu) throw new g("unsupported", "ComputePass requires WebGPU; see https://margoengine.com/errors#webgpu");
|
|
318
|
+
this.engine = e, d.hold(e, this);
|
|
313
319
|
}
|
|
314
320
|
registerPasses(e) {
|
|
315
321
|
e.add({
|
|
@@ -324,12 +330,12 @@ var R = class {
|
|
|
324
330
|
this.encode(e.device, e.encoder, {
|
|
325
331
|
width: e.width,
|
|
326
332
|
height: e.height,
|
|
327
|
-
time:
|
|
333
|
+
time: d.find(this.engine)?.time ?? 0,
|
|
328
334
|
delta: e.delta
|
|
329
335
|
});
|
|
330
336
|
}
|
|
331
337
|
encode(e, t, r) {
|
|
332
|
-
this.pipeline ??=
|
|
338
|
+
this.pipeline ??= u(e, this.code, "main");
|
|
333
339
|
let i = this.program.entries(e, r);
|
|
334
340
|
(!this.group || !n(i, this.last)) && (this.last = i, this.group = e.createBindGroup({
|
|
335
341
|
layout: this.pipeline.getBindGroupLayout(0),
|
|
@@ -344,11 +350,11 @@ var R = class {
|
|
|
344
350
|
}
|
|
345
351
|
dispose() {
|
|
346
352
|
let e = this.engine;
|
|
347
|
-
this.engine = void 0, this.onDeviceRestored(),
|
|
353
|
+
this.engine = void 0, this.onDeviceRestored(), d.release(e, this), e?.sceneOf(this)?.removePlugin(this.name);
|
|
348
354
|
}
|
|
349
355
|
[Symbol.dispose ?? Symbol()]() {
|
|
350
356
|
this.dispose();
|
|
351
357
|
}
|
|
352
358
|
};
|
|
353
359
|
//#endregion
|
|
354
|
-
export {
|
|
360
|
+
export { E as a, x as c, R as d, P as f, A as g, j as h, D as i, T as l, I as m, w as n, O as o, B as p, z as r, k as s, W as t, L as u };
|
package/dist/compute-texture.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T as e, o as t, rn as n, sn as r, tn as i } from "./node-
|
|
2
|
-
import { d as a, f as o } from "./control-
|
|
3
|
-
import { c as s } from "./compute-
|
|
1
|
+
import { T as e, o as t, rn as n, sn as r, tn as i } from "./node-B6yoIC9V.js";
|
|
2
|
+
import { d as a, f as o } from "./control-CFjkGPBk.js";
|
|
3
|
+
import { c as s } from "./compute-CXGG9qvI.js";
|
|
4
4
|
import { n as c, r as l, t as u } from "./storage-format-DWaiSxmq.js";
|
|
5
5
|
import { MargoError as d } from "@margoengine/math/errors";
|
|
6
6
|
//#region src/compute-texture.ts
|
package/dist/compute-volume.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T as e, cn as t, in as n, o as r, tn as i } from "./node-
|
|
2
|
-
import { d as a, f as o } from "./control-
|
|
3
|
-
import { c as s } from "./compute-
|
|
1
|
+
import { T as e, cn as t, in as n, o as r, tn as i } from "./node-B6yoIC9V.js";
|
|
2
|
+
import { d as a, f as o } from "./control-CFjkGPBk.js";
|
|
3
|
+
import { c as s } from "./compute-CXGG9qvI.js";
|
|
4
4
|
import { n as c, r as l, t as u } from "./storage-format-DWaiSxmq.js";
|
|
5
5
|
import { MargoError as d } from "@margoengine/math/errors";
|
|
6
6
|
//#region src/compute-volume.ts
|
package/dist/compute.d.ts
CHANGED
|
@@ -40,8 +40,14 @@ export declare class StorageBuffer<T extends StorageType = StorageType> implemen
|
|
|
40
40
|
/** @internal */ entries(device: GPUDevice): GPUBindingResource[];
|
|
41
41
|
/** The GPU copy for `device`, created from `data` on first use and after `update()`. */
|
|
42
42
|
buffer(device: GPUDevice): GPUBuffer;
|
|
43
|
-
/**
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Re-upload `data` on next use, replacing what the GPU computed. With `range` (in elements), only those elements are
|
|
45
|
+
* written, at once, to each copy that is otherwise up to date.
|
|
46
|
+
*/
|
|
47
|
+
update(range?: {
|
|
48
|
+
start: number;
|
|
49
|
+
count: number;
|
|
50
|
+
}): void;
|
|
45
51
|
/** Element `i` (an `atomicLoad` on an atomic buffer inside a ComputePass; use `atomicLoad` to fix when it reads relative to other atomics). */
|
|
46
52
|
element(i: Index): Node<T>;
|
|
47
53
|
/** A write made at the end of the ComputePass body (`atomicStore` on an atomic buffer); inside `If`, `Loop` and other statement bodies it happens right where it is called. */
|
package/dist/deform.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as e, fn as t, ln as n, mt as r, on as i, st as a, vt as o, wt as s } from "./node-
|
|
2
|
-
import { l as c } from "./compute-
|
|
1
|
+
import { T as e, fn as t, ln as n, mt as r, on as i, st as a, vt as o, wt as s } from "./node-B6yoIC9V.js";
|
|
2
|
+
import { l as c } from "./compute-CXGG9qvI.js";
|
|
3
3
|
import { MargoError as l } from "@margoengine/math/errors";
|
|
4
4
|
//#region ../shared/vertex-map.js
|
|
5
5
|
var u = /* @__PURE__ */ new WeakMap();
|
package/dist/editor-pass.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Lt as e, Mt as t, Rt as n, Zt as r, cn as i, ln as a } from "./node-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Lt as e, Mt as t, Rt as n, Zt as r, cn as i, ln as a } from "./node-B6yoIC9V.js";
|
|
2
|
+
import { g as o, i as s, n as c, o as l, t as u } from "./compute-CXGG9qvI.js";
|
|
3
|
+
import { n as d, r as f, t as p } from "./post-DLpZ110L.js";
|
|
4
4
|
import { compileSurfaceGraph as m, parseSurfaceGraph as h, serializeSurfaceGraph as g } from "./graph.js";
|
|
5
5
|
import { NodeEditor as _ } from "./editor.js";
|
|
6
6
|
import { ComputeTexture as v } from "./compute-texture.js";
|
|
@@ -88,34 +88,34 @@ function E(e) {
|
|
|
88
88
|
}
|
|
89
89
|
var D = (e, t, n) => {
|
|
90
90
|
let r = Object.hasOwn(e, t) ? e[t] : void 0;
|
|
91
|
-
if (!(r instanceof
|
|
92
|
-
if (r instanceof
|
|
91
|
+
if (!(r instanceof c || r instanceof v || r instanceof y)) throw TypeError(`Provide the pass graph resource '${t}'`);
|
|
92
|
+
if (r instanceof c ? r.type !== "vec4f" || r.count < n : /[us]int$/.test(r.format) || r.pixels < n) throw TypeError(`Use a float texture or vec4f buffer '${t}' large enough for ${n} invocations`);
|
|
93
93
|
return r;
|
|
94
|
-
}, O = (e, t) => e instanceof
|
|
94
|
+
}, O = (e, t) => e instanceof c ? e.element(t) : e.load(e.coord(t));
|
|
95
95
|
function k(h, g = {}) {
|
|
96
96
|
let _ = T(E(h));
|
|
97
97
|
if (_.kind === "post") {
|
|
98
|
-
let
|
|
98
|
+
let o = m(_.graph, {
|
|
99
99
|
position: i(e, 0),
|
|
100
100
|
worldPosition: i(t, 1),
|
|
101
|
-
normal: i(
|
|
101
|
+
normal: i(f()),
|
|
102
102
|
worldNormal: i(r),
|
|
103
|
-
color:
|
|
103
|
+
color: d().rgb,
|
|
104
104
|
uv: i(n, 0)
|
|
105
105
|
});
|
|
106
|
-
return new
|
|
106
|
+
return new p(a(o.colorNode?.rgb ?? i(0), o.opacityNode ?? d().a), { kind: _.colorSpace });
|
|
107
107
|
}
|
|
108
108
|
let v = _.compute, y = v.size.reduce((e, t) => e * t, 1), b = D(g, v.target, y), x = v.source ? D(g, v.source, y) : void 0;
|
|
109
|
-
return new
|
|
109
|
+
return new u(v.size, (e) => {
|
|
110
110
|
let t = m(_.graph, {
|
|
111
|
-
position:
|
|
112
|
-
worldPosition:
|
|
113
|
-
normal:
|
|
111
|
+
position: s.toFloat(),
|
|
112
|
+
worldPosition: o.toFloat(),
|
|
113
|
+
normal: l.toFloat(),
|
|
114
114
|
worldNormal: i(r),
|
|
115
115
|
color: x ? O(x, e).rgb : i(0),
|
|
116
|
-
uv:
|
|
116
|
+
uv: s.toFloat().add(.5).div(i(...v.size))
|
|
117
117
|
}), n = a(t.colorNode?.rgb ?? i(0), t.opacityNode ?? (x ? O(x, e).a : 1));
|
|
118
|
-
return b instanceof
|
|
118
|
+
return b instanceof c ? b.store(e, n) : b.store(b.coord(e), n);
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
var A = (e) => {
|
|
@@ -174,7 +174,7 @@ var A = (e) => {
|
|
|
174
174
|
...e,
|
|
175
175
|
graph: t
|
|
176
176
|
}, this.resources);
|
|
177
|
-
return n instanceof
|
|
177
|
+
return n instanceof p ? n.code() : n.code;
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
}), this.stop = this.view.onGraph(() => {
|
package/dist/effects.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as e, Lt as t, Mt as n, Rt as r, Ut as i, Wt as a, cn as o, ct as s, en as c, ft as l, ln as u, sn as d, ut as f, zt as p } from "./node-
|
|
2
|
-
import { n as m, t as h } from "./post-
|
|
1
|
+
import { D as e, Lt as t, Mt as n, Rt as r, Ut as i, Wt as a, cn as o, ct as s, en as c, ft as l, ln as u, sn as d, ut as f, zt as p } from "./node-B6yoIC9V.js";
|
|
2
|
+
import { n as m, t as h } from "./post-DLpZ110L.js";
|
|
3
3
|
//#region src/effects.ts
|
|
4
4
|
var g = 0;
|
|
5
5
|
function _(e, t, n) {
|
package/dist/glsl-material.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, t as d, u as f } from "./material-
|
|
1
|
+
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, t as d, u as f } from "./material-C6bpqlnE.js";
|
|
2
2
|
import { LinearToSRGB as p, parseColor as m } from "@margoengine/math/color";
|
|
3
3
|
//#region ../shared/fog.js
|
|
4
4
|
var h = (e, t, n, r) => {
|
|
@@ -129,7 +129,7 @@ function x(o) {
|
|
|
129
129
|
${t}
|
|
130
130
|
${h(!1)}${n}${c.map((e) => `let margoKept_${e}=${e};\n`).join("")}${r}();
|
|
131
131
|
${l("margoClip")}${c.map((e) => `${e}=margoKept_${e};\n`).join("")}${h(!0)}${r}();
|
|
132
|
-
${l("margoPrevious")}return MargoVelocity(margoClip,margoPrevious);
|
|
132
|
+
${l("margoPrevious")}return MargoVelocity(margoClip,margoPrevious,margoClip);
|
|
133
133
|
}
|
|
134
134
|
`;
|
|
135
135
|
}
|
package/dist/glsl-pass.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
3
|
|
|
4
4
|
import { n as e, r as t, t as n } from "./view-rect-Bm1ac-TK.js";
|
|
5
5
|
import { t as r } from "./own-stack-D1XnXrrz.js";
|
|
6
|
-
import { i } from "./raw-
|
|
7
|
-
import { n as a, t as o } from "./material-
|
|
6
|
+
import { i } from "./raw-0AYej3Ak.js";
|
|
7
|
+
import { n as a, t as o } from "./material-C6bpqlnE.js";
|
|
8
8
|
import { MargoError as s } from "@margoengine/math/errors";
|
|
9
9
|
//#region src/glsl-pass.ts
|
|
10
10
|
var c = [
|
|
@@ -74,7 +74,7 @@ function h(e, t) {
|
|
|
74
74
|
let n = /^\s*#\s*version\s+300\s+es\b/m.test(e) || t === 300, r = l.filter((t) => m(e, "vec2", t)), [i, a] = n ? ["in", "out"] : ["attribute", "varying"];
|
|
75
75
|
return `${n ? "#version 300 es\n" : ""}${i} vec3 position;\n${i} vec2 uv;\n${r.map((e) => `${a} vec2 ${e};\n`).join("")}void main() { ${r.map((e) => `${e} = uv; `).join("")}gl_Position = vec4(position.xy, 0.0, 1.0); }\n`;
|
|
76
76
|
}
|
|
77
|
-
var g = 0, _ = class l {coreRequirement=__margoCoreRequirement("
|
|
77
|
+
var g = 0, _ = class l {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
78
78
|
constructor(e, t = {}) {
|
|
79
79
|
if (this.raw = new i({ name: "shader:glsl-pass:raw" }), this.disposed = !1, this.rect = "", this.context = {
|
|
80
80
|
format: "rgba8unorm",
|
|
@@ -103,7 +103,7 @@ var g = 0, _ = class l {coreRequirement=__margoCoreRequirement("0.1.0",import.me
|
|
|
103
103
|
}), this.input !== null && !this.material.program.textures.some((e) => e.name === this.input)) throw new s("failed", `ShaderPass input ${this.input} is not a sampler of the program; declare it or pass input: null`);
|
|
104
104
|
this.mesh = a(p, this.material, { frustumCulled: !1 });
|
|
105
105
|
}
|
|
106
|
-
static async attach(e, t, n = {}) {__margoAssertCore(e,__margoCoreRequirement("
|
|
106
|
+
static async attach(e, t, n = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
107
107
|
let { signal: i, ...a } = n;
|
|
108
108
|
i?.throwIfAborted();
|
|
109
109
|
let o = new l(t, a);
|