@wildshard/sdk 0.2.13 → 0.3.1

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 (88) hide show
  1. package/GUIDE.md +26 -13
  2. package/bin/wildshard.mjs +2 -1
  3. package/docs/api/EXPORT-TIERS.md +16 -4
  4. package/lint/export-tiers.json +12 -0
  5. package/lint/host-callbacks.mjs +1 -1
  6. package/package.json +22 -6
  7. package/scripts/bake/template-skins.mjs +6 -3
  8. package/scripts/bake/template-warden.mjs +25 -0
  9. package/scripts/build-shardfiles.mjs +7 -2
  10. package/scripts/export-ci21-guests.mjs +89 -0
  11. package/scripts/prepare-product.mjs +2 -2
  12. package/scripts/scratch-sweep.mjs +182 -0
  13. package/scripts/wildshard.mjs +1 -1
  14. package/skills/wildshard-mockup-to-model/SKILL.md +5 -3
  15. package/skills/wildshard-upgrade/SKILL.md +4 -4
  16. package/src/cli/help.ts +9 -5
  17. package/src/cli/upload/validate.ts +7 -5
  18. package/src/sharddev/as/prelude.ts +67 -0
  19. package/src/sharddev/assets.ts +1 -1
  20. package/src/sharddev/authorLint.ts +45 -0
  21. package/src/sharddev/bake/compactGlb.ts +1 -1
  22. package/src/sharddev/bake/compileScript.ts +6 -0
  23. package/src/sharddev/bake/glbCompression.ts +1 -1
  24. package/src/sharddev/bake/gltfSource.ts +1 -1
  25. package/src/sharddev/bake/placeholders.ts +1 -1
  26. package/src/sharddev/bake/terrain.ts +12 -3
  27. package/src/sharddev/blobBytes.ts +1 -1
  28. package/src/sharddev/blobs.ts +2 -2
  29. package/src/sharddev/checkProject.ts +7 -18
  30. package/src/sharddev/cli.ts +17 -4
  31. package/src/sharddev/engineMusic.ts +23 -0
  32. package/src/sharddev/formatJsonSchema.ts +1 -1
  33. package/src/sharddev/materialGraphFiles.ts +1 -1
  34. package/src/sharddev/materials.ts +7 -3
  35. package/src/sharddev/newProject.ts +18 -10
  36. package/src/sharddev/outputProduct.ts +2 -2
  37. package/src/sharddev/productOutput.ts +2 -2
  38. package/src/sharddev/project.ts +6 -1
  39. package/src/sharddev/projectMap.ts +1 -1
  40. package/src/sharddev/refusals.ts +5 -3
  41. package/src/sharddev/reportCard.ts +1 -1
  42. package/src/sharddev/scene/author.ts +184 -0
  43. package/src/sharddev/scene/canvas.ts +212 -0
  44. package/src/sharddev/scene/description.ts +223 -0
  45. package/src/sharddev/scene/hash.ts +23 -0
  46. package/src/sharddev/scene/lower.ts +341 -0
  47. package/src/sharddev/scene/shard.ts +41 -0
  48. package/src/sharddev/scene/shardfile.ts +621 -0
  49. package/src/sharddev/threeGate.mjs +14 -0
  50. package/src/sharddev/threePin.mjs +40 -0
  51. package/src/sharddev/watch/page.ts +284 -0
  52. package/src/sharddev/watch/pageEntry.ts +59 -0
  53. package/src/sharddev/watch/parity-baseline.json +22 -0
  54. package/src/sharddev/watch/parity.mjs +168 -0
  55. package/src/sharddev/watch/proof.mjs +199 -0
  56. package/src/sharddev/watch/protocol.ts +166 -0
  57. package/src/sharddev/watch/socket.ts +57 -0
  58. package/src/sharddev/watch/watch.ts +373 -0
  59. package/src/shards/_template/assets/3058c100bc477fd6fe8268f33b53756b8a2556e7e41c58b2216c703ca7b042c6 +1 -0
  60. package/src/shards/_template/assets/8a0440f392737a31cf0926a3c7dc011c320144972882945a5462c893e817d94a +0 -0
  61. package/src/shards/_template/behaviour/door.as +16 -26
  62. package/src/shards/_template/card/landscape.jpg +0 -0
  63. package/src/shards/_template/card/portrait.jpg +0 -0
  64. package/src/shards/_template/card/thumb.jpg +0 -0
  65. package/src/shards/_template/data/clientScripts.json +43 -43
  66. package/src/shards/_template/data/creatures.json +2 -2
  67. package/src/shards/_template/data/look.json +141 -13
  68. package/src/shards/_template/data/rows.json +20 -2
  69. package/src/shards/_template/data/skins.json +32 -0
  70. package/src/shards/_template/data/water.json +18 -0
  71. package/src/shards/_template/generators/product.ts +5 -1
  72. package/src/shards/_template/generators/warden.ts +273 -0
  73. package/src/shards/_template/generators/world.ts +52 -21
  74. package/src/shards/_template/hero.json +6 -6
  75. package/src/shards/authoring-slice/generators/shard.ts +14 -0
  76. package/src/shards/authoring-slice/generators/sky.ts +64 -0
  77. package/src/shards/authoring-slice/generators/template-sky.ts +27 -0
  78. package/src/shards/authoring-slice/generators/textures.ts +232 -0
  79. package/src/shards/authoring-slice/generators/world.ts +518 -0
  80. package/src/shards/authoring-slice/shard.config.ts +7 -0
  81. package/src/shards/mossgate/generators/shard.ts +6 -0
  82. package/src/shards/mossgate/generators/sky.ts +64 -0
  83. package/src/shards/mossgate/generators/textures.ts +249 -0
  84. package/src/shards/mossgate/generators/world.ts +998 -0
  85. package/src/shards/mossgate/shard.config.ts +7 -0
  86. package/scripts/shard-output-report.d.mts +0 -9
  87. package/scripts/shard-output-report.mjs +0 -85
  88. package/scripts/shard-platform-cli.mjs +0 -93
