@kerf-js/keel 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +306 -2
  3. package/package.json +59 -3
  4. package/src/blend-inset.ts +79 -0
  5. package/src/blend.ts +120 -0
  6. package/src/client.d.ts +9 -0
  7. package/src/generate/bust.ts +24 -0
  8. package/src/generate/bust.worker.ts +4 -0
  9. package/src/generate/pack.ts +69 -0
  10. package/src/generate/plate.ts +51 -0
  11. package/src/generate/plate.worker.ts +4 -0
  12. package/src/generate/serve.ts +56 -0
  13. package/src/generate/surface.ts +16 -0
  14. package/src/generate/surface.worker.ts +4 -0
  15. package/src/generate.ts +133 -0
  16. package/src/governor.ts +87 -0
  17. package/src/index.d.ts +15 -0
  18. package/src/index.mjs +63 -0
  19. package/src/lit.d.ts +384 -0
  20. package/src/paint-live.ts +60 -0
  21. package/src/paint-recipe.d.mts +29 -0
  22. package/src/paint-recipe.mjs +29 -0
  23. package/src/paint-worker.mjs +20 -0
  24. package/src/paint.d.mts +37 -0
  25. package/src/paint.mjs +180 -0
  26. package/src/runtime.ts +35 -0
  27. package/src/scene.ts +289 -0
  28. package/src/stage.ts +192 -0
  29. package/vendor/LICENSE +21 -0
  30. package/vendor/LICENSE-modules +21 -0
  31. package/vendor/NOTICE +24 -0
  32. package/vendor/README.md +13 -0
  33. package/vendor/lit.d.mts +1 -0
  34. package/vendor/lit.mjs +2 -0
  35. package/vendor/lock.json +177 -0
  36. package/vendor/modules/band/events.d.ts +20 -0
  37. package/vendor/modules/band/index.d.ts +29 -0
  38. package/vendor/modules/band/player.d.ts +43 -0
  39. package/vendor/modules/band/roll.d.ts +14 -0
  40. package/vendor/modules/band/score.d.ts +45 -0
  41. package/vendor/modules/band/styles.data.d.ts +37 -0
  42. package/vendor/modules/band/voices.d.ts +33 -0
  43. package/vendor/modules/band.d.mts +1 -0
  44. package/vendor/modules/band.mjs +2 -0
  45. package/vendor/modules/butterflies/butterflies.glsl.d.ts +2 -0
  46. package/vendor/modules/butterflies/flight.d.ts +68 -0
  47. package/vendor/modules/butterflies/index.d.ts +79 -0
  48. package/vendor/modules/butterflies/wing.d.ts +38 -0
  49. package/vendor/modules/butterflies.d.mts +1 -0
  50. package/vendor/modules/butterflies.inputs.json +73 -0
  51. package/vendor/modules/butterflies.mjs +39 -0
  52. package/vendor/modules/camera-rail/index.d.ts +113 -0
  53. package/vendor/modules/camera-rail.d.mts +1 -0
  54. package/vendor/modules/camera-rail.mjs +2 -0
  55. package/vendor/modules/device-profile/index.d.ts +47 -0
  56. package/vendor/modules/device-profile.d.mts +1 -0
  57. package/vendor/modules/device-profile.mjs +2 -0
  58. package/vendor/modules/lit-finish/dress.d.ts +34 -0
  59. package/vendor/modules/lit-finish/finish.glsl.d.ts +15 -0
  60. package/vendor/modules/lit-finish/index.d.ts +33 -0
  61. package/vendor/modules/lit-finish/lit.d.ts +52 -0
  62. package/vendor/modules/lit-finish/pass.d.ts +35 -0
  63. package/vendor/modules/lit-finish/settings.d.ts +88 -0
  64. package/vendor/modules/lit-finish.d.mts +1 -0
  65. package/vendor/modules/lit-finish.inputs.json +200 -0
  66. package/vendor/modules/lit-finish.mjs +267 -0
  67. package/vendor/modules/look/index.d.ts +159 -0
  68. package/vendor/modules/look.d.mts +1 -0
  69. package/vendor/modules/look.inputs.json +23 -0
  70. package/vendor/modules/look.mjs +2 -0
  71. package/vendor/modules/motes/index.d.ts +83 -0
  72. package/vendor/modules/motes/motes.glsl.d.ts +9 -0
  73. package/vendor/modules/motes/place.d.ts +59 -0
  74. package/vendor/modules/motes.d.mts +1 -0
  75. package/vendor/modules/motes.inputs.json +116 -0
  76. package/vendor/modules/motes.mjs +68 -0
  77. package/vendor/modules/plate-painter/dab.d.ts +44 -0
  78. package/vendor/modules/plate-painter/exact.d.ts +19 -0
  79. package/vendor/modules/plate-painter/foliage.d.ts +4 -0
  80. package/vendor/modules/plate-painter/gpu.d.ts +65 -0
  81. package/vendor/modules/plate-painter/index.d.ts +14 -0
  82. package/vendor/modules/plate-painter/paint.glsl.d.ts +14 -0
  83. package/vendor/modules/plate-painter/plan.d.ts +42 -0
  84. package/vendor/modules/plate-painter/recipe.d.ts +136 -0
  85. package/vendor/modules/plate-painter/scene.d.ts +4 -0
  86. package/vendor/modules/plate-painter.d.mts +1 -0
  87. package/vendor/modules/plate-painter.inputs.json +50 -0
  88. package/vendor/modules/plate-painter.mjs +384 -0
  89. package/vendor/modules/portrait/body.d.ts +25 -0
  90. package/vendor/modules/portrait/bust.d.ts +67 -0
  91. package/vendor/modules/portrait/cap.d.ts +12 -0
  92. package/vendor/modules/portrait/compile.d.ts +8 -0
  93. package/vendor/modules/portrait/exact.d.ts +17 -0
  94. package/vendor/modules/portrait/hair.d.ts +26 -0
  95. package/vendor/modules/portrait/hand.d.ts +30 -0
  96. package/vendor/modules/portrait/head.d.ts +18 -0
  97. package/vendor/modules/portrait/index.d.ts +12 -0
  98. package/vendor/modules/portrait/mesh.d.ts +24 -0
  99. package/vendor/modules/portrait/parts.d.ts +33 -0
  100. package/vendor/modules/portrait/portrait.glsl.d.ts +4 -0
  101. package/vendor/modules/portrait/render.d.ts +125 -0
  102. package/vendor/modules/portrait/sdf.d.ts +75 -0
  103. package/vendor/modules/portrait/settings.d.ts +27 -0
  104. package/vendor/modules/portrait.d.mts +1 -0
  105. package/vendor/modules/portrait.inputs.json +111 -0
  106. package/vendor/modules/portrait.mjs +2 -0
  107. package/vendor/modules/quality/index.d.ts +130 -0
  108. package/vendor/modules/quality.d.mts +1 -0
  109. package/vendor/modules/quality.inputs.json +34 -0
  110. package/vendor/modules/quality.mjs +2 -0
  111. package/vendor/modules/scene-blend/blend.d.ts +54 -0
  112. package/vendor/modules/scene-blend/blend.glsl.d.ts +8 -0
  113. package/vendor/modules/scene-blend/index.d.ts +25 -0
  114. package/vendor/modules/scene-blend/lit.d.ts +61 -0
  115. package/vendor/modules/scene-blend/noise.d.ts +13 -0
  116. package/vendor/modules/scene-blend/settings.d.ts +63 -0
  117. package/vendor/modules/scene-blend.d.mts +1 -0
  118. package/vendor/modules/scene-blend.inputs.json +133 -0
  119. package/vendor/modules/scene-blend.mjs +2 -0
  120. package/vendor/modules/section-post/index.d.ts +23 -0
  121. package/vendor/modules/section-post/lit.d.ts +47 -0
  122. package/vendor/modules/section-post/noise.d.ts +14 -0
  123. package/vendor/modules/section-post/post.d.ts +31 -0
  124. package/vendor/modules/section-post/post.glsl.d.ts +8 -0
  125. package/vendor/modules/section-post/settings.d.ts +84 -0
  126. package/vendor/modules/section-post.d.mts +1 -0
  127. package/vendor/modules/section-post.inputs.json +107 -0
  128. package/vendor/modules/section-post.mjs +53 -0
  129. package/vendor/modules/surfaces/exact.d.ts +8 -0
  130. package/vendor/modules/surfaces/field.d.ts +7 -0
  131. package/vendor/modules/surfaces/gpu.d.ts +19 -0
  132. package/vendor/modules/surfaces/index.d.ts +17 -0
  133. package/vendor/modules/surfaces/paint.d.ts +28 -0
  134. package/vendor/modules/surfaces/plan.d.ts +39 -0
  135. package/vendor/modules/surfaces/print.d.ts +55 -0
  136. package/vendor/modules/surfaces/recipe.d.ts +143 -0
  137. package/vendor/modules/surfaces/surface.glsl.d.ts +4 -0
  138. package/vendor/modules/surfaces.d.mts +1 -0
  139. package/vendor/modules/surfaces.inputs.json +54 -0
  140. package/vendor/modules/surfaces.mjs +172 -0
  141. package/vendor/modules/tracks/index.d.ts +66 -0
  142. package/vendor/modules/tracks.d.mts +1 -0
  143. package/vendor/modules/tracks.mjs +2 -0
  144. package/vendor/modules/tree-growth/bend.d.ts +28 -0
  145. package/vendor/modules/tree-growth/frame.d.ts +60 -0
  146. package/vendor/modules/tree-growth/index.d.ts +23 -0
  147. package/vendor/modules/tree-growth/light.d.ts +13 -0
  148. package/vendor/modules/tree-growth/math.d.ts +19 -0
  149. package/vendor/modules/tree-growth/model.d.ts +100 -0
  150. package/vendor/modules/tree-growth/sectors.d.ts +10 -0
  151. package/vendor/modules/tree-growth/simulation.d.ts +58 -0
  152. package/vendor/modules/tree-growth/species.d.ts +117 -0
  153. package/vendor/modules/tree-growth/species.data.d.ts +2 -0
  154. package/vendor/modules/tree-growth/year.d.ts +38 -0
  155. package/vendor/modules/tree-growth.d.mts +1 -0
  156. package/vendor/modules/tree-growth.inputs.json +75 -0
  157. package/vendor/modules/tree-growth.mjs +2 -0
  158. package/vendor/modules/tree-render/features.d.ts +9 -0
  159. package/vendor/modules/tree-render/forest/bake.d.ts +41 -0
  160. package/vendor/modules/tree-render/forest/cards.d.ts +28 -0
  161. package/vendor/modules/tree-render/forest/forest.d.ts +156 -0
  162. package/vendor/modules/tree-render/index.d.ts +52 -0
  163. package/vendor/modules/tree-render/inputs.d.ts +260 -0
  164. package/vendor/modules/tree-render/instances.d.ts +66 -0
  165. package/vendor/modules/tree-render/math.d.ts +8 -0
  166. package/vendor/modules/tree-render/tree/bark.d.ts +20 -0
  167. package/vendor/modules/tree-render/tree/leaves.d.ts +29 -0
  168. package/vendor/modules/tree-render/tree/litter.d.ts +21 -0
  169. package/vendor/modules/tree-render/tree/ornaments.d.ts +36 -0
  170. package/vendor/modules/tree-render/tree/roots.d.ts +75 -0
  171. package/vendor/modules/tree-render/tree/shapes.d.ts +49 -0
  172. package/vendor/modules/tree-render/tree/tree.d.ts +239 -0
  173. package/vendor/modules/tree-render/tree/wood.d.ts +27 -0
  174. package/vendor/modules/tree-render/wind.d.ts +51 -0
  175. package/vendor/modules/tree-render.d.mts +1 -0
  176. package/vendor/modules/tree-render.inputs.json +45 -0
  177. package/vendor/modules/tree-render.mjs +2 -0
  178. package/vendor/modules/voxel-dither/dither.glsl.d.ts +9 -0
  179. package/vendor/modules/voxel-dither/index.d.ts +35 -0
  180. package/vendor/modules/voxel-dither/light.d.ts +33 -0
  181. package/vendor/modules/voxel-dither/lit.d.ts +86 -0
  182. package/vendor/modules/voxel-dither/pass.d.ts +46 -0
  183. package/vendor/modules/voxel-dither/screens.d.ts +21 -0
  184. package/vendor/modules/voxel-dither/settings.d.ts +307 -0
  185. package/vendor/modules/voxel-dither/signals.d.ts +35 -0
  186. package/vendor/modules/voxel-dither.d.mts +1 -0
  187. package/vendor/modules/voxel-dither.inputs.json +295 -0
  188. package/vendor/modules/voxel-dither.mjs +452 -0
  189. package/vendor/modules/world-light/index.d.ts +133 -0
  190. package/vendor/modules/world-light.d.mts +1 -0
  191. package/vendor/modules/world-light.inputs.json +68 -0
  192. package/vendor/modules/world-light.mjs +2 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * motes: dust, light motes and sparkles for keel/lit, as one instanced quad (see the README). keel/lit is passed in,
