@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
package/dist/shared/caster.d.ts
CHANGED
|
@@ -1,152 +1,159 @@
|
|
|
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(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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` (default 0); its vertex stage writes `o.clip=<camera>*...` (default `f.camera`). */
|
|
115
|
+
export function clippedDepth(
|
|
116
|
+
code: string,
|
|
117
|
+
binding: number,
|
|
118
|
+
name: string,
|
|
119
|
+
hardware?: boolean,
|
|
120
|
+
group?: number,
|
|
121
|
+
camera?: string,
|
|
122
|
+
): string;
|
|
123
|
+
/** A cleared depth-only pass descriptor; set `depthStencilAttachment.view` before each use. */
|
|
124
|
+
export function depthPassDescriptor(): GPURenderPassDescriptor & {
|
|
125
|
+
depthStencilAttachment: GPURenderPassDepthStencilAttachment;
|
|
126
|
+
};
|
|
127
|
+
/** Writes one caster's uniform (view, node matrix, alpha, cutoff at least `floor`, uv set, alpha transform), uploads it and draws. */
|
|
128
|
+
export function drawCaster(
|
|
129
|
+
pass: GPURenderPassEncoder,
|
|
130
|
+
device: GPUDevice,
|
|
131
|
+
pipeline: GPURenderPipeline,
|
|
132
|
+
group: GPUBindGroup,
|
|
133
|
+
uniform: GPUBuffer,
|
|
134
|
+
values: Float32Array<ArrayBuffer>,
|
|
135
|
+
view: ArrayLike<number>,
|
|
136
|
+
p: {
|
|
137
|
+
node: { matrix: ArrayLike<number> };
|
|
138
|
+
alpha?: number;
|
|
139
|
+
cutoff?: number;
|
|
140
|
+
texCoord?: number;
|
|
141
|
+
vertex: GPUBuffer;
|
|
142
|
+
/** Byte offset of the caster's vertices in `vertex`. Default 0. */
|
|
143
|
+
vertexOffset?: number;
|
|
144
|
+
index: GPUBuffer;
|
|
145
|
+
count: number;
|
|
146
|
+
},
|
|
147
|
+
transform: ArrayLike<number> | undefined | null,
|
|
148
|
+
displaced: GPUBindGroup | undefined,
|
|
149
|
+
instances: { upload(device: GPUDevice): GPUBuffer; count: number } | undefined | null,
|
|
150
|
+
/** Lowest cutoff written: the larger of this and `p.cutoff`. Default 0. */
|
|
151
|
+
floor?: number,
|
|
152
|
+
): void;
|
|
153
|
+
/** Whether a caster's cached draw `record` no longer fits primitive `p` drawn with `pipeline` and `displacement`. */
|
|
154
|
+
export function staleCaster<R extends object>(
|
|
155
|
+
record: R | undefined,
|
|
156
|
+
p: { vertex: GPUBuffer; alphaTexture?: unknown; alphaSampler?: unknown; opacity?: unknown; animation?: unknown },
|
|
157
|
+
pipeline: GPURenderPipeline,
|
|
158
|
+
displacement: unknown,
|
|
159
|
+
): record is undefined;
|
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/fractal.d.ts
CHANGED
|
@@ -1,9 +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];
|
|
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];
|
package/dist/shared/msaa.d.ts
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
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
|
-
/**
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
/** Copies a pass's private depth back into the scene attachment it replaced. */
|
|
21
|
+
export class DepthCopy {
|
|
22
|
+
constructor(device: GPUDevice, depth: GPUTexture, samples: number);
|
|
23
|
+
copy(context: Context, view: GPUTextureView, count: number, format: GPUTextureFormat): void;
|
|
24
|
+
}
|
|
25
|
+
/** `[null]` where a fragment shader can read `@builtin(sample_index)`, else each sample index (compatibility level). */
|
|
26
|
+
export function perSample(device: GPUDevice, count: number): (number | null)[];
|
|
27
|
+
export function sceneTarget(context: Context): SceneTarget | undefined;
|
|
28
|
+
export function resolveMSAA(context: Context): void;
|
|
29
|
+
|
|
30
|
+
export function sceneSamples(): number;
|
package/dist/shared/stack.d.ts
CHANGED
|
@@ -1,22 +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
|
-
}
|
|
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
|
+
}
|
package/dist/subgroups.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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 s=(engine,version="
|
|
4
|
-
import { Ht as e, T as t, b as n, k as r, o as i, tn as a } from "./node-
|
|
5
|
-
import { f as o } from "./compute-
|
|
3
|
+
const s=(engine,version="1.0.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-B6yoIC9V.js";
|
|
5
|
+
import { f as o } from "./compute-CXGG9qvI.js";
|
|
6
6
|
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
7
7
|
//#region src/subgroups.ts
|
|
8
8
|
var c = (e, t, n) => {
|
package/dist/texture-array.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as e, X as t, nn as n, o as r } from "./node-
|
|
2
|
-
import { t as i } from "./texture-
|
|
1
|
+
import { T as e, X as t, nn as n, o as r } from "./node-B6yoIC9V.js";
|
|
2
|
+
import { t as i } from "./texture-BawKO_h9.js";
|
|
3
3
|
//#region src/texture-array.ts
|
|
4
4
|
function a(a, o, s = n(), c) {
|
|
5
5
|
if (o instanceof r) {
|