@margoengine/creative 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 +307 -3
- package/dist/display-C6RC-F2-.js +3 -0
- package/dist/errors-XvcwUnU4.js +7 -0
- package/dist/gpu-DN8sGUpu.js +30 -0
- package/dist/grass-StuKCE_k.js +450 -0
- package/dist/grass-settings.d.ts +63 -0
- package/dist/grass-settings.js +131 -0
- package/dist/grass-terrain.d.ts +33 -0
- package/dist/grass-terrain.js +185 -0
- package/dist/grass.d.ts +106 -0
- package/dist/grass.js +1 -0
- package/dist/hdr-format-DXpjc3bW.js +4 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/msaa-DjFZ9hVW.js +213 -0
- package/dist/paint-aniso.d.ts +36 -0
- package/dist/paint-aniso.js +215 -0
- package/dist/paint.d.ts +56 -0
- package/dist/paint.js +148 -0
- package/dist/particles.d.ts +38 -0
- package/dist/particles.js +79 -0
- package/dist/pass-B5mPip-t.js +27 -0
- package/dist/planet-C2ewqAmf.js +505 -0
- package/dist/planet-atmosphere.d.ts +37 -0
- package/dist/planet-atmosphere.js +196 -0
- package/dist/planet-pass.d.ts +47 -0
- package/dist/planet.d.ts +76 -0
- package/dist/planet.js +1 -0
- package/dist/post.d.ts +108 -0
- package/dist/post.js +265 -0
- package/dist/quality-DFm-cQWC.js +7 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/stars-DWF7qnc1.js +90 -0
- package/dist/stars.d.ts +34 -0
- package/dist/stars.js +1 -0
- package/dist/targets-depth.d.ts +35 -0
- package/dist/targets-depth.js +169 -0
- package/dist/targets.d.ts +35 -0
- package/dist/targets.js +42 -0
- package/dist/texture-target-CGqE9pOa.js +131 -0
- package/dist/texture-target.d.ts +49 -0
- package/dist/toon.d.ts +32 -0
- package/dist/toon.js +58 -0
- package/dist/view-rect-TO68f_UR.js +48 -0
- package/package.json +126 -6
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const n=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { r as e, t } from "./errors-XvcwUnU4.js";
|
|
5
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
6
|
+
import { Geometry as r } from "@margoengine/core";
|
|
7
|
+
//#region ../shared/scene-scope.js
|
|
8
|
+
var i = 0, a = (e, t) => {
|
|
9
|
+
let n = t + i++;
|
|
10
|
+
for (; e.plugins?.has(n);) n += ":";
|
|
11
|
+
return n;
|
|
12
|
+
};
|
|
13
|
+
function o(e) {
|
|
14
|
+
let t;
|
|
15
|
+
if (typeof e?.sceneOf == "function") {
|
|
16
|
+
for (let n of e.plugins?.values() ?? []) if (t = e.sceneOf(n)) break;
|
|
17
|
+
if (!t) {
|
|
18
|
+
let n = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
|
|
19
|
+
name: a(e, "scene-scope:"),
|
|
20
|
+
setup() {
|
|
21
|
+
t = e.sceneOf(n);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
e.use(n), e.removePlugin(n.name);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return s(e, t);
|
|
28
|
+
}
|
|
29
|
+
function s(e, t) {
|
|
30
|
+
return {
|
|
31
|
+
scene: t,
|
|
32
|
+
run(n) {
|
|
33
|
+
if (!t) return n();
|
|
34
|
+
let r, i = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
|
|
35
|
+
name: a(e, "scene-scope:"),
|
|
36
|
+
setup() {
|
|
37
|
+
r = n();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return t.use(i), t.removePlugin(i.name), r;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/grass-terrain.ts
|
|
46
|
+
function c(t) {
|
|
47
|
+
let n = t.colorMap ?? {
|
|
48
|
+
width: 1,
|
|
49
|
+
height: 1,
|
|
50
|
+
data: new Float32Array([
|
|
51
|
+
1,
|
|
52
|
+
1,
|
|
53
|
+
1,
|
|
54
|
+
1
|
|
55
|
+
])
|
|
56
|
+
}, { width: r, height: i, data: a } = n, o = t.area ?? [50, 50], s = t.center ?? [
|
|
57
|
+
0,
|
|
58
|
+
0,
|
|
59
|
+
0
|
|
60
|
+
], c = n.bounds ?? t.bounds ?? [
|
|
61
|
+
s[0] - o[0] / 2,
|
|
62
|
+
s[2] - o[1] / 2,
|
|
63
|
+
s[0] + o[0] / 2,
|
|
64
|
+
s[2] + o[1] / 2
|
|
65
|
+
];
|
|
66
|
+
if (!Number.isInteger(r) || !Number.isInteger(i) || r < 1 || i < 1 || r > 4096 || i > 4096 || r * i > 1048576 || !(a instanceof Float32Array) || a.length !== r * i * 4 || a.some((e) => !Number.isFinite(e) || e < 0 || e > 1) || c.length !== 4 || c.some((e) => !Number.isFinite(Math.fround(e))) || ![0, 1].every((e) => Number.isFinite(Math.fround(c[e + 2] - c[e])) && Math.fround(c[e + 2]) > Math.fround(c[e]) && Math.fround(c[e + 2] - c[e]) >= 2 ** -126)) throw e("Grass colour map needs finite RGBA in 0..1, matching dimensions and ascending bounds; use at most 1048576 pixels", "arguments");
|
|
67
|
+
let l = new Float32Array(8 + a.length);
|
|
68
|
+
return l.set(c), l.set([r, i], 4), l.set(a, 8), l;
|
|
69
|
+
}
|
|
70
|
+
var l = (e, t) => `
|
|
71
|
+
@group(${e}) @binding(${t}) var<storage,read> grassMap:array<vec4f>;
|
|
72
|
+
fn grassTexel(p:vec2i)->vec3f {
|
|
73
|
+
let size=vec2i(grassMap[1].xy);let c=clamp(p,vec2i(0),size-1);
|
|
74
|
+
return grassMap[2+c.y*size.x+c.x].rgb;
|
|
75
|
+
}
|
|
76
|
+
fn grassTint(root:vec3f)->vec3f {
|
|
77
|
+
let texel=clamp((root.xz-grassMap[0].xy)/(grassMap[0].zw-grassMap[0].xy),vec2f(0),vec2f(1))*grassMap[1].xy-0.5;
|
|
78
|
+
let c=vec2i(floor(texel));let f=fract(texel);
|
|
79
|
+
return mix(mix(grassTexel(c),grassTexel(c+vec2i(1,0)),f.x),mix(grassTexel(c+vec2i(0,1)),grassTexel(c+vec2i(1,1)),f.x),f.y);
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
async function u(i, a = {}) {
|
|
83
|
+
a.signal?.throwIfAborted();
|
|
84
|
+
let s = o(i), u = c(a), { TrampledScatter: d } = await import("@margoengine/scatter/interact");
|
|
85
|
+
a.signal?.throwIfAborted();
|
|
86
|
+
let f = a.geometry ?? new r([
|
|
87
|
+
-.04,
|
|
88
|
+
0,
|
|
89
|
+
0,
|
|
90
|
+
.04,
|
|
91
|
+
0,
|
|
92
|
+
0,
|
|
93
|
+
-.027,
|
|
94
|
+
1 / 3,
|
|
95
|
+
0,
|
|
96
|
+
.027,
|
|
97
|
+
1 / 3,
|
|
98
|
+
0,
|
|
99
|
+
-.014,
|
|
100
|
+
2 / 3,
|
|
101
|
+
0,
|
|
102
|
+
.014,
|
|
103
|
+
2 / 3,
|
|
104
|
+
0,
|
|
105
|
+
0,
|
|
106
|
+
1,
|
|
107
|
+
0
|
|
108
|
+
], [
|
|
109
|
+
0,
|
|
110
|
+
0,
|
|
111
|
+
1,
|
|
112
|
+
0,
|
|
113
|
+
0,
|
|
114
|
+
1,
|
|
115
|
+
0,
|
|
116
|
+
0,
|
|
117
|
+
1,
|
|
118
|
+
0,
|
|
119
|
+
0,
|
|
120
|
+
1,
|
|
121
|
+
0,
|
|
122
|
+
0,
|
|
123
|
+
1,
|
|
124
|
+
0,
|
|
125
|
+
0,
|
|
126
|
+
1,
|
|
127
|
+
0,
|
|
128
|
+
0,
|
|
129
|
+
1
|
|
130
|
+
], [
|
|
131
|
+
0,
|
|
132
|
+
1,
|
|
133
|
+
2,
|
|
134
|
+
1,
|
|
135
|
+
3,
|
|
136
|
+
2,
|
|
137
|
+
2,
|
|
138
|
+
3,
|
|
139
|
+
4,
|
|
140
|
+
3,
|
|
141
|
+
5,
|
|
142
|
+
4,
|
|
143
|
+
4,
|
|
144
|
+
5,
|
|
145
|
+
6
|
|
146
|
+
]);
|
|
147
|
+
class p extends d {
|
|
148
|
+
#e;
|
|
149
|
+
poseEntries() {
|
|
150
|
+
let e = super.poseEntries();
|
|
151
|
+
if (!this.#e) {
|
|
152
|
+
let e = this.engine.gpu;
|
|
153
|
+
this.#e = e.createBuffer({
|
|
154
|
+
size: u.byteLength,
|
|
155
|
+
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
|
|
156
|
+
}), e.queue.writeBuffer(this.#e, 0, u);
|
|
157
|
+
}
|
|
158
|
+
return [...e, { buffer: this.#e }];
|
|
159
|
+
}
|
|
160
|
+
poseCode(e, n, r) {
|
|
161
|
+
let i = super.poseCode(e, n, r), a = r + super.poseEntries().length;
|
|
162
|
+
if (!i.includes("shade:f32}") || !i.includes("return ScatterPose(")) throw t("state", "Terrain grass needs the scatter pose contract; rebuild compatible creative and scatter packages");
|
|
163
|
+
let o = l(n, a) + i.replace("shade:f32}", "shade:f32,tint:vec3f}").replace(/return ScatterPose\(([^;]+)\);/, "return ScatterPose($1,grassTint(position.xyz));");
|
|
164
|
+
return o.includes("var color=frame.color.rgb*i.shade") && (o = o.replace(/struct Output \{([^}]+)\}/, "struct Output {$1,@location(4) tint:vec3f}").replace(/return Output\(([^;]+)\);/, "return Output($1,pose.tint);").replace("frame.color.rgb*i.shade", "frame.color.rgb*i.shade*i.tint")), o;
|
|
165
|
+
}
|
|
166
|
+
release() {
|
|
167
|
+
this.#e?.destroy(), this.#e = void 0, super.release();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let { geometry: m, colorMap: h, interaction: g, signal: _, ...v } = a;
|
|
171
|
+
if ("material" in a) throw e("Terrain grass takes colour and colour maps; use the scatter material entries for custom materials", "arguments");
|
|
172
|
+
let y = new p(f, {
|
|
173
|
+
wind: [
|
|
174
|
+
1,
|
|
175
|
+
.35,
|
|
176
|
+
.45
|
|
177
|
+
],
|
|
178
|
+
maxSlope: 90,
|
|
179
|
+
blades: {},
|
|
180
|
+
...v
|
|
181
|
+
}, g);
|
|
182
|
+
return _?.throwIfAborted(), s.run(() => n(i).use(y)), y;
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
export { u as createTerrainGrass };
|
package/dist/grass.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
|
|
4
|
+
/** Grass field settings, fixed at construction except the wind ones and the live setters of `GrassField` (see `@margoengine/creative/grass-settings`); invalid values throw RangeError. */
|
|
5
|
+
export interface GrassOptions {
|
|
6
|
+
/** Blade count, an integer 1-16,777,216 (bounded by device limits). Default 100,000. */
|
|
7
|
+
blades?: number;
|
|
8
|
+
/** X/Z extent centred on the origin at Y = 0, world units, each 0-100,000 (exclusive of 0). Default [50, 50]. */
|
|
9
|
+
area?: readonly [number, number];
|
|
10
|
+
/** Blade height in world units, 0-100 (exclusive of 0); instances vary 0.7x-1.25x. Default 1.2. */
|
|
11
|
+
bladeHeight?: number;
|
|
12
|
+
/** Noise scroll and spore drift speed, 0-100; also `field.windSpeed`. Default 1.2. */
|
|
13
|
+
windSpeed?: number;
|
|
14
|
+
/** Bend strength, 0-2; also `field.windStrength`. Default 0.45. */
|
|
15
|
+
windStrength?: number;
|
|
16
|
+
/** X/Z wind direction (nonzero, normalised). Default [1, 0.35]. */
|
|
17
|
+
windDirection?: readonly [number, number];
|
|
18
|
+
/** Distance from the camera beyond which blades are culled, world units, 0-100,000 (exclusive of 0). Default 100. */
|
|
19
|
+
drawDistance?: number;
|
|
20
|
+
/** Also draw 240 drifting dandelion spores. Default false. */
|
|
21
|
+
spores?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* GPU grass: blades culled against the camera frustum and distance by a compute pass every frame, drawn with
|
|
25
|
+
* indirect near (7-vertex) and far (3-vertex) blades, bent by scrolling wind noise. `GrassField.attach(engine,
|
|
26
|
+
* options)`; WebGPU only. Not a core mesh (no picking, clipping or shadows).
|
|
27
|
+
* @throws RangeError when an option is out of range or the blades exceed GPU limits.
|
|
28
|
+
* @throws MargoError `'unsupported'` on a WebGL engine or an unsupported target format, `'attached'` when attached twice.
|
|
29
|
+
*/
|
|
30
|
+
export declare class GrassField implements EnginePlugin {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly blades: number;
|
|
33
|
+
private engine?;
|
|
34
|
+
private device?;
|
|
35
|
+
private instances?;
|
|
36
|
+
private visible?;
|
|
37
|
+
private indirect?;
|
|
38
|
+
private vertices?;
|
|
39
|
+
private uniform?;
|
|
40
|
+
private compute?;
|
|
41
|
+
private computeGroup?;
|
|
42
|
+
private module?;
|
|
43
|
+
private pipelineLayout?;
|
|
44
|
+
private group?;
|
|
45
|
+
private canvasFormat?;
|
|
46
|
+
private readonly variants;
|
|
47
|
+
private readonly frame;
|
|
48
|
+
private time;
|
|
49
|
+
private readonly spores;
|
|
50
|
+
private readonly pass;
|
|
51
|
+
private readonly color;
|
|
52
|
+
private readonly depth;
|
|
53
|
+
private readonly sporeDepth;
|
|
54
|
+
private readonly sporePass;
|
|
55
|
+
/** Creates the GrassField on `engine` (preferred over the constructor). */
|
|
56
|
+
static attach(engine: EngineKernel, options?: GrassOptions): GrassField;
|
|
57
|
+
constructor(stage: {
|
|
58
|
+
readonly engine: EngineKernel;
|
|
59
|
+
}, options?: GrassOptions);
|
|
60
|
+
get windSpeed(): number;
|
|
61
|
+
set windSpeed(value: number);
|
|
62
|
+
get windStrength(): number;
|
|
63
|
+
set windStrength(value: number);
|
|
64
|
+
/** X/Z wind direction as a unit vector; assign any nonzero finite pair and it is normalised. */
|
|
65
|
+
get windDirection(): readonly [number, number];
|
|
66
|
+
set windDirection(value: readonly [number, number]);
|
|
67
|
+
/** Blade height in world units, 0-100 (exclusive of 0); read every frame. */
|
|
68
|
+
get bladeHeight(): number;
|
|
69
|
+
set bladeHeight(value: number);
|
|
70
|
+
/** Cull distance in world units, 0-100,000 (exclusive of 0); read every frame. */
|
|
71
|
+
get drawDistance(): number;
|
|
72
|
+
set drawDistance(value: number);
|
|
73
|
+
/** Fraction of the blades kept, 0-1 (a hash of the blade number, so lowering it only thins the field); read every frame. */
|
|
74
|
+
get density(): number;
|
|
75
|
+
set density(value: number);
|
|
76
|
+
/** Blade colour at the root, linear RGB 0-1 (default [0.025, 0.065, 0.012]); read every frame. */
|
|
77
|
+
get rootColor(): readonly [number, number, number];
|
|
78
|
+
set rootColor(value: readonly [number, number, number]);
|
|
79
|
+
/** Blade colour at the tip, linear RGB 0-1 (default [0.25, 0.46, 0.045]); each blade mixes it toward `tipVariantColor`. */
|
|
80
|
+
get tipColor(): readonly [number, number, number];
|
|
81
|
+
set tipColor(value: readonly [number, number, number]);
|
|
82
|
+
/** The tip colour of the most varied blades, linear RGB 0-1 (default [0.38, 0.57, 0.085]). */
|
|
83
|
+
get tipVariantColor(): readonly [number, number, number];
|
|
84
|
+
set tipVariantColor(value: readonly [number, number, number]);
|
|
85
|
+
/** Colour of sunlight seen through the blades, linear RGB 0-1 (default [0.34, 0.5, 0.09]). */
|
|
86
|
+
get translucencyColor(): readonly [number, number, number];
|
|
87
|
+
set translucencyColor(value: readonly [number, number, number]);
|
|
88
|
+
/** Strength of the back-light, 0-4 (default 0.4): the glow of blades against a low sun; 0 is none. */
|
|
89
|
+
get translucency(): number;
|
|
90
|
+
set translucency(value: number);
|
|
91
|
+
private colour;
|
|
92
|
+
get windTime(): number;
|
|
93
|
+
set windTime(value: number);
|
|
94
|
+
setup(engine: Engine): void;
|
|
95
|
+
registerPasses(graph: FrameGraph): void;
|
|
96
|
+
private readonly update;
|
|
97
|
+
private readonly draw;
|
|
98
|
+
private readonly drawSpores;
|
|
99
|
+
private variant;
|
|
100
|
+
private release;
|
|
101
|
+
onDeviceRestored(engine: Engine): void;
|
|
102
|
+
/** @deprecated Use dispose(); kept as an alias until 1.0. */
|
|
103
|
+
destroy(): void;
|
|
104
|
+
dispose(): void;
|
|
105
|
+
[Symbol.dispose]: () => void;
|
|
106
|
+
}
|
package/dist/grass.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as GrassField } from "./grass-StuKCE_k.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { GPUParticles, type ParticleOptions, type WindObstacle, type ParticleTexture } from './particles.js';
|
|
2
|
+
export { HDRRenderTarget } from './targets.js';
|
|
3
|
+
export { ToonShading, type ToonOptions } from './toon.js';
|
|
4
|
+
export { PostProcessing, type PostOptions, type AtmosphereOptions } from './post.js';
|
|
5
|
+
export { GrassField, type GrassOptions } from './grass.js';
|
|
6
|
+
export { Planet, type PlanetOptions } from './planet.js';
|
|
7
|
+
export { Stars } from './stars.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GPUParticles as e } from "./particles.js";
|
|
2
|
+
import { HDRRenderTarget as t } from "./targets.js";
|
|
3
|
+
import { ToonShading as n } from "./toon.js";
|
|
4
|
+
import { PostProcessing as r } from "./post.js";
|
|
5
|
+
import { t as i } from "./grass-StuKCE_k.js";
|
|
6
|
+
import { t as a } from "./planet-C2ewqAmf.js";
|
|
7
|
+
import { t as o } from "./stars-DWF7qnc1.js";
|
|
8
|
+
export { e as GPUParticles, i as GrassField, t as HDRRenderTarget, a as Planet, r as PostProcessing, o as Stars, n as ToonShading };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { n as e, r as t } from "./view-rect-TO68f_UR.js";
|
|
2
|
+
//#region ../shared/frame-resources.js
|
|
3
|
+
var n = (globalThis[Symbol.for("margoengine.frame-resources")] ??= { devices: /* @__PURE__ */ new WeakMap() }).devices;
|
|
4
|
+
function r(e) {
|
|
5
|
+
let t = n.get(e);
|
|
6
|
+
return t || (n.set(e, t = {
|
|
7
|
+
frame: 0,
|
|
8
|
+
open: !1,
|
|
9
|
+
lost: !1,
|
|
10
|
+
views: /* @__PURE__ */ new Set(),
|
|
11
|
+
drawing: 0,
|
|
12
|
+
retired: [],
|
|
13
|
+
written: /* @__PURE__ */ new WeakMap()
|
|
14
|
+
}), e.lost?.then?.(() => {
|
|
15
|
+
t.lost = !0;
|
|
16
|
+
let e = t.retired;
|
|
17
|
+
t.retired = [];
|
|
18
|
+
for (let t of e) t.destroy();
|
|
19
|
+
})), t;
|
|
20
|
+
}
|
|
21
|
+
function i(e, t) {
|
|
22
|
+
if (!t) return;
|
|
23
|
+
let n = r(e), i = [t, ...n.written.get(t)?.extras ?? []];
|
|
24
|
+
if (n.written.delete(t), !n.lost && n.open && (n.views.size > 1 || n.drawing > 0)) n.retired.push(...i);
|
|
25
|
+
else for (let e of i) e.destroy();
|
|
26
|
+
}
|
|
27
|
+
function a(e) {
|
|
28
|
+
return e?.adapterInfo?.vendor === "margo-webgl2" ? "webgl2" : "native";
|
|
29
|
+
}
|
|
30
|
+
function o(e) {
|
|
31
|
+
return a(e) === "native" && e?.features?.has("core-features-and-limits") === !1;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../shared/msaa.js
|
|
35
|
+
var s = "@vertex fn vertex(@builtin(vertex_index) i:u32)->@builtin(position) vec4f {return vec4f(array<vec2f,3>(vec2f(-1,-1),vec2f(3,-1),vec2f(-1,3))[i],0,1);}", c = (e, t, n) => e.createBindGroup({
|
|
36
|
+
layout: t.getBindGroupLayout(0),
|
|
37
|
+
entries: [{
|
|
38
|
+
binding: 0,
|
|
39
|
+
resource: n
|
|
40
|
+
}]
|
|
41
|
+
}), l = Symbol.for("margoengine.optional.msaa"), u = s + "\n@group(0) @binding(0) var source:texture_depth_multisampled_2d;\n@fragment fn fragment(@builtin(position) p:vec4f)->@builtin(frag_depth) f32 {\n let q=vec2i(p.xy);\n return max(max(textureLoad(source,q,0),textureLoad(source,q,1)),max(textureLoad(source,q,2),textureLoad(source,q,3)));\n}";
|
|
42
|
+
function d(e, t, n, r, i, a = !1) {
|
|
43
|
+
let s = (e) => u.replace(/return max[^;]+;/, `return textureLoad(source,q,${e});`), l = (n, r) => {
|
|
44
|
+
let a = e.createShaderModule({ code: n }), o = e.createRenderPipeline({
|
|
45
|
+
layout: "auto",
|
|
46
|
+
vertex: {
|
|
47
|
+
module: a,
|
|
48
|
+
entryPoint: "vertex"
|
|
49
|
+
},
|
|
50
|
+
fragment: {
|
|
51
|
+
module: a,
|
|
52
|
+
entryPoint: "fragment",
|
|
53
|
+
targets: []
|
|
54
|
+
},
|
|
55
|
+
depthStencil: {
|
|
56
|
+
format: i,
|
|
57
|
+
depthWriteEnabled: !0,
|
|
58
|
+
depthCompare: "always"
|
|
59
|
+
},
|
|
60
|
+
multisample: r
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
pipeline: o,
|
|
64
|
+
group: c(e, o, t)
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
draws: a ? [l(s(0).replace("_multisampled", ""), { count: r })] : r === 4 ? o(e) ? [
|
|
69
|
+
0,
|
|
70
|
+
1,
|
|
71
|
+
2,
|
|
72
|
+
3
|
|
73
|
+
].map((e) => l(s(e), {
|
|
74
|
+
count: r,
|
|
75
|
+
mask: 1 << e
|
|
76
|
+
})) : [l(s("i32(sample)").replace("p:vec4f)", "p:vec4f,@builtin(sample_index) sample:u32)"), { count: r })] : [l(u, { count: r })],
|
|
77
|
+
descriptor: {
|
|
78
|
+
colorAttachments: [],
|
|
79
|
+
depthStencilAttachment: {
|
|
80
|
+
view: n,
|
|
81
|
+
depthLoadOp: "clear",
|
|
82
|
+
depthClearValue: 0,
|
|
83
|
+
depthStoreOp: "store",
|
|
84
|
+
stencilReadOnly: !0
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
var f = class {
|
|
90
|
+
constructor(e, t, n, r = 4) {
|
|
91
|
+
if (r !== 1 && r !== 4) throw RangeError("Scene samples must be 1 or 4");
|
|
92
|
+
this.samples = r, this.device = e, this.resolvedColor = t, this.resolvedDepth = n, this.textures = [], this.pipelines = /* @__PURE__ */ new Map();
|
|
93
|
+
try {
|
|
94
|
+
if (r === 1) {
|
|
95
|
+
this.color = t.createView(), this.depth = n.createView();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (let r of [t, n]) this.textures.push(e.createTexture({
|
|
99
|
+
size: [r.width, r.height],
|
|
100
|
+
format: r.format,
|
|
101
|
+
sampleCount: 4,
|
|
102
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
103
|
+
}));
|
|
104
|
+
this.color = this.textures[0].createView(), this.depth = this.textures[1].createView(), this.resolution = { colorAttachments: [{
|
|
105
|
+
view: this.color,
|
|
106
|
+
resolveTarget: t.createView(),
|
|
107
|
+
loadOp: "load",
|
|
108
|
+
storeOp: "store"
|
|
109
|
+
}] }, this.finalResolution = {
|
|
110
|
+
colorAttachments: [{
|
|
111
|
+
...this.resolution.colorAttachments[0],
|
|
112
|
+
storeOp: "discard"
|
|
113
|
+
}],
|
|
114
|
+
depthStencilAttachment: {
|
|
115
|
+
view: this.depth,
|
|
116
|
+
depthLoadOp: "load",
|
|
117
|
+
depthStoreOp: "discard",
|
|
118
|
+
stencilReadOnly: !0
|
|
119
|
+
}
|
|
120
|
+
}, this.depthSource = this.textures[1].createView({ aspect: "depth-only" }), this.resolvedDepthView = n.createView();
|
|
121
|
+
} catch (e) {
|
|
122
|
+
throw this.dispose(), e;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
begin(e) {
|
|
126
|
+
(this.viewContext ??= {}).view = e.view, Object.assign(this.original ??= {}, {
|
|
127
|
+
color: e.color,
|
|
128
|
+
depth: e.depth,
|
|
129
|
+
format: e.format,
|
|
130
|
+
descriptor: e.descriptor,
|
|
131
|
+
owner: p(e)
|
|
132
|
+
}), e.color = this.color, e.depth = this.depth, e.format = this.resolvedColor.format, this.baseDescriptor !== e.descriptor && (this.baseDescriptor = e.descriptor, this.descriptor = {
|
|
133
|
+
...e.descriptor,
|
|
134
|
+
depthStencil: {
|
|
135
|
+
...e.descriptor.depthStencil,
|
|
136
|
+
format: this.resolvedDepth.format
|
|
137
|
+
},
|
|
138
|
+
multisample: { count: this.samples }
|
|
139
|
+
}), e.descriptor = this.descriptor, e[l] = this, this.retired = !1;
|
|
140
|
+
}
|
|
141
|
+
copyDepth(t, n, r, i = this.resolvedDepth.format) {
|
|
142
|
+
let a = this.pipelines.get(r);
|
|
143
|
+
a || this.pipelines.set(r, a = /* @__PURE__ */ new Map());
|
|
144
|
+
let o = a.get(i);
|
|
145
|
+
o || (this.depthSource ??= this.resolvedDepth.createView({ aspect: "depth-only" }), a.set(i, o = d(this.device, this.depthSource, n, r, i, this.samples === 1))), o.descriptor.depthStencilAttachment.view = n, o.descriptor.depthStencilAttachment.depthLoadOp = this.viewContext?.view ? "load" : "clear";
|
|
146
|
+
let s = t.beginRenderPass(o.descriptor);
|
|
147
|
+
this.viewContext && e(s, this.viewContext);
|
|
148
|
+
let c = o.draws;
|
|
149
|
+
for (let e = 0; e < c.length; e++) s.setPipeline(c[e].pipeline), s.setBindGroup(0, c[e].group), s.draw(3);
|
|
150
|
+
s.end();
|
|
151
|
+
}
|
|
152
|
+
resolve(e, t = !1, n = !0) {
|
|
153
|
+
if (this.samples !== 1) {
|
|
154
|
+
if (n && this.copyDepth(e, this.resolvedDepthView, 1), t) {
|
|
155
|
+
let t = this.viewContext?.view ? "store" : "discard";
|
|
156
|
+
this.finalResolution.colorAttachments[0].storeOp = t, this.finalResolution.depthStencilAttachment.depthStoreOp = t, this.original && this.copyDepth(e, this.original.depth, this.original.descriptor.multisample?.count ?? 1, this.original.descriptor.depthStencil.format), this.retired = !0;
|
|
157
|
+
}
|
|
158
|
+
e.beginRenderPass(t ? this.finalResolution : this.resolution).end();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
restore(e) {
|
|
162
|
+
let t = this.original;
|
|
163
|
+
this.samples === 1 ? (Object.assign(e, {
|
|
164
|
+
color: t.color,
|
|
165
|
+
depth: t.depth,
|
|
166
|
+
format: t.format,
|
|
167
|
+
descriptor: t.descriptor
|
|
168
|
+
}), e[l] = t.owner) : (this.retired || this.copyDepth(e.encoder, t.depth, t.descriptor.multisample?.count ?? 1, t.descriptor.depthStencil.format), Object.assign(e, {
|
|
169
|
+
color: t.color,
|
|
170
|
+
depth: t.depth,
|
|
171
|
+
format: t.format,
|
|
172
|
+
descriptor: t.descriptor
|
|
173
|
+
}), e[l] = t.owner);
|
|
174
|
+
}
|
|
175
|
+
present(n) {
|
|
176
|
+
this.resolve(n.encoder, !0), this.restore(n);
|
|
177
|
+
let r = n.descriptor.multisample?.count ?? 1;
|
|
178
|
+
if (!this.presentation || this.presentationFormat !== n.format || this.presentationSamples !== r) {
|
|
179
|
+
let e = this.device.createShaderModule({ code: s + "@group(0) @binding(0) var source:texture_2d<f32>;@fragment fn fragment(@builtin(position) p:vec4f)->@location(0) vec4f{return textureLoad(source,vec2i(p.xy),0);}" });
|
|
180
|
+
this.presentation = this.device.createRenderPipeline({
|
|
181
|
+
layout: "auto",
|
|
182
|
+
vertex: {
|
|
183
|
+
module: e,
|
|
184
|
+
entryPoint: "vertex"
|
|
185
|
+
},
|
|
186
|
+
fragment: {
|
|
187
|
+
module: e,
|
|
188
|
+
entryPoint: "fragment",
|
|
189
|
+
targets: [{ format: n.format }]
|
|
190
|
+
},
|
|
191
|
+
multisample: n.descriptor.multisample
|
|
192
|
+
}), this.presentationGroup = c(this.device, this.presentation, this.resolvedColor.createView()), this.presentationFormat = n.format, this.presentationSamples = r;
|
|
193
|
+
}
|
|
194
|
+
let i = this.presentationPass ??= { colorAttachments: [{
|
|
195
|
+
view: n.color,
|
|
196
|
+
loadOp: "clear",
|
|
197
|
+
storeOp: "store"
|
|
198
|
+
}] };
|
|
199
|
+
i.colorAttachments[0].view = n.color, i.colorAttachments[0].loadOp = t(n, "clear");
|
|
200
|
+
let a = n.encoder.beginRenderPass(i);
|
|
201
|
+
a.setPipeline(this.presentation), a.setBindGroup(0, this.presentationGroup), e(a, n), a.draw(3), a.end();
|
|
202
|
+
}
|
|
203
|
+
dispose() {
|
|
204
|
+
for (let e of this.textures) i(this.device, e);
|
|
205
|
+
this.textures = [], this.pipelines.clear();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
function p(e) {
|
|
209
|
+
let t = e[l];
|
|
210
|
+
return t?.color === e.color && t.depth === e.depth ? t : void 0;
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
export { f as t };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
|
|
4
|
+
/** Live controls for structure-tensor oriented, eight-sector polynomial Kuwahara filtering. */
|
|
5
|
+
export interface AnisotropicPainterlyOptions {
|
|
6
|
+
/** Integer 1..8, default 3; the longest ellipse radius is at most twice this value. */
|
|
7
|
+
radius?: number;
|
|
8
|
+
/** Blend 0..1, default 1; zero copies input exactly and omits the tensor passes. */
|
|
9
|
+
strength?: number;
|
|
10
|
+
/** Orientation adaptation 0..1, default 1; zero uses circular sectors. */
|
|
11
|
+
anisotropy?: number;
|
|
12
|
+
/** Variance preference exponent 1..8, default 8. */
|
|
13
|
+
sharpness?: number;
|
|
14
|
+
/** Default true; false copies input exactly. */
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** LDR PostStack effect with a smoothed RGB structure tensor and overlapping elliptical sectors. */
|
|
18
|
+
export declare class AnisotropicPainterly implements EnginePlugin {
|
|
19
|
+
#private;
|
|
20
|
+
readonly options: AnisotropicPainterlyOptions;
|
|
21
|
+
readonly name = "anisotropic-painterly";
|
|
22
|
+
constructor(options?: AnisotropicPainterlyOptions);
|
|
23
|
+
/** Adds a new effect to the scene's PostStack after its last LDR effect, or to a new PostStack when the scene has
|
|
24
|
+
* none. Disposing the effect takes it out, and a stack made for it goes with it. */
|
|
25
|
+
static attach(engine: EngineKernel, options?: AnisotropicPainterlyOptions): AnisotropicPainterly;
|
|
26
|
+
/** False copies the input exactly. */
|
|
27
|
+
get enabled(): boolean;
|
|
28
|
+
set enabled(value: boolean);
|
|
29
|
+
private joinStack;
|
|
30
|
+
setup(engine: Engine): void;
|
|
31
|
+
onPreUpdate(delta: number): void;
|
|
32
|
+
onDeviceRestored(engine: Engine): void;
|
|
33
|
+
/** Terminal, idempotent teardown; releases the stack owned by attach. */
|
|
34
|
+
dispose(): void;
|
|
35
|
+
[Symbol.dispose](): void;
|
|
36
|
+
}
|