3
+ * so this module imports nothing. The time comes from the host's clock, never a wall clock: a paused clock is a still
4
+ * field, and any frame can be drawn on its own.
5
+ */
6
+ import type { MoteDensity, MoteSettings } from "./place.js";
7
+ export { MOTE_FRAGMENT, MOTE_PATH_GLSL, MOTE_VERTEX } from "./motes.glsl.js";
8
+ export { DEFAULT_MOTES, moteHash, moteSettings, placeMotes } from "./place.js";
9
+ export type { MoteDensity, MoteField, MoteSettings, Vec3 } from "./place.js";
10
+ interface Uniform {
11
+ value: unknown;
12
+ }
13
+ interface AttributeLike {
14
+ readonly array: ArrayLike<number>;
15
+ }
16
+ interface NodeLike {
17
+ frustumCulled: boolean;
18
+ renderOrder: number;
19
+ visible: boolean;
20
+ }
21
+ interface InstancesLike extends NodeLike {
22
+ count: number;
23
+ }
24
+ interface GeometryLike {
25
+ setAttribute(name: string, attribute: unknown): unknown;
26
+ dispose(): void;
27
+ }
28
+ interface MaterialLike {
29
+ readonly uniforms: Record<string, Uniform>;
30
+ dispose(): void;
31
+ }
32
+ interface ColorLike {
33
+ readonly r: number;
34
+ readonly g: number;
35
+ readonly b: number;
36
+ }
37
+ interface Vector2Like {
38
+ set(x: number, y: number): unknown;
39
+ }
40
+ interface Vector3Like {
41
+ set(x: number, y: number, z: number): unknown;
42
+ }
43
+ /** The parts of keel/lit this module calls. Pass the keel/lit namespace itself. */
44
+ export interface LitLike {
45
+ readonly Instances: new (geometry: unknown, material: unknown, count: number) => InstancesLike;
46
+ readonly InstanceAttribute: new (array: Float32Array, size: number) => AttributeLike;
47
+ readonly CustomMaterial: new (parameters: Readonly<Record<string, unknown>>) => MaterialLike;
48
+ readonly Color: new (value?: string) => ColorLike;
49
+ readonly Vector2: new (x?: number, y?: number) => Vector2Like;
50
+ readonly Vector3: new (x?: number, y?: number, z?: number) => Vector3Like;
51
+ plane(width: number, height: number): GeometryLike;
52
+ }
53
+ /** One frame: the host's clock, and the keyed field values. */
54
+ export interface MoteFrame {
55
+ /** Seconds on the host's clock. Ignored when `still`. */
56
+ readonly time: number;
57
+ /** Multiplies every mote's opacity, 0 to 1 (a keyed fade). Default 1. */
58
+ readonly opacity?: number;
59
+ /** Reduced motion: the field holds at time 0, with no blink. */
60
+ readonly still?: boolean;
61
+ }
62
+ /** A field of motes in the scene. */
63
+ export interface Motes {
64
+ /** The instanced quad: add it to the stage; move or rotate it to move the whole field. */
65
+ readonly mesh: NodeLike;
66
+ /** How many motes are drawn, up to the settings' count (a quality lever). */
67
+ shown: number;
68
+ /** The drawing buffer's size in pixels, for pixel sizes and the smallest size. Call on resize. */
69
+ resize(width: number, height: number): void;
70
+ /** Sets the clock and the keyed values for the next draw. */
71
+ update(frame: MoteFrame): void;
72
+ dispose(): void;
73
+ }
74
+ /**
75
+ * Makes a field of motes: one instanced quad, every mote's drift, turbulence and blink worked out in the vertex shader
76
+ * from the time `update` hands in. Additive, unlit, and drawn after the opaque scene without writing depth.
77
+ *
78
+ * @param lit The keel/lit namespace.
79
+ * @param settings The field's settings; anything missing takes `DEFAULT_MOTES`.
80
+ * @param density Optional: where motes are welcome, 0 to 1, to thin the field in places.
81
+ * @returns The field: add `mesh` to the stage.
82
+ */
83
+ export declare function createMotes(lit: LitLike, settings?: Partial<MoteSettings>, density?: MoteDensity): Motes;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `vec3 motePath(vec4 mote, vec4 life, float t)`: where a mote is at time t. The base place drifts with `uDrift` and
3
+ * wraps in the box (`uBoxMin`, `uBox`), then wanders by hashed sines `uTurbulence` world units across. A mesh-instanced
4
+ * variant (coins, confetti) can include this and orient its own geometry about the result.
5
+ * `float moteFade(vec3 p)`: 0 at a wrapping face of the box, 1 a little inside it, so wrapping never pops.
6
+ */
7
+ export declare const MOTE_PATH_GLSL = "\nuniform vec3 uDrift, uBoxMin, uBox;\nuniform float uTurbulence;\nvec3 motePath(vec4 mote, vec4 life, float t) {\n vec3 p = mote.xyz + uDrift * t - uBoxMin;\n p = uBoxMin + p - uBox * floor(p / uBox);\n float s = life.w * 61.0 + mote.w;\n vec3 a = vec3(0.37, 0.29, 0.23) * t + vec3(s, s * 1.7, s * 2.9);\n vec3 b = vec3(0.83, 0.71, 0.59) * t + vec3(s * 2.3, s * 3.1, s * 1.3);\n return p + uTurbulence * (sin(a) + 0.5 * sin(b)) / 1.5;\n}\nfloat moteFade(vec3 p) {\n vec3 f = fract((p - uBoxMin) / uBox);\n vec3 edge = clamp(min(f, 1.0 - f) * 16.0, 0.0, 1.0);\n vec3 moving = step(1e-6, abs(uDrift));\n vec3 fade = mix(vec3(1.0), edge, moving);\n return fade.x * fade.y * fade.z;\n}\n";
8
+ export declare const MOTE_VERTEX = "\nattribute vec4 aMote;\nattribute vec4 aLife;\nattribute vec3 aColor;\nuniform float uTime, uBlink, uOpacity, uIntensity, uMinPixels;\nuniform vec2 uPixel;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSparkle;\n\nuniform vec3 uDrift, uBoxMin, uBox;\nuniform float uTurbulence;\nvec3 motePath(vec4 mote, vec4 life, float t) {\n vec3 p = mote.xyz + uDrift * t - uBoxMin;\n p = uBoxMin + p - uBox * floor(p / uBox);\n float s = life.w * 61.0 + mote.w;\n vec3 a = vec3(0.37, 0.29, 0.23) * t + vec3(s, s * 1.7, s * 2.9);\n vec3 b = vec3(0.83, 0.71, 0.59) * t + vec3(s * 2.3, s * 3.1, s * 1.3);\n return p + uTurbulence * (sin(a) + 0.5 * sin(b)) / 1.5;\n}\nfloat moteFade(vec3 p) {\n vec3 f = fract((p - uBoxMin) / uBox);\n vec3 edge = clamp(min(f, 1.0 - f) * 16.0, 0.0, 1.0);\n vec3 moving = step(1e-6, abs(uDrift));\n vec3 fade = mix(vec3(1.0), edge, moving);\n return fade.x * fade.y * fade.z;\n}\n\nvoid main() {\n float t = uTime;\n vec3 p = motePath(aMote, aLife, t);\n vec4 view = modelViewMatrix * vec4(p, 1.0);\n vec4 clip = projectionMatrix * view;\n // (A sparkle's rays reach past its core, so its quad is three times as wide.)\n float reach = mix(1.0, 3.0, aLife.z);\n#ifdef ATTENUATE\n float pixels = aLife.y * projectionMatrix[1][1] / max(clip.w, 1e-4) / uPixel.y;\n#else\n float pixels = aLife.y;\n#endif\n float shown = max(pixels, uMinPixels);\n float dim = (pixels * pixels) / max(shown * shown, 1e-8);\n clip.xy += position.xy * reach * shown * uPixel * clip.w;\n gl_Position = clip;\n float wave = 0.5 + 0.5 * sin(6.2831853 * t / aLife.x + aMote.w);\n float alpha = uOpacity * mix(1.0, wave * wave, uBlink) * dim * moteFade(p);\n vUv = position.xy * 2.0;\n vColor = vec4(aColor * uIntensity, alpha);\n vSparkle = aLife.z;\n}\n";
9
+ export declare const MOTE_FRAGMENT = "\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSparkle;\nvoid main() {\n // (A dot: a soft round sprite, nothing at the quad's edge. A sparkle: a core and four rays, on a quad 3x as wide.)\n float r2 = dot(vUv, vUv);\n float soft = max(0.0, 1.0 - r2);\n float dot2 = soft * soft;\n vec2 a = abs(vUv);\n float rays = max(0.0, 1.0 - a.x) * exp(-a.y * 48.0) + max(0.0, 1.0 - a.y) * exp(-a.x * 48.0);\n float star = exp(-r2 * 24.0) + rays * 0.7;\n float shape = mix(dot2, star, vSparkle);\n if (shape * vColor.a < 0.002) discard;\n gl_FragColor = vec4(vColor.rgb, vColor.a * shape);\n}\n";
@@ -0,0 +1,59 @@
1
+ export type Vec3 = readonly [number, number, number];
2
+ /** How a field of motes looks and moves. Every field has a default (`DEFAULT_MOTES`). */
3
+ export interface MoteSettings {
4
+ /** How many motes, 0 to 4096. */
5
+ readonly count: number;
6
+ /** Lays the field: the same seed, the same field. */
7
+ readonly seed: number;
8
+ /** The box the motes live in: its centre and its size along x, y and z, in world units. */
9
+ readonly centre: Vec3;
10
+ readonly box: Vec3;
11
+ /** A mote's size in world units, and how far it may differ, as a share either way (0.5: 0.5 to 1.5 times). */
12
+ readonly size: number;
13
+ readonly sizeSpread: number;
14
+ /** The smallest a mote is drawn, in drawing-buffer pixels: a smaller one is drawn this big and dimmer. */
15
+ readonly minPixels: number;
16
+ /** Hex colours; each mote takes one, seeded. */
17
+ readonly colors: readonly string[];
18
+ /** Opacity at full blink, 0 to 1, and a multiplier on the colour (over 1 reaches a bloom threshold). */
19
+ readonly opacity: number;
20
+ readonly intensity: number;
21
+ /** World units a second the whole field drifts; the box wraps, so the field never empties. */
22
+ readonly drift: Vec3;
23
+ /** How far, in world units, each mote wanders about its drifting place. */
24
+ readonly turbulence: number;
25
+ /** The shortest and longest blink period, seconds; each mote takes one between, seeded. */
26
+ readonly blinkPeriod: readonly [number, number];
27
+ /** How deep the blink goes: 0 a steady light, 1 out to nothing at the trough. */
28
+ readonly blink: number;
29
+ /** The share of motes drawn as four-pointed sparkles, 0 to 1. */
30
+ readonly sparkle: number;
31
+ /** True: `size` is in world units and shrinks with distance. False: `size` is in drawing-buffer pixels. */
32
+ readonly attenuate: boolean;
33
+ }
34
+ export declare const DEFAULT_MOTES: MoteSettings;
35
+ /** Where motes are welcome, 0 (never) to 1 (always), at a point in world units; the field is thinned by it. */
36
+ export type MoteDensity = (x: number, y: number, z: number) => number;
37
+ /**
38
+ * The field laid out, one entry a mote. `mote` is four numbers a mote: x, y, z and the blink phase in radians. `life`
39
+ * is four: the blink period in seconds, the size, 1 for a sparkle or 0 for a dot, and a seed from 0 to 1 for the
40
+ * turbulence. `color` is each mote's index into the colours.
41
+ */
42
+ export interface MoteField {
43
+ readonly count: number;
44
+ readonly mote: Float32Array;
45
+ readonly life: Float32Array;
46
+ readonly color: Uint8Array;
47
+ }
48
+ /** A uniform number in [0, 1) for a seed, a mote and a channel: a 32-bit integer hash, exact everywhere. */
49
+ export declare function moteHash(seed: number, index: number, channel: number): number;
50
+ /** Settings with every missing or out-of-range field put right. */
51
+ export declare function moteSettings(partial?: Partial<MoteSettings>): MoteSettings;
52
+ /**
53
+ * Lays a field of motes from its settings: the same settings and seed give the same numbers on every engine.
54
+ *
55
+ * @param partial Settings; anything missing takes `DEFAULT_MOTES`.
56
+ * @param density Optional: where motes are welcome, to make a field denser in some places than others.
57
+ * @returns The field, ready to upload as instance attributes.
58
+ */
59
+ export declare function placeMotes(partial?: Partial<MoteSettings>, density?: MoteDensity): MoteField;
@@ -0,0 +1 @@
1
+ export * from './motes/index.js'
@@ -0,0 +1,116 @@
1
+ {
2
+ "protocol": "keel-module-inputs@1",
3
+ "fields": [
4
+ {
5
+ "key": "count",
6
+ "label": "Motes",
7
+ "required": false,
8
+ "type": "number",
9
+ "min": 0,
10
+ "max": 4096,
11
+ "step": 1,
12
+ "control": "slider",
13
+ "default": 300
14
+ },
15
+ {
16
+ "key": "colors",
17
+ "label": "Colours",
18
+ "required": false,
19
+ "help": "Each mote takes one, seeded.",
20
+ "type": "palette",
21
+ "minItems": 1,
22
+ "maxItems": 8,
23
+ "default": [
24
+ "#ffbe26"
25
+ ]
26
+ },
27
+ {
28
+ "key": "size",
29
+ "label": "Size",
30
+ "required": false,
31
+ "help": "World units, or pixels when attenuation is off.",
32
+ "type": "number",
33
+ "min": 0,
34
+ "max": 1,
35
+ "step": 0.001,
36
+ "default": 0.07
37
+ },
38
+ {
39
+ "key": "opacity",
40
+ "label": "Opacity",
41
+ "required": false,
42
+ "type": "number",
43
+ "min": 0,
44
+ "max": 1,
45
+ "step": 0.01,
46
+ "control": "slider",
47
+ "default": 0.88
48
+ },
49
+ {
50
+ "key": "intensity",
51
+ "label": "Intensity",
52
+ "required": false,
53
+ "help": "Over 1 reaches a bloom threshold of 1.",
54
+ "placement": "advanced",
55
+ "type": "number",
56
+ "min": 0,
57
+ "max": 8,
58
+ "step": 0.05,
59
+ "default": 1
60
+ },
61
+ {
62
+ "key": "turbulence",
63
+ "label": "Turbulence",
64
+ "required": false,
65
+ "placement": "advanced",
66
+ "type": "number",
67
+ "min": 0,
68
+ "max": 1,
69
+ "step": 0.005,
70
+ "unit": "world units",
71
+ "default": 0.03
72
+ },
73
+ {
74
+ "key": "blink",
75
+ "label": "Blink depth",
76
+ "required": false,
77
+ "placement": "advanced",
78
+ "type": "number",
79
+ "min": 0,
80
+ "max": 1,
81
+ "step": 0.05,
82
+ "default": 1
83
+ },
84
+ {
85
+ "key": "sparkle",
86
+ "label": "Sparkles",
87
+ "required": false,
88
+ "help": "The share of motes drawn as four-pointed sparkles.",
89
+ "placement": "advanced",
90
+ "type": "number",
91
+ "min": 0,
92
+ "max": 1,
93
+ "step": 0.01,
94
+ "default": 0
95
+ },
96
+ {
97
+ "key": "attenuate",
98
+ "label": "Size attenuation",
99
+ "required": false,
100
+ "placement": "advanced",
101
+ "type": "boolean",
102
+ "default": true
103
+ },
104
+ {
105
+ "key": "seed",
106
+ "label": "Seed",
107
+ "required": false,
108
+ "placement": "advanced",
109
+ "type": "number",
110
+ "min": 0,
111
+ "max": 2147483647,
112
+ "step": 1,
113
+ "default": 1
114
+ }
115
+ ]
116
+ }
@@ -0,0 +1,68 @@
1
+ // motes@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var x=`
3
+ uniform vec3 uDrift, uBoxMin, uBox;
4
+ uniform float uTurbulence;
5
+ vec3 motePath(vec4 mote, vec4 life, float t) {
6
+ vec3 p = mote.xyz + uDrift * t - uBoxMin;
7
+ p = uBoxMin + p - uBox * floor(p / uBox);
8
+ float s = life.w * 61.0 + mote.w;
9
+ vec3 a = vec3(0.37, 0.29, 0.23) * t + vec3(s, s * 1.7, s * 2.9);
10
+ vec3 b = vec3(0.83, 0.71, 0.59) * t + vec3(s * 2.3, s * 3.1, s * 1.3);
11
+ return p + uTurbulence * (sin(a) + 0.5 * sin(b)) / 1.5;
12
+ }
13
+ float moteFade(vec3 p) {
14
+ vec3 f = fract((p - uBoxMin) / uBox);
15
+ vec3 edge = clamp(min(f, 1.0 - f) * 16.0, 0.0, 1.0);
16
+ vec3 moving = step(1e-6, abs(uDrift));
17
+ vec3 fade = mix(vec3(1.0), edge, moving);
18
+ return fade.x * fade.y * fade.z;
19
+ }
20
+ `,b=`
21
+ attribute vec4 aMote;
22
+ attribute vec4 aLife;
23
+ attribute vec3 aColor;
24
+ uniform float uTime, uBlink, uOpacity, uIntensity, uMinPixels;
25
+ uniform vec2 uPixel;
26
+ varying vec2 vUv;
27
+ varying vec4 vColor;
28
+ varying float vSparkle;
29
+ ${x}
30
+ void main() {
31
+ float t = uTime;
32
+ vec3 p = motePath(aMote, aLife, t);
33
+ vec4 view = modelViewMatrix * vec4(p, 1.0);
34
+ vec4 clip = projectionMatrix * view;
35
+ // (A sparkle's rays reach past its core, so its quad is three times as wide.)
36
+ float reach = mix(1.0, 3.0, aLife.z);
37
+ #ifdef ATTENUATE
38
+ float pixels = aLife.y * projectionMatrix[1][1] / max(clip.w, 1e-4) / uPixel.y;
39
+ #else
40
+ float pixels = aLife.y;
41
+ #endif
42
+ float shown = max(pixels, uMinPixels);
43
+ float dim = (pixels * pixels) / max(shown * shown, 1e-8);
44
+ clip.xy += position.xy * reach * shown * uPixel * clip.w;
45
+ gl_Position = clip;
46
+ float wave = 0.5 + 0.5 * sin(6.2831853 * t / aLife.x + aMote.w);
47
+ float alpha = uOpacity * mix(1.0, wave * wave, uBlink) * dim * moteFade(p);
48
+ vUv = position.xy * 2.0;
49
+ vColor = vec4(aColor * uIntensity, alpha);
50
+ vSparkle = aLife.z;
51
+ }
52
+ `,f=`
53
+ varying vec2 vUv;
54
+ varying vec4 vColor;
55
+ varying float vSparkle;
56
+ void main() {
57
+ // (A dot: a soft round sprite, nothing at the quad's edge. A sparkle: a core and four rays, on a quad 3x as wide.)
58
+ float r2 = dot(vUv, vUv);
59
+ float soft = max(0.0, 1.0 - r2);
60
+ float dot2 = soft * soft;
61
+ vec2 a = abs(vUv);
62
+ float rays = max(0.0, 1.0 - a.x) * exp(-a.y * 48.0) + max(0.0, 1.0 - a.y) * exp(-a.x * 48.0);
63
+ float star = exp(-r2 * 24.0) + rays * 0.7;
64
+ float shape = mix(dot2, star, vSparkle);
65
+ if (shape * vColor.a < 0.002) discard;
66
+ gl_FragColor = vec4(vColor.rgb, vColor.a * shape);
67
+ }
68
+ `;var p={count:300,seed:1,centre:[0,0,0],box:[3,3,4],size:.07,sizeSpread:.5,minPixels:1.5,colors:["#ffbe26"],opacity:.88,intensity:1,drift:[.014,.014,0],turbulence:.03,blinkPeriod:[2,5],blink:1,sparkle:0,attenuate:!0},g=6.283185307179586,w=4096,L=8,m=(n,e,o)=>Math.min(o,Math.max(e,n));function u(n,e,o){let t=Math.imul(n|0,2654435761)^Math.imul(e+1,2246822519)^Math.imul(o+1,3266489917);return t=Math.imul(t^t>>>16,2146121005),t=Math.imul(t^t>>>15,2221713035),t^=t>>>16,(t>>>0)/4294967296}function d(n={}){let e={...p,...n},o=Math.max(.05,Math.min(e.blinkPeriod[0],e.blinkPeriod[1]));return{...e,count:m(Math.floor(e.count),0,w),seed:e.seed|0,box:[Math.max(.001,e.box[0]),Math.max(.001,e.box[1]),Math.max(.001,e.box[2])],size:Math.max(0,e.size),sizeSpread:m(e.sizeSpread,0,1),minPixels:Math.max(0,e.minPixels),colors:e.colors.length>0?e.colors.slice(0,255):p.colors,opacity:m(e.opacity,0,1),intensity:Math.max(0,e.intensity),turbulence:Math.max(0,e.turbulence),blinkPeriod:[o,Math.max(o,e.blinkPeriod[0],e.blinkPeriod[1])],blink:m(e.blink,0,1),sparkle:m(e.sparkle,0,1)}}function v(n,e,o){let t=o*3;return[n.centre[0]+(u(n.seed,e,t)-.5)*n.box[0],n.centre[1]+(u(n.seed,e,t+1)-.5)*n.box[1],n.centre[2]+(u(n.seed,e,t+2)-.5)*n.box[2]]}function T(n,e,o){let t=v(n,e,0);if(!o)return t;for(let a=0;a<L;a+=1)if(t=v(n,e,a),u(n.seed,e,100+a)<o(t[0],t[1],t[2]))return t;return t}function y(n={},e){let o=d(n),t=new Float32Array(o.count*4),a=new Float32Array(o.count*4),l=new Uint8Array(o.count),[i,s]=o.blinkPeriod;for(let r=0;r<o.count;r+=1){let c=T(o,r,e);t.set([c[0],c[1],c[2],u(o.seed,r,40)*g],r*4);let M=o.size*(1+(u(o.seed,r,42)*2-1)*o.sizeSpread),h=u(o.seed,r,43)<o.sparkle?1:0,k=i+u(o.seed,r,41)*(s-i);a.set([k,M,h,u(o.seed,r,44)],r*4),l[r]=Math.floor(u(o.seed,r,45)*o.colors.length)}return{count:o.count,mote:t,life:a,color:l}}function A(n,e,o){let t=y(e,o),a=e.colors.map(i=>new n.Color(i)),l=new Float32Array(t.count*3);for(let i=0;i<t.count;i+=1){let s=a[t.color[i]??0]??{r:1,g:1,b:1};l.set([s.r,s.g,s.b],i*3)}return{aMote:new n.InstanceAttribute(t.mote,4),aLife:new n.InstanceAttribute(t.life,4),aColor:new n.InstanceAttribute(l,3)}}function P(n,e){let o=e.centre.map((t,a)=>t-(e.box[a]??1)/2);return{uTime:{value:0},uBlink:{value:e.blink},uOpacity:{value:e.opacity},uIntensity:{value:e.intensity},uMinPixels:{value:e.minPixels},uPixel:{value:new n.Vector2(2/1024,2/1024)},uDrift:{value:new n.Vector3(e.drift[0],e.drift[1],e.drift[2])},uBoxMin:{value:new n.Vector3(o[0],o[1],o[2])},uBox:{value:new n.Vector3(e.box[0],e.box[1],e.box[2])},uTurbulence:{value:e.turbulence}}}function O(n,e={},o){let t=d(e),a=n.plane(1,1);for(let[r,c]of Object.entries(A(n,t,o)))a.setAttribute(r,c);let l=P(n,t),i=new n.CustomMaterial({uniforms:l,vertexShader:b,fragmentShader:f,defines:t.attenuate?{ATTENUATE:""}:{},transparent:!0,depthWrite:!1,blending:"add"}),s=new n.Instances(a,i,t.count);return s.frustumCulled=!1,{mesh:s,get shown(){return s.count},set shown(r){s.count=Math.max(0,Math.min(t.count,Math.floor(r)))},resize(r,c){l.uPixel.value.set(2/Math.max(1,r),2/Math.max(1,c))},update(r){let c=r.still===!0;l.uTime.value=c?0:r.time,l.uBlink.value=c?0:t.blink,l.uOpacity.value=t.opacity*Math.max(0,Math.min(1,r.opacity??1))},dispose(){a.dispose(),i.dispose()}}}export{p as DEFAULT_MOTES,f as MOTE_FRAGMENT,x as MOTE_PATH_GLSL,b as MOTE_VERTEX,O as createMotes,u as moteHash,d as moteSettings,y as placeMotes};
@@ -0,0 +1,44 @@
1
+ /** An sRGB colour, 0..1 a channel. */
2
+ export type Rgb = readonly [number, number, number];
3
+ /** The shapes a dab can take. The numbers are the shader's. */
4
+ export declare const KIND: {
5
+ readonly blot: 0;
6
+ readonly spire: 1;
7
+ readonly crown: 2;
8
+ readonly wall: 3;
9
+ readonly leaf: 4;
10
+ readonly stem: 5;
11
+ };
12
+ /** Floats per dab in the instance buffer. */
13
+ export declare const STRIDE = 16;
14
+ /** One dab. Position in plate fractions; sizes and axis in plate heights (x scaled by the aspect). */
15
+ export interface Dab {
16
+ /** Centre, x across and y down, 0..1. */
17
+ readonly x: number;
18
+ readonly y: number;
19
+ /** Half its length along the axis and half its width across it. */
20
+ readonly len: number;
21
+ readonly wid: number;
22
+ /** A unit vector from its foot or stalk toward its tip. */
23
+ readonly ax: number;
24
+ readonly ay: number;
25
+ readonly kind: number;
26
+ /** 0..1, varies the shape's detail. */
27
+ readonly seed: number;
28
+ readonly color: Rgb;
29
+ readonly alpha: number;
30
+ /** How much light falls on it, 0..1. */
31
+ readonly light: number;
32
+ /** Lobes for a leaf (1, 3 or 5); the shaded side's share for a wall. */
33
+ readonly variant: number;
34
+ /** For a reflection: the waterline y it is clipped to. 0 is no reflection. */
35
+ readonly water: number;
36
+ /** Depth steps toward the haze. */
37
+ readonly depth: number;
38
+ }
39
+ /** `#rrggbb` to 0..1 channels. */
40
+ export declare function rgb(hex: string): Rgb;
41
+ /** The colour `t` of the way from `a` to `b`. */
42
+ export declare function mix(a: Rgb, b: Rgb, t: number): Rgb;
43
+ /** Dabs as an instance buffer, in the order given (back first). */
44
+ export declare function packDabs(dabs: readonly Dab[]): Float32Array;
@@ -0,0 +1,19 @@
1
+ /** A 32-bit hash of two integers. */
2
+ export declare function hash(a: number, b: number): number;
3
+ /** A stream of numbers in 0..1 from a seed and a stream name. */
4
+ export interface Draw {
5
+ /** The next number, from 0 up to 1. */
6
+ (): number;
7
+ /** The next number between `low` and `high`. */
8
+ within(low: number, high: number): number;
9
+ }
10
+ /** A stream of numbers that depends on the seed and on `stream` only. */
11
+ export declare function draws(seed: number, stream: number): Draw;
12
+ /** The smooth step of 0..1, a polynomial. */
13
+ export declare function ease(t: number): number;
14
+ /** Value noise in one dimension, 0..1, a lattice point every 1 of `x`. */
15
+ export declare function noise1(seed: number, x: number): number;
16
+ /** A unit vector turned from `x, y` by the angle whose half-tangent is `t` (-1..1 is a half turn each way). */
17
+ export declare function turn(x: number, y: number, t: number): [number, number];
18
+ /** FNV-1a over the bytes of 32-bit floats, two lanes, as 16 hex digits. */
19
+ export declare function digestOf(parts: readonly Float32Array[]): string;
@@ -0,0 +1,4 @@
1
+ import { type Dab } from "./dab.js";
2
+ import type { PlateRecipe } from "./recipe.js";
3
+ /** Every dab of the near foliage: blots, stems, deep leaves, then the leaves in the light. */
4
+ export declare function foliageDabs(recipe: PlateRecipe, seed: number): Dab[];
@@ -0,0 +1,65 @@
1
+ import { type PlatePlan } from "./plan.js";
2
+ /** A rectangle of the plate in plate fractions: left, top, width, height. */
3
+ export type PlateView = readonly [number, number, number, number];
4
+ /** The size of a painted plate in pixels, and the part of the plate it holds (all of it unless said). */
5
+ export interface PlateSize {
6
+ readonly width: number;
7
+ readonly height: number;
8
+ readonly view?: PlateView;
9
+ }
10
+ /** A painted plate: a texture whose row 0 is the plate's top. */
11
+ export interface Plate {
12
+ readonly texture: WebGLTexture;
13
+ readonly width: number;
14
+ readonly height: number;
15
+ readonly digest: string;
16
+ readonly view: PlateView;
17
+ }
18
+ /** Where and how the backdrop is drawn. */
19
+ export interface BackdropView {
20
+ /** The target rectangle in pixels; x and y from the bottom left as WebGL counts. */
21
+ readonly width: number;
22
+ readonly height: number;
23
+ readonly x?: number;
24
+ readonly y?: number;
25
+ /** 1 fits the plate to cover the target; above 1 leaves room to move. */
26
+ readonly zoom?: number;
27
+ /** The point of the plate kept in view, 0..1 each way. */
28
+ readonly focus?: readonly [number, number];
29
+ /** The parallax hook: a move in crop widths and heights (small, ±0.05), held inside the plate. */
30
+ readonly shift?: readonly [number, number];
31
+ }
32
+ /** Pixels of a plate, rows from the top, RGBA: what `new ImageData(data, width, height)` takes. */
33
+ export interface PlateStill {
34
+ readonly width: number;
35
+ readonly height: number;
36
+ readonly data: Uint8ClampedArray;
37
+ }
38
+ export interface PlatePainter {
39
+ /** Paints a plan, or returns the plate already painted for the same digest, size and view. */
40
+ paint(plan: PlatePlan, size: PlateSize): Plate;
41
+ /** Draws a plate over the bound framebuffer as a screen-locked backdrop. */
42
+ draw(plate: Plate, view: BackdropView): void;
43
+ /** Reads a plate back, for a still. */
44
+ read(plate: Plate): PlateStill;
45
+ /** Frees one plate and forgets it. */
46
+ release(plate: Plate): void;
47
+ /** Frees every plate and the programs. */
48
+ dispose(): void;
49
+ }
50
+ /**
51
+ * The part of a source to show so it covers a target: left, top, width, height in source fractions.
52
+ *
53
+ * @param source The source's width over height.
54
+ * @param target The target's width over height.
55
+ * @param view Zoom, focus and shift, as for `draw`.
56
+ * @returns The crop, always inside the source.
57
+ */
58
+ export declare function coverCrop(source: number, target: number, view?: Omit<BackdropView, "width" | "height">): PlateView;
59
+ /**
60
+ * A painter on a WebGL2 context. Programs compile here, once; plates are cached by digest, size and view.
61
+ *
62
+ * @param gl The host's context. The painter restores the state it changes.
63
+ * @returns paint, draw, read, release and dispose.
64
+ */
65
+ export declare function createPlatePainter(gl: WebGL2RenderingContext): PlatePainter;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * plate-painter: a painted landscape plate, generated on the GPU at load from a seeded recipe, and drawn as a
3
+ * screen-locked backdrop. MIT.
4
+ *
5
+ * `planPlate` turns a recipe and a seed into every number the GPU needs, in exact arithmetic, with a digest.
6
+ * `createPlatePainter(gl)` paints a plan into a texture, draws it behind a scene, and reads it back for a still.
7
+ */
8
+ export { LAKE_VALLEY } from "./recipe.js";
9
+ export type { BranchRecipe, MassRecipe, Pair, PlateRecipe, RangeRecipe, StrokeRecipe, TownRecipe, TreeRecipe, } from "./recipe.js";
10
+ export { MAX_RANGES, PAINTER_VERSION, RIDGE_SAMPLES, planPlate } from "./plan.js";
11
+ export type { PlanUniform, PlatePlan, PlateSettings } from "./plan.js";
12
+ export { KIND, STRIDE } from "./dab.js";
13
+ export { coverCrop, createPlatePainter } from "./gpu.js";
14
+ export type { BackdropView, Plate, PlatePainter, PlateSize, PlateStill, PlateView } from "./gpu.js";
@@ -0,0 +1,14 @@
1
+ /** A triangle over the whole target, from the vertex id alone. */
2
+ export declare const FULL_VERT = "#version 300 es\nvoid main() {\n vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n gl_Position = vec4(p * 2. - 1., 0., 1.);\n}";
3
+ /** Sky, ranges, far shore, the lake reflecting them, near ground. Alpha carries the region for the strokes. */
4
+ export declare const SCENE_FRAG = "#version 300 es\nprecision highp float;\nprecision highp int;\nuniform vec4 uView;\nuniform vec2 uSize;\nuniform float uAspect;\nuniform vec2 uSeedOff;\nuniform vec3 uHaze;\nuniform float uHazeStep;\nuint hashU(ivec2 p) {\n uvec2 q = uvec2(p) * uvec2(1597334673u, 3812015801u);\n uint n = (q.x ^ q.y) * 1597334673u;\n n ^= n >> 16; n *= 2246822519u; n ^= n >> 13;\n return n;\n}\nfloat rnd(vec2 c) { return float(hashU(ivec2(floor(c))) >> 8) / 16777216.0; }\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3. - 2. * f);\n return mix(mix(rnd(i), rnd(i + vec2(1, 0)), u.x), mix(rnd(i + vec2(0, 1)), rnd(i + 1.), u.x), u.y);\n}\nfloat fbm(vec2 p, int oct) {\n float s = 0.;\n float a = .5;\n float t = 0.;\n for (int k = 0; k < 6; k++) {\n if (k >= oct) break;\n s += a * vnoise(p); t += a;\n p = p * 2.03 + vec2(17.1, 9.3); a *= .5;\n }\n return s / t;\n}\nfloat hazeOf(float depth) { return 1. - pow(1. - uHazeStep, depth); }\nvec2 plateUv() { return uView.xy + gl_FragCoord.xy / uSize * uView.zw; }\n\nuniform vec3 uSkyTop, uSkyLow, uSkyCorner, uCloudLit, uCloudShade;\nuniform vec4 uCloud;\nuniform highp sampler2D uRidge;\nuniform float uRanges;\nuniform vec3 uRangeLit[4];\nuniform vec3 uRangeShade[4];\nuniform vec4 uRangeInfo[4];\nuniform vec4 uShore;\nuniform vec3 uShoreCol, uShoreLit, uWaterFar, uWaterDeep, uSheen, uGround, uGroundWarm, uGroundDark;\nout vec4 outColor;\nfloat crest(int i, float u) {\n float x = clamp(u, 0., 1.) * 511.;\n int k = int(x);\n float a = texelFetch(uRidge, ivec2(k, i), 0).r;\n float b = texelFetch(uRidge, ivec2(min(k + 1, 511), i), 0).r;\n return mix(a, b, x - float(k));\n}\nvec3 sky(vec2 uv, int oct) {\n vec2 p = vec2(uv.x * uAspect, uv.y);\n float t = clamp(uv.y / uShore.x, 0., 1.);\n vec3 c = mix(uSkyTop, uSkyLow, smoothstep(0., 1., t));\n float corner = clamp((1. - uv.x * 1.5) * (1. - t * 1.3), 0., 1.);\n c = mix(c, uSkyCorner, corner * corner);\n c = mix(c, uSkyLow * 1.04, exp(-(uv.x - uCloud.z) * (uv.x - uCloud.z) * 4.84) * smoothstep(.05, .35, uv.y) * .35);\n vec2 cp = p * vec2(1.3, 2.6) + uSeedOff;\n vec2 warp = vec2(fbm(cp * .5, 3), fbm(cp * .5 + 7.3, 3));\n float n = fbm(cp + warp * 1.4, oct);\n float band = smoothstep(uCloud.x - .1, uCloud.x + .05, uv.y) * (1. - smoothstep(uCloud.y - .06, uCloud.y + .14, uv.y));\n float side = exp(-(uv.x - uCloud.z) * (uv.x - uCloud.z) * 3.24);\n float d = smoothstep(uCloud.w, uCloud.w + .3, n * (.55 + .45 * band) + band * side * .22);\n float toward = fbm(cp + warp * 1.4 + vec2(-.05, -.08), oct);\n float lit = clamp((n - toward) * 7. + .5, 0., 1.);\n c = mix(c, mix(uCloudShade, uCloudLit, lit), d * .88);\n float streak = fbm(vec2(p.x * 1.2, p.y * 26.) + uSeedOff * 1.7, 3);\n float low = smoothstep(uShore.x - .24, uShore.x - .14, uv.y) * (1. - smoothstep(uShore.x - .12, uShore.x - .04, uv.y));\n return mix(c, uCloudLit, smoothstep(.55, .75, streak) * low * .3);\n}\nvec3 ranges(vec2 uv, vec3 c, inout int code) {\n for (int i = 0; i < 4; i++) {\n if (float(i) >= uRanges) break;\n vec4 info = uRangeInfo[i];\n float top = crest(i, uv.x);\n float dry = vnoise(vec2(uv.x * uAspect * 600., uv.y * 200.) + float(i) * 13.);\n float a = smoothstep(-info.z, info.z, uv.y - top + (dry - .5) * info.z * 1.6);\n if (a <= 0.) continue;\n float below = max(uv.y - top, 0.);\n float win = .014 + below * .9;\n float slope = (crest(i, uv.x + win) - crest(i, uv.x - win)) / (2. * win);\n float gx = uv.x + below * clamp(-slope, -1.2, 1.2) * .7;\n float spur = vnoise(vec2(gx * uAspect * 26., below * 5.) + uSeedOff + float(i) * 5.);\n float fine = vnoise(vec2(gx * uAspect * 90., below * 16.) + uSeedOff);\n float face = smoothstep(0., 1., .5 - slope * 1.1 + (spur - .5) * .5 + (fine - .5) * .16);\n face = mix(face, .42, smoothstep(.0, .09, below) * .25);\n vec3 col = mix(uRangeShade[i], uRangeLit[i], smoothstep(.1, .9, face));\n float wood = smoothstep(.45, .8, vnoise(vec2(uv.x * uAspect * 240., uv.y * 330.) + uSeedOff));\n col *= 1. - wood * .22 * (1. - smoothstep(.8, 1.6, info.x));\n col = mix(col, uHaze, hazeOf(info.x));\n float mist = smoothstep(info.y - info.w, info.y, uv.y);\n col = mix(col, mix(uHaze, uSkyLow, .4), mist * .5);\n c = mix(c, col, a);\n if (a > .5) code = 16 + (slope < 0. ? 0 : 1);\n }\n return c;\n}\nvec3 shore(vec2 uv, vec3 c, inout int code) {\n float top = uShore.x + (fbm(vec2(uv.x * uAspect * 7., 3.1) + uSeedOff, 3) - .5) * .016;\n float a = smoothstep(top - .0012, top + .0012, uv.y);\n if (a <= 0.) return c;\n float s = fbm(vec2(uv.x * uAspect * 26., uv.y * 260.) + uSeedOff, 3);\n float lit = smoothstep(.42, .72, s) * (1. - smoothstep(top, uShore.y, uv.y) * .7);\n vec3 col = mix(mix(uShoreCol, uGround, .25), uShoreLit, lit);\n col = mix(col, uHaze, hazeOf(uShore.w));\n if (a > .5) code = 32;\n return mix(c, col, a);\n}\nvec3 above(vec2 uv, int oct, inout int code) {\n return shore(uv, ranges(uv, sky(uv, oct), code), code);\n}\nvec3 water(vec2 uv) {\n float t = clamp((uv.y - uShore.y) / (uShore.z - uShore.y), 0., 1.);\n vec3 w = mix(uWaterFar, uWaterDeep, smoothstep(0., 1., t));\n float rip = vnoise(vec2(uv.x * uAspect * 8., uv.y * 240.) + uSeedOff) - .5;\n vec2 m = vec2(uv.x + rip * .014 * (.3 + t), 2. * uShore.y - uv.y + rip * .004);\n int ignore = 0;\n vec3 refl = (above(m, 2, ignore) + above(m + vec2(0., .008 + .02 * t), 1, ignore)) * .5;\n vec3 c = mix(w, refl * vec3(.88, .94, .95), mix(.72, .3, t));\n float sheen = exp(-(uv.y - uShore.y) / .014) * smoothstep(.3, .7, vnoise(vec2(uv.x * uAspect * 12., uv.y * 420.)));\n c = mix(c, uSheen, sheen * .55);\n float line = smoothstep(.64, .82, vnoise(vec2(uv.x * uAspect * 2.5, uv.y * 520.) + uSeedOff * 2.));\n return mix(c, mix(c, uSheen, .4), line * (1. - t) * .7);\n}\nvec3 ground(vec2 uv) {\n float t = clamp((uv.y - uShore.z) / (1. - uShore.z), 0., 1.);\n vec3 c = mix(uGround, uGroundDark, smoothstep(0., .6, t));\n c = mix(c, uGroundWarm, smoothstep(.5, 1., uv.x) * smoothstep(.15, .9, t) * .8);\n float grass = fbm(vec2(uv.x * uAspect * 9., uv.y * 70.) + uSeedOff, 4);\n c *= .84 + .3 * grass;\n vec2 bp = vec2(uv.x * uAspect * 6., uv.y * 11.) + uSeedOff * 1.3;\n float shrub = fbm(bp, 5) + t * .12;\n float toward = fbm(bp + vec2(-.12, -.18), 5) + t * .12;\n float m = smoothstep(.46, .6, shrub) * (1. - t * .5);\n float lit = clamp((shrub - toward) * 6. + .4, 0., 1.);\n vec3 bush = mix(uGroundDark * .8, uGround * 1.12, lit) * (.9 + .2 * grass);\n return mix(c, bush, m * .8);\n}\nvoid main() {\n vec2 uv = plateUv();\n int code = 0;\n vec3 c = above(uv, 5, code);\n float wa = smoothstep(uShore.y - .0008, uShore.y + .0008, uv.y);\n if (wa > 0.) {\n c = mix(c, water(uv), wa);\n if (wa > .5) code = 48;\n float edge = uShore.z + (fbm(vec2(uv.x * uAspect * 3., 8.7) + uSeedOff, 4) - .5) * .045;\n float ga = smoothstep(edge - .003, edge + .003, uv.y);\n c = mix(c, ground(uv), ga);\n if (ga > .5) code = 64;\n }\n outColor = vec4(c, float(code) / 255.);\n}";
5
+ /** Brush strokes over the scene: a short smear along the flow, then strokes laid one a cell, the colour under each. */
6
+ export declare const STROKE_FRAG = "#version 300 es\nprecision highp float;\nprecision highp int;\nuniform vec4 uView;\nuniform vec2 uSize;\nuniform float uAspect;\nuniform vec2 uSeedOff;\nuniform vec3 uHaze;\nuniform float uHazeStep;\nuint hashU(ivec2 p) {\n uvec2 q = uvec2(p) * uvec2(1597334673u, 3812015801u);\n uint n = (q.x ^ q.y) * 1597334673u;\n n ^= n >> 16; n *= 2246822519u; n ^= n >> 13;\n return n;\n}\nfloat rnd(vec2 c) { return float(hashU(ivec2(floor(c))) >> 8) / 16777216.0; }\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3. - 2. * f);\n return mix(mix(rnd(i), rnd(i + vec2(1, 0)), u.x), mix(rnd(i + vec2(0, 1)), rnd(i + 1.), u.x), u.y);\n}\nfloat fbm(vec2 p, int oct) {\n float s = 0.;\n float a = .5;\n float t = 0.;\n for (int k = 0; k < 6; k++) {\n if (k >= oct) break;\n s += a * vnoise(p); t += a;\n p = p * 2.03 + vec2(17.1, 9.3); a *= .5;\n }\n return s / t;\n}\nfloat hazeOf(float depth) { return 1. - pow(1. - uHazeStep, depth); }\nvec2 plateUv() { return uView.xy + gl_FragCoord.xy / uSize * uView.zw; }\n\nuniform sampler2D uBase;\nuniform vec4 uStroke[5];\nout vec4 outColor;\nvec2 toSt(vec2 q) { return (vec2(q.x / uAspect, q.y) - uView.xy) / uView.zw; }\nvoid main() {\n vec2 st = gl_FragCoord.xy / uSize;\n vec4 b = texture(uBase, st);\n int code = int(b.a * 255. + .5);\n int region = min(code / 16, 4);\n vec4 S = uStroke[region];\n float ang = (code == 17) ? -S.x : S.x;\n vec2 dir = vec2(cos(ang), sin(ang));\n vec2 across = vec2(-dir.y, dir.x);\n vec2 uv = plateUv();\n vec2 q = vec2(uv.x * uAspect, uv.y);\n vec2 r = vec2(dot(q, dir), dot(q, across));\n vec2 cell = S.yz;\n vec3 under = b.rgb;\n float wsum = 1.;\n for (int k = 1; k <= 3; k++) {\n for (int sgn = -1; sgn <= 1; sgn += 2) {\n vec3 s = texture(uBase, toSt(q + dir * float(k * sgn) * cell.x * .09)).rgb;\n float w = exp(-dot(s - b.rgb, s - b.rgb) * 400.);\n under += s * w; wsum += w;\n }\n }\n under /= wsum;\n vec2 c0 = floor(r / cell);\n float best = -1.;\n float cov = 0.;\n vec2 bd = vec2(0);\n vec2 bc = vec2(0);\n float bh = 0.;\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n vec2 id = c0 + vec2(i, j);\n uint h = hashU(ivec2(id) + ivec2(code * 7919, code * 104729));\n vec4 hv = vec4(float(h & 255u), float((h >> 8) & 255u), float((h >> 16) & 255u), float(h >> 24)) / 255.;\n vec2 ctr = (id + .5 + (hv.xy - .5) * vec2(.9, .7)) * cell;\n vec2 hs = cell * vec2(.6 + .6 * hv.z, .5 + .35 * hv.w);\n vec2 d = (r - ctr) / hs;\n float taper = max(1. - .3 * d.x * d.x, .2);\n float m = 1. - smoothstep(.7, 1., length(vec2(d.x, d.y / taper)));\n float z = fract(hv.x * 7.13 + hv.w * 3.7);\n if (m > 0. && z > best) { best = z; cov = m; bd = d; bc = ctr; bh = hv.z; }\n }\n }\n vec3 col = under;\n if (cov > 0.) {\n vec4 sc = texture(uBase, toSt(bc.x * dir + bc.y * across));\n float own = (1. - smoothstep(.04, .12, length(sc.rgb - b.rgb))) * step(abs(sc.a - b.a), .001);\n vec3 paint = mix(under, sc.rgb, own);\n paint *= 1. + (bh - .5) * .07;\n paint += (fract(bh * 13.7) - .5) * vec3(.022, .004, -.02);\n float bristle = .72 + .28 * vnoise(vec2(bd.x * 1.3, bd.y * 6. + bh * 31.));\n col = mix(under, paint, cov * S.w * bristle);\n }\n outColor = vec4(col, b.a);\n}";
7
+ /** Glaze, canvas weave in the lights, vignette and varnish over the finished painting. */
8
+ export declare const FINISH_FRAG = "#version 300 es\nprecision highp float;\nprecision highp int;\nuniform vec4 uView;\nuniform vec2 uSize;\nuniform float uAspect;\nuniform vec2 uSeedOff;\nuniform vec3 uHaze;\nuniform float uHazeStep;\nuint hashU(ivec2 p) {\n uvec2 q = uvec2(p) * uvec2(1597334673u, 3812015801u);\n uint n = (q.x ^ q.y) * 1597334673u;\n n ^= n >> 16; n *= 2246822519u; n ^= n >> 13;\n return n;\n}\nfloat rnd(vec2 c) { return float(hashU(ivec2(floor(c))) >> 8) / 16777216.0; }\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3. - 2. * f);\n return mix(mix(rnd(i), rnd(i + vec2(1, 0)), u.x), mix(rnd(i + vec2(0, 1)), rnd(i + 1.), u.x), u.y);\n}\nfloat fbm(vec2 p, int oct) {\n float s = 0.;\n float a = .5;\n float t = 0.;\n for (int k = 0; k < 6; k++) {\n if (k >= oct) break;\n s += a * vnoise(p); t += a;\n p = p * 2.03 + vec2(17.1, 9.3); a *= .5;\n }\n return s / t;\n}\nfloat hazeOf(float depth) { return 1. - pow(1. - uHazeStep, depth); }\nvec2 plateUv() { return uView.xy + gl_FragCoord.xy / uSize * uView.zw; }\n\nuniform sampler2D uPaint;\nuniform vec4 uFinish;\nout vec4 outColor;\nvoid main() {\n vec3 c = texture(uPaint, gl_FragCoord.xy / uSize).rgb;\n vec2 uv = plateUv();\n vec2 q = vec2(uv.x * uAspect, uv.y);\n float g = fbm(q * 2.5 + uSeedOff * .3, 3) - .5;\n c = c * (1. + g * .07) + g * vec3(.012, 0., -.012);\n vec2 w = q / uFinish.x;\n float perPixel = uView.w / uSize.y / uFinish.x;\n vec2 cellW = floor(w);\n vec2 f = fract(w);\n float over = mod(cellW.x + cellW.y, 2.);\n float thread = mix(4. * f.y * (1. - f.y), 4. * f.x * (1. - f.x), over);\n float slub = rnd(over > .5 ? vec2(cellW.x, floor(cellW.y / 7.)) : vec2(floor(cellW.x / 7.), cellW.y) + 91.);\n float weave = (thread - .6) * (.6 + .8 * slub);\n float lum = dot(c, vec3(.3, .59, .11));\n c *= 1. + weave * .045 * smoothstep(.3, .7, lum) * (1. - smoothstep(.22, .34, perPixel));\n vec2 v = uv - .5;\n c *= 1. - uFinish.y * smoothstep(.12, .5, dot(v, v));\n c = vec3(.043, .055, .051) + c * (1. - vec3(.043, .055, .051));\n c = mix(c, c * vec3(1.025, 1., .965), smoothstep(.45, .9, lum));\n outColor = vec4(c, 1.);\n}";
9
+ /** A dab's quad: four corners of a strip, placed by the instance. */
10
+ export declare const DAB_VERT = "#version 300 es\nlayout(location = 0) in vec4 aPos;\nlayout(location = 1) in vec4 aAxis;\nlayout(location = 2) in vec4 aCol;\nlayout(location = 3) in vec4 aMore;\nuniform vec4 uView;\nuniform float uAspect;\nout vec2 vL;\nout vec2 vUv;\nflat out vec4 fPos;\nflat out vec4 fAxis;\nflat out vec4 fCol;\nflat out vec4 fMore;\nvoid main() {\n vec2 corner = vec2(float(gl_VertexID & 1), float(gl_VertexID >> 1)) * 2. - 1.;\n vec2 ax = aAxis.xy;\n vec2 L = corner * 1.1;\n vec2 q = vec2(aPos.x * uAspect, aPos.y) + ax * L.x * aPos.z + vec2(-ax.y, ax.x) * L.y * aPos.w;\n vUv = vec2(q.x / uAspect, q.y);\n vL = L;\n fPos = aPos; fAxis = aAxis; fCol = aCol; fMore = aMore;\n gl_Position = vec4((vUv - uView.xy) / uView.zw * 2. - 1., 0., 1.);\n}";
11
+ /** The shapes: blot, spire, crown, wall, leaf, stem. Each gives a distance (inside below 0) and a colour. */
12
+ export declare const DAB_FRAG = "#version 300 es\nprecision highp float;\nprecision highp int;\nuniform vec4 uView;\nuniform vec2 uSize;\nuniform float uAspect;\nuniform vec2 uSeedOff;\nuniform vec3 uHaze;\nuniform float uHazeStep;\nuint hashU(ivec2 p) {\n uvec2 q = uvec2(p) * uvec2(1597334673u, 3812015801u);\n uint n = (q.x ^ q.y) * 1597334673u;\n n ^= n >> 16; n *= 2246822519u; n ^= n >> 13;\n return n;\n}\nfloat rnd(vec2 c) { return float(hashU(ivec2(floor(c))) >> 8) / 16777216.0; }\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3. - 2. * f);\n return mix(mix(rnd(i), rnd(i + vec2(1, 0)), u.x), mix(rnd(i + vec2(0, 1)), rnd(i + 1.), u.x), u.y);\n}\nfloat fbm(vec2 p, int oct) {\n float s = 0.;\n float a = .5;\n float t = 0.;\n for (int k = 0; k < 6; k++) {\n if (k >= oct) break;\n s += a * vnoise(p); t += a;\n p = p * 2.03 + vec2(17.1, 9.3); a *= .5;\n }\n return s / t;\n}\nfloat hazeOf(float depth) { return 1. - pow(1. - uHazeStep, depth); }\nvec2 plateUv() { return uView.xy + gl_FragCoord.xy / uSize * uView.zw; }\n\nin vec2 vL;\nin vec2 vUv;\nflat in vec4 fPos;\nflat in vec4 fAxis;\nflat in vec4 fCol;\nflat in vec4 fMore;\nout vec4 outColor;\nvec2 leafSide(vec2 p, float seed, out float rib) {\n float x = p.x;\n float hw = fPos.w / fPos.z * .5 * 2.75 * x * (1. - x) * (1.5 - .5 * x) * smoothstep(1.02, .7, x * x);\n hw *= 1. - .035 * fract(x * 24. + seed * 7.);\n rib = abs(p.y);\n float d = max(abs(p.y) - hw, max(-x, x - 1.));\n float vein = abs(fract((x - abs(p.y) * 1.4) * 6. + seed) - .5);\n return vec2(d, smoothstep(.04, 0., vein - .44) * step(.03, abs(p.y)));\n}\nvec2 leafHand(vec2 p, float seed, float lobes, out float rib) {\n vec2 v = p - vec2(.36, 0.);\n float a = atan(v.y, v.x);\n float r = length(v);\n float R = .22;\n rib = 9.;\n for (int k = 0; k < 5; k++) {\n if (float(k) >= lobes) break;\n float side = (k % 2 == 1) ? 1. : -1.;\n float phi = side * float((k + 1) / 2) * (lobes > 3. ? .8 : .95);\n float len = .64 - .14 * float((k + 1) / 2);\n float t = abs(a - phi) / .74;\n R = max(R, len * pow(max(0., 1. - t), .55));\n rib = min(rib, r * abs(sin(a - phi)) + step(1.2, abs(a - phi)));\n }\n R *= 1. - .035 * fract(a * 13. + seed * 5.);\n return vec2(r - R, 0.);\n}\nvec4 leaf() {\n vec2 p = vec2((vL.x + 1.) * .5, vL.y * fPos.w / fPos.z * .5);\n float rib;\n vec2 s = fMore.y < 2. ? leafSide(p, fAxis.w, rib) : leafHand(p, fAxis.w, fMore.y, rib);\n float aa = fwidth(s.x) * .8;\n float alpha = 1. - smoothstep(-aa, aa, s.x);\n vec2 lightDir = normalize(vec2(-1., -1.3));\n float L = fMore.x;\n float fold = dot(vec2(-fAxis.y, fAxis.x), lightDir) * sign(p.y) * .5 + .5;\n float inner = clamp(-s.x / .07, 0., 1.);\n vec3 c = fCol.rgb * mix(.74, 1.12, fold * (.45 + .55 * L));\n c *= .86 + .28 * vnoise(vec2(p.x * 3., p.y * 6.) + fAxis.w * 60.);\n float streak = vnoise(vec2(p.x * 5., p.y * 42.) + fAxis.w * 30.);\n c *= .92 + .16 * streak;\n c += (vnoise(vec2(p.x * 2.5, p.y * 14.) + fAxis.w * 17.) - .5) * vec3(.05, .035, -.03);\n c += vec3(.05, .06, .045) * L * fold * inner * (1. - inner) * 4. * smoothstep(.15, .6, p.x);\n float line = (1. - smoothstep(.002, .009, rib)) * smoothstep(0., .06, p.x) * (1. - .7 * p.x);\n vec3 vein = mix(c * .66, c * 1.22 + .02, smoothstep(.2, .6, L));\n c = mix(c, vein, line * (fMore.y < 2. ? .7 : .4) + s.y * .2 * inner);\n c = mix(c, c * .8, (1. - smoothstep(0., .012, -s.x)) * (1. - L) * .6);\n return vec4(c, alpha);\n}\nvec4 spire() {\n float t = (vL.x + 1.) * .5;\n float w = (1. - t) * (.62 + 1.5 * t) * (.8 + .4 * vnoise(vec2(t * 16., vL.y * 2.) + fAxis.w * 40.));\n float d = max(abs(vL.y) - w, -vL.x - 1.);\n float aa = fwidth(d) * (1. + fMore.w * 2.5);\n float lit = smoothstep(.4, -.7, vL.y / max(w, .05)) * fMore.x;\n vec3 c = fCol.rgb * (.75 + .6 * lit) * (.85 + .3 * vnoise(vL * vec2(9., 3.) + fAxis.w * 30.));\n return vec4(c, 1. - smoothstep(-aa, aa, d));\n}\nvec4 crown() {\n float n = vnoise(vL * 2.4 + fAxis.w * 40.) * .65 + vnoise(vL * 6. + fAxis.w * 13.) * .35;\n float d = max(length(vL * vec2(1., 1.1)) - (.66 + .38 * n), -vL.x - .8);\n float aa = fwidth(d) * (1. + fMore.w * 2.5);\n float lit = clamp(.5 + .6 * dot(normalize(vL + .001), normalize(vec2(.7, -.7))), 0., 1.) * fMore.x;\n vec3 c = fCol.rgb * (.72 + .6 * lit) * (.85 + .3 * vnoise(vL * 7. + fAxis.w * 20.));\n return vec4(c, 1. - smoothstep(-aa, aa, d));\n}\nvec4 wall() {\n float d = max(abs(vL.x), abs(vL.y)) - 1.;\n float aa = fwidth(d) * (1. + fMore.w * 1.5);\n float side = smoothstep(1. - 2. * fMore.y - .08, 1. - 2. * fMore.y + .08, vL.y);\n vec3 c = fCol.rgb * mix(.8 + .15 * fMore.x, .72, side);\n c *= 1. - .25 * smoothstep(.7, .85, vL.x);\n c *= .95 + .1 * vnoise(vL * vec2(3., 5.) + fAxis.w * 20.);\n return vec4(c, 1. - smoothstep(-aa, aa, d));\n}\nvec4 blot() {\n float n = vnoise(vL * 2.2 + fAxis.w * 50.);\n float d = length(vL) + (n - .5) * .45;\n vec3 c = fCol.rgb * (.85 + .3 * vnoise(vL * 5. + fAxis.w * 9.));\n return vec4(c, 1. - smoothstep(.72, .95, d));\n}\nvec4 stem() {\n float d = abs(vL.y) - 1.;\n float aa = fwidth(d) * .9;\n vec3 c = fCol.rgb * (1. + .4 * smoothstep(.2, -.8, vL.y));\n return vec4(c, (1. - smoothstep(-aa, aa, d)) * smoothstep(1.1, .9, abs(vL.x)));\n}\nvoid main() {\n int kind = int(fAxis.z + .5);\n vec4 s = kind == 0 ? blot() : kind == 1 ? spire() : kind == 2 ? crown() : kind == 3 ? wall() : kind == 4 ? leaf() : stem();\n if (fMore.z > 0.) {\n if (vUv.y < fMore.z) discard;\n s.a *= .55 + .45 * smoothstep(.25, .6, vnoise(vec2(vUv.x * uAspect * 60., vUv.y * 900.)));\n s.a *= 1. - .6 * smoothstep(0., fPos.z * 2.4, vUv.y - fMore.z);\n }\n vec3 c = mix(s.rgb, uHaze, hazeOf(fMore.w));\n outColor = vec4(c, s.a * fCol.a);\n}";
13
+ /** The plate as a backdrop: cover-fitted into the target rectangle, locked to the screen. */
14
+ export declare const BACKDROP_FRAG = "#version 300 es\nprecision highp float;\nuniform sampler2D uPlate;\nuniform vec4 uCrop;\nuniform vec4 uRect;\nout vec4 outColor;\nvoid main() {\n vec2 f = (gl_FragCoord.xy - uRect.xy) / uRect.zw;\n outColor = vec4(texture(uPlate, uCrop.xy + vec2(f.x, 1. - f.y) * uCrop.zw).rgb, 1.);\n}";
@@ -0,0 +1,42 @@
1
+ import type { PlateRecipe } from "./recipe.js";
2
+ /** Bumped whenever the passes paint the same plan differently, so a cached plate of an older painter is not reused. */
3
+ export declare const PAINTER_VERSION = 1;
4
+ /** Crest samples across the plate for each range. */
5
+ export declare const RIDGE_SAMPLES = 512;
6
+ /** The most ranges a plate holds. */
7
+ export declare const MAX_RANGES = 4;
8
+ /** What the host may change when it includes the module (keel.module.json's inputs). */
9
+ export interface PlateSettings {
10
+ /** Decides every shape. A whole number from 0. */
11
+ readonly seed?: number;
12
+ /** Scales every depth step toward the haze, 0..2; 1 is the recipe's air. */
13
+ readonly haze?: number;
14
+ /** Moves the clouds' cover, -0.5 (clearer) .. 0.5 (heavier). */
15
+ readonly clouds?: number;
16
+ /** False leaves the near leaves out. */
17
+ readonly foliage?: boolean;
18
+ }
19
+ /** One uniform: its name, its components (1..4) and its values (several for an array). */
20
+ export type PlanUniform = readonly [name: string, size: 1 | 2 | 3 | 4, values: Float32Array];
21
+ /** Everything the GPU paints from. */
22
+ export interface PlatePlan {
23
+ readonly digest: string;
24
+ /** Width over height of the whole plate. */
25
+ readonly aspect: number;
26
+ readonly uniforms: readonly PlanUniform[];
27
+ /** Crest y of each range, RIDGE_SAMPLES across, one row a range (MAX_RANGES rows). */
28
+ readonly ridges: Float32Array;
29
+ /** The middle distance's dabs, drawn under the brush strokes. */
30
+ readonly scene: Float32Array;
31
+ /** The near leaves, drawn over the brush strokes. */
32
+ readonly foliage: Float32Array;
33
+ }
34
+ /**
35
+ * The plan for a recipe and settings: uniforms, crests and dabs, with their digest.
36
+ *
37
+ * @param recipe What the plate holds (LAKE_VALLEY, or one of your own).
38
+ * @param settings The seed and the host's settings.
39
+ * @returns The plan; `paint` it with a painter from `createPlatePainter`.
40
+ * @throws RangeError on a recipe or setting out of range.
41
+ */
42
+ export declare function planPlate(recipe: PlateRecipe, settings?: PlateSettings): PlatePlan;