@@ -128,10 +128,11 @@ export function buildTemplateWorld(ctx: TemplateWorldPorts, propCount: number):
128
128
  ctx.root.add(gate.vines); ctx.piece({ id: 'template.mossgate-vines', name: 'Moss gate vines', category: 'nature', file, object: gate.vines });
129
129
  ctx.root.add(gate.panel); ctx.piece({ id: 'template.mossgate', name: 'Moss gate', category: 'nature', file, object: gate.panel, colliders: gate.panelColliders, active: () => true });
130
130
  // Mossgate Hollow v3 (MH-3): brazier B's field raises the pond's stones out of the water, and brazier C's takes away the
131
- // bars across the arena's one way in. The sunken stones are static (no collider), so the raised panel covers them.
131
+ // bars across the arena's one way in. The sunk slabs are static and have no collider on purpose: before B the walk ends in
132
+ // the water (MG10's proof swims across), so B is what makes the crossing dry (the M4.10 review asked; this stays the design).
132
133
  const stones = pondStones();
133
134
  ctx.root.add(stones.raised); ctx.piece({ id: 'template.pond-stones', name: 'Pond stepping stones', category: 'nature', file, object: stones.raised, colliders: stones.colliders, active: () => false });
134
- ctx.root.add(stones.sunk); ctx.piece({ id: 'template.pond-stones-sunk', name: 'Sunken pond stones', category: 'nature', file, object: stones.sunk, surface: 'stone' });
135
+ ctx.root.add(stones.sunk); ctx.piece({ id: 'template.pond-stones-sunk', name: 'Sunken pond stones', category: 'nature', file, object: stones.sunk });
135
136
  const planting = pondPlanting(heightAt);
136
137
  ctx.root.add(planting); ctx.piece({ id: 'template.pond-planting', name: 'Pond reeds, lily pads and lip', category: 'nature', file, object: planting });
137
138
  const arena = arenaRing(heightAt);
@@ -444,7 +445,10 @@ export function hutLamp(heightAt: (x: number, z: number) => number): { mesh: Mes
444
445
  // M2: and the hut room's hanging lamp over the table, in the same whole (one draw)
445
446
  const room = new BoxGeometry(0.3, 0.38, 0.3).translate(layout.HUT.x + 0.8 - x, heightAt(layout.HUT.x, layout.HUT.z) + 2.15 - y, layout.HUT.z - 0.5 - z);
446
447
  const geometry = mergeGeometries([new BoxGeometry(0.36, 0.48, 0.36), room]).toNonIndexed(); geometry.deleteAttribute('uv');
447
- geometry.setAttribute('color', new Float32BufferAttribute(new Float32Array(geometry.getAttribute('position').count * 3).fill(1), 3));
448
+ // M4.10: warm glass, brightest low where the wick burns (the cleanroom's lamp glass gradient), dimmer under the lid
449
+ const p = geometry.getAttribute('position'), colour = new Float32Array(p.count * 3);
450
+ for (let i = 0; i < p.count; i++) { const k = p.getY(i) > 0.1 ? 0.62 : 1; colour.set([k, k * (0.9 + 0.1 * k), k * (0.8 + 0.2 * k)], i * 3); }
451
+ geometry.setAttribute('color', new Float32BufferAttribute(colour, 3));
448
452
  const mesh = new Mesh(geometry, new MeshStandardMaterial({ color: 0xffffff, vertexColors: true })); mesh.castShadow = false;
449
453
  return { mesh, transform: new Matrix4().makeTranslation(x, y, z) };
450
454
  }
@@ -460,11 +464,28 @@ export function brazierFlame(heightAt: (x: number, z: number) => number, which =
460
464
  if (which === 1) { const [bx = 0, bz = 0] = layout.ROW[0] ?? []; flameCones(flame, bx, heightAt(bx, bz) + 1.5, bz); }
461
465
  return flame;
462
466
  }
