@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,452 @@
1
+ // voxel-dither@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var w=["none","bayer2","bayer4","bayer8","halftone","lines","diagonal","hatch","ign","stipple","checker"],se=["#000000","#1d2b53","#7e2553","#008751","#ab5236","#5f574f","#c2c3c7","#fff1e8","#ff004d","#ffa300","#ffec27","#00e436","#29adff","#83769c","#ff77a8","#ffccaa"],ce=["#000000","#222034","#45283c","#663931","#8f563b","#df7126","#d9a066","#eec39a","#fbf236","#99e550","#6abe30","#37946e","#4b692f","#524b24","#323c39","#3f3f74","#306082","#5b6ee1","#639bff","#5fcde4","#cbdbfc","#ffffff","#9badb7","#847e87","#696a6a","#595652","#76428a","#ac3232","#d95763","#d77bba","#8f974a","#8a6f30"],ue=["#f3ead6","#1e1c2a","#2f8fc4","#e2477d","#f4c542","#d9503f","#3c9a63","#3e4597","#f4a8c6","#a8cde4"],de=["#1b1726","#3a2d45","#5c4363","#8a5a78","#c77d97","#f0a8bd","#ffd9e2","#fff6ef","#2e4a3c","#4f7a52","#8fb36a","#d6e59a","#6b4a3a","#a0705a","#7fa7c9","#cfe3ef"],B={pixel:{label:"3D pixel art",screen:"bayer4",pixel:4,levels:5,snap:.45,lift:.07,clump:.6,ramp:.6,color:"luma",shading:"cel",bands:3,outline:1,crease:.3,contrast:1.25,saturation:1.45},smart:{label:"Smart voxel",screen:"auto",pixel:0,levels:6,lift:.03,clump:.5,ramp:.35,color:"luma",shading:"cel",bands:4,outline:.9,crease:.35,contrast:1.05,saturation:1.1},bayer:{label:"Bayer 32",screen:"bayer4",pixel:4,palette:ce,lift:.04,shading:"cel",bands:3,outline:.85,crease:.25,contrast:1.1,saturation:1.25},soft:{label:"Soft ordered",screen:"bayer8",pixel:3,levels:5,lift:.12,clump:.4,ramp:.3,color:"luma",shading:"smooth",outline:.5,crease:.2,contrast:.92,saturation:.95},halftone:{label:"Riso print",screen:"halftone",pixel:2,palette:ue,shading:"smooth",outline:.7,outlineColor:"#3e4597",crease:0,contrast:1.15,saturation:1.3},engraving:{label:"Engraving",screen:"hatch",pixel:2,levels:3,color:"luma",shading:"smooth",outline:1,outlineColor:"#1d1a24",crease:.3,saturation:.55,rays:1.3},chunky:{label:"Chunky 8-bit",screen:"bayer2",pixel:6,palette:se,amount:.4,skySaturation:2,clump:.85,shading:"cel",bands:3,outline:1,crease:.4,contrast:1.15,saturation:1.3},grain:{label:"Film grain",screen:"ign",pixel:2,levels:6,lift:.14,ramp:1,color:"luma",shading:"smooth",outline:.4,crease:.1,contrast:1.2,saturation:.8},blossom:{label:"Blossom 16",screen:"bayer4",pixel:3,palette:de,shading:"cel",bands:4,outline:.9,crease:.3},pocket:{label:"Pocket green",screen:"bayer4",pixel:4,palette:["#0f2a1d","#2f5a35","#7a9a4a","#cddc8a"],accent:["#e8a6b8","#a85a76"],shading:"cel",bands:3,outline:0,crease:0,saturation:1,rays:.6},clean:{label:"Clean cel",screen:"none",pixel:3,levels:5,clump:1,lift:.05,color:"luma",shading:"cel",bands:3,outline:1,outlineColor:"#241a2e",crease:.5,contrast:1.15,saturation:1.35},crt:{label:"CRT painted",screen:"bayer8",pixel:2,levels:7,snap:.75,color:"luma",shading:"smooth",outline:1,outlineColor:"#0b0d22",crease:.15,contrast:1.3,saturation:1.55,scanlines:.55,chroma:.5}},K=Object.keys(B),k={style:"smart",screen:"auto",pixel:0,detail:0,levels:6,color:"luma",palette:[],accent:[],skySaturation:1,amount:1,snap:0,lift:0,clump:0,ramp:0,shading:"cel",bands:4,outline:.9,outlineColor:null,crease:.35,contrast:1.05,saturation:1.1,depthBands:[18,30],rays:1,skyDistance:0,scanlines:0,chroma:0,glitch:0},D=/^#[0-9a-f]{6}$/iu;function c(e,t,a,r){return typeof e=="number"&&Number.isFinite(e)?Math.min(a,Math.max(t,e)):r}function L(e,t,a){return typeof e=="string"&&t.includes(e)?e:a}function fe(e,t){return e===null?null:typeof e=="string"&&D.test(e)?e.toLowerCase():t}function X(e,t){return Array.isArray(e)?e.filter(a=>typeof a=="string"&&D.test(a)).slice(0,32).map(a=>a.toLowerCase()):t}function E(e,t){if(!Array.isArray(e)||e.length!==2)return t;let a=c(e[0],.1,1e3,t[0]);return[a,c(e[1],a,1e3,Math.max(a,t[1]))]}function me(e){let t=Object.fromEntries(Object.entries(B[e]).filter(([a])=>a!=="label"));return{...k,...t,style:e}}function he(e,t){return{levels:Math.round(c(e.levels,2,16,t.levels)),color:L(e.color,["rgb","luma"],t.color),palette:X(e.palette,t.palette),accent:X(e.accent,t.accent).slice(0,4),skySaturation:c(e.skySaturation,0,3,t.skySaturation),amount:c(e.amount,0,1,t.amount),snap:c(e.snap,0,.9,t.snap),lift:c(e.lift,0,.3,t.lift),clump:c(e.clump,0,1,t.clump),ramp:c(e.ramp,0,1,t.ramp),contrast:c(e.contrast,.5,2,t.contrast),saturation:c(e.saturation,0,2,t.saturation)}}function pe(e,t){return{scanlines:c(e.scanlines,0,1,t.scanlines),chroma:c(e.chroma,0,1,t.chroma),glitch:c(e.glitch,0,1,t.glitch)}}function ge(e,t){return{screen:L(e.screen,["auto",...w],t.screen),pixel:Math.round(c(e.pixel,0,12,t.pixel)*2)/2,detail:Math.round(c(e.detail,0,12,t.detail)*2)/2,shading:L(e.shading,["cel","smooth"],t.shading),bands:Math.round(c(e.bands,2,8,t.bands)),outline:c(e.outline,0,1,t.outline),outlineColor:fe(e.outlineColor,t.outlineColor),crease:c(e.crease,0,1,t.crease),depthBands:E(e.depthBands,t.depthBands),rays:c(e.rays,0,2,t.rays),skyDistance:c(e.skyDistance,0,1e5,t.skyDistance)}}function T(e){if(e===null||typeof e!="object")return k;let t=e,a=me(L(t.style,K,k.style)),r={...a,...he(t,a),...ge(t,a),...pe(t,a)};return ye(r,t.limit)}function ye(e,t){if(t===null||typeof t!="object")return e;let a=Math.round(c(t.levels,0,16,0)),r=Math.round(c(t.colours,0,1<<24,0));return{...e,levels:a>=2?Math.min(e.levels,a):e.levels,palette:r>=2?e.palette.slice(0,r):e.palette}}var be=4;function ve(e,t,a){if(t<=0)return 1;let r=Math.max(1,Math.round(t*a)),o=1;for(let n=2;n<=be;n+=1)e%n===0&&e/n>=r&&(o=n);return o}function W(e,t){let a=Math.max(1,Math.min(e,t));return Math.min(6,Math.max(2,Math.round(a/210)))}function I(e,t,a,r){let o=c(a,.5,4,1),n=r.pixel===0?W(e,t):r.pixel,l=Math.max(1,Math.round(n*o)),i=Math.max(1,Math.floor(e*o)),s=Math.max(1,Math.floor(t*o)),m=Math.ceil(i/l),h=Math.ceil(s/l);return{width:m,height:h,pixel:l,originX:Math.floor((i-m*l)/2),originY:Math.floor((s-h*l)/2),detail:ve(l,r.detail,o)}}function z(e,t){let a=e.amount;if(e.screen!=="auto"){let r=e.screen;return{near:{screen:r,scale:1,amount:a},mid:{screen:r,scale:1,amount:a*.85},far:{screen:r,scale:1,amount:a*.6}}}return t<128?{near:{screen:"bayer2",scale:1,amount:a},mid:{screen:"bayer2",scale:1,amount:a*.8},far:{screen:"checker",scale:1,amount:a*.5}}:t<260?{near:{screen:"bayer4",scale:1,amount:a},mid:{screen:"bayer8",scale:1,amount:a*.8},far:{screen:"bayer8",scale:1,amount:a*.5}}:{near:{screen:"bayer8",scale:1,amount:a},mid:{screen:"bayer8",scale:1,amount:a*.8},far:{screen:"ign",scale:1,amount:a*.45}}}var v=e=>e-Math.floor(e),R=(e,t)=>Math.abs(v(e/t)*2-1);function A(e,t){let a=Math.floor(e),r=Math.floor(t);return v(a*.5+r*r*.75)}var x=(e,t)=>A(e*.5,t*.5)*.25+A(e,t),xe=(e,t)=>x(e*.5,t*.5)*.25+A(e,t);function Se(e,t){let a=v((e+t+1)*.1767767)-.5,r=v((e-t)*.1767767)-.5;return Math.min(.999,Math.hypot(a,r)*1.41421356)}function ke(e,t){let a=Math.imul(Math.floor(e)>>>0,1973)+Math.imul(Math.floor(t)>>>0,9277)|1;return a^=a>>>16,a=Math.imul(a,2146121005),a^=a>>>15,a=Math.imul(a,2221713035),a^=a>>>16,(a&65535)/65536}var Le={none:()=>.5,bayer2:A,bayer4:x,bayer8:xe,halftone:Se,lines:(e,t)=>R(t+.5,4)*.7+x(e,t)*.3,diagonal:(e,t)=>R(e+t+.5,4)*.7+x(e,t)*.3,hatch:(e,t)=>Math.min(R(e+t+.5,4),.5+.5*R(e-t+.5,4))*.75+x(e,t)*.25,ign:(e,t)=>v(52.9829189*v(.06711056*Math.floor(e)+.00583715*Math.floor(t))),stipple:ke,checker:(e,t)=>(Math.floor(e)+Math.floor(t)&1)*.5+.25};function we(e,t,a){return Le[e](t,a)}function De(e,t,a=1,r=0){let{levels:o,threshold:n}=t,l=Math.max(1,o-1),i=.5+(n-.5)*Math.min(1,Math.max(0,a)),s=Math.min(1,Math.max(0,e))*l,m=Math.floor(s),h=Math.min(1,Math.max(0,(s-m-.5)/Math.max(1-Math.min(.9,Math.max(0,r)),.001)+.5));return Math.min(l,Math.max(0,m+(h>=1-i?1:0)))/l}function _(e){let t=Math.round(c(e,2,8,4)),a=new Uint8Array(t);for(let r=0;r<t;r+=1)a[r]=Math.round(255*(.3+.7*(r/(t-1))**1.2));return a}function M(e){let t=Number.parseInt(e.slice(1),16);return[(t>>16&255)/255,(t>>8&255)/255,(t&255)/255]}function $(e){let[t,a,r]=e.map(i=>i<=.04045?i/12.92:((i+.055)/1.055)**2.4),o=Math.cbrt(.4122*t+.5363*a+.0514*r),n=Math.cbrt(.2119*t+.6807*a+.1074*r),l=Math.cbrt(.0883*t+.2817*a+.63*r);return[.2105*o+.7936*n-.0041*l,1.978*o-2.4286*n+.4506*l,.0259*o+.7828*n-.8087*l]}function F(e){let t=new Float32Array(96),a=new Float32Array(96),r=e.slice(0,32);return r.forEach((o,n)=>{let l=M(o);t.set(l,n*3),a.set($(l),n*3)}),{data:t,lab:a,size:r.length}}var Te=`
3
+ float bayer2(vec2 a) { a = floor(a); return fract(a.x * 0.5 + a.y * a.y * 0.75); }
4
+ float bayer4(vec2 a) { return bayer2(0.5 * a) * 0.25 + bayer2(a); }
5
+ float bayer8(vec2 a) { return bayer4(0.5 * a) * 0.25 + bayer2(a); }
6
+ float tri(float v, float p) { return abs(fract(v / p) * 2.0 - 1.0); }
7
+ float halftone(vec2 a) {
8
+ vec2 f = fract(vec2(a.x + a.y + 1.0, a.x - a.y) * 0.1767767) - 0.5;
9
+ return min(0.999, length(f) * 1.41421356);
10
+ }
11
+ float stipple(vec2 a) {
12
+ uint h = (uint(a.x) * 1973u + uint(a.y) * 9277u) | 1u;
13
+ h ^= h >> 16; h *= 0x7feb352du; h ^= h >> 15; h *= 0x846ca68bu; h ^= h >> 16;
14
+ return float(h & 0xffffu) / 65536.0;
15
+ }
16
+ float screenAt(float id, vec2 a) {
17
+ int s = int(id + 0.5);
18
+ if (s == 1) return bayer2(a);
19
+ if (s == 2) return bayer4(a);
20
+ if (s == 3) return bayer8(a);
21
+ if (s == 4) return halftone(a);
22
+ if (s == 5) return tri(a.y + 0.5, 4.0) * 0.7 + bayer4(a) * 0.3;
23
+ if (s == 6) return tri(a.x + a.y + 0.5, 4.0) * 0.7 + bayer4(a) * 0.3;
24
+ if (s == 7) return min(tri(a.x + a.y + 0.5, 4.0), 0.5 + 0.5 * tri(a.x - a.y + 0.5, 4.0)) * 0.75 + bayer4(a) * 0.25;
25
+ if (s == 8) return fract(52.9829189 * fract(0.06711056 * a.x + 0.00583715 * a.y));
26
+ if (s == 9) return stipple(a);
27
+ if (s == 10) return mod(a.x + a.y, 2.0) * 0.5 + 0.25;
28
+ return 0.5;
29
+ }
30
+ `,U=`
31
+ void main() { gl_Position = vec4(position.xy, 0.0, 1.0); }
32
+ `,N=`
33
+ precision highp float;
34
+ precision highp int;
35
+ uniform sampler2D tColor;
36
+ uniform sampler2D tDepth;
37
+ uniform vec2 uGrid;
38
+ // The detail parts' own colour and depth, uFine texels to an art pixel's side,
39
+ // and (on the detail pass) the world's finished look to fill in around them.
40
+ uniform sampler2D tDetail;
41
+ uniform sampler2D tDetailDepth;
42
+ uniform sampler2D tCoarse;
43
+ uniform float uFine;
44
+ uniform float uPass;
45
+ uniform float uNear;
46
+ uniform float uFar;
47
+ uniform float uOrtho;
48
+ uniform vec3 uScreen;
49
+ uniform vec3 uScale;
50
+ uniform vec3 uAmount;
51
+ uniform vec2 uBands;
52
+ uniform float uLevels;
53
+ uniform float uSnap;
54
+ uniform float uLift;
55
+ uniform float uClump;
56
+ uniform float uRamp;
57
+ uniform float uLuma;
58
+ uniform int uPaletteSize;
59
+ uniform int uAccentSize;
60
+ uniform vec3 uAccent[4];
61
+ uniform vec3 uAccentLab[4];
62
+ uniform float uSkySaturation;
63
+ uniform vec3 uPalette[32];
64
+ uniform vec3 uPaletteLab[32];
65
+ uniform float uOutline;
66
+ uniform vec4 uOutlineColor;
67
+ uniform float uCrease;
68
+ uniform float uContrast;
69
+ uniform float uSaturation;
70
+ uniform float uSkyFrom;
71
+ uniform vec2 uRaySource;
72
+ uniform vec3 uRayColor;
73
+ uniform float uRayStrength;
74
+ uniform float uRayDecay;
75
+ uniform float uRayDensity;
76
+ uniform float uScanlines;
77
+ uniform float uChroma;
78
+ uniform float uGlitch;
79
+ uniform float uTime;
80
+ // Per-part signals: x scanlines, y chroma, z glitch, for the parts tagged 1, 2 and 3.
81
+ uniform vec3 uSignal[3];
82
+ // Per-part filters: x the filter's number in SIGNAL_FILTERS, y its amount.
83
+ uniform vec2 uFilter[3];
84
+ ${Te}
85
+ // The pass's cells: art pixels (gF 1), or detail pixels (gF uFine) on the detail pass.
86
+ vec2 gGrid;
87
+ float gF;
88
+ vec2 worldUv(vec2 cell) { return (floor(clamp(cell, vec2(0.0), gGrid - 1.0) / gF) + 0.5) / uGrid; }
89
+ vec2 detailUv(vec2 cell) { return (clamp(cell, vec2(0.0), gGrid - 1.0) + 0.5) / gGrid; }
90
+ // The world is drawn once per art pixel and the detail parts per detail pixel; a cell shows the nearer.
91
+ bool onDetail(vec2 cell) { return gF > 1.5 && texture2D(tDetailDepth, detailUv(cell)).x < texture2D(tDepth, worldUv(cell)).x; }
92
+ vec4 colorAt(vec2 cell) { return onDetail(cell) ? texture2D(tDetail, detailUv(cell)) : texture2D(tColor, worldUv(cell)); }
93
+ float distanceAt(vec2 cell) {
94
+ float d = texture2D(tDepth, worldUv(cell)).x;
95
+ if (gF > 1.5) d = min(d, texture2D(tDetailDepth, detailUv(cell)).x);
96
+ if (d >= 0.99999) return uFar;
97
+ if (uOrtho > 0.5) return uNear + d * (uFar - uNear);
98
+ return (uNear * uFar) / (uFar - d * (uFar - uNear));
99
+ }
100
+ // God rays: walk from the pixel toward the light, gathering the open sky the
101
+ // walk crosses. Trees and terrain block it, so shafts fall between them. The
102
+ // result is added in continuous light and only then stepped, so the shafts
103
+ // come out as dithered bands.
104
+ vec3 godRays(vec2 cell) {
105
+ if (uRayStrength <= 0.001) return vec3(0.0);
106
+ vec2 uv = (cell + 0.5) / gGrid;
107
+ vec2 step = (uv - uRaySource) * uRayDensity / 40.0;
108
+ vec2 aspect = vec2(gGrid.x / gGrid.y, 1.0);
109
+ vec2 p = uv;
110
+ float weight = 1.0;
111
+ float sum = 0.0;
112
+ for (int i = 0; i < 40; i++) {
113
+ p -= step;
114
+ float open = distanceAt(floor(clamp(p, 0.0, 0.9999) * gGrid)) >= uSkyFrom ? 1.0 : 0.0;
115
+ float near = 0.3 + 0.7 * exp(-3.5 * length((p - uRaySource) * aspect));
116
+ sum += open * near * weight;
117
+ weight *= uRayDecay;
118
+ }
119
+ return uRayColor * (sum / 40.0) * uRayStrength;
120
+ }
121
+ vec3 toSrgb(vec3 c) {
122
+ c = max(c, 0.0);
123
+ return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(vec3(0.0031308), c));
124
+ }
125
+ // One step: the share past the lower tone, squeezed by uSnap so most of it
126
+ // snaps flat and only the middle of the step dithers.
127
+ float snapStep(float value, float t) {
128
+ float base = floor(value);
129
+ float share = clamp((value - base - 0.5) / max(1.0 - uSnap, 0.001) + 0.5, 0.0, 1.0);
130
+ return base + step(1.0 - t, share);
131
+ }
132
+ vec3 stepTones(vec3 c, float t) {
133
+ float steps = max(1.0, uLevels - 1.0);
134
+ if (uLuma < 0.5) {
135
+ // Dither between two step colours only, never off-hue confetti.
136
+ vec3 q = floor(c * steps + 0.5);
137
+ vec3 e = c * steps - q;
138
+ vec3 a = abs(e);
139
+ vec3 lean = step(0.5 * max(a.x, max(a.y, a.z)) + 0.001, a);
140
+ float share = dot(a, lean) / max(1.0, dot(lean, vec3(1.0)));
141
+ share = clamp((share - 0.5) / max(1.0 - uSnap, 0.001) + 0.5, 0.0, 1.0);
142
+ return clamp((q + sign(e) * lean * step(1.0 - t, share)) / steps, 0.0, 1.0);
143
+ }
144
+ // YCoCg: lightness gets twice the steps of colour, so shading reads as ramps.
145
+ float y = dot(c, vec3(0.25, 0.5, 0.25));
146
+ float co = 0.5 * (c.r - c.b);
147
+ float cg = -0.25 * c.r + 0.5 * c.g - 0.25 * c.b;
148
+ // Colour dithers gently; warm-cool steps finely, so a pale sky or night navy keeps its hue. Grey stays grey.
149
+ float ys = steps * 2.0;
150
+ float cs = steps * 2.0 + 2.0;
151
+ float tc = 0.5 + (t - 0.5) * 0.35;
152
+ y = snapStep(y * ys, t) / ys;
153
+ co = snapStep(co * cs * 2.0, tc) / (cs * 2.0);
154
+ cg = snapStep(cg * cs, tc) / cs;
155
+ return clamp(vec3(y + co - cg, y + cg, y - co - cg), 0.0, 1.0);
156
+ }
157
+ // OKLab, so the nearest palette entry is the one that looks nearest.
158
+ vec3 okLab(vec3 c) {
159
+ c = mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c));
160
+ vec3 lms = pow(max(mat3(0.4122, 0.2119, 0.0883, 0.5363, 0.6807, 0.2817, 0.0514, 0.1074, 0.63) * c, 0.0), vec3(1.0 / 3.0));
161
+ return mat3(0.2105, 1.978, 0.0259, 0.7936, -2.4286, 0.7828, -0.0041, 0.4506, -0.8087) * lms;
162
+ }
163
+ vec3 stepPalette(vec3 c, float t, bool spot, float hueWeight) {
164
+ vec3 best = c; vec3 next = c; vec3 bl = c; vec3 nl = c;
165
+ float bd = 1e9; float nd = 1e9;
166
+ vec3 lab = okLab(c);
167
+ // Spot inks: taken only by a pixel already clearly of the ink's hue, dithering between the inks alone.
168
+ if (spot && uAccentSize > 0 && length(lab.yz) > 0.028) {
169
+ float hue = atan(lab.z, lab.y);
170
+ for (int i = 0; i < 4; i++) {
171
+ if (i >= uAccentSize) break;
172
+ vec3 al = uAccentLab[i];
173
+ if (abs(mod(atan(al.z, al.y) - hue + 3.14159, 6.28318) - 3.14159) > 0.35) continue;
174
+ vec3 e = (al - lab) * vec3(1.0, 1.6, 1.6);
175
+ float d = dot(e, e);
176
+ if (d < bd) { nd = bd; next = best; bd = d; best = uAccent[i]; }
177
+ else if (d < nd) { nd = d; next = uAccent[i]; }
178
+ }
179
+ if (bd < 1e8) return t < sqrt(bd) / max(1e-5, sqrt(bd) + sqrt(nd)) && nd < 1e8 ? next : best;
180
+ }
181
+ for (int i = 0; i < 32; i++) {
182
+ if (i >= uPaletteSize) break;
183
+ // Hue outweighs lightness: a pale sky picks a pale blue, not a grey.
184
+ vec3 e = (uPaletteLab[i] - lab) * vec3(1.0, hueWeight, hueWeight);
185
+ float d = dot(e, e);
186
+ if (d < bd) { nd = bd; next = best; nl = bl; bd = d; best = uPalette[i]; bl = uPaletteLab[i]; }
187
+ else if (d < nd) { nd = d; next = uPalette[i]; nl = uPaletteLab[i]; }
188
+ }
189
+ // Only neighbours on a ramp dither; far-apart entries meet in a clean edge.
190
+ float m = sqrt(bd) / max(1e-5, sqrt(bd) + sqrt(nd)) * clamp(1.6 - 3.0 * length(bl - nl), 0.0, 1.0);
191
+ return t < m ? next : best;
192
+ }
193
+ float signalHash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
194
+ // The part a pixel belongs to, from the alpha its material wrote (see tagSignal):
195
+ // 0 untagged, else 1 to 3.
196
+ int partAt(vec2 cell) {
197
+ float a = colorAt(cell).a;
198
+ return a < 0.375 ? 1 : a < 0.625 ? 2 : a < 0.875 ? 3 : 0;
199
+ }
200
+ vec3 signalOf(int part) {
201
+ vec3 own = part == 1 ? uSignal[0] : part == 2 ? uSignal[1] : part == 3 ? uSignal[2] : vec3(0.0);
202
+ return max(own, vec3(uScanlines, uChroma, uGlitch));
203
+ }
204
+ // A burst lasts one eighth of a second; each part keeps its own timing, and how
205
+ // many of its slots burst grows with its glitch strength.
206
+ float burstOf(float strength, float part) {
207
+ if (strength <= 0.0) return 0.0;
208
+ return step(1.0 - strength * 0.16, signalHash(vec2(floor(uTime * 8.0), 1.7 + part * 13.1)));
209
+ }
210
+ // Where a bursting part reads from: bands of rows slide sideways (carrying the
211
+ // part's silhouette out over its neighbours), and one block of the part shows
212
+ // what sits above it, so sky tears into it.
213
+ vec2 tornCell(vec2 cell, float strength, float part) {
214
+ float slot = floor(uTime * 8.0) + part * 31.0;
215
+ float rows = floor(cell.y / (2.0 + floor(signalHash(vec2(slot, 3.1)) * 6.0)));
216
+ if (signalHash(vec2(rows, slot)) > 1.0 - 0.5 * strength) cell.x += floor((signalHash(vec2(rows, slot + 9.0)) - 0.5) * gGrid.x * 0.12 * strength);
217
+ return clamp(cell, vec2(0.0), gGrid - 1.0);
218
+ }
219
+ bool inTearBlock(vec2 cell, float part) {
220
+ float slot = floor(uTime * 8.0) + part * 31.0;
221
+ vec2 size = gGrid * vec2(0.12 + 0.2 * signalHash(vec2(slot, 5.0)), 0.02 + 0.035 * signalHash(vec2(slot, 6.0)));
222
+ vec2 origin = vec2(signalHash(vec2(slot, 7.0)), signalHash(vec2(slot, 8.0))) * gGrid;
223
+ return all(greaterThan(cell, origin)) && all(lessThan(cell, origin + size));
224
+ }
225
+ vec2 glitchCell(vec2 cell, int part) {
226
+ for (int k = 1; k <= 3; k++) {
227
+ float strength = signalOf(k).z;
228
+ if (burstOf(strength, float(k)) < 0.5) continue;
229
+ vec2 source = tornCell(cell, strength, float(k));
230
+ if (part == k && inTearBlock(cell, float(k))) return clamp(source + vec2(0.0, floor(gGrid.y * 0.06)), vec2(0.0), gGrid - 1.0);
231
+ if (part == k || partAt(source) == k) return source;
232
+ }
233
+ return cell;
234
+ }
235
+ vec2 filterOf(int part) { return part == 1 ? uFilter[0] : part == 2 ? uFilter[1] : part == 3 ? uFilter[2] : vec2(0.0); }
236
+ bool isFilter(vec2 f, float id) { return f.y > 0.0 && abs(f.x - id) < 0.5; }
237
+ vec3 rgbAt(vec2 cell) { return toSrgb(colorAt(cell).rgb); }
238
+ float lumaOf(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
239
+ vec3 hueOf(float h) { return clamp(abs(fract(h + vec3(0.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0) - 1.0, 0.0, 1.0); }
240
+ // Filters that move pixels: where a filtered part reads from. Every offset is a
241
+ // whole art pixel, so a filter never smears the grid.
242
+ vec2 filterCell(vec2 cell, vec2 f, int part) {
243
+ float a = f.y;
244
+ // mosaic: the part is drawn in blocks of 2 to 4 art pixels
245
+ if (isFilter(f, 3.0)) { float k = 2.0 + floor(a * 2.0); cell = floor(cell / k) * k + floor(k * 0.5); }
246
+ // vhs: rows wobble, and a band of tracking noise rolls up the frame
247
+ if (isFilter(f, 7.0)) {
248
+ float band = 1.0 - smoothstep(0.0, 5.0, abs(cell.y - fract(uTime * 0.06) * gGrid.y));
249
+ cell.x += floor(sin(cell.y * 0.37 + uTime * 2.7) * a * 1.4 + band * a * 7.0 * (signalHash(vec2(cell.y, floor(uTime * 12.0))) - 0.5));
250
+ }
251
+ // wave: heat haze, rows sway on a slow sine
252
+ if (isFilter(f, 9.0)) cell.x += floor(sin(cell.y * 0.22 + uTime * 2.1) * (1.0 + 2.5 * a) + 0.5);
253
+ // slitscan: each row shows the part at its own moment, so the part shears and unshears
254
+ if (isFilter(f, 15.0)) cell.x += floor(sin(cell.y * 0.045 - uTime * 0.9) * gGrid.x * 0.035 * a + 0.5);
255
+ // datamosh: blocks of the part jump and stick for half a second
256
+ if (isFilter(f, 17.0)) {
257
+ vec2 block = floor(cell / 6.0);
258
+ float slot = floor(uTime * 2.0);
259
+ if (signalHash(block + slot * 7.31) > 1.0 - 0.32 * a) cell += floor((vec2(signalHash(block + slot), signalHash(block - slot + 3.0)) - 0.5) * 14.0 * a);
260
+ }
261
+ // pixel sort: bright runs of the part drip down over darker pixels below them
262
+ if (isFilter(f, 16.0)) {
263
+ vec2 pick = cell;
264
+ float best = 0.42;
265
+ for (int k = 1; k <= 14; k++) {
266
+ if (float(k) > 14.0 * a) break;
267
+ vec2 p = clamp(cell + vec2(0.0, float(k)), vec2(0.0), gGrid - 1.0);
268
+ if (partAt(p) != part) break;
269
+ float l = lumaOf(rgbAt(p));
270
+ if (l > best + 0.03) { best = l; pick = p; }
271
+ }
272
+ cell = pick;
273
+ }
274
+ return clamp(cell, vec2(0.0), gGrid - 1.0);
275
+ }
276
+ // Filters that change colour, applied before the tones are stepped, so a
277
+ // filtered part is still dithered pixel art.
278
+ vec3 filterColor(vec3 c, vec2 cell, vec2 f, float edge) {
279
+ if (f.y <= 0.0) return c;
280
+ float a = clamp(f.y, 0.0, 1.0);
281
+ float l = lumaOf(c);
282
+ float frame = floor(uTime * 12.0);
283
+ vec3 o = c;
284
+ // snow: static speckles
285
+ if (isFilter(f, 1.0)) o = mix(c, vec3(signalHash(cell + frame * 1.37)), step(1.0 - 0.22 * a, signalHash(cell * 1.31 + frame)));
286
+ // film: sepia, a little grain, and the gate's flicker
287
+ if (isFilter(f, 2.0)) o = vec3(l * 1.07 + 0.05, l * 0.9 + 0.03, l * 0.68) * (0.93 + 0.07 * signalHash(vec2(frame, 2.0))) + (signalHash(cell + frame) - 0.5) * 0.08;
288
+ // cga: the four-colour 1981 palette
289
+ if (isFilter(f, 4.0)) o = l < 0.2 ? vec3(0.0) : l < 0.5 ? vec3(0.33, 1.0, 1.0) * (0.55 + l) : l < 0.78 ? vec3(1.0, 0.33, 1.0) : vec3(1.0);
290
+ // negative
291
+ if (isFilter(f, 5.0)) o = 1.0 - c;
292
+ // glow: bright pixels bloom into their neighbours
293
+ if (isFilter(f, 6.0) || isFilter(f, 13.0)) {
294
+ vec3 sum = vec3(0.0);
295
+ for (int k = 0; k < 8; k++) {
296
+ float t = float(k) * 0.785398;
297
+ vec3 s = rgbAt(cell + floor(vec2(cos(t), sin(t)) * 2.5 + 0.5));
298
+ sum += s * smoothstep(0.45, 0.9, lumaOf(s));
299
+ }
300
+ o = c + sum * 0.22;
301
+ // neon: dark bodies, glowing rims in a cycling hue
302
+ if (isFilter(f, 13.0)) o = edge > 0.5 ? hueOf(fract(cell.y * 0.01 + uTime * 0.12)) * 1.2 : c * 0.22 + sum * 0.12;
303
+ }
304
+ // bleed: colour smears to the right of where it belongs, as on a worn tape
305
+ if (isFilter(f, 8.0)) {
306
+ vec3 smear = (rgbAt(cell - vec2(1.0, 0.0)) + rgbAt(cell - vec2(2.0, 0.0)) + rgbAt(cell - vec2(3.0, 0.0))) / 3.0;
307
+ o = vec3(l) + (smear - vec3(lumaOf(smear))) * 1.3;
308
+ }
309
+ // night vision: green phosphor and noise
310
+ if (isFilter(f, 10.0)) o = vec3(0.12, 1.0, 0.28) * (l * 1.35 + 0.06) + (signalHash(cell + frame) - 0.5) * 0.12;
311
+ // sparkle: bright pixels twinkle white
312
+ if (isFilter(f, 11.0)) o = c + step(0.5, l) * step(1.0 - 0.07 * a, signalHash(cell + floor(uTime * 6.0) * 2.17)) * vec3(0.9);
313
+ // thermal: black, blue, magenta, red, yellow, white by brightness
314
+ if (isFilter(f, 12.0)) {
315
+ float h = clamp(l * 1.15, 0.0, 1.0);
316
+ o = h < 0.25 ? mix(vec3(0.02, 0.0, 0.1), vec3(0.15, 0.1, 0.9), h * 4.0) : h < 0.5 ? mix(vec3(0.15, 0.1, 0.9), vec3(0.9, 0.1, 0.7), h * 4.0 - 1.0) : h < 0.75 ? mix(vec3(0.9, 0.1, 0.7), vec3(1.0, 0.55, 0.0), h * 4.0 - 2.0) : mix(vec3(1.0, 0.55, 0.0), vec3(1.0, 1.0, 0.85), h * 4.0 - 3.0);
317
+ }
318
+ // rainbow: colours cycle through the hues
319
+ if (isFilter(f, 14.0)) o = hueOf(fract(l * 1.4 + cell.y * 0.008 + uTime * 0.18)) * (0.35 + 0.85 * l);
320
+ // holo: iridescent foil that shifts across the part, with a sweeping sheen
321
+ if (isFilter(f, 18.0)) {
322
+ float sheen = smoothstep(0.92, 1.0, fract((cell.x + cell.y) * 0.02 - uTime * 0.35));
323
+ o = mix(c, hueOf(fract(cell.x * 0.018 + cell.y * 0.012 + uTime * 0.2 + l * 0.6)) * (0.55 + 0.6 * l), 0.65) + sheen * 0.5;
324
+ }
325
+ return mix(c, clamp(o, 0.0, 1.0), isFilter(f, 1.0) || isFilter(f, 11.0) ? 1.0 : a);
326
+ }
327
+ // Clump: a smooth Kuwahara filter gathers speckle into masses; what lies behind never bleeds in.
328
+ vec3 clumpAt(vec2 cell, vec3 c, float d0, float gap) {
329
+ vec3 s[9];
330
+ for (int j = 0; j < 3; j++) for (int i = 0; i < 3; i++) {
331
+ vec2 at = cell + vec2(float(i) - 1.0, float(j) - 1.0);
332
+ s[j * 3 + i] = (i == 1 && j == 1) || distanceAt(at) - d0 > gap ? c : rgbAt(at);
333
+ }
334
+ vec3 sum = vec3(0.0);
335
+ float total = 0.0;
336
+ for (int q = 0; q < 4; q++) {
337
+ int ox = q - (q / 2) * 2;
338
+ int oy = q / 2;
339
+ vec3 a = s[oy * 3 + ox]; vec3 b = s[oy * 3 + ox + 1]; vec3 d = s[oy * 3 + ox + 3]; vec3 e = s[oy * 3 + ox + 4];
340
+ vec3 mean = (a + b + d + e) * 0.25;
341
+ vec3 va = a - mean; vec3 vb = b - mean; vec3 vd = d - mean; vec3 ve = e - mean;
342
+ float w = 1.0 / (0.004 + dot(va, va) + dot(vb, vb) + dot(vd, vd) + dot(ve, ve));
343
+ sum += mean * w * w;
344
+ total += w * w;
345
+ }
346
+ return sum / total;
347
+ }
348
+ void main() {
349
+ gF = 1.0;
350
+ gGrid = uGrid;
351
+ vec2 at = floor(gl_FragCoord.xy);
352
+ // The detail pass redraws only the detail parts' own pixels; the rest is the world's look.
353
+ if (uPass > 0.5) {
354
+ gF = uFine;
355
+ gGrid = uGrid * uFine;
356
+ if (!onDetail(at)) {
357
+ gl_FragColor = texture2D(tCoarse, (floor(at / uFine) + 0.5) / uGrid);
358
+ return;
359
+ }
360
+ }
361
+ // Clump would gather a small animal's eye and muzzle into its coat.
362
+ float clump = gF > 1.5 ? 0.0 : uClump;
363
+ vec2 home = clamp(at, vec2(0.0), gGrid - 1.0);
364
+ int part = partAt(home);
365
+ vec3 signal = signalOf(part);
366
+ vec2 partFilter = filterOf(part);
367
+ vec2 cell = filterCell(glitchCell(home, part), partFilter, part);
368
+ vec3 c = toSrgb(colorAt(cell).rgb);
369
+ // Red and blue drift apart by whole art pixels around a fringed part, and
370
+ // further while it bursts.
371
+ float fringe = max(signal.y, max(signalOf(partAt(home + vec2(2.0, 0.0))).y, signalOf(partAt(home - vec2(2.0, 0.0))).y));
372
+ float split = floor(fringe * 1.6) + burstOf(signal.z, float(part));
373
+ if (split >= 1.0) {
374
+ c.r = toSrgb(colorAt(cell + vec2(split, 0.0)).rgb).r;
375
+ c.b = toSrgb(colorAt(cell - vec2(split, 0.0)).rgb).b;
376
+ }
377
+ float d0 = distanceAt(cell);
378
+ bool sky = d0 >= uSkyFrom;
379
+ float dl = distanceAt(cell - vec2(1.0, 0.0));
380
+ float dr = distanceAt(cell + vec2(1.0, 0.0));
381
+ float dd = distanceAt(cell - vec2(0.0, 1.0));
382
+ float du = distanceAt(cell + vec2(0.0, 1.0));
383
+ float gap = 0.06 * d0 + 0.08;
384
+ float edge = (!sky && max(max(dl, dr), max(du, dd)) - d0 > gap) ? 1.0 : 0.0;
385
+ // Clumped, a leaf among leaves is not a silhouette.
386
+ if (clump > 0.0 && d0 - min(min(dl, dr), min(du, dd)) > gap) edge = 0.0;
387
+ float lap = abs(dl + dr - 2.0 * d0) + abs(du + dd - 2.0 * d0);
388
+ float crease = (!sky && edge < 0.5 && lap > 0.012 * d0 + 0.02) ? 1.0 : 0.0;
389
+ if (clump > 0.0 && !sky && split < 1.0) c = mix(c, clumpAt(cell, c, d0, gap), clump);
390
+ c = filterColor(c, cell, partFilter, edge);
391
+
392
+ float jitter = (bayer8(cell + 3.0) - 0.5) * 0.18;
393
+ float far = d0 * (1.0 + jitter);
394
+ int band = sky || far > uBands.y ? 2 : far > uBands.x ? 1 : 0;
395
+ float screen = band == 0 ? uScreen.x : band == 1 ? uScreen.y : uScreen.z;
396
+ float scale = band == 0 ? uScale.x : band == 1 ? uScale.y : uScale.z;
397
+ float amount = band == 0 ? uAmount.x : band == 1 ? uAmount.y : uAmount.z;
398
+
399
+ c += godRays(cell) * (sky ? 0.6 : 1.0);
400
+ // Soft knee into black; lift the darkest toward cool blue; ramps lean lights warm, shadows cool.
401
+ c = (c - 0.5) * uContrast + 0.5;
402
+ c = mix(0.1 * exp(c * 10.0 - 1.0), c, step(0.1, c));
403
+ float lo = 1.0 - clamp(lumaOf(c), 0.0, 1.0);
404
+ c += uLift * lo * lo * lo * vec3(0.8, 0.9, 1.3) + (sky ? 0.0 : uRamp) * 0.09 * (0.55 - lo) * vec3(1.0, 0.3, -0.9);
405
+ // Only a light far band is pushed: a night or blue-hour sky keeps its depth.
406
+ float farPush = band == 2 ? mix(1.0, uSkySaturation, smoothstep(0.3, 0.6, lumaOf(c))) : 1.0;
407
+ c = mix(vec3(lumaOf(c)), c, uSaturation * farPush);
408
+ // Outlines thin out with distance, so a far skyline is a soft edge, not a wire.
409
+ float outline = uOutline * (band == 0 ? 1.0 : band == 1 ? 0.7 : 0.3);
410
+ vec3 ink = uOutlineColor.a > 0.5 ? uOutlineColor.rgb : c * vec3(0.36, 0.33, 0.46);
411
+ c = mix(c, ink, edge * outline);
412
+ c = mix(c, c * vec3(0.74, 0.72, 0.8), crease * uCrease);
413
+ c = clamp(c, 0.0, 1.0);
414
+
415
+ // A silhouette is a solid run of tone, never broken speckle.
416
+ // A dark sky bands, never a grid of dots.
417
+ if (sky) amount *= smoothstep(0.03, 0.2, lumaOf(c));
418
+ // On a fixed palette the sky keeps its hue and settles into bands rather than a checker of far-apart inks.
419
+ if (sky && uPaletteSize > 0) amount *= 0.35;
420
+ float t = 0.5 + (screenAt(screen, floor(cell / scale)) - 0.5) * amount * (1.0 - edge * outline);
421
+ // Alpha carries this pixel's scanline strength to the blit.
422
+ gl_FragColor = vec4(uPaletteSize > 0 ? stepPalette(c, t, !sky, 1.6 * farPush) : stepTones(c, t), signal.x);
423
+ }
424
+ `,H=`
425
+ precision highp float;
426
+ uniform sampler2D tLook;
427
+ uniform vec2 uGrid;
428
+ uniform float uPixel;
429
+ uniform vec2 uOrigin;
430
+ uniform float uScanlines;
431
+ uniform float uTime;
432
+ uniform float uFine;
433
+ void main() {
434
+ vec2 frame = (gl_FragCoord.xy - uOrigin) / uPixel;
435
+ // The look target holds uFine detail pixels to an art pixel's side.
436
+ vec2 grid = uGrid * uFine;
437
+ vec2 cell = clamp(floor(frame * uFine), vec2(0.0), grid - 1.0);
438
+ vec4 look = texture2D(tLook, (cell + 0.5) / grid);
439
+ vec3 c = look.rgb;
440
+ // Each pixel's scanline strength came from the look pass (whole frame or its part);
441
+ // none show when an art pixel is too few device pixels tall.
442
+ float scan = uPixel >= 2.0 ? look.a : 0.0;
443
+ // Scanlines: the lower part of every art-pixel row is dimmed, and a faint
444
+ // brighter band rolls slowly down the frame, as on a tube screen.
445
+ // Dark gaps between lines, with the lit rows lifted to keep the frame's brightness.
446
+ float line = (1.0 + scan * 0.22) * (1.0 - scan * 0.5 * step(fract(frame.y), 0.4));
447
+ float roll = 1.0 + scan * 0.07 * sin((frame.y / uGrid.y + uTime * 0.12) * 6.2832);
448
+ gl_FragColor = vec4(c * line * roll, 1.0);
449
+ }
450
+ `,Re={vertex:U,fragment:N,blit:H};function j(e,t,a){let r=(p,P)=>p[P]??0,[o,n,l]=a,i=r(e,0)*o+r(e,4)*n+r(e,8)*l,s=r(e,1)*o+r(e,5)*n+r(e,9)*l,m=r(e,2)*o+r(e,6)*n+r(e,10)*l,h=r(t,0)*i+r(t,4)*s+r(t,8)*m,y=r(t,1)*i+r(t,5)*s+r(t,9)*m,u=r(t,3)*i+r(t,7)*s+r(t,11)*m,f=Math.hypot(i,s,m)||1,d=Math.max(0,-m/f);return u<=1e-4?{x:.5,y:.5,facing:0}:{x:Math.max(-2,Math.min(3,h/u*.5+.5)),y:Math.max(-2,Math.min(3,y/u*.5+.5)),facing:d}}function J(e,t){e.color!==void 0&&t.color!==void 0&&t.color.copy(e.color),t.opacity=e.opacity,t.transparent=e.transparent,t.visible=e.visible}var Ae=["map","emissive","emissiveIntensity","transparent","opacity","depthWrite","depthTest","side","alphaTest","vertexColors","flatShading","name"];function Me(e,t){let a=e,r={gradientMap:t};e.color!==void 0&&(r.color=e.color);for(let o of Ae)a[o]!==void 0&&a[o]!==null&&(r[o]=a[o]);return r}function Q(e,t){let a=new Map,r=n=>{let l=_(n),i=new e.DataTexture(l,l.length,1,"red");return i.minFilter="nearest",i.magFilter="nearest",i.generateMipmaps=!1,i.needsUpdate=!0,i},o=r(t);return{setBands(n){o.dispose(),o=r(n);for(let l of a.values())l.gradientMap=o,l.needsUpdate=!0},swap(n,l){let i=n.userData.voxelDitherSource;if(l==="smooth")return i===void 0?n:(J(n,i),i);if(i!==void 0||n.isLitMaterial!==!0||n.userData.voxelDitherKeep===!0)return n;let s=a.get(n);return s===void 0&&(s=new e.ToonMaterial(Me(n,o)),s.userData.voxelDitherSource=n,a.set(n,s)),J(n,s),s},dispose(){o.dispose();for(let n of a.values())n.dispose();a.clear()}}}var Z=["none","snow","film","mosaic","cga","negative","glow","vhs","bleed","wave","nightvision","sparkle","thermal","neon","rainbow","slitscan","pixelsort","datamosh","holo"],ee={1:.25,2:.5,3:.75};function q(e){let t=new Float32Array(9);for(let a=0;a<3;a+=1){let r=e[a];r!=null&&(t[a*3]=c(r.scanlines,0,1,0),t[a*3+1]=c(r.chroma,0,1,0),t[a*3+2]=c(r.glitch,0,1,0))}return t}function Y(e){let t=new Float32Array(6);for(let a=0;a<3;a+=1){let r=e[a],o=r?.filter===void 0?-1:Z.indexOf(r.filter);r==null||o<=0||(t[a*2]=o,t[a*2+1]=c(r.amount,0,1,1))}return t}function Fe(e,t){if(e.transparent||e.userData.voxelDitherSignal===t)return;let a=e.userData.voxelDitherSignalBase??{compile:e.onCompile,key:e.customProgramCacheKey};e.userData.voxelDitherSignalBase=a,e.userData.voxelDitherSignal=t;let r=ee[t].toFixed(2);e.onCompile=(o,n)=>{a.compile?.call(e,o,n);let l=o.fragmentShader.lastIndexOf("}");o.fragmentShader=`${o.fragmentShader.slice(0,l)} gl_FragColor.a = ${r};
451
+ }
452
+ `},e.customProgramCacheKey=()=>`${a.key?.call(e)??""}|voxel-dither-signal-${String(t)}`,e.needsUpdate=!0}function te(e,t){e.traverse(a=>{if(!(a.isMesh!==!0||a.material===void 0))for(let r of Array.isArray(a.material)?a.material:[a.material])Fe(r,t)})}var ae=30,C=1<<ae>>>0;function Ce(e){return e.material===void 0?[]:Array.isArray(e.material)?e.material:[e.material]}function re(e,t){for(let a of e)a.traverse(r=>{r.isMesh!==!0||r.layers===void 0||Ce(r).every(o=>o.colorWrite===!1)||(r.layers.mask=t?C:1)})}function Oe(){return{tColor:{value:null},tDepth:{value:null},uGrid:{value:[1,1]},uPixel:{value:1},uOrigin:{value:[0,0]},uScreen:{value:[2,3,8]},uScale:{value:[1,1,1]},uAmount:{value:[1,1,1]},uBands:{value:[18,30]},uLevels:{value:6},uSnap:{value:0},uLift:{value:0},uClump:{value:0},uRamp:{value:0},uLuma:{value:1},uPaletteSize:{value:0},uAccentSize:{value:0},uAccent:{value:new Float32Array(12)},uAccentLab:{value:new Float32Array(12)},uSkySaturation:{value:1},uPalette:{value:new Float32Array(96)},uPaletteLab:{value:new Float32Array(96)},uOutline:{value:.9},uOutlineColor:{value:[0,0,0,0]},uCrease:{value:.35},uContrast:{value:1},uSaturation:{value:1},uSkyFrom:{value:100},uRaySource:{value:[.5,.5]},uRayColor:{value:[1,1,1]},uRayStrength:{value:0},uRayDecay:{value:.95},uRayDensity:{value:.8},tLook:{value:null},uScanlines:{value:0},uChroma:{value:0},uGlitch:{value:0},uTime:{value:0},uSignal:{value:new Float32Array(9)},uFilter:{value:new Float32Array(6)},tDetail:{value:null},tDetailDepth:{value:null},tCoarse:{value:null},uFine:{value:1},uPass:{value:0}}}function Pe(e,t,a){let r=z(t,Math.min(a.width,a.height)),o=[r.near,r.mid,r.far],n=(l,i)=>{g(e,l,i)};n("uScreen",o.map(l=>w.indexOf(l.screen))),n("uScale",o.map(l=>l.scale)),n("uAmount",o.map(l=>l.amount)),n("uBands",[...t.depthBands]),n("uLevels",t.levels),n("uSnap",t.snap),n("uLift",t.lift),n("uClump",t.clump),n("uRamp",t.ramp),n("uLuma",t.color==="luma"?1:0)}function Ge(e,t){let a=F(t.palette),r=(n,l)=>{g(e,n,l)};r("uPalette",a.data),r("uPaletteLab",a.lab),r("uPaletteSize",a.size);let o=F(t.accent);r("uAccent",o.data.subarray(0,12)),r("uAccentLab",o.lab.subarray(0,12)),r("uAccentSize",o.size)}function Be(e,t,a){let r=(o,n)=>{g(e,o,n)};r("uSkySaturation",t.skySaturation),r("uOutline",t.outline),r("uOutlineColor",t.outlineColor===null?[0,0,0,0]:[...M(t.outlineColor),1]),r("uCrease",t.crease),r("uContrast",t.contrast),r("uSaturation",t.saturation),r("uScanlines",t.scanlines),r("uChroma",t.chroma),r("uGlitch",t.glitch),r("uGrid",[a.width,a.height]),r("uPixel",a.pixel),r("uOrigin",[a.originX,a.originY])}function ne(e,t,a){Pe(e,t,a),Ge(e,t),Be(e,t,a)}function O(e,t){let a={minFilter:"nearest",magFilter:"nearest",generateMipmaps:!1};return t?new e.RenderTarget(1,1,{...a,type:"half",depthBuffer:!0,depthTexture:new e.DepthTexture(1,1)}):new e.RenderTarget(1,1,{...a,depthBuffer:!1})}function oe(e,t,a,r){let o=new e.CustomMaterial({uniforms:a,vertexShader:U,fragmentShader:r,depthTest:!1,depthWrite:!1}),n=new e.Mesh(t,o);n.frustumCulled=!1;let l=new e.Stage;return l.add(n),{scene:l,material:o}}function Ee(e,t,a,r){let o=e.uRayStrength;if(o===void 0)return;if(t===null||a.matrixWorldInverse===void 0||a.projectionMatrix===void 0){o.value=0;return}let n=j(a.matrixWorldInverse.elements,a.projectionMatrix.elements,t.direction);o.value=Math.max(0,t.strength)*r*Math.min(1,n.facing*2.5),Object.assign(e.uRaySource??{},{value:[n.x,n.y]}),Object.assign(e.uRayColor??{},{value:[...M(D.test(t.color)?t.color:"#ffffff")]}),Object.assign(e.uRayDecay??{},{value:c(t.decay,.85,.995,.95)}),Object.assign(e.uRayDensity??{},{value:c(t.density,.2,1,.8)})}function g(e,t,a){let r=e[t];r!==void 0&&(r.value=a)}function le(e,t,a,r){let o=a.layers,n=o?.mask??1;o&&(o.mask=r),e.render(t,a),o&&(o.mask=n)}function Ie(e,t,a){let{renderer:r,scene:o,view:n}=e,l=n.layers?.mask??1;r.setRenderTarget(t.world),le(r,o,n,a?l&~C:l),a&&(r.setRenderTarget(t.detail),le(r,o,n,C))}function ze(e,t,a){let{post:r,quad:o,uniforms:n,targets:l}=t;return g(n,"uFine",a),g(n,"uPass",0),g(n,"tCoarse",l.detailLook.texture),e.setRenderTarget(l.look),e.render(r.scene,o),a<=1?l.look:(g(n,"uPass",1),g(n,"tCoarse",l.look.texture),e.setRenderTarget(l.detailLook),e.render(r.scene,o),l.detailLook)}function _e(e,t){let a={world:O(e,!0),look:O(e,!1),detail:O(e,!0),detailLook:O(e,!1)},{world:r,look:o,detail:n,detailLook:l}=a,i=1,s={near:{value:.1},far:{value:100},ortho:{value:0},sky:{value:100}};Object.assign(t,{tColor:{value:r.texture},tDepth:{value:r.depthTexture},tLook:{value:o.texture},tDetail:{value:n.texture},tDetailDepth:{value:n.depthTexture},tCoarse:{value:l.texture},uNear:s.near,uFar:s.far,uOrtho:s.ortho,uSkyFrom:s.sky});let m=e.plane(2,2),h=oe(e,m,t,N),y=oe(e,m,t,H),u=new e.OrthoCamera(-1,1,1,-1,0,1),f={post:h,quad:u,uniforms:t,targets:a};return{resize(d){i=d.detail,r.setSize(d.width,d.height),o.setSize(d.width,d.height);let p=i>1?i:1;n.setSize(d.width*p,d.height*p),l.setSize(d.width*p,d.height*p)},draw(d,p,P,V){let{renderer:S,view:b}=d,ie=S.getRenderTarget(),G=i>1&&V.size>0;re(V,G),Ie(d,a,G),s.near.value=b.near,s.far.value=b.far,s.ortho.value=b.isOrthographicCamera===!0?1:0,s.sky.value=p.skyDistance>0?Math.min(p.skyDistance,b.far*.999):b.far*.999,Ee(t,P,b,p.rays),g(t,"tLook",ze(S,f,G?i:1).texture),S.setRenderTarget(ie),S.render(y.scene,u)},dispose(){r.depthTexture?.dispose(),r.dispose(),o.dispose(),n.depthTexture?.dispose(),n.dispose(),l.dispose(),h.material.dispose(),y.material.dispose(),m.dispose()}}}function Ue(e,t,a){let r=T(a),o={width:1,height:1,pixel:1,originX:0,originY:0,detail:1},n={width:1,height:1,ratio:1},l=null,i=new Set,s=Oe(),m=_e(e,s),h=Q(e,r.bands);ne(s,r,o);let y={get settings(){return r},get grid(){return o},setSettings(u){let f=r;return r=T(u),r.bands!==f.bands&&h.setBands(r.bands),y.setSize(n.width,n.height,n.ratio),r},setDepthBands(u,f){let[d,p]=E([u,f],r.depthBands);(d!==r.depthBands[0]||p!==r.depthBands[1])&&(r={...r,depthBands:[d,p]}),Object.assign(s.uBands?.value??[],[d,p])},setSize(u,f,d){return n={width:u,height:f,ratio:d},o=I(u,f,d,r),m.resize(o),ne(s,r,o),o},shade(u){u.traverse(f=>{f.isMesh!==!0||f.material===void 0||(f.material=Array.isArray(f.material)?f.material.map(d=>h.swap(d,r.shading)):h.swap(f.material,r.shading))})},setRays(u){l=u},setTime(u){g(s,"uTime",Number.isFinite(u)?u%3600:0)},tagSignal(u,f){te(u,f)},setSignals(u){Object.assign(s.uSignal??{},{value:q(u)}),Object.assign(s.uFilter??{},{value:Y(u)})},tagDetail(u){i.add(u)},render(u,f){m.draw({renderer:t,scene:u,view:f},r,l,i)},dispose(){m.dispose(),h.dispose()}};return y}export{k as DEFAULT_DITHER_SETTINGS,ae as DETAIL_LAYER,B as DITHER_STYLES,w as SCREENS,Z as SIGNAL_FILTERS,ee as SIGNAL_TAG_ALPHA,K as STYLE_IDS,Re as VOXEL_DITHER_GLSL,W as autoPixel,z as bandScreens,_ as celRamp,Ue as createVoxelDither,T as ditherSettings,Y as filterUniform,$ as okLab,F as paletteUniform,De as quantizeTone,I as resolveGrid,j as screenLight,q as signalUniform,we as thresholdAt};
@@ -0,0 +1,133 @@
1
+ /**
2
+ * A small world model for light: where the sun and moon really are for a
3
+ * place and an instant, and what the sky, the key light, the ambient fill,
4
+ * the fog and the god rays look like there, given the season, the climate
5
+ * and the weather. MIT.
6
+ *
7
+ * const place = locateTimeZone(Intl.DateTimeFormat().resolvedOptions().timeZone);
8
+ * const light = worldLight({ timestamp: Date.now(), lat: place.lat, lon: place.lon, season: "autumn", climate:
9
+ * "maritime", weather: "clear" });
10
+ * light.sun.direction -> [x, y, z], +y up, -z north
11
+ * light.sky.horizon -> "#f4a259"
12
+ * light.rays -> { source: "sun", strength, color, decay, density }
13
+ *
14
+ * Pure and deterministic: everything is a function of its input. Colours are
15
+ * sRGB hex, directions unit vectors, so any renderer can use it; nothing here
16
+ * touches a clock, a global or a GPU.
17
+ */
18
+ /** Where a body sits in the sky, in degrees: elevation above the horizon and azimuth clockwise from north. */
19
+ export interface SkyPosition {
20
+ readonly elevation: number;
21
+ readonly azimuth: number;
22
+ }
23
+ export interface SolarPosition extends SkyPosition {
24
+ readonly declination: number;
25
+ /** Local solar hour angle, degrees (0 at solar noon, negative in the morning). */
26
+ readonly hourAngle: number;
27
+ }
28
+ /**
29
+ * The sun's position for a place and instant (the low-precision almanac
30
+ * formulae, good to about a degree, plenty for light).
31
+ *
32
+ * @param timestamp Milliseconds since the Unix epoch.
33
+ * @param lat Latitude, degrees north.
34
+ * @param lon Longitude, degrees east.
35
+ */
36
+ export declare function solarPosition(timestamp: number, lat: number, lon: number): SolarPosition;
37
+ export interface MoonState extends SkyPosition {
38
+ /** 0 new, 0.25 first quarter, 0.5 full, 0.75 last quarter. */
39
+ readonly phase: number;
40
+ /** Lit fraction of the disc, 0 to 1. */
41
+ readonly illumination: number;
42
+ }
43
+ /**
44
+ * The moon's phase and an approximate position: it trails the sun by its
45
+ * phase of a day (full moon opposite the sun), on the sun's declination.
46
+ * Accurate enough to light a scene; not an ephemeris.
47
+ */
48
+ export declare function moonState(timestamp: number, lat: number, lon: number): MoonState;
49
+ /** A unit vector toward a sky position: +y up, -z north, +x east. */
50
+ export declare function skyDirection(position: SkyPosition): readonly [number, number, number];
51
+ /** A place for the sky: coordinates and a name. `exact` is false when only the UTC offset placed it. */
52
+ export interface Place {
53
+ readonly lat: number;
54
+ readonly lon: number;
55
+ readonly place: string;
56
+ readonly exact: boolean;
57
+ }
58
+ /**
59
+ * A place for a time zone: its own city when the zone is known, otherwise a
60
+ * longitude from the UTC offset (15° an hour) at a temperate northern latitude.
61
+ *
62
+ * @param timeZone IANA zone, e.g. from Intl.DateTimeFormat().resolvedOptions().timeZone.
63
+ * @param utcOffsetMinutes The zone's offset from UTC now, used only when the zone is unknown.
64
+ */
65
+ export declare function locateTimeZone(timeZone: string, utcOffsetMinutes?: number): Place;
66
+ /** Every zone the table places exactly. */
67
+ export declare const KNOWN_ZONES: readonly string[];
68
+ /** Mixes two #rrggbb colours in sRGB. */
69
+ export declare function mixHex(from: string, to: string, amount: number): string;
70
+ export type Weather = "clear" | "wind" | "leaves" | "rain" | "snow";
71
+ export type Climate = "temperate" | "maritime" | "alpine" | "monsoon" | "highland" | "desert";
72
+ export type LightPhase = "night" | "twilight" | "blue hour" | "golden hour" | "day" | "high sun";
73
+ export interface WorldLightInput {
74
+ readonly timestamp: number;
75
+ readonly lat: number;
76
+ readonly lon: number;
77
+ readonly season?: string | undefined;
78
+ readonly climate?: Climate | undefined;
79
+ readonly weather?: Weather | undefined;
80
+ }
81
+ export interface LightSource {
82
+ readonly direction: readonly [number, number, number];
83
+ readonly elevation: number;
84
+ readonly azimuth: number;
85
+ readonly color: string;
86
+ readonly intensity: number;
87
+ }
88
+ /** God rays: which body casts them, how strong, their colour, and how they fall off along the ray. */
89
+ export interface Rays {
90
+ readonly source: "sun" | "moon" | "none";
91
+ readonly direction: readonly [number, number, number];
92
+ readonly strength: number;
93
+ readonly color: string;
94
+ /** Per-sample falloff along a ray (0.9 short shafts, 0.98 long ones). */
95
+ readonly decay: number;
96
+ /** How far toward the source a ray reaches, as a fraction of the way (0..1). */
97
+ readonly density: number;
98
+ }
99
+ export interface WorldLight {
100
+ readonly phase: LightPhase;
101
+ readonly sun: LightSource;
102
+ readonly moon: LightSource & {
103
+ readonly phase: number;
104
+ readonly illumination: number;
105
+ };
106
+ readonly sky: {
107
+ readonly top: string;
108
+ readonly horizon: string;
109
+ readonly ground: string;
110
+ };
111
+ readonly fill: {
112
+ readonly sky: string;
113
+ readonly ground: string;
114
+ readonly intensity: number;
115
+ };
116
+ readonly fog: {
117
+ readonly color: string;
118
+ readonly near: number;
119
+ readonly far: number;
120
+ };
121
+ /** 0 clear air to 1 thick haze; morning mist and wet seasons raise it. */
122
+ readonly haze: number;
123
+ /** 0 day to 1 full night (stars). */
124
+ readonly night: number;
125
+ readonly rays: Rays;
126
+ }
127
+ export declare function lightPhase(elevation: number): LightPhase;
128
+ /**
129
+ * The light of a place at an instant: the real sun and moon for its
130
+ * latitude, longitude and date (so season and place change the sun's path),
131
+ * bent by the season's, climate's and weather's mood.
132
+ */
133
+ export declare function worldLight(input: WorldLightInput): WorldLight;
@@ -0,0 +1 @@
1
+ export * from './world-light/index.js'