@margoengine/creative 0.0.0-stage → 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.
Files changed (47) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +310 -2
  4. package/dist/display-C6RC-F2-.js +3 -0
  5. package/dist/errors-XvcwUnU4.js +7 -0
  6. package/dist/gpu-DaSofAeP.js +30 -0
  7. package/dist/grass-OkjgCaF7.js +450 -0
  8. package/dist/grass-settings.d.ts +63 -0
  9. package/dist/grass-settings.js +131 -0
  10. package/dist/grass-terrain.d.ts +33 -0
  11. package/dist/grass-terrain.js +185 -0
  12. package/dist/grass.d.ts +106 -0
  13. package/dist/grass.js +1 -0
  14. package/dist/hdr-format-DXpjc3bW.js +4 -0
  15. package/dist/index.d.ts +7 -0
  16. package/dist/index.js +8 -0
  17. package/dist/msaa-8hWFieoE.js +220 -0
  18. package/dist/paint-aniso.d.ts +36 -0
  19. package/dist/paint-aniso.js +217 -0
  20. package/dist/paint.d.ts +56 -0
  21. package/dist/paint.js +167 -0
  22. package/dist/particles.d.ts +38 -0
  23. package/dist/particles.js +79 -0
  24. package/dist/pass-B5mPip-t.js +27 -0
  25. package/dist/planet-BYTix5S1.js +505 -0
  26. package/dist/planet-atmosphere.d.ts +37 -0
  27. package/dist/planet-atmosphere.js +196 -0
  28. package/dist/planet-pass.d.ts +47 -0
  29. package/dist/planet.d.ts +76 -0
  30. package/dist/planet.js +1 -0
  31. package/dist/post.d.ts +108 -0
  32. package/dist/post.js +265 -0
  33. package/dist/quality-DFm-cQWC.js +7 -0
  34. package/dist/shared/settings.d.ts +89 -0
  35. package/dist/stars-C0SH8-aJ.js +90 -0
  36. package/dist/stars.d.ts +34 -0
  37. package/dist/stars.js +1 -0
  38. package/dist/targets-depth.d.ts +35 -0
  39. package/dist/targets-depth.js +169 -0
  40. package/dist/targets.d.ts +35 -0
  41. package/dist/targets.js +42 -0
  42. package/dist/texture-target-CGqE9pOa.js +131 -0
  43. package/dist/texture-target.d.ts +49 -0
  44. package/dist/toon.d.ts +32 -0
  45. package/dist/toon.js +58 -0
  46. package/dist/view-rect-TO68f_UR.js +48 -0
  47. package/package.json +124 -4