463
- /** Five faceted cones in a bowl whose rim is at y. */
464
- function flameCones(flame: Group, x: number, y: number, z: number): void {
465
- const cones: [number, number, number, number][] = [[0, 0, 0.42, 1.3], [0.24, 0.12, 0.24, 0.8], [-0.22, 0.16, 0.26, 0.9], [0.08, -0.25, 0.22, 0.75], [-0.14, -0.18, 0.2, 0.65]];
466
- cones.forEach(([dx, dz, r, h], i) => {
467
- const cone = new Mesh(foliageUv(new CylinderGeometry(0, r, h, 5), 1), foliageMaterial(0xffffff)); cone.position.set(x + dx, y + h / 2 - 0.05, z + dz); cone.rotation.y = jitter(i, 110) * 1.2; flame.add(cone);
467
+ /**
468
+ * M4.10 (the cleanroom's layered flame cards, MG textures.js and world.js:338): one flame tongue, a cone whose vertex
469
+ * colours run from `base` at its foot to `tip`, fading to dark at its point. The flame look entry is additive and reads the
470
+ * vertex colours, so a tongue fades out where it is dark and the tongues overlapping in the bowl add up to a hot core.
471
+ */
472
+ const FLAME_OUTER: readonly [readonly [number, number, number], readonly [number, number, number]] = [[1, 0.42, 0.07], [0.22, 0.03, 0]];
473
+ const FLAME_INNER: readonly [readonly [number, number, number], readonly [number, number, number]] = [[1, 0.78, 0.32], [0.45, 0.13, 0.01]];
474
+ function tongue(r: number, h: number, [base, tip]: typeof FLAME_OUTER): Mesh {
475
+ const geometry = foliageUv(new CylinderGeometry(0, r, h, 6, 1, true), 1), p = geometry.getAttribute('position'), colour = new Float32Array(p.count * 3);
476
+ for (let i = 0; i < p.count; i++) {
477
+ const t = Math.min(1, Math.max(0, p.getY(i) / h + 0.5)), k = t * t;
478
+ for (let c = 0; c < 3; c++) colour[i * 3 + c] = (base[c] ?? 0) * (1 - k) + (tip[c] ?? 0) * k;
479
+ }
480
+ geometry.setAttribute('color', new Float32BufferAttribute(colour, 3));
481
+ return new Mesh(geometry, foliageMaterial(0xffffff));
482
+ }
483
+ /** Five outer tongues and three inner ones in a bowl whose rim is at y (M4.10: was five opaque faceted cones). */
484
+ function flameCones(flame: Group, x: number, y: number, z: number, s = 1): void {
485
+ const outer: [number, number, number, number][] = [[0, 0, 0.42, 1.3], [0.24, 0.12, 0.24, 0.8], [-0.22, 0.16, 0.26, 0.9], [0.08, -0.25, 0.22, 0.75], [-0.14, -0.18, 0.2, 0.65]];
486
+ const inner: [number, number, number, number][] = [[0.02, 0.01, 0.24, 0.95], [0.12, -0.08, 0.15, 0.6], [-0.1, 0.07, 0.15, 0.55]];
487
+ for (const [layer, cones, seed] of [[FLAME_OUTER, outer, 110], [FLAME_INNER, inner, 112]] as const) cones.forEach(([dx, dz, r, h], i) => {
488
+ const cone = tongue(r * s, h * s, layer); cone.position.set(x + dx * s, y + (h * s) / 2 - 0.05, z + dz * s); cone.rotation.set(jitter(i, seed + 1) * 0.12, jitter(i, seed) * 1.2, jitter(i, seed + 2) * 0.12); flame.add(cone);
468
489
  });
469
490
  }
470
491
 
@@ -581,19 +602,26 @@ export function mossGate(heightAt: (x: number, z: number) => number): { frame: G
581
602
  }
582
603
 
583
604
  /**
584
- * The moss bridge (MH-3): five stone pillars across the pond at `layout.POND` (radius 5, bed −3, water at 0), west to east.
585
- * `raised` stands their moss-capped tops 0.1 m over the water, with colliders, for brazier B's field to show; `sunk` is the
586
- * same pillars, a little thinner and 1.4 m under, with no collider, so before B the walk ends in the water.
605
+ * The moss bridge (MH-3): six stone pillars across the pond at `layout.POND` (radius 5, bed −3, water at 0), west to east.
606
+ * `raised` stands their moss-capped tops 0.3 m over the water, with colliders, for brazier B's field to show; `sunk` is the
607
+ * same pillars, a little thinner, as wet slabs awash at the surface (M4.10, the cleanroom's look) with no collider, so before
608
+ * B the walk ends in the water.
587
609
  */
610
+ /** The raised bridge stones' top over the water, the sunk slabs' top, and their wet stone. */
611
+ const STONE_TOP = 0.3, SUNK_TOP = 0.05, WET_STONE = 0x5a524a;
588
612
  export function pondStones(): { raised: Group; sunk: Group; colliders: Colliders } {
589
613
  const { x: cx, z: cz } = layout.POND, raised = new Group(), sunk = new Group(), colliders: Colliders = [], BED = -3, w = 1.75;
590
614
  for (let i = 0; i < BRIDGE_STONES; i++) {
591
615
  const x = cx - BRIDGE_REACH + i * ((BRIDGE_REACH * 2) / (BRIDGE_STONES - 1)), z = cz + jitter(i, 80) * 0.12, yaw = jitter(i, 81) * 0.1;
592
- for (const [root, top, s] of [[raised, 0.1, w], [sunk, -1.4, w - 0.2]] as const) {
616
+ // M4.10: the sunk stones are the cleanroom's stepping slabs, a hand over the water (the mirror pond hides anything under
617
+ // it); the raised bridge stands a step (under the motor's 0.35 m autostep) above them once brazier B burns
618
+ for (const [root, top, s] of [[raised, STONE_TOP, w], [sunk, SUNK_TOP, w - 0.2]] as const) {
593
619
  const h = top - BED - 0.1;
594
- root.add(block(s, h, s, 1, x, BED + h / 2, z, yaw), block(s + 0.1, 0.1, s + 0.1, 2, x, top - 0.05, z, yaw));
620
+ // the slabs read as wet dark stone, as the cleanroom's sunk blocks do (not the bridge's moss caps)
621
+ const wet = root === sunk ? WET_STONE : undefined;
622
+ root.add(block(s, h, s, 1, x, BED + h / 2, z, yaw, 0, wet), block(s + 0.1, 0.1, s + 0.1, wet === undefined ? 2 : 1, x, top - 0.05, z, yaw, 0, wet));
595
623
  }
596
- colliders.push(stoneBox(x, (0.1 + BED) / 2, z, w / 2, (0.1 - BED) / 2, w / 2, yaw));
624
+ colliders.push(stoneBox(x, (STONE_TOP + BED) / 2, z, w / 2, (STONE_TOP - BED) / 2, w / 2, yaw));
597
625
  }
598
626
  return { raised, sunk, colliders };
599
627
  }
@@ -719,8 +747,12 @@ export function arenaRing(heightAt: (x: number, z: number) => number): { wall: G
719
747
  export const SLATE = 0x4f4d52, FLOOR_MOSS = 0x4e6a2a, ARENA_CELL = 1.5;
720
748
  /** LF1-9: the three braziers on the arena rim, as angles round `layout.ARENA` from the way in (across from it and either side). */
721
749
  export const RIM_BRAZIERS: readonly number[] = [Math.PI - 0.72, Math.PI, Math.PI + 0.72];
722
- /** M2: the Warden's core gem floats this high over its feet (the Warden is 3 times the blob, was 2.2). */
723
- export const WARDEN_CORE = 4.6;
750
+ /**
751
+ * The open-core gem's centre over the Warden's feet: just over its crown (warden.ts `WARDEN_CROWN`, 1.76 m at scale 1, so
752
+ * 5.27 m at the spawn's scale 3) by its own half height (0.76 m) and a 0.2 m gap. It was 4.6, inside the golem's head
753
+ * (M4.10 review); the panel is fixed, so over the crown it reads whichever way the Warden turns.
754
+ */
755
+ export const WARDEN_CORE = 6.2;
724
756
  /** LF1-9: the Warden's slam tell, a ring this far round `layout.BOSS` (MH-4's twelve anchors stood 3.5 m out). */
725
757
  export const TELL_RADIUS = 3.5;
726
758
  /** A rim brazier's centre, on the wall cap's top. */
@@ -764,12 +796,11 @@ export function rimFlames(heightAt: (x: number, z: number) => number): Group {
764
796
  const flames = new Group();
765
797
  RIM_BRAZIERS.forEach((_, k) => {
766
798
  const [x, y, z] = rimBrazier(heightAt, k);
767
- for (const [i, [dx, dz, rr, h]] of ([[0, 0, 0.34, 1.05], [0.18, 0.1, 0.2, 0.7], [-0.16, -0.12, 0.2, 0.62]] as const).entries()) {
768
- const cone = new Mesh(foliageUv(new CylinderGeometry(0, rr, h, 5), 1), foliageMaterial(0xffffff)); cone.position.set(x + dx, y + 0.94 + h / 2, z + dz); cone.rotation.y = jitter(k * 3 + i, 170) * 1.2; flames.add(cone);
769
- }
799
+ flameCones(flames, x, y + 0.99, z, 0.8);
770
800
  });
771
- // M2: brazier C's field also lights the row's C beacon at the back of the yard
772
- const [bx = 0, bz = 0] = layout.ROW[1] ?? []; flameCones(flames, bx, heightAt(bx, bz) + 1.5, bz);
801
+ // M2: brazier C's field also lights the row's C beacon at the back of the yard; M4.10: and brazier C's own bowl
802
+ const [bx = 0, bz = 0] = layout.ROW[1] ?? [], [cx = 0, cz = 0] = layout.BRAZIERS[2] ?? [];
803
+ flameCones(flames, bx, heightAt(bx, bz) + 1.5, bz); flameCones(flames, cx, heightAt(cx, cz) + 1.5, cz);
773
804
  return flames;
774
805
  }
775
806
  /**
@@ -1,10 +1,10 @@
1
1
  {
2
- "content": "da9e8f46215b485b582901179bf5823a2234362f6606c13e471412292d60e5f3",
3
- "captured": "2026-11-14T01:06:36.105Z",
4
- "base": "http://127.0.0.1:4473",
2
+ "content": "a3f16dec276836f29a0164f9f37dae5f29eab523307beffee71133e3541f33aa",
3
+ "captured": "2026-11-15T19:17:50.686Z",
4
+ "base": "http://127.0.0.1:4878",
5
5
  "card": {
6
- "card/thumb.jpg": "17bd4bb0ea1da525b384cd64d855a819185c7621155870c4b59d1f9b1400bab5",
7
- "card/portrait.jpg": "fda8c38ef932b68653395ad6be1e463a42f5fbb87d10b2c2d587c2328ad339d4",
8
- "card/landscape.jpg": "019a8a89659ce3620b838b7c564d4c25c5584f9d0175a21697b3084089834276"
6
+ "card/thumb.jpg": "3ab250eab85cafffd077e67aa24a7c3608a043ff1b64baeb2714c9eb3d6c04d7",
7
+ "card/portrait.jpg": "2f3574e0e9e5f20360cffa9529a7246afdd3fe1d3a792ee9d80271332002214b",
8
+ "card/landscape.jpg": "45bb2d038f2a00a9d7f904303e3d59354854f5a77acd5ea21fa54a4469663841"
9
9
  }
10
10
  }
@@ -0,0 +1,14 @@
1
+ // AUTHORING-PARITY AP7: the slice is one scene module. `wildshard build` runs this as the shard's generator (the
2
+ // shardfile back end); `wildshard watch` calls its describe() and streams the parts to a running page.
3
+ import { defineShard } from '@wildshard/sdk/scene/shard';
4
+ import { buildSlice } from './world';
5
+
6
+ /** SHARD-SOURCE AP19: one quest, so a gameplay edit has something to show (`proof.mjs --edit quest` rewrites its objective). */
7
+ export const SLICE_QUESTS = {
8
+ flags: ['slice.pond', 'slice.walk'], triggers: [{ id: 'slice.pond', kind: 'region' as const, flag: 'slice.pond', x: -10.4, z: 0.3, radius: 4 }], dialogue: [],
9
+ quests: [{ id: 'slice.walk', title: 'A walk to the pond', completeFlag: 'slice.walk',
10
+ steps: [{ id: 'pond', objective: 'Walk down to the pond', done: { all: ['slice.pond'] } }] }],
11
+ };
12
+
13
+ export const slice = defineShard({ slug: 'authoring-slice', name: 'Authoring Slice', author: 'Wildshard', revision: 1, seed: 357 }, buildSlice,
14
+ { extend: (shard) => ({ ...shard, quests: SLICE_QUESTS }) });
@@ -0,0 +1,64 @@
1
+ // The cleanroom's sunset sky dome (mossgate-cleanroom src/sky.js `makeSky`, 9cb4dc6) in TSL, line for line (SHARD-SOURCE
2
+ // AP14): periwinkle zenith, mauve, rose, a wide peach horizon glow, the low sun, small puffy clouds lit coral from below
3
+ // and a few stars. `world.sky(...)` compiles it to the dome's graph; the same value noise as the cleanroom's GLSL, so the
4
+ // clouds sit where the cleanroom's do. The detail and underside noise drop their finest octaves (weights 0.012 and 0.03 of
5
+ // the cloud shape) to fit the sky's budget (format look-sky, 1,024 instructions). Its `dusk` is 0 (the slice is the golden hour), so the night mix drops out.
6
+ import * as THREE from 'three';
7
+ import { dot, floor, fract, max, mix, normalize, pow, sin, smoothstep, step, vec2, vec3 } from 'three/tsl';
8
+ import { skyRay } from '@wildshard/sdk/scene/author';
9
+ import type { GraphValue } from '@wildshard/sdk/materials';
10
+
11
+ type V = ReturnType<typeof vec3>;
12
+ type F = ReturnType<typeof dot>;
13
+ type P = ReturnType<typeof vec2>;
14
+
15
+ /** The cleanroom's SKY colours (linear, as its uniforms hold them). */
16
+ const SKY = { zenith: '#2c3282', upper: '#5652a2', mid: '#b06ea2', low: '#f88c80', horizon: '#ffb878', sun: '#ffe6b0' };
17
+ const lin = (hex: string): V => { const c = new THREE.Color(hex); return vec3(c.r, c.g, c.b); };
18
+ /** Where the sun sits: just over the skyline behind the hut (cleanroom main.js `sunVisible`). */
19
+ export const SUN_DIRECTION = new THREE.Vector3(0.32, 0.035, -1).normalize();
20
+
21
+ const hash = (p: P): F => fract(sin(dot(p, vec2(127.1, 311.7))).mul(43758.5453));
22
+ function noise(p: P): F {
23
+ const i = floor(p), f = fract(p), u = f.mul(f).mul(f.mul(-2).add(3));
24
+ return mix(mix(hash(i), hash(i.add(vec2(1, 0))), u.x), mix(hash(i.add(vec2(0, 1))), hash(i.add(vec2(1, 1))), u.x), u.y);
25
+ }
26
+ /** The cleanroom's five-octave fbm; `octaves` below 5 drops the finest (each is half the weight of the one before). */
27
+ function fbm(start: P, octaves = 5): F {
28
+ let sum: F = noise(start).mul(0.5), p = start, a = 0.5;
29
+ for (let octave = 1; octave < octaves; octave++) { p = p.mul(2.07).add(13.1); a *= 0.5; sum = sum.add(noise(p).mul(a)); }
30
+ return sum;
31
+ }
32
+
33
+ /** The sky colour along the view ray. */
34
+ export function sunsetSky(): GraphValue {
35
+ const d = skyRay, h = d.y, e = max(h, 0);
36
+ const sun = vec3(SUN_DIRECTION.x, SUN_DIRECTION.y, SUN_DIRECTION.z);
37
+ // the glow toward the sun's side is wider and warmer
38
+ const sd = max(dot(d, sun), 0);
39
+ const az = pow(max(dot(normalize(d.xz.add(1e-4)), normalize(vec2(SUN_DIRECTION.x, SUN_DIRECTION.z))), 0), 2);
40
+ const lift = az.mul(0.06).add(0.06); // the peach band climbs higher on the sun side
41
+ let col: V = lin(SKY.horizon);
42
+ col = mix(col, lin(SKY.low), smoothstep(lift.sub(0.02), lift.add(0.1), e));
43
+ col = mix(col, lin(SKY.mid), smoothstep(lift.add(0.06), 0.26, e));
44
+ col = mix(col, lin(SKY.upper), smoothstep(0.22, 0.42, e));
45
+ col = mix(col, lin(SKY.zenith), smoothstep(0.4, 0.75, e));
46
+ col = mix(col, lin(SKY.horizon).mul(0.92), smoothstep(0, -0.08, h)); // under the skyline: haze
47
+ // sun: wide warm wash, halo, disc sitting on the horizon
48
+ col = col.add(vec3(1, 0.62, 0.36).mul(pow(sd, 6).mul(0.4).mul(smoothstep(0, 0.4, e).oneMinus())));
49
+ col = col.add(lin(SKY.sun).mul(pow(sd, 120).mul(0.35)));
50
+ col = col.add(vec3(1, 0.85, 0.6).mul(smoothstep(0.99935, 0.9997, sd).mul(0.9)));
51
+ // puffy clouds: a plane projection, small cumulus clumps in a band
52
+ const cp = d.xz.div(max(h.add(0.08), 0.04)).mul(1.6);
53
+ const band = smoothstep(0.04, 0.1, h).mul(smoothstep(0.3, 0.5, h).oneMinus());
54
+ const shape = fbm(cp.mul(0.55).add(4)).mul(0.75).add(fbm(cp.mul(2.4).add(9), 4).mul(0.38));
55
+ const cloud = smoothstep(0.57, 0.68, shape).mul(band);
56
+ const underside = smoothstep(0.2, 0.75, fbm(cp.mul(2.4).add(vec2(0, 0.6)).add(9), 3)); // lit from below
57
+ const lit = mix(vec3(1, 0.46, 0.46), vec3(1, 0.56, 0.32), pow(sd, 2)).mul(0.86);
58
+ const shade = mix(lin(SKY.mid), lin(SKY.upper), 0.45).mul(0.95);
59
+ const cloudCol = mix(lit, shade, underside.mul(0.35)).mul(mix(1, 0.72, smoothstep(0.14, 0.45, e))); // high clouds sit in shade
60
+ col = mix(col, cloudCol, cloud.mul(0.92));
61
+ // stars, faint at the golden hour (dusk 0)
62
+ const st = step(0.9965, hash(floor(d.xz.div(max(h, 0.15)).mul(260)))).mul(smoothstep(0.35, 0.8, e));
63
+ return col.add(vec3(st, st, st).mul(0.15)).mul(0.95);
64
+ }
@@ -0,0 +1,27 @@
1
+ import { dot, max, mix, screenUV, smoothstep, vec3 } from 'three/tsl';
2
+ import { graph, graphInputs, noise, sceneDepth } from '@wildshard/sdk/materials';
3
+ import type { GraphIr } from '@wildshard/format/materialGraph';
4
+
5
+ // The Template's sky post pass, kept here so the Template's own hero stamp stays true (data/look.json post[0], 77 graph nodes) as TSL (SHARD-SOURCE AP13): a five-band dusk,
6
+ // a sun glow, halo and disc, three octaves of cloud, the vignette. `graph()` compiles it to the same graph.
7
+ export function templateSky(): GraphIr {
8
+ const { sceneColour, viewRay } = graphInputs;
9
+ const rgb = sceneColour.xyz.toVar('rgb'), sky = smoothstep(400, 480, sceneDepth().toVar('depth')).toVar('sky');
10
+ const ray = viewRay.toVar('ray'), h = ray.y.toVar('h'), e = max(h, 0).toVar('e');
11
+ const sd = max(dot(ray, vec3(0.30461, 0.03332, -0.9519)), 0).toVar('sd');
12
+ const band = (from: ReturnType<typeof mix>, to: [number, number, number], a: number, b: number): ReturnType<typeof mix> => mix(from, vec3(...to), smoothstep(a, b, e));
13
+ const bands = band(band(band(mix(vec3(1, 0.4793, 0.1878), vec3(0.9387, 0.2623, 0.2159), smoothstep(0.07, 0.19, e)),
14
+ [0.4342, 0.1559, 0.3613], 0.15, 0.26), [0.0931, 0.0844, 0.3613], 0.22, 0.42), [0.0252, 0.0319, 0.2232], 0.4, 0.75);
15
+ const glow = vec3(1, 0.62, 0.36).mul(sd.pow(6).mul(0.4).mul(smoothstep(0, 0.4, e).oneMinus()));
16
+ const halo = vec3(1, 0.7913, 0.4342).mul(sd.pow(120).mul(0.35));
17
+ const disc = vec3(1, 0.85, 0.6).mul(smoothstep(0.99935, 0.9997, sd).mul(0.9));
18
+ const p = ray.xz.div(max(h.add(0.08), 0.04)).mul(1.6);
19
+ const n3 = noise(p.mul(2.4).add(9));
20
+ const octaves = noise(p.mul(0.55).add(4)).mul(0.6).add(noise(p.mul(1.15).add(17)).mul(0.3)).add(n3.mul(0.22));
21
+ const cloud = smoothstep(0.1, 0.24, octaves).mul(smoothstep(0.04, 0.1, h).mul(smoothstep(0.3, 0.5, h).oneMinus())).toVar('cloud');
22
+ const lit = mix(mix(vec3(1, 0.46, 0.46), vec3(1, 0.56, 0.32), sd.mul(sd)).mul(0.86), vec3(0.2667, 0.1175, 0.3432), smoothstep(-0.2, 0.4, n3).mul(0.35));
23
+ const skyCol = mix(bands.add(glow).add(halo).add(disc), lit.mul(mix(1, 0.72, smoothstep(0.14, 0.45, e))), cloud.mul(0.92)).mul(0.95).toVar('skyCol');
24
+ const vd = screenUV.toVar('uv').sub(0.5).toVar('vd');
25
+ const vig = smoothstep(0.2, 0.75, dot(vd, vd).toVar('vr')).mul(0.22).oneMinus().toVar('vig');
26
+ return graph({ kind: 'post', post: { colour: mix(rgb, skyCol, sky).toVar('scene').mul(vig).toVar('out') } });
27
+ }
@@ -0,0 +1,232 @@
1
+ // Procedural textures, ported from the Mossgate cleanroom (mossgate-cleanroom eac5bb8 src/textures.js). The painters are the
2
+ // cleanroom's own lines; only `canvas()` / `new CanvasTexture(c)` became `paint` / `paintCanvas`, which run at compile time.
3
+ import type { DataTexture } from 'three';
4
+ import { paint } from '@wildshard/sdk/scene/author';
5
+ import { paintCanvas, type PaintContext } from '@wildshard/sdk/scene/canvas';
6
+
7
+ export function rng(seed = 1): () => number {
8
+ let s = seed >>> 0;
9
+ return () => {
10
+ s = (s + 0x6d2b79f5) >>> 0;
11
+ let t = s;
12
+ t = Math.imul(t ^ (t >>> 15), t | 1);
13
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
14
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
15
+ };
16
+ }
17
+
18
+ export interface Noise { (x: number, y: number): number; fbm: (x: number, y: number, oct?: number) => number }
19
+ // Smooth value noise, 2D, tileable over `period`.
20
+ export function makeNoise(seed = 7): Noise {
21
+ const r = rng(seed);
22
+ const N = 256;
23
+ const g = new Float32Array(N * N);
24
+ for (let i = 0; i < g.length; i++) g[i] = r();
25
+ const at = (x: number, y: number): number => g[((y & (N - 1)) * N) + (x & (N - 1))] ?? 0;
26
+ const sm = (t: number): number => t * t * (3 - 2 * t);
27
+ const n = (x: number, y: number): number => {
28
+ const xi = Math.floor(x), yi = Math.floor(y);
29
+ const xf = sm(x - xi), yf = sm(y - yi);
30
+ const a = at(xi, yi), b = at(xi + 1, yi), c = at(xi, yi + 1), d = at(xi + 1, yi + 1);
31
+ return a + (b - a) * xf + (c - a) * yf + (a - b - c + d) * xf * yf;
32
+ };
33
+ const fbm = (x: number, y: number, oct = 4): number => {
34
+ let s = 0, amp = 0.5, f = 1;
35
+ for (let i = 0; i < oct; i++) { s += amp * n(x * f, y * f); amp *= 0.5; f *= 2; }
36
+ return s;
37
+ };
38
+ return Object.assign(n, { fbm });
39
+ }
40
+
41
+ type Rgb = [number, number, number];
42
+ const mix = (a: number, b: number, t: number): number => a + (b - a) * t;
43
+ const mix3 = (a: readonly number[], b: readonly number[], t: number): Rgb => [mix(a[0] ?? 0, b[0] ?? 0, t), mix(a[1] ?? 0, b[1] ?? 0, t), mix(a[2] ?? 0, b[2] ?? 0, t)];
44
+ const clamp = (v: number, lo = 0, hi = 1): number => Math.max(lo, Math.min(hi, v));
45
+
46
+ // Weathered warm-grey stone with moss blotches and edge darkening.
47
+ export function stone(seed = 3, { moss = 0.35 } = {}): DataTexture {
48
+ const n = makeNoise(seed);
49
+ const S = 512;
50
+ const g1 = [106, 102, 94], g2 = [150, 145, 134], mossC = [84, 104, 38];
51
+ return paint(S, S, (u, v) => {
52
+ const a = n.fbm(u * 8, v * 8, 5);
53
+ const sp = n(u * 120, v * 120);
54
+ let col = mix3(g1, g2, clamp(a * 1.6 - 0.3));
55
+ col = col.map((x) => x * (0.85 + sp * 0.25)) as Rgb;
56
+ // cracks
57
+ const cr = Math.abs(n.fbm(u * 6 + 5, v * 6 + 2, 3) - 0.5);
58
+ if (cr < 0.012) col = col.map((x) => x * 0.6) as Rgb;
59
+ // moss: favours the top of a face (v small)
60
+ const m = n.fbm(u * 10 + 3, v * 10 + 7, 4) + (1 - v) * 0.25 * moss * 2;
61
+ const t = clamp((m - (1 - moss)) * 6);
62
+ col = mix3(col, mossC.map((x) => x * (0.8 + sp * 0.4)), t);
63
+ // edge darkening for bevel read
64
+ const e = Math.min(u, v, 1 - u, 1 - v);
65
+ const ed = clamp(e * 18, 0.7, 1);
66
+ return col.map((x) => x * ed);
67
+ });
68
+ }
69
+
70
+ // Flat slab stone for the path: lighter, pink-grey, no moss on top.
71
+ export function slab(): DataTexture {
72
+ const n = makeNoise(21);
73
+ const S = 256;
74
+ return paint(S, S, (u, v) => {
75
+ const a = n.fbm(u * 6, v * 6, 4);
76
+ const sp = n(u * 90, v * 90);
77
+ const col = mix3([126, 120, 110], [164, 156, 142], clamp(a * 1.5 - 0.2));
78
+ const e = Math.min(u, v, 1 - u, 1 - v);
79
+ const ed = clamp(e * 14, 0.72, 1);
80
+ return col.map((x) => x * (0.88 + sp * 0.2) * ed);
81
+ });
82
+ }
83
+
84
+ export function wood(): DataTexture {
85
+ const n = makeNoise(5);
86
+ const S = 256;
87
+ return paint(S, S, (u, v) => {
88
+ const grain = n(u * 4, v * 60) * 0.6 + n(u * 2, v * 140) * 0.4;
89
+ return mix3([84, 58, 38], [138, 98, 62], grain);
90
+ });
91
+ }
92
+
93
+ export function shingle(): DataTexture {
94
+ const n = makeNoise(9);
95
+ const S = 256;
96
+ return paint(S, S, (u, v) => {
97
+ const a = n.fbm(u * 8, v * 8, 4);
98
+ const sp = n(u * 100, v * 100);
99
+ let col = mix3([104, 96, 78], [128, 120, 96], a);
100
+ col = mix3(col, [112, 130, 50], clamp((n.fbm(u * 5 + 3, v * 5, 3) - 0.5) * 3));
101
+ return col.map((x) => x * (0.85 + sp * 0.3));
102
+ });
103
+ }
104
+
105
+ // Painted floor/wall stencil ("A", "3x3"), white on transparent.
106
+ export function stencil(text: string, { w = 256, h = 128, font = 'bold 96px monospace', alpha = 0.75 } = {}): DataTexture {
107
+ return paintCanvas(w, h, (ctx) => {
108
+ ctx.clearRect(0, 0, w, h);
109
+ ctx.fillStyle = `rgba(235,228,214,${alpha})`;
110
+ ctx.font = font;
111
+ ctx.textAlign = 'center';
112
+ ctx.textBaseline = 'middle';
113
+ ctx.fillText(text, w / 2, h / 2 + 4);
114
+ // scuff it
115
+ const r = rng(text.length * 31);
116
+ ctx.globalCompositeOperation = 'destination-out';
117
+ for (let i = 0; i < 260; i++) {
118
+ ctx.fillStyle = `rgba(0,0,0,${r() * 0.6})`;
119
+ ctx.fillRect(r() * w, r() * h, 1 + r() * 4, 1 + r() * 3);
120
+ }
121
+ });
122
+ }
123
+
124
+ // Soft round glow sprite.
125
+ export function glow(): DataTexture {
126
+ return paintCanvas(128, 128, (ctx) => {
127
+ const g = ctx.createRadialGradient(64, 64, 0, 64, 64, 64);
128
+ g.addColorStop(0, 'rgba(255,240,200,1)');
129
+ g.addColorStop(0.25, 'rgba(255,190,90,0.6)');
130
+ g.addColorStop(1, 'rgba(255,140,40,0)');
131
+ ctx.fillStyle = g;
132
+ ctx.fillRect(0, 0, 128, 128);
133
+ });
134
+ }
135
+
136
+ // Ivy strand: a wavy stem with heart-shaped leaves, top to bottom.
137
+ export function ivy(): DataTexture {
138
+ return paintCanvas(128, 512, (ctx: PaintContext) => {
139
+ ctx.clearRect(0, 0, 128, 512);
140
+ const r = rng(13);
141
+ ctx.strokeStyle = '#4a5a22'; ctx.lineWidth = 3;
142
+ ctx.beginPath(); ctx.moveTo(64, 0);
143
+ for (let y = 0; y <= 512; y += 16) ctx.lineTo(64 + Math.sin(y / 40) * 14, y);
144
+ ctx.stroke();
145
+ for (let y = 8; y < 500; y += 13) {
146
+ const x = 64 + Math.sin(y / 40) * 14, s = r() < 0.5 ? -1 : 1, sz = 10 + r() * 9 - y / 120;
147
+ const l = 0.7 + r() * 0.4;
148
+ ctx.fillStyle = `rgb(${Math.round(92 * l)},${Math.round(128 * l)},${Math.round(40 * l)})`;
149
+ ctx.save(); ctx.translate(x + s * sz * 0.8, y); ctx.rotate(s * (0.4 + r() * 0.6));
150
+ ctx.beginPath(); ctx.moveTo(0, -sz * 0.2);
151
+ ctx.bezierCurveTo(sz, -sz, sz * 1.1, sz * 0.4, 0, sz); ctx.bezierCurveTo(-sz * 1.1, sz * 0.4, -sz, -sz, 0, -sz * 0.2);
152
+ ctx.fill(); ctx.restore();
153
+ }
154
+ });
155
+ }
156
+
157
+ // Hanging moss: shaggy strands, dense at the top, thinning to wisps.
158
+ export function hangingMoss(): DataTexture {
159
+ return paintCanvas(256, 256, (ctx) => {
160
+ ctx.clearRect(0, 0, 256, 256);
161
+ const r = rng(29);
162
+ for (let i = 0; i < 90; i++) {
163
+ const x = r() * 256, len = 40 + r() * 200 * r(), w = 3 + r() * 6;
164
+ const l = 0.75 + r() * 0.35;
165
+ const g = ctx.createLinearGradient(0, 0, 0, len);
166
+ g.addColorStop(0, `rgba(${Math.round(98 * l)},${Math.round(118 * l)},${Math.round(40 * l)},1)`);
167
+ g.addColorStop(1, `rgba(${Math.round(130 * l)},${Math.round(142 * l)},${Math.round(60 * l)},0)`);
168
+ ctx.fillStyle = g;
169
+ ctx.beginPath(); ctx.moveTo(x - w, 0); ctx.quadraticCurveTo(x + (r() - 0.5) * 10, len * 0.6, x + (r() - 0.5) * 8, len); ctx.lineTo(x + w, 0); ctx.fill();
170
+ }
171
+ ctx.fillStyle = 'rgb(84,104,36)'; ctx.fillRect(0, 0, 256, 10);
172
+ });
173
+ }
174
+
175
+ // Fern frond: a tapered stem with paired leaflets, root at the bottom.
176
+ export function frond(): DataTexture {
177
+ return paintCanvas(128, 512, (ctx) => {
178
+ ctx.clearRect(0, 0, 128, 512);
179
+ const grad = ctx.createLinearGradient(0, 512, 0, 0);
180
+ grad.addColorStop(0, '#3e5a1c');
181
+ grad.addColorStop(1, '#8fae3c');
182
+ ctx.fillStyle = grad;
183
+ ctx.strokeStyle = grad;
184
+ ctx.lineWidth = 4;
185
+ ctx.beginPath(); ctx.moveTo(64, 512); ctx.lineTo(64, 10); ctx.stroke();
186
+ for (let y = 40; y < 500; y += 16) {
187
+ const len = 54 * Math.sin(((y - 20) / 490) * Math.PI) + 4;
188
+ for (const s of [-1, 1]) {
189
+ ctx.beginPath();
190
+ ctx.ellipse(64 + s * len * 0.5, y - 6, len * 0.5, 6, s * -0.35, 0, Math.PI * 2);
191
+ ctx.fill();
192
+ }
193
+ }
194
+ });
195
+ }
196
+
197
+ // Grass blade card: a fan of tapered blades.
198
+ export function grassCard(): DataTexture {
199
+ return paintCanvas(128, 128, (ctx) => {
200
+ ctx.clearRect(0, 0, 128, 128);
201
+ const r = rng(4);
202
+ for (let i = 0; i < 14; i++) {
203
+ const x = 20 + r() * 88, h = 60 + r() * 64, lean = (r() - 0.5) * 40;
204
+ const g = ctx.createLinearGradient(0, 128, 0, 128 - h);
205
+ g.addColorStop(0, '#6a8a2e'); g.addColorStop(1, r() < 0.3 ? '#c6cc6a' : '#a4c04c');
206
+ ctx.fillStyle = g;
207
+ ctx.beginPath(); ctx.moveTo(x - 3, 128); ctx.quadraticCurveTo(x + lean * 0.4, 128 - h * 0.6, x + lean, 128 - h); ctx.lineTo(x + 3, 128); ctx.fill();
208
+ }
209
+ });
210
+ }
211
+
212
+ // Flame sprite: five pointed tongues in three layers, red-orange outside, orange, then a yellow-white core.
213
+ export function flameSprite(): DataTexture {
214
+ return paintCanvas(128, 256, (ctx) => {
215
+ ctx.clearRect(0, 0, 128, 256);
216
+ const tongue = (cx: number, top: number, w: number, col: string): void => {
217
+ ctx.fillStyle = col;
218
+ ctx.beginPath(); ctx.moveTo(cx - w, 236);
219
+ ctx.bezierCurveTo(cx - w * 1.1, 170, cx - w * 0.2, 120, cx + w * 0.15, top);
220
+ ctx.bezierCurveTo(cx + w * 0.5, 120, cx + w * 1.2, 170, cx + w, 236);
221
+ ctx.closePath(); ctx.fill();
222
+ };
223
+ const base = (r: number, col: string): void => { ctx.fillStyle = col; ctx.beginPath(); ctx.ellipse(64, 222, r, r * 0.5, 0, 0, Math.PI * 2); ctx.fill(); };
224
+ base(46, 'rgba(232,74,22,0.95)');
225
+ for (const [x, t, w] of [[38, 92, 24], [58, 18, 30], [82, 60, 26], [100, 120, 18], [24, 140, 16]] as const) tongue(x, t, w, 'rgba(232,74,22,0.95)');
226
+ base(36, 'rgba(255,140,30,1)');
227
+ for (const [x, t, w] of [[44, 110, 18], [62, 50, 22], [80, 96, 18]] as const) tongue(x, t, w, 'rgba(255,140,30,1)');
228
+ base(24, 'rgba(255,214,90,1)');
229
+ for (const [x, t, w] of [[56, 120, 13], [70, 104, 13]] as const) tongue(x, t, w, 'rgba(255,214,90,1)');
230
+ base(12, 'rgba(255,248,214,1)');
231
+ });
232
+ }