@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,136 @@
1
+ /** Two numbers: a span on one axis, or a point. */
2
+ export type Pair = readonly [number, number];
3
+ /** A mountain range, one plane of depth. */
4
+ export interface RangeRecipe {
5
+ /** Where it stands across the plate; it tapers away outside. */
6
+ readonly x: Pair;
7
+ /** The y its foot fades out at, into mist or the next plane. */
8
+ readonly base: number;
9
+ /** Peaks as `[x, y of the summit]`; the seed moves each a little and adds smaller ones. */
10
+ readonly peaks: readonly Pair[];
11
+ /** How broken the crest is, 0..1. */
12
+ readonly rough: number;
13
+ /** Depth steps toward the haze: each moves the colour a `hazeStep` of the way. */
14
+ readonly depth: number;
15
+ /** The faces the light falls on, and the faces turned away. */
16
+ readonly lit: string;
17
+ readonly shade: string;
18
+ }
19
+ /** A row of trees, or a wooded bank of round crowns. */
20
+ export interface TreeRecipe {
21
+ readonly kind: "spire" | "crown";
22
+ readonly x: Pair;
23
+ /** The y of their feet: one number for a row, a span for a bank. */
24
+ readonly y: Pair;
25
+ readonly count: number;
26
+ /** Heights as a share of the plate's height. */
27
+ readonly height: Pair;
28
+ readonly color: string;
29
+ readonly lit: string;
30
+ readonly depth: number;
31
+ }
32
+ /** A small town: flat walls and a few towers on a rise. */
33
+ export interface TownRecipe {
34
+ readonly x: Pair;
35
+ /** The y the walls stand on. */
36
+ readonly y: number;
37
+ readonly walls: number;
38
+ readonly towers: number;
39
+ /** Wall heights, then tower heights, as shares of the plate's height. */
40
+ readonly height: Pair;
41
+ readonly tower: Pair;
42
+ readonly lit: string;
43
+ readonly shade: string;
44
+ readonly rock: string;
45
+ readonly depth: number;
46
+ }
47
+ /** A leafy branch: a curve from `from` through `bend` to `to`, leaves along it. */
48
+ export interface BranchRecipe {
49
+ readonly from: Pair;
50
+ readonly bend: Pair;
51
+ readonly to: Pair;
52
+ readonly leaves: number;
53
+ /** Leaf length as a share of the plate's height. */
54
+ readonly size: number;
55
+ }
56
+ /** A mass of leaves filling a box, darker toward its heart. */
57
+ export interface MassRecipe {
58
+ readonly x: Pair;
59
+ readonly y: Pair;
60
+ readonly leaves: number;
61
+ readonly size: number;
62
+ }
63
+ /** Brush strokes of one region: angle in radians (0 runs right, y down), length and width as shares of the width. */
64
+ export interface StrokeRecipe {
65
+ readonly angle: number;
66
+ readonly length: number;
67
+ readonly width: number;
68
+ readonly opacity: number;
69
+ }
70
+ /** The whole plate. */
71
+ export interface PlateRecipe {
72
+ /** Width over height. */
73
+ readonly aspect: number;
74
+ /** The colour of the air, and how far each depth step moves toward it. */
75
+ readonly haze: string;
76
+ readonly hazeStep: number;
77
+ readonly sky: {
78
+ readonly top: string;
79
+ readonly low: string;
80
+ /** The darker, bluer top-left corner. */
81
+ readonly corner: string;
82
+ readonly cloudLit: string;
83
+ readonly cloudShade: string;
84
+ /** The cloud band's top and bottom y, its centre x, and how much sky it covers (0..1). */
85
+ readonly band: Pair;
86
+ readonly centre: number;
87
+ readonly cover: number;
88
+ };
89
+ /** Back to front, at most four. */
90
+ readonly ranges: readonly RangeRecipe[];
91
+ readonly shore: {
92
+ readonly top: number;
93
+ readonly y: number;
94
+ readonly color: string;
95
+ readonly lit: string;
96
+ };
97
+ readonly water: {
98
+ readonly near: number;
99
+ readonly far: string;
100
+ readonly deep: string;
101
+ readonly sheen: string;
102
+ };
103
+ readonly ground: {
104
+ readonly color: string;
105
+ readonly warm: string;
106
+ readonly dark: string;
107
+ };
108
+ readonly trees: readonly TreeRecipe[];
109
+ readonly town?: TownRecipe;
110
+ readonly leaves: {
111
+ readonly lit: string;
112
+ readonly mid: string;
113
+ readonly shadow: string;
114
+ readonly deep: string;
115
+ /** No leaf crosses this x. */
116
+ readonly bound: number;
117
+ readonly branches: readonly BranchRecipe[];
118
+ readonly masses: readonly MassRecipe[];
119
+ };
120
+ readonly strokes: {
121
+ readonly sky: StrokeRecipe;
122
+ readonly ridges: StrokeRecipe;
123
+ readonly shore: StrokeRecipe;
124
+ readonly water: StrokeRecipe;
125
+ readonly ground: StrokeRecipe;
126
+ };
127
+ /** The canvas weave's period as a share of the width, and the corners' darkening (0..1). */
128
+ readonly weave: number;
129
+ readonly vignette: number;
130
+ }
131
+ /**
132
+ * A lake in a valley under an overcast sky: mauve far peaks on the right, a blue-green range left of centre, low
133
+ * hills, a pale far shore with a small town, a row of dark spires, a still lake, and a leafy branch and mass of
134
+ * broad leaves in the near left.
135
+ */
136
+ export declare const LAKE_VALLEY: PlateRecipe;
@@ -0,0 +1,4 @@
1
+ import { type Dab } from "./dab.js";
2
+ import type { PlateRecipe } from "./recipe.js";
3
+ /** Every dab of the middle distance, reflections first, then far to near. */
4
+ export declare function sceneDabs(recipe: PlateRecipe, seed: number): Dab[];
@@ -0,0 +1 @@
1
+ export * from './plate-painter/index.js'
@@ -0,0 +1,50 @@
1
+ {
2
+ "protocol": "keel-module-inputs@1",
3
+ "fields": [
4
+ {
5
+ "key": "seed",
6
+ "label": "Seed",
7
+ "required": false,
8
+ "help": "Decides every peak, tree, cloud and leaf inside the recipe's bounds.",
9
+ "type": "number",
10
+ "min": 0,
11
+ "max": 999999,
12
+ "step": 1,
13
+ "default": 0
14
+ },
15
+ {
16
+ "key": "haze",
17
+ "label": "Haze",
18
+ "required": false,
19
+ "help": "How thick the air is: 1 is the recipe's.",
20
+ "type": "number",
21
+ "min": 0,
22
+ "max": 2,
23
+ "step": 0.05,
24
+ "control": "slider",
25
+ "default": 1
26
+ },
27
+ {
28
+ "key": "clouds",
29
+ "label": "Clouds",
30
+ "required": false,
31
+ "help": "Below 0 clears the sky, above 0 fills it.",
32
+ "placement": "advanced",
33
+ "type": "number",
34
+ "min": -0.5,
35
+ "max": 0.5,
36
+ "step": 0.05,
37
+ "control": "slider",
38
+ "default": 0
39
+ },
40
+ {
41
+ "key": "foliage",
42
+ "label": "Near leaves",
43
+ "required": false,
44
+ "help": "Leave the near branch and leaves out when something else fills the foreground.",
45
+ "placement": "advanced",
46
+ "type": "boolean",
47
+ "default": true
48
+ }
49
+ ]
50
+ }
@@ -0,0 +1,384 @@
1
+ // plate-painter@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var Q={aspect:1.6,haze:"#b5bfbd",hazeStep:.25,sky:{top:"#5d8090",low:"#a9b9b6",corner:"#43606e",cloudLit:"#c9cec6",cloudShade:"#8a9fa6",band:[.08,.3],centre:.78,cover:.55},ranges:[{x:[.6,1.08],base:.47,peaks:[[.8,.335],[.93,.355],[.69,.39]],rough:.5,depth:2.3,lit:"#9a8aa2",shade:"#665c7a"},{x:[.12,.7],base:.475,peaks:[[.3,.37],[.45,.342],[.58,.385]],rough:.6,depth:1.2,lit:"#7fa0ad",shade:"#46677a"},{x:[-.1,1.1],base:.505,peaks:[[.22,.44],[.6,.452],[.86,.448]],rough:.4,depth:.7,lit:"#5b7566",shade:"#34504f"}],shore:{top:.5,y:.52,color:"#95937c",lit:"#bdb8a0"},water:{near:.72,far:"#7a9a9e",deep:"#3f6469",sheen:"#bfc6bc"},ground:{color:"#3b4b40",warm:"#574a37",dark:"#222d28"},trees:[{kind:"crown",x:[.27,.42],y:[.505,.54],count:26,height:[.018,.034],color:"#27352f",lit:"#46594a",depth:.7},{kind:"spire",x:[.35,.5],y:[.52,.522],count:8,height:[.035,.065],color:"#1f2b26",lit:"#3b4d43",depth:.6}],town:{x:[.855,1],y:.522,walls:7,towers:2,height:[.014,.03],tower:[.045,.06],lit:"#c9bfa8",shade:"#878372",rock:"#7d7766",depth:1.2},leaves:{lit:"#6b7859",mid:"#46553f",shadow:"#2a3a33",deep:"#141b17",bound:.3,branches:[{from:[-.02,.02],bend:[.17,0],to:[.27,.4],leaves:26,size:.14}],masses:[{x:[0,.29],y:[.42,1.02],leaves:96,size:.17}]},strokes:{sky:{angle:-.17,length:.04,width:.011,opacity:.3},ridges:{angle:-.5,length:.012,width:.003,opacity:.4},shore:{angle:0,length:.014,width:.0025,opacity:.5},water:{angle:0,length:.05,width:.006,opacity:.6},ground:{angle:-.12,length:.026,width:.009,opacity:.6}},weave:.001,vignette:.08};var b={blot:0,spire:1,crown:2,wall:3,leaf:4,stem:5},R=16;function l(e){let o=parseInt(e.slice(1,7),16);if(e.length!==7||!Number.isInteger(o))throw new TypeError(`plate-painter: "${e}" is not #rrggbb.`);return[(o>>16)/255,(o>>8&255)/255,(o&255)/255]}function P(e,o,t){return[e[0]+(o[0]-e[0])*t,e[1]+(o[1]-e[1])*t,e[2]+(o[2]-e[2])*t]}function D(e){let o=new Float32Array(e.length*R);return e.forEach((t,n)=>{o.set([t.x,t.y,t.len,t.wid,t.ax,t.ay,t.kind,t.seed,t.color[0],t.color[1],t.color[2],t.alpha,t.light,t.variant,t.water,t.depth],n*R)}),o}function v(e,o){let t=Math.imul(e^2654435769,2246822507)^Math.imul(o+1663821227,3266489909);return t=Math.imul(t^t>>>16,2146121005),t=Math.imul(t^t>>>15,2221713035),(t^t>>>16)>>>0}function x(e,o){let t=0,n=()=>(t+=1,v(v(e,o),t)/4294967296);return Object.assign(n,{within:(a,i)=>a+(i-a)*n()})}function ee(e){let o=e<0?0:Math.min(e,1);return o*o*(3-2*o)}function F(e,o){let t=Math.floor(o),n=ee(o-t),r=v(e,t)/4294967296,a=v(e,t+1)/4294967296;return r+(a-r)*n}function _(e,o,t){let n=1+t*t,r=(1-t*t)/n,a=2*t/n,i=e*r-o*a,s=e*a+o*r,c=Math.sqrt(i*i+s*s)||1;return[i/c,s/c]}function U(e){let o=2166136261,t=16777619;for(let n of e){let r=new Uint8Array(n.buffer,n.byteOffset,n.byteLength);for(let a of r)o=Math.imul(o^a,16777619),t=Math.imul(t^a,16777629)^o>>>7}return(o>>>0).toString(16).padStart(8,"0")+(t>>>0).toString(16).padStart(8,"0")}var C=(e,o)=>{let[t,n,r]=[e[0]??[0,0],e[1]??[0,0],e[2]??[0,0]],a=1-o;return[a*a*t[0]+2*a*o*n[0]+o*o*r[0],a*a*t[1]+2*a*o*n[1]+o*o*r[1]]},te=(e,o)=>{let[t,n,r]=[e[0]??[0,0],e[1]??[0,0],e[2]??[0,0]];return[2*(1-o)*(n[0]-t[0])+2*o*(r[0]-n[0]),2*(1-o)*(n[1]-t[1])+2*o*(r[1]-n[1])]},S=(e,o)=>{let t=Math.sqrt(e*e+o*o)||1;return[e/t,o/t]};function G(e,o){let t=Math.min(Math.max(o,0),1)*(e.length-1),n=Math.min(Math.floor(t),e.length-2);return P(e[n]??[0,0,0],e[n+1]??[0,0,0],t-n)}function z(e,o,t){let n=o()<.6?1:3+2*Math.floor(o()*2),r=t.length/2,a=r*(n===1?o.within(.42,.55):o.within(.8,.95)),[i,s]=t.axis,c=Math.abs(i)*r+Math.abs(s)*a,u=Math.min(t.base[0]+i*r,e.maxX-c),f=(-i-s)*.12,d=(t.deep?o.within(.05,.4):o.within(.35,.95))+f;return{x:u/e.aspect,y:t.base[1]+s*r,len:r,wid:a,ax:i,ay:s,kind:b.leaf,seed:o(),color:G(e.ramp,d*.92),alpha:1,light:Math.min(Math.max(d,0),.85),variant:n,water:0,depth:t.deep?.25:0}}function I(e,o,t){let n=[];for(let a=0;a<14;a+=1){let i=C(e,a/14),s=C(e,(a+1)/14),[c,u]=[s[0]-i[0],s[1]-i[1]],f=Math.sqrt(c*c+u*u)*.6,[d,m]=S(c,u);n.push({x:(i[0]+s[0])/2/o,y:(i[1]+s[1])/2,len:f,wid:t*(1-.7*a/14),ax:d,ay:m,kind:b.stem,seed:a/14,color:[.16,.16,.12],alpha:1,light:.4,variant:1,water:0,depth:0})}return n}function oe(e,o,t){let n=i=>[i[0]*e.aspect,i[1]],r=[n(o.from),n(o.bend),n(o.to)],a=[];for(let i=0;i<o.leaves;i+=1){let s=(i+t.within(0,.8))/o.leaves,[c,u]=S(...te(r,s)),f=i%2===0?1:-1,[d,m]=_(c,u,f*t.within(.35,.9)),w=S(d,m+t.within(.2,.9)),g=C(r,s),k=o.size*t.within(.6,1.25)*(1-.35*s);a.push(z(e,t,{base:g,axis:w,length:k,deep:t()<.35}))}return{stems:I(r,e.aspect,.006),leaves:a}}function re(e,o,t){let[n,r]=[o.x[0]*e.aspect,o.x[1]*e.aspect],[a,i]=o.y,s=[];for(let f=0;f<30;f+=1){let d=t.within(n,n+(r-n)*.5),m=t.within(.06,.12);s.push({x:d/e.aspect,y:t.within(a+.24,i),len:m,wid:m*t.within(.6,1),ax:1,ay:0,kind:b.blot,seed:t(),color:G(e.ramp,t.within(0,.12)),alpha:.95,light:0,variant:1,water:0,depth:0})}let c=[];for(let f=0;f<4;f+=1){let d=[t.within(n,n+(r-n)*.4),i+.02],m=[t.within(n+(r-n)*.4,r-.04),t.within(a,a+(i-a)*.5)];c.push(...I([d,[d[0]-.02,(d[1]+m[1])/2],m],e.aspect,.005))}let u=[];for(let f=0;f<o.leaves;f+=1)u.push(ne(e,o,t,[n,r,a,i]));return{blots:s,stems:c,leaves:u}}function ne(e,o,t,n){let[r=0,a=0,i=0,s=0]=n,c=t(),u=r+(a-r)*(.35*c+.65*c*c)*t.within(.85,1.12),f=t.within(i,s),[d,m]=S(u-(r-.1),f-(s+.1)),w=S(..._(d,m,t.within(-.5,.5))),g=(f-i)/(s-i),k=o.size*t.within(.65,1.2)*(.75+.45*g),J=t()<.3+.35*(1-(u-r)/(a-r));return z(e,t,{base:[u,f],axis:S(w[0],w[1]+.25),length:k,deep:J})}function O(e,o){let{leaves:t,aspect:n}={leaves:e.leaves,aspect:e.aspect},r={ramp:[l(t.deep),l(t.shadow),l(t.mid),l(t.lit)],maxX:t.bound*n,aspect:n},a=[],i=[],s=[];t.masses.forEach((f,d)=>{let m=re(r,f,x(o,400+d));a.push(...m.blots),i.push(...m.stems),s.push(...m.leaves)}),t.branches.forEach((f,d)=>{let m=oe(r,f,x(o,500+d));i.push(...m.stems),s.push(...m.leaves)});let c=s.filter(f=>f.depth>0),u=s.filter(f=>f.depth===0);return[...a,...i,...c,...u]}var W={ax:0,ay:-1};function ae(e,o){let t=o.within(e.x[0],e.x[1]),n=o.within(e.y[0],e.y[1]),r=o.within(e.height[0],e.height[1]),a=e.kind==="spire",i=a?r/2:r*.55,s=a?r*o.within(.1,.15):r*o.within(.42,.62),c={x:t,y:n-i*.92,len:i,wid:s,...W,kind:a?b.spire:b.crown,seed:o(),color:P(l(e.color),l(e.lit),o.within(0,.25)),alpha:1,light:o.within(.35,.7),variant:1,water:0,depth:e.depth};return{foot:n,dab:c}}function ie(e,o,t){let n=t.tower?e.tower:e.height,r=o.within(n[0],n[1]),a=t.tower?o.within(.006,.01):o.within(.012,.026);return{x:t.left+a/2,y:t.foot-r/2,len:r/2,wid:a*.8,...W,kind:b.wall,seed:o(),color:P(l(e.lit),l(e.shade),o.within(0,.3)),alpha:1,light:o.within(.55,.9),variant:o.within(.2,.45),water:0,depth:e.depth}}function se(e,o){let t=e.x[1]-e.x[0],n={x:e.x[0]+t/2,y:e.y-.004,len:t*.62,wid:.011,ax:1,ay:0,kind:b.blot,seed:o(),color:l(e.rock),alpha:1,light:.6,variant:1,water:0,depth:e.depth},r=[{foot:e.y-.001,dab:n}],a=new Set;for(;a.size<Math.min(e.towers,e.walls);)a.add(Math.floor(o()*e.walls));for(let i=0;i<e.walls;i+=1){let s=e.x[0]+t*(i+o.within(-.2,.2))/e.walls,c=e.y-.008+o.within(-.002,.003);r.push({foot:c,dab:ie(e,o,{left:s,foot:c,tower:a.has(i)})})}return r}function ce(e,o,t){return{...e,y:2*o-e.y,len:e.len*1.08,ay:-e.ay,color:P(e.color,l(t),.3),alpha:.62,water:o}}function B(e,o){let t=[];return e.trees.forEach((r,a)=>{let i=x(o,200+a);for(let s=0;s<r.count;s+=1)t.push(ae(r,i))}),e.town&&t.push(...se(e.town,x(o,300))),t.sort((r,a)=>r.foot-a.foot),[...t.filter(({foot:r})=>r<e.water.near-.02).map(({foot:r,dab:a})=>ce(a,Math.max(r,e.shore.y),e.water.deep)),...t.map(({dab:r})=>r)]}var N=1,y=512,p=4;function ue(e,o){let t=0;for(let[n,r,a]of e){let i=Math.abs(o-n)/a,s=.5/(1+3*i*i)+.5*Math.max(0,1-.8*i);t=Math.max(t,r*s)}return t}function fe(e,o,t){let n=x(o,100+t),r=e.peaks.map(([s,c])=>{let u=e.base-c+n.within(-.008,.008);return[s+n.within(-.02,.02),u,u*n.within(1.1,1.6)]}),a=r.reduce((s,c)=>s+c[1],0)/Math.max(r.length,1),i=2+Math.floor(n()*3);for(let s=0;s<i;s+=1){let c=a*n.within(.25,.55);r.push([n.within(e.x[0],e.x[1]),c,c*n.within(1.2,2)])}return r}function le(e,o,t){let n=fe(e,o,t),r=new Float32Array(y),a=v(o,900+t);for(let i=0;i<y;i+=1){let s=i/(y-1),c=Math.min(1,Math.max(0,(s-e.x[0])/.08),Math.max(0,(e.x[1]-s)/.08)),u=ue(n,s)*c*c*(3-2*c),f=(F(a,s*26)-.5)*.014+(F(a+1,s*97)-.5)*.005;u+=f*e.rough*Math.min(1,u*12),r[i]=u>5e-4?e.base-u:e.base+.004}return r}var h=(...e)=>new Float32Array(e.flatMap(o=>typeof o=="number"?[o]:[...o])),de=(e,o)=>[e.angle,e.length*o,e.width*o,e.opacity];function me(e,o){let t=new Float32Array(p*3),n=new Float32Array(p*3),r=new Float32Array(p*4);return e.ranges.forEach((a,i)=>{t.set(l(a.lit),i*3),n.set(l(a.shade),i*3);let s=a.depth*o;r.set([s,a.base,.0012+s*.0011,.05],i*4)}),[["uRangeLit",3,t],["uRangeShade",3,n],["uRangeInfo",4,r],["uRanges",1,h(e.ranges.length)]]}function he(e,o){let{sky:t,shore:n,water:r,ground:a,strokes:i}=e,s=o.seed,c=h(v(s,1)%997*.37,v(s,2)%991*.41),u=[i.sky,i.ridges,i.shore,i.water,i.ground];return[["uAspect",1,h(e.aspect)],["uSeedOff",2,c],["uHaze",3,h(l(e.haze))],["uHazeStep",1,h(e.hazeStep)],["uSkyTop",3,h(l(t.top))],["uSkyLow",3,h(l(t.low))],["uSkyCorner",3,h(l(t.corner))],["uCloudLit",3,h(l(t.cloudLit))],["uCloudShade",3,h(l(t.cloudShade))],["uCloud",4,h(t.band[0],t.band[1],t.centre,t.cover-o.clouds*.4)],...me(e,o.haze),["uShore",4,h(n.top,n.y,r.near,.6*o.haze)],["uShoreCol",3,h(l(n.color))],["uShoreLit",3,h(l(n.lit))],["uWaterFar",3,h(l(r.far))],["uWaterDeep",3,h(l(r.deep))],["uSheen",3,h(l(r.sheen))],["uGround",3,h(l(a.color))],["uGroundWarm",3,h(l(a.warm))],["uGroundDark",3,h(l(a.dark))],["uStroke",4,new Float32Array(u.flatMap(f=>de(f,e.aspect)))],["uFinish",4,h(e.weave*e.aspect,e.vignette,o.haze,0)]]}function be(e,o){let t=n=>{throw new RangeError(`plate-painter: ${n}`)};e.aspect>0||t("aspect must be above 0."),e.ranges.length>p&&t(`at most ${p} ranges.`),(!Number.isInteger(o.seed)||o.seed<0)&&t("seed must be a whole number from 0."),o.haze>=0&&o.haze<=2||t("haze must be within 0..2."),o.clouds>=-.5&&o.clouds<=.5||t("clouds must be within -0.5..0.5."),e.shore.y<e.water.near||t("the water's near edge must be below the shore.")}function pe(e,o={}){let t={seed:o.seed??0,haze:o.haze??1,clouds:o.clouds??0,foliage:o.foliage??!0};be(e,t);let n=new Float32Array(y*p).fill(1);e.ranges.forEach((u,f)=>{n.set(le(u,t.seed,f),f*y)});let r=he(e,t),a=D(B(e,t.seed)),i=D(t.foliage?O(e,t.seed):[]),s=new Float32Array(r.map(([u])=>u.length));return{digest:U([h(N),s,...r.map(([,,u])=>u),n,a,i]),aspect:e.aspect,uniforms:r,ridges:n,scene:a,foliage:i}}var T=`#version 300 es
3
+ precision highp float;
4
+ precision highp int;
5
+ uniform vec4 uView;
6
+ uniform vec2 uSize;
7
+ uniform float uAspect;
8
+ uniform vec2 uSeedOff;
9
+ uniform vec3 uHaze;
10
+ uniform float uHazeStep;
11
+ uint hashU(ivec2 p) {
12
+ uvec2 q = uvec2(p) * uvec2(1597334673u, 3812015801u);
13
+ uint n = (q.x ^ q.y) * 1597334673u;
14
+ n ^= n >> 16; n *= 2246822519u; n ^= n >> 13;
15
+ return n;
16
+ }
17
+ float rnd(vec2 c) { return float(hashU(ivec2(floor(c))) >> 8) / 16777216.0; }
18
+ float vnoise(vec2 p) {
19
+ vec2 i = floor(p);
20
+ vec2 f = fract(p);
21
+ vec2 u = f * f * (3. - 2. * f);
22
+ 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);
23
+ }
24
+ float fbm(vec2 p, int oct) {
25
+ float s = 0.;
26
+ float a = .5;
27
+ float t = 0.;
28
+ for (int k = 0; k < 6; k++) {
29
+ if (k >= oct) break;
30
+ s += a * vnoise(p); t += a;
31
+ p = p * 2.03 + vec2(17.1, 9.3); a *= .5;
32
+ }
33
+ return s / t;
34
+ }
35
+ float hazeOf(float depth) { return 1. - pow(1. - uHazeStep, depth); }
36
+ vec2 plateUv() { return uView.xy + gl_FragCoord.xy / uSize * uView.zw; }
37
+ `,A=`#version 300 es
38
+ void main() {
39
+ vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
40
+ gl_Position = vec4(p * 2. - 1., 0., 1.);
41
+ }`,V=`${T}
42
+ uniform vec3 uSkyTop, uSkyLow, uSkyCorner, uCloudLit, uCloudShade;
43
+ uniform vec4 uCloud;
44
+ uniform highp sampler2D uRidge;
45
+ uniform float uRanges;
46
+ uniform vec3 uRangeLit[4];
47
+ uniform vec3 uRangeShade[4];
48
+ uniform vec4 uRangeInfo[4];
49
+ uniform vec4 uShore;
50
+ uniform vec3 uShoreCol, uShoreLit, uWaterFar, uWaterDeep, uSheen, uGround, uGroundWarm, uGroundDark;
51
+ out vec4 outColor;
52
+ float crest(int i, float u) {
53
+ float x = clamp(u, 0., 1.) * 511.;
54
+ int k = int(x);
55
+ float a = texelFetch(uRidge, ivec2(k, i), 0).r;
56
+ float b = texelFetch(uRidge, ivec2(min(k + 1, 511), i), 0).r;
57
+ return mix(a, b, x - float(k));
58
+ }
59
+ vec3 sky(vec2 uv, int oct) {
60
+ vec2 p = vec2(uv.x * uAspect, uv.y);
61
+ float t = clamp(uv.y / uShore.x, 0., 1.);
62
+ vec3 c = mix(uSkyTop, uSkyLow, smoothstep(0., 1., t));
63
+ float corner = clamp((1. - uv.x * 1.5) * (1. - t * 1.3), 0., 1.);
64
+ c = mix(c, uSkyCorner, corner * corner);
65
+ c = mix(c, uSkyLow * 1.04, exp(-(uv.x - uCloud.z) * (uv.x - uCloud.z) * 4.84) * smoothstep(.05, .35, uv.y) * .35);
66
+ vec2 cp = p * vec2(1.3, 2.6) + uSeedOff;
67
+ vec2 warp = vec2(fbm(cp * .5, 3), fbm(cp * .5 + 7.3, 3));
68
+ float n = fbm(cp + warp * 1.4, oct);
69
+ float band = smoothstep(uCloud.x - .1, uCloud.x + .05, uv.y) * (1. - smoothstep(uCloud.y - .06, uCloud.y + .14, uv.y));
70
+ float side = exp(-(uv.x - uCloud.z) * (uv.x - uCloud.z) * 3.24);
71
+ float d = smoothstep(uCloud.w, uCloud.w + .3, n * (.55 + .45 * band) + band * side * .22);
72
+ float toward = fbm(cp + warp * 1.4 + vec2(-.05, -.08), oct);
73
+ float lit = clamp((n - toward) * 7. + .5, 0., 1.);
74
+ c = mix(c, mix(uCloudShade, uCloudLit, lit), d * .88);
75
+ float streak = fbm(vec2(p.x * 1.2, p.y * 26.) + uSeedOff * 1.7, 3);
76
+ float low = smoothstep(uShore.x - .24, uShore.x - .14, uv.y) * (1. - smoothstep(uShore.x - .12, uShore.x - .04, uv.y));
77
+ return mix(c, uCloudLit, smoothstep(.55, .75, streak) * low * .3);
78
+ }
79
+ vec3 ranges(vec2 uv, vec3 c, inout int code) {
80
+ for (int i = 0; i < 4; i++) {
81
+ if (float(i) >= uRanges) break;
82
+ vec4 info = uRangeInfo[i];
83
+ float top = crest(i, uv.x);
84
+ float dry = vnoise(vec2(uv.x * uAspect * 600., uv.y * 200.) + float(i) * 13.);
85
+ float a = smoothstep(-info.z, info.z, uv.y - top + (dry - .5) * info.z * 1.6);
86
+ if (a <= 0.) continue;
87
+ float below = max(uv.y - top, 0.);
88
+ float win = .014 + below * .9;
89
+ float slope = (crest(i, uv.x + win) - crest(i, uv.x - win)) / (2. * win);
90
+ float gx = uv.x + below * clamp(-slope, -1.2, 1.2) * .7;
91
+ float spur = vnoise(vec2(gx * uAspect * 26., below * 5.) + uSeedOff + float(i) * 5.);
92
+ float fine = vnoise(vec2(gx * uAspect * 90., below * 16.) + uSeedOff);
93
+ float face = smoothstep(0., 1., .5 - slope * 1.1 + (spur - .5) * .5 + (fine - .5) * .16);
94
+ face = mix(face, .42, smoothstep(.0, .09, below) * .25);
95
+ vec3 col = mix(uRangeShade[i], uRangeLit[i], smoothstep(.1, .9, face));
96
+ float wood = smoothstep(.45, .8, vnoise(vec2(uv.x * uAspect * 240., uv.y * 330.) + uSeedOff));
97
+ col *= 1. - wood * .22 * (1. - smoothstep(.8, 1.6, info.x));
98
+ col = mix(col, uHaze, hazeOf(info.x));
99
+ float mist = smoothstep(info.y - info.w, info.y, uv.y);
100
+ col = mix(col, mix(uHaze, uSkyLow, .4), mist * .5);
101
+ c = mix(c, col, a);
102
+ if (a > .5) code = 16 + (slope < 0. ? 0 : 1);
103
+ }
104
+ return c;
105
+ }
106
+ vec3 shore(vec2 uv, vec3 c, inout int code) {
107
+ float top = uShore.x + (fbm(vec2(uv.x * uAspect * 7., 3.1) + uSeedOff, 3) - .5) * .016;
108
+ float a = smoothstep(top - .0012, top + .0012, uv.y);
109
+ if (a <= 0.) return c;
110
+ float s = fbm(vec2(uv.x * uAspect * 26., uv.y * 260.) + uSeedOff, 3);
111
+ float lit = smoothstep(.42, .72, s) * (1. - smoothstep(top, uShore.y, uv.y) * .7);
112
+ vec3 col = mix(mix(uShoreCol, uGround, .25), uShoreLit, lit);
113
+ col = mix(col, uHaze, hazeOf(uShore.w));
114
+ if (a > .5) code = 32;
115
+ return mix(c, col, a);
116
+ }
117
+ vec3 above(vec2 uv, int oct, inout int code) {
118
+ return shore(uv, ranges(uv, sky(uv, oct), code), code);
119
+ }
120
+ vec3 water(vec2 uv) {
121
+ float t = clamp((uv.y - uShore.y) / (uShore.z - uShore.y), 0., 1.);
122
+ vec3 w = mix(uWaterFar, uWaterDeep, smoothstep(0., 1., t));
123
+ float rip = vnoise(vec2(uv.x * uAspect * 8., uv.y * 240.) + uSeedOff) - .5;
124
+ vec2 m = vec2(uv.x + rip * .014 * (.3 + t), 2. * uShore.y - uv.y + rip * .004);
125
+ int ignore = 0;
126
+ vec3 refl = (above(m, 2, ignore) + above(m + vec2(0., .008 + .02 * t), 1, ignore)) * .5;
127
+ vec3 c = mix(w, refl * vec3(.88, .94, .95), mix(.72, .3, t));
128
+ float sheen = exp(-(uv.y - uShore.y) / .014) * smoothstep(.3, .7, vnoise(vec2(uv.x * uAspect * 12., uv.y * 420.)));
129
+ c = mix(c, uSheen, sheen * .55);
130
+ float line = smoothstep(.64, .82, vnoise(vec2(uv.x * uAspect * 2.5, uv.y * 520.) + uSeedOff * 2.));
131
+ return mix(c, mix(c, uSheen, .4), line * (1. - t) * .7);
132
+ }
133
+ vec3 ground(vec2 uv) {
134
+ float t = clamp((uv.y - uShore.z) / (1. - uShore.z), 0., 1.);
135
+ vec3 c = mix(uGround, uGroundDark, smoothstep(0., .6, t));
136
+ c = mix(c, uGroundWarm, smoothstep(.5, 1., uv.x) * smoothstep(.15, .9, t) * .8);
137
+ float grass = fbm(vec2(uv.x * uAspect * 9., uv.y * 70.) + uSeedOff, 4);
138
+ c *= .84 + .3 * grass;
139
+ vec2 bp = vec2(uv.x * uAspect * 6., uv.y * 11.) + uSeedOff * 1.3;
140
+ float shrub = fbm(bp, 5) + t * .12;
141
+ float toward = fbm(bp + vec2(-.12, -.18), 5) + t * .12;
142
+ float m = smoothstep(.46, .6, shrub) * (1. - t * .5);
143
+ float lit = clamp((shrub - toward) * 6. + .4, 0., 1.);
144
+ vec3 bush = mix(uGroundDark * .8, uGround * 1.12, lit) * (.9 + .2 * grass);
145
+ return mix(c, bush, m * .8);
146
+ }
147
+ void main() {
148
+ vec2 uv = plateUv();
149
+ int code = 0;
150
+ vec3 c = above(uv, 5, code);
151
+ float wa = smoothstep(uShore.y - .0008, uShore.y + .0008, uv.y);
152
+ if (wa > 0.) {
153
+ c = mix(c, water(uv), wa);
154
+ if (wa > .5) code = 48;
155
+ float edge = uShore.z + (fbm(vec2(uv.x * uAspect * 3., 8.7) + uSeedOff, 4) - .5) * .045;
156
+ float ga = smoothstep(edge - .003, edge + .003, uv.y);
157
+ c = mix(c, ground(uv), ga);
158
+ if (ga > .5) code = 64;
159
+ }
160
+ outColor = vec4(c, float(code) / 255.);
161
+ }`,X=`${T}
162
+ uniform sampler2D uBase;
163
+ uniform vec4 uStroke[5];
164
+ out vec4 outColor;
165
+ vec2 toSt(vec2 q) { return (vec2(q.x / uAspect, q.y) - uView.xy) / uView.zw; }
166
+ void main() {
167
+ vec2 st = gl_FragCoord.xy / uSize;
168
+ vec4 b = texture(uBase, st);
169
+ int code = int(b.a * 255. + .5);
170
+ int region = min(code / 16, 4);
171
+ vec4 S = uStroke[region];
172
+ float ang = (code == 17) ? -S.x : S.x;
173
+ vec2 dir = vec2(cos(ang), sin(ang));
174
+ vec2 across = vec2(-dir.y, dir.x);
175
+ vec2 uv = plateUv();
176
+ vec2 q = vec2(uv.x * uAspect, uv.y);
177
+ vec2 r = vec2(dot(q, dir), dot(q, across));
178
+ vec2 cell = S.yz;
179
+ vec3 under = b.rgb;
180
+ float wsum = 1.;
181
+ for (int k = 1; k <= 3; k++) {
182
+ for (int sgn = -1; sgn <= 1; sgn += 2) {
183
+ vec3 s = texture(uBase, toSt(q + dir * float(k * sgn) * cell.x * .09)).rgb;
184
+ float w = exp(-dot(s - b.rgb, s - b.rgb) * 400.);
185
+ under += s * w; wsum += w;
186
+ }
187
+ }
188
+ under /= wsum;
189
+ vec2 c0 = floor(r / cell);
190
+ float best = -1.;
191
+ float cov = 0.;
192
+ vec2 bd = vec2(0);
193
+ vec2 bc = vec2(0);
194
+ float bh = 0.;
195
+ for (int j = -1; j <= 1; j++) {
196
+ for (int i = -1; i <= 1; i++) {
197
+ vec2 id = c0 + vec2(i, j);
198
+ uint h = hashU(ivec2(id) + ivec2(code * 7919, code * 104729));
199
+ vec4 hv = vec4(float(h & 255u), float((h >> 8) & 255u), float((h >> 16) & 255u), float(h >> 24)) / 255.;
200
+ vec2 ctr = (id + .5 + (hv.xy - .5) * vec2(.9, .7)) * cell;
201
+ vec2 hs = cell * vec2(.6 + .6 * hv.z, .5 + .35 * hv.w);
202
+ vec2 d = (r - ctr) / hs;
203
+ float taper = max(1. - .3 * d.x * d.x, .2);
204
+ float m = 1. - smoothstep(.7, 1., length(vec2(d.x, d.y / taper)));
205
+ float z = fract(hv.x * 7.13 + hv.w * 3.7);
206
+ if (m > 0. && z > best) { best = z; cov = m; bd = d; bc = ctr; bh = hv.z; }
207
+ }
208
+ }
209
+ vec3 col = under;
210
+ if (cov > 0.) {
211
+ vec4 sc = texture(uBase, toSt(bc.x * dir + bc.y * across));
212
+ float own = (1. - smoothstep(.04, .12, length(sc.rgb - b.rgb))) * step(abs(sc.a - b.a), .001);
213
+ vec3 paint = mix(under, sc.rgb, own);
214
+ paint *= 1. + (bh - .5) * .07;
215
+ paint += (fract(bh * 13.7) - .5) * vec3(.022, .004, -.02);
216
+ float bristle = .72 + .28 * vnoise(vec2(bd.x * 1.3, bd.y * 6. + bh * 31.));
217
+ col = mix(under, paint, cov * S.w * bristle);
218
+ }
219
+ outColor = vec4(col, b.a);
220
+ }`,q=`${T}
221
+ uniform sampler2D uPaint;
222
+ uniform vec4 uFinish;
223
+ out vec4 outColor;
224
+ void main() {
225
+ vec3 c = texture(uPaint, gl_FragCoord.xy / uSize).rgb;
226
+ vec2 uv = plateUv();
227
+ vec2 q = vec2(uv.x * uAspect, uv.y);
228
+ float g = fbm(q * 2.5 + uSeedOff * .3, 3) - .5;
229
+ c = c * (1. + g * .07) + g * vec3(.012, 0., -.012);
230
+ vec2 w = q / uFinish.x;
231
+ float perPixel = uView.w / uSize.y / uFinish.x;
232
+ vec2 cellW = floor(w);
233
+ vec2 f = fract(w);
234
+ float over = mod(cellW.x + cellW.y, 2.);
235
+ float thread = mix(4. * f.y * (1. - f.y), 4. * f.x * (1. - f.x), over);
236
+ float slub = rnd(over > .5 ? vec2(cellW.x, floor(cellW.y / 7.)) : vec2(floor(cellW.x / 7.), cellW.y) + 91.);
237
+ float weave = (thread - .6) * (.6 + .8 * slub);
238
+ float lum = dot(c, vec3(.3, .59, .11));
239
+ c *= 1. + weave * .045 * smoothstep(.3, .7, lum) * (1. - smoothstep(.22, .34, perPixel));
240
+ vec2 v = uv - .5;
241
+ c *= 1. - uFinish.y * smoothstep(.12, .5, dot(v, v));
242
+ c = vec3(.043, .055, .051) + c * (1. - vec3(.043, .055, .051));
243
+ c = mix(c, c * vec3(1.025, 1., .965), smoothstep(.45, .9, lum));
244
+ outColor = vec4(c, 1.);
245
+ }`,K=`#version 300 es
246
+ layout(location = 0) in vec4 aPos;
247
+ layout(location = 1) in vec4 aAxis;
248
+ layout(location = 2) in vec4 aCol;
249
+ layout(location = 3) in vec4 aMore;
250
+ uniform vec4 uView;
251
+ uniform float uAspect;
252
+ out vec2 vL;
253
+ out vec2 vUv;
254
+ flat out vec4 fPos;
255
+ flat out vec4 fAxis;
256
+ flat out vec4 fCol;
257
+ flat out vec4 fMore;
258
+ void main() {
259
+ vec2 corner = vec2(float(gl_VertexID & 1), float(gl_VertexID >> 1)) * 2. - 1.;
260
+ vec2 ax = aAxis.xy;
261
+ vec2 L = corner * 1.1;
262
+ vec2 q = vec2(aPos.x * uAspect, aPos.y) + ax * L.x * aPos.z + vec2(-ax.y, ax.x) * L.y * aPos.w;
263
+ vUv = vec2(q.x / uAspect, q.y);
264
+ vL = L;
265
+ fPos = aPos; fAxis = aAxis; fCol = aCol; fMore = aMore;
266
+ gl_Position = vec4((vUv - uView.xy) / uView.zw * 2. - 1., 0., 1.);
267
+ }`,H=`${T}
268
+ in vec2 vL;
269
+ in vec2 vUv;
270
+ flat in vec4 fPos;
271
+ flat in vec4 fAxis;
272
+ flat in vec4 fCol;
273
+ flat in vec4 fMore;
274
+ out vec4 outColor;
275
+ vec2 leafSide(vec2 p, float seed, out float rib) {
276
+ float x = p.x;
277
+ float hw = fPos.w / fPos.z * .5 * 2.75 * x * (1. - x) * (1.5 - .5 * x) * smoothstep(1.02, .7, x * x);
278
+ hw *= 1. - .035 * fract(x * 24. + seed * 7.);
279
+ rib = abs(p.y);
280
+ float d = max(abs(p.y) - hw, max(-x, x - 1.));
281
+ float vein = abs(fract((x - abs(p.y) * 1.4) * 6. + seed) - .5);
282
+ return vec2(d, smoothstep(.04, 0., vein - .44) * step(.03, abs(p.y)));
283
+ }
284
+ vec2 leafHand(vec2 p, float seed, float lobes, out float rib) {
285
+ vec2 v = p - vec2(.36, 0.);
286
+ float a = atan(v.y, v.x);
287
+ float r = length(v);
288
+ float R = .22;
289
+ rib = 9.;
290
+ for (int k = 0; k < 5; k++) {
291
+ if (float(k) >= lobes) break;
292
+ float side = (k % 2 == 1) ? 1. : -1.;
293
+ float phi = side * float((k + 1) / 2) * (lobes > 3. ? .8 : .95);
294
+ float len = .64 - .14 * float((k + 1) / 2);
295
+ float t = abs(a - phi) / .74;
296
+ R = max(R, len * pow(max(0., 1. - t), .55));
297
+ rib = min(rib, r * abs(sin(a - phi)) + step(1.2, abs(a - phi)));
298
+ }
299
+ R *= 1. - .035 * fract(a * 13. + seed * 5.);
300
+ return vec2(r - R, 0.);
301
+ }
302
+ vec4 leaf() {
303
+ vec2 p = vec2((vL.x + 1.) * .5, vL.y * fPos.w / fPos.z * .5);
304
+ float rib;
305
+ vec2 s = fMore.y < 2. ? leafSide(p, fAxis.w, rib) : leafHand(p, fAxis.w, fMore.y, rib);
306
+ float aa = fwidth(s.x) * .8;
307
+ float alpha = 1. - smoothstep(-aa, aa, s.x);
308
+ vec2 lightDir = normalize(vec2(-1., -1.3));
309
+ float L = fMore.x;
310
+ float fold = dot(vec2(-fAxis.y, fAxis.x), lightDir) * sign(p.y) * .5 + .5;
311
+ float inner = clamp(-s.x / .07, 0., 1.);
312
+ vec3 c = fCol.rgb * mix(.74, 1.12, fold * (.45 + .55 * L));
313
+ c *= .86 + .28 * vnoise(vec2(p.x * 3., p.y * 6.) + fAxis.w * 60.);
314
+ float streak = vnoise(vec2(p.x * 5., p.y * 42.) + fAxis.w * 30.);
315
+ c *= .92 + .16 * streak;
316
+ c += (vnoise(vec2(p.x * 2.5, p.y * 14.) + fAxis.w * 17.) - .5) * vec3(.05, .035, -.03);
317
+ c += vec3(.05, .06, .045) * L * fold * inner * (1. - inner) * 4. * smoothstep(.15, .6, p.x);
318
+ float line = (1. - smoothstep(.002, .009, rib)) * smoothstep(0., .06, p.x) * (1. - .7 * p.x);
319
+ vec3 vein = mix(c * .66, c * 1.22 + .02, smoothstep(.2, .6, L));
320
+ c = mix(c, vein, line * (fMore.y < 2. ? .7 : .4) + s.y * .2 * inner);
321
+ c = mix(c, c * .8, (1. - smoothstep(0., .012, -s.x)) * (1. - L) * .6);
322
+ return vec4(c, alpha);
323
+ }
324
+ vec4 spire() {
325
+ float t = (vL.x + 1.) * .5;
326
+ float w = (1. - t) * (.62 + 1.5 * t) * (.8 + .4 * vnoise(vec2(t * 16., vL.y * 2.) + fAxis.w * 40.));
327
+ float d = max(abs(vL.y) - w, -vL.x - 1.);
328
+ float aa = fwidth(d) * (1. + fMore.w * 2.5);
329
+ float lit = smoothstep(.4, -.7, vL.y / max(w, .05)) * fMore.x;
330
+ vec3 c = fCol.rgb * (.75 + .6 * lit) * (.85 + .3 * vnoise(vL * vec2(9., 3.) + fAxis.w * 30.));
331
+ return vec4(c, 1. - smoothstep(-aa, aa, d));
332
+ }
333
+ vec4 crown() {
334
+ float n = vnoise(vL * 2.4 + fAxis.w * 40.) * .65 + vnoise(vL * 6. + fAxis.w * 13.) * .35;
335
+ float d = max(length(vL * vec2(1., 1.1)) - (.66 + .38 * n), -vL.x - .8);
336
+ float aa = fwidth(d) * (1. + fMore.w * 2.5);
337
+ float lit = clamp(.5 + .6 * dot(normalize(vL + .001), normalize(vec2(.7, -.7))), 0., 1.) * fMore.x;
338
+ vec3 c = fCol.rgb * (.72 + .6 * lit) * (.85 + .3 * vnoise(vL * 7. + fAxis.w * 20.));
339
+ return vec4(c, 1. - smoothstep(-aa, aa, d));
340
+ }
341
+ vec4 wall() {
342
+ float d = max(abs(vL.x), abs(vL.y)) - 1.;
343
+ float aa = fwidth(d) * (1. + fMore.w * 1.5);
344
+ float side = smoothstep(1. - 2. * fMore.y - .08, 1. - 2. * fMore.y + .08, vL.y);
345
+ vec3 c = fCol.rgb * mix(.8 + .15 * fMore.x, .72, side);
346
+ c *= 1. - .25 * smoothstep(.7, .85, vL.x);
347
+ c *= .95 + .1 * vnoise(vL * vec2(3., 5.) + fAxis.w * 20.);
348
+ return vec4(c, 1. - smoothstep(-aa, aa, d));
349
+ }
350
+ vec4 blot() {
351
+ float n = vnoise(vL * 2.2 + fAxis.w * 50.);
352
+ float d = length(vL) + (n - .5) * .45;
353
+ vec3 c = fCol.rgb * (.85 + .3 * vnoise(vL * 5. + fAxis.w * 9.));
354
+ return vec4(c, 1. - smoothstep(.72, .95, d));
355
+ }
356
+ vec4 stem() {
357
+ float d = abs(vL.y) - 1.;
358
+ float aa = fwidth(d) * .9;
359
+ vec3 c = fCol.rgb * (1. + .4 * smoothstep(.2, -.8, vL.y));
360
+ return vec4(c, (1. - smoothstep(-aa, aa, d)) * smoothstep(1.1, .9, abs(vL.x)));
361
+ }
362
+ void main() {
363
+ int kind = int(fAxis.z + .5);
364
+ vec4 s = kind == 0 ? blot() : kind == 1 ? spire() : kind == 2 ? crown() : kind == 3 ? wall() : kind == 4 ? leaf() : stem();
365
+ if (fMore.z > 0.) {
366
+ if (vUv.y < fMore.z) discard;
367
+ s.a *= .55 + .45 * smoothstep(.25, .6, vnoise(vec2(vUv.x * uAspect * 60., vUv.y * 900.)));
368
+ s.a *= 1. - .6 * smoothstep(0., fPos.z * 2.4, vUv.y - fMore.z);
369
+ }
370
+ vec3 c = mix(s.rgb, uHaze, hazeOf(fMore.w));
371
+ outColor = vec4(c, s.a * fCol.a);
372
+ }`,j=`#version 300 es
373
+ precision highp float;
374
+ uniform sampler2D uPlate;
375
+ uniform vec4 uCrop;
376
+ uniform vec4 uRect;
377
+ out vec4 outColor;
378
+ void main() {
379
+ vec2 f = (gl_FragCoord.xy - uRect.xy) / uRect.zw;
380
+ outColor = vec4(texture(uPlate, uCrop.xy + vec2(f.x, 1. - f.y) * uCrop.zw).rgb, 1.);
381
+ }`;function Y(e,o,t={}){let n=Math.max(t.zoom??1,1),r=(o>e?1:o/e)/n,a=(o>e?e/o:1)/n,[i,s]=t.focus??[.5,.5],[c,u]=t.shift??[0,0],f=(d,m)=>Math.min(Math.max(d,0),m);return[f(i-r/2+c*r,1-r),f(s-a/2+u*a,1-a),r,a]}function E(e,o,t){let n=e.createProgram();for(let[r,a]of[[e.VERTEX_SHADER,o],[e.FRAGMENT_SHADER,t]]){let i=e.createShader(r);if(!i)throw new Error("plate-painter: no shader.");e.shaderSource(i,a),e.compileShader(i),e.attachShader(n,i),e.deleteShader(i)}if(e.linkProgram(n),!e.getProgramParameter(n,e.LINK_STATUS)){let a=(e.getAttachedShaders(n)??[]).map(i=>e.getShaderInfoLog(i)??"").join(`
382
+ `);throw new Error(`plate-painter: a pass did not compile.
383
+ ${e.getProgramInfoLog(n)??""}
384
+ ${a}`)}return n}function ve(e,o,t){for(let[n,r,a]of t){let i=e.getUniformLocation(o,n)??e.getUniformLocation(o,`${n}[0]`);i&&(r===1?e.uniform1fv(i,a):r===2?e.uniform2fv(i,a):r===3?e.uniform3fv(i,a):e.uniform4fv(i,a))}}function Z(e,o,t){let n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n);let r=t?e.NEAREST:e.LINEAR;return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),t?(e.pixelStorei(e.UNPACK_ALIGNMENT,4),e.texImage2D(e.TEXTURE_2D,0,e.R32F,o.width,o.height,0,e.RED,e.FLOAT,t)):e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8,o.width,o.height),n}function $(e,o){let t=Z(e,o),n=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,n),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0),{texture:t,framebuffer:n}}function M(e){let o=e.getParameter(e.FRAMEBUFFER_BINDING),t=e.getParameter(e.VIEWPORT),n=e.getParameter(e.CURRENT_PROGRAM),r=e.getParameter(e.VERTEX_ARRAY_BINDING),a=e.getParameter(e.ACTIVE_TEXTURE),i=[e.BLEND,e.DEPTH_TEST,e.CULL_FACE,e.SCISSOR_TEST].map(u=>[u,e.isEnabled(u)]),s=e.getParameter(e.UNPACK_FLIP_Y_WEBGL);e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.activeTexture(e.TEXTURE0);let c=e.getParameter(e.TEXTURE_BINDING_2D);for(let[u]of i)e.disable(u);return()=>{e.bindTexture(e.TEXTURE_2D,c),e.activeTexture(a);for(let[u,f]of i)f?e.enable(u):e.disable(u);e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,s),e.bindFramebuffer(e.FRAMEBUFFER,o),e.viewport(t[0]??0,t[1]??0,t[2]??0,t[3]??0),e.useProgram(n),e.bindVertexArray(r)}}function xe(e,o){let t=o.length/R;if(t===0)return;let n=e.createVertexArray(),r=e.createBuffer();e.bindVertexArray(n),e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);for(let a=0;a<4;a+=1)e.enableVertexAttribArray(a),e.vertexAttribPointer(a,4,e.FLOAT,!1,R*4,a*16),e.vertexAttribDivisor(a,1);e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ZERO,e.ONE),e.drawArraysInstanced(e.TRIANGLE_STRIP,0,4,t),e.disable(e.BLEND),e.bindVertexArray(null),e.deleteBuffer(r),e.deleteVertexArray(n)}function L(e,o,t,n){e.useProgram(o),ve(e,o,t);let r=e.getUniformLocation(o,"uBase")??e.getUniformLocation(o,"uPaint");r&&e.uniform1i(r,0);let a=e.getUniformLocation(o,"uRidge");a&&e.uniform1i(a,1),n?xe(e,n):e.drawArrays(e.TRIANGLES,0,3)}function ye(e,o,t,n){let r=Z(e,{width:y,height:p},t.ridges);e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,r),e.activeTexture(e.TEXTURE0),e.bindFramebuffer(e.FRAMEBUFFER,n.out.framebuffer),L(e,o.scene,n.uniforms),L(e,o.dab,n.uniforms,t.scene),e.bindFramebuffer(e.FRAMEBUFFER,n.work.framebuffer),e.bindTexture(e.TEXTURE_2D,n.out.texture),L(e,o.stroke,n.uniforms),L(e,o.dab,n.uniforms,t.foliage),e.bindFramebuffer(e.FRAMEBUFFER,n.out.framebuffer),e.bindTexture(e.TEXTURE_2D,n.work.texture),L(e,o.finish,n.uniforms),e.bindTexture(e.TEXTURE_2D,null),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,null),e.activeTexture(e.TEXTURE0),e.deleteTexture(r)}function we(e,o,t,n){let r=Y(t.width/t.height,n.width/n.height,n),[a,i]=[n.x??0,n.y??0];e.viewport(a,i,n.width,n.height),e.useProgram(o),e.uniform4f(e.getUniformLocation(o,"uCrop"),r[0],r[1],r[2],r[3]),e.uniform4f(e.getUniformLocation(o,"uRect"),a,i,n.width,n.height),e.uniform1i(e.getUniformLocation(o,"uPlate"),0),e.bindTexture(e.TEXTURE_2D,t.texture),e.bindVertexArray(null),e.drawArrays(e.TRIANGLES,0,3)}function Re(e){let o={scene:E(e,A,V),stroke:E(e,A,X),finish:E(e,A,q),dab:E(e,K,H),backdrop:E(e,A,j)},t=new Map,n=(r,a)=>[r,a.width,a.height,...a.view??[0,0,1,1]].join(",");return{paint(r,a){let i=n(r.digest,a),s=t.get(i);if(s)return s;let c=M(e),u=$(e,a),f=$(e,a),d=a.view??[0,0,1,1],m=[...r.uniforms,["uView",4,new Float32Array(d)],["uSize",2,new Float32Array([a.width,a.height])]];e.viewport(0,0,a.width,a.height),ye(e,o,r,{out:u,work:f,uniforms:m}),e.deleteFramebuffer(f.framebuffer),e.deleteTexture(f.texture),c();let w={texture:u.texture,framebuffer:u.framebuffer,width:a.width,height:a.height,digest:r.digest,view:d};return t.set(i,w),w},draw(r,a){let i=M(e);we(e,o.backdrop,r,a),i()},read(r){let a=[...t.values()].find(c=>c.texture===r.texture);if(!a)throw new Error("plate-painter: that plate was released or is not this painter's.");let i=new Uint8ClampedArray(r.width*r.height*4),s=M(e);return e.bindFramebuffer(e.FRAMEBUFFER,a.framebuffer),e.readPixels(0,0,r.width,r.height,e.RGBA,e.UNSIGNED_BYTE,i),s(),{width:r.width,height:r.height,data:i}},release(r){for(let[a,i]of t)i.texture===r.texture&&(e.deleteFramebuffer(i.framebuffer),e.deleteTexture(i.texture),t.delete(a))},dispose(){for(let r of[...t.values()])this.release(r);for(let r of Object.values(o))e.deleteProgram(r)}}}export{b as KIND,Q as LAKE_VALLEY,p as MAX_RANGES,N as PAINTER_VERSION,y as RIDGE_SAMPLES,R as STRIDE,Y as coverCrop,Re as createPlatePainter,pe as planPlate};
@@ -0,0 +1,25 @@
1
+ import type { Node, V3 } from "./sdf.js";
2
+ /** Where the raised arm goes: the shoulder, the elbow and the wrist, and the hanging arm's elbow. */
3
+ export interface Arms {
4
+ readonly shoulder: V3;
5
+ readonly elbow: V3;
6
+ readonly wrist: V3;
7
+ readonly hanging: V3;
8
+ }
9
+ export declare const ARMS: Arms;
10
+ /** The neck and the shoulders' slope, which the skin and cloth share. */
11
+ export declare function neckShape(): Node;
12
+ /** The torso and arms, grown by `grow`. */
13
+ export declare function torso(arms: Arms, grow: number): Node;
14
+ /** The forearm of the raised arm, grown by `grow`. */
15
+ export declare function forearm(arms: Arms, grow: number): Node;
16
+ /** A wave a turn long, -1 to 1: round on its ridges, creased in its valleys, from arithmetic alone. */
17
+ export declare function wave(turns: number): number;
18
+ /** The chemise: a white layer just over the skin, gathered at its top edge. */
19
+ export declare function chemiseShape(arms: Arms): Node;
20
+ /** The dress: a layer over the chemise with a square neckline, and its sleeve on the raised forearm. */
21
+ export declare function dressShape(arms: Arms): Node;
22
+ /** The over-gown: velvet over the shoulders and arms, open down the front, with wide sleeves. */
23
+ export declare function gownShape(arms: Arms): Node;
24
+ /** The chain's path: from behind the neck, round over the collarbones, low on the chest in front. */
25
+ export declare function chainPath(n: number): V3[];