@margoengine/shader 0.0.0-stage → 0.1.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 +1771 -3
- package/dist/black-hole.d.ts +246 -0
- package/dist/black-hole.js +445 -0
- package/dist/clock-BLGNexlt.js +52 -0
- package/dist/clock.d.ts +42 -0
- package/dist/compute-D-BghbXj.js +354 -0
- package/dist/compute-texture.d.ts +100 -0
- package/dist/compute-texture.js +131 -0
- package/dist/compute-volume.d.ts +57 -0
- package/dist/compute-volume.js +130 -0
- package/dist/compute.d.ts +194 -0
- package/dist/control-DvjfV7R0.js +201 -0
- package/dist/control.d.ts +93 -0
- package/dist/deform.d.ts +111 -0
- package/dist/deform.js +89 -0
- package/dist/display-BrJM_Qkd.js +5 -0
- package/dist/editor-model.d.ts +192 -0
- package/dist/editor-pass.d.ts +71 -0
- package/dist/editor-pass.js +216 -0
- package/dist/editor.d.ts +150 -0
- package/dist/editor.js +1071 -0
- package/dist/effects.d.ts +150 -0
- package/dist/effects.js +87 -0
- package/dist/errors-CsQwshHA.js +7 -0
- package/dist/glsl/emit.d.ts +43 -0
- package/dist/glsl/host.d.ts +55 -0
- package/dist/glsl/material.d.ts +173 -0
- package/dist/glsl/parser.d.ts +76 -0
- package/dist/glsl/preprocess.d.ts +9 -0
- package/dist/glsl/presets.d.ts +33 -0
- package/dist/glsl/program.d.ts +210 -0
- package/dist/glsl/scene.d.ts +9 -0
- package/dist/glsl-material.d.ts +82 -0
- package/dist/glsl-material.js +288 -0
- package/dist/glsl-pass.d.ts +93 -0
- package/dist/glsl-pass.js +186 -0
- package/dist/glsl.d.ts +94 -0
- package/dist/glsl.js +170 -0
- package/dist/gpu-DQ5Jmggz.js +31 -0
- package/dist/graph.d.ts +82 -0
- package/dist/graph.js +365 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/lighting-Dx8_RsBz.js +77 -0
- package/dist/lighting.d.ts +62 -0
- package/dist/lighting.js +1 -0
- package/dist/material-CU7p-Q8u.js +1184 -0
- package/dist/material-REzUrXtu.js +275 -0
- package/dist/material.d.ts +74 -0
- package/dist/node-DzKv9CF2.js +590 -0
- package/dist/node.d.ts +427 -0
- package/dist/noise.d.ts +38 -0
- package/dist/noise.js +107 -0
- package/dist/own-stack-D1XnXrrz.js +11 -0
- package/dist/own-stack.d.ts +12 -0
- package/dist/pass.d.ts +108 -0
- package/dist/pass.js +236 -0
- package/dist/post-DC62ZleD.js +113 -0
- package/dist/post.d.ts +69 -0
- package/dist/preprocess-CWGWlBWQ.js +1195 -0
- package/dist/raw-D0W8U3Qa.js +1351 -0
- package/dist/raw.d.ts +634 -0
- package/dist/raw.js +1 -0
- package/dist/readback.d.ts +42 -0
- package/dist/readback.js +84 -0
- package/dist/scope.d.ts +21 -0
- package/dist/serialization.d.ts +11 -0
- package/dist/serialization.js +192 -0
- package/dist/shadertoy/sound.d.ts +48 -0
- package/dist/shadertoy.d.ts +249 -0
- package/dist/shadertoy.js +909 -0
- package/dist/shared/caster.d.ts +152 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/fractal.d.ts +9 -0
- package/dist/shared/msaa.d.ts +25 -0
- package/dist/shared/stack.d.ts +22 -0
- package/dist/sound-CF_dzP41.js +78 -0
- package/dist/storage-format-DWaiSxmq.js +25 -0
- package/dist/storage-format.d.ts +7 -0
- package/dist/subgroups.d.ts +97 -0
- package/dist/subgroups.js +95 -0
- package/dist/texture-D6vy0bam.js +62 -0
- package/dist/texture-array.d.ts +7 -0
- package/dist/texture-array.js +11 -0
- package/dist/texture.d.ts +16 -0
- package/dist/utils.d.ts +106 -0
- package/dist/utils.js +90 -0
- package/dist/view-rect-Bm1ac-TK.js +16 -0
- package/package.json +151 -6
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/** Vertex buffers of a 24-byte (core) or 80-byte (gltf/pbr) caster, plus instance matrices when `instanced`. */
|
|
2
|
+
export function casterBuffers(stride: number, displaced?: boolean, instanced?: boolean): GPUVertexBufferLayout[];
|
|
3
|
+
/** How a caster cuts its surface out like its colour pass, besides its alpha texture and cutoff. */
|
|
4
|
+
export interface CasterCutout {
|
|
5
|
+
/** UV transform of `alphaTexture` (80-byte vertices): 8 finite floats, rows (a, b, offset, unused) for u and then v. */
|
|
6
|
+
alphaTransform?: Float32Array;
|
|
7
|
+
/** Opacity map of the cut-out (materials `alphaMap`, 80-byte vertices): its green channel multiplies the alpha tested. */
|
|
8
|
+
opacity?: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler };
|
|
9
|
+
/**
|
|
10
|
+
* Moving UVs of the cut-out (VRMC_materials_mtoon 1.0 UV animation, 80-byte vertices): an 80-byte uniform (scroll x,
|
|
11
|
+
* scroll y, rotation, time; the base map's affine rows; the mask's affine rows), the mask view and its sampler. The
|
|
12
|
+
* alpha map is read at the animated UV in place of `alphaTransform`'s, as the colour pass reads it.
|
|
13
|
+
*/
|
|
14
|
+
animation?: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler };
|
|
15
|
+
/** False keeps vertex alpha out of the cut-out, as the colour pass does (materials `vertexColors: false`). Default true. */
|
|
16
|
+
vertexAlpha?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Cuts against hashed noise instead of `cutoff`, as materials `alphaHash()` does in its colour pass, so the shadow
|
|
19
|
+
* keeps a share of texels equal to the opacity: the caster shader edit (shared/alpha-hash.js `hashedDepth`) that a
|
|
20
|
+
* materials record hands over as `castHashed`, so only an app that imports `alphaHash` carries its WGSL. Only a
|
|
21
|
+
* primitive that cuts (`cutoff` above 0) uses it. Default none.
|
|
22
|
+
*/
|
|
23
|
+
hashed?: (code: string) => string;
|
|
24
|
+
/** Vertex displacement along the normal (materials `displacementMap`, 80-byte vertices). */
|
|
25
|
+
displacement?: CasterDisplacement;
|
|
26
|
+
/** Planes that clip the shadow (materials `clippingPlanes` with `clipShadows`, 80-byte vertices). */
|
|
27
|
+
clip?: GPUBufferBinding;
|
|
28
|
+
/** Planes that clip the surface, whatever `clipShadows` says (80-byte vertices). */
|
|
29
|
+
surfaceClip?: GPUBufferBinding;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What moves a caster's vertices: a displacement map's uniform, view and sampler, or a shader patch of its own (a
|
|
33
|
+
* NodeMaterial's graph), with a `key` for its pipeline and its bind group.
|
|
34
|
+
*/
|
|
35
|
+
export type CasterDisplacement =
|
|
36
|
+
| {
|
|
37
|
+
readonly buffer: GPUBuffer;
|
|
38
|
+
readonly view: GPUTextureView;
|
|
39
|
+
readonly sampler: GPUSampler;
|
|
40
|
+
readonly key?: undefined;
|
|
41
|
+
readonly depth?: undefined;
|
|
42
|
+
readonly velocity?: undefined;
|
|
43
|
+
readonly entries?: undefined;
|
|
44
|
+
readonly layout?: undefined;
|
|
45
|
+
readonly cuts?: undefined;
|
|
46
|
+
readonly move?: undefined;
|
|
47
|
+
readonly program?: undefined;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
readonly key: string;
|
|
51
|
+
depth(code: string, group: number): string;
|
|
52
|
+
/** TAA's object velocity shader, moved and cut as `depth` does it. Absent on a patch that does not support it. */
|
|
53
|
+
velocity?(code: string, group: number): string;
|
|
54
|
+
entries(): GPUBindGroupEntry[];
|
|
55
|
+
/** The group's layout, for passes that build their pipeline layouts by hand. */
|
|
56
|
+
layout(): GPUBindGroupLayout;
|
|
57
|
+
/** The patch discards fragments, so a pass that skips the fragment stage of opaque casters needs it here. */
|
|
58
|
+
readonly cuts: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The WGSL lines of the patch's move of `margoPosition` alone (empty: no move), and its program: TAA runs a move
|
|
61
|
+
* that reads the uniform block `ndu` again on last frame's bytes of it, bound at `program.next`.
|
|
62
|
+
*/
|
|
63
|
+
readonly move?: readonly string[];
|
|
64
|
+
readonly program?: { readonly next: number; readonly buffers: WeakMap<GPUDevice, { bytes: Uint8Array }> };
|
|
65
|
+
};
|
|
66
|
+
/** A depth-only caster pipeline (less-equal depth into depth32float, line lists for `lines`). */
|
|
67
|
+
export function casterPipeline(
|
|
68
|
+
device: GPUDevice,
|
|
69
|
+
module: GPUShaderModule,
|
|
70
|
+
stride: number,
|
|
71
|
+
displaced: boolean,
|
|
72
|
+
instanced: boolean,
|
|
73
|
+
lines: boolean | undefined,
|
|
74
|
+
): GPURenderPipeline;
|
|
75
|
+
/** The per-primitive draw records of `node` in `draws`, created empty on first use. */
|
|
76
|
+
export function nodeRecords<N, K, R>(draws: Map<N, Map<K, R>>, node: N): Map<K, R>;
|
|
77
|
+
/** The runtime object of a caster source; throws MargoError 'disposed' or 'attached'. */
|
|
78
|
+
export function casterRuntime<S extends object, R>(source: S, engine: unknown, noun: string): R;
|
|
79
|
+
/**
|
|
80
|
+
* The bind group of a displaced caster: its feature uniform, map and sampler; else undefined. Also undefined when the
|
|
81
|
+
* displacement binds nothing and `layout` is an automatic layout's group (`explicit` false, the default), which a
|
|
82
|
+
* default pipeline layout does not hold.
|
|
83
|
+
*/
|
|
84
|
+
export function displacementGroup(
|
|
85
|
+
device: GPUDevice,
|
|
86
|
+
layout: () => GPUBindGroupLayout,
|
|
87
|
+
displacement: CasterDisplacement | undefined,
|
|
88
|
+
explicit?: boolean,
|
|
89
|
+
): GPUBindGroup | undefined;
|
|
90
|
+
/** WGSL of a moving cut-out (MToon UV animation) at bindings `first` to `first` + 2 (default 7), and `margoAnimatedUV`. */
|
|
91
|
+
export function animationCode(group: number, first?: number): string;
|
|
92
|
+
/** A caster depth shader whose cut-out reads its alpha map at the animated UV, bound at 7-9 of `group`. */
|
|
93
|
+
export function animatedDepth(code: string, group: number, first?: number): string;
|
|
94
|
+
/** The bind group entries of a caster's UV `animation`, from binding `first` (default 7). */
|
|
95
|
+
export function animationEntries(
|
|
96
|
+
animation: { readonly buffer: GPUBuffer; readonly view: GPUTextureView; readonly sampler: GPUSampler },
|
|
97
|
+
first?: number,
|
|
98
|
+
): GPUBindGroupEntry[];
|
|
99
|
+
/** WGSL of an opacity map at bindings `first` to `first` + 2 (default 4) of `group`, and `margoOpacityAt` of both UV sets. */
|
|
100
|
+
export function opacityCode(group: number, first?: number): string;
|
|
101
|
+
/** A caster depth shader whose cut-out also multiplies by an opacity map's green channel, bound at 4-6 of `group`. */
|
|
102
|
+
export function opacityDepth(code: string, group: number): string;
|
|
103
|
+
/** The bind group entries of a caster's `opacity`, from binding `first` (default 4). */
|
|
104
|
+
export function opacityEntries(
|
|
105
|
+
opacity: {
|
|
106
|
+
buffer: GPUBuffer;
|
|
107
|
+
view: GPUTextureView;
|
|
108
|
+
sampler: GPUSampler;
|
|
109
|
+
},
|
|
110
|
+
first?: number,
|
|
111
|
+
): GPUBindGroupEntry[];
|
|
112
|
+
/** A caster shader that leaves vertex alpha out of its cut-out (a primitive with `vertexAlpha: false`). */
|
|
113
|
+
export function solidVertexDepth(code: string): string;
|
|
114
|
+
/** A caster shader that discards what uniform `name`'s planes cut away, bound at `binding` of group 0. */
|
|
115
|
+
export function clippedDepth(code: string, binding: number, name: string, hardware?: boolean): string;
|
|
116
|
+
/** A cleared depth-only pass descriptor; set `depthStencilAttachment.view` before each use. */
|
|
117
|
+
export function depthPassDescriptor(): GPURenderPassDescriptor & {
|
|
118
|
+
depthStencilAttachment: GPURenderPassDepthStencilAttachment;
|
|
119
|
+
};
|
|
120
|
+
/** Writes one caster's uniform (view, node matrix, alpha, cutoff at least `floor`, uv set, alpha transform), uploads it and draws. */
|
|
121
|
+
export function drawCaster(
|
|
122
|
+
pass: GPURenderPassEncoder,
|
|
123
|
+
device: GPUDevice,
|
|
124
|
+
pipeline: GPURenderPipeline,
|
|
125
|
+
group: GPUBindGroup,
|
|
126
|
+
uniform: GPUBuffer,
|
|
127
|
+
values: Float32Array<ArrayBuffer>,
|
|
128
|
+
view: ArrayLike<number>,
|
|
129
|
+
p: {
|
|
130
|
+
node: { matrix: ArrayLike<number> };
|
|
131
|
+
alpha?: number;
|
|
132
|
+
cutoff?: number;
|
|
133
|
+
texCoord?: number;
|
|
134
|
+
vertex: GPUBuffer;
|
|
135
|
+
/** Byte offset of the caster's vertices in `vertex`. Default 0. */
|
|
136
|
+
vertexOffset?: number;
|
|
137
|
+
index: GPUBuffer;
|
|
138
|
+
count: number;
|
|
139
|
+
},
|
|
140
|
+
transform: ArrayLike<number> | undefined | null,
|
|
141
|
+
displaced: GPUBindGroup | undefined,
|
|
142
|
+
instances: { upload(device: GPUDevice): GPUBuffer; count: number } | undefined | null,
|
|
143
|
+
/** Lowest cutoff written: the larger of this and `p.cutoff`. Default 0. */
|
|
144
|
+
floor?: number,
|
|
145
|
+
): void;
|
|
146
|
+
/** Whether a caster's cached draw `record` no longer fits primitive `p` drawn with `pipeline` and `displacement`. */
|
|
147
|
+
export function staleCaster<R extends object>(
|
|
148
|
+
record: R | undefined,
|
|
149
|
+
p: { vertex: GPUBuffer; alphaTexture?: unknown; alphaSampler?: unknown; opacity?: unknown; animation?: unknown },
|
|
150
|
+
pipeline: GPURenderPipeline,
|
|
151
|
+
displacement: unknown,
|
|
152
|
+
): record is undefined;
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Octave sum settings for `fbm` and `ridged`. */
|
|
2
|
+
export interface FractalOptions {
|
|
3
|
+
/** Octaves summed, 1..16 (default 5). */ octaves?: number;
|
|
4
|
+
/** Frequency multiplier per octave (default 2). */ lacunarity?: number;
|
|
5
|
+
/** Amplitude multiplier per octave (default 0.5). */ gain?: number;
|
|
6
|
+
/** Frequency of the first octave (default 1). */ frequency?: number;
|
|
7
|
+
}
|
|
8
|
+
/** `[octaves, lacunarity, gain, frequency]` with the defaults; RangeError for invalid settings. */
|
|
9
|
+
export function fractalOptions(options: FractalOptions): [number, number, number, number];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PassContext } from '@margoengine/core/extension';
|
|
2
|
+
type Context = Extract<PassContext, { backend: 'webgpu' }>;
|
|
3
|
+
export class SceneTarget {
|
|
4
|
+
constructor(device: GPUDevice, color: GPUTexture, depth: GPUTexture, samples?: number);
|
|
5
|
+
readonly samples: number;
|
|
6
|
+
readonly color: GPUTextureView;
|
|
7
|
+
readonly depth: GPUTextureView;
|
|
8
|
+
readonly resolvedColor: GPUTexture;
|
|
9
|
+
readonly resolvedDepth: GPUTexture;
|
|
10
|
+
readonly depthSource?: GPUTextureView;
|
|
11
|
+
begin(context: Context): void;
|
|
12
|
+
/** Resolves colour and, unless `depth` is false (a final resolve whose caller reads no 1x depth afterwards), depth. */
|
|
13
|
+
resolve(encoder: GPUCommandEncoder, final?: boolean, depth?: boolean): void;
|
|
14
|
+
/** Copies reversed-Z depth; format defaults to the capture depth format. */
|
|
15
|
+
copyDepth(encoder: GPUCommandEncoder, view: GPUTextureView, count: number, format?: GPUTextureFormat): void;
|
|
16
|
+
restore(context: Context): void;
|
|
17
|
+
present(context: Context): void;
|
|
18
|
+
dispose(): void;
|
|
19
|
+
}
|
|
20
|
+
/** `[null]` where a fragment shader can read `@builtin(sample_index)`, else each sample index (compatibility level). */
|
|
21
|
+
export function perSample(device: GPUDevice, count: number): (number | null)[];
|
|
22
|
+
export function sceneTarget(context: Context): SceneTarget | undefined;
|
|
23
|
+
export function resolveMSAA(context: Context): void;
|
|
24
|
+
|
|
25
|
+
export function sceneSamples(): number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Types only: the protocol between @margoengine/post's PostStack and the effects it combines.
|
|
2
|
+
import type { PassContext } from '@margoengine/core/extension';
|
|
3
|
+
import type { SceneTarget } from './msaa.js';
|
|
4
|
+
type Context = Extract<PassContext, { backend: 'webgpu' }>;
|
|
5
|
+
/** The shared capture; both fields change identity on resize and device restoration. */
|
|
6
|
+
export interface StackHost {
|
|
7
|
+
target?: SceneTarget;
|
|
8
|
+
depthTexture?: GPUTexture;
|
|
9
|
+
}
|
|
10
|
+
/** Linear HDR (rgba16float, 1x) when `hdr`, otherwise display-encoded output of `format` and `multisample`. */
|
|
11
|
+
export interface StageOutput {
|
|
12
|
+
view: GPUTextureView;
|
|
13
|
+
format: GPUTextureFormat;
|
|
14
|
+
multisample: GPUMultisampleState;
|
|
15
|
+
hdr: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** hdr effects read and write linear light (tonemapping only when last); a display effect ends the HDR chain; ldr effects follow it.
|
|
18
|
+
* render may return its own view for the next stage instead of writing `output`. */
|
|
19
|
+
export interface StackStage {
|
|
20
|
+
readonly kind: 'hdr' | 'display' | 'ldr';
|
|
21
|
+
render(context: Context, input: GPUTextureView, output: StageOutput): GPUTextureView | void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MargoError as e } from "@margoengine/math/errors";
|
|
2
|
+
//#region src/shadertoy/sound.ts
|
|
3
|
+
var t = 512, n = 262144, r = class {
|
|
4
|
+
constructor(e, t, r, i) {
|
|
5
|
+
this.samples = e, this.sampleRate = t, this.draw = r, this.next = 0, this.read = 0, this.over = !1, this.output = {
|
|
6
|
+
view: void 0,
|
|
7
|
+
format: "rgba32float",
|
|
8
|
+
multisample: { count: 1 },
|
|
9
|
+
hdr: !1
|
|
10
|
+
}, this.submitted = [], this.done = new Promise((e, t) => {
|
|
11
|
+
this.resolve = e, this.reject = t;
|
|
12
|
+
}), this.blocks = Math.ceil(e / n), this.left = new Float32Array(e), this.right = new Float32Array(e), i?.aborted ? this.stop(i.reason) : i?.addEventListener("abort", () => this.stop(i.reason), { once: !0 });
|
|
13
|
+
}
|
|
14
|
+
frame(e) {
|
|
15
|
+
if (this.over) return;
|
|
16
|
+
this.device !== e.device && (this.release(), this.device = e.device, this.next = this.read = 0);
|
|
17
|
+
for (let t of this.submitted.splice(0)) this.map(t.buffer, t.block, e.device);
|
|
18
|
+
if (this.next === this.blocks) return;
|
|
19
|
+
let t = e.device;
|
|
20
|
+
this.texture || (this.texture = t.createTexture({
|
|
21
|
+
label: "shader:shadertoy:sound",
|
|
22
|
+
size: [512, 512],
|
|
23
|
+
format: "rgba32float",
|
|
24
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC
|
|
25
|
+
}), this.output.view = this.texture.createView()), this.frameContext?.base !== e && (this.frameContext = {
|
|
26
|
+
base: e,
|
|
27
|
+
context: Object.create(e, {
|
|
28
|
+
width: { value: 512 },
|
|
29
|
+
height: { value: 512 },
|
|
30
|
+
view: { value: void 0 }
|
|
31
|
+
})
|
|
32
|
+
}), this.draw(this.frameContext.context, this.next * n, this.output);
|
|
33
|
+
let r = t.createBuffer({
|
|
34
|
+
label: "shader:shadertoy:sound",
|
|
35
|
+
size: n * 16,
|
|
36
|
+
usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
|
|
37
|
+
});
|
|
38
|
+
e.encoder.copyTextureToBuffer({ texture: this.texture }, {
|
|
39
|
+
buffer: r,
|
|
40
|
+
bytesPerRow: 8192
|
|
41
|
+
}, [512, 512]), this.submitted.push({
|
|
42
|
+
buffer: r,
|
|
43
|
+
block: this.next++
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
map(t, r, i) {
|
|
47
|
+
t.mapAsync(GPUMapMode.READ).then(() => {
|
|
48
|
+
if (!this.over && i === this.device) {
|
|
49
|
+
let e = new Float32Array(t.getMappedRange()), i = r * n, a = Math.min(n, this.samples - i);
|
|
50
|
+
for (let t = 0; t < a; t++) this.left[i + t] = e[t * 4], this.right[i + t] = e[t * 4 + 1];
|
|
51
|
+
++this.read === this.blocks && this.finish();
|
|
52
|
+
}
|
|
53
|
+
t.destroy();
|
|
54
|
+
}, (n) => {
|
|
55
|
+
t.destroy(), i === this.device && !this.over && this.stop(new e("failed", `Shadertoy sound readback failed (${String(n)}); call toy.sound() again`));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
finish() {
|
|
59
|
+
let { left: e, right: t, sampleRate: n } = this;
|
|
60
|
+
this.over = !0, this.release(), this.resolve({
|
|
61
|
+
sampleRate: n,
|
|
62
|
+
channels: [e, t],
|
|
63
|
+
audioBuffer(r) {
|
|
64
|
+
let i = r.createBuffer(2, e.length, n);
|
|
65
|
+
return i.copyToChannel(e, 0), i.copyToChannel(t, 1), i;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
stop(e) {
|
|
70
|
+
this.over || (this.over = !0, this.release(), this.reject(e));
|
|
71
|
+
}
|
|
72
|
+
release() {
|
|
73
|
+
this.texture?.destroy(), this.texture = this.frameContext = void 0;
|
|
74
|
+
for (let e of this.submitted.splice(0)) e.buffer.destroy();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { t as EDGE, r as SoundJob };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/storage-format.ts
|
|
2
|
+
var e = {
|
|
3
|
+
rgba8unorm: 4,
|
|
4
|
+
rgba8snorm: 4,
|
|
5
|
+
rgba8uint: 4,
|
|
6
|
+
rgba8sint: 4,
|
|
7
|
+
rgba16float: 8,
|
|
8
|
+
rgba16uint: 8,
|
|
9
|
+
rgba16sint: 8,
|
|
10
|
+
r32float: 4,
|
|
11
|
+
r32uint: 4,
|
|
12
|
+
r32sint: 4,
|
|
13
|
+
rg32float: 8,
|
|
14
|
+
rg32uint: 8,
|
|
15
|
+
rg32sint: 8,
|
|
16
|
+
rgba32float: 16,
|
|
17
|
+
rgba32uint: 16,
|
|
18
|
+
rgba32sint: 16
|
|
19
|
+
}, t = (e) => /uint$/.test(e) ? "vec4u" : /sint$/.test(e) ? "vec4i" : "vec4f", n = (e) => ({
|
|
20
|
+
vec4f: "f32",
|
|
21
|
+
vec4i: "i32",
|
|
22
|
+
vec4u: "u32"
|
|
23
|
+
})[t(e)];
|
|
24
|
+
//#endregion
|
|
25
|
+
export { n, t as r, e as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Formats WebGPU can write from a compute shader on every device. */
|
|
2
|
+
export type StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16float' | 'rgba16uint' | 'rgba16sint' | 'r32float' | 'r32uint' | 'r32sint' | 'rg32float' | 'rg32uint' | 'rg32sint' | 'rgba32float' | 'rgba32uint' | 'rgba32sint';
|
|
3
|
+
/** What `load` returns and `store` takes: four components, whatever the format holds (a missing one reads 0, alpha 1). */
|
|
4
|
+
export type Texel<F extends StorageFormat> = F extends `${string}uint` ? 'vec4u' : F extends `${string}sint` ? 'vec4i' : 'vec4f';
|
|
5
|
+
export declare const bytes: Record<StorageFormat, number>;
|
|
6
|
+
export declare const texel: (f: StorageFormat) => "vec4f" | "vec4i" | "vec4u";
|
|
7
|
+
export declare const sampled: (f: StorageFormat) => string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
2
|
+
import { Node, type Matrix, type NodeInput, type Type } from './node.js';
|
|
3
|
+
/** Types a subgroup reduction takes: every scalar and vector but the booleans. */
|
|
4
|
+
export type SubgroupValue = Exclude<Type, Matrix | 'bool' | `vec${2 | 3 | 4}<bool>`>;
|
|
5
|
+
/** Types the bitwise reductions take. */
|
|
6
|
+
export type SubgroupBits = Extract<SubgroupValue, 'i32' | 'u32' | `vec${2 | 3 | 4}${'i' | 'u'}`>;
|
|
7
|
+
/** Full-precision float types {@link HalfFloats.half} takes. */
|
|
8
|
+
export type FullFloat = 'f32' | 'vec2f' | 'vec3f' | 'vec4f';
|
|
9
|
+
/** The half-float type of a {@link FullFloat}: `'f16'` for `'f32'`, `'vec3h'` for `'vec3f'`. */
|
|
10
|
+
export type HalfOf<T extends FullFloat> = T extends 'f32' ? 'f16' : T extends `vec${infer K extends 2 | 3 | 4}f` ? `vec${K}h` : never;
|
|
11
|
+
/** The full-precision type of a half-float type. */
|
|
12
|
+
export type FullOf<T extends HalfFloat> = T extends 'f16' ? 'f32' : T extends `vec${infer K extends 2 | 3 | 4}h` ? `vec${K}f` : never;
|
|
13
|
+
/** Half-float node types. */
|
|
14
|
+
export type HalfFloat = 'f16' | 'vec2h' | 'vec3h' | 'vec4h';
|
|
15
|
+
/**
|
|
16
|
+
* Subgroup operations of one device, from {@link subgroups}. Lanes of a subgroup run together, and the operations read across
|
|
17
|
+
* them with no workgroup memory and no barrier. Write for any `size`: a device with no `subgroups` feature gives subgroups of one
|
|
18
|
+
* lane, where a reduction is the value itself, and code that is right for every size stays right.
|
|
19
|
+
* An operation must run in uniform control flow, so a ComputePass using them runs whole workgroups, as with a barrier.
|
|
20
|
+
*/
|
|
21
|
+
export interface Subgroups {
|
|
22
|
+
/** True when the device has the `subgroups` feature: the nodes below are the hardware's. */
|
|
23
|
+
readonly supported: boolean;
|
|
24
|
+
/** Lanes in this subgroup. */
|
|
25
|
+
readonly size: Node<'u32'>;
|
|
26
|
+
/** This lane's number, from 0. */
|
|
27
|
+
readonly id: Node<'u32'>;
|
|
28
|
+
/** The sum of `x` over the lanes. */
|
|
29
|
+
add<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
30
|
+
/** The product of `x` over the lanes. */
|
|
31
|
+
mul<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
32
|
+
/** The least `x` over the lanes. */
|
|
33
|
+
min<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
34
|
+
/** The greatest `x` over the lanes. */
|
|
35
|
+
max<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
36
|
+
/** Bitwise and of `x` over the lanes. */
|
|
37
|
+
and<T extends SubgroupBits>(x: Node<T>): Node<T>;
|
|
38
|
+
/** Bitwise or of `x` over the lanes. */
|
|
39
|
+
or<T extends SubgroupBits>(x: Node<T>): Node<T>;
|
|
40
|
+
/** Bitwise xor of `x` over the lanes. */
|
|
41
|
+
xor<T extends SubgroupBits>(x: Node<T>): Node<T>;
|
|
42
|
+
/** The sum of `x` over the lanes up to and including this one. */
|
|
43
|
+
inclusiveAdd<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
44
|
+
/** The sum of `x` over the lanes before this one (0 on the first). */
|
|
45
|
+
exclusiveAdd<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
46
|
+
/** The product of `x` over the lanes up to and including this one. */
|
|
47
|
+
inclusiveMul<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
48
|
+
/** The product of `x` over the lanes before this one (1 on the first). */
|
|
49
|
+
exclusiveMul<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
50
|
+
/** True when `x` holds on every lane. */
|
|
51
|
+
all(x: Node<'bool'>): Node<'bool'>;
|
|
52
|
+
/** True when `x` holds on any lane. */
|
|
53
|
+
any(x: Node<'bool'>): Node<'bool'>;
|
|
54
|
+
/** A bit per lane where `x` holds: lane 0 is bit 0 of `.x`, lane 32 bit 0 of `.y`. */
|
|
55
|
+
ballot(x: Node<'bool'>): Node<'vec4u'>;
|
|
56
|
+
/** True on one lane of the subgroup: the one to write its result. */
|
|
57
|
+
elect(): Node<'bool'>;
|
|
58
|
+
/** `x` of lane `lane`, a constant below `size`. */
|
|
59
|
+
broadcast<T extends SubgroupValue>(x: Node<T>, lane: number): Node<T>;
|
|
60
|
+
/** `x` of the first active lane. */
|
|
61
|
+
broadcastFirst<T extends SubgroupValue>(x: Node<T>): Node<T>;
|
|
62
|
+
/** `x` of lane `lane`, which may differ per lane. Keep it below `size`. */
|
|
63
|
+
shuffle<T extends SubgroupValue>(x: Node<T>, lane: NodeInput<'u32'>): Node<T>;
|
|
64
|
+
/** `x` of the lane `delta` below this one. Keep it within the subgroup. */
|
|
65
|
+
shuffleUp<T extends SubgroupValue>(x: Node<T>, delta: NodeInput<'u32'>): Node<T>;
|
|
66
|
+
/** `x` of the lane `delta` above this one. Keep it within the subgroup. */
|
|
67
|
+
shuffleDown<T extends SubgroupValue>(x: Node<T>, delta: NodeInput<'u32'>): Node<T>;
|
|
68
|
+
/** `x` of the lane whose number is this one's xor `mask`. Keep it within the subgroup. */
|
|
69
|
+
shuffleXor<T extends SubgroupValue>(x: Node<T>, mask: NodeInput<'u32'>): Node<T>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The subgroup operations of `engine`'s device. Ask for them with `features: ['subgroups']` when creating the engine: a device
|
|
73
|
+
* without the feature gets the one-lane form, so the same graph runs everywhere.
|
|
74
|
+
*/
|
|
75
|
+
export declare function subgroups(engine: EngineKernel | GPUDevice): Subgroups;
|
|
76
|
+
/**
|
|
77
|
+
* Half floats of one device, from {@link halfFloats}. Maths on half floats takes half the registers and, on many GPUs, half the
|
|
78
|
+
* time. Without the `shader-f16` feature the same graph runs in f32: values keep more precision and go past 65,504 without
|
|
79
|
+
* becoming infinite, so results differ by what f16 rounds away.
|
|
80
|
+
*/
|
|
81
|
+
export interface HalfFloats {
|
|
82
|
+
/** True when the device has the `shader-f16` feature: nodes from `half` are f16. */
|
|
83
|
+
readonly supported: boolean;
|
|
84
|
+
/** `x` as a half float. Numbers take part in maths on the result as usual; nodes of f32 do not, so convert them too. */
|
|
85
|
+
half<T extends FullFloat>(x: Node<T>): Node<HalfOf<T>>;
|
|
86
|
+
/** A half float back at full precision. */
|
|
87
|
+
full<T extends HalfFloat>(x: Node<T>): Node<FullOf<T>>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The half floats of `engine`'s device. Ask for them with `features: ['shader-f16']` when creating the engine: a device without
|
|
91
|
+
* the feature gets the f32 form.
|
|
92
|
+
*/
|
|
93
|
+
export declare function halfFloats(engine: EngineKernel | GPUDevice): HalfFloats;
|
|
94
|
+
/** Two floats as the two halves of a u32, rounded to f16: half the storage on every device. */
|
|
95
|
+
export declare const packHalf2: (x: Node<'vec2f'>) => Node<'u32'>;
|
|
96
|
+
/** The two floats of a {@link packHalf2}. */
|
|
97
|
+
export declare const unpackHalf2: (x: Node<'u32'>) => Node<'vec2f'>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const s=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { Ht as e, T as t, b as n, k as r, o as i, tn as a } from "./node-DzKv9CF2.js";
|
|
5
|
+
import { f as o } from "./compute-D-BghbXj.js";
|
|
6
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
7
|
+
//#region src/subgroups.ts
|
|
8
|
+
var c = (e, t, n) => {
|
|
9
|
+
if (e.stage.kind !== "compute") throw TypeError(`${t} is only available in ComputePass nodes; move it into a ComputePass`);
|
|
10
|
+
e.declare(n, `enable ${n};`);
|
|
11
|
+
}, l = (e, t) => !!("queue" in e ? e : s(e).gpu)?.features.has(t);
|
|
12
|
+
function u(e, t, n) {
|
|
13
|
+
return new i(t, "sg" + a(), n, (t, n) => {
|
|
14
|
+
c(t, e, "subgroups"), o(t.program);
|
|
15
|
+
let r = n.args.map((e) => t.expr(e)), i = t.name();
|
|
16
|
+
return t.line(`let ${i} = ${e}(${r.join(", ")});`), i;
|
|
17
|
+
}, 28);
|
|
18
|
+
}
|
|
19
|
+
var d = (e, t) => {
|
|
20
|
+
let r = n(t, "u32");
|
|
21
|
+
return new i("u32", "sg:" + t, [r], (t, n) => (c(t, e, "subgroups"), t.expr(n.args[0])));
|
|
22
|
+
}, f = (e) => (t) => u(e, t.type, [t]), p = (e) => (n, r) => u(e, n.type, [n, t(r, "u32")]), m = (e) => e;
|
|
23
|
+
function h(e) {
|
|
24
|
+
return l(e, "subgroups") ? {
|
|
25
|
+
supported: !0,
|
|
26
|
+
size: d("subgroups.size", "subgroupSize"),
|
|
27
|
+
id: d("subgroups.id", "subgroupId"),
|
|
28
|
+
add: f("subgroupAdd"),
|
|
29
|
+
mul: f("subgroupMul"),
|
|
30
|
+
min: f("subgroupMin"),
|
|
31
|
+
max: f("subgroupMax"),
|
|
32
|
+
and: f("subgroupAnd"),
|
|
33
|
+
or: f("subgroupOr"),
|
|
34
|
+
xor: f("subgroupXor"),
|
|
35
|
+
inclusiveAdd: f("subgroupInclusiveAdd"),
|
|
36
|
+
exclusiveAdd: f("subgroupExclusiveAdd"),
|
|
37
|
+
inclusiveMul: f("subgroupInclusiveMul"),
|
|
38
|
+
exclusiveMul: f("subgroupExclusiveMul"),
|
|
39
|
+
all: f("subgroupAll"),
|
|
40
|
+
any: f("subgroupAny"),
|
|
41
|
+
ballot: (e) => u("subgroupBallot", "vec4u", [e]),
|
|
42
|
+
elect: () => u("subgroupElect", "bool", []),
|
|
43
|
+
broadcast: (e, t) => u("subgroupBroadcast", e.type, [e, r(t, "u32")]),
|
|
44
|
+
broadcastFirst: f("subgroupBroadcastFirst"),
|
|
45
|
+
shuffle: p("subgroupShuffle"),
|
|
46
|
+
shuffleUp: p("subgroupShuffleUp"),
|
|
47
|
+
shuffleDown: p("subgroupShuffleDown"),
|
|
48
|
+
shuffleXor: p("subgroupShuffleXor")
|
|
49
|
+
} : {
|
|
50
|
+
supported: !1,
|
|
51
|
+
size: r(1, "u32"),
|
|
52
|
+
id: r(0, "u32"),
|
|
53
|
+
add: m,
|
|
54
|
+
mul: m,
|
|
55
|
+
min: m,
|
|
56
|
+
max: m,
|
|
57
|
+
and: m,
|
|
58
|
+
or: m,
|
|
59
|
+
xor: m,
|
|
60
|
+
inclusiveAdd: m,
|
|
61
|
+
exclusiveAdd: (e) => r(0, e.type),
|
|
62
|
+
inclusiveMul: m,
|
|
63
|
+
exclusiveMul: (e) => r(1, e.type),
|
|
64
|
+
all: m,
|
|
65
|
+
any: m,
|
|
66
|
+
ballot: (e) => new i("vec4u", "ballot", [e], (e, t) => `vec4u(select(0u, 1u, ${e.expr(t.args[0])}), 0u, 0u, 0u)`),
|
|
67
|
+
elect: () => r(!0, "bool"),
|
|
68
|
+
broadcast: m,
|
|
69
|
+
broadcastFirst: m,
|
|
70
|
+
shuffle: m,
|
|
71
|
+
shuffleUp: m,
|
|
72
|
+
shuffleDown: m,
|
|
73
|
+
shuffleXor: m
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function g(t) {
|
|
77
|
+
return l(t, "shader-f16") ? {
|
|
78
|
+
supported: !0,
|
|
79
|
+
half: (t) => {
|
|
80
|
+
let n = e(t.type) === 1 ? "f16" : t.type.replace("f", "h");
|
|
81
|
+
return new i(n, "half", [t], (e, t) => (c(e, "half", "f16"), `${n}(${e.expr(t.args[0])})`));
|
|
82
|
+
},
|
|
83
|
+
full: (t) => {
|
|
84
|
+
let n = e(t.type) === 1 ? "f32" : t.type.replace("h", "f");
|
|
85
|
+
return new i(n, "full", [t], (e, t) => `${n}(${e.expr(t.args[0])})`);
|
|
86
|
+
}
|
|
87
|
+
} : {
|
|
88
|
+
supported: !1,
|
|
89
|
+
half: (e) => e,
|
|
90
|
+
full: (e) => e
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
var _ = (e) => new i("u32", "packHalf2", [e], (e, t) => `pack2x16float(${e.expr(t.args[0])})`), v = (e) => new i("vec2f", "unpackHalf2", [e], (e, t) => `unpack2x16float(${e.expr(t.args[0])})`);
|
|
94
|
+
//#endregion
|
|
95
|
+
export { g as halfFloats, _ as packHalf2, h as subgroups, v as unpackHalf2 };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { T as e, nn as t, o as n, tn as r } from "./node-DzKv9CF2.js";
|
|
2
|
+
//#region ../shared/white-texture.js
|
|
3
|
+
var i = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function a(e, t = "2d") {
|
|
5
|
+
let n = i.get(e);
|
|
6
|
+
n || i.set(e, n = /* @__PURE__ */ new Map());
|
|
7
|
+
let r = n.get(t);
|
|
8
|
+
if (!r) {
|
|
9
|
+
let i = t === "cube" ? 6 : 1, a = e.createTexture({
|
|
10
|
+
size: [
|
|
11
|
+
1,
|
|
12
|
+
1,
|
|
13
|
+
i
|
|
14
|
+
],
|
|
15
|
+
dimension: t === "3d" ? "3d" : "2d",
|
|
16
|
+
format: "rgba8unorm",
|
|
17
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
|
|
18
|
+
});
|
|
19
|
+
e.queue.writeTexture({ texture: a }, new Uint8Array(4 * i).fill(255), {
|
|
20
|
+
bytesPerRow: 4,
|
|
21
|
+
rowsPerImage: 1
|
|
22
|
+
}, [
|
|
23
|
+
1,
|
|
24
|
+
1,
|
|
25
|
+
i
|
|
26
|
+
]), n.set(t, r = [a.createView({ dimension: t }), e.createSampler()]);
|
|
27
|
+
}
|
|
28
|
+
return r;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/texture.ts
|
|
32
|
+
var o = /* @__PURE__ */ new WeakMap();
|
|
33
|
+
function s(n, r = t(), i) {
|
|
34
|
+
return u("texture", "2d", n, e(r, "vec2f", "texture uv"), i);
|
|
35
|
+
}
|
|
36
|
+
function c(t, n, r) {
|
|
37
|
+
return u("textureCube", "cube", t, e(n, "vec3f", "textureCube direction"), r);
|
|
38
|
+
}
|
|
39
|
+
function l(t, n, r) {
|
|
40
|
+
return u("texture3D", "3d", t, e(n, "vec3f", "texture3D coordinate"), r);
|
|
41
|
+
}
|
|
42
|
+
function u(t, i, s, c, l, u) {
|
|
43
|
+
if (typeof s?.bind != "function") throw TypeError(`${t}() needs a Texture from @margoengine/materials`);
|
|
44
|
+
let d = s.dimension ?? "2d";
|
|
45
|
+
if (d !== i) throw TypeError(`${t}() needs a Texture of dimension ${i}, not ${d}`);
|
|
46
|
+
let f = o.get(s);
|
|
47
|
+
f || (f = {
|
|
48
|
+
id: r(),
|
|
49
|
+
source: s,
|
|
50
|
+
prefix: "ndt",
|
|
51
|
+
bindings: 2,
|
|
52
|
+
declare: (e, t, n) => `@group(${t}) @binding(${n}) var ${e}:texture_${i.replace("-", "_")}<f32>;\n@group(${t}) @binding(${n + 1}) var ${e}s:sampler;`,
|
|
53
|
+
entries: (e) => s.bind(e, !0) ?? a(e, i)
|
|
54
|
+
}, o.set(s, f));
|
|
55
|
+
let p = f, m = [c];
|
|
56
|
+
return u && m.push(u), l !== void 0 && m.push(e(l, "f32", "texture level")), new n("vec4f", "t" + f.id, m, (e, t) => {
|
|
57
|
+
let n = e.resource(p), r = e.expr(t.args[0]) + (u ? `, ${e.expr(t.args[1])}` : ""), i = t.args[u ? 2 : 1] ? e.expr(t.args[u ? 2 : 1]) : void 0;
|
|
58
|
+
return i === void 0 && (e.stage.kind === "fragment" || e.stage.kind === "post") ? `textureSample(${n}, ${n}s, ${r})` : `textureSampleLevel(${n}, ${n}s, ${r}, ${i ?? "0.0"})`;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { c as i, s as n, l as r, u as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Node, type NodeInput } from './node.js';
|
|
2
|
+
import { type BindableTexture } from './texture.js';
|
|
3
|
+
/** Samples an integer layer of a 2d-array texture, sharing one texture/sampler pair across all layer nodes.
|
|
4
|
+
* UV defaults to uv(); fragment/post sampling uses implicit derivatives unless level is supplied.
|
|
5
|
+
* Vertex/compute sampling defaults to level zero. Layer selection clamps to the available range in the shader API.
|
|
6
|
+
*/
|
|
7
|
+
export declare function textureArray(source: BindableTexture, layer: NodeInput<'i32' | 'u32'>, coord?: NodeInput<'vec2f'>, level?: NodeInput<'f32'>): Node<'vec4f'>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { T as e, X as t, nn as n, o as r } from "./node-DzKv9CF2.js";
|
|
2
|
+
import { t as i } from "./texture-D6vy0bam.js";
|
|
3
|
+
//#region src/texture-array.ts
|
|
4
|
+
function a(a, o, s = n(), c) {
|
|
5
|
+
if (o instanceof r) {
|
|
6
|
+
if (o.type !== "i32" && o.type !== "u32") throw TypeError("Use an i32 or u32 texture array layer");
|
|
7
|
+
} else if (!Number.isInteger(o) || o < -2147483648 || o > 2147483647) throw RangeError("Use an integer texture array layer within the i32 range");
|
|
8
|
+
return i("textureArray", "2d-array", a, e(s, "vec2f", "texture array UV"), c, o instanceof r ? o : t(o));
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { a as textureArray };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Node, type NodeInput } from './node.js';
|
|
2
|
+
/** Anything with `@margoengine/materials` Texture's `bind`; `srgb` is the default colour space (a texture's own `colorSpace` wins). */
|
|
3
|
+
export interface BindableTexture {
|
|
4
|
+
bind(device: GPUDevice, srgb: boolean): [GPUTextureView, GPUSampler] | undefined;
|
|
5
|
+
}
|
|
6
|
+
type Dimension = '2d' | 'cube' | '3d' | '2d-array';
|
|
7
|
+
/** Samples a texture (sRGB by default; `new Texture(source, {colorSpace: 'linear'})` for data). Vertex and compute stages, or an explicit
|
|
8
|
+
* `level`, use textureSampleLevel. */
|
|
9
|
+
export declare function texture(source: BindableTexture, coord?: NodeInput<'vec2f'>, level?: NodeInput<'f32'>): Node<'vec4f'>;
|
|
10
|
+
/** Samples a cube texture (`CubeTexture` from `@margoengine/materials`) towards `direction`; `level` as in {@link texture}. */
|
|
11
|
+
export declare function textureCube(source: BindableTexture, direction: NodeInput<'vec3f'>, level?: NodeInput<'f32'>): Node<'vec4f'>;
|
|
12
|
+
/** Samples a 3D texture (`dimension: '3d'`) at `coord`, each axis 0-1; `level` as in {@link texture}. */
|
|
13
|
+
export declare function texture3D(source: BindableTexture, coord: NodeInput<'vec3f'>, level?: NodeInput<'f32'>): Node<'vec4f'>;
|
|
14
|
+
/** @internal Shared sampled resource, including the optional array-layer argument. */
|
|
15
|
+
export declare function sampled(name: string, dimension: Dimension, source: BindableTexture, coord: Node, level: NodeInput<'f32'> | undefined, layer?: Node<'i32' | 'u32'>): Node<'vec4f'>;
|
|
16
|
+
export {};
|