@margoengine/creative 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.
@@ -1,4 +1,4 @@
1
- import "./msaa-DjFZ9hVW.js";
1
+ import "./msaa-8hWFieoE.js";
2
2
  //#region ../shared/gpu.js
3
3
  var e = "\nstruct Vertex { @builtin(position) position:vec4f,@location(0) uv:vec2f }\n@vertex fn vertex(@builtin(vertex_index) index:u32)->Vertex {\n let p=array<vec2f,3>(vec2f(-1,-1),vec2f(3,-1),vec2f(-1,3))[index];\n return Vertex(vec4f(p,0,1),vec2f(p.x*0.5+0.5,0.5-p.y*0.5));\n}";
4
4
  function t(e, t, n) {
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const a=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const a=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e } from "./view-rect-TO68f_UR.js";
5
5
  import { t } from "./quality-DFm-cQWC.js";
6
6
  import { t as n } from "./display-C6RC-F2-.js";
@@ -11,7 +11,7 @@ import { MargoError as o } from "@margoengine/math/errors";
11
11
  import { finiteVector as s } from "@margoengine/math/validate";
12
12
  import { createLcgRandom as c } from "@margoengine/math/mathutils";
13
13
  //#region src/shaders/grass-frame.wgsl?raw
14
- var l = "struct Frame {\r\n camera: mat4x4f,\r\n planes: array<vec4f, 6>,\r\n eye: vec4f,\r\n light: vec4f,\r\n radiance: vec4f,\r\n wind: vec4f,\r\n field: vec4f,\r\n settings: vec4f,\r\n right: vec4f,\r\n up: vec4f,\r\n root: vec4f,\r\n tip: vec4f,\r\n tipVariant: vec4f,\r\n translucency: vec4f,\r\n}\r\nstruct Blade {\r\n posX: f32, posY: f32, posZ: f32,\r\n rotationY: f32, scale: f32, stiffness: f32,\r\n}\r\n@group(0) @binding(0) var<uniform> frame: Frame;\r\n@group(0) @binding(1) var<storage, read> blades: array<Blade>;\r\n\r\nfn gust(root: vec2f) -> f32 {\r\n let p = root * 0.08 + frame.field.w * frame.wind.z * vec2f(0.45, 0.2);\r\n return 0.5 + 0.25 * sin(p.x * 2.1 + sin(p.y * 1.7)) + 0.25 * sin(p.y * 3.1 - p.x * 0.8);\r\n}\r\nfn displayColor(linear: vec3f) -> vec3f {\r\n if (frame.settings.z > 0.5) { return linear; }\r\n return toDisplay(linear);\r\n}\r\n", u = "@group(0) @binding(2) var<storage, read_write> visible: array<u32>;\r\nstruct Draw { vertices: u32, instances: atomic<u32>, firstVertex: u32, firstInstance: u32 }\r\n@group(0) @binding(3) var<storage, read_write> draws: array<Draw, 2>;\r\n\r\n\r\nfn bladeHash(seed: u32) -> f32 {\r\n var n = seed * 747796405u + 2891336453u;\r\n n = ((n >> ((n >> 28u) + 4u)) ^ n) * 277803737u;\r\n return f32((n >> 22u) ^ n) / 4294967296.0;\r\n}\r\n\r\n@compute @workgroup_size(64)\r\nfn cull(@builtin(global_invocation_id) id: vec3u) {\r\n let count = u32(frame.settings.y);\r\n if (id.x >= count) { return; }\r\n if (frame.settings.w < 1.0 && bladeHash(id.x) >= frame.settings.w) { return; }\r\n let b = blades[id.x];\r\n let height = frame.field.z * b.scale;\r\n let root = vec3f(b.posX, b.posY, b.posZ);\r\n let center = root + vec3f(0, height * 0.5, 0);\r\n let radius = height * 0.95;\r\n let distance = length(center - frame.eye.xyz);\r\n if (distance - radius > frame.settings.x) { return; }\r\n for (var i = 0u; i < 6u; i++) {\r\n if (dot(frame.planes[i].xyz, center) + frame.planes[i].w < -radius) { return; }\r\n }\r\n let lod = select(0u, 1u, distance > frame.settings.x * 0.45);\r\n if (distance > frame.settings.x * 0.7 && id.x % 4u != 0u) { return; }\r\n let slot = atomicAdd(&draws[lod].instances, 1u);\r\n visible[lod * count + slot] = id.x;\r\n}\r\n", d = "@group(0) @binding(2) var<storage, read> visible: array<u32>;\r\nstruct Output {\r\n @builtin(position) clip: vec4f,\r\n @location(0) uv: vec2f,\r\n @location(1) world: vec3f,\r\n @location(2) normal: vec3f,\r\n @location(3) variation: f32,\r\n}\r\n\r\nfn bladeVertex(position: vec3f, uv: vec2f, id: u32) -> Output {\r\n let b = blades[id];\r\n let root = vec3f(b.posX, b.posY, b.posZ);\r\n let height = frame.field.z * b.scale;\r\n let bend = clamp(frame.wind.w * (0.35 + 0.65 * gust(root.xz)) / b.stiffness, 0.0, 0.58);\r\n let sideways = vec3f(cos(b.rotationY), 0, sin(b.rotationY));\r\n let direction = vec3f(frame.wind.x, 0, frame.wind.y);\r\n var vertical = 0.0;\r\n var tangent = vec2f(0);\r\n\r\n for (var segment = 0; segment < 3; segment++) {\r\n let start = f32(segment) / 3.0;\r\n let end = f32(segment + 1) / 3.0;\r\n let dx = bend * (pow(end, 1.8) - pow(start, 1.8));\r\n let dy = sqrt(1.0 / 9.0 - dx * dx);\r\n vertical += dy * clamp(uv.y * 3.0 - f32(segment), 0.0, 1.0);\r\n if (abs(uv.y - start) < 0.001 || abs(uv.y - end) < 0.001) { tangent += vec2f(dx, dy); }\r\n }\r\n let curve = direction * height * bend * pow(uv.y, 1.8) + vec3f(0, height * vertical, 0);\r\n let along = direction * tangent.x + vec3f(0, tangent.y, 0);\r\n var o: Output;\r\n o.world = root + curve + sideways * position.x * height * 0.075;\r\n o.clip = frame.camera * vec4f(o.world, 1);\r\n o.uv = uv;\r\n o.normal = normalize(cross(sideways, along));\r\n o.variation = fract(b.rotationY * 7.13);\r\n return o;\r\n}\r\n@vertex fn nearVertex(@location(0) position: vec3f, @location(1) uv: vec2f, @builtin(instance_index) instance: u32) -> Output {\r\n return bladeVertex(position, uv, visible[instance]);\r\n}\r\n@vertex fn farVertex(@location(0) position: vec3f, @location(1) uv: vec2f, @builtin(instance_index) instance: u32) -> Output {\r\n return bladeVertex(position, uv, visible[u32(frame.settings.y) + instance]);\r\n}\r\n@fragment fn fragment(i: Output, @builtin(front_facing) front: bool) -> @location(0) vec4f {\r\n let n = normalize(i.normal) * select(-1.0, 1.0, front);\r\n let lightDir = frame.light.xyz;\r\n let viewDir = normalize(frame.eye.xyz - i.world);\r\n\r\n let height = clamp(i.uv.y, 0.0, 1.0);\r\n let wrap = max(dot(n, lightDir) + 0.45, 0.0) / 1.45;\r\n let sss = pow(max(dot(-lightDir, viewDir), 0.0), 2.0) * height * frame.translucency.w;\r\n let root = frame.root.xyz;\r\n let tip = mix(frame.tip.xyz, frame.tipVariant.xyz, i.variation);\r\n let color = mix(root, tip, pow(height, 0.7));\r\n let light = frame.radiance.xyz * frame.light.w;\r\n let linear = color * (frame.radiance.w + wrap * light) + frame.translucency.xyz * sss * light;\r\n return vec4f(displayColor(linear), 1);\r\n}\r\n\r\nstruct SporeOutput { @builtin(position) clip: vec4f, @location(0) uv: vec2f }\r\nfn random(seed: u32) -> f32 {\r\n var n = seed * 747796405u + 2891336453u;\r\n n = ((n >> ((n >> 28u) + 4u)) ^ n) * 277803737u;\r\n return f32((n >> 22u) ^ n) / 4294967296.0;\r\n}\r\n@vertex fn sporeVertex(@builtin(vertex_index) vertex: u32, @builtin(instance_index) id: u32) -> SporeOutput {\r\n let corners = array<vec2f, 6>(vec2f(-1,-1), vec2f(1,-1), vec2f(1,1), vec2f(-1,-1), vec2f(1,1), vec2f(-1,1));\r\n let seed = vec2f(random(id * 3u), random(id * 3u + 1u));\r\n let phase = random(id * 3u + 2u);\r\n let drift = frame.wind.xy * frame.field.w * frame.wind.z * (0.25 + gust(seed * frame.field.xy) * 0.2);\r\n let xz = (fract(seed + drift / frame.field.xy) - 0.5) * frame.field.xy;\r\n let y = frame.field.z + phase * 4.0 + sin(frame.field.w * 0.6 + phase * 6.283) * 0.25;\r\n let q = corners[vertex];\r\n let world = vec3f(xz.x, y, xz.y) + (frame.right.xyz * q.x + frame.up.xyz * q.y) * (0.035 + phase * 0.025);\r\n var o: SporeOutput; o.clip = frame.camera * vec4f(world, 1); o.uv = q; return o;\r\n}\r\n@fragment fn sporeFragment(i: SporeOutput) -> @location(0) vec4f {\r\n let radius = length(i.uv);\r\n let spokes = pow(abs(cos(atan2(i.uv.y, i.uv.x) * 6.0)), 18.0);\r\n let alpha = (1.0 - smoothstep(0.0, 0.22, radius)) + spokes * (1.0 - smoothstep(0.25, 1.0, radius)) * 0.55;\r\n if (alpha < 0.015) { discard; }\r\n return vec4f(displayColor(vec3f(2.5, 2.4, 2.1)), min(alpha, 0.85));\r\n}\r\n";
14
+ var l = "struct Frame {\n camera: mat4x4f,\n planes: array<vec4f, 6>,\n eye: vec4f,\n light: vec4f,\n radiance: vec4f,\n wind: vec4f,\n field: vec4f,\n settings: vec4f,\n right: vec4f,\n up: vec4f,\n root: vec4f,\n tip: vec4f,\n tipVariant: vec4f,\n translucency: vec4f,\n}\nstruct Blade {\n posX: f32, posY: f32, posZ: f32,\n rotationY: f32, scale: f32, stiffness: f32,\n}\n@group(0) @binding(0) var<uniform> frame: Frame;\n@group(0) @binding(1) var<storage, read> blades: array<Blade>;\n\nfn gust(root: vec2f) -> f32 {\n let p = root * 0.08 + frame.field.w * frame.wind.z * vec2f(0.45, 0.2);\n return 0.5 + 0.25 * sin(p.x * 2.1 + sin(p.y * 1.7)) + 0.25 * sin(p.y * 3.1 - p.x * 0.8);\n}\nfn displayColor(linear: vec3f) -> vec3f {\n if (frame.settings.z > 0.5) { return linear; }\n return toDisplay(linear);\n}\n", u = "@group(0) @binding(2) var<storage, read_write> visible: array<u32>;\nstruct Draw { vertices: u32, instances: atomic<u32>, firstVertex: u32, firstInstance: u32 }\n@group(0) @binding(3) var<storage, read_write> draws: array<Draw, 2>;\n\n\nfn bladeHash(seed: u32) -> f32 {\n var n = seed * 747796405u + 2891336453u;\n n = ((n >> ((n >> 28u) + 4u)) ^ n) * 277803737u;\n return f32((n >> 22u) ^ n) / 4294967296.0;\n}\n\n@compute @workgroup_size(64)\nfn cull(@builtin(global_invocation_id) id: vec3u) {\n let count = u32(frame.settings.y);\n if (id.x >= count) { return; }\n if (frame.settings.w < 1.0 && bladeHash(id.x) >= frame.settings.w) { return; }\n let b = blades[id.x];\n let height = frame.field.z * b.scale;\n let root = vec3f(b.posX, b.posY, b.posZ);\n let center = root + vec3f(0, height * 0.5, 0);\n let radius = height * 0.95;\n let distance = length(center - frame.eye.xyz);\n if (distance - radius > frame.settings.x) { return; }\n for (var i = 0u; i < 6u; i++) {\n if (dot(frame.planes[i].xyz, center) + frame.planes[i].w < -radius) { return; }\n }\n let lod = select(0u, 1u, distance > frame.settings.x * 0.45);\n if (distance > frame.settings.x * 0.7 && id.x % 4u != 0u) { return; }\n let slot = atomicAdd(&draws[lod].instances, 1u);\n visible[lod * count + slot] = id.x;\n}\n", d = "@group(0) @binding(2) var<storage, read> visible: array<u32>;\nstruct Output {\n @builtin(position) clip: vec4f,\n @location(0) uv: vec2f,\n @location(1) world: vec3f,\n @location(2) normal: vec3f,\n @location(3) variation: f32,\n}\n\nfn bladeVertex(position: vec3f, uv: vec2f, id: u32) -> Output {\n let b = blades[id];\n let root = vec3f(b.posX, b.posY, b.posZ);\n let height = frame.field.z * b.scale;\n let bend = clamp(frame.wind.w * (0.35 + 0.65 * gust(root.xz)) / b.stiffness, 0.0, 0.58);\n let sideways = vec3f(cos(b.rotationY), 0, sin(b.rotationY));\n let direction = vec3f(frame.wind.x, 0, frame.wind.y);\n var vertical = 0.0;\n var tangent = vec2f(0);\n\n for (var segment = 0; segment < 3; segment++) {\n let start = f32(segment) / 3.0;\n let end = f32(segment + 1) / 3.0;\n let dx = bend * (pow(end, 1.8) - pow(start, 1.8));\n let dy = sqrt(1.0 / 9.0 - dx * dx);\n vertical += dy * clamp(uv.y * 3.0 - f32(segment), 0.0, 1.0);\n if (abs(uv.y - start) < 0.001 || abs(uv.y - end) < 0.001) { tangent += vec2f(dx, dy); }\n }\n let curve = direction * height * bend * pow(uv.y, 1.8) + vec3f(0, height * vertical, 0);\n let along = direction * tangent.x + vec3f(0, tangent.y, 0);\n var o: Output;\n o.world = root + curve + sideways * position.x * height * 0.075;\n o.clip = frame.camera * vec4f(o.world, 1);\n o.uv = uv;\n o.normal = normalize(cross(sideways, along));\n o.variation = fract(b.rotationY * 7.13);\n return o;\n}\n@vertex fn nearVertex(@location(0) position: vec3f, @location(1) uv: vec2f, @builtin(instance_index) instance: u32) -> Output {\n return bladeVertex(position, uv, visible[instance]);\n}\n@vertex fn farVertex(@location(0) position: vec3f, @location(1) uv: vec2f, @builtin(instance_index) instance: u32) -> Output {\n return bladeVertex(position, uv, visible[u32(frame.settings.y) + instance]);\n}\n@fragment fn fragment(i: Output, @builtin(front_facing) front: bool) -> @location(0) vec4f {\n let n = normalize(i.normal) * select(-1.0, 1.0, front);\n let lightDir = frame.light.xyz;\n let viewDir = normalize(frame.eye.xyz - i.world);\n\n let height = clamp(i.uv.y, 0.0, 1.0);\n let wrap = max(dot(n, lightDir) + 0.45, 0.0) / 1.45;\n let sss = pow(max(dot(-lightDir, viewDir), 0.0), 2.0) * height * frame.translucency.w;\n let root = frame.root.xyz;\n let tip = mix(frame.tip.xyz, frame.tipVariant.xyz, i.variation);\n let color = mix(root, tip, pow(height, 0.7));\n let light = frame.radiance.xyz * frame.light.w;\n let linear = color * (frame.radiance.w + wrap * light) + frame.translucency.xyz * sss * light;\n return vec4f(displayColor(linear), 1);\n}\n\nstruct SporeOutput { @builtin(position) clip: vec4f, @location(0) uv: vec2f }\nfn random(seed: u32) -> f32 {\n var n = seed * 747796405u + 2891336453u;\n n = ((n >> ((n >> 28u) + 4u)) ^ n) * 277803737u;\n return f32((n >> 22u) ^ n) / 4294967296.0;\n}\n@vertex fn sporeVertex(@builtin(vertex_index) vertex: u32, @builtin(instance_index) id: u32) -> SporeOutput {\n let corners = array<vec2f, 6>(vec2f(-1,-1), vec2f(1,-1), vec2f(1,1), vec2f(-1,-1), vec2f(1,1), vec2f(-1,1));\n let seed = vec2f(random(id * 3u), random(id * 3u + 1u));\n let phase = random(id * 3u + 2u);\n let drift = frame.wind.xy * frame.field.w * frame.wind.z * (0.25 + gust(seed * frame.field.xy) * 0.2);\n let xz = (fract(seed + drift / frame.field.xy) - 0.5) * frame.field.xy;\n let y = frame.field.z + phase * 4.0 + sin(frame.field.w * 0.6 + phase * 6.283) * 0.25;\n let q = corners[vertex];\n let world = vec3f(xz.x, y, xz.y) + (frame.right.xyz * q.x + frame.up.xyz * q.y) * (0.035 + phase * 0.025);\n var o: SporeOutput; o.clip = frame.camera * vec4f(world, 1); o.uv = q; return o;\n}\n@fragment fn sporeFragment(i: SporeOutput) -> @location(0) vec4f {\n let radius = length(i.uv);\n let spokes = pow(abs(cos(atan2(i.uv.y, i.uv.x) * 6.0)), 18.0);\n let alpha = (1.0 - smoothstep(0.0, 0.22, radius)) + spokes * (1.0 - smoothstep(0.25, 1.0, radius)) * 0.55;\n if (alpha < 0.015) { discard; }\n return vec4f(displayColor(vec3f(2.5, 2.4, 2.1)), min(alpha, 0.85));\n}\n";
15
15
  //#endregion