@@ -0,0 +1,196 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ import { r as e, t } from "./errors-XvcwUnU4.js";
5
+ import { i as n, n as r, t as i } from "./view-rect-TO68f_UR.js";
6
+ import { t as a } from "./display-C6RC-F2-.js";
7
+ import { t as o } from "./hdr-format-DXpjc3bW.js";
8
+ import { invertMatrixStable as s } from "@margoengine/math/mat4";
9
+ import { PlanetAtmosphere as c, planetWGSL as l } from "@margoengine/sky/planet";
10
+ //#region src/planet-atmosphere.ts
11
+ var u = `${l}
12
+ ${a}
13
+ struct Frame { inverse:mat4x4f, eye:vec4f, rect:vec4f }
14
+ @group(0) @binding(0) var<uniform> frame:Frame;
15
+ override hdr:bool=false;
16
+ @vertex fn vertex(@builtin(vertex_index) i:u32)->@builtin(position) vec4f {
17
+ let p=array<vec2f,3>(vec2f(-1,-1),vec2f(3,-1),vec2f(-1,3));return vec4f(p[i],0,1);
18
+ }
19
+ @fragment fn fragment(@builtin(position) p:vec4f)->@location(0) vec4f {
20
+ let uv=(p.xy-frame.rect.xy)/frame.rect.zw;
21
+ let h=frame.inverse*vec4f(uv.x*2.0-1.0,1.0-uv.y*2.0,0.0001,1);
22
+ let linear=planetSky(h.xyz/h.w-frame.eye.xyz);
23
+ if(hdr){return vec4f(linear,1);}
24
+ return vec4f(toDisplay(linear),1);
25
+ }`, d = 0, f = class a {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
26
+ #e;
27
+ #t;
28
+ #n;
29
+ #r;
30
+ #i;
31
+ #a;
32
+ #o;
33
+ #s;
34
+ #c;
35
+ #l;
36
+ #u;
37
+ constructor(e = {}) {
38
+ this.options = e, this.name = `creative:orbit-atmosphere:${d++}`, this.enabled = !0, this.#t = new i(() => {
39
+ let e = this.#e.gpu, t = new c(e), n = e.createBuffer({
40
+ size: 96,
41
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
42
+ });
43
+ return {
44
+ transport: t,
45
+ buffer: n,
46
+ group: e.createBindGroup({
47
+ layout: this.#n,
48
+ entries: [{
49
+ binding: 0,
50
+ resource: { buffer: n }
51
+ }]
52
+ })
53
+ };
54
+ }, (e) => {
55
+ e.transport.dispose(), e.buffer.destroy();
56
+ }), this.#o = /* @__PURE__ */ new Map(), this.#s = !1, this.#c = /* @__PURE__ */ new Float32Array(16), this.#l = /* @__PURE__ */ new Float64Array(52), this.#u = /* @__PURE__ */ new Float32Array(24), this.#f = (e) => {
57
+ if (!this.enabled) return;
58
+ if (this.#s) throw t("disposed", "Orbit atmosphere is disposed; attach a new instance");
59
+ if (e.backend !== "webgpu") throw t("unsupported", "Orbit atmosphere needs a GPU device; use the full compatibility layer");
60
+ if (this.#d(), !s(e.camera.matrix, this.#c, this.#l)) throw t("state", "Planet camera is singular; use an invertible projection");
61
+ let i = this.options, a = i.center ?? [
62
+ 0,
63
+ 0,
64
+ 0
65
+ ], c = (i.atmosphere?.bottomRadius ?? 6360) / (i.radius ?? 1), l = new Float32Array([
66
+ c,
67
+ 0,
68
+ 0,
69
+ 0,
70
+ 0,
71
+ c,
72
+ 0,
73
+ 0,
74
+ 0,
75
+ 0,
76
+ c,
77
+ 0,
78
+ -a[0] * c,
79
+ -a[1] * c,
80
+ -a[2] * c,
81
+ 1
82
+ ]), u = Array.from(e.camera.position, (e, t) => (e - a[t]) * c), d = this.#t.get(e);
83
+ d.transport.prepare(e.encoder, l, u, i.sun ?? [
84
+ 1,
85
+ 0,
86
+ 0
87
+ ], i);
88
+ let f = e.descriptor.depthStencil.format, p = e.descriptor.multisample?.count ?? 1, m = `${e.format}:${p}:${f}`, h = this.#o.get(m);
89
+ h || (h = e.device.createRenderPipeline({
90
+ layout: e.device.createPipelineLayout({ bindGroupLayouts: [
91
+ this.#n,
92
+ this.#r,
93
+ d.transport.layout
94
+ ] }),
95
+ vertex: {
96
+ module: this.#a,
97
+ entryPoint: "vertex"
98
+ },
99
+ fragment: {
100
+ module: this.#a,
101
+ entryPoint: "fragment",
102
+ constants: { hdr: +o(e.format) },
103
+ targets: [{ format: e.format }]
104
+ },
105
+ depthStencil: {
106
+ format: f,
107
+ depthWriteEnabled: !1,
108
+ depthCompare: "greater-equal"
109
+ },
110
+ multisample: { count: p }
111
+ }), this.#o.set(m, h)), this.#u.set(this.#c), this.#u.set(e.camera.position, 16), this.#u.set(n(e) ?? [
112
+ 0,
113
+ 0,
114
+ e.width,
115
+ e.height
116
+ ], 20), e.device.queue.writeBuffer(d.buffer, 0, this.#u);
117
+ let g = e.encoder.beginRenderPass({
118
+ colorAttachments: [{
119
+ view: e.color,
120
+ loadOp: "load",
121
+ storeOp: "store"
122
+ }],
123
+ depthStencilAttachment: {
124
+ view: e.depth,
125
+ depthReadOnly: !0,
126
+ ...f.includes("stencil") ? { stencilReadOnly: !0 } : {}
127
+ }
128
+ });
129
+ g.setPipeline(h), g.setBindGroup(0, d.group), g.setBindGroup(1, this.#i), g.setBindGroup(2, d.transport.group), r(g, e), g.draw(3), g.end();
130
+ }, this.#d();
131
+ }
132
+ static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
133
+ let n = new a(t);
134
+ return e.use(n), n;
135
+ }
136
+ #d() {
137
+ let t = this.options;
138
+ for (let n of [t.center ?? [
139
+ 0,
140
+ 0,
141
+ 0
142
+ ], t.sun ?? [
143
+ 1,
144
+ 0,
145
+ 0
146
+ ]]) if (n.length !== 3 || Array.from(n).some((e) => !Number.isFinite(Math.fround(e)))) throw e("Orbit atmosphere needs finite xyz vectors; supply three finite numbers", "arguments");
147
+ if (!(Math.hypot(...t.sun ?? [
148
+ 1,
149
+ 0,
150
+ 0
151
+ ]) > 0) || !Number.isFinite(Math.fround(t.radius ?? 1)) || (t.radius ?? 1) <= 0) throw e("Orbit atmosphere needs positive radius and nonzero sun; adjust the planet frame", "arguments");
152
+ }
153
+ setup(e) {
154
+ if (this.#s) throw t("disposed", "Orbit atmosphere is disposed; create a new instance");
155
+ if (this.#e) throw t("attached", "Orbit atmosphere is already attached; create another instance", "state");
156
+ if (!e.gpu) throw t("unsupported", "Orbit atmosphere needs a GPU device; use WebGPU or the full WebGL2 layer");
157
+ this.#e = e;
158
+ let n = e.gpu;
159
+ this.#n = n.createBindGroupLayout({ entries: [{
160
+ binding: 0,
161
+ visibility: GPUShaderStage.FRAGMENT,
162
+ buffer: { type: "uniform" }
163
+ }] }), this.#r = n.createBindGroupLayout({ entries: [] }), this.#i = n.createBindGroup({
164
+ layout: this.#r,
165
+ entries: []
166
+ }), this.#a = n.createShaderModule({ code: u });
167
+ }
168
+ registerPasses(e) {
169
+ e.add({
170
+ name: this.name,
171
+ order: 2,
172
+ execute: this.#f
173
+ });
174
+ }
175
+ #f;
176
+ #p() {
177
+ this.#t.clear(), this.#o.clear();
178
+ }
179
+ onPreUpdate(e) {
180
+ e > 0 && this.#t.prune();
181
+ }
182
+ onDeviceRestored(e) {
183
+ this.#p(), this.#e = void 0, this.setup(e);
184
+ }
185
+ dispose() {
186
+ if (this.#s) return;
187
+ this.#s = !0;
188
+ let e = this.#e;
189
+ this.#e = void 0, e?.sceneOf(this)?.removePlugin(this.name), this.#p();
190
+ }
191
+ [Symbol.dispose]() {
192
+ this.dispose();
193
+ }
194
+ };
195
+ //#endregion
196
+ export { f as OrbitAtmosphere };
@@ -0,0 +1,47 @@
1
+ import type { PassContext, Vec3 } from '@margoengine/core/extension';
2
+ export interface PlanetImages {
3
+ day: ImageBitmap;
4
+ night?: ImageBitmap;
5
+ specular?: ImageBitmap;
6
+ normal?: ImageBitmap;
7
+ clouds?: ImageBitmap;
8
+ }
9
+ export interface PlanetPassConfig {
10
+ radius: number;
11
+ atmosphereColor: Vec3;
12
+ atmosphereIntensity: number;
13
+ nightIntensity: number;
14
+ }
15
+ type Context = Extract<PassContext, {
16
+ backend: 'webgpu';
17
+ }>;
18
+ export declare class PlanetPass {
19
+ private readonly device;
20
+ private readonly format;
21
+ private readonly depthFormat;
22
+ private readonly samples;
23
+ private readonly uniformData;
24
+ private readonly buffers;
25
+ private readonly textures;
26
+ private readonly variants;
27
+ private readonly uniform;
28
+ private readonly vertex;
29
+ private readonly index;
30
+ private readonly indexCount;
31
+ private readonly color;
32
+ private readonly surfaceDepth;
33
+ private readonly shellDepth;
34
+ private readonly surfaceDescriptor;
35
+ private readonly shellDescriptor;
36
+ private disposed;
37
+ private views;
38
+ private sampler?;
39
+ private surfaceModule?;
40
+ private shellModule?;
41
+ constructor(device: GPUDevice, images: PlanetImages, format: GPUTextureFormat, depthFormat: GPUTextureFormat, config: PlanetPassConfig, samples?: number);
42
+ private variant;
43
+ updateFrame(cameraMatrix: Float32Array, modelMatrix: Float32Array, cameraPosition: Vec3, sunDirection: ArrayLike<number>, cloudOffsetU: number): void;
44
+ record(context: Context, shell: boolean): void;
45
+ dispose(): void;
46
+ }
47
+ export {};
@@ -0,0 +1,76 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel, Vec3, VectorRef } from '@margoengine/core';
3
+ import type { Engine, EnginePlugin, FrameGraph } from '@margoengine/core/extension';
4
+ /**
5
+ * `Planet.attach` / `Planet.create` settings. Maps are equirectangular URLs (north at the top), at most 32 MiB each
6
+ * and 256 MiB decoded in total. Invalid values reject with TypeError or RangeError.
7
+ */
8
+ export interface PlanetOptions {
9
+ /** sRGB surface colour map (required). */
10
+ dayMap: string | URL;
11
+ /** sRGB city lights, boosted 3x and faded in across twilight. Omitted: none. */
12
+ nightMap?: string | URL;
13
+ /** Linear map: red = ocean specular strength, green = roughness. */
14
+ specularRoughnessMap?: string | URL;
15
+ /** Linear tangent-space RGB normal map; changes shading, not geometry. */
16
+ normalMap?: string | URL;
17
+ /** Linear grayscale cloud coverage. */
18
+ clouds?: string | URL;
19
+ /** Sphere radius in world units, > 0; clouds and glow sit at 1.01x. Default 1. */
20
+ radius?: number;
21
+ /** Axial tilt in degrees. Default: 23.4. Rotation accessors use radians. */
22
+ tilt?: number;
23
+ /** World direction towards the sun (nonzero, normalised); also `setSunDirection`. Default [-1, 0.2, 0.5]. */
24
+ sunDirection?: Vec3;
25
+ /** Rim glow: linear RGB `color` (default [0.3, 0.6, 1]) and `intensity` >= 0 (default 1.2). */
26
+ atmosphere?: {
27
+ color?: Vec3;
28
+ intensity?: number;
29
+ };
30
+ /** Cancels loading and attachment. */
31
+ signal?: AbortSignal;
32
+ /** Fetch for the maps, for example an AssetCache's or a LoadingManager's `fetch`. Default `globalThis.fetch`. */
33
+ fetch?: typeof fetch;
34
+ }
35
+ type MapOptions = Pick<PlanetOptions, 'dayMap' | 'nightMap' | 'specularRoughnessMap' | 'normalMap' | 'clouds' | 'signal' | 'fetch'>;
36
+ /** One WebGPU planet plugin per engine; created and attached asynchronously. */
37
+ export declare class Planet implements EnginePlugin {
38
+ readonly name = "planet";
39
+ readonly clouds: {
40
+ offsetU: number;
41
+ };
42
+ private readonly controller;
43
+ private readonly images;
44
+ private readonly sources;
45
+ private readonly sun;
46
+ private readonly config;
47
+ private readonly tilt;
48
+ private engine?;
49
+ private parent?;
50
+ private spin?;
51
+ private pass?;
52
+ private disposed;
53
+ private offset;
54
+ private upgrading?;
55
+ private readonly fetcher;
56
+ private constructor();
57
+ /** Adds a planet to `engine` and resolves once its maps are loaded (same as `create`). */
58
+ static attach(engine: EngineKernel, options: PlanetOptions): Promise<Planet>;
59
+ static create(engine: EngineKernel, options: PlanetOptions): Promise<Planet>;
60
+ get rotation(): VectorRef;
61
+ /** Replace the complete map set after loading/validation; the current planet stays visible on failure. `fetch` defaults to the planet's. */
62
+ updateMaps(options: MapOptions): Promise<void>;
63
+ setSunDirection(direction: Vec3): void;
64
+ private check;
65
+ setup(engine: Engine): void;
66
+ registerPasses(graph: FrameGraph): void;
67
+ private load;
68
+ private readMaps;
69
+ private createPass;
70
+ private readonly surface;
71
+ private readonly shell;
72
+ onDeviceRestored(engine: Engine): void;
73
+ dispose(): void;
74
+ [Symbol.dispose]: () => void;
75
+ }
76
+ export {};
package/dist/planet.js ADDED
@@ -0,0 +1 @@
1
+ export { t as Planet } from "./planet-BYTix5S1.js";
package/dist/post.d.ts ADDED
@@ -0,0 +1,108 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ import type { Engine, EnginePlugin, FrameGraph, Vec3 } from '@margoengine/core/extension';
4
+ import { HDRRenderTarget } from './targets.js';
5
+ /** Height fog and god rays. For a sky backdrop use `Sky` from `@margoengine/sky`. */
6
+ export interface AtmosphereOptions {
7
+ /** Exponential fog density, 0-10. Default 0 (no fog). */
8
+ density?: number;
9
+ /** How fast the fog thins with height, 0-10. Default 0. */
10
+ heightFalloff?: number;
11
+ /** Fog colour, linear RGB 0..1. Default [0.45, 0.62, 0.8]. */
12
+ color?: Vec3;
13
+ /** World direction towards the sun (nonzero) for god rays. Default [0.3, 0.6, -0.7]. */
14
+ sun?: Vec3;
15
+ /** God-ray strength, 0-4. Default 0 (off). */
16
+ godRays?: number;
17
+ }
18
+ /** For bloom, put `Bloom` from `@margoengine/post/bloom` before this effect in a `PostStack`. */
19
+ export interface PostOptions {
20
+ /** Exposure in stops, -10 to 10. Default 0. */
21
+ exposure?: number;
22
+ /** Contrast about 18% grey, 0-4; default 1: scene-linear `0.18 * (c / 0.18) ** contrast`, a slope in log exposure, so a contrast above 1 deepens the shadows without clipping them to black; contrast 0 gives flat 18% grey everywhere, black included (`0 ** 0` is 1). */
23
+ contrast?: number;
24
+ /** Saturation, 0-4 (0 is greyscale). Default 1. */
25
+ saturation?: number;
26
+ /** Per-channel multiplier, 0-16. Default [1, 1, 1]. */
27
+ gain?: Vec3;
28
+ /** Per-channel offset added after gain, -4 to 4. Default [0, 0, 0]. */
29
+ lift?: Vec3;
30
+ /** Focus distance in world units, 0.01-10,000. Default 5. */
31
+ focus?: number;
32
+ /** Focus blur strength, 0-64. Default 0 (no blur). */
33
+ aperture?: number;
34
+ /** Film grain amount, 0..1. Default 0. */
35
+ grain?: number;
36
+ /** Height fog and god rays. */
37
+ atmosphere?: AtmosphereOptions;
38
+ }
39
+ /**
40
+ * Grades the HDR scene: exponential height fog, screen-space god rays, a depth-of-field focus blur,
41
+ * exposure/contrast/saturation/gain/lift, the PBR Neutral display transform and grain; reads `post.options` each
42
+ * frame. Alone it owns the scene capture; in a `PostStack` it is the display effect (put `Bloom` before it for bloom).
43
+ * WebGPU only.
44
+ * @throws RangeError when an option is out of range; TypeError for removed options (`bloom`, `threshold`,
45
+ * `atmosphere.sky`), naming the replacement.
46
+ * @throws MargoError `'unsupported'` on a WebGL engine, `'attached'` when attached twice, `'state'` when the camera
47
+ * matrix is not invertible.
48
+ */
49
+ export declare class PostProcessing implements EnginePlugin {
50
+ readonly options: PostOptions;
51
+ readonly name = "post-processing";
52
+ target?: HDRRenderTarget;
53
+ private engine?;
54
+ private device?;
55
+ private output?;
56
+ private resolve?;
57
+ private present?;
58
+ private original?;
59
+ private readonly values;
60
+ private clock;
61
+ private updated;
62
+ private ready;
63
+ private presentKey;
64
+ private readonly inverse;
65
+ private readonly inverseWorkspace;
66
+ private shaderSource?;
67
+ private linearShader;
68
+ private colorView?;
69
+ private depthView?;
70
+ private readonly views;
71
+ private slot?;
72
+ private inputs?;
73
+ private presentGroup?;
74
+ private presentPass?;
75
+ private host?;
76
+ private sceneDepth?;
77
+ /** Same as `engine.use(new PostProcessing(...))`; returns the PostProcessing. */
78
+ static attach(engine: EngineKernel, options?: PostOptions): PostProcessing;
79
+ constructor(options?: PostOptions);
80
+ /** In a PostStack, grades (fog, focus blur, Khronos PBR Neutral, grain) the stack's HDR result as its display effect. */
81
+ private joinStack;
82
+ private validate;
83
+ setup(engine: Engine): void;
84
+ registerPasses(graph: FrameGraph): void;
85
+ private resize;
86
+ private bind;
87
+ private groupOf;
88
+ private preparePresent;
89
+ private update;
90
+ private dispatch;
91
+ private failed;
92
+ private process;
93
+ private apply;
94
+ /** Seconds on the grain clock: each frame update moves it (`advanceTime`), a draw does not. */
95
+ get time(): number;
96
+ /** Back to time 0 and a fresh one's state, history dropped (GAP-FILM-RESET; `resetClocks` in `@margoengine/cutscene/seek`). */
97
+ resetTime(): void;
98
+ /**
99
+ * Moves the film grain clock by `delta` seconds without drawing (a delta of 0 or less moves nothing). Each frame update
100
+ * runs it, so `seek` from `@margoengine/cutscene/seek` replays the grain exactly.
101
+ */
102
+ advanceTime(delta: number): void;
103
+ onPreUpdate(delta: number): void;
104
+ onDeviceRestored(engine: Engine): void;
105
+ dispose(): void;
106
+ private release;
107
+ [Symbol.dispose]: () => void;
108
+ }