@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,133 @@
1
+ {
2
+ "protocol": "keel-module-inputs@1",
3
+ "fields": [
4
+ {
5
+ "key": "seed",
6
+ "label": "Noise seed",
7
+ "required": false,
8
+ "placement": "advanced",
9
+ "type": "number",
10
+ "min": 0,
11
+ "max": 2147483647,
12
+ "step": 1,
13
+ "default": 1
14
+ },
15
+ {
16
+ "key": "lineColour",
17
+ "label": "Line colour",
18
+ "required": false,
19
+ "type": "color",
20
+ "swatches": [
21
+ "#f7f7ee",
22
+ "#ffffff",
23
+ "#292919"
24
+ ],
25
+ "default": "#f7f7ee"
26
+ },
27
+ {
28
+ "key": "lines",
29
+ "label": "Line strength",
30
+ "required": false,
31
+ "type": "number",
32
+ "min": 0,
33
+ "max": 1,
34
+ "step": 0.01,
35
+ "control": "slider",
36
+ "default": 0.55
37
+ },
38
+ {
39
+ "key": "seamColour",
40
+ "label": "Seam colour",
41
+ "required": false,
42
+ "type": "color",
43
+ "swatches": [
44
+ "#fff1cc",
45
+ "#ffffff",
46
+ "#ffd27a"
47
+ ],
48
+ "default": "#fff1cc"
49
+ },
50
+ {
51
+ "key": "glow",
52
+ "label": "Seam glow",
53
+ "required": false,
54
+ "type": "number",
55
+ "min": 0,
56
+ "max": 4,
57
+ "step": 0.05,
58
+ "control": "slider",
59
+ "default": 0.25
60
+ },
61
+ {
62
+ "key": "seam",
63
+ "label": "Seam width",
64
+ "required": false,
65
+ "help": "A share of the noise's range.",
66
+ "placement": "advanced",
67
+ "type": "number",
68
+ "min": 0,
69
+ "max": 0.3,
70
+ "step": 0.005,
71
+ "default": 0.05
72
+ },
73
+ {
74
+ "key": "soft",
75
+ "label": "Boundary softness",
76
+ "required": false,
77
+ "help": "A share of the noise's range.",
78
+ "placement": "advanced",
79
+ "type": "number",
80
+ "min": 0,
81
+ "max": 0.3,
82
+ "step": 0.005,
83
+ "default": 0.06
84
+ },
85
+ {
86
+ "key": "edge",
87
+ "label": "Line threshold",
88
+ "required": false,
89
+ "help": "The luma step that makes a line; lower draws more.",
90
+ "placement": "advanced",
91
+ "type": "number",
92
+ "min": 0.01,
93
+ "max": 1,
94
+ "step": 0.01,
95
+ "default": 0.05
96
+ },
97
+ {
98
+ "key": "noiseScale",
99
+ "label": "Noise scale",
100
+ "required": false,
101
+ "placement": "advanced",
102
+ "type": "number",
103
+ "min": 0.25,
104
+ "max": 8,
105
+ "step": 0.05,
106
+ "default": 0.6
107
+ },
108
+ {
109
+ "key": "pull",
110
+ "label": "Pointer pull",
111
+ "required": false,
112
+ "help": "How far the pointer pulls a radial reveal's centre.",
113
+ "placement": "advanced",
114
+ "type": "number",
115
+ "min": 0,
116
+ "max": 1,
117
+ "step": 0.01,
118
+ "default": 0.1
119
+ },
120
+ {
121
+ "key": "scale",
122
+ "label": "Blend scale",
123
+ "required": false,
124
+ "help": "The less visible scene's scale (quality's blendScale); needs a scaled finish.",
125
+ "placement": "advanced",
126
+ "type": "number",
127
+ "min": 0.25,
128
+ "max": 1,
129
+ "step": 0.05,
130
+ "default": 1
131
+ }
132
+ ]
133
+ }
@@ -0,0 +1,2 @@
1
+ // scene-blend@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var e={seed:1,lineColour:"#f7f7ee",lines:.55,edge:.05,soft:.06,seamColour:"#fff1cc",glow:.25,seam:.05,noiseScale:.6,pull:.1,scale:1},t=/^#[0-9a-f]{6}$/iu;function n(e,t,n,l){return"number"==typeof e&&Number.isFinite(e)?Math.min(l,Math.max(n,e)):t}var l=(e,n)=>"string"==typeof e&&t.test(e)?e.toLowerCase():n;function a(t){if(null==t||"object"!=typeof t)return e;let a=t,u=e;return{seed:Math.trunc(n(a.seed,u.seed,0,2147483647)),lineColour:l(a.lineColour,u.lineColour),lines:n(a.lines,u.lines,0,1),edge:n(a.edge,u.edge,.01,1),soft:n(a.soft,u.soft,0,.3),seamColour:l(a.seamColour,u.seamColour),glow:n(a.glow,u.glow,0,4),seam:n(a.seam,u.seam,0,.3),noiseScale:n(a.noiseScale,u.noiseScale,.25,8),pull:n(a.pull,u.pull,0,1),scale:n(a.scale,u.scale,.25,1)}}function u(e){let t=Number.parseInt(e.slice(1),16);return[(t>>16&255)/255,(t>>8&255)/255,(255&t)/255]}var r=e=>Math.min(1,Math.max(0,e));function i(e){let t=r(e);return[t<=.5?1-t:Math.max(0,(.9-t)/.8),Math.max(0,2*(t-.5))]}function o(e){return r((e-.25)/.75)}function s(e){return e<.5?"b":"a"}function f(e){return e<.5?"a":"b"}function c(e,t,n){return[((null===t?e.x:e.x+(t.x-e.x)*n)+1)/2,((null===t?e.y:e.y+(t.y-e.y)*n)+1)/2]}function m(e,t){let n=Math.max(e[0],1-e[0])*t,l=Math.max(e[1],1-e[1]);return Math.sqrt(n*n+l*l)}var d=256;function h(e,t,n){let l=Math.imul(0|e,521288629)^Math.imul(0|t,1597334677)^(0|n);return l=Math.imul(l^l>>>15,739982445),l=Math.imul(l^l>>>12,695872825),((l^l>>>15)>>>0)/4294967296}var g=e=>e*e*(3-2*e);function p(e,t,n,l){let a=e*n,u=t*n,r=Math.floor(a),i=Math.floor(u),o=g(a-r),s=g(u-i),f=(e,t)=>h(e%n,t%n,l),c=f(r,i)+(f(r+1,i)-f(r,i))*o;return c+(f(r,i+1)+(f(r+1,i+1)-f(r,i+1))*o-c)*s}function x(e,t,n,l){let a=0,u=1;for(let r=0;r<4;r+=1)a+=p(e,t,n<<r,l+r)*u,u/=2;return a/1.875}function v(e){let t=1/0,n=-1/0;for(let l of e)t=Math.min(t,l),n=Math.max(n,l);let l=n>t?n-t:1;return Uint8Array.from(e,e=>Math.round((e-t)/l*255))}function S(e=0,t=256){let n=t*t,l=new Float64Array(n),a=new Float64Array(n);for(let n=0;n<t;n+=1)for(let u=0;u<t;u+=1)l[n*t+u]=x(u/t,n/t,16,e),a[n*t+u]=x(u/t,n/t,4,e+101);let u=v(l),r=v(a),i=new Uint8Array(4*n);for(let l=0;l<n;l+=1)i[4*l]=u[l]??0,i[4*l+1]=r[l]??0,i[4*l+2]=Math.floor(256*h(l%t,Math.floor(l/t),e+7)),i[4*l+3]=255;return i}var M="\nvoid main() { gl_Position = vec4(position.xy, 0.0, 1.0); }\n",L="\nprecision highp float;\nuniform sampler2D tA;\nuniform sampler2D tB;\nuniform sampler2D tNoise;\nuniform vec2 uSize;\nuniform vec2 uTexelA;\nuniform vec2 uTexelB;\nuniform float uMode;\nuniform float uFill;\nuniform float uLinesIn;\nuniform float uLinesOut;\nuniform float uDarken;\nuniform vec3 uLine;\nuniform float uLineStrength;\nuniform float uEdge;\nuniform float uSoft;\nuniform vec3 uSeam;\nuniform float uGlow;\nuniform float uSeamWidth;\nuniform float uNoiseScale;\nuniform vec2 uCentre;\nuniform float uReach;\nfloat luma(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }\nfloat lines(sampler2D t, float here, vec2 uv, vec2 px) {\n float right = luma(texture2D(t, uv + vec2(px.x, 0.0)).rgb);\n float up = luma(texture2D(t, uv + vec2(0.0, px.y)).rgb);\n float across = luma(texture2D(t, uv + px).rgb);\n return smoothstep(uEdge, uEdge * 3.0, length(vec2(here - across, right - up)));\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / uSize;\n vec3 a = texture2D(tA, uv).rgb;\n vec3 b = texture2D(tB, uv).rgb;\n if (uMode > 1.5) { gl_FragColor = vec4(mix(a, b, uFill) * (1.0 - uDarken), 1.0); return; }\n float aspect = uSize.x / uSize.y;\n float n = texture2D(tNoise, vec2(uv.x * aspect, uv.y) * uNoiseScale).r;\n float field = n;\n if (uMode > 0.5) field = mix(length((uv - uCentre) * vec2(aspect, 1.0)) / uReach, n, 0.18);\n float level = uFill * (1.0 + 2.0 * uSoft) - uSoft;\n float fill = 1.0 - smoothstep(level - uSoft, level + uSoft, field);\n float seam = (1.0 - smoothstep(0.0, uSeamWidth, abs(field - level))) * step(0.0001, uFill) * step(uFill, 0.9999);\n float la = uLinesOut > 0.0 ? lines(tA, luma(a), uv, uTexelA) : 0.0;\n float lb = uLinesIn > 0.0 ? lines(tB, luma(b), uv, uTexelB) : 0.0;\n vec3 outgoing = mix(a, vec3(0.0), uLinesOut * 0.6) + uLine * la * uLinesOut * uLineStrength;\n vec3 c = mix(outgoing, b, fill);\n c += uLine * lb * uLinesIn * uLineStrength * (1.0 - 0.6 * fill);\n c += uSeam * seam * seam * uGlow * 0.25;\n gl_FragColor = vec4(clamp(c * (1.0 - uDarken), 0.0, 1.0), 1.0);\n}\n",w={noise:0,radial:1,fade:2};function b(e,t,n){let l=e[t];void 0!==l&&(l.value=n)}function C(e,t){let n=[["uLine",u(t.lineColour)],["uLineStrength",t.lines],["uEdge",t.edge],["uSoft",t.soft],["uSeam",u(t.seamColour)],["uGlow",t.glow],["uSeamWidth",t.seam],["uNoiseScale",t.noiseScale]];for(let[t,l]of n)b(e,t,l)}function y(e,t){let n=new e.DataTexture(S(t),256,256,"rgba");return n.wrapS="repeat",n.wrapT="repeat",n.minFilter="linear",n.magFilter="linear",n.needsUpdate=!0,n}function D(e,t,n){"function"==typeof t?t():null!==n?n.render(t.scene,t.camera):e.render(t.scene,t.camera)}function F(e,t,n=null,l){let u=a(l),{main:r,scaled:d}=function(e){return null===e?{main:null,scaled:null}:"main"in e?{main:e.main,scaled:e.scaled??null}:{main:e,scaled:null}}(n),h=function(){let e=e=>({value:e});return{tA:e(null),tB:e(null),tNoise:e(null),uSize:e([1,1]),uTexelA:e([1,1]),uTexelB:e([1,1]),uMode:e(0),uFill:e(0),uLinesIn:e(0),uLinesOut:e(0),uDarken:e(0),uLine:e([1,1,1]),uLineStrength:e(.5),uEdge:e(.05),uSoft:e(.05),uSeam:e([1,1,1]),uGlow:e(0),uSeamWidth:e(.05),uNoiseScale:e(1),uCentre:e([.5,.5]),uReach:e(1)}}(),g=function(e,t,n,l){let a={type:"half",minFilter:"linear",magFilter:"linear",generateMipmaps:!1,depthBuffer:n},u=new e.RenderTarget(1,1,a),r=new e.RenderTarget(1,1,a);b(t,"tNoise",y(e,l));let i=new e.CustomMaterial({uniforms:t,vertexShader:M,fragmentShader:L,depthTest:!1,depthWrite:!1}),o=e.plane(2,2),s=new e.Mesh(o,i);s.frustumCulled=!1;let f=new e.Stage;return f.add(s),{whole:u,scaled:r,material:i,scene:f,camera:new e.OrthoCamera(-1,1,1,-1,0,1),dispose:()=>{u.dispose(),r.dispose(),(t.tNoise?.value).dispose(),i.dispose(),o.dispose()}}}(e,h,null===r,u.seed);C(h,u);let p=function(e){let t=new Set;return n=>{for(let l of e)void 0===l?.settings||void 0===l.setSettings||(n&&!0===l.settings.taa?(l.setSettings({...l.settings,taa:!1}),t.add(l)):!n&&t.delete(l)&&l.setSettings({...l.settings,taa:!0}))}}([r,d]),x={css:[1,1],ratio:1,px:[1,1],scaledPx:[1,1]},v=0,S=()=>{let e=x.ratio*(null===r||null!==d?u.scale:1);x.scaledPx=[Math.max(1,Math.round(x.css[0]*e)),Math.max(1,Math.round(x.css[1]*e))],g.whole.setSize(x.px[0],x.px[1]),g.scaled.setSize(x.scaledPx[0],x.scaledPx[1]),d?.setSize?.(x.css[0],x.css[1],e),b(h,"uSize",x.px)},F=(e,n,l,a)=>{t.setRenderTarget(n),D(t,e,l);let u=n===g.whole?x.px:x.scaledPx;b(h,`t${a}`,n.texture),b(h,`uTexel${a}`,[1/u[0],1/u[1]])};return{get settings(){return u},setSettings(t){let n=u;return u=a(t),u.seed!==n.seed&&function(e,t,n){let l=t.tNoise?.value;b(t,"tNoise",y(e,n)),l?.dispose()}(e,h,u.seed),u.scale!==n.scale&&S(),C(h,u),u},setSize(e,t,n){let l=e=>Math.max(1,Math.round(e*n));x.css=[e,t],x.ratio=n,x.px=[l(e),l(t)],S()},draw(e,n,l,a={}){let x=Number.isFinite(l)?Math.min(1,Math.max(0,l)):0;if(x<=0||x>=1)return p(!1),D(t,x<=0?e:n,r),f(x);p(!0),((e,t)=>{if(v++%30==0&&void 0!==r?.dress)for(let n of[e,t])"function"!=typeof n&&r.dress(n.scene)})(e,n);let S=t.getRenderTarget(),M=s(x),L=d??r;return F(e,"a"===M?g.scaled:g.whole,"a"===M?L:r,"A"),F(n,"b"===M?g.scaled:g.whole,"b"===M?L:r,"B"),function(e,t,n,l){let a=n.mode??"noise",[u,r]=i(t),s=e.uSize?.value,f=c(n.centre??{x:0,y:0},n.pointer??null,l.pull);b(e,"uMode",w[a]),b(e,"uFill","fade"===a?t:o(t)),b(e,"uLinesIn",n.lines?.in??u),b(e,"uLinesOut",n.lines?.out??r),b(e,"uDarken",Math.min(1,Math.max(0,n.darken??0))),b(e,"uCentre",f),b(e,"uReach",m(f,s[0]/s[1]))}(h,x,a,u),t.setRenderTarget(S),t.render(g.scene,g.camera),f(x)},dispose(){p(!1),g.dispose()}}}export{L as BLEND_GLSL,M as BLEND_VERTEX_GLSL,e as DEFAULT_BLEND_SETTINGS,d as NOISE_SIZE,o as blendFill,i as blendLines,a as blendSettings,F as createSceneBlend,f as currentAt,u as displayColour,m as farthestCorner,h as latticeHash,s as minorAt,S as noiseTexels,c as radialCentre};
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The section pass: one full-screen pass after the finish, for what a scrolled section lays over its scene. MIT.
3
+ *
4
+ * import * as finishModule from "keel://module/lit-finish.js";
5
+ * const post = createSectionPost(lit, renderer, finishModule, { colour: "#f7f7ee", tear: 1 });
6
+ * post.setSize(cssWidth, cssHeight, renderer.getPixelRatio());
7
+ * // each frame, the values from the host's tracks:
8
+ * post.render(() => finish.render(scene, camera), { progress, position, darken, blur });
9
+ *
10
+ * A paper panel sweeps up over the frame (`progress` 0 → 1) and on up out of it (1 → 2), its edges moved by
11
+ * `position`, straight or torn, with a thin line of lighter fibres and a soft shadow past them. Under the panel the
12
+ * frame can be darkened and blurred (lit-finish's own blur, passed in); a one-pixel grain lies over everything. A
13
+ * frame that needs none of it is drawn straight to the host's target.
14
+ *
15
+ * keel/lit and lit-finish are injected: the module never imports them and never touches globals.
16
+ */
17
+ export { DEFAULT_POST_SETTINGS, TEAR_REACH, postSettings, frameOf, panelEdges, panelShows, idle, blurStep, displayColour, } from "./settings.js";
18
+ export type { Frame, PostSettings, PostValues } from "./settings.js";
19
+ export { NOISE_SIZE, latticeHash, noiseTexels } from "./noise.js";
20
+ export { POST_GLSL, POST_VERTEX_GLSL } from "./post.glsl.js";
21
+ export type { LitLike } from "./lit.js";
22
+ export { createSectionPost } from "./post.js";
23
+ export type { FinishShaders, SectionPost } from "./post.js";
@@ -0,0 +1,47 @@
1
+ export interface TextureLike {
2
+ dispose(): void;
3
+ }
4
+ export interface DataTextureLike extends TextureLike {
5
+ wrapS: string;
6
+ wrapT: string;
7
+ minFilter: string;
8
+ magFilter: string;
9
+ needsUpdate: boolean;
10
+ }
11
+ export interface RenderTargetLike {
12
+ readonly texture: TextureLike;
13
+ setSize(width: number, height: number): void;
14
+ dispose(): void;
15
+ }
16
+ export interface Uniform {
17
+ value: unknown;
18
+ }
19
+ export interface ShaderMaterialLike {
20
+ readonly uniforms: Record<string, Uniform>;
21
+ dispose(): void;
22
+ }
23
+ export interface RendererLike {
24
+ getRenderTarget(): RenderTargetLike | null;
25
+ setRenderTarget(target: RenderTargetLike | null): void;
26
+ render(scene: unknown, camera: unknown): void;
27
+ }
28
+ export interface DisposableLike {
29
+ dispose(): void;
30
+ }
31
+ interface MeshLike {
32
+ frustumCulled: boolean;
33
+ }
34
+ export interface SceneLike {
35
+ add(object: unknown): void;
36
+ }
37
+ /** The parts of keel/lit this module calls. Pass the keel/lit namespace itself. */
38
+ export interface LitLike {
39
+ readonly RenderTarget: new (width: number, height: number, options: Readonly<Record<string, unknown>>) => RenderTargetLike;
40
+ readonly DataTexture: new (data: Uint8Array, width: number, height: number, format: string) => DataTextureLike;
41
+ readonly CustomMaterial: new (parameters: Readonly<Record<string, unknown>>) => ShaderMaterialLike;
42
+ plane(width: number, height: number): DisposableLike;
43
+ readonly Mesh: new (geometry: unknown, material: unknown) => MeshLike;
44
+ readonly Stage: new () => SceneLike;
45
+ readonly OrthoCamera: new (left: number, right: number, top: number, bottom: number, near: number, far: number) => unknown;
46
+ }
47
+ export {};
@@ -0,0 +1,14 @@
1
+ /** Texels along a side of the noise texture. */
2
+ export declare const NOISE_SIZE = 256;
3
+ /** A lattice point and a seed to a share in [0, 1), by 32-bit integer mixing. */
4
+ export declare function latticeHash(x: number, y: number, seed: number): number;
5
+ /**
6
+ * The noise texture's texels, RGBA, `size` a side (a power of two). R: fine fractal noise (16 cells a side and up),
7
+ * the threshold the panel dissolves by and its paper's mottle. G: broad fractal noise (4 cells and up), the torn
8
+ * edge's shape. B: white noise, the grain. A: 255. R and G are stretched to the full range. The same seed gives the
9
+ * same bytes everywhere.
10
+ *
11
+ * @param seed An integer seed.
12
+ * @param size Texels a side, a power of two from 32; 256 by default.
13
+ */
14
+ export declare function noiseTexels(seed?: number, size?: number): Uint8Array;
@@ -0,0 +1,31 @@
1
+ import type { LitLike, RendererLike } from "./lit.js";
2
+ import type { PostSettings, PostValues } from "./settings.js";
3
+ /** lit-finish's shaders this pass reuses: pass the lit-finish namespace itself. */
4
+ export interface FinishShaders {
5
+ /** A separable 9-tap Gaussian: `tBlur` sampled at this target's uv, `uDir` in its pixels, `uBloomSize` its size. */
6
+ readonly BLUR_GLSL: string;
7
+ }
8
+ export interface SectionPost {
9
+ readonly settings: PostSettings;
10
+ setSettings(input?: unknown): PostSettings;
11
+ /** The canvas's CSS size and pixel ratio (the renderer's). */
12
+ setSize(cssWidth: number, cssHeight: number, devicePixelRatio: number): void;
13
+ /**
14
+ * Draws a frame with the section's overlay onto the renderer's current target.
15
+ *
16
+ * @param draw Draws the frame onto the renderer's current target: `finish.render(...)` or `blend.draw(...)`.
17
+ * @param values This frame's overlay values, from the host's tracks.
18
+ */
19
+ render(draw: () => void, values?: PostValues): void;
20
+ dispose(): void;
21
+ }
22
+ /**
23
+ * Binds the section pass to a renderer: a paper panel that sweeps in and out with a straight or torn edge and a fibre
24
+ * line, darkening, blur and grain, over a finished frame. Every value is a plain number a host feeds from tracks.
25
+ *
26
+ * @param lit The keel/lit namespace (WebGL2).
27
+ * @param renderer The renderer that owns the canvas.
28
+ * @param shaders lit-finish's namespace, for its blur.
29
+ * @param input Settings, normalized through `postSettings`.
30
+ */
31
+ export declare function createSectionPost(lit: LitLike, renderer: RendererLike, shaders: FinishShaders, input?: unknown): SectionPost;
@@ -0,0 +1,8 @@
1
+ export declare const POST_VERTEX_GLSL = "\nvoid main() { gl_Position = vec4(position.xy, 0.0, 1.0); }\n";
2
+ /**
3
+ * The finished frame, blurred and darkened, under a paper panel between heights `uBottom` and `uTop` (frame heights,
4
+ * y up). A torn edge is a line y = f(x): a gentle wander from the broad noise plus fine jaggedness from the white
5
+ * noise, both times the tear, so it never breaks into islands. Past each edge lie a thin band of lighter fibres, a
6
+ * few hairs where torn, and a soft shadow on the frame. One-pixel grain lies over everything.
7
+ */
8
+ export declare const POST_GLSL = "\nprecision highp float;\nuniform sampler2D tColor;\nuniform sampler2D tBlurred;\nuniform sampler2D tNoise;\nuniform vec2 uSize;\nuniform float uNoiseScale;\nuniform float uBottom;\nuniform float uTop;\nuniform vec3 uColour;\nuniform float uTear;\nuniform float uTearReach;\nuniform float uFibre;\nuniform float uShadow;\nuniform float uPaper;\nuniform float uGrain;\nuniform float uDarken;\nuniform float uBlur;\n// How far an edge strays from its line at x (frame heights): a slow wander, a ragged middle and fine jags on it.\nfloat stray(float x, float row) {\n float wander = texture2D(tNoise, vec2(x * 0.9, row)).g - 0.5;\n float ragged = texture2D(tNoise, vec2(x * 2.5, row + 0.13)).r - 0.5;\n float jag = texture2D(tNoise, vec2(x * 0.7, row + 0.31)).b - 0.5;\n return (wander + ragged * 0.6 + jag * 0.35) * uTearReach * uTear;\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / uSize;\n vec3 c = texture2D(tColor, uv).rgb;\n if (uBlur > 0.0) c = mix(c, texture2D(tBlurred, uv).rgb, smoothstep(0.0, 0.02, uBlur));\n c *= 1.0 - uDarken;\n float x = uv.x * uSize.x / uSize.y;\n float px = 1.0 / uSize.y;\n float top = uTop + stray(x, 0.21);\n float bottom = uBottom + stray(x, 0.68);\n // Signed distance into the panel from its nearer edge, frame heights: positive inside.\n float depth = min(uv.y - bottom, top - uv.y);\n float inside = smoothstep(-px, px, depth);\n float past = max(-depth, 0.0);\n c *= 1.0 - uShadow * 0.6 * (1.0 - smoothstep(0.0, 0.025, past)) * (1.0 - inside);\n float band = (1.5 + 2.5 * uTear) * px;\n float fibres = (1.0 - smoothstep(band * 0.5, band, past)) * (1.0 - inside);\n float hairs = step(0.985, texture2D(tNoise, vec2(x * 70.0, 0.83)).b) * uTear;\n fibres = max(fibres, hairs * (1.0 - smoothstep(0.0, band * 5.0, past)) * (1.0 - inside));\n vec3 paper = uColour * (1.0 - uPaper * 0.06 * (texture2D(tNoise, vec2(x, uv.y) * 6.0 * uNoiseScale).r - 0.5));\n c = mix(c, paper, inside);\n c = mix(c, mix(uColour, vec3(1.0), 0.6), uFibre * fibres);\n float grain = texture2D(tNoise, gl_FragCoord.xy / 256.0).b - 0.5;\n gl_FragColor = vec4(clamp(c + grain * uGrain, 0.0, 1.0), 1.0);\n}\n";
@@ -0,0 +1,84 @@
1
+ /** How the overlay looks when a frame does not say. Colours are display (sRGB) values: the pass follows the finish. */
2
+ export interface PostSettings {
3
+ /** The noise texture's seed. */
4
+ readonly seed: number;
5
+ /** The paper's colour, "#rrggbb". */
6
+ readonly colour: string;
7
+ /** How torn the panel's edges are, 0 (straight) to 1. */
8
+ readonly tear: number;
9
+ /** The fibre line along a torn or straight edge: a lighter band of paper fibres, 0 to 1. */
10
+ readonly fibre: number;
11
+ /** The paper's own mottle, 0 to 1. */
12
+ readonly paper: number;
13
+ /** A soft shadow the panel casts past its edges onto the frame, 0 to 1. */
14
+ readonly shadow: number;
15
+ /** One-pixel grain over the whole frame, as a share of full luminance, 0 to 0.2. */
16
+ readonly grain: number;
17
+ /** How many times the noise repeats down the frame's height, 0.25 to 8. */
18
+ readonly noiseScale: number;
19
+ /** Give the frame's own target a depth buffer: needed when the frame drawn into it is a plain scene, not a finish. */
20
+ readonly depth: boolean;
21
+ }
22
+ export declare const DEFAULT_POST_SETTINGS: PostSettings;
23
+ /** What a host feeds each frame, from its tracks. Every field is optional; the settings fill the rest. */
24
+ export interface PostValues {
25
+ /**
26
+ * The panel's sweep: 0 none; 0 → 1 its top edge rises from the frame's bottom to its top; 1 it covers the frame;
27
+ * 1 → 2 its bottom edge rises after it, so it leaves through the top; 2 gone.
28
+ */
29
+ readonly progress?: number;
30
+ /** Moves the panel's edges up (positive) or down, in frame heights, -1..1: a second track, a mobile one, say. */
31
+ readonly position?: number;
32
+ /** The paper's colour, [r, g, b] each 0..1 (display values). */
33
+ readonly colour?: readonly [number, number, number];
34
+ readonly tear?: number;
35
+ readonly fibre?: number;
36
+ readonly shadow?: number;
37
+ readonly grain?: number;
38
+ /** Darkens the frame under the panel, 0..1. */
39
+ readonly darken?: number;
40
+ /** Blurs the frame under the panel, 0..1: the outer taps reach `blur` × 16 % of the frame's height. */
41
+ readonly blur?: number;
42
+ }
43
+ /** A frame's values, every one present and bounded. */
44
+ export interface Frame {
45
+ readonly progress: number;
46
+ readonly position: number;
47
+ readonly colour: readonly [number, number, number];
48
+ readonly tear: number;
49
+ readonly fibre: number;
50
+ readonly shadow: number;
51
+ readonly grain: number;
52
+ readonly darken: number;
53
+ readonly blur: number;
54
+ }
55
+ /**
56
+ * Settings from anything: each one checked and bounded, a missing or broken one falling back to its default.
57
+ *
58
+ * @param input A partial settings object, or nothing for the defaults.
59
+ */
60
+ export declare function postSettings(input?: unknown): PostSettings;
61
+ /** "#rrggbb" to [r, g, b] in 0..1, unconverted: the pass works on display values. */
62
+ export declare function displayColour(value: string): [number, number, number];
63
+ /**
64
+ * A frame's values, bounded, with the settings standing in for any left out.
65
+ *
66
+ * @param values What the host's tracks give this frame.
67
+ * @param settings The overlay's settings.
68
+ */
69
+ export declare function frameOf(values: PostValues, settings: PostSettings): Frame;
70
+ /** How far a torn edge can stray from its line, in frame heights, at `tear` 1. */
71
+ export declare const TEAR_REACH = 0.016;
72
+ /**
73
+ * Where the panel's edges are this frame, in frame heights from the bottom (y up). Before progress 1 the panel is open
74
+ * below and its top edge is the sweep; after it the panel is open above and its bottom edge is the sweep.
75
+ *
76
+ * @returns `[bottom, top]`.
77
+ */
78
+ export declare function panelEdges(frame: Frame): [number, number];
79
+ /** Whether the panel, its shadow or its fibres show any of themselves in the frame. */
80
+ export declare function panelShows(frame: Frame): boolean;
81
+ /** Whether a frame needs the pass at all: no panel, no darkening, no blur and no grain draw straight to the host. */
82
+ export declare function idle(frame: Frame): boolean;
83
+ /** The blur's tap step in pixels of the half-size target, for a frame `height` pixels tall (half of it is blurred). */
84
+ export declare function blurStep(blur: number, height: number): number;
@@ -0,0 +1 @@
1
+ export * from './section-post/index.js'
@@ -0,0 +1,107 @@
1
+ {
2
+ "protocol": "keel-module-inputs@1",
3
+ "fields": [
4
+ {
5
+ "key": "seed",
6
+ "label": "Noise seed",
7
+ "required": false,
8
+ "placement": "advanced",
9
+ "type": "number",
10
+ "min": 0,
11
+ "max": 2147483647,
12
+ "step": 1,
13
+ "default": 1
14
+ },
15
+ {
16
+ "key": "colour",
17
+ "label": "Paper colour",
18
+ "required": false,
19
+ "type": "color",
20
+ "swatches": [
21
+ "#f7f7ee",
22
+ "#dcdcd0",
23
+ "#ffffff"
24
+ ],
25
+ "default": "#f7f7ee"
26
+ },
27
+ {
28
+ "key": "tear",
29
+ "label": "Torn edge",
30
+ "required": false,
31
+ "help": "0 is one clean straight edge; 1 is finely jagged paper.",
32
+ "type": "number",
33
+ "min": 0,
34
+ "max": 1,
35
+ "step": 0.01,
36
+ "control": "slider",
37
+ "default": 0
38
+ },
39
+ {
40
+ "key": "fibre",
41
+ "label": "Fibre line",
42
+ "required": false,
43
+ "help": "A thin band of lighter fibres just past the edge.",
44
+ "type": "number",
45
+ "min": 0,
46
+ "max": 1,
47
+ "step": 0.01,
48
+ "control": "slider",
49
+ "default": 0.8
50
+ },
51
+ {
52
+ "key": "shadow",
53
+ "label": "Edge shadow",
54
+ "required": false,
55
+ "help": "A soft shadow the panel casts past its edge.",
56
+ "type": "number",
57
+ "min": 0,
58
+ "max": 1,
59
+ "step": 0.01,
60
+ "control": "slider",
61
+ "default": 0.35
62
+ },
63
+ {
64
+ "key": "paper",
65
+ "label": "Paper mottle",
66
+ "required": false,
67
+ "placement": "advanced",
68
+ "type": "number",
69
+ "min": 0,
70
+ "max": 1,
71
+ "step": 0.01,
72
+ "default": 0.4
73
+ },
74
+ {
75
+ "key": "grain",
76
+ "label": "Grain",
77
+ "required": false,
78
+ "help": "One-pixel grain over the whole frame, as a share of full luminance.",
79
+ "type": "number",
80
+ "min": 0,
81
+ "max": 0.2,
82
+ "step": 0.005,
83
+ "control": "slider",
84
+ "default": 0.02
85
+ },
86
+ {
87
+ "key": "noiseScale",
88
+ "label": "Noise scale",
89
+ "required": false,
90
+ "placement": "advanced",
91
+ "type": "number",
92
+ "min": 0.25,
93
+ "max": 8,
94
+ "step": 0.05,
95
+ "default": 1
96
+ },
97
+ {
98
+ "key": "depth",
99
+ "label": "Depth buffer",
100
+ "required": false,
101
+ "help": "Needed when the frame is a plain scene, not a finish.",
102
+ "placement": "advanced",
103
+ "type": "boolean",
104
+ "default": false
105
+ }
106
+ ]
107
+ }
@@ -0,0 +1,53 @@
1
+ // section-post@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var T={seed:1,colour:"#f7f7ee",tear:0,fibre:.8,paper:.4,shadow:.35,grain:.02,noiseScale:1,depth:!1},A=/^#[0-9a-f]{6}$/iu;function d(r,e,o,t){return typeof r=="number"&&Number.isFinite(r)?Math.min(t,Math.max(o,r)):e}function h(r){if(r==null||typeof r!="object")return T;let e=r,o=T;return{seed:Math.trunc(d(e.seed,o.seed,0,2147483647)),colour:typeof e.colour=="string"&&A.test(e.colour)?e.colour.toLowerCase():o.colour,tear:d(e.tear,o.tear,0,1),fibre:d(e.fibre,o.fibre,0,1),paper:d(e.paper,o.paper,0,1),shadow:d(e.shadow,o.shadow,0,1),grain:d(e.grain,o.grain,0,.2),noiseScale:d(e.noiseScale,o.noiseScale,.25,8),depth:typeof e.depth=="boolean"?e.depth:o.depth}}function _(r){let e=Number.parseInt(r.slice(1),16);return[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]}function w(r,e){let o=r.colour?.length===3&&r.colour.every(Number.isFinite)?[...r.colour]:_(e.colour);return{progress:d(r.progress,0,0,2),position:d(r.position,0,-1,1),colour:o,tear:d(r.tear,e.tear,0,1),fibre:d(r.fibre,e.fibre,0,1),shadow:d(r.shadow,e.shadow,0,1),grain:d(r.grain,e.grain,0,.2),darken:d(r.darken,0,0,1),blur:d(r.blur,0,0,1)}}var S=.016,G=.03,v=4;function x(r){return r.progress<=1?[-v,r.progress+r.position]:[r.progress-1+r.position,v]}function M(r){let[e,o]=x(r),t=r.tear*S+G;return r.progress>0&&r.progress<2&&o>-t&&e<1+t}function L(r){return!M(r)&&r.darken===0&&r.blur===0&&r.grain===0}function P(r,e){return r*.05*Math.max(1,Math.ceil(e/2))}var y=256;function k(r,e,o){let t=Math.imul(r|0,521288629)^Math.imul(e|0,1597334677)^(o|0);return t=Math.imul(t^t>>>15,739982445),t=Math.imul(t^t>>>12,695872825),((t^t>>>15)>>>0)/4294967296}var N=r=>r*r*(3-2*r);function U(r,e,o,t){let a=r*o,s=e*o,u=Math.floor(a),n=Math.floor(s),i=N(a-u),m=N(s-n),l=(b,g)=>k(b%o,g%o,t),c=l(u,n)+(l(u+1,n)-l(u,n))*i,f=l(u,n+1)+(l(u+1,n+1)-l(u,n+1))*i;return c+(f-c)*m}function D(r,e,o,t){let a=0,s=1;for(let u=0;u<4;u+=1)a+=U(r,e,o<<u,t+u)*s,s/=2;return a/1.875}function B(r){let e=1/0,o=-1/0;for(let a of r)e=Math.min(e,a),o=Math.max(o,a);let t=o>e?o-e:1;return Uint8Array.from(r,a=>Math.round((a-e)/t*255))}function R(r=0,e=256){let o=e*e,t=new Float64Array(o),a=new Float64Array(o);for(let i=0;i<e;i+=1)for(let m=0;m<e;m+=1)t[i*e+m]=D(m/e,i/e,16,r),a[i*e+m]=D(m/e,i/e,4,r+101);let s=B(t),u=B(a),n=new Uint8Array(o*4);for(let i=0;i<o;i+=1)n[i*4]=s[i]??0,n[i*4+1]=u[i]??0,n[i*4+2]=Math.floor(k(i%e,Math.floor(i/e),r+7)*256),n[i*4+3]=255;return n}var E=`
3
+ void main() { gl_Position = vec4(position.xy, 0.0, 1.0); }
4
+ `,F=`
5
+ precision highp float;
6
+ uniform sampler2D tColor;
7
+ uniform sampler2D tBlurred;
8
+ uniform sampler2D tNoise;
9
+ uniform vec2 uSize;
10
+ uniform float uNoiseScale;
11
+ uniform float uBottom;
12
+ uniform float uTop;
13
+ uniform vec3 uColour;
14
+ uniform float uTear;
15
+ uniform float uTearReach;
16
+ uniform float uFibre;
17
+ uniform float uShadow;
18
+ uniform float uPaper;
19
+ uniform float uGrain;
20
+ uniform float uDarken;
21
+ uniform float uBlur;
22
+ // How far an edge strays from its line at x (frame heights): a slow wander, a ragged middle and fine jags on it.
23
+ float stray(float x, float row) {
24
+ float wander = texture2D(tNoise, vec2(x * 0.9, row)).g - 0.5;
25
+ float ragged = texture2D(tNoise, vec2(x * 2.5, row + 0.13)).r - 0.5;
26
+ float jag = texture2D(tNoise, vec2(x * 0.7, row + 0.31)).b - 0.5;
27
+ return (wander + ragged * 0.6 + jag * 0.35) * uTearReach * uTear;
28
+ }
29
+ void main() {
30
+ vec2 uv = gl_FragCoord.xy / uSize;
31
+ vec3 c = texture2D(tColor, uv).rgb;
32
+ if (uBlur > 0.0) c = mix(c, texture2D(tBlurred, uv).rgb, smoothstep(0.0, 0.02, uBlur));
33
+ c *= 1.0 - uDarken;
34
+ float x = uv.x * uSize.x / uSize.y;
35
+ float px = 1.0 / uSize.y;
36
+ float top = uTop + stray(x, 0.21);
37
+ float bottom = uBottom + stray(x, 0.68);
38
+ // Signed distance into the panel from its nearer edge, frame heights: positive inside.
39
+ float depth = min(uv.y - bottom, top - uv.y);
40
+ float inside = smoothstep(-px, px, depth);
41
+ float past = max(-depth, 0.0);
42
+ c *= 1.0 - uShadow * 0.6 * (1.0 - smoothstep(0.0, 0.025, past)) * (1.0 - inside);
43
+ float band = (1.5 + 2.5 * uTear) * px;
44
+ float fibres = (1.0 - smoothstep(band * 0.5, band, past)) * (1.0 - inside);
45
+ float hairs = step(0.985, texture2D(tNoise, vec2(x * 70.0, 0.83)).b) * uTear;
46
+ fibres = max(fibres, hairs * (1.0 - smoothstep(0.0, band * 5.0, past)) * (1.0 - inside));
47
+ vec3 paper = uColour * (1.0 - uPaper * 0.06 * (texture2D(tNoise, vec2(x, uv.y) * 6.0 * uNoiseScale).r - 0.5));
48
+ c = mix(c, paper, inside);
49
+ c = mix(c, mix(uColour, vec3(1.0), 0.6), uFibre * fibres);
50
+ float grain = texture2D(tNoise, gl_FragCoord.xy / 256.0).b - 0.5;
51
+ gl_FragColor = vec4(clamp(c + grain * uGrain, 0.0, 1.0), 1.0);
52
+ }
53
+ `;function p(r,e,o){let t=r[e];t!==void 0&&(t.value=o)}function C(r,e,o,t){let a=new r.CustomMaterial({uniforms:o,vertexShader:E,fragmentShader:t,depthTest:!1,depthWrite:!1}),s=new r.Mesh(e,a);s.frustumCulled=!1;let u=new r.Stage;return u.add(s),{scene:u,material:a}}function O(r,e){let o=new r.DataTexture(R(e),256,256,"rgba");return o.wrapS="repeat",o.wrapT="repeat",o.minFilter="linear",o.magFilter="linear",o.needsUpdate=!0,o}function I(r,e,o){let t={minFilter:"linear",magFilter:"linear",generateMipmaps:!1,depthBuffer:!1},a=new r.RenderTarget(1,1,{...t,depthBuffer:o.depth}),s=[new r.RenderTarget(1,1,t),new r.RenderTarget(1,1,t)],u=r.plane(2,2),n=c=>({value:c}),i=C(r,u,{tColor:n(a.texture),tBlurred:n(s[1].texture),tNoise:n(O(r,o.seed)),uSize:n([1,1]),uNoiseScale:n(1),uBottom:n(-4),uTop:n(-4),uColour:n([1,1,1]),uTear:n(0),uTearReach:n(S),uFibre:n(0),uShadow:n(0),uPaper:n(0),uGrain:n(0),uDarken:n(0),uBlur:n(0)},F),m={tBlur:n(null),uBloomSize:n([1,1]),uDir:n([1,0])},l=C(r,u,m,e.BLUR_GLSL);return{frame:a,blurred:s,post:i,blur:l,camera:new r.OrthoCamera(-1,1,1,-1,0,1),geometry:u}}function j(r,e,o){let[t,a]=x(e),s=[["uBottom",t],["uTop",a],["uColour",e.colour],["uTear",e.tear],["uFibre",e.fibre],["uShadow",e.shadow],["uGrain",e.grain],["uDarken",e.darken],["uBlur",e.blur],["uPaper",o.paper],["uNoiseScale",o.noiseScale]];for(let[u,n]of s)p(r,u,n)}function H(r,e,o){let t=e.blur.material.uniforms;p(t,"tBlur",e.frame.texture),p(t,"uDir",[o,0]),r.setRenderTarget(e.blurred[0]),r.render(e.blur.scene,e.camera),p(t,"tBlur",e.blurred[0].texture),p(t,"uDir",[0,o]),r.setRenderTarget(e.blurred[1]),r.render(e.blur.scene,e.camera)}function V(r,e,o,t){let a=h(t),s=I(r,o,a),u=s.post.material.uniforms,n=1;return{get settings(){return a},setSettings(i){let m=a.seed;if(a=h(i),a.seed!==m){let l=u.tNoise?.value;p(u,"tNoise",O(r,a.seed)),l.dispose()}return a},setSize(i,m,l){let c=g=>Math.max(1,Math.round(g*l)),f=[c(i),c(m)],b=[Math.max(1,Math.ceil(f[0]/2)),Math.max(1,Math.ceil(f[1]/2))];s.frame.setSize(f[0],f[1]);for(let g of s.blurred)g.setSize(b[0],b[1]);p(u,"uSize",f),p(s.blur.material.uniforms,"uBloomSize",b),n=f[1]},render(i,m={}){let l=w(m,a);if(L(l)){i();return}let c=e.getRenderTarget();e.setRenderTarget(s.frame),i(),l.blur>0&&H(e,s,P(l.blur,n)),j(u,l,a),e.setRenderTarget(c),e.render(s.post.scene,s.camera)},dispose(){for(let i of[s.frame,...s.blurred])i.dispose();(u.tNoise?.value).dispose(),s.post.material.dispose(),s.blur.material.dispose(),s.geometry.dispose()}}}export{T as DEFAULT_POST_SETTINGS,y as NOISE_SIZE,F as POST_GLSL,E as POST_VERTEX_GLSL,S as TEAR_REACH,P as blurStep,V as createSectionPost,_ as displayColour,w as frameOf,L as idle,k as latticeHash,R as noiseTexels,x as panelEdges,M as panelShows,h as postSettings};
@@ -0,0 +1,8 @@
1
+ /** A 32-bit hash of two integers. The shaders' `hh` is the same function. */
2
+ export declare function hash(a: number, b: number): number;
3
+ /** A stream of numbers between `low` and `high` that depends on the seed and on `stream` only. */
4
+ export declare function draws(seed: number, stream: number): (low: number, high: number) => number;
5
+ /** The unit vector along `x, y`, turned by the angle whose half-tangent is `t`. */
6
+ export declare function turn(x: number, y: number, t?: number): [number, number];
7
+ /** FNV-1a over the bytes of 32-bit floats, two lanes, as 16 hex digits. */
8
+ export declare function digestOf(parts: readonly Float32Array[]): string;
@@ -0,0 +1,7 @@
1
+ type Rgb = [number, number, number];
2
+ /** Reads a plan's uniforms by index. */
3
+ export type Uniforms = (index: number) => number;
4
+ type Surface = (u: Uniforms, x: number, y: number, c: Rgb) => number;
5
+ /** Each kind's painter, by its number in `KINDS`. */
6
+ export declare const FIELDS: readonly Surface[];
7
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { Surface } from "./paint.js";
2
+ import { type SurfacePlan, type SurfaceSettings } from "./plan.js";
3
+ import type { SurfaceRecipe } from "./recipe.js";
4
+ /** Paints surfaces on one context. */
5
+ export interface SurfacePainter {
6
+ /** A recipe in, `{ digest, buffers }` out, as `paintSurface` gives on the CPU. */
7
+ paint(recipe: SurfaceRecipe, settings?: SurfaceSettings): Surface;
8
+ /** The same from a plan already made. */
9
+ paintPlan(plan: SurfacePlan): Surface;
10
+ /** Frees the programs. */
11
+ dispose(): void;
12
+ }
13
+ /**
14
+ * A painter on a WebGL2 context. Each kind's program compiles the first time it paints.
15
+ *
16
+ * @param gl The host's context. The painter restores the state it changes.
17
+ * @returns paint, paintPlan and dispose.
18
+ */
19
+ export declare function createSurfacePainter(gl: WebGL2RenderingContext): SurfacePainter;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * surfaces: seeded painters of 2D surfaces (paper, rib knit, a painted ground), each an albedo and a relief (normal
3
+ * and height) at any size, on the GPU or the CPU; and prints, a host's own 2D drawing as a lit texture. MIT.
4
+ *
5
+ * A recipe in, `{ digest, buffers }` out: `planSurface` works out every number in exact arithmetic with a digest, so a
6
+ * host caches a surface by it; `paintSurface` paints on the CPU and `createSurfacePainter(gl).paint` on the GPU.
7
+ */
8
+ export { KNIT, PAINTED_CLOTH, PAINTED_FLORAL, PAPER, PLANNED } from "./recipe.js";
9
+ export type { Axis, CracksRecipe, Folds, KnitRecipe, Mass, MotifRecipe, PaintedRecipe, PaperRecipe, PlannedRecipe, SurfaceRecipe, VeinsRecipe, } from "./recipe.js";
10
+ export { KINDS, MAX_MASSES, PAINTER_VERSION, UNIFORMS, planSurface } from "./plan.js";
11
+ export type { SurfacePlan, SurfaceSettings } from "./plan.js";
12
+ export { paintPlan, paintSurface } from "./paint.js";
13
+ export type { Surface } from "./paint.js";
14
+ export { createSurfacePainter } from "./gpu.js";
15
+ export type { SurfacePainter } from "./gpu.js";
16
+ export { createPrinter, pbr, surfaceTextures } from "./print.js";
17
+ export type { CanvasLike, Context2D, DataTextureLike, DrawPrint, Print, PrintLit, PrintOptions, TextureLike, } from "./print.js";
@@ -0,0 +1,28 @@
1
+ import { type SurfacePlan, type SurfaceSettings } from "./plan.js";
2
+ import type { SurfaceRecipe } from "./recipe.js";
3
+ /**
4
+ * A painted surface. `buffers` is `[albedo, relief]`, each `width × height × 4` bytes, rows from the top as
5
+ * `ImageData` holds them: the albedo in sRGB with alpha 255; the relief's normal in RGB (+x right, +y toward the top
6
+ * row, 128 flat) and its height in A. Post it to another thread with `postMessage(surface, surface.buffers)`.
7
+ */
8
+ export interface Surface {
9
+ readonly digest: string;
10
+ readonly width: number;
11
+ readonly height: number;
12
+ readonly buffers: [ArrayBuffer, ArrayBuffer];
13
+ }
14
+ /**
15
+ * Paints a plan on the CPU: the shaders' arithmetic in JavaScript, the same bytes but for float rounding.
16
+ *
17
+ * @param plan From `planSurface`.
18
+ * @returns The surface.
19
+ */
20
+ export declare function paintPlan(plan: SurfacePlan): Surface;
21
+ /**
22
+ * Paints a surface on the CPU: a recipe in, `{ digest, buffers }` out.
23
+ *
24
+ * @param recipe What the surface holds.
25
+ * @param settings The seed and the size in pixels.
26
+ * @returns The surface.
27
+ */
28
+ export declare function paintSurface(recipe: SurfaceRecipe, settings?: SurfaceSettings): Surface;