16
16
  //#region ../shared/unit-light.js
17
17
  function f(e, t, n) {
@@ -20,8 +20,8 @@ function f(e, t, n) {
20
20
  }
21
21
  //#endregion
22
22
  //#region src/grass.ts
23
- var p = 0, m = class m {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
24
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
23
+ var p = 0, m = class m {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
24
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
25
25
  return new m({ engine: e }, t);
26
26
  }
27
27
  constructor(t, n = {}) {
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
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);
3
+ const n=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { r as e, t } from "./errors-XvcwUnU4.js";
5
5
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
6
  import { Geometry as r } from "@margoengine/core";
@@ -15,7 +15,7 @@ function o(e) {
15
15
  if (typeof e?.sceneOf == "function") {
16
16
  for (let n of e.plugins?.values() ?? []) if (t = e.sceneOf(n)) break;
17
17
  if (!t) {
18
- let n = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
18
+ let n = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
19
19
  name: a(e, "scene-scope:"),
20
20
  setup() {
21
21
  t = e.sceneOf(n);
@@ -31,7 +31,7 @@ function s(e, t) {
31
31
  scene: t,
32
32
  run(n) {
33
33
  if (!t) return n();
34
- let r, i = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("0.1.0",import.meta.url),
34
+ let r, i = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
35
35
  name: a(e, "scene-scope:"),
36
36
  setup() {
37
37
  r = n();
package/dist/grass.js CHANGED
@@ -1 +1 @@
1
- export { t as GrassField } from "./grass-StuKCE_k.js";
1
+ export { t as GrassField } from "./grass-OkjgCaF7.js";
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { GPUParticles as e } from "./particles.js";
2
2
  import { HDRRenderTarget as t } from "./targets.js";
3
3
  import { ToonShading as n } from "./toon.js";
4
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";
5
+ import { t as i } from "./grass-OkjgCaF7.js";
6
+ import { t as a } from "./planet-BYTix5S1.js";
7
+ import { t as o } from "./stars-C0SH8-aJ.js";
8
8
  export { e as GPUParticles, i as GrassField, t as HDRRenderTarget, a as Planet, r as PostProcessing, o as Stars, n as ToonShading };
@@ -86,7 +86,22 @@ function d(e, t, n, r, i, a = !1) {
86
86
  }
87
87
  };
88
88
  }
89
- var f = class {
89
+ function f(t, n, r, i, a, o) {
90
+ let s = t.pipelines.get(i);
91
+ s || t.pipelines.set(i, s = /* @__PURE__ */ new Map());
92
+ let c = s.get(a);
93
+ if (!c) {
94
+ let e = t.samples === 1;
95
+ s.set(a, c = d(t.device, t.depthSource, r, i, a, e));
96
+ }
97
+ c.descriptor.depthStencilAttachment.view = r, c.descriptor.depthStencilAttachment.depthLoadOp = o?.view ? "load" : "clear";
98
+ let l = n.beginRenderPass(c.descriptor);
99
+ o && e(l, o);
100
+ let u = c.draws;
101
+ for (let e = 0; e < u.length; e++) l.setPipeline(u[e].pipeline), l.setBindGroup(0, u[e].group), l.draw(3);
102
+ l.end();
103
+ }
104
+ var p = class {
90
105
  constructor(e, t, n, r = 4) {
91
106
  if (r !== 1 && r !== 4) throw RangeError("Scene samples must be 1 or 4");
92
107
  this.samples = r, this.device = e, this.resolvedColor = t, this.resolvedDepth = n, this.textures = [], this.pipelines = /* @__PURE__ */ new Map();
@@ -128,7 +143,7 @@ var f = class {
128
143
  depth: e.depth,
129
144
  format: e.format,
130
145
  descriptor: e.descriptor,
131
- owner: p(e)
146
+ owner: m(e)
132
147
  }), e.color = this.color, e.depth = this.depth, e.format = this.resolvedColor.format, this.baseDescriptor !== e.descriptor && (this.baseDescriptor = e.descriptor, this.descriptor = {
133
148
  ...e.descriptor,
134
149
  depthStencil: {
@@ -136,41 +151,33 @@ var f = class {
136
151
  format: this.resolvedDepth.format
137
152
  },
138
153
  multisample: { count: this.samples }
139
- }), e.descriptor = this.descriptor, e[l] = this, this.retired = !1;
154
+ }), e.descriptor = this.descriptor, e[l] = this, this.retired = !1, this.resized = e.width !== void 0 && (e.width !== this.resolvedDepth.width || e.height !== this.resolvedDepth.height);
140
155
  }
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();
156
+ copyDepth(e, t, n, r = this.resolvedDepth.format) {
157
+ this.depthSource ??= this.resolvedDepth.createView({ aspect: "depth-only" }), f(this, e, t, n, r, this.viewContext);
151
158
  }
152
159
  resolve(e, t = !1, n = !0) {
153
- if (this.samples !== 1) {
160
+ if (this.samples === 1) t && this.give(e);
161
+ else {
154
162
  if (n && this.copyDepth(e, this.resolvedDepthView, 1), t) {
155
163
  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;
164
+ this.finalResolution.colorAttachments[0].storeOp = t, this.finalResolution.depthStencilAttachment.depthStoreOp = t, this.give(e);
157
165
  }
158
166
  e.beginRenderPass(t ? this.finalResolution : this.resolution).end();
159
167
  }
160
168
  }
169
+ give(e) {
170
+ let t = this.original;
171
+ this.retired || !t || this.resized || (this.copyDepth(e, t.depth, t.descriptor.multisample?.count ?? 1, t.descriptor.depthStencil.format), this.retired = !0);
172
+ }
161
173
  restore(e) {
162
174
  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, {
175
+ this.give(e.encoder), Object.assign(e, {
169
176
  color: t.color,
170
177
  depth: t.depth,
171
178
  format: t.format,
172
179
  descriptor: t.descriptor
173
- }), e[l] = t.owner);
180
+ }), e[l] = t.owner;
174
181
  }
175
182
  present(n) {
176
183
  this.resolve(n.encoder, !0), this.restore(n);
@@ -205,9 +212,9 @@ var f = class {
205
212
  this.textures = [], this.pipelines.clear();
206
213
  }
207
214
  };
208
- function p(e) {
215
+ function m(e) {
209
216
  let t = e[l];
210
217
  return t?.color === e.color && t.depth === e.depth ? t : void 0;
211
218
  }
212
219
  //#endregion
213
- export { f as t };
220
+ export { p as t };
@@ -1,9 +1,9 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const l=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const l=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { r as e, t } from "./errors-XvcwUnU4.js";
5
5
  import { i as n, n as r, r as i, t as a } from "./view-rect-TO68f_UR.js";
6
- import { n as o, r as s, t as c } from "./gpu-DN8sGUpu.js";
6
+ import { n as o, r as s, t as c } from "./gpu-DaSofAeP.js";
7
7
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
8
8
  import { PostStack as u } from "@margoengine/post/stack";
9
9
  //#region src/paint-aniso.ts
@@ -56,7 +56,7 @@ fn tensorAt(p:vec2i)->vec3f {return textureLoad(tensor,coord(p),0).rgb;}
56
56
  result+=mean*preference;total+=preference;
57
57
  }
58
58
  return vec4f(mix(centre.rgb,clamp(result/total,vec3f(0),vec3f(1)),paint.parameters.y),centre.a);
59
- }`, h = class c {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
59
+ }`, h = class c {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
60
60
  #e;
61
61
  #t;
62
62
  #n;
@@ -77,7 +77,7 @@ fn tensorAt(p:vec2i)->vec3f {return textureLoad(tensor,coord(p),0).rgb;}
77
77
  e.uniform.destroy(), e.first?.destroy(), e.second?.destroy();
78
78
  }), this.#p();
79
79
  }
80
- static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
80
+ static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
81
81
  let r = new c(n);
82
82
  if (!l(e).gpu) throw t("unsupported", "Anisotropic paint needs a GPU device; use WebGPU or the full compatibility layer");
83
83
  return r.#t = u.join(e, r), r;
@@ -149,11 +149,13 @@ fn tensorAt(p:vec2i)->vec3f {return textureLoad(tensor,coord(p),0).rgb;}
149
149
  texture: { sampleType: "unfilterable-float" }
150
150
  }] });
151
151
  }
152
- let r = t.format + ":" + (t.multisample?.count ?? 1), i = this.#s.get(r);
152
+ let r = this.#s.get(t.format);
153
+ r || this.#s.set(t.format, r = /* @__PURE__ */ new Map());
154
+ let i = r.get(t.multisample?.count ?? 1);
153
155
  return i || (i = s(n, m, t.format, {
154
156
  layout: n.createPipelineLayout({ bindGroupLayouts: [this.#o] }),
155
157
  multisample: t.multisample
156
- }), this.#s.set(r, i)), i;
158
+ }), r.set(t.multisample?.count ?? 1, i)), i;
157
159
  }
158
160
  #h(r, i, a) {
159
161
  if (this.#f(), this.#p(), !this.#e) throw t("state", "Anisotropic paint needs a live stack; attach before drawing");
package/dist/paint.js CHANGED
@@ -1,13 +1,33 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const l=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const l=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { r as e, t } from "./errors-XvcwUnU4.js";
5
5
  import { i as n, n as r, r as i, t as a } from "./view-rect-TO68f_UR.js";
6
- import { n as o, r as s, t as c } from "./gpu-DN8sGUpu.js";
6
+ import { n as o, r as s, t as c } from "./gpu-DaSofAeP.js";
7
7
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
8
8
  import { PostStack as u } from "@margoengine/post/stack";
9
- //#region src/paint.ts
10
- var d = `${c}
9
+ //#region ../shared/output-key.js
10
+ var d = class {
11
+ format = "";
12
+ samples = -1;
13
+ hdr = !1;
14
+ straight = !1;
15
+ extra = void 0;
16
+ #e = "";
17
+ #t = -1;
18
+ #n = !1;
19
+ #r = !1;
20
+ #i = void 0;
21
+ changed(e, t, n) {
22
+ return this.format === e.format && this.samples === e.multisample.count && this.hdr === !!e.hdr && this.straight === t && this.extra === n ? !1 : (this.#e = e.format, this.#t = e.multisample.count, this.#n = !!e.hdr, this.#r = t, this.#i = n, !0);
23
+ }
24
+ done() {
25
+ this.format = this.#e, this.samples = this.#t, this.hdr = this.#n, this.straight = this.#r, this.extra = this.#i;
26
+ }
27
+ reset() {
28
+ this.format = "";
29
+ }
30
+ }, f = `${c}
11
31
  struct Paint {rect:vec4i,flags:vec4u,blend:vec4f}
12
32
  @group(0) @binding(0) var<uniform> paint:Paint;
13
33
  @group(0) @binding(1) var image:texture_2d<f32>;
@@ -56,14 +76,14 @@ fn smoothColour(p:vec2i,r:i32)->vec3f {
56
76
  }
57
77
  }
58
78
  return vec4f(mix(centre.rgb,clamp(colour,vec3f(0),vec3f(1)),paint.blend.x),centre.a);
59
- }`, f = class c {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
79
+ }`, p = class c {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
60
80
  constructor(e = {}) {
61
- this.options = e, this.name = "painterly", this.stacked = !1, this.disposed = !1, this.key = "", this.bytes = /* @__PURE__ */ new ArrayBuffer(48), this.rect = new Int32Array(this.bytes, 0, 4), this.flags = new Uint32Array(this.bytes, 16, 4), this.blend = new Float32Array(this.bytes, 32, 4), this.views = new a(() => ({ uniform: this.engine.gpu.createBuffer({
81
+ this.options = e, this.name = "painterly", this.stacked = !1, this.disposed = !1, this.key = new d(), this.bytes = /* @__PURE__ */ new ArrayBuffer(48), this.rect = new Int32Array(this.bytes, 0, 4), this.flags = new Uint32Array(this.bytes, 16, 4), this.blend = new Float32Array(this.bytes, 32, 4), this.views = new a(() => ({ uniform: this.engine.gpu.createBuffer({
62
82
  size: 48,
63
83
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
64
84
  }) }), (e) => e.uniform.destroy()), this.validate();
65
85
  }
66
- static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
86
+ static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
67
87
  let r = new c(n);
68
88
  if (!l(e).gpu) throw t("unsupported", "Painterly requires WebGPU; WebGL2 is unsupported");
69
89
  return r.stack = u.join(e, r), r;
@@ -120,29 +140,28 @@ fn smoothColour(p:vec2i,r:i32)->vec3f {
120
140
  }
121
141
  draw(e, a, c) {
122
142
  if (this.alive(), this.validate(), !this.engine) throw t("state", "Attach Painterly to a live PostStack before drawing");
123
- let l = c.format + ":" + (c.multisample?.count ?? 1);
124
- l !== this.key && (this.pipeline = s(e.device, d, c.format, { multisample: c.multisample }), this.key = l);
125
- let u = this.views.get(e);
143
+ this.key.changed(c, !1) && (this.pipeline = s(e.device, f, c.format, { multisample: c.multisample }), this.key.done());
144
+ let l = this.views.get(e);
126
145
  this.rect.set(n(e) ?? [
127
146
  0,
128
147
  0,
129
148
  e.width,
130
149
  e.height
131
- ]), this.flags[0] = this.options.radius ?? 3, this.flags[1] = this.options.mode === "sketch" ? 2 : +(this.options.mode === "watercolour"), this.flags[2] = +this.enabled, this.blend[0] = this.options.strength ?? 1, e.device.queue.writeBuffer(u.uniform, 0, this.bytes), (u.input !== a || u.pipeline !== this.pipeline) && (u.group = o(e.device, this.pipeline, [{ buffer: u.uniform }, a]), u.input = a, u.pipeline = this.pipeline);
132
- let f = e.encoder.beginRenderPass({ colorAttachments: [{
150
+ ]), this.flags[0] = this.options.radius ?? 3, this.flags[1] = this.options.mode === "sketch" ? 2 : +(this.options.mode === "watercolour"), this.flags[2] = +this.enabled, this.blend[0] = this.options.strength ?? 1, e.device.queue.writeBuffer(l.uniform, 0, this.bytes), (l.input !== a || l.pipeline !== this.pipeline) && (l.group = o(e.device, this.pipeline, [{ buffer: l.uniform }, a]), l.input = a, l.pipeline = this.pipeline);
151
+ let u = e.encoder.beginRenderPass({ colorAttachments: [{
133
152
  view: c.view,
134
153
  loadOp: i(e, "clear"),
135
154
  storeOp: "store"
136
155
  }] });
137
156
  try {
138
- f.setPipeline(this.pipeline), f.setBindGroup(0, u.group), r(f, e), f.draw(3);
157
+ u.setPipeline(this.pipeline), u.setBindGroup(0, l.group), r(u, e), u.draw(3);
139
158
  } finally {
140
- f.end();
159
+ u.end();
141
160
  }
142
161
  }
143
162
  release() {
144
- this.views.clear(), this.pipeline = void 0, this.key = "";
163
+ this.views.clear(), this.pipeline = void 0, this.key.reset();
145
164
  }
146
165
  };
147
166
  //#endregion
148
- export { f as Painterly };
167
+ export { p as Painterly };
package/dist/particles.js CHANGED
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { VFX as e } from "@margoengine/vfx/base";
@@ -8,7 +8,7 @@ import { sort as r } from "@margoengine/vfx/sort";
8
8
  import { textureFeature as i } from "@margoengine/vfx/texture";
9
9
  //#region src/particles.ts
10
10
  var a = class a extends e {
11
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
11
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
12
12
  let n = new a(t);
13
13
  return e.use(n), n;
14
14
  }
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { n as e } from "./errors-XvcwUnU4.js";
@@ -74,7 +74,7 @@ async function l(t, n) {
74
74
  }
75
75
  //#endregion
76
76
  //#region src/shaders/planet_surface.wgsl?raw
77
- var u = "struct PlanetFrame {\r\n camera: mat4x4f,\r\n model: mat4x4f,\r\n eyeRadius: vec4f,\r\n sunOffset: vec4f,\r\n atmosphere: vec4f,\r\n settings: vec4f,\r\n};\r\n\r\n@group(0) @binding(0) var<uniform> frame: PlanetFrame;\r\n@group(0) @binding(1) var filtering: sampler;\r\n@group(0) @binding(2) var dayMap: texture_2d<f32>;\r\n@group(0) @binding(3) var nightMap: texture_2d<f32>;\r\n@group(0) @binding(4) var specularMap: texture_2d<f32>;\r\n@group(0) @binding(5) var normalMap: texture_2d<f32>;\r\noverride outputHdr: bool = false;\r\n\r\nstruct VertexOutput {\r\n @builtin(position) clip: vec4f,\r\n @location(0) direction: vec3f,\r\n @location(1) world: vec3f,\r\n};\r\n\r\n@vertex fn vs_main(@location(0) position: vec3f) -> VertexOutput {\r\n var out: VertexOutput;\r\n let world = frame.model * vec4f(position * frame.eyeRadius.w, 1.0);\r\n out.clip = frame.camera * world;\r\n out.direction = position;\r\n out.world = world.xyz;\r\n return out;\r\n}\r\n\r\nfn encodeColor(linear: vec3f) -> vec3f {\r\n if (outputHdr) {return linear;}\r\n return toDisplay(linear);\r\n}\r\n\r\n@fragment fn fs_main(input: VertexOutput) -> @location(0) vec4f {\r\n let local = normalize(input.direction);\r\n let uv = vec2f(atan2(local.z, local.x) / 6.283185307 + 0.5, acos(clamp(local.y, -1.0, 1.0)) / 3.141592654);\r\n let day = textureSample(dayMap, filtering, uv).rgb;\r\n let night = textureSample(nightMap, filtering, uv).rgb;\r\n let mask = textureSample(specularMap, filtering, uv).rg;\r\n let relief = textureSample(normalMap, filtering, uv).rgb * 2.0 - 1.0;\r\n let rotation = mat3x3f(frame.model[0].xyz, frame.model[1].xyz, frame.model[2].xyz);\r\n let geometricNormal = normalize(rotation * local);\r\n var shadingNormal = geometricNormal;\r\n if (frame.settings.x > 0.0) {\r\n let horizontal = length(local.xz);\r\n var tangent = vec3f(1.0, 0.0, 0.0);\r\n if (horizontal > 0.0001) {tangent = vec3f(-local.z, 0.0, local.x) / horizontal;}\r\n let bitangent = cross(local, tangent);\r\n let mapped = tangent * relief.x + bitangent * relief.y + local * relief.z;\r\n if (dot(mapped, mapped) > 0.000001) {shadingNormal = normalize(rotation * mapped);}\r\n }\r\n let light = frame.sunOffset.xyz;\r\n let view = normalize(frame.eyeRadius.xyz - input.world);\r\n let geometricLight = dot(geometricNormal, light);\r\n let diffuse = max(dot(shadingNormal, light), 0.0);\r\n let nightWeight = 1.0 - smoothstep(-0.15, 0.05, geometricLight);\r\n let shininess = mix(256.0, 8.0, mask.g);\r\n let glint = pow(max(dot(reflect(-light, shadingNormal), view), 0.0), shininess) * mask.r * max(geometricLight, 0.0);\r\n let color = day * diffuse + night * frame.settings.z * nightWeight + vec3f(glint);\r\n return vec4f(encodeColor(color), 1.0);\r\n}\r\n", d = "struct PlanetFrame {\r\n camera: mat4x4f,\r\n model: mat4x4f,\r\n eyeRadius: vec4f,\r\n sunOffset: vec4f,\r\n atmosphere: vec4f,\r\n settings: vec4f,\r\n};\r\n\r\n@group(0) @binding(0) var<uniform> frame: PlanetFrame;\r\n@group(0) @binding(1) var filtering: sampler;\r\n@group(0) @binding(2) var cloudMap: texture_2d<f32>;\r\noverride outputHdr: bool = false;\r\n\r\nstruct VertexOutput {\r\n @builtin(position) clip: vec4f,\r\n @location(0) direction: vec3f,\r\n @location(1) world: vec3f,\r\n};\r\n\r\n@vertex fn vs_main(@location(0) position: vec3f) -> VertexOutput {\r\n var out: VertexOutput;\r\n let world = frame.model * vec4f(position * frame.eyeRadius.w * 1.01, 1.0);\r\n out.clip = frame.camera * world;\r\n out.direction = position;\r\n out.world = world.xyz;\r\n return out;\r\n}\r\n\r\nfn encodeColor(linear: vec3f) -> vec3f {\r\n if (outputHdr) {return linear;}\r\n return toDisplay(linear);\r\n}\r\n\r\n@fragment fn fs_main(input: VertexOutput) -> @location(0) vec4f {\r\n let local = normalize(input.direction);\r\n let uv = vec2f(atan2(local.z, local.x) / 6.283185307 + 0.5 + frame.sunOffset.w, acos(clamp(local.y, -1.0, 1.0)) / 3.141592654);\r\n let cloud = textureSample(cloudMap, filtering, uv);\r\n let rotation = mat3x3f(frame.model[0].xyz, frame.model[1].xyz, frame.model[2].xyz);\r\n let normal = normalize(rotation * local);\r\n let view = normalize(frame.eyeRadius.xyz - input.world);\r\n let light = dot(normal, frame.sunOffset.xyz);\r\n let opacity = clamp(cloud.r * cloud.a * frame.settings.y, 0.0, 1.0);\r\n let cloudColor = vec3f(max(light, 0.0) + 0.025);\r\n let rim = pow(1.0 - clamp(dot(view, normal), 0.0, 1.0), 3.5);\r\n let sunlight = smoothstep(-0.15, 0.35, light);\r\n let glow = frame.atmosphere.rgb * frame.atmosphere.a * rim * sunlight;\r\n return vec4f(encodeColor(cloudColor) * opacity + encodeColor(glow), opacity);\r\n}\r\n", f = class {
77
+ var u = "struct PlanetFrame {\n camera: mat4x4f,\n model: mat4x4f,\n eyeRadius: vec4f,\n sunOffset: vec4f,\n atmosphere: vec4f,\n settings: vec4f,\n};\n\n@group(0) @binding(0) var<uniform> frame: PlanetFrame;\n@group(0) @binding(1) var filtering: sampler;\n@group(0) @binding(2) var dayMap: texture_2d<f32>;\n@group(0) @binding(3) var nightMap: texture_2d<f32>;\n@group(0) @binding(4) var specularMap: texture_2d<f32>;\n@group(0) @binding(5) var normalMap: texture_2d<f32>;\noverride outputHdr: bool = false;\n\nstruct VertexOutput {\n @builtin(position) clip: vec4f,\n @location(0) direction: vec3f,\n @location(1) world: vec3f,\n};\n\n@vertex fn vs_main(@location(0) position: vec3f) -> VertexOutput {\n var out: VertexOutput;\n let world = frame.model * vec4f(position * frame.eyeRadius.w, 1.0);\n out.clip = frame.camera * world;\n out.direction = position;\n out.world = world.xyz;\n return out;\n}\n\nfn encodeColor(linear: vec3f) -> vec3f {\n if (outputHdr) {return linear;}\n return toDisplay(linear);\n}\n\n@fragment fn fs_main(input: VertexOutput) -> @location(0) vec4f {\n let local = normalize(input.direction);\n let uv = vec2f(atan2(local.z, local.x) / 6.283185307 + 0.5, acos(clamp(local.y, -1.0, 1.0)) / 3.141592654);\n let day = textureSample(dayMap, filtering, uv).rgb;\n let night = textureSample(nightMap, filtering, uv).rgb;\n let mask = textureSample(specularMap, filtering, uv).rg;\n let relief = textureSample(normalMap, filtering, uv).rgb * 2.0 - 1.0;\n let rotation = mat3x3f(frame.model[0].xyz, frame.model[1].xyz, frame.model[2].xyz);\n let geometricNormal = normalize(rotation * local);\n var shadingNormal = geometricNormal;\n if (frame.settings.x > 0.0) {\n let horizontal = length(local.xz);\n var tangent = vec3f(1.0, 0.0, 0.0);\n if (horizontal > 0.0001) {tangent = vec3f(-local.z, 0.0, local.x) / horizontal;}\n let bitangent = cross(local, tangent);\n let mapped = tangent * relief.x + bitangent * relief.y + local * relief.z;\n if (dot(mapped, mapped) > 0.000001) {shadingNormal = normalize(rotation * mapped);}\n }\n let light = frame.sunOffset.xyz;\n let view = normalize(frame.eyeRadius.xyz - input.world);\n let geometricLight = dot(geometricNormal, light);\n let diffuse = max(dot(shadingNormal, light), 0.0);\n let nightWeight = 1.0 - smoothstep(-0.15, 0.05, geometricLight);\n let shininess = mix(256.0, 8.0, mask.g);\n let glint = pow(max(dot(reflect(-light, shadingNormal), view), 0.0), shininess) * mask.r * max(geometricLight, 0.0);\n let color = day * diffuse + night * frame.settings.z * nightWeight + vec3f(glint);\n return vec4f(encodeColor(color), 1.0);\n}\n", d = "struct PlanetFrame {\n camera: mat4x4f,\n model: mat4x4f,\n eyeRadius: vec4f,\n sunOffset: vec4f,\n atmosphere: vec4f,\n settings: vec4f,\n};\n\n@group(0) @binding(0) var<uniform> frame: PlanetFrame;\n@group(0) @binding(1) var filtering: sampler;\n@group(0) @binding(2) var cloudMap: texture_2d<f32>;\noverride outputHdr: bool = false;\n\nstruct VertexOutput {\n @builtin(position) clip: vec4f,\n @location(0) direction: vec3f,\n @location(1) world: vec3f,\n};\n\n@vertex fn vs_main(@location(0) position: vec3f) -> VertexOutput {\n var out: VertexOutput;\n let world = frame.model * vec4f(position * frame.eyeRadius.w * 1.01, 1.0);\n out.clip = frame.camera * world;\n out.direction = position;\n out.world = world.xyz;\n return out;\n}\n\nfn encodeColor(linear: vec3f) -> vec3f {\n if (outputHdr) {return linear;}\n return toDisplay(linear);\n}\n\n@fragment fn fs_main(input: VertexOutput) -> @location(0) vec4f {\n let local = normalize(input.direction);\n let uv = vec2f(atan2(local.z, local.x) / 6.283185307 + 0.5 + frame.sunOffset.w, acos(clamp(local.y, -1.0, 1.0)) / 3.141592654);\n let cloud = textureSample(cloudMap, filtering, uv);\n let rotation = mat3x3f(frame.model[0].xyz, frame.model[1].xyz, frame.model[2].xyz);\n let normal = normalize(rotation * local);\n let view = normalize(frame.eyeRadius.xyz - input.world);\n let light = dot(normal, frame.sunOffset.xyz);\n let opacity = clamp(cloud.r * cloud.a * frame.settings.y, 0.0, 1.0);\n let cloudColor = vec3f(max(light, 0.0) + 0.025);\n let rim = pow(1.0 - clamp(dot(view, normal), 0.0, 1.0), 3.5);\n let sunlight = smoothstep(-0.15, 0.35, light);\n let glow = frame.atmosphere.rgb * frame.atmosphere.a * rim * sunlight;\n return vec4f(encodeColor(cloudColor) * opacity + encodeColor(glow), opacity);\n}\n", f = class {
78
78
  constructor(e, t, i, a, s, c = n()) {
79
79
  if (this.device = e, this.format = i, this.depthFormat = a, this.samples = c, this.uniformData = /* @__PURE__ */ new Float32Array(48), this.buffers = [], this.textures = [], this.variants = /* @__PURE__ */ new Map(), this.color = {
80
80
  view: void 0,
@@ -305,7 +305,7 @@ function p(e) {
305
305
  }
306
306
  return t;
307
307
  }
308
- var m = class e {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
308
+ var m = class e {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
309
309
  constructor(e) {
310
310
  if (this.name = "planet", this.controller = new AbortController(), this.images = { day: void 0 }, this.sources = [], this.sun = /* @__PURE__ */ new Float32Array(3), this.disposed = !1, this.offset = 0, this.surface = (e) => {
311
311
  this.pass && e.backend === "webgpu" && (this.pass.updateFrame(e.camera.matrix, this.spin.matrix, e.camera.position, this.sun, this.offset), this.pass.record(e, !1));
@@ -350,7 +350,7 @@ var m = class e {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url)
350
350
  }
351
351
  };
352
352
  }
353
- static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
353
+ static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
354
354
  return e.create(t, n);
355
355
  }
356
356
  static async create(t, n) {
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { r as e, t } from "./errors-XvcwUnU4.js";
@@ -22,7 +22,7 @@ override hdr:bool=false;
22
22
  let linear=planetSky(h.xyz/h.w-frame.eye.xyz);
23
23
  if(hdr){return vec4f(linear,1);}
24
24
  return vec4f(toDisplay(linear),1);
25
- }`, d = 0, f = class a {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
25
+ }`, d = 0, f = class a {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
26
26
  #e;
27
27
  #t;
28
28
  #n;
@@ -129,7 +129,7 @@ override hdr:bool=false;
129
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
130
  }, this.#d();
131
131
  }
132
- static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
132
+ static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
133
133
  let n = new a(t);
134
134
  return e.use(n), n;
135
135
  }
package/dist/planet.js CHANGED
@@ -1 +1 @@
1
- export { t as Planet } from "./planet-C2ewqAmf.js";
1
+ export { t as Planet } from "./planet-BYTix5S1.js";
package/dist/post.js CHANGED
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { r as e, t } from "./view-rect-TO68f_UR.js";
@@ -45,8 +45,8 @@ fn grainPcg(v:u32)->u32 {let s=v*747796405u+2891336453u;let w=((s>>((s>>28u)+4u)
45
45
  let sunWorld=f.eye.xyz+f.sun.xyz*f.settings.y;let ray=normalize(sunWorld-f.eye.xyz);let farRay=normalize(w-f.eye.xyz);let alignment=pow(max(dot(ray,farRay),0.0),16.0);var shafts=0.0;
46
46
  let sunClip=f.camera*vec4f(sunWorld,1);if(sunClip.w>0&&f.fog.z>0){let sunUV=sunClip.xy/sunClip.w*vec2f(0.5,-0.5)+0.5;for(var i=1;i<=16;i++){let q=clamp(vec2i(mix(uv,sunUV,f32(i)*0.05)*vec2f(size)),vec2i(0),size-1);shafts+=select(0.0,1.0,textureLoad(depth,origin+q,0)<0.000001)*pow(0.95,f32(i))/16.0;}}c+=vec3f(1,0.8,0.5)*shafts*alignment*f.fog.z;
47
47
  c=max(vec3f(0),c*exp2(f.grade.x)*f.gain.xyz+f.lift.xyz);let luminance=dot(c,vec3f(0.2126,0.7152,0.0722));c=mix(vec3f(luminance),c,f.grade.z);c=max(c,vec3f(0));if(f.grade.y==0.0){c=vec3f(0.18);}else if(f.grade.y!=1.0){c=0.18*pow(c/0.18,vec3f(f.grade.y));}
48
- c=toDisplay(c);let noise=f32(grainPcg(id.x+grainPcg(id.y+grainPcg(bitcast<u32>(f.lens.w))))>>8u)*5.9604645e-8-0.5;textureStore(output,p,vec4f(clamp(c+noise*f.lens.z,vec3f(0),vec3f(1)),1));}`, y = _ + "@group(0) @binding(0) var image:texture_2d<f32>;@fragment fn fragment(i:Out)->@location(0) vec4f{return textureLoad(image,clamp(vec2i(i.uv*vec2f(textureDimensions(image))),vec2i(0),vec2i(textureDimensions(image))-1),0);}", b = class i {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
49
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
48
+ c=toDisplay(c);let noise=f32(grainPcg(id.x+grainPcg(id.y+grainPcg(bitcast<u32>(f.lens.w))))>>8u)*5.9604645e-8-0.5;textureStore(output,p,vec4f(clamp(c+noise*f.lens.z,vec3f(0),vec3f(1)),1));}`, y = _ + "@group(0) @binding(0) var image:texture_2d<f32>;@fragment fn fragment(i:Out)->@location(0) vec4f{return textureLoad(image,clamp(vec2i(i.uv*vec2f(textureDimensions(image))),vec2i(0),vec2i(textureDimensions(image))-1),0);}", b = class i {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
49
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
50
50
  let n = new i(t);
51
51
  return e.use(n), n;
52
52
  }