@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,2 @@
1
+ // tree-render@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var e=["roots","leaves","flowers","fruit","deadwood","litter","snow","fallers","sway","shadows","crownShade","bark","sprays","clumps","rootSink","rootBreak"],t=t=>e.includes(t);function a(a={}){let r=Object.fromEntries(e.map(e=>[e,!0]));if("string"!=typeof a){for(let t of e)r[t]=a[t]??!0;return r}for(let e of a.split(/[,\s]+/)){let[a="",n]=e.trim().split("="),o=a.startsWith("-")||"off"===n||"0"===n||"false"===n,l=a.replace(/^[-+]/,"");t(l)&&(r[l]=!o)}return r}var r=2*Math.PI,n=(e,t,a)=>Math.min(a,Math.max(t,e)),o=(e,t)=>e[t]??0;function l(e,t,a){let r=n((a-e)/(t-e),0,1);return r*r*(3-2*r)}function s(e){let t=e>>>0;return t=Math.imul(t^t>>>16,569420461),t=Math.imul(t^t>>>15,1935289751),(t^t>>>15)>>>0}function i(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}function f(e,t,a=0){let n=a%9973*.731,o=e,s=.5+.5*(.6*Math.sin(.047*o+n)+.4*Math.sin(.113*o+1.7*n)),i=1-l(.72,.86,Math.sin(.0093*o+2.3*n)*Math.sin(.0151*o+3.1*n));return{wind:Math.max(0,t*(.35+.75*s)*i),dir:n%r+.45*Math.sin(.013*o+n)+.2*Math.sin(.041*o+.6*n)}}var u=(e,t)=>{let a=.5*e-.22*t;return Math.max(0,Math.sin(a)*Math.sin(.43*a+1.7))**2};function d(e,t,a){let[r,o,l]=t,{elapsed:s,wind:i,height:f}=a,d=a.dir??0,c=n(o/Math.max(f,1),0,1.4),h=Math.min(Math.hypot(r,l)/Math.max(.5*f,.5),1.5),m=Math.cos(d),p=Math.sin(d),g=r*m+l*p,v=u(s,g),y=i*(.5+1*v)*c*c*.3*(1+.15*Math.sin(.9*s+.4*g)),w=(.022*i+.003)*c*(.3+h)*(Math.sin(2.2*s+2.1*r+1.3*o)*(.4+v)+.5*v),b=.35*w*Math.cos(1.7*s+1.9*l+o),x=.014*c*(Math.sin(.6*s+.3*o)+.6*Math.sin(.97*s+2.1))*(1-.5*Math.min(1,3*i)),M=y+w;return e.x=m*M-p*b+x,e.z=p*M+m*b+.7*x*Math.cos(.83*s+.4*r),e}function c(e,t,a,n=2.1*a){let{elapsed:o,wind:l}=e,s=.035*Math.sin(.8*o+31*t)+.02*Math.sin(1.9*o+57*t),i=u(o,n),f=l*(.12+.45*i)*Math.sin(o*(6+4*t)+40*t),d=l*i*1.6*(.6+.4*Math.sin(1.6*o+19*t));return{droop:.35+.25*t+s-.3*d,twist:t*r*.25+.8*f+d,nod:1.5*s+.35*f}}function h(e,t,a){let r=16*t;for(let t=0;t<12;t+=1)e[r+t]=a[t]??0;e[r+15]=1}function m(e,t,a){let r=16*t;e[r+12]=a[0],e[r+13]=a[1],e[r+14]=a[2],e[r+15]=1}function p(e,t){e.fill(0,16*t,16*t+16),e[16*t+13]=-50,e[16*t+15]=1}function g(e,t,a){let[r,n,o]=a.size,l=Math.cos(a.yaw),s=Math.sin(a.yaw);h(e,t,[l*r,0,-s*r,0,0,n,0,0,s*o,0,l*o,0]),m(e,t,a.at)}function v(e,t,a,r){let[n,o,l]=a.at,[s,i,f]=a.along,{radius:u}=a,{width:d,depth:c,long:g}=r,v=Math.hypot(s,i,f),y=Math.hypot(s,f);if(v<1e-5||y<1e-5)return void p(e,t);let w=s/v,b=i/v,x=f/v,M=f/y,k=-s/y,z=k*b,S=M*x-k*w,A=-M*b;h(e,t,[M*d,0,k*d,0,z*c,S*c,A*c,0,w*g,b*g,x*g,0]);let L=u+c/2;m(e,t,[n+z*L,o+S*L,l+A*L])}function y(e,t,a,r){let{size:n,yaw:o}=r;g(e,t,{at:a,size:[n,n*(r.flat??1),n],yaw:o})}function w(e,t,a){let{a:r,b:n,radius:o}=a,l=n[0]-r[0],s=n[1]-r[1],i=n[2]-r[2],f=Math.hypot(l,s,i);if(f<1e-5||o<=0)return void p(e,t);let u=l/f,d=s/f,c=i/f,g=Math.max(2*o,.045),v=f+.5*g;if(d<-.9999)h(e,t,[g,0,0,0,0,-v,0,0,0,0,-g,0]);else{let a=1/(1+d);h(e,t,[(1-u*u*a)*g,-u*g,-u*c*a*g,0,u*v,d*v,c*v,0,-u*c*a*g,-c*g,(1-c*c*a)*g,0])}m(e,t,[(r[0]+n[0])/2,(r[1]+n[1])/2,(r[2]+n[2])/2])}var b=[0,1,0],x=(e,t,a)=>{let r=Math.hypot(e,t,a);return r>1e-6?[e/r,t/r,a/r]:[0,0,0]},M=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],k=e=>0===e[0]&&0===e[1]&&0===e[2],z=new Float64Array(9);function S(e,t,a,r){let{p:n,n:l,size:s}=a,i=a.long??1;!function(e,t){(function(e,t){let a=e[0],r=e[1]-t,n=e[2],o=Math.hypot(a,r,n);o>1e-6?(a/=o,r/=o,n/=o):(a=0,r=1,n=0),z[3]=a,z[4]=r,z[5]=n})(e,t),function(){let e=o(z,3),t=o(z,5),a=-e,r=Math.hypot(t,a);r>1e-6?(t/=r,a/=r):(t=1,a=0),z[0]=t,z[2]=a}(),function(){let e=o(z,0),t=o(z,2),a=o(z,3),r=o(z,4),n=-t*r,l=t*a-e*o(z,5),s=e*r,i=Math.hypot(n,l,s);i>1e-6?(n/=i,l/=i,s/=i):(n=0,l=0,s=0),z[6]=n,z[7]=l,z[8]=s}()}(l,r.droop);let f=Math.cos(r.twist),u=Math.sin(r.twist),d=1.05*s,c=s*i*(1+.15*r.nod),h=16*t;e[h]=(o(z,0)*f+o(z,6)*u)*d,e[h+1]=o(z,7)*u*d,e[h+2]=(o(z,2)*f+o(z,8)*u)*d,e[h+3]=0,e[h+4]=o(z,3)*c,e[h+5]=o(z,4)*c,e[h+6]=o(z,5)*c,e[h+7]=0,e[h+8]=(o(z,6)*f-o(z,0)*u)*d,e[h+9]=o(z,7)*f*d,e[h+10]=(o(z,8)*f-o(z,2)*u)*d,e[h+11]=0,e[h+12]=n[0],e[h+13]=n[1],e[h+14]=n[2],e[h+15]=1}var A=[[0,0],[.09,.07],[.18,.26],[.21,.48],[.17,.7],[.09,.9],[.02,1.06],[0,1.16]];function L(e,t=A,a=.1,r=0){return O(e,t,{fold:a,bend:r},C)}var C=[1.22,.5,.18],F=[1.08,.2,.08];function B(e){return O(e,A,{fold:.1,bend:0},F)}function O(e,t,{fold:a,bend:r},[n,o,s]){let i=Math.max(...t.map(([e])=>e)),f=[],u=[],d=(e,t)=>{let a=Math.abs(e)/i,r=n-o*a-s*l(.25,0,t);return[r,r*(1+.04*(1-a)),r]};for(let e=0;e<t.length-1;e+=1){let[n,o]=t[e]??[0,0],[l,s]=t[e+1]??[0,0];for(let e of[-1,1]){let t=[0,o,r*o*o],c=[0,s,r*s*s],h=[e*n,o,a*n/i+r*o*o],m=[e*l,s,a*l/i+r*s*s],p=e>0?[t,h,m,t,m,c]:[t,m,h,t,c,m];for(let e of p)f.push(...e),u.push(...d(e[0]??0,e[1]??0))}}let c=new e.Geometry;return c.setAttribute("position",new e.Attribute(new Float32Array(f),3)),c.setAttribute("color",new e.Attribute(new Float32Array(u),3)),c.computeVertexNormals(),c}var R=[[0,.2,0,.56],[.5,-.08,.12,.46],[-.34,-.04,.4,.44],[-.16,-.12,-.46,.45],[.12,-.42,.04,.36]];function D(e){let t=[],a=[],r=e.icosahedron(1,0).attributes.position?.array??new Float32Array(0),o=e=>r[e]??0;for(let[e=0,l=0,s=0,i=.5]of R)for(let f=0;f+8<r.length;f+=9){let r=n(.5+(o(f+1)+o(f+4)+o(f+7))/3*.55+.6*l,0,1),u=.74+.34*r;for(let n=f;n<f+9;n+=3)t.push(e+o(n)*i,l+o(n+1)*i,s+o(n+2)*i),a.push(u,u*(.8+.2*r),u*(.88+.12*r))}let l=new e.Geometry;return l.setAttribute("position",new e.Attribute(new Float32Array(t),3)),l.setAttribute("color",new e.Attribute(new Float32Array(a),3)),l.computeVertexNormals(),l}function T(e,t){let{positions:a,colors:r}=e,{from:n,to:o,across:l,width:s,tone:i}=t,f=t.bend??0,u=f>0?[0,.45,.8,1]:[0,.8,1],d=e=>[n[0]+(o[0]-n[0])*e,n[1]+(o[1]-n[1])*e-f*e*e,n[2]+(o[2]-n[2])*e],c=e=>s*(e<=.8?1:.06);for(let e=0;e<u.length-1;e+=1){let t=u[e]??0,n=u[e+1]??1,o=d(t),s=d(n),f=c(t),h=c(n),m=[o[0]-l[0]*f,o[1]-l[1]*f,o[2]-l[2]*f],p=[o[0]+l[0]*f,o[1]+l[1]*f,o[2]+l[2]*f],g=[s[0]+l[0]*h,s[1]+l[1]*h,s[2]+l[2]*h],v=[s[0]-l[0]*h,s[1]-l[1]*h,s[2]-l[2]*h];for(let[e,o]of[[m,t],[p,t],[g,n],[m,t],[g,n],[v,n]])a.push(...e),r.push(...i(o))}}function U(e,t){let{from:a,to:r}=t,n=x(r[0]-a[0],r[1]-a[1],r[2]-a[2]),o=x(...M(n,b));k(o)&&(o=[1,0,0]);let l=x(...M(n,o));T(e,{...t,across:o}),T(e,{...t,across:l})}function I(e,t,a){let r={positions:[],colors:[]},n=e=>{let t=.8+.34*e;return[t,t,t]},o="pine"===t,l=o?.32:.24,s=o?.62:.3,i=(o?.075:.1)*Math.sqrt(10/a);T(r,{from:[0,0,0],to:[0,1,0],across:[1,0,0],width:.025,tone:()=>[.62,.6,.58]});for(let e=0;e<a;e+=1){let t=.06+e/a*.84,o=2.39996*e,f=Math.cos(o),u=Math.sin(o);T(r,{from:[0,t,0],to:[f*l,t+s,u*l],across:[-u,.1,f],width:i,tone:n})}return _(e,r)}function _(e,t){let a=new e.Geometry;return a.setAttribute("position",new e.Attribute(new Float32Array(t.positions),3)),a.setAttribute("color",new e.Attribute(new Float32Array(t.colors),3)),a.computeVertexNormals(),a}var Y=(e,t)=>a=>{let r=e+(t-e)*a;return[r,r,r]};function W(e,t,a=[.62,.6,.58]){T(e,{from:[0,0,0],to:[0,t,0],across:[1,0,0],width:.02,tone:()=>a}),T(e,{from:[0,0,0],to:[0,t,0],across:[0,0,1],width:.02,tone:()=>a})}function N(e,t){let a={positions:[],colors:[]};return"pine"===t?function(e){W(e,1);for(let t=0;t<5;t+=1){let a=.12+.2*t;for(let n=0;n<3;n+=1){let o=2.39996*t+n/3*r,l=.3+.05*n;U(e,{from:[0,a,0],to:[Math.cos(o)*l,a+.62,Math.sin(o)*l],width:.014,tone:Y(.78,1.16),bend:.06})}}}(a):"spruce"===t?function(e){W(e,1,[.78,.52,.36]);let t=e=>[.78+.24*e,.82+.24*e,.84+.26*e];for(let a=0;a<30;a+=1){let r=.04+a/30*.86,n=2.39996*a,o=.24;U(e,{from:[0,r,0],to:[Math.cos(n)*o,r+.2,Math.sin(n)*o],width:.016,tone:t})}for(let a=0;a<12;a+=1){let n=a/12*r+.2,o=a%2==0?.24:.08;U(e,{from:[0,.96,0],to:[.24*Math.cos(n),1+o,.24*Math.sin(n)],width:.016,tone:t})}let a=()=>[1.25,.95,.62];T(e,{from:[0,.94,0],to:[0,1.08,0],across:[1,0,0],width:.05,tone:a}),T(e,{from:[0,.94,0],to:[0,1.08,0],across:[0,0,1],width:.05,tone:a})}(a):function(e){W(e,1.1);for(let t=0;t<9;t+=1){let a=.08+t/9*.92,r=.24*Math.sin(Math.PI*(.2+.8*(1-a)))+.06;for(let t of[-1,1])T(e,{from:[0,a,0],to:[t*r,a+.35*r,0],across:[0,.4,1],width:.035,tone:Y(.8,1.12)})}}(a),_(e,a)}var E={pine:"pine",spruce:"spruce",redwood:"redwood"},G=new WeakMap,$=[[0,0],[.012,.04],[.026,.18],[.03,.4],[.027,.62],[.018,.82],[.008,.94],[0,1]],P=new WeakMap;function V(e,t){if("palm"===t){let t=P.get(e);return t||P.set(e,t=L(e,$,.014,.24)),t}let a=E[t];if(!a)return K(e).blade;let r=G.get(e);r||G.set(e,r=new Map);let n=r.get(a);return n||r.set(a,n=N(e,a)),n}var H=new WeakMap;function K(e){let t=H.get(e);return t||(t={wood:e.cylinder(.5,.5,1,7,1),leaf:e.icosahedron(.56,0),blade:L(e),bud:e.icosahedron(.55,1),box:e.box(1,1,1),softBlade:B(e),spray:D(e)},H.set(e,t)),t}function j(e,t=0,a=!1,r=!1){let n=new e.LitMaterial({color:"#ffffff",roughness:.92,metalness:0});return n.userData.voxelDitherKeep=!0,n.onCompile=e=>{e.vertexShader="\nvarying vec3 vBark;\nvarying vec3 vBarkWorld;\nvarying float vBarkUp;\n"+e.vertexShader.replace("#include <begin_vertex>","#include <begin_vertex>\n#ifdef USE_INSTANCING\n float barkRadius = length(instanceMatrix[0].xyz);\n vec4 barkWorld = modelMatrix * instanceMatrix * vec4(position, 1.0);\n vec3 barkAxis = normalize(instanceMatrix[1].xyz);\n#else\n float barkRadius = 1.0;\n vec4 barkWorld = modelMatrix * vec4(position, 1.0);\n vec3 barkAxis = vec3(0.0, 1.0, 0.0);\n#endif\n float barkAngle = atan(position.z, position.x);\n vBark = vec3(cos(barkAngle) * barkRadius, sin(barkAngle) * barkRadius, dot(barkWorld.xyz, barkAxis));\n vBarkWorld = barkWorld.xyz;\n vBarkUp = abs(barkAxis.y);"),e.fragmentShader=`${a?"#define BARK_UPRIGHT_MOSS\n":""}${r?"#define BARK_BARE_WALL\n":""}uniform float uBarkGround;\n\nvarying vec3 vBark;\nvarying vec3 vBarkWorld;\nvarying float vBarkUp;\nfloat barkHash(vec3 p) { return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453); }\nfloat barkNoise(vec3 p) {\n vec3 i = floor(p);\n vec3 f = fract(p);\n f = f * f * (3.0 - 2.0 * f);\n return mix(mix(mix(barkHash(i), barkHash(i + vec3(1, 0, 0)), f.x), mix(barkHash(i + vec3(0, 1, 0)), barkHash(i + vec3(1, 1, 0)), f.x), f.y),\n mix(mix(barkHash(i + vec3(0, 0, 1)), barkHash(i + vec3(1, 0, 1)), f.x), mix(barkHash(i + vec3(0, 1, 1)), barkHash(i + vec3(1, 1, 1)), f.x), f.y), f.z);\n}\nvec3 barkSurface(vec3 base) {\n vec3 p = vec3(vBark.xy * 3.2, vBark.z * 0.7);\n float ridge = barkNoise(p) * 0.65 + barkNoise(p * 2.1 + 7.0) * 0.35;\n float fissure = 1.0 - smoothstep(0.03, 0.11, abs(ridge - 0.5));\n float plate = barkNoise(vec3(vBark.xy * 1.6, vBark.z * 0.35) + 3.0);\n vec3 c = base * (1.0 + 0.5 * plate) * 1.15;\n c += base * 0.45 * smoothstep(0.62, 0.82, ridge);\n c *= 1.0 - 0.65 * fissure;\n float fleck = step(0.94, barkHash(floor(vec3(vBark.xy * 9.0, vBark.z * 7.0))));\n c = mix(c, mix(base, vec3(0.72, 0.76, 0.62), 0.65), fleck * 0.55);\n float knot = smoothstep(0.88, 0.95, barkNoise(vec3(vBark.xy * 0.9, vBark.z * 0.5) + 11.0));\n c *= 1.0 - 0.45 * knot;\n float moss = smoothstep(1.6, 0.4, vBarkWorld.y - uBarkGround) * smoothstep(0.45, 0.65, barkNoise(vBarkWorld * 2.2));\n#ifdef BARK_UPRIGHT_MOSS\n // Moss climbs the upright trunk foot, not the roots lying along the soil (green hairlines on a planter).\n moss *= smoothstep(0.35, 0.75, vBarkUp);\n#endif\n#ifdef BARK_BARE_WALL\n // Below the soil line the wood is a root on the planter's wall: bare bark, not a green vine.\n moss *= smoothstep(uBarkGround - 0.3, uBarkGround + 0.05, vBarkWorld.y);\n#endif\n return mix(c, vec3(0.33, 0.46, 0.2) * (0.8 + 0.4 * plate), moss * 0.85);\n}\n${e.fragmentShader.replace("#include <color_fragment>","#include <color_fragment>\n diffuseColor.rgb = barkSurface(diffuseColor.rgb);")}`,e.uniforms.uBarkGround={value:t}},n.customProgramCacheKey=()=>`living-bark${a?"-upright":""}${r?"-bare":""}`,n}var q={blossom:{size:[.7,.7,.7],lift:0,fall:.55},catkin:{size:[.35,1.5,.35],lift:-.75,colors:["#c9c27a","#b8ae64","#d9d394"],fall:.9},candle:{size:[.4,1.2,.4],lift:.65,colors:["#e2e8b0","#d0daa0","#eef0c8"],fall:0},puff:{size:[.5,.5,.5],lift:.1,colors:["#f2d33c","#f7e26e","#e6bf27"],fall:.6},spadix:{size:[.4,1.2,.4],lift:-.55,colors:["#efe2a6","#e6d48a","#f4ecc4"],fall:.7},cherry:{size:[.85,.85,.85],lift:-.7,colors:["#c8102e","#a8102a","#e0303e"],green:"#86a24c",fall:2.4},acorn:{size:[.5,.65,.5],lift:-.45,colors:["#7a5a2a","#8c6a32","#6b4f22"],green:"#7f9a4a",fall:2.6},cone:{size:[.5,.85,.5],lift:-.6,colors:["#7b5733","#6a4a2a","#8a6640"],green:"#6d8a4c",fall:2.4},coconut:{size:[1,1.1,1],lift:-.7,colors:["#7c9a36","#6b8a2e","#6a5230"],green:"#86ab3e",fall:3.2},pod:{size:[.35,1.8,.6],lift:-.9,colors:["#8a6a3a","#9a7a46","#7a5c30"],green:"#8aa058",fall:1.4},samara:{size:[.8,.95,.16],lift:-.55,colors:["#b99a5c","#a8844a","#c9ab6e"],green:"#a4bf62",fall:.45},bell:{size:[.85,.95,.85],lift:-1.1,colors:["#f6f1e2","#efe6cc","#fbf8ee"],fall:.8},gourd:{size:[.8,1.4,.8],lift:-1.6,colors:["#9c9474","#8c8466","#aaa282"],green:"#83905c",fall:3},apple:{size:[1.4,1.35,1.4],lift:-.6,colors:["#c8202a","#e0402c","#a81c26"],green:"#9ab84c",fall:2.6},pear:{size:[1.1,1.6,1.1],lift:-.75,colors:["#c8d84a","#d8e060","#a8b838"],green:"#8fb04a",fall:2.6},peach:{size:[1.35,1.35,1.35],lift:-.5,colors:["#f29a5c","#f8b878","#e8604a"],green:"#a8b860",fall:2.4},plum:{size:[1.2,1.35,1.2],lift:-.65,colors:["#7b3fa0","#b77ad1","#5e2c80"],green:"#8aa04a",fall:2.4},orange:{size:[1.4,1.4,1.4],lift:-.5,colors:["#ff8a00","#ff9e1a","#f07000"],green:"#b8d468",fall:2.6},lemon:{size:[1.15,1.5,1.15],lift:-.55,colors:["#fff23a","#fff680","#f0dc20"],green:"#7aa03e",fall:2.6},fig:{size:[1.3,1.5,1.3],lift:-.4,colors:["#5a2a4a","#7a3c64","#46203a"],green:"#a8b86a",fall:2.2},mango:{size:[1.25,1.8,1.25],lift:-.95,colors:["#f0a020","#e8602a","#c8c03a"],green:"#6a9a3a",fall:3}},X={size:[.28,.85,.28],lift:.45,colors:["#e9e6cf","#f2edb0","#d8d4b8"],fall:.9},Z={size:[1,1,1],lift:0,fall:0},J={...q.cone??Z,size:[.4,1,.4],colors:["#a58256","#8f6c46","#b8966a"],green:"#7a5f55"};function Q(e,t=""){return"catkin"===e.kind&&"willow"===t?X:"cone"===e.kind&&"spruce"===t?J:q[e.kind]??Z}var ee=18,te={heave:0,burst:0,hang:0},ae=.7,re=.42,ne=e=>e%1e3/1e3;function oe(e){let t=e.wall??{depth:1,flare:0};return{hard:e.planter?.hard??t.depth<.5,hang:Math.max(0,e.planter?.hang??1.2*t.depth)}}function le(e,t,a,r=1){let n=l(.45,.85,t);if(n<=0||!a.lip)return e.map(()=>te);let{hard:o,hang:i}=oe(a),f=a.rootReach??a.radius,u=s((2135587861^r)>>>0),d=!o&&n>.15&&ne(u)<.83,c=e=>(.3+16*t)*e.reach>=.92*f,h=e.map((e,t)=>{let a=s((r^Math.imul(t+1,2654435761))>>>0);return{burst:d&&c(e)&&ne(a)<.12+.2*n,depth:.28+.32*ne(a>>>10)}});if(d&&!h.some(e=>e.burst)){let t=h[function(e,t){let a=-1;for(let[r,n]of e.entries())t(n)&&(a<0||n.reach>(e[a]?.reach??0))&&(a=r);return a}(e,c)];t&&(t.burst=!0)}return h.map(e=>({heave:n,burst:e.burst?e.depth:0,hang:i}))}function se(e,t,a){if(t.first)return e.y+.9*t.trunk;let{s:r,reach:n,radius:o,phase:s,heave:i}=t,f=.7*Math.sin(2.1*r+s)+.3*Math.sin(4.7*r+2.3*s),u=Math.max(l(.8,.1,r),l(a-.7,a-.1,n)),d=1.1+.9*i;return e.y+o*(.15+d*Math.max(f,.6*u))-o*(1.3+.4*i)*(1-u)*Math.max(0,-f)}function ie(e,t,a){let r=e.wall??{depth:1,flare:0},o=t.reach-a,l=t.heave*t.radius*.7;if(o<.32){let r=o/.32*Math.PI*.5;return{r:a+.3*Math.sin(r)+.6*t.radius,y:e.y+.5*t.radius+l*Math.cos(r)-.3*(1-Math.cos(r)),gone:!1}}let s=o-.32,i=e.y-.3-s;if(e.surface){let n=e.surface(t.angle,i);return{r:n+.6*t.radius,y:i,gone:s>.92*r.depth||n<.45*a}}let f=n(s/Math.max(r.depth,.1),0,1);return{r:(a+.3)*(1+r.flare*f)+.7*t.radius,y:i,gone:s>.92*r.depth}}function fe(e,t,a,r){let o=e.wall??{depth:1,flare:0};return e.surface?e.surface(t,r):(a+.28)*(1+o.flare*n((e.y-r)/Math.max(o.depth,.1),0,1))}var ue=(e,t)=>t.burst>0&&void 0!==e.lip;function de(e,t,a){return a?.42*e*(1-.5*t)*(1-t**5)+.035:.5*e*(1-.55*t)*(1-t**3)+.03*t**3}function ce(e,t,a,r){let n=ue(e,r);return n&&t.reach>=a-ae?function(e,t,a,r){let n=e.wall??{depth:1,flare:0},o=Math.min(n.depth,2.4),s=e.y-Math.max(.3,o*r.burst),i=t.reach-(a-ae);if(i<ae){let r=l(0,.6,i/ae),n=e.y-1.4*t.radius-.08,o=n+(Math.min(s,n)-n)*r;return{r:Math.min(t.reach,fe(e,t.angle,a,o)-t.radius-.08),y:o,gone:!1,swell:0}}if(i<ae+re){let r=(i-ae)/re,n=Math.sin(r*Math.PI);return{r:fe(e,t.angle,a,s)+t.radius*(.35+.45*r)+.16*n,y:s+.08*n,gone:!1,swell:n}}let f=i-ae-re,u=e.y-o,d=s-f;if(d>u){let r=fe(e,t.angle,a,d);if(!e.surface||r>.7*a)return{r:r+.6*t.radius,y:d,gone:!1,swell:0}}let c=Math.max(d,u),h=fe(e,t.angle,a,c)+.6*t.radius,m=Math.max(0,Math.min(u,s)-d);return{r:Math.max(h,.7*a)+.18*Math.sin(1.3*Math.min(m,1.2)),y:d,gone:m>r.hang,swell:0}}(e,t,a,r):t.reach<a?{r:t.reach,y:se(e,t,n?a+9:a),gone:!1,swell:0}:{...ie(e,t,a),swell:0}}function he(e,t,a,r=te){let n=ue(a,r),o=function(e,t,a,r){let n=a.wall??{depth:1,flare:0},o=a.rootReach??a.radius;return r.burst>0&&void 0!==a.lip?Math.max(.5,a.lip(e.angle)-.12-.5*t)+re+Math.min(n.depth,2.4)*(1-r.burst)+r.hang:Math.min((.3+16*t)*e.reach,o+1.4*n.depth)}(e,t,a,r),l=7.3*e.angle,s=[];for(let i=0;i<=ee;i+=1){let f=o*i/ee,u=de(t,f/o,n),d=e.angle+.3*Math.sin(.7*f+l)+.06*Math.sin(2.1*f+1.7*l),c={s:f,reach:.5*t+f,angle:d,radius:u,phase:l,trunk:t,heave:r.heave,first:0===i},h=(a.lip?.(d)??1/0)-.12,m=ce(a,c,h,r);s.push({x:Math.cos(d)*m.r,y:m.y,z:Math.sin(d)*m.r,radius:Math.max(u*(1+.6*m.swell),.022),gone:m.gone})}return s}var me=8;function pe(e,t){let{random:a,size:r}=e,{angle:n,r:o,y:l,side:s,scale:i,tilt:f}=t,u=r*i*(.75+.5*a()),d=-Math.sin(n),c=Math.cos(n),h=Math.sin(n);e.shards.push({x:c*o+d*s,y:l,z:h*o+c*s,size:[u*(.9+.45*a()),u*(.6+.35*a()),u*(.7+.35*a())],angle:n,tilt:f+.3*(a()-.5),roll:.9*(a()-.5)+.25*Math.sign(s),tone:1+Math.floor(2*a())})}function ge(e,t,a){let{y:r,side:n,width:o,height:l,roll:s,tone:i}=a,f=a.push??.02,u=-Math.sin(t.angle),d=Math.cos(t.angle),c=Math.sin(t.angle),h=fe(e.ground,t.angle,t.lip,r)+f;e.shards.push({x:d*h+u*n,y:r,z:c*h+d*n,size:[o,l,.05],angle:t.angle,tilt:0,roll:s,tone:i})}function ve(e,t,a){let{trunk:r,ground:n,plan:o}=a,l=a.seed??1;if(o.heave<.2||!n.lip)return[];let f=i((625341585^s((l^Math.imul(t+7,2246822507))>>>0))>>>0),{hard:u}=oe(n),d=7.3*e.angle,c=t=>e.angle+.3*Math.sin(.7*t+d)+.06*Math.sin(2.1*t+1.7*d),h=(.2+.2*o.heave)*(u?.7:1),m=Math.max(.25*r,.1),p=Math.max(.1,n.lip(e.angle)-.12-.5*r),g=c(p),v=n.lip(g)-.12,y={random:f,ground:n,plan:o,hard:u,size:h,thick:m,shards:[],rimAngle:g,lip:v};if(o.burst<=0)return(.3+16*r)*e.reach<v+.1?[]:function(e){let{random:t,ground:a,plan:r,hard:n,size:o,thick:l,rimAngle:s,lip:i}=e;for(let n of[-1,1])pe(e,{angle:s,r:i+.08,y:a.y+.06+.2*o,side:n*(l+.14+.08*t()),scale:1,tilt:.35+.35*r.heave});return!n&&r.heave>.45&&pe(e,{angle:s,r:i+.32,y:a.y-.35-.4*t(),side:.3*(t()-.5),scale:.7,tilt:1.2}),e.shards}(y);let w=c(p+.21);return function(e,t){let{random:a,ground:r,plan:n,size:o,thick:l,rimAngle:s,lip:i}=e,f=r.wall??{depth:1,flare:0},u=Math.min(f.depth,2.4),d=r.y-Math.max(.3,u*n.burst),c=fe(r,t.angle,t.lip,d),h=Math.min(l,.22)+.12;ge(e,t,{y:d,side:0,width:1.9*h,height:1.7*h,roll:.6*(a()-.5),tone:3}),pe(e,{angle:t.angle,r:c+.1,y:d+.95*h,side:.25*(a()-.5),scale:1.4,tilt:1}),pe(e,{angle:t.angle,r:c+.1,y:d-.15*h,side:1.1*-h,scale:1.2,tilt:.85}),pe(e,{angle:t.angle,r:c+.1,y:d-.05*h,side:1.1*h,scale:1.2,tilt:.85}),pe(e,{angle:t.angle,r:fe(r,t.angle,t.lip,d-.6)+.14,y:d-h-.45,side:.6*(a()-.5),scale:.9,tilt:1.35});let m=d+h,p=Math.max(0,r.y-.04-m);if(p>.12){let r=(a()<.5?-1:1)*(.08+.1*a()),n={tone:3,push:.03},o={y:m+.25*p,side:.5*r,width:.13,height:.55*p};ge(e,t,{...n,...o,roll:.35*-Math.sign(r)});let l={y:m+.72*p,side:.6*r,width:.11,height:.5*p};ge(e,t,{...n,...l,roll:.3*Math.sign(r)})}return pe(e,{angle:s,r:i+.06,y:r.y+.06+.2*o,side:.3*(a()-.5),scale:1.1,tilt:.5}),e.shards}(y,{angle:w,lip:n.lip(w)-.12})}function ye(e,t,a){let{ground:r}=e,{first:n,root:o,trunk:l}=a,s=(.25+2.4*l)*o.reach,i=Math.cos(o.angle),f=Math.sin(o.angle);w(t,n,{a:[i*l*.5,r.y+.9*l,f*l*.5],b:[i*s,r.y+.02,f*s],radius:.42*l})}function we(e,t,a,r){let{model:n,ground:o}=e,{first:l,root:s,trunk:i}=a,f=e.features.rootSink&&n.species.palm?4:ee,u=function(e,t){let{ground:a}=e;return e.features.rootSink&&t<ze?.42*(a.rootReach??a.radius):1/0}(e,i);!function(e,t,a,r){let{sink:n,parts:o,reach:l}=r;for(let r=0;r<o;r+=1){let o=a[r],s=a[r+1];if(void 0!==o&&void 0!==s&&!o.gone){if(r>1&&(o.radius<n||Math.hypot(o.x,o.z)>l))break;w(e,t+r,{a:[o.x,o.y,o.z],b:[s.x,s.y,s.z],radius:(o.radius+s.radius)/2})}}}(t,l,he(s,i,o,r),{sink:e.features.rootSink?ke:0,parts:f,reach:r.heave>0?1/0:u})}var be=["#5e4a3a","#7a634f","#958068"];function xe(e,t){return 3===t.tone?e[0]??be[0]:e[Math.min(t.tone,e.length-1)]??be[0]}function Me(e,t,a){let r=Math.cos(a.angle),n=Math.sin(a.angle),o=Math.cos(a.tilt),l=Math.sin(a.tilt),s=Math.cos(a.roll),i=Math.sin(a.roll),f=[-n,0,r],u=[r*l,o,n*l],d=[r*o,-l,n*o],c=f.map((e,t)=>e*s+(u[t]??0)*i),p=u.map((e,t)=>e*s-(f[t]??0)*i),[g,v,y]=a.size;h(e,t,[(c[0]??0)*g,(c[1]??0)*g,(c[2]??0)*g,0,(p[0]??0)*v,(p[1]??0)*v,(p[2]??0)*v,0,(d[0]??0)*y,(d[1]??0)*y,(d[2]??0)*y,0]),m(e,t,[a.x,a.y,a.z])}var ke=.06,ze=.45;function Se(e,t){let a=e.strainOf&&t<e.model.count?o(e.strainOf,t):0;return(a>0?e.strains[a]?.colors:void 0)??e.colors}var Ae=(e,t)=>e.strainOf&&t<e.model.count?e.strains[o(e.strainOf,t)]:void 0;function Le(e,t,a){let r=Ae(e,t)?.hang??0;return r>0?r*(.25+7*a%8/8):0}function Ce(e,t){let a=e.strainOf&&t<e.model.count?o(e.strainOf,t):0,r=a>0?e.strains[a]:void 0;return void 0!==r?.skin?r.skin:e.skin}function Fe(e,t){let a=e.model.parent,r=a&&t<e.model.count?Math.max(0,o(a,t)):t;return s(2654435769^Math.imul(r+1,2654435761))}function Be(e,t,a){return!e.strainOf||0===e.strainYears.length||t>=e.model.count?a:e.strainYears[o(e.strainOf,t)]??a}function Oe(e,t){return t>.2?e[0]:t>.07?e[1]:e[2]}function Re(e,t,a){let r=function(e,t){let a=e.strainOf&&t<e.model.count?o(e.strainOf,t):0;return(a>0?e.strains[a]?.bark:void 0)??Se(e,t).trunk}(e,a),n=a>=e.model.count?1:o(t.radius,a),l=s(2654435761*a)%100;return"birch"===e.model.species.id?function(e,t,a){return a<18&&t>.05?e[2]:t>.05?e[0]:e[1]}(r,n,l)??"#6b4a33":Oe(r,n)??"#6b4a33"}function De(e,t,a){if(e.still)return e.offset.x=0,void(e.offset.z=0);d(e.offset,a,t.gust)}var Te=(e,t,a)=>t*Math.cos(e.dir)+a*Math.sin(e.dir);function Ue(e,t,a){if(e.fronds)return void function(e,t,a,r){let{frame:l}=a,{size:s,swing:i}=a.leaf,f=e.model.leaves,u=o(f.node,r),d=[o(l.x,u),o(l.y,u),o(l.z,u)],c=[o(l.baseX,u),o(l.baseY,u),o(l.baseZ,u)],h=o(t.along,r),m=[c[0]+(d[0]-c[0])*h,c[1]+(d[1]-c[1])*h,c[2]+(d[2]-c[2])*h],{fw:p,side:g,down:v}=function(e,t){let a=x(e[0]-t[0],e[1]-t[1],e[2]-t[2]);k(a)&&(a=b);let r=x(...M(a,b));return k(r)&&(r=[1,0,0]),{fw:a,side:r,down:x(...M(a,r))}}(d,c),y=o(t.out,r),w=o(t.side,r),z=o(f.rank,r),A=.35*a.wind*Math.sin(a.elapsed*(6+3*z)+40*z+.8*Te(a,m[0],m[2])),L=.5+.15*y,C=.3+.45*y+.5*A,F=[w*g[0]*Math.cos(L)+p[0]*Math.sin(L)+v[0]*C,w*g[1]*Math.cos(L)+p[1]*Math.sin(L)+v[1]*C,w*g[2]*Math.cos(L)+p[2]*Math.sin(L)+v[2]*C],B=Math.hypot(d[0]-c[0],d[1]-c[1],d[2]-c[2])*o(t.pieces,r)*.3*(.25+.75*Math.sin(Math.PI*(.08+.88*y))**.7)*n(s/Math.max(a.size,1e-6),0,1.4)*(.85+.3*o(f.size,r));De(e,a,m),S(a.array,r,{p:[m[0]+e.offset.x+i,m[1],m[2]+e.offset.z+.4*i],n:x(...F),size:B},{droop:.04,twist:.35*w+.6*A,nod:0})}(e,e.fronds,t,a);if(function(e,t){if(!e.needles)return!1;let a=Ae(e,t)?.species;return void 0===a||void 0!==E[a]}(e,o(e.model.leaves.node,a)))return void function(e,t,a){let{frame:n}=t,{size:l,swing:s}=t.leaf,i=e.model.leaves,f=o(i.node,a),{p:u,n:d}=_e(n,i,a);De(e,t,u);let h=c(t.air,o(i.rank,a),o(e.model.phase,f),Te(t,u[0],u[2])),m={droop:.12*h.droop,twist:o(i.rank,a)*r+.2*h.twist,nod:.3*h.nod};S(t.array,a,{p:[u[0]+e.offset.x+.3*s,u[1],u[2]+e.offset.z+.12*s],n:d,size:1.9*l},m)}(e,t,a);let{frame:l}=t,{size:s,swing:i}=t.leaf,f=e.model.leaves,u=o(f.node,a),d=o(f.dx,a),h=o(f.dy,a),m=o(f.dz,a),p=Math.hypot(d,h,m)*t.spread,g=Math.min(.3*p,.22),v=p/t.spread||1,y=(Ae(e,u)?.hang??0)>0,w=y?[d/v*.25,-1,m/v*.25]:[d/v,h/v,m/v],z=y?.55:0,A=o(l.x,u)+w[0]*g+d/v*z,L=o(l.y,u)+w[1]*g-Le(e,u,a),C=o(l.z,u)+w[2]*g+m/v*z;De(e,t,[A,L,C]);let F=c(t.air,o(f.rank,a),o(e.model.phase,u),Te(t,A,C));S(t.array,a,{p:[A+e.offset.x+i,L,C+e.offset.z+.4*i],n:w,size:s*(y?1.5:1.9),long:y?2.4:1},F)}function Ie(e){let{parent:t,order:a}=e;if(!e.species.palm||!t||!a)return null;let{depth:r,base:n,pieces:l}=function(e,t,a){let r=new Float32Array(e.count),n=new Int32Array(e.count).fill(-1),l=new Float32Array(e.count);for(let s=0;s<e.count;s+=1){let e=o(t,s);if(0===o(a,s))continue;let i=e<0||0===o(a,e);r[s]=i?0:o(r,e)+1,n[s]=i?s:o(n,e);let f=o(n,s);l[f]=Math.max(o(l,f),o(r,s)+1)}return{depth:r,base:n,pieces:l}}(e,t,a),s=e.leaves,i={along:new Float32Array(s.count),side:new Float32Array(s.count),out:new Float32Array(s.count),pieces:new Float32Array(s.count)},f=0;for(let e=1;e<=s.count;e+=1){if(e<s.count&&o(s.node,e)===o(s.node,f))continue;let t=o(s.node,f),a=Math.max(1,o(l,Math.max(0,o(n,t)))),u=Math.ceil((e-f)/2);for(let n=0;n<e-f;n+=1){let e=(Math.floor(n/2)+.5+n%2*.2)/u;i.along[f+n]=e,i.side[f+n]=n%2==0?1:-1,i.out[f+n]=(o(r,t)+e)/a,i.pieces[f+n]=a}f=e}return i}function _e(e,t,a){let r=o(t.node,a),n=[o(e.x,r),o(e.y,r),o(e.z,r)],l=[o(e.baseX,r),o(e.baseY,r),o(e.baseZ,r)],s=.15+7.31*o(t.rank,a)%1*.7,i=.35,f=x(n[0]-l[0]+o(t.dx,a)*i,n[1]-l[1]+o(t.dy,a)*i,n[2]-l[2]+o(t.dz,a)*i);return k(f)&&(f=b),{p:[l[0]+(n[0]-l[0])*s,l[1]+(n[1]-l[1])*s,l[2]+(n[2]-l[2])*s],n:f}}function Ye(e,t,a){let{frame:n}=t,{size:l,swing:s}=t.leaf,i=e.model.leaves,f=o(i.node,a),u=o(i.rank,a),d=o(n.x,f)+o(i.dx,a)*t.spread,c=o(n.y,f)+o(i.dy,a)*t.spread-Le(e,f,a),h=o(n.z,f)+o(i.dz,a)*t.spread;De(e,t,[d,c,h]);let m=.012*t.wind*Math.sin(6.3*t.elapsed+40*u),p=m*Math.cos(t.dir),g=m*Math.sin(t.dir),v=[d+e.offset.x+p+s*Math.cos(t.dir),c+.4*m,h+e.offset.z+g+s*Math.sin(t.dir)];y(t.array,a,v,{size:l,yaw:u*r+6*m})}function We(e,t,a,r){let{frame:n}=t,l=e.model.leaves,s=o(l.node,r);return(t.seedling||zt(n,s,t.tipLimit))&&o(n.grow,s)>0&&o(l.rank,r)>=a.drop&&!e.hiddenSlots.leaf.has(r)}function Ne(e,t){return e.features.clumps?1+.9*n(1-(t.visible-4)/90,0,1):t.visible<=4?.8:1}function Ee(e,t,a,r){let n=e.model.leaves,l=o(n.node,a);return r.year.leaf<=0?.24*t.size:t.size*((e,t,a)=>a>0&&!0===Se(e,t).blossom?1-.55*a:1)(e,l,r.flowering)*o(n.size,a)*(.2+.8*r.year.leaf)*(.45+.55*o(t.frame.grow,l))}function Ge(e,t,a){let r=new Float32Array(t.count).fill(1),l=[];for(let a=0;a<t.count;a+=1)o(e.grow,o(t.node,a))>0&&l.push(a);if(0===l.length)return r;let s=l.reduce((a,r)=>{let n=o(t.node,r);return[a[0]+o(e.x,n)/l.length,a[1]+o(e.y,n)/l.length,a[2]+o(e.z,n)/l.length]},[0,0,0]),i=a=>{let r=(a=>{let r=o(t.node,a);return[o(e.x,r)+o(t.dx,a),o(e.y,r)+o(t.dy,a),o(e.z,r)+o(t.dz,a)]})(a);return Math.hypot(r[0]-s[0],r[2]-s[2],1.3*(r[1]-s[1]))},f=l.map(a=>o(e.y,o(t.node,a))),u=Math.min(...f),d=Math.max(...f),c=Math.max(.001,...l.map(i));for(let l=0;l<t.count;l+=1){let s=n((o(e.y,o(t.node,l))-u)/Math.max(d-u,.5),0,1);r[l]=(.55+.5*n(i(l)/c,0,1)**.8)*(.85+.25*s)*(.9+.2*(a?a(l):o(t.rank,l)))}return r}function $e(e,t,a,r){let l=e.model.leaves,s=o(l.rank,r),i=o(a.dead,o(l.node,r));return e.a.set(t.leaves[o(l.tone,r)%3]??"#ffffff").offsetHSL(.04*(7.3*s%1-.5),0,.1*(3.1*s%1-.5)),i>.05&&e.a.lerp(e.b.set("#6e6a66"),n(3*i,0,.8)),e.a}function Pe(e,t,a,r){let{tone:o,rank:l,turnRank:s}=r,{model:i,a:f,b:u}=e;f.set(a.leaves[o]??"#6c9a54"),t.flush>0&&f.lerp(u.set((!0===a.blossom?a.leaves[2]:a.spring[o])??"#a6ce6f"),.7*t.flush);let d=l<(i.species.evergreen?1.4*i.species.phenology.dropMax:2)?n(1.5*t.color-.5*s,0,1):0;return d>0&&f.lerp(u.set(a.autumn[(o+Math.floor(3*s))%a.autumn.length]??"#cf6b4e"),d),t.withered&&f.set(a.autumn[o]??"#cf6b4e").lerp(u.set("#7d5c3a"),.6),f}function Ve(e,t,a){let{frame:r,snow:l}=t,{model:s,a:i,b:f}=e,u=s.leaves,d=o(u.node,a),c=Ce(e,d),h=Se(e,d),m=Be(e,d,t.year);if(c)return function(e,t,a,r){let{skin:n,colors:l,year:s}=t,i=e.model.leaves,f=o(i.node,r),u=e.features.clumps&&s.leaf>0?Ae(e,f):void 0;if(void 0===u?.species||void 0===u.colors)return $e(e,n,a,r);let d=o(i.rank,r);return e.c.copy(Pe(e,s,l,{tone:Fe(e,f)%3,rank:d,turnRank:d})),$e(e,n,a,r).lerp(e.c,.45)}(e,{skin:c,colors:h,year:m},r,a);if(m.leaf<=0)return i.set(h.trunk[2]??"#9a6946").lerp(f.set(h.leaves[0]??"#6c9a54"),.25);!function(e,t,a,r){let n=e.model.leaves,l=o(n.rank,a);if(!e.features.clumps)return Pe(e,t,r,{tone:o(n.tone,a),rank:l,turnRank:l});let s=Fe(e,o(n.node,a));Pe(e,t,r,{tone:a%11==0?2:s%3,rank:l,turnRank:(s>>>8)%1e3/1e3*.7+.3*l})}(e,m,a,h);let p=o(r.dead,d);return p>.05&&i.lerp(f.set("#8a6b45"),n(4*p,0,1)),l>0&&s.species.evergreen&&o(u.dy,a)>-.02&&i.lerp(f.set("#f2f6fb"),.75*l),i}function He(e,t,a){let{slots:r,index:n,scale:l}=a,s=o(r.node,n),i=(1.4+1.6*o(r.size,n))*l,f=o(t.x,s)+o(r.dx,n)*i+.9*(o(r.rank,n)-.5)*l,u=o(t.z,s)+o(r.dz,n)*i+1.6*(o(r.size,n)-1)*l,d=Math.hypot(f,u),c=e.ground.lip?.(Math.atan2(u,f)),h=void 0===c?e.ground.radius:Math.min(e.ground.radius,c-.3);return d>h&&(f*=h/d,u*=h/d),{x:f,z:u}}function Ke(e,t,a){let{open:r,fallen:n}=xt(e,t);return!(e.look.fall<=0||n<=0||r<=0||!0===a.snowed)&&("fruit"===e.name||n<1||t.leaf<.9)}function je(e,t,a){let r=o(e.slots.node,a);return a<e.slots.count&&o(t.grow,r)>.25&&o(t.dead,r)<.25&&0===o(t.fall,r)}function qe(e,t,a,r){let{frame:n,year:l,motion:s}=a,{fallen:i}=xt(t,l),f=t.look,u=Ke(t,l,s);for(let a=0;a<t.litterLimit;a+=1){let l=a*t.stride,s=t.litterStart+a;if(!u||!je(t,n,l)||o(t.slots.rank,l)>=i||lt(e,t,l)){p(r,s);continue}let d=He(e,n,{slots:t.slots,index:l,scale:"fruit"===t.name?.45:1}),c=e.colors.leafScale*o(t.slots.size,l),h="fruit"===t.name?1:.2;g(r,s,{at:[d.x,e.ground.y+.02+c*f.size[2]*.5*h,d.z],size:[f.size[0]*c,f.size[2]*c*h,f.size[1]*c],yaw:17*o(t.slots.rank,l)})}}function Xe(e,t,a,n){let l=function(e,t,a,r){let{model:n}=e;if("leaf"===r){let r=kt(e),l=n.leaves;return{slots:l,front:a.drop,fall:.8,ok:e=>zt(t,o(l.node,e),r),key:e=>`leaf:${String(e)}`,shape:e=>[o(l.size,e),o(l.size,e),o(l.size,e)],color:t=>{let a=o(l.tone,t);return(e.skin?e.skin.leaves[a%3]:e.colors.autumn[a])??"#cf6b4e"}}}let l="fruit"===r?e.fruits:e.flowers;if(!l)return null;let{open:s,fallen:i}=xt(l,a);return{slots:l.slots,front:i,fall:l.look.fall,ok:a=>o(l.slots.rank,a)<s&&St(e,t,l,o(l.slots.node,a)),key:e=>`${l.name}:${String(e)}`,shape:e=>[l.look.size[0]*o(l.slots.size,e),l.look.size[1]*o(l.slots.size,e),l.look.size[2]*o(l.slots.size,e)],color:t=>`#${gt(e,l,t,a).getHexString()}`}}(e,t,a,n);if(!l)return null;let{slots:s}=l,i=e.random;for(let a=0;a<16&&s.count>0;a+=1){let a=Math.floor(i()*s.count),f=o(s.rank,a),u=l.key(a);if(f<l.front||f>l.front+.08||e.hidden.has(u)||!l.ok(a))continue;let d=o(s.node,a);e.hidden.set(u,{rank:f,kind:n,index:a}),e.hiddenSlots[n].add(a);let[c,h,m]=l.shape(a),p=e.colors.leafScale;return{key:u,kind:n,speed:l.fall,landed:!1,color:l.color(a),x:o(t.x,d)+o(s.dx,a),y:o(t.y,d)+.5*o(s.dy,a),z:o(t.z,d)+o(s.dz,a),vx:.3*(i()-.5),vz:.3*(i()-.5),phase:i()*r,size:[c*p,h*p,m*p]}}return null}function Ze(e,t,a){if("leaf"===a)return t.drop;let r="fruit"===a?e.fruits:e.flowers;return r?xt(r,t).fallen:1}function Je(e,t,a){if(t.landed)return;let{elapsed:r,wind:n}=a,o=a.delta??0,l=a.windDir??0,s=t.speed>1.5?.15:1,i=Math.sin(2.4*r+t.phase),f=.3*Math.cos(1.7*r+t.phase),u=1.4*n+.2*i;t.vx+=((u*Math.cos(l)-f*Math.sin(l))*s-t.vx)*o,t.vz+=((u*Math.sin(l)+f*Math.cos(l))*s-t.vz)*o,t.x+=t.vx*o,t.z+=t.vz*o,t.y-=o*t.speed*(s<1?1:.7+.3*Math.abs(i));let d=e.ground.radius+1,c=Math.hypot(t.x,t.z);c>d&&(t.x*=d/c,t.z*=d/c),t.y<=e.ground.y+.02&&(t.y=e.ground.y+.02,t.landed=!0)}function Qe(e,t){let a=e-t.leaf;return a<0?"leaf":(a-=t.flowers,a<0?"flowers":"fruit")}function et(e,t,a){let{tree:r,elapsed:n}=e,o=r.blades&&"leaf"===t.kind?e.fallingLeaves:e.falling,l=t.landed?t.phase:n*(t.speed>1.5?.6:2.2)+t.phase,[s,i,f]=t.size,u=o.instanceMatrix.array;if(r.blades&&"leaf"===t.kind){let e=t.landed?0:.9*Math.sin(.8*l);S(u,a,{p:[t.x,t.y,t.z],n:[Math.cos(l),e,Math.sin(l)],size:1.9*s},{droop:0,twist:t.landed?.2:1.3*l,nod:0})}else{let e=t.landed&&t.speed<=1.5?.22:1;g(u,a,{at:[t.x,t.y,t.z],size:[s,i*e,f],yaw:l})}o.setColorAt(a,r.a.set(t.color))}function tt(e,t,a,r){return bt(e,r.spray&&r.sprayShape?r.sprayShape:r.shape,a,{roughness:"fruit"===t?.62:.7,shadows:e.features.shadows})}function at(e,t,a){let{shape:r,litterStart:n,litterLimit:o}=a,l=a.spray??null,s="fruit"===t?e.model.species.fruit:e.model.species.flower,i="fruit"===t?e.model.fruit:e.model.blossoms;if(null===s||0===i.count||!e.features[t])return null;let f=yt(e,s,i,null!==l);return{name:t,spec:s,slots:i,litterStart:n,litterLimit:o,strain:-1,...f,look:Q(s,e.model.species.id),mesh:tt(e,t,i.count,{shape:r,sprayShape:l,spray:f.spray}),stride:Math.max(1,Math.ceil(i.count/Math.max(o,1)))}}function rt(e,t,a,r){let n=r.spray??null,o="fruit"===a?t.fruit:t.flower;if(!o||0===o.slots.count||!e.features[a])return null;let l=yt(e,o.spec,o.slots,null!==n);return{name:a,spec:o.spec,slots:o.slots,litterStart:0,litterLimit:0,strain:t.strain,stride:1,...l,look:Q(o.spec,t.species),mesh:tt(e,a,o.slots.count,{shape:r.shape,sprayShape:n,spray:l.spray})}}var nt=(e,t,a)=>t.strain>=0?e.strainYears[t.strain]??a:a;function ot(e,t){return t===e.fruits?"fruit":t===e.flowers?"flowers":`kind${String(e.kinds.indexOf(t))}`}var lt=(e,t,a)=>"fruit"===t.name&&!0===e.eaten.get(ot(e,t))?.has(a),st=e=>[e.fruits,...e.kinds].filter(e=>null!==e&&"fruit"===e.name);function it(e,t,a,r){let{frame:l,year:s}=a,i=o(t.slots.node,r),f=e.colors.leafScale*o(t.slots.size,r)*(.35+.65*n(8*(xt(t,s).open-o(t.slots.rank,r)),0,1));return{x:o(l.x,i)+o(t.slots.dx,r),y:o(l.y,i)+.5*o(t.slots.dy,r)+t.look.lift*f,z:o(l.z,i)+o(t.slots.dz,r),unit:f}}function ft(e,t,a,r){let{frame:n,year:l}=a,{open:s,fallen:i}=xt(t,l),f=o(t.slots.rank,r);return!(f>=s||f<i||e.hiddenSlots[t.name].has(r)||lt(e,t,r)||pt(t,r,l)<.7)&&St(e,n,t,o(t.slots.node,r))}function ut(e,t,a,r){let n=ot(e,t),o=t.spec.kind;for(let l=0;l<t.slots.count;l+=1){if(!ft(e,t,a,l))continue;let s=it(e,t,a,l),i=s.unit*t.look.size[0];r.push({key:`${n}:${String(l)}`,kind:o,x:s.x,y:s.y,z:s.z,size:i,hanging:!0})}}function dt(e,t,a,r){let{frame:n,year:l}=a,{fallen:s}=xt(t,l),i=ot(e,t),f=t.spec.kind;for(let a=0;a<t.litterLimit;a+=1){let l=a*t.stride;if(!je(t,n,l)||o(t.slots.rank,l)>=s||lt(e,t,l))continue;let u=He(e,n,{slots:t.slots,index:l,scale:.45}),d=e.colors.leafScale*o(t.slots.size,l),c=e.ground.y+.02+d*t.look.size[2]*.5;r.push({key:`${i}:${String(l)}`,kind:f,x:u.x,y:c,z:u.z,size:d*t.look.size[0],hanging:!1})}}function ct(e,t,a,r=a.wind){if(e.still)return e.offset.x=0,void(e.offset.z=0);let{motion:n}=a,o={elapsed:n.elapsed,wind:r*(n.field??1),height:a.height,dir:n.windDir};d(e.offset,t,o)}function ht(e,t){let{tree:a,set:l,frame:s,air:i,open:f,grow:u,box:d}=e,{slots:c,look:h}=l,m=o(c.node,t),p=o(c.rank,t),v=a.colors.leafScale*o(c.size,t)*u*(.35+.65*n(8*(f-p),0,1)),y=o(s.x,m)+o(c.dx,t),w=o(s.z,m)+o(c.dz,t),b=o(s.y,m)+.5*o(c.dy,t)+h.lift*v;ct(a,[y,b,w],i);let x=function(e,t,a,r){let n=e<0?.04*t*(.6+Math.sin(2.1*a.elapsed+30*r)):0,o=a.windDir??0;return{x:n*Math.cos(o),z:n*Math.sin(o)}}(h.lift,i.wind,i.motion,p);d.at[0]=y+a.offset.x+x.x,d.at[1]=b,d.at[2]=w+a.offset.z+x.z,d.size[0]=h.size[0]*v,d.size[1]=h.size[1]*v,d.size[2]=h.size[2]*v,d.yaw=p*r,g(e.array,t,d)}function mt(e,t,a){let{frame:r,year:l,motion:s}=a,{slots:i,mesh:f}=t,{open:u,fallen:d}=xt(t,l);if(f.visible=!0!==s.dead&&u>0&&d<1&&r.cycle>=t.spec.from,!f.visible)return;let c=f.instanceMatrix.array,h=Math.max(r.height,.5),m=e.features.sway?s.wind:0,g=function(e,t){let a=e.hiddenSlots[t.name],r="fruit"===t.name?e.eaten.get(ot(e,t)):void 0;return r?e=>a.has(e)||r.has(e):e=>a.has(e)}(e,t),v={tree:e,set:t,frame:r,air:{motion:s,wind:m,height:h},open:u,grow:1+(t.grow-1)*n(r.visible/1500,.2,1),array:c,box:{at:[0,0,0],size:[0,0,0],yaw:0}};for(let a=0;a<i.count;a+=t.thin){let n=o(i.node,a),l=o(i.rank,a);l>=u||l<d||g(a)||!St(e,r,t,n)?p(c,a):ht(v,a)}f.instanceMatrix.needsUpdate=!0}var pt=(e,t,a)=>void 0===e.look.green?1:n(1.8*a.fruit-.7-.3*o(e.slots.rank,t),0,1);function gt(e,t,a,r){let{a:l,b:i}=e,f=o(t.slots.node,a),u=Se(e,f),d=Ce(e,f),c=o(t.slots.tone,a),h=o(t.slots.rank,a);if("blossom"===t.spec.kind){let a=n(3*(r.petals-h+.25),0,1),d=function(e,t,a,r){if(0===e.blooms.length)return a.spring;let n=e.blooms.reduce((e,t)=>e+t.share,0),l=r,{parent:i,order:f}=e.model;if(i&&f)for(let e=o(i,l);e>=0&&o(f,e)>0;e=o(i,l))l=e;let u=s(2246822519*l+7)%1e4/1e4*n;for(let t of e.blooms)if((u-=t.share)<0)return t.colors;return e.blooms[e.blooms.length-1]?.colors??a.spring}(e,0,u,f),m=t.spray?Fe(e,f)%d.length:c%d.length;l.set(d[m]??"#f6bacb"),t.spray&&l.offsetHSL(0,.16,-.06),l.lerp(i.set("#fff4f6"),.6*a)}else{let e=t.look.colors??["#ffffff"];l.set(e[c%e.length]??"#ffffff"),void 0!==t.look.green&&l.lerp(i.set(t.look.green),1-pt(t,a,r))}let m="fruit"===t.name&&e.features.clumps?.2:.82;return d&&l.lerp(i.set(d.leaves[(a+1)%d.leaves.length]??"#ffffff"),m),l}function vt(e,t,a){for(let r=0;r<t.slots.count;r+=t.thin)t.mesh.setColorAt(r,gt(e,t,r,a));t.mesh.instanceColor&&(t.mesh.instanceColor.needsUpdate=!0)}function yt(e,t,a,r){let n=e.features.sprays&&e.smooth&&r&&"blossom"===t.kind;return n?a.count>900?{spray:n,thin:2,grow:2}:{spray:n,thin:1,grow:1.5}:{spray:n,thin:1,grow:1}}var wt={litter:1800,flowerLitter:600,fruitLitter:320,falling:64};function bt(e,t,a,r){let n=e.lit,{roughness:o,shadows:l}=r,s=!!t.attributes.color,i=!0===r.sheet?"both":"front",f=new n.LitMaterial({color:"#ffffff",roughness:o,side:i,vertexColors:s}),u=new n.Instances(t,f,Math.max(1,a));u.instanceMatrix.setUsage("dynamic"),u.setColorAt(0,new n.Color("#ffffff")),u.count=a;for(let e=0;e<Math.max(1,a);e+=1)p(u.instanceMatrix.array,e);return u.castShadow=l,u.receiveShadow=!0,u.frustumCulled=!1,e.group.add(u),u}var xt=(e,t)=>"fruit"===e.name?{open:t.fruit,fallen:t.fruitDrop}:{open:t.bloom,fallen:t.petals};function Mt(e,t){return e?40:t?7:2.6}var kt=e=>Mt(e.needles,e.model.species.evergreen);function zt(e,t,a){return o(e.grow,t)>.25&&o(e.dead,t)<.25&&0===o(e.fall,t)&&o(e.tips,t)<=a}function St(e,t,a,r){let{spec:n}=a;return!(t.cycle<n.from||o(t.fall,r)>0||o(t.dead,r)>=.2||!function(e,t){return!(e.strainOf&&!1===e.strains[o(e.strainOf,t)]?.bears)}(e,r)&&a.strain<0)&&("tip"===n.on?zt(t,r,e.model.species.evergreen?7:2.6):o(t.grow,r)>=1&&o(t.tips,r)<=9&&t.cycle-o(e.model.birth,r)>.5)}var At=e=>e.flowers||e.fruit;function Lt(e,t,a){let r=bt(e,t,e.model.count+e.model.roots.length*ee,{roughness:.86,shadows:e.features.shadows});return e.smooth&&e.features.bark&&(r.material.dispose(),r.material=j(e.lit,a,e.features.rootSink,e.features.rootBreak)),r}var Ct=(e,t)=>e?t():null;function Ft(e,t){let{model:a,features:r,limits:n}=e,o=t.blade,l=r.shadows,s=n.litter+n.flowerLitter+n.fruitLitter;return{leafLitter:Ct(r.litter&&r.leaves,()=>bt(e,o,n.litter,{roughness:.92,shadows:!1,sheet:e.smooth})),litter:Ct(r.litter&&At(r),()=>bt(e,t.leaf,s,{roughness:.92,shadows:!1})),snow:Ct(r.snow,()=>bt(e,t.leaf,a.count,{roughness:.55,shadows:!1})),falling:Ct(r.fallers,()=>bt(e,t.leaf,n.falling,{roughness:.78,shadows:l})),fallingLeaves:Ct(r.fallers,()=>bt(e,o,n.falling,{roughness:.78,shadows:l,sheet:e.smooth}))}}function Bt(e,t){let{features:a,model:r}=e;return!!(a.rootBreak&&a.roots&&e.smooth)&&void 0!==t.ground?.lip&&!r.species.palm}function Ot(e,t){let{model:a,smooth:r}=e;return{blades:r,needles:r&&!t.shapes?.blade&&void 0!==E[a.species.id],fronds:r&&!t.shapes?.blade?Ie(a):null}}function Rt(e,t,r){let l=a(r.features??{}),s={...wt,...r.limits},f="voxel"!==r.form,u=new e.Group,c={lit:e,group:u,model:t,features:l,limits:s,smooth:f},{meshes:h,flowers:m,fruits:g,kinds:b}=function(e,t){let{model:a,features:r}=e,n=function(e,t){let a=K(e.lit),r=t.shapes??{};if(!e.smooth){let e=r.leaf??a.box;return{wood:a.box,leaf:e,blade:e,bud:a.box}}let n=V(e.lit,e.model.species.id);return{wood:a.wood,leaf:a.leaf,blade:e.features.clumps&&n===a.blade?a.softBlade:n,bud:a.bud,...r}}(e,t),o=r.shadows,l={wood:Lt(e,n.wood,t.ground?.y??0),leaves:Ct(r.leaves,()=>bt(e,n.blade,a.leaves.count,{roughness:.78,shadows:o,sheet:e.smooth})),flowers:null,fruit:null,...Ft(e,n),shards:Ct(Bt(e,t),()=>bt(e,K(e.lit).box,8*a.roots.length,{roughness:.95,shadows:o}))};l.snow?.material.color.set("#f4f8ff");let{flowers:s,fruits:i,kinds:f}=function(e,t,a){let{limits:r}=e,n=((e,t)=>e.smooth&&!t.shapes?.leaf?K(e.lit).spray:null)(e,t),o=e.smooth?a.leaf:a.wood,l=e.smooth?a.bud:a.wood,s=at(e,"flowers",{shape:o,spray:n,litterStart:r.litter,litterLimit:r.flowerLitter});return!0===s?.spray&&function(e,t){let a=e.material;a.emissive&&(a.emissive.set(t.spring[0]??"#f6bacb"),a.emissiveIntensity=.16)}(s.mesh,t.colors),{flowers:s,fruits:at(e,"fruit",{shape:l,litterStart:r.litter+r.flowerLitter,litterLimit:r.fruitLitter}),kinds:(t.kinds??[]).flatMap(t=>[rt(e,t,"flowers",{shape:o,spray:n}),rt(e,t,"fruit",{shape:l})]).filter(e=>null!==e)}}(e,t,n);return{meshes:{...l,flowers:s?.mesh??null,fruit:i?.mesh??null},flowers:s,fruits:i,kinds:f}}(c,r),x=function(e,t){return{ground:t.ground??{y:0,radius:4.4},...Ot(e,t),skin:t.skin??null,strains:t.strains??[],strainOf:t.strainOf??null,blooms:(t.blooms??[]).filter(e=>e.share>0&&e.colors.length>0),seed:t.seed??1}}(c,r),M={lit:e,model:t,colors:r.colors,features:l,smooth:f,group:u,meshes:h,flowers:m,fruits:g,kinds:b,limits:s,...x,strainYears:[],leafStride:Math.max(1,Math.ceil(t.leaves.count/s.litter)),hidden:new Map,hiddenSlots:{leaf:new Set,flowers:new Set,fruit:new Set},eaten:new Map,lastYear:null,lastMotion:null,fallers:[],random:i(20983^x.seed),a:new e.Color,b:new e.Color,c:new e.Color,offset:{x:0,z:0},spawnClock:0,paintKey:"",lastFrame:null,still:!1,breaks:{trunk:-1,plans:[]}};return{group:u,features:l,meshes:h,fallers:M.fallers,kinds:b.map(e=>e.mesh),update:(e,t,a)=>{!function(e,t){let{frame:a,year:r,motion:l}=t;e.strainYears=l.strainYears??[],e.lastYear=r,e.lastMotion=l,e.still=0===l.field,function(e,t){for(let a of st(e))xt(a,nt(e,a,t)).open<=0&&e.eaten.delete(ot(e,a))}(e,r);let s=[r,...e.strainYears.filter(e=>void 0!==e)].map(e=>function(e,t){let a=[e.leaf,e.color,e.flush,e.drop,e.petals,e.fruit,t.snow??0],r=(e.withered?":withered":"")+(!0===t.dead?":dead":"");return a.map(e=>Math.round(60*e)).join(":")+r}(e,l)).join("|");(a!==e.lastFrame||s!==e.paintKey)&&(function(e,t){let{frame:a,year:r,motion:l}=t;(function(e,t,a){let{model:r,meshes:n,a:l,b:s,colors:i}=e,f=r.count+r.roots.length*ee;for(let u=0;u<f;u+=1)l.set(Re(e,t,u)),u<r.count&&((o(t.grow,u)<1||t.cycle-o(r.birth,u)<1)&&!a&&l.lerp(s.set(Se(e,u).leaves[0]??i.leaves[0]??"#6c9a54"),.45),l.lerp(s.set("#8e897f"),.85*o(t.dead,u)),o(t.fall,u)>0&&l.lerp(s.set("#4a3b2f"),.55+.35*o(t.rot,u))),a&&l.lerp(s.set("#8e897f"),.7),n.wood.setColorAt(u,l);n.wood.instanceColor&&(n.wood.instanceColor.needsUpdate=!0)})(e,a,!0===l.dead),e.meshes.leaves&&function(e,t,a){let{frame:r,year:n}=a,l={frame:r,year:n,snow:a.motion.snow??0},s=e.model.leaves,i=e.features.clumps?t=>Fe(e,o(s.node,t))%1e3/1e3:void 0,f=e.smooth&&e.features.crownShade&&(!e.skin||e.strains.length>1)?Ge(r,s,i):null;for(let a=0;a<s.count;a+=1){let r=Ve(e,l,a);f&&n.leaf>0&&!Ce(e,o(s.node,a))&&r.multiplyScalar(o(f,a)),t.setColorAt(a,r)}t.instanceColor&&(t.instanceColor.needsUpdate=!0)}(e,e.meshes.leaves,t);for(let t of[e.flowers,e.fruits])t&&vt(e,t,r);for(let t of e.kinds)vt(e,t,nt(e,t,r));!function(e,t){let{model:a,meshes:r,a:l,b:s,colors:i,leafStride:f}=e,u=r.leafLitter;if(u){for(let r=0;r<e.limits.litter;r+=1){let d=Math.min(r*f,Math.max(a.leaves.count-1,0)),c=o(a.leaves.tone,d),h=t.drop<=0?1:n(2*(t.drop-o(a.leaves.rank,d)),0,1);e.skin?l.set(e.skin.leaves[c%3]??"#ffffff").multiplyScalar(.85):l.set(i.autumn[c]??"#cf6b4e").lerp(s.set("#7a5a3c"),.25+.5*h),u.setColorAt(r,l)}u.instanceColor&&(u.instanceColor.needsUpdate=!0)}r.litter&&function(e,t){let{a,b:r,colors:n}=e;for(let o of[e.flowers,e.fruits]){if(!o)continue;let l=o.look.colors??n.spring;for(let s=0;s<o.litterLimit;s+=1)"blossom"===o.spec.kind?a.set(n.spring[s%n.spring.length]??"#f6bacb"):a.set(l[s%l.length]??"#ffffff").lerp(r.set("#6b5038"),"fruit"===o.name?.15:.35),e.skin&&a.lerp(r.set(e.skin.leaves[(s+1)%e.skin.leaves.length]??"#ffffff"),.82).multiplyScalar(.85),t.setColorAt(o.litterStart+s,a)}t.instanceColor&&(t.instanceColor.needsUpdate=!0)}(e,r.litter)}(e,r)}(e,t),e.paintKey=s,e.lastFrame=a);let{meshes:i}=e;(function(e,t,a){let{model:r,meshes:n,offset:l}=e,s=n.wood.instanceMatrix.array,i=Math.max(t.height,.5),f=e.features.sway?a.wind*(a.field??1):0,u={x:0,z:0},c={elapsed:a.elapsed,wind:f,height:i,dir:a.windDir};for(let a=0;a<r.count;a+=1){let r=o(t.fall,a)>0;if(o(t.grow,a)<=0||o(t.rot,a)>=1||r&&!e.features.deadwood){p(s,a);continue}let n=o(t.radius,a)*(1-.7*o(t.rot,a)),i=[o(t.baseX,a),o(t.baseY,a),o(t.baseZ,a)],f=[o(t.x,a),o(t.y,a),o(t.z,a)];!r&&!e.still&&(d(l,i,c),d(u,f,c),i[0]+=l.x,i[2]+=l.z,f[0]+=u.x,f[2]+=u.z),w(s,a,{a:i,b:f,radius:n})}(function(e,t,a){let{model:r}=e,n=o(t.radius,0),l=function(e,t){let{model:a}=e;return e.features.rootBreak&&e.features.roots&&e.smooth&&!a.species.palm?(e.breaks.trunk!==t&&(e.breaks.trunk=t,e.breaks.plans=le(a.roots,t,e.ground,e.seed),function(e,t){let a=e.meshes.shards;if(!a)return;let r=a.instanceMatrix.array,n=e.ground.planter?.colors,o=n&&n.length>0?n:be;for(let[n,l]of e.model.roots.entries()){let s=ve(l,n,{trunk:t,ground:e.ground,plan:e.breaks.plans[n]??te,seed:e.seed});for(let t=0;t<8;t+=1){let l=s[t],i=8*n+t;l?(Me(r,i,l),e.a.set(xe(o,l)),a.setColorAt(i,3===l.tone?e.a.multiplyScalar(.28):e.a)):p(r,i)}}a.instanceMatrix.needsUpdate=!0,a.instanceColor&&(a.instanceColor.needsUpdate=!0)}(e,t)),e.breaks.plans):[]}(e,n);for(let[t,o]of r.roots.entries()){let s=r.count+t*ee;for(let e=0;e<ee;e+=1)p(a,s+e);if(!e.features.roots||n<.06)continue;let i={first:s,root:o,trunk:n};e.smooth?we(e,a,i,l[t]??te):ye(e,a,i)}})(e,t,s),n.wood.instanceMatrix.needsUpdate=!0})(e,a,l),i.leaves&&function(e,t,a){let{year:r,motion:l}=a,{model:s}=e,i=s.leaves;if(!0===l.dead){for(let e=0;e<i.count;e+=1)p(t.instanceMatrix.array,e);return void(t.instanceMatrix.needsUpdate=!0)}let f=function(e,t,a){let{frame:r,year:n,motion:o}=a,l=n.leaf<=0,s=Math.max(1,r.scale??1)**.75,i=Math.max(r.height,.5),f=e.features.sway?o.wind:0,u=o.windDir??0,d=e.features.sway?o.wind*(o.field??1):0;return{array:t.instanceMatrix.array,frame:r,height:i,bare:l,size:e.colors.leafScale*Ne(e,r)*(e.skin?.leafSize??1)*s,spread:(l?.15:.35+.65*n.leaf)*s,wind:f,dir:u,elapsed:o.elapsed,field:d,gust:{elapsed:o.elapsed,wind:d,height:i,dir:u},air:{elapsed:o.elapsed,wind:f},seedling:r.visible<=4,tipLimit:kt(e),leaf:{size:0,swing:0}}}(e,t,a),u=((e,t)=>e.features.sprays&&!0===e.flowers?.spray?n(1.6*t.bloom,0,1)*(1-n(1.2*t.petals,0,1)):0)(e,r);for(let t=0;t<i.count;t+=1){let a=o(i.node,t),n=Be(e,a,r),l=n.leaf<=0;!We(e,f,n,t)||l&&t%4!=0?p(f.array,t):(f.leaf.size=Ee(e,f,t,{year:n,flowering:u}),f.leaf.swing=Math.max(0,-o(i.dy,t))*f.wind*.35*Math.sin(1.4*f.elapsed+o(s.phase,a)),e.blades?Ue(e,f,t):Ye(e,f,t))}t.instanceMatrix.needsUpdate=!0}(e,i.leaves,t);for(let a of[e.flowers,e.fruits])a&&mt(e,a,t);for(let a of e.kinds)mt(e,a,{...t,year:nt(e,a,r)});(function(e,t){let{leafLitter:a,litter:r}=e.meshes;if(a&&function(e,t,a){let{frame:r,year:n,motion:l}=a,{model:s,leafStride:i,ground:f}=e,u=t.instanceMatrix.array,d=kt(e),c=r.visible<=4;for(let t=0;t<e.limits.litter;t+=1){let a=t*i,h=o(s.leaves.node,a);if(!(a<s.leaves.count&&!0!==l.dead&&o(r.grow,h)>0&&(c||zt(r,h,d)))||!0===l.snowed||o(s.leaves.rank,a)>=n.litter){p(u,t);continue}let m=He(e,r,{slots:s.leaves,index:a,scale:1}),g=31*o(s.leaves.rank,a),v=f.y+.015+t%3*.006,w=e.colors.leafScale*o(s.leaves.size,a);e.blades?S(u,t,{p:[m.x,v,m.z],n:[Math.cos(g),0,Math.sin(g)],size:1.9*w},{droop:0,twist:.25*Math.sin(3*g),nod:0}):y(u,t,[m.x,v,m.z],{size:w,yaw:g,flat:.22})}t.instanceMatrix.needsUpdate=!0}(e,a,t),!r)return;let n=r.instanceMatrix.array;for(let a of[e.flowers,e.fruits])a&&qe(e,a,t,n);r.instanceMatrix.needsUpdate=!0})(e,t),i.snow&&function(e,t,a,r){let n=r.snow??0;if(t.visible=n>0,!t.visible)return;let l=t.instanceMatrix.array,s=Math.max(a.height,.5),i=e.features.sway?r.wind:0,f={motion:r,wind:i,height:s};for(let t=0;t<e.model.count;t+=1){let r=o(a.radius,t),s=o(a.x,t)-o(a.baseX,t),u=o(a.y,t)-o(a.baseY,t),d=o(a.z,t)-o(a.baseZ,t),c=Math.hypot(s,d);if(o(a.grow,t)<1||r<.035||o(a.rot,t)>.5||c<.7*Math.abs(u)){p(l,t);continue}let h=(.03+.35*r)*n,m=(o(a.x,t)+o(a.baseX,t))/2,g=(o(a.y,t)+o(a.baseY,t))/2,y=(o(a.z,t)+o(a.baseZ,t))/2;ct(e,[m,g,y],f,o(a.fall,t)>0?0:i),v(l,t,{at:[m+e.offset.x,g,y+e.offset.z],along:[s,u,d],radius:r},{width:2.1*r,depth:h,long:Math.hypot(c,u)+r})}t.instanceMatrix.needsUpdate=!0}(e,i.snow,a,l),i.falling&&i.fallingLeaves&&(function(e,t,a,r){let n=function(e,t,a){if(a)return{leaf:0,flowers:0,fruit:0};let r=e.model.species.phenology.dropMax,n=(e,a)=>{if(!e||e.look.fall<=0)return 0;let{open:r,fallen:n}=xt(e,t);return n>.005&&n<.995&&r>.5?a:0};return{leaf:t.drop>.005&&t.drop<r-.005&&e.features.leaves?3.2:0,flowers:n(e.flowers,4),fruit:n(e.fruits,1.2)}}(e,a,!0===r.dead),o=n.leaf+n.flowers+n.fruit;for(e.spawnClock+=(r.delta??0)*o*(1+2*r.wind);e.spawnClock>=1&&o>0;){e.spawnClock-=1;let r=Qe(e.random()*o,n),l=Xe(e,t,a,r);null!==l&&(e.fallers.length>=e.limits.falling&&e.fallers.shift(),e.fallers.push(l))}for(let[t,r]of e.hidden)r.rank>=Ze(e,a,r.kind)||(e.hidden.delete(t),e.hiddenSlots[r.kind].delete(r.index))}(e,a,r,l),function(e,t,a,r){let n=t.instanceMatrix.array,o=a.instanceMatrix.array,l={tree:e,falling:t,fallingLeaves:a,elapsed:r.elapsed};for(let t=0;t<e.limits.falling;t+=1){let a=e.fallers[t];p(n,t),p(o,t),void 0!==a&&(Je(e,a,r),et(l,a,t))}for(let e of[t,a])e.instanceMatrix.needsUpdate=!0,e.instanceColor&&(e.instanceColor.needsUpdate=!0)}(e,i.falling,i.fallingLeaves,l))}(M,{frame:e,year:t,motion:a})},fruit:()=>function(e){let t=e.lastFrame,a=e.lastYear,r=e.lastMotion;if(!t||!a||!r||!0===r.dead)return[];let n=[];for(let o of st(e)){let l=nt(e,o,a),{open:s}=xt(o,l);s<=0||t.cycle<o.spec.from||(ut(e,o,{frame:t,year:l},n),o===e.fruits&&e.meshes.litter&&Ke(o,l,r)&&dt(e,o,{frame:t,year:l},n))}return n}(M),eat:e=>function(e,t){let a=t.lastIndexOf(":"),r=t.slice(0,a),n=Number(t.slice(a+1)),o=st(e).find(t=>ot(e,t)===r);if(!o||!Number.isInteger(n)||n<0||n>=o.slots.count)return!1;let l=e.eaten.get(r)??new Set;return!l.has(n)&&(l.add(n),e.eaten.set(r,l),!0)}(M,e),repaint:()=>{M.paintKey=""},dispose:()=>{for(let e of[...Object.values(h),...b.map(e=>e.mesh)])e&&(e.material.dispose(),e.dispose())}}}var Dt=e=>{let t=e.index?e.toNonIndexed():e;return{position:t.attributes.position?.array??new Float32Array,normal:t.attributes.normal?.array??new Float32Array,color:t.attributes.color?.array??null}},Tt=e=>Math.max(e[0]*e[0]+e[1]*e[1]+e[2]*e[2],1e-12);function Ut(e,t,a,r){let[n,l,s]=(e=>[[o(e,0),o(e,1),o(e,2)],[o(e,4),o(e,5),o(e,6)],[o(e,8),o(e,9),o(e,10)]])(a),i=1/Tt(n),f=1/Tt(l),u=1/Tt(s),d=o(a,12),c=o(a,13),h=o(a,14),{position:m,normal:p,color:g}=t,{positions:v,normals:y,colors:w,leaf:b,stalk:x,wind:M}=e,{rgb:k}=r;for(let e=0;e<m.length;e+=3){let t=o(m,e+1),a=t>0?r.taper??1:1,z=o(m,e)*a,S=o(m,e+2)*a,A=o(p,e)*i,L=o(p,e+1)*f,C=o(p,e+2)*u;v.push(d+n[0]*z+l[0]*t+s[0]*S,c+n[1]*z+l[1]*t+s[1]*S,h+n[2]*z+l[2]*t+s[2]*S),y.push(n[0]*A+l[0]*L+s[0]*C,n[1]*A+l[1]*L+s[1]*C,n[2]*A+l[2]*L+s[2]*C);let F=g?o(g,e):1;w.push(k[0]*F,k[1]*F,k[2]*F),b.push(r.leaf[0],r.leaf[1]),x.push(r.stalk[0],r.stalk[1],r.stalk[2]),M.push(r.wind)}}function It(e,t,a){return!(o(e.grow,t)<.5||o(e.fall,t)>0||o(e.rot,t)>.5||o(e.radius,t)<a)}function _t(e,t,a,n){let l=e.variant.model.leaves,{stalk:s,d:i,rank:f,s:u}=a,d=f*r+2.4*n,c=.1+.05*n,h=[s[0]+Math.cos(d)*c,s[1]+Math.sin(1.7*d)*c*.6,s[2]+Math.sin(d)*c];S(e.m,0,{p:h,n:x(i[0]+.5*Math.cos(d),i[1],i[2]+.5*Math.sin(d)),size:e.size*o(l.size,t)*.82},e.needles?{droop:.04,twist:d,nod:0}:{droop:.3+.3*f,twist:.25*d,nod:0}),Ut(e.bake,e.template,e.m,{rgb:[u,u,u],leaf:[Math.min(1,f+.04*n),o(l.tone,t)%3],stalk:h,wind:(h[1]/e.height)**2})}function Yt(e,t){let{frame:a,model:n}=e.variant,l=n.leaves,{needles:s}=e,i=o(l.rank,t),{stalk:f,d:u}=function(e,t,a,r){if(r){let{p:r,n}=_e(e,t,a);return{stalk:r,d:n}}let n=o(t.node,a),l=x(o(t.dx,a),o(t.dy,a),o(t.dz,a)),s=Math.min(.3*Math.hypot(o(t.dx,a),o(t.dy,a),o(t.dz,a)),.22);return{stalk:[o(e.x,n)+l[0]*s,o(e.y,n)+l[1]*s,o(e.z,n)+l[2]*s],d:l}}(a,l,t,s),d=s?{droop:.04,twist:i*r,nod:0}:{droop:.35+.25*i,twist:i*r*.25,nod:0};S(e.m,0,{p:f,n:u,size:e.size*o(l.size,t)},d);let c=o(e.shade,t);Ut(e.bake,e.template,e.m,{rgb:[c,c,c],leaf:[i,o(l.tone,t)%3],stalk:f,wind:(f[1]/e.height)**2});for(let a=1;1===e.stride&&!s&&a<e.fill;a+=1)_t(e,t,{stalk:f,d:u,rank:i,s:c},a)}function Wt(e,t){let{m:a,cell:r}=e,n=t.x/t.n,o=t.y/t.n,l=t.z/t.n,s=r*Math.min(.5,.2+.05*Math.sqrt(t.n));a.fill(0),a[0]=s,a[5]=.8*s,a[10]=s,a[12]=n,a[13]=o,a[14]=l,a[15]=1;let i=t.shade/t.n*.7;Ut(e.bake,e.template,a,{rgb:[i,i,i],leaf:[t.rank/t.n,t.tone],stalk:[n,o,l],wind:(o/e.height)**2})}function Nt(e){let t=e.attributes.position?.array??new Float32Array,a=.5,r=1,n=0;for(let e=0;e<t.length;e+=3)a=Math.max(a,Math.abs(o(t,e)),Math.abs(o(t,e+2))),r=Math.max(r,o(t,e+1)),n=Math.min(n,o(t,e+1));return{half:1.05*a,height:1.04*(r-n),base:n}}var Et=(e,t)=>{let a=new e.Color(t??"#ffffff");return new e.Vector3(a.r,a.g,a.b)};function Gt(e,t,a){let r=new e.LitMaterial({color:"#ffffff",vertexColors:!0,roughness:.85,metalness:0,side:"both"});return r.onCompile=e=>{Object.assign(e.uniforms,t),e.vertexShader="\nattribute vec2 aLeaf;\nattribute vec3 aStalk;\nattribute float aWind;\nuniform float uTime, uWind;\nuniform vec4 uYear;\nuniform vec4 uYear2;\nuniform vec3 uLeafCol[3];\nuniform vec3 uSpring[3];\nuniform vec3 uAutumn[3];\nuniform vec3 uBloom;\nvarying vec3 vSeason;\nvarying float vViewDepth;\nvarying float vLodDistance;\nvec3 pick3(vec3 a[3], float i) { return i < 0.5 ? a[0] : i < 1.5 ? a[1] : a[2]; }\n"+e.vertexShader.replace("#include <begin_vertex>","#include <begin_vertex>\n vSeason = vec3(1.0);\n if (aLeaf.x >= 0.0) {\n float keep = aLeaf.x >= uYear.w ? 1.0 : 0.0;\n // A blossom tree in bloom shows its crown before the leaves are out.\n float grow = max(uYear.x <= 0.0 ? 0.0 : 0.2 + 0.8 * uYear.x, uYear2.y > 0.01 ? 0.75 : 0.0);\n transformed = aStalk + (transformed - aStalk) * keep * grow;\n vec3 base = pick3(uLeafCol, aLeaf.y);\n base = mix(base, pick3(uSpring, aLeaf.y), uYear.z * 0.7);\n float turn = clamp(uYear.y * 1.5 - aLeaf.x * 0.5, 0.0, 1.0) * step(aLeaf.x, uYear2.z);\n base = mix(base, pick3(uAutumn, aLeaf.y), turn);\n if (uYear2.x > 0.5) base = mix(pick3(uAutumn, aLeaf.y), vec3(0.49, 0.36, 0.23), 0.6);\n vSeason = mix(base, uBloom, uYear2.y);\n }\n#ifdef USE_INSTANCING\n vec3 forestOrigin = (instanceMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz;\n#else\n vec3 forestOrigin = vec3(0.0);\n#endif\n float forestSway = aWind * (uWind * 0.5 + 0.06) * sin(uTime * 1.2 + forestOrigin.x * 0.37 + forestOrigin.z * 0.21);\n transformed.x += forestSway;\n transformed.z += forestSway * 0.5;\n vLodDistance = distance(cameraPosition, (modelMatrix * vec4(forestOrigin, 1.0)).xyz);").replace("#include <project_vertex>","#include <project_vertex>\n vViewDepth = -mvPosition.z;"),e.fragmentShader="\nuniform vec4 uLod;\nvarying vec3 vSeason;\nvarying float vViewDepth;\nvarying float vLodDistance;\nuniform vec2 uLodIn;\n// Whole pixels the dither is moved by this frame: 0 holds it still (the pixel look); a temporal resolve (lit-finish's\n// TAA) moves it each frame so a fade averages to real cover instead of a stipple.\nuniform vec2 uDither;\nfloat forestBayer(vec2 p) {\n vec2 q = mod(floor(p + uDither), 4.0);\n float m = mod(q.x + q.y * 4.0, 16.0);\n return fract(m * 0.4375 + floor(m * 0.25) * 0.3125);\n}\n"+e.fragmentShader.replace("void main() {","void main() {"+(a?"":"\n float forestT = forestBayer(gl_FragCoord.xy);\n if (smoothstep(uLod.x + uLod.y, uLod.x - uLod.y, vLodDistance) <= forestT) discard;\n if (uLodIn.x > 0.0 && smoothstep(uLodIn.x + uLodIn.y, uLodIn.x - uLodIn.y, vLodDistance) > forestT) discard;\n if (smoothstep(uLod.z, uLod.w, vViewDepth) < forestT) discard;")).replace("#include <color_fragment>","#include <color_fragment>\n diffuseColor.rgb *= vSeason;")},r.customProgramCacheKey=()=>"keel-forest"+(a?"-bake":""),r.userData.voxelDitherKeep=!0,r}var $t=`\n#define MAXV ${String(8)}\nattribute vec2 aCard;\nuniform vec3 uBox[MAXV];\nuniform float uFrames, uRows;\nvarying vec2 vCardUv;\nvarying float vTint, vLodDistance, vViewDepth, vFogDepth;\nvoid main() {\n vec3 origin = (modelMatrix * instanceMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz;\n float scale = length(instanceMatrix[0].xyz);\n float yaw = atan(-instanceMatrix[0].z, instanceMatrix[0].x);\n vec3 box = uBox[int(aCard.x + 0.5)];\n vec3 toCamera = cameraPosition - origin;\n vec3 dir = normalize(vec3(toCamera.x, 0.0, toCamera.z) + vec3(1e-5, 0.0, 0.0));\n vec3 right = vec3(dir.z, 0.0, -dir.x);\n // Pick the baked view nearest the camera's angle round this tree.\n float view = atan(dir.x, dir.z) - yaw;\n float frame = mod(floor(view / 6.2831853 * uFrames + 0.5), uFrames);\n vec3 world = origin + right * position.x * box.x * 2.0 * scale + vec3(0.0, ((position.y + 0.5) * box.y + box.z) * scale, 0.0);\n vCardUv = vec2((frame + position.x + 0.5) / uFrames, (aCard.x + position.y + 0.5) / uRows);\n vTint = aCard.y;\n vLodDistance = length(toCamera);\n vec4 mv = viewMatrix * vec4(world, 1.0);\n vViewDepth = -mv.z;\n vFogDepth = -mv.z;\n gl_Position = projectionMatrix * mv;\n}`;function Pt(e){let t=i(986711^e.seed),a=e.gap??2.2,[n,o]=e.scale??[.9,1.5],l=e.clump??.6,s=t()*r,f=[];for(let i=0;i<30*e.count&&f.length<e.count;i+=1){let i=t()*r,u=Math.sqrt(e.inner**2+t()*(e.outer**2-e.inner**2)),d=Math.cos(i)*u,c=Math.sin(i)*u,h=.5+.5*Math.sin(3*i+s)*Math.cos(.21*u+.7*s);if(t()<l*(1-h))continue;let m=e.height(d,c);null===m||f.some(e=>Math.hypot(e.x-d,e.z-c)<a)||f.push({x:d,y:m,z:c,yaw:t()*r,scale:n+t()*(o-n),variant:Math.floor(t()*e.variants),tint:.82+.3*t()})}return f}var Vt=new WeakMap;function Ht(e,t,a){let r=Vt.get(t.frame)??new Map;Vt.set(t.frame,r);let n=`${JSON.stringify(a)}|${t.colors.trunk.join()}|${String(t.colors.leafScale)}`,l=r.get(n);if(!l){let s=function(e,t,a){let r={positions:[],normals:[],colors:[],leaf:[],stalk:[],wind:[]};(function(e,t,a,r){let{model:n,frame:l,colors:s}=a,i=Dt(e.cylinder(.5,.5,1,r.sides,1)),f=new Float32Array(16),u=new e.Color,d=Math.max(l.height,1),c=function(e,t){let a=new Float32Array(e.count);if(!e.parent)return a;for(let r=0;r<e.count;r+=1){let n=o(e.parent,r);n>=0&&o(t.grow,r)>=.5&&(a[n]=Math.max(o(a,n),o(t.radius,r)))}return a}(n,l);for(let a=0;a<n.count;a+=1){let h=o(l.radius,a);It(l,a,r.wood)&&(w(f,0,{a:[o(l.baseX,a),o(l.baseY,a),o(l.baseZ,a)],b:[o(l.x,a),o(l.y,a),o(l.z,a)],radius:h}),u.set(Oe(s.trunk,h)??"#6b4a33"),o(l.dead,a)>.3&&u.lerp(new e.Color("#8e897f"),.6),Ut(t,i,f,{rgb:[u.r,u.g,u.b],leaf:[-1,0],stalk:[0,0,0],wind:(o(l.y,a)/d)**2,taper:n.parent?Math.min(1,Math.max(o(c,a),.0225)/Math.max(h,.0225)):1}))}})(e,r,t,a),a.clumps>0&&void 0===E[t.model.species.id]&&function(e,t,a,r){let n=Math.max(a.frame.height,1),l=Math.max(n/r,.5),s=function(e,t){let{model:a,frame:r}=e,n=a.leaves,l=void 0!==E[a.species.id],s=Ge(r,n),i=Mt(l,a.species.evergreen),f=new Map;for(let e=0;e<n.count;e+=1){let a=o(n.node,e);if(!zt(r,a,i))continue;let l=o(r.x,a),u=o(r.y,a),d=o(r.z,a),c=`${String(Math.floor(l/t))},${String(Math.floor(u/t))},${String(Math.floor(d/t))}`,h=f.get(c)??{x:0,y:0,z:0,n:0,rank:0,shade:0,tone:o(n.tone,e)%3,reach:0};h.x+=l,h.y+=u,h.z+=d,h.n+=1,h.rank+=o(n.rank,e),h.shade+=o(s,e),f.set(c,h)}return f}(a,l),i=Dt(e.icosahedron(1,1)),f={bake:t,template:{...i,normal:i.position},m:new Float32Array(16),cell:l,height:n};for(let e of s.values())Wt(f,e)}(e,r,t,a.clumps),function(e,t,a,r){let{model:n,frame:l,colors:s}=a,i=n.leaves,f=Math.max(1,Math.ceil(i.count/r.leaves)),u=void 0!==E[n.species.id],d=u?I(e,n.species.id,r.needles):V(e,n.species.id),c={bake:t,template:Dt(d),variant:a,shade:Ge(l,i),m:new Float32Array(16),height:Math.max(l.height,1),size:1.9*s.leafScale*Math.sqrt(f)*(r.leafSize??1),needles:u,fill:r.fill,stride:f},h=Mt(u,n.species.evergreen);for(let e=0;e<i.count;e+=f)zt(l,o(i.node,e),h)&&Yt(c,e)}(e,r,t,a);let n=new e.Geometry;return n.setAttribute("position",new e.Attribute(new Float32Array(r.positions),3)),n.setAttribute("normal",new e.Attribute(new Float32Array(r.normals),3)),n.setAttribute("color",new e.Attribute(new Float32Array(r.colors),3)),n.setAttribute("aLeaf",new e.Attribute(new Float32Array(r.leaf),2)),n.setAttribute("aStalk",new e.Attribute(new Float32Array(r.stalk),3)),n.setAttribute("aWind",new e.Attribute(new Float32Array(r.wind),1)),n}(e,t,a);l={geometry:s,box:Nt(s),triangles:(s.attributes.position?.array.length??0)/9,users:0},r.set(n,l)}return l.users+=1,l}function Kt(e,t){if(t.users-=1,t.users>0)return;t.geometry.dispose();let a=Vt.get(e.frame);if(a)for(let[e,r]of a)r===t&&a.delete(e)}var jt=(e,t)=>Math.min(e,1.2,.05*t);function qt(e,t,a){let{lit:r}=e,n=Ht(r,t.variant,a.spec),o=Gt(r,{...t.uniforms,uLod:{value:a.lod},uLodIn:{value:a.lodIn}},!1);a.built={shape:n,material:o,mesh:Xt(e,t,n,o)},a.idle=0}function Xt(e,t,a,r){let{lit:n}=e,o=new n.Instances(a.geometry,r,Math.max(1,t.capacity));return o.frustumCulled=!1,o.count=0,o.castShadow=!1,o.receiveShadow=!0,o.setColorAt(0,new n.Color("#ffffff")),e.group.add(o),o}function Zt(e,t,a){let{built:r}=a;r&&(e.group.remove(r.mesh),r.mesh.dispose(),r.material.dispose(),Kt(t.variant,r.shape),a.built=null)}function Jt(e){let{cards:t}=e;t&&(e.group.remove(t.mesh),t.material.dispose(),t.mesh.geometry.dispose(),t.mesh.dispose(),t.target.dispose(),e.trees.forEach((e,a)=>{let r=Vt.get(e.variant.frame),n=t.rows[a]?.geometry;for(let t of r?.values()??[])if(t.geometry===n){Kt(e.variant,t);break}}),e.cards=null)}var Qt=(e,t)=>"function"==typeof e.year?e.year(t):e.year;function ea(e,t){for(let a=0;a<e.rungs.length;a+=1){if(e.rungs[t+a]?.built)return t+a;if(e.rungs[t-a]?.built)return t-a}return-1}function ta(e,t){e.rungs.forEach((a,r)=>{let n=e.rungs[r-1],o=e.rungs[r+1];a.lodIn.x=n?.built?a.from:0,a.lod.x=(o?null!==o.built:t)?a.to:1e6})}var aa={at:[0,0,0],size:[0,0,0],yaw:0};function ra(e){return aa.at[0]=e.x,aa.at[1]=e.y,aa.at[2]=e.z,aa.size[0]=e.scale,aa.size[1]=e.scale,aa.size[2]=e.scale,aa.yaw=e.yaw,aa}function na(e,t,a,r){return!(a<e.from-e.lodIn.y||a>e.to+e.band&&(r||!t))}function oa(e,t,a,r){let{c:n,cardsOn:o}=t,l=Math.hypot(r.x-n.x,r.y-n.y,r.z-n.z),s=0;for(let[n,i]of a.rungs.entries()){if(!na(i,n===a.rungs.length-1,l,o))continue;i.built||(t.missing??=[a,i],ea(a,n)<0&&qt(e,a,i));let f=ea(a,n),u=a.rungs[f];if(!u?.built||s&1<<f)continue;s|=1<<f;let{mesh:d}=u.built;g(d.instanceMatrix.array,u.count,ra(r)),d.setColorAt(u.count,e.tint.setRGB(r.tint,r.tint,r.tint)),u.count+=1}return l}function la(e,t,a){let{far:r}=t;g(e.mesh.instanceMatrix.array,r,ra(a)),e.card[2*r]=a.variant,e.card[2*r+1]=a.tint,t.far+=1}function sa(e,t){let a=new e.Group,o=t.fade??[1.5,5],l={x:t.near??26,y:t.band??3,z:o[0],w:o[1]},s=t.variants.slice(0,8),i=s.map((e,a)=>t.places.filter(e=>e.variant===a).length),f=s.map((a,r)=>function(e,t,a,r){let{options:n,lod:o}=r,l=function(e,t){let a=t=>[0,1,2].map(a=>Et(e,t[a%t.length]));return{uTime:{value:0},uWind:{value:0},uYear:{value:{x:1,y:0,z:0,w:0}},uYear2:{value:{x:0,y:0,z:2,w:0}},uLeafCol:{value:a(t.leaves)},uSpring:{value:a(t.spring)},uAutumn:{value:a(t.autumn)},uBloom:{value:Et(e,t.spring[1])},uLod:{value:{x:0,y:0,z:0,w:0}},uLodIn:{value:{x:0,y:0}},uDither:{value:{x:0,y:0}}}}(e,t.colors),s=[[{wood:.012,sides:9,leaves:6e3,fill:4,leafSize:.7,needles:24,clumps:0},.45*o.x],[{wood:n.minRadius??.025,sides:6,leaves:n.maxLeaves??1600,fill:1,needles:9,clumps:0},o.x],[{wood:.03,sides:3,leaves:280,fill:1,leafSize:1.3,needles:4,clumps:6},2.2*o.x]],i=0,f=s.map(([e,t],a)=>{let r=jt(o.y,t),n=jt(o.y,s[a-1]?.[1]??0),l={spec:e,from:i,to:t,band:r,lod:{x:t,y:r,z:o.z,w:o.w},lodIn:{x:i,y:n},built:null,count:0,idle:0};return i=t,l});return{variant:t,uniforms:l,bakeMaterial:Gt(e,l,!0),rungs:f,capacity:a}}(e,a,i[r]??0,{options:t,lod:l})),u={...l,x:2.2*l.x,y:jt(l.y,2.2*l.x)},d={lit:e,group:a,options:{...t,variants:s},trees:f,cardLod:u,keep:t.keep??900,tint:new e.Color,cards:null,far:0};return{group:a,get levels(){let e=e=>f.reduce((t,a)=>t+(a.rungs[e]?.count??0),0),t=f.flatMap(e=>e.rungs.flatMap(e=>e.built?[e.built.shape]:[]));return{close:e(0),full:e(1),layered:e(2),cards:d.far,built:t.length+(d.cards?1:0),triangles:f.reduce((e,t)=>e+t.rungs.reduce((e,t)=>e+t.count*(t.built?.shape.triangles??0),0),0)}},update:e=>{!function(e,t){e.trees.forEach((e,a)=>{(function(e,t,a,r){let o=e.uYear?.value,l=e.uYear2?.value;o.x=t.leaf,o.y=t.color,o.z=!0===r.blossom?0:t.flush,o.w=t.drop;let s=!0===r.blossom&&a.species.flower?.75*n(t.bloom-t.petals,0,1):0;l.x=t.withered?1:0,l.y=s,l.z=a.species.evergreen?1.4*a.species.phenology.dropMax:2})(e.uniforms,Qt(t,a),e.variant.model,e.variant.colors),e.uniforms.uTime.value=t.elapsed,e.uniforms.uWind.value=t.wind;let r=e.uniforms.uDither?.value;r&&([r.x,r.y]=t.dither??[0,0])});let a=t.renderer??null,o=t.camera.position,l=e.cardLod.x-e.cardLod.y,s=null!==a&&e.options.places.some(e=>Math.hypot(e.x-o.x,e.y-o.y,e.z-o.z)>l)?e.cards??function(e){let t=e.trees.map(t=>{let{geometry:a,box:r}=Ht(e.lit,t.variant,function(e){let t=e.rungs[1];if(!t)throw new Error("tree-render: a ladder tree has no plain bake");return t}(t).spec);return{geometry:a,box:r,material:t.bakeMaterial}}),{options:a}=e,r={frames:a.frames,cell:a.cell,lod:e.cardLod},n=function(e,t,a,r){let{lod:n}=r,o=r.frames??8,l=r.cell??160,s=new e.RenderTarget(o*l,t.length*l,{depthBuffer:!0}),i=Array.from({length:8},(a,r)=>{let n=t[r]?.box;return new e.Vector3(n?.half??1,n?.height??1,n?.base??0)}),f={uAtlas:{value:s.texture},uFrames:{value:o},uRows:{value:t.length},uBox:{value:i},uLight:{value:new e.Vector3(1,1,1)},uFogColor:{value:new e.Vector3(1,1,1)},uFog:{value:{x:0,y:0}},uLod:{value:n}},u=new e.CustomMaterial({uniforms:f,vertexShader:$t,fragmentShader:"\nuniform sampler2D uAtlas;\nuniform vec3 uLight;\nuniform vec3 uFogColor;\nuniform vec2 uFog;\nuniform vec4 uLod;\nvarying vec2 vCardUv;\nvarying float vTint, vLodDistance, vViewDepth, vFogDepth;\nfloat forestBayer(vec2 p) {\n vec2 q = mod(floor(p), 4.0);\n float m = mod(q.x + q.y * 4.0, 16.0);\n return fract(m * 0.4375 + floor(m * 0.25) * 0.3125);\n}\nvoid main() {\n float t = forestBayer(gl_FragCoord.xy);\n // The card takes over exactly where the geometry dithers away.\n if (smoothstep(uLod.x + uLod.y, uLod.x - uLod.y, vLodDistance) > t) discard;\n if (smoothstep(uLod.z, uLod.w, vViewDepth) < t) discard;\n vec4 texel = texture2D(uAtlas, vCardUv);\n if (texel.a < 0.5) discard;\n vec3 color = texel.rgb * uLight * vTint;\n float fog = uFog.y > uFog.x ? smoothstep(uFog.x, uFog.y, vFogDepth) : 0.0;\n gl_FragColor = vec4(mix(color, uFogColor, fog), 1.0);\n #include <colorspace_fragment>\n}",side:"both"}),d=new Float32Array(2*Math.max(1,a)),c=e.plane(1,1);c.setAttribute("aCard",new e.InstanceAttribute(d,2));let h=new e.Instances(c,u,Math.max(1,a));return h.frustumCulled=!1,h.count=0,{mesh:h,material:u,uniforms:f,card:d,target:s,frames:o,cell:l,rows:t,capacity:Math.max(1,a),key:"",idle:0}}(e.lit,t,2*a.places.length,r);return e.group.add(n.mesh),e.cards=n,n}(e):e.cards;if(s&&a){let n=function(e,t){return e.trees.map((e,a)=>{let r=Qt(t,a);return[r.leaf,r.color,r.flush,r.drop,r.bloom-r.petals].map(e=>Math.round(24*e)).join(",")+(r.withered?"w":"")}).join("|")}(e,t);n!==s.key&&(function(e,t,a,n){let o=new e.Stage,l=new e.SkyLight("#ffffff","#5a5a50",1.9),s=new e.SunLight("#ffffff",2.4);o.add(l,s);let i=t.getRenderTarget(),f=t.getClearColor(new e.Color),u=t.getClearAlpha(),d=t.autoClear;t.autoClear=!1,t.setRenderTarget(a.target),t.setClearColor(new e.Color("#000000"),0),a.target.scissorTest=!1,a.target.viewport.set(0,0,a.frames*a.cell,n.length*a.cell),t.setRenderTarget(a.target),t.clear(!0,!0,!1);let c={lit:e,renderer:t,cards:a,scene:o,light:s};n.forEach((e,t)=>{!function(e,t,a){let{lit:n,renderer:o,cards:l,scene:s,light:i}=e,{half:f,height:u,base:d}=t.box,c=new n.Mesh(t.geometry,t.material);s.add(c);let h=new n.OrthoCamera(-f,f,u/2,-u/2,.01,8*f),m=d+u/2;for(let e=0;e<l.frames;e+=1){let t=e/l.frames*r;h.position.set(Math.sin(t)*f*4,m,Math.cos(t)*f*4),h.lookAt(0,m,0),h.updateProjectionMatrix(),i.position.set(4*Math.sin(t+.6),6,4*Math.cos(t+.6)),l.target.viewport.set(e*l.cell,a*l.cell,l.cell,l.cell),l.target.scissor.set(e*l.cell,a*l.cell,l.cell,l.cell),l.target.scissorTest=!0,o.setRenderTarget(l.target),o.clear(!1,!0,!1),o.render(s,h)}s.remove(c)}(c,e,t)}),a.target.scissorTest=!1,t.setRenderTarget(i),t.setClearColor(f,u),t.autoClear=d}(e.lit,a,s,s.rows),s.key=n),function(e,t){let a=e.uniforms.uLight?.value,r=t.light??[1,1,1];a.set(r[0],r[1],r[2]);let n=e.uniforms.uFogColor?.value,o=e.uniforms.uFog?.value;t.fog?(n.set(...t.fog.color),o.x=t.fog.near,o.y=t.fog.far):(o.x=0,o.y=0)}(s,t)}!function(e,t,a){let{trees:r,cards:n,options:o,cardLod:l}=e;for(let e of r){ta(e,a);for(let t of e.rungs)t.count=0}let s={cardsOn:a,c:t.camera.position,missing:null,far:0};for(let t of o.places){let o=r[t.variant];if(!o)continue;let i=oa(e,s,o,t);n&&a&&i>l.x-l.y&&la(n,s,t)}!function(e,t){let{cards:a}=e,{cardsOn:r,missing:n,far:o}=t;if(n){let[t,a]=n;a.built||qt(e,t,a)}(function(e){for(let t of e.trees)for(let a of t.rungs)a.idle=a.count>0?0:a.idle+1,a.built&&a.idle>e.keep&&Zt(e,t,a),a.built&&(a.built.mesh.count=a.count,a.built.mesh.instanceMatrix.needsUpdate=!0,a.built.mesh.instanceColor&&(a.built.mesh.instanceColor.needsUpdate=!0))})(e),e.far=o,a&&(function(e,t){e.mesh.count=t,e.mesh.instanceMatrix.needsUpdate=!0;let a=e.mesh.geometry.attributes.aCard;a&&(a.needsUpdate=!0)}(a,r?o:0),a.idle=o>0?0:a.idle+1,a.idle>e.keep&&Jt(e))}(e,s)}(e,t,null!==s&&""!==s.key)}(d,e)},setPlaces:e=>{!function(e,t){e.options={...e.options,places:t},e.trees.forEach((a,r)=>{let n=t.filter(e=>e.variant===r).length;if(!(n<=a.capacity)){a.capacity=Math.ceil(1.5*n);for(let t of a.rungs){let{built:r}=t;r&&(e.group.remove(r.mesh),r.mesh.dispose(),t.built={...r,mesh:Xt(e,a,r.shape,r.material)})}}}),e.cards&&t.length>e.cards.capacity&&Jt(e)}(d,e)},dispose:()=>{Jt(d);for(let e of f){for(let t of e.rungs)Zt(d,e,t);e.bakeMaterial.dispose()}}}}export{A as LEAF_OUTLINE,te as NO_ROOT_BREAK,q as ORNAMENTS,$ as PALM_LEAFLET,ee as ROOT_SEGMENTS,me as ROOT_SHARDS,e as TREE_FEATURES,j as barkMaterial,L as bladeGeometry,f as breezeAt,p as clearSlot,sa as createForest,Rt as createTreeRender,Ge as crownShade,Pt as forestPlaces,s as hash32,c as leafFlutter,I as lightSprig,N as needleGeometry,Q as ornamentLook,le as rootBreaks,he as rootPath,ve as rootShards,i as seededRandom,l as smoothstep,B as softBladeGeometry,V as speciesBlade,D as sprayGeometry,d as sway,a as treeFeatures,K as treeShapes,S as writeBlade,g as writeBox,w as writeSegment,Me as writeShard,v as writeSlab,y as writeVoxel};
@@ -0,0 +1,9 @@
1
+ export declare const VERTEX_GLSL = "\nvoid main() { gl_Position = vec4(position.xy, 0.0, 1.0); }\n";
2
+ export declare const FRAGMENT_GLSL = "\nprecision highp float;\nprecision highp int;\nuniform sampler2D tColor;\nuniform sampler2D tDepth;\nuniform vec2 uGrid;\n// The detail parts' own colour and depth, uFine texels to an art pixel's side,\n// and (on the detail pass) the world's finished look to fill in around them.\nuniform sampler2D tDetail;\nuniform sampler2D tDetailDepth;\nuniform sampler2D tCoarse;\nuniform float uFine;\nuniform float uPass;\nuniform float uNear;\nuniform float uFar;\nuniform float uOrtho;\nuniform vec3 uScreen;\nuniform vec3 uScale;\nuniform vec3 uAmount;\nuniform vec2 uBands;\nuniform float uLevels;\nuniform float uSnap;\nuniform float uLift;\nuniform float uClump;\nuniform float uRamp;\nuniform float uLuma;\nuniform int uPaletteSize;\nuniform int uAccentSize;\nuniform vec3 uAccent[4];\nuniform vec3 uAccentLab[4];\nuniform float uSkySaturation;\nuniform vec3 uPalette[32];\nuniform vec3 uPaletteLab[32];\nuniform float uOutline;\nuniform vec4 uOutlineColor;\nuniform float uCrease;\nuniform float uContrast;\nuniform float uSaturation;\nuniform float uSkyFrom;\nuniform vec2 uRaySource;\nuniform vec3 uRayColor;\nuniform float uRayStrength;\nuniform float uRayDecay;\nuniform float uRayDensity;\nuniform float uScanlines;\nuniform float uChroma;\nuniform float uGlitch;\nuniform float uTime;\n// Per-part signals: x scanlines, y chroma, z glitch, for the parts tagged 1, 2 and 3.\nuniform vec3 uSignal[3];\n// Per-part filters: x the filter's number in SIGNAL_FILTERS, y its amount.\nuniform vec2 uFilter[3];\n\nfloat bayer2(vec2 a) { a = floor(a); return fract(a.x * 0.5 + a.y * a.y * 0.75); }\nfloat bayer4(vec2 a) { return bayer2(0.5 * a) * 0.25 + bayer2(a); }\nfloat bayer8(vec2 a) { return bayer4(0.5 * a) * 0.25 + bayer2(a); }\nfloat tri(float v, float p) { return abs(fract(v / p) * 2.0 - 1.0); }\nfloat halftone(vec2 a) {\n vec2 f = fract(vec2(a.x + a.y + 1.0, a.x - a.y) * 0.1767767) - 0.5;\n return min(0.999, length(f) * 1.41421356);\n}\nfloat stipple(vec2 a) {\n uint h = (uint(a.x) * 1973u + uint(a.y) * 9277u) | 1u;\n h ^= h >> 16; h *= 0x7feb352du; h ^= h >> 15; h *= 0x846ca68bu; h ^= h >> 16;\n return float(h & 0xffffu) / 65536.0;\n}\nfloat screenAt(float id, vec2 a) {\n int s = int(id + 0.5);\n if (s == 1) return bayer2(a);\n if (s == 2) return bayer4(a);\n if (s == 3) return bayer8(a);\n if (s == 4) return halftone(a);\n if (s == 5) return tri(a.y + 0.5, 4.0) * 0.7 + bayer4(a) * 0.3;\n if (s == 6) return tri(a.x + a.y + 0.5, 4.0) * 0.7 + bayer4(a) * 0.3;\n 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;\n if (s == 8) return fract(52.9829189 * fract(0.06711056 * a.x + 0.00583715 * a.y));\n if (s == 9) return stipple(a);\n if (s == 10) return mod(a.x + a.y, 2.0) * 0.5 + 0.25;\n return 0.5;\n}\n\n// The pass's cells: art pixels (gF 1), or detail pixels (gF uFine) on the detail pass.\nvec2 gGrid;\nfloat gF;\nvec2 worldUv(vec2 cell) { return (floor(clamp(cell, vec2(0.0), gGrid - 1.0) / gF) + 0.5) / uGrid; }\nvec2 detailUv(vec2 cell) { return (clamp(cell, vec2(0.0), gGrid - 1.0) + 0.5) / gGrid; }\n// The world is drawn once per art pixel and the detail parts per detail pixel; a cell shows the nearer.\nbool onDetail(vec2 cell) { return gF > 1.5 && texture2D(tDetailDepth, detailUv(cell)).x < texture2D(tDepth, worldUv(cell)).x; }\nvec4 colorAt(vec2 cell) { return onDetail(cell) ? texture2D(tDetail, detailUv(cell)) : texture2D(tColor, worldUv(cell)); }\nfloat distanceAt(vec2 cell) {\n float d = texture2D(tDepth, worldUv(cell)).x;\n if (gF > 1.5) d = min(d, texture2D(tDetailDepth, detailUv(cell)).x);\n if (d >= 0.99999) return uFar;\n if (uOrtho > 0.5) return uNear + d * (uFar - uNear);\n return (uNear * uFar) / (uFar - d * (uFar - uNear));\n}\n// God rays: walk from the pixel toward the light, gathering the open sky the\n// walk crosses. Trees and terrain block it, so shafts fall between them. The\n// result is added in continuous light and only then stepped, so the shafts\n// come out as dithered bands.\nvec3 godRays(vec2 cell) {\n if (uRayStrength <= 0.001) return vec3(0.0);\n vec2 uv = (cell + 0.5) / gGrid;\n vec2 step = (uv - uRaySource) * uRayDensity / 40.0;\n vec2 aspect = vec2(gGrid.x / gGrid.y, 1.0);\n vec2 p = uv;\n float weight = 1.0;\n float sum = 0.0;\n for (int i = 0; i < 40; i++) {\n p -= step;\n float open = distanceAt(floor(clamp(p, 0.0, 0.9999) * gGrid)) >= uSkyFrom ? 1.0 : 0.0;\n float near = 0.3 + 0.7 * exp(-3.5 * length((p - uRaySource) * aspect));\n sum += open * near * weight;\n weight *= uRayDecay;\n }\n return uRayColor * (sum / 40.0) * uRayStrength;\n}\nvec3 toSrgb(vec3 c) {\n c = max(c, 0.0);\n return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(vec3(0.0031308), c));\n}\n// One step: the share past the lower tone, squeezed by uSnap so most of it\n// snaps flat and only the middle of the step dithers.\nfloat snapStep(float value, float t) {\n float base = floor(value);\n float share = clamp((value - base - 0.5) / max(1.0 - uSnap, 0.001) + 0.5, 0.0, 1.0);\n return base + step(1.0 - t, share);\n}\nvec3 stepTones(vec3 c, float t) {\n float steps = max(1.0, uLevels - 1.0);\n if (uLuma < 0.5) {\n // Dither between two step colours only, never off-hue confetti.\n vec3 q = floor(c * steps + 0.5);\n vec3 e = c * steps - q;\n vec3 a = abs(e);\n vec3 lean = step(0.5 * max(a.x, max(a.y, a.z)) + 0.001, a);\n float share = dot(a, lean) / max(1.0, dot(lean, vec3(1.0)));\n share = clamp((share - 0.5) / max(1.0 - uSnap, 0.001) + 0.5, 0.0, 1.0);\n return clamp((q + sign(e) * lean * step(1.0 - t, share)) / steps, 0.0, 1.0);\n }\n // YCoCg: lightness gets twice the steps of colour, so shading reads as ramps.\n float y = dot(c, vec3(0.25, 0.5, 0.25));\n float co = 0.5 * (c.r - c.b);\n float cg = -0.25 * c.r + 0.5 * c.g - 0.25 * c.b;\n // Colour dithers gently; warm-cool steps finely, so a pale sky or night navy keeps its hue. Grey stays grey.\n float ys = steps * 2.0;\n float cs = steps * 2.0 + 2.0;\n float tc = 0.5 + (t - 0.5) * 0.35;\n y = snapStep(y * ys, t) / ys;\n co = snapStep(co * cs * 2.0, tc) / (cs * 2.0);\n cg = snapStep(cg * cs, tc) / cs;\n return clamp(vec3(y + co - cg, y + cg, y - co - cg), 0.0, 1.0);\n}\n// OKLab, so the nearest palette entry is the one that looks nearest.\nvec3 okLab(vec3 c) {\n c = mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c));\n 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));\n return mat3(0.2105, 1.978, 0.0259, 0.7936, -2.4286, 0.7828, -0.0041, 0.4506, -0.8087) * lms;\n}\nvec3 stepPalette(vec3 c, float t, bool spot, float hueWeight) {\n vec3 best = c; vec3 next = c; vec3 bl = c; vec3 nl = c;\n float bd = 1e9; float nd = 1e9;\n vec3 lab = okLab(c);\n // Spot inks: taken only by a pixel already clearly of the ink's hue, dithering between the inks alone.\n if (spot && uAccentSize > 0 && length(lab.yz) > 0.028) {\n float hue = atan(lab.z, lab.y);\n for (int i = 0; i < 4; i++) {\n if (i >= uAccentSize) break;\n vec3 al = uAccentLab[i];\n if (abs(mod(atan(al.z, al.y) - hue + 3.14159, 6.28318) - 3.14159) > 0.35) continue;\n vec3 e = (al - lab) * vec3(1.0, 1.6, 1.6);\n float d = dot(e, e);\n if (d < bd) { nd = bd; next = best; bd = d; best = uAccent[i]; }\n else if (d < nd) { nd = d; next = uAccent[i]; }\n }\n if (bd < 1e8) return t < sqrt(bd) / max(1e-5, sqrt(bd) + sqrt(nd)) && nd < 1e8 ? next : best;\n }\n for (int i = 0; i < 32; i++) {\n if (i >= uPaletteSize) break;\n // Hue outweighs lightness: a pale sky picks a pale blue, not a grey.\n vec3 e = (uPaletteLab[i] - lab) * vec3(1.0, hueWeight, hueWeight);\n float d = dot(e, e);\n if (d < bd) { nd = bd; next = best; nl = bl; bd = d; best = uPalette[i]; bl = uPaletteLab[i]; }\n else if (d < nd) { nd = d; next = uPalette[i]; nl = uPaletteLab[i]; }\n }\n // Only neighbours on a ramp dither; far-apart entries meet in a clean edge.\n float m = sqrt(bd) / max(1e-5, sqrt(bd) + sqrt(nd)) * clamp(1.6 - 3.0 * length(bl - nl), 0.0, 1.0);\n return t < m ? next : best;\n}\nfloat signalHash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }\n// The part a pixel belongs to, from the alpha its material wrote (see tagSignal):\n// 0 untagged, else 1 to 3.\nint partAt(vec2 cell) {\n float a = colorAt(cell).a;\n return a < 0.375 ? 1 : a < 0.625 ? 2 : a < 0.875 ? 3 : 0;\n}\nvec3 signalOf(int part) {\n vec3 own = part == 1 ? uSignal[0] : part == 2 ? uSignal[1] : part == 3 ? uSignal[2] : vec3(0.0);\n return max(own, vec3(uScanlines, uChroma, uGlitch));\n}\n// A burst lasts one eighth of a second; each part keeps its own timing, and how\n// many of its slots burst grows with its glitch strength.\nfloat burstOf(float strength, float part) {\n if (strength <= 0.0) return 0.0;\n return step(1.0 - strength * 0.16, signalHash(vec2(floor(uTime * 8.0), 1.7 + part * 13.1)));\n}\n// Where a bursting part reads from: bands of rows slide sideways (carrying the\n// part's silhouette out over its neighbours), and one block of the part shows\n// what sits above it, so sky tears into it.\nvec2 tornCell(vec2 cell, float strength, float part) {\n float slot = floor(uTime * 8.0) + part * 31.0;\n float rows = floor(cell.y / (2.0 + floor(signalHash(vec2(slot, 3.1)) * 6.0)));\n 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);\n return clamp(cell, vec2(0.0), gGrid - 1.0);\n}\nbool inTearBlock(vec2 cell, float part) {\n float slot = floor(uTime * 8.0) + part * 31.0;\n vec2 size = gGrid * vec2(0.12 + 0.2 * signalHash(vec2(slot, 5.0)), 0.02 + 0.035 * signalHash(vec2(slot, 6.0)));\n vec2 origin = vec2(signalHash(vec2(slot, 7.0)), signalHash(vec2(slot, 8.0))) * gGrid;\n return all(greaterThan(cell, origin)) && all(lessThan(cell, origin + size));\n}\nvec2 glitchCell(vec2 cell, int part) {\n for (int k = 1; k <= 3; k++) {\n float strength = signalOf(k).z;\n if (burstOf(strength, float(k)) < 0.5) continue;\n vec2 source = tornCell(cell, strength, float(k));\n if (part == k && inTearBlock(cell, float(k))) return clamp(source + vec2(0.0, floor(gGrid.y * 0.06)), vec2(0.0), gGrid - 1.0);\n if (part == k || partAt(source) == k) return source;\n }\n return cell;\n}\nvec2 filterOf(int part) { return part == 1 ? uFilter[0] : part == 2 ? uFilter[1] : part == 3 ? uFilter[2] : vec2(0.0); }\nbool isFilter(vec2 f, float id) { return f.y > 0.0 && abs(f.x - id) < 0.5; }\nvec3 rgbAt(vec2 cell) { return toSrgb(colorAt(cell).rgb); }\nfloat lumaOf(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }\nvec3 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); }\n// Filters that move pixels: where a filtered part reads from. Every offset is a\n// whole art pixel, so a filter never smears the grid.\nvec2 filterCell(vec2 cell, vec2 f, int part) {\n float a = f.y;\n // mosaic: the part is drawn in blocks of 2 to 4 art pixels\n if (isFilter(f, 3.0)) { float k = 2.0 + floor(a * 2.0); cell = floor(cell / k) * k + floor(k * 0.5); }\n // vhs: rows wobble, and a band of tracking noise rolls up the frame\n if (isFilter(f, 7.0)) {\n float band = 1.0 - smoothstep(0.0, 5.0, abs(cell.y - fract(uTime * 0.06) * gGrid.y));\n 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));\n }\n // wave: heat haze, rows sway on a slow sine\n if (isFilter(f, 9.0)) cell.x += floor(sin(cell.y * 0.22 + uTime * 2.1) * (1.0 + 2.5 * a) + 0.5);\n // slitscan: each row shows the part at its own moment, so the part shears and unshears\n if (isFilter(f, 15.0)) cell.x += floor(sin(cell.y * 0.045 - uTime * 0.9) * gGrid.x * 0.035 * a + 0.5);\n // datamosh: blocks of the part jump and stick for half a second\n if (isFilter(f, 17.0)) {\n vec2 block = floor(cell / 6.0);\n float slot = floor(uTime * 2.0);\n 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);\n }\n // pixel sort: bright runs of the part drip down over darker pixels below them\n if (isFilter(f, 16.0)) {\n vec2 pick = cell;\n float best = 0.42;\n for (int k = 1; k <= 14; k++) {\n if (float(k) > 14.0 * a) break;\n vec2 p = clamp(cell + vec2(0.0, float(k)), vec2(0.0), gGrid - 1.0);\n if (partAt(p) != part) break;\n float l = lumaOf(rgbAt(p));\n if (l > best + 0.03) { best = l; pick = p; }\n }\n cell = pick;\n }\n return clamp(cell, vec2(0.0), gGrid - 1.0);\n}\n// Filters that change colour, applied before the tones are stepped, so a\n// filtered part is still dithered pixel art.\nvec3 filterColor(vec3 c, vec2 cell, vec2 f, float edge) {\n if (f.y <= 0.0) return c;\n float a = clamp(f.y, 0.0, 1.0);\n float l = lumaOf(c);\n float frame = floor(uTime * 12.0);\n vec3 o = c;\n // snow: static speckles\n 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)));\n // film: sepia, a little grain, and the gate's flicker\n 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;\n // cga: the four-colour 1981 palette\n 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);\n // negative\n if (isFilter(f, 5.0)) o = 1.0 - c;\n // glow: bright pixels bloom into their neighbours\n if (isFilter(f, 6.0) || isFilter(f, 13.0)) {\n vec3 sum = vec3(0.0);\n for (int k = 0; k < 8; k++) {\n float t = float(k) * 0.785398;\n vec3 s = rgbAt(cell + floor(vec2(cos(t), sin(t)) * 2.5 + 0.5));\n sum += s * smoothstep(0.45, 0.9, lumaOf(s));\n }\n o = c + sum * 0.22;\n // neon: dark bodies, glowing rims in a cycling hue\n 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;\n }\n // bleed: colour smears to the right of where it belongs, as on a worn tape\n if (isFilter(f, 8.0)) {\n 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;\n o = vec3(l) + (smear - vec3(lumaOf(smear))) * 1.3;\n }\n // night vision: green phosphor and noise\n 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;\n // sparkle: bright pixels twinkle white\n 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);\n // thermal: black, blue, magenta, red, yellow, white by brightness\n if (isFilter(f, 12.0)) {\n float h = clamp(l * 1.15, 0.0, 1.0);\n 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);\n }\n // rainbow: colours cycle through the hues\n if (isFilter(f, 14.0)) o = hueOf(fract(l * 1.4 + cell.y * 0.008 + uTime * 0.18)) * (0.35 + 0.85 * l);\n // holo: iridescent foil that shifts across the part, with a sweeping sheen\n if (isFilter(f, 18.0)) {\n float sheen = smoothstep(0.92, 1.0, fract((cell.x + cell.y) * 0.02 - uTime * 0.35));\n 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;\n }\n return mix(c, clamp(o, 0.0, 1.0), isFilter(f, 1.0) || isFilter(f, 11.0) ? 1.0 : a);\n}\n// Clump: a smooth Kuwahara filter gathers speckle into masses; what lies behind never bleeds in.\nvec3 clumpAt(vec2 cell, vec3 c, float d0, float gap) {\n vec3 s[9];\n for (int j = 0; j < 3; j++) for (int i = 0; i < 3; i++) {\n vec2 at = cell + vec2(float(i) - 1.0, float(j) - 1.0);\n s[j * 3 + i] = (i == 1 && j == 1) || distanceAt(at) - d0 > gap ? c : rgbAt(at);\n }\n vec3 sum = vec3(0.0);\n float total = 0.0;\n for (int q = 0; q < 4; q++) {\n int ox = q - (q / 2) * 2;\n int oy = q / 2;\n 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];\n vec3 mean = (a + b + d + e) * 0.25;\n vec3 va = a - mean; vec3 vb = b - mean; vec3 vd = d - mean; vec3 ve = e - mean;\n float w = 1.0 / (0.004 + dot(va, va) + dot(vb, vb) + dot(vd, vd) + dot(ve, ve));\n sum += mean * w * w;\n total += w * w;\n }\n return sum / total;\n}\nvoid main() {\n gF = 1.0;\n gGrid = uGrid;\n vec2 at = floor(gl_FragCoord.xy);\n // The detail pass redraws only the detail parts' own pixels; the rest is the world's look.\n if (uPass > 0.5) {\n gF = uFine;\n gGrid = uGrid * uFine;\n if (!onDetail(at)) {\n gl_FragColor = texture2D(tCoarse, (floor(at / uFine) + 0.5) / uGrid);\n return;\n }\n }\n // Clump would gather a small animal's eye and muzzle into its coat.\n float clump = gF > 1.5 ? 0.0 : uClump;\n vec2 home = clamp(at, vec2(0.0), gGrid - 1.0);\n int part = partAt(home);\n vec3 signal = signalOf(part);\n vec2 partFilter = filterOf(part);\n vec2 cell = filterCell(glitchCell(home, part), partFilter, part);\n vec3 c = toSrgb(colorAt(cell).rgb);\n // Red and blue drift apart by whole art pixels around a fringed part, and\n // further while it bursts.\n float fringe = max(signal.y, max(signalOf(partAt(home + vec2(2.0, 0.0))).y, signalOf(partAt(home - vec2(2.0, 0.0))).y));\n float split = floor(fringe * 1.6) + burstOf(signal.z, float(part));\n if (split >= 1.0) {\n c.r = toSrgb(colorAt(cell + vec2(split, 0.0)).rgb).r;\n c.b = toSrgb(colorAt(cell - vec2(split, 0.0)).rgb).b;\n }\n float d0 = distanceAt(cell);\n bool sky = d0 >= uSkyFrom;\n float dl = distanceAt(cell - vec2(1.0, 0.0));\n float dr = distanceAt(cell + vec2(1.0, 0.0));\n float dd = distanceAt(cell - vec2(0.0, 1.0));\n float du = distanceAt(cell + vec2(0.0, 1.0));\n float gap = 0.06 * d0 + 0.08;\n float edge = (!sky && max(max(dl, dr), max(du, dd)) - d0 > gap) ? 1.0 : 0.0;\n // Clumped, a leaf among leaves is not a silhouette.\n if (clump > 0.0 && d0 - min(min(dl, dr), min(du, dd)) > gap) edge = 0.0;\n float lap = abs(dl + dr - 2.0 * d0) + abs(du + dd - 2.0 * d0);\n float crease = (!sky && edge < 0.5 && lap > 0.012 * d0 + 0.02) ? 1.0 : 0.0;\n if (clump > 0.0 && !sky && split < 1.0) c = mix(c, clumpAt(cell, c, d0, gap), clump);\n c = filterColor(c, cell, partFilter, edge);\n\n float jitter = (bayer8(cell + 3.0) - 0.5) * 0.18;\n float far = d0 * (1.0 + jitter);\n int band = sky || far > uBands.y ? 2 : far > uBands.x ? 1 : 0;\n float screen = band == 0 ? uScreen.x : band == 1 ? uScreen.y : uScreen.z;\n float scale = band == 0 ? uScale.x : band == 1 ? uScale.y : uScale.z;\n float amount = band == 0 ? uAmount.x : band == 1 ? uAmount.y : uAmount.z;\n\n c += godRays(cell) * (sky ? 0.6 : 1.0);\n // Soft knee into black; lift the darkest toward cool blue; ramps lean lights warm, shadows cool.\n c = (c - 0.5) * uContrast + 0.5;\n c = mix(0.1 * exp(c * 10.0 - 1.0), c, step(0.1, c));\n float lo = 1.0 - clamp(lumaOf(c), 0.0, 1.0);\n 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);\n // Only a light far band is pushed: a night or blue-hour sky keeps its depth.\n float farPush = band == 2 ? mix(1.0, uSkySaturation, smoothstep(0.3, 0.6, lumaOf(c))) : 1.0;\n c = mix(vec3(lumaOf(c)), c, uSaturation * farPush);\n // Outlines thin out with distance, so a far skyline is a soft edge, not a wire.\n float outline = uOutline * (band == 0 ? 1.0 : band == 1 ? 0.7 : 0.3);\n vec3 ink = uOutlineColor.a > 0.5 ? uOutlineColor.rgb : c * vec3(0.36, 0.33, 0.46);\n c = mix(c, ink, edge * outline);\n c = mix(c, c * vec3(0.74, 0.72, 0.8), crease * uCrease);\n c = clamp(c, 0.0, 1.0);\n\n // A silhouette is a solid run of tone, never broken speckle.\n // A dark sky bands, never a grid of dots.\n if (sky) amount *= smoothstep(0.03, 0.2, lumaOf(c));\n // On a fixed palette the sky keeps its hue and settles into bands rather than a checker of far-apart inks.\n if (sky && uPaletteSize > 0) amount *= 0.35;\n float t = 0.5 + (screenAt(screen, floor(cell / scale)) - 0.5) * amount * (1.0 - edge * outline);\n // Alpha carries this pixel's scanline strength to the blit.\n gl_FragColor = vec4(uPaletteSize > 0 ? stepPalette(c, t, !sky, 1.6 * farPush) : stepTones(c, t), signal.x);\n}\n";
3
+ export declare const BLIT_GLSL = "\nprecision highp float;\nuniform sampler2D tLook;\nuniform vec2 uGrid;\nuniform float uPixel;\nuniform vec2 uOrigin;\nuniform float uScanlines;\nuniform float uTime;\nuniform float uFine;\nvoid main() {\n vec2 frame = (gl_FragCoord.xy - uOrigin) / uPixel;\n // The look target holds uFine detail pixels to an art pixel's side.\n vec2 grid = uGrid * uFine;\n vec2 cell = clamp(floor(frame * uFine), vec2(0.0), grid - 1.0);\n vec4 look = texture2D(tLook, (cell + 0.5) / grid);\n vec3 c = look.rgb;\n // Each pixel's scanline strength came from the look pass (whole frame or its part);\n // none show when an art pixel is too few device pixels tall.\n float scan = uPixel >= 2.0 ? look.a : 0.0;\n // Scanlines: the lower part of every art-pixel row is dimmed, and a faint\n // brighter band rolls slowly down the frame, as on a tube screen.\n // Dark gaps between lines, with the lit rows lifted to keep the frame's brightness.\n float line = (1.0 + scan * 0.22) * (1.0 - scan * 0.5 * step(fract(frame.y), 0.4));\n float roll = 1.0 + scan * 0.07 * sin((frame.y / uGrid.y + uTime * 0.12) * 6.2832);\n gl_FragColor = vec4(c * line * roll, 1.0);\n}\n";
4
+ /** The passes' GLSL, for hosts that run their own pipeline. Uniform names are the contract. */
5
+ export declare const VOXEL_DITHER_GLSL: {
6
+ readonly vertex: "\nvoid main() { gl_Position = vec4(position.xy, 0.0, 1.0); }\n";
7
+ readonly fragment: "\nprecision highp float;\nprecision highp int;\nuniform sampler2D tColor;\nuniform sampler2D tDepth;\nuniform vec2 uGrid;\n// The detail parts' own colour and depth, uFine texels to an art pixel's side,\n// and (on the detail pass) the world's finished look to fill in around them.\nuniform sampler2D tDetail;\nuniform sampler2D tDetailDepth;\nuniform sampler2D tCoarse;\nuniform float uFine;\nuniform float uPass;\nuniform float uNear;\nuniform float uFar;\nuniform float uOrtho;\nuniform vec3 uScreen;\nuniform vec3 uScale;\nuniform vec3 uAmount;\nuniform vec2 uBands;\nuniform float uLevels;\nuniform float uSnap;\nuniform float uLift;\nuniform float uClump;\nuniform float uRamp;\nuniform float uLuma;\nuniform int uPaletteSize;\nuniform int uAccentSize;\nuniform vec3 uAccent[4];\nuniform vec3 uAccentLab[4];\nuniform float uSkySaturation;\nuniform vec3 uPalette[32];\nuniform vec3 uPaletteLab[32];\nuniform float uOutline;\nuniform vec4 uOutlineColor;\nuniform float uCrease;\nuniform float uContrast;\nuniform float uSaturation;\nuniform float uSkyFrom;\nuniform vec2 uRaySource;\nuniform vec3 uRayColor;\nuniform float uRayStrength;\nuniform float uRayDecay;\nuniform float uRayDensity;\nuniform float uScanlines;\nuniform float uChroma;\nuniform float uGlitch;\nuniform float uTime;\n// Per-part signals: x scanlines, y chroma, z glitch, for the parts tagged 1, 2 and 3.\nuniform vec3 uSignal[3];\n// Per-part filters: x the filter's number in SIGNAL_FILTERS, y its amount.\nuniform vec2 uFilter[3];\n\nfloat bayer2(vec2 a) { a = floor(a); return fract(a.x * 0.5 + a.y * a.y * 0.75); }\nfloat bayer4(vec2 a) { return bayer2(0.5 * a) * 0.25 + bayer2(a); }\nfloat bayer8(vec2 a) { return bayer4(0.5 * a) * 0.25 + bayer2(a); }\nfloat tri(float v, float p) { return abs(fract(v / p) * 2.0 - 1.0); }\nfloat halftone(vec2 a) {\n vec2 f = fract(vec2(a.x + a.y + 1.0, a.x - a.y) * 0.1767767) - 0.5;\n return min(0.999, length(f) * 1.41421356);\n}\nfloat stipple(vec2 a) {\n uint h = (uint(a.x) * 1973u + uint(a.y) * 9277u) | 1u;\n h ^= h >> 16; h *= 0x7feb352du; h ^= h >> 15; h *= 0x846ca68bu; h ^= h >> 16;\n return float(h & 0xffffu) / 65536.0;\n}\nfloat screenAt(float id, vec2 a) {\n int s = int(id + 0.5);\n if (s == 1) return bayer2(a);\n if (s == 2) return bayer4(a);\n if (s == 3) return bayer8(a);\n if (s == 4) return halftone(a);\n if (s == 5) return tri(a.y + 0.5, 4.0) * 0.7 + bayer4(a) * 0.3;\n if (s == 6) return tri(a.x + a.y + 0.5, 4.0) * 0.7 + bayer4(a) * 0.3;\n 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;\n if (s == 8) return fract(52.9829189 * fract(0.06711056 * a.x + 0.00583715 * a.y));\n if (s == 9) return stipple(a);\n if (s == 10) return mod(a.x + a.y, 2.0) * 0.5 + 0.25;\n return 0.5;\n}\n\n// The pass's cells: art pixels (gF 1), or detail pixels (gF uFine) on the detail pass.\nvec2 gGrid;\nfloat gF;\nvec2 worldUv(vec2 cell) { return (floor(clamp(cell, vec2(0.0), gGrid - 1.0) / gF) + 0.5) / uGrid; }\nvec2 detailUv(vec2 cell) { return (clamp(cell, vec2(0.0), gGrid - 1.0) + 0.5) / gGrid; }\n// The world is drawn once per art pixel and the detail parts per detail pixel; a cell shows the nearer.\nbool onDetail(vec2 cell) { return gF > 1.5 && texture2D(tDetailDepth, detailUv(cell)).x < texture2D(tDepth, worldUv(cell)).x; }\nvec4 colorAt(vec2 cell) { return onDetail(cell) ? texture2D(tDetail, detailUv(cell)) : texture2D(tColor, worldUv(cell)); }\nfloat distanceAt(vec2 cell) {\n float d = texture2D(tDepth, worldUv(cell)).x;\n if (gF > 1.5) d = min(d, texture2D(tDetailDepth, detailUv(cell)).x);\n if (d >= 0.99999) return uFar;\n if (uOrtho > 0.5) return uNear + d * (uFar - uNear);\n return (uNear * uFar) / (uFar - d * (uFar - uNear));\n}\n// God rays: walk from the pixel toward the light, gathering the open sky the\n// walk crosses. Trees and terrain block it, so shafts fall between them. The\n// result is added in continuous light and only then stepped, so the shafts\n// come out as dithered bands.\nvec3 godRays(vec2 cell) {\n if (uRayStrength <= 0.001) return vec3(0.0);\n vec2 uv = (cell + 0.5) / gGrid;\n vec2 step = (uv - uRaySource) * uRayDensity / 40.0;\n vec2 aspect = vec2(gGrid.x / gGrid.y, 1.0);\n vec2 p = uv;\n float weight = 1.0;\n float sum = 0.0;\n for (int i = 0; i < 40; i++) {\n p -= step;\n float open = distanceAt(floor(clamp(p, 0.0, 0.9999) * gGrid)) >= uSkyFrom ? 1.0 : 0.0;\n float near = 0.3 + 0.7 * exp(-3.5 * length((p - uRaySource) * aspect));\n sum += open * near * weight;\n weight *= uRayDecay;\n }\n return uRayColor * (sum / 40.0) * uRayStrength;\n}\nvec3 toSrgb(vec3 c) {\n c = max(c, 0.0);\n return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(vec3(0.0031308), c));\n}\n// One step: the share past the lower tone, squeezed by uSnap so most of it\n// snaps flat and only the middle of the step dithers.\nfloat snapStep(float value, float t) {\n float base = floor(value);\n float share = clamp((value - base - 0.5) / max(1.0 - uSnap, 0.001) + 0.5, 0.0, 1.0);\n return base + step(1.0 - t, share);\n}\nvec3 stepTones(vec3 c, float t) {\n float steps = max(1.0, uLevels - 1.0);\n if (uLuma < 0.5) {\n // Dither between two step colours only, never off-hue confetti.\n vec3 q = floor(c * steps + 0.5);\n vec3 e = c * steps - q;\n vec3 a = abs(e);\n vec3 lean = step(0.5 * max(a.x, max(a.y, a.z)) + 0.001, a);\n float share = dot(a, lean) / max(1.0, dot(lean, vec3(1.0)));\n share = clamp((share - 0.5) / max(1.0 - uSnap, 0.001) + 0.5, 0.0, 1.0);\n return clamp((q + sign(e) * lean * step(1.0 - t, share)) / steps, 0.0, 1.0);\n }\n // YCoCg: lightness gets twice the steps of colour, so shading reads as ramps.\n float y = dot(c, vec3(0.25, 0.5, 0.25));\n float co = 0.5 * (c.r - c.b);\n float cg = -0.25 * c.r + 0.5 * c.g - 0.25 * c.b;\n // Colour dithers gently; warm-cool steps finely, so a pale sky or night navy keeps its hue. Grey stays grey.\n float ys = steps * 2.0;\n float cs = steps * 2.0 + 2.0;\n float tc = 0.5 + (t - 0.5) * 0.35;\n y = snapStep(y * ys, t) / ys;\n co = snapStep(co * cs * 2.0, tc) / (cs * 2.0);\n cg = snapStep(cg * cs, tc) / cs;\n return clamp(vec3(y + co - cg, y + cg, y - co - cg), 0.0, 1.0);\n}\n// OKLab, so the nearest palette entry is the one that looks nearest.\nvec3 okLab(vec3 c) {\n c = mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c));\n 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));\n return mat3(0.2105, 1.978, 0.0259, 0.7936, -2.4286, 0.7828, -0.0041, 0.4506, -0.8087) * lms;\n}\nvec3 stepPalette(vec3 c, float t, bool spot, float hueWeight) {\n vec3 best = c; vec3 next = c; vec3 bl = c; vec3 nl = c;\n float bd = 1e9; float nd = 1e9;\n vec3 lab = okLab(c);\n // Spot inks: taken only by a pixel already clearly of the ink's hue, dithering between the inks alone.\n if (spot && uAccentSize > 0 && length(lab.yz) > 0.028) {\n float hue = atan(lab.z, lab.y);\n for (int i = 0; i < 4; i++) {\n if (i >= uAccentSize) break;\n vec3 al = uAccentLab[i];\n if (abs(mod(atan(al.z, al.y) - hue + 3.14159, 6.28318) - 3.14159) > 0.35) continue;\n vec3 e = (al - lab) * vec3(1.0, 1.6, 1.6);\n float d = dot(e, e);\n if (d < bd) { nd = bd; next = best; bd = d; best = uAccent[i]; }\n else if (d < nd) { nd = d; next = uAccent[i]; }\n }\n if (bd < 1e8) return t < sqrt(bd) / max(1e-5, sqrt(bd) + sqrt(nd)) && nd < 1e8 ? next : best;\n }\n for (int i = 0; i < 32; i++) {\n if (i >= uPaletteSize) break;\n // Hue outweighs lightness: a pale sky picks a pale blue, not a grey.\n vec3 e = (uPaletteLab[i] - lab) * vec3(1.0, hueWeight, hueWeight);\n float d = dot(e, e);\n if (d < bd) { nd = bd; next = best; nl = bl; bd = d; best = uPalette[i]; bl = uPaletteLab[i]; }\n else if (d < nd) { nd = d; next = uPalette[i]; nl = uPaletteLab[i]; }\n }\n // Only neighbours on a ramp dither; far-apart entries meet in a clean edge.\n float m = sqrt(bd) / max(1e-5, sqrt(bd) + sqrt(nd)) * clamp(1.6 - 3.0 * length(bl - nl), 0.0, 1.0);\n return t < m ? next : best;\n}\nfloat signalHash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }\n// The part a pixel belongs to, from the alpha its material wrote (see tagSignal):\n// 0 untagged, else 1 to 3.\nint partAt(vec2 cell) {\n float a = colorAt(cell).a;\n return a < 0.375 ? 1 : a < 0.625 ? 2 : a < 0.875 ? 3 : 0;\n}\nvec3 signalOf(int part) {\n vec3 own = part == 1 ? uSignal[0] : part == 2 ? uSignal[1] : part == 3 ? uSignal[2] : vec3(0.0);\n return max(own, vec3(uScanlines, uChroma, uGlitch));\n}\n// A burst lasts one eighth of a second; each part keeps its own timing, and how\n// many of its slots burst grows with its glitch strength.\nfloat burstOf(float strength, float part) {\n if (strength <= 0.0) return 0.0;\n return step(1.0 - strength * 0.16, signalHash(vec2(floor(uTime * 8.0), 1.7 + part * 13.1)));\n}\n// Where a bursting part reads from: bands of rows slide sideways (carrying the\n// part's silhouette out over its neighbours), and one block of the part shows\n// what sits above it, so sky tears into it.\nvec2 tornCell(vec2 cell, float strength, float part) {\n float slot = floor(uTime * 8.0) + part * 31.0;\n float rows = floor(cell.y / (2.0 + floor(signalHash(vec2(slot, 3.1)) * 6.0)));\n 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);\n return clamp(cell, vec2(0.0), gGrid - 1.0);\n}\nbool inTearBlock(vec2 cell, float part) {\n float slot = floor(uTime * 8.0) + part * 31.0;\n vec2 size = gGrid * vec2(0.12 + 0.2 * signalHash(vec2(slot, 5.0)), 0.02 + 0.035 * signalHash(vec2(slot, 6.0)));\n vec2 origin = vec2(signalHash(vec2(slot, 7.0)), signalHash(vec2(slot, 8.0))) * gGrid;\n return all(greaterThan(cell, origin)) && all(lessThan(cell, origin + size));\n}\nvec2 glitchCell(vec2 cell, int part) {\n for (int k = 1; k <= 3; k++) {\n float strength = signalOf(k).z;\n if (burstOf(strength, float(k)) < 0.5) continue;\n vec2 source = tornCell(cell, strength, float(k));\n if (part == k && inTearBlock(cell, float(k))) return clamp(source + vec2(0.0, floor(gGrid.y * 0.06)), vec2(0.0), gGrid - 1.0);\n if (part == k || partAt(source) == k) return source;\n }\n return cell;\n}\nvec2 filterOf(int part) { return part == 1 ? uFilter[0] : part == 2 ? uFilter[1] : part == 3 ? uFilter[2] : vec2(0.0); }\nbool isFilter(vec2 f, float id) { return f.y > 0.0 && abs(f.x - id) < 0.5; }\nvec3 rgbAt(vec2 cell) { return toSrgb(colorAt(cell).rgb); }\nfloat lumaOf(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }\nvec3 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); }\n// Filters that move pixels: where a filtered part reads from. Every offset is a\n// whole art pixel, so a filter never smears the grid.\nvec2 filterCell(vec2 cell, vec2 f, int part) {\n float a = f.y;\n // mosaic: the part is drawn in blocks of 2 to 4 art pixels\n if (isFilter(f, 3.0)) { float k = 2.0 + floor(a * 2.0); cell = floor(cell / k) * k + floor(k * 0.5); }\n // vhs: rows wobble, and a band of tracking noise rolls up the frame\n if (isFilter(f, 7.0)) {\n float band = 1.0 - smoothstep(0.0, 5.0, abs(cell.y - fract(uTime * 0.06) * gGrid.y));\n 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));\n }\n // wave: heat haze, rows sway on a slow sine\n if (isFilter(f, 9.0)) cell.x += floor(sin(cell.y * 0.22 + uTime * 2.1) * (1.0 + 2.5 * a) + 0.5);\n // slitscan: each row shows the part at its own moment, so the part shears and unshears\n if (isFilter(f, 15.0)) cell.x += floor(sin(cell.y * 0.045 - uTime * 0.9) * gGrid.x * 0.035 * a + 0.5);\n // datamosh: blocks of the part jump and stick for half a second\n if (isFilter(f, 17.0)) {\n vec2 block = floor(cell / 6.0);\n float slot = floor(uTime * 2.0);\n 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);\n }\n // pixel sort: bright runs of the part drip down over darker pixels below them\n if (isFilter(f, 16.0)) {\n vec2 pick = cell;\n float best = 0.42;\n for (int k = 1; k <= 14; k++) {\n if (float(k) > 14.0 * a) break;\n vec2 p = clamp(cell + vec2(0.0, float(k)), vec2(0.0), gGrid - 1.0);\n if (partAt(p) != part) break;\n float l = lumaOf(rgbAt(p));\n if (l > best + 0.03) { best = l; pick = p; }\n }\n cell = pick;\n }\n return clamp(cell, vec2(0.0), gGrid - 1.0);\n}\n// Filters that change colour, applied before the tones are stepped, so a\n// filtered part is still dithered pixel art.\nvec3 filterColor(vec3 c, vec2 cell, vec2 f, float edge) {\n if (f.y <= 0.0) return c;\n float a = clamp(f.y, 0.0, 1.0);\n float l = lumaOf(c);\n float frame = floor(uTime * 12.0);\n vec3 o = c;\n // snow: static speckles\n 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)));\n // film: sepia, a little grain, and the gate's flicker\n 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;\n // cga: the four-colour 1981 palette\n 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);\n // negative\n if (isFilter(f, 5.0)) o = 1.0 - c;\n // glow: bright pixels bloom into their neighbours\n if (isFilter(f, 6.0) || isFilter(f, 13.0)) {\n vec3 sum = vec3(0.0);\n for (int k = 0; k < 8; k++) {\n float t = float(k) * 0.785398;\n vec3 s = rgbAt(cell + floor(vec2(cos(t), sin(t)) * 2.5 + 0.5));\n sum += s * smoothstep(0.45, 0.9, lumaOf(s));\n }\n o = c + sum * 0.22;\n // neon: dark bodies, glowing rims in a cycling hue\n 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;\n }\n // bleed: colour smears to the right of where it belongs, as on a worn tape\n if (isFilter(f, 8.0)) {\n 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;\n o = vec3(l) + (smear - vec3(lumaOf(smear))) * 1.3;\n }\n // night vision: green phosphor and noise\n 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;\n // sparkle: bright pixels twinkle white\n 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);\n // thermal: black, blue, magenta, red, yellow, white by brightness\n if (isFilter(f, 12.0)) {\n float h = clamp(l * 1.15, 0.0, 1.0);\n 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);\n }\n // rainbow: colours cycle through the hues\n if (isFilter(f, 14.0)) o = hueOf(fract(l * 1.4 + cell.y * 0.008 + uTime * 0.18)) * (0.35 + 0.85 * l);\n // holo: iridescent foil that shifts across the part, with a sweeping sheen\n if (isFilter(f, 18.0)) {\n float sheen = smoothstep(0.92, 1.0, fract((cell.x + cell.y) * 0.02 - uTime * 0.35));\n 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;\n }\n return mix(c, clamp(o, 0.0, 1.0), isFilter(f, 1.0) || isFilter(f, 11.0) ? 1.0 : a);\n}\n// Clump: a smooth Kuwahara filter gathers speckle into masses; what lies behind never bleeds in.\nvec3 clumpAt(vec2 cell, vec3 c, float d0, float gap) {\n vec3 s[9];\n for (int j = 0; j < 3; j++) for (int i = 0; i < 3; i++) {\n vec2 at = cell + vec2(float(i) - 1.0, float(j) - 1.0);\n s[j * 3 + i] = (i == 1 && j == 1) || distanceAt(at) - d0 > gap ? c : rgbAt(at);\n }\n vec3 sum = vec3(0.0);\n float total = 0.0;\n for (int q = 0; q < 4; q++) {\n int ox = q - (q / 2) * 2;\n int oy = q / 2;\n 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];\n vec3 mean = (a + b + d + e) * 0.25;\n vec3 va = a - mean; vec3 vb = b - mean; vec3 vd = d - mean; vec3 ve = e - mean;\n float w = 1.0 / (0.004 + dot(va, va) + dot(vb, vb) + dot(vd, vd) + dot(ve, ve));\n sum += mean * w * w;\n total += w * w;\n }\n return sum / total;\n}\nvoid main() {\n gF = 1.0;\n gGrid = uGrid;\n vec2 at = floor(gl_FragCoord.xy);\n // The detail pass redraws only the detail parts' own pixels; the rest is the world's look.\n if (uPass > 0.5) {\n gF = uFine;\n gGrid = uGrid * uFine;\n if (!onDetail(at)) {\n gl_FragColor = texture2D(tCoarse, (floor(at / uFine) + 0.5) / uGrid);\n return;\n }\n }\n // Clump would gather a small animal's eye and muzzle into its coat.\n float clump = gF > 1.5 ? 0.0 : uClump;\n vec2 home = clamp(at, vec2(0.0), gGrid - 1.0);\n int part = partAt(home);\n vec3 signal = signalOf(part);\n vec2 partFilter = filterOf(part);\n vec2 cell = filterCell(glitchCell(home, part), partFilter, part);\n vec3 c = toSrgb(colorAt(cell).rgb);\n // Red and blue drift apart by whole art pixels around a fringed part, and\n // further while it bursts.\n float fringe = max(signal.y, max(signalOf(partAt(home + vec2(2.0, 0.0))).y, signalOf(partAt(home - vec2(2.0, 0.0))).y));\n float split = floor(fringe * 1.6) + burstOf(signal.z, float(part));\n if (split >= 1.0) {\n c.r = toSrgb(colorAt(cell + vec2(split, 0.0)).rgb).r;\n c.b = toSrgb(colorAt(cell - vec2(split, 0.0)).rgb).b;\n }\n float d0 = distanceAt(cell);\n bool sky = d0 >= uSkyFrom;\n float dl = distanceAt(cell - vec2(1.0, 0.0));\n float dr = distanceAt(cell + vec2(1.0, 0.0));\n float dd = distanceAt(cell - vec2(0.0, 1.0));\n float du = distanceAt(cell + vec2(0.0, 1.0));\n float gap = 0.06 * d0 + 0.08;\n float edge = (!sky && max(max(dl, dr), max(du, dd)) - d0 > gap) ? 1.0 : 0.0;\n // Clumped, a leaf among leaves is not a silhouette.\n if (clump > 0.0 && d0 - min(min(dl, dr), min(du, dd)) > gap) edge = 0.0;\n float lap = abs(dl + dr - 2.0 * d0) + abs(du + dd - 2.0 * d0);\n float crease = (!sky && edge < 0.5 && lap > 0.012 * d0 + 0.02) ? 1.0 : 0.0;\n if (clump > 0.0 && !sky && split < 1.0) c = mix(c, clumpAt(cell, c, d0, gap), clump);\n c = filterColor(c, cell, partFilter, edge);\n\n float jitter = (bayer8(cell + 3.0) - 0.5) * 0.18;\n float far = d0 * (1.0 + jitter);\n int band = sky || far > uBands.y ? 2 : far > uBands.x ? 1 : 0;\n float screen = band == 0 ? uScreen.x : band == 1 ? uScreen.y : uScreen.z;\n float scale = band == 0 ? uScale.x : band == 1 ? uScale.y : uScale.z;\n float amount = band == 0 ? uAmount.x : band == 1 ? uAmount.y : uAmount.z;\n\n c += godRays(cell) * (sky ? 0.6 : 1.0);\n // Soft knee into black; lift the darkest toward cool blue; ramps lean lights warm, shadows cool.\n c = (c - 0.5) * uContrast + 0.5;\n c = mix(0.1 * exp(c * 10.0 - 1.0), c, step(0.1, c));\n float lo = 1.0 - clamp(lumaOf(c), 0.0, 1.0);\n 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);\n // Only a light far band is pushed: a night or blue-hour sky keeps its depth.\n float farPush = band == 2 ? mix(1.0, uSkySaturation, smoothstep(0.3, 0.6, lumaOf(c))) : 1.0;\n c = mix(vec3(lumaOf(c)), c, uSaturation * farPush);\n // Outlines thin out with distance, so a far skyline is a soft edge, not a wire.\n float outline = uOutline * (band == 0 ? 1.0 : band == 1 ? 0.7 : 0.3);\n vec3 ink = uOutlineColor.a > 0.5 ? uOutlineColor.rgb : c * vec3(0.36, 0.33, 0.46);\n c = mix(c, ink, edge * outline);\n c = mix(c, c * vec3(0.74, 0.72, 0.8), crease * uCrease);\n c = clamp(c, 0.0, 1.0);\n\n // A silhouette is a solid run of tone, never broken speckle.\n // A dark sky bands, never a grid of dots.\n if (sky) amount *= smoothstep(0.03, 0.2, lumaOf(c));\n // On a fixed palette the sky keeps its hue and settles into bands rather than a checker of far-apart inks.\n if (sky && uPaletteSize > 0) amount *= 0.35;\n float t = 0.5 + (screenAt(screen, floor(cell / scale)) - 0.5) * amount * (1.0 - edge * outline);\n // Alpha carries this pixel's scanline strength to the blit.\n gl_FragColor = vec4(uPaletteSize > 0 ? stepPalette(c, t, !sky, 1.6 * farPush) : stepTones(c, t), signal.x);\n}\n";
8
+ readonly blit: "\nprecision highp float;\nuniform sampler2D tLook;\nuniform vec2 uGrid;\nuniform float uPixel;\nuniform vec2 uOrigin;\nuniform float uScanlines;\nuniform float uTime;\nuniform float uFine;\nvoid main() {\n vec2 frame = (gl_FragCoord.xy - uOrigin) / uPixel;\n // The look target holds uFine detail pixels to an art pixel's side.\n vec2 grid = uGrid * uFine;\n vec2 cell = clamp(floor(frame * uFine), vec2(0.0), grid - 1.0);\n vec4 look = texture2D(tLook, (cell + 0.5) / grid);\n vec3 c = look.rgb;\n // Each pixel's scanline strength came from the look pass (whole frame or its part);\n // none show when an art pixel is too few device pixels tall.\n float scan = uPixel >= 2.0 ? look.a : 0.0;\n // Scanlines: the lower part of every art-pixel row is dimmed, and a faint\n // brighter band rolls slowly down the frame, as on a tube screen.\n // Dark gaps between lines, with the lit rows lifted to keep the frame's brightness.\n float line = (1.0 + scan * 0.22) * (1.0 - scan * 0.5 * step(fract(frame.y), 0.4));\n float roll = 1.0 + scan * 0.07 * sin((frame.y / uGrid.y + uTime * 0.12) * 6.2832);\n gl_FragColor = vec4(c * line * roll, 1.0);\n}\n";
9
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Dithered voxel pixel art for any keel/lit stage. MIT.
3
+ *
4
+ * The scene is drawn at a low, integer-scaled resolution and only ever SHOWN
5
+ * through a dither screen: a threshold map plus a few tone steps, or a fixed
6
+ * palette. Each art pixel picks its screen by depth band (near things crisp
7
+ * and structured, far things fine and calm), carries a one-pixel silhouette
8
+ * outline and voxel creases, and can be cel-lit through stepped toon ramps.
9
+ *
10
+ * Every screen is a pure function of the art pixel, never of time or of a
11
+ * neighbour's error, so a pixel whose light does not change never changes
12
+ * colour and the picture does not crawl.
13
+ *
14
+ * const look = createVoxelDither(lit, renderer, { style: "smart" });
15
+ * look.setSize(cssWidth, cssHeight, devicePixelRatio);
16
+ * look.shade(scene); // after building or rebuilding the scene
17
+ * renderer.setAnimationLoop(() => look.render(scene, camera));
18
+ *
19
+ * keel/lit is injected: the module never imports it and never touches globals.
20
+ *
21
+ * Outlines and creases come from the depth buffer, so anything drawn with
22
+ * `depthWrite: false` (rain, sparks, glows) is still dithered but never outlined.
23
+ */
24
+ export { SCREENS, DITHER_STYLES, STYLE_IDS, DEFAULT_DITHER_SETTINGS, ditherSettings, autoPixel, resolveGrid, bandScreens, } from "./settings.js";
25
+ export type { ScreenId, ScreenChoice, Shading, ColorMode, DepthBand, BandScreen, BandScreens, DitherSettings, StyleId, PixelGrid, } from "./settings.js";
26
+ export { thresholdAt, quantizeTone, celRamp, okLab, paletteUniform } from "./screens.js";
27
+ export type { ToneStep } from "./screens.js";
28
+ export { VOXEL_DITHER_GLSL } from "./dither.glsl.js";
29
+ export { screenLight } from "./light.js";
30
+ export type { RaySpec, ScreenLight } from "./light.js";
31
+ export type { LitLike } from "./lit.js";
32
+ export { SIGNAL_FILTERS, SIGNAL_TAG_ALPHA, signalUniform, filterUniform, DETAIL_LAYER } from "./signals.js";
33
+ export type { SignalPart, SignalFilter, SignalSpec } from "./signals.js";
34
+ export { createVoxelDither } from "./pass.js";
35
+ export type { VoxelDither } from "./pass.js";
@@ -0,0 +1,33 @@
1
+ import type { Shading } from "./settings.js";
2
+ import type { LitLike, MaterialLike } from "./lit.js";
3
+ /**
4
+ * God rays as a scene describes them: toward which light (a world direction), its colour, and how the shafts fall off.
5
+ */
6
+ export interface RaySpec {
7
+ readonly direction: readonly [number, number, number];
8
+ readonly color: string;
9
+ /** 0 to about 1.5. */
10
+ readonly strength: number;
11
+ /** Falloff per step along a shaft, 0.85 to 0.995. */
12
+ readonly decay?: number | undefined;
13
+ /** How much of the way to the light a shaft samples, 0.2 to 1. */
14
+ readonly density?: number | undefined;
15
+ }
16
+ /** Where a light direction lands on screen: uv (0..1, may fall outside) and how squarely the camera faces it (0..1). */
17
+ export interface ScreenLight {
18
+ readonly x: number;
19
+ readonly y: number;
20
+ readonly facing: number;
21
+ }
22
+ /**
23
+ * Projects a world direction (a light at infinity) through a camera's view
24
+ * and projection matrices (column-major, as keel/lit keeps them).
25
+ */
26
+ export declare function screenLight(view: ArrayLike<number>, projection: ArrayLike<number>, direction: readonly [number, number, number]): ScreenLight;
27
+ interface CelShader {
28
+ setBands(bands: number): void;
29
+ swap(material: MaterialLike, mode: Shading): MaterialLike;
30
+ dispose(): void;
31
+ }
32
+ export declare function createCelShader(lit: LitLike, bands: number): CelShader;
33
+ export {};
@@ -0,0 +1,86 @@
1
+ interface ColorLike {
2
+ copy(color: ColorLike): ColorLike;
3
+ }
4
+ export interface TextureLike {
5
+ minFilter: unknown;
6
+ magFilter: unknown;
7
+ generateMipmaps: boolean;
8
+ needsUpdate: boolean;
9
+ dispose(): void;
10
+ }
11
+ export interface RenderTargetLike {
12
+ readonly texture: TextureLike;
13
+ readonly depthTexture: TextureLike | null;
14
+ setSize(width: number, height: number): void;
15
+ dispose(): void;
16
+ }
17
+ export interface Uniform {
18
+ value: unknown;
19
+ }
20
+ export interface ShaderMaterialLike {
21
+ readonly uniforms: Record<string, Uniform>;
22
+ dispose(): void;
23
+ }
24
+ export interface MaterialLike {
25
+ readonly isLitMaterial?: boolean;
26
+ onCompile?: (shader: {
27
+ fragmentShader: string;
28
+ }, renderer: unknown) => void;
29
+ customProgramCacheKey?: () => string;
30
+ readonly color?: ColorLike;
31
+ opacity: number;
32
+ transparent: boolean;
33
+ visible: boolean;
34
+ readonly userData: Record<string, unknown>;
35
+ gradientMap?: TextureLike | null;
36
+ readonly colorWrite?: boolean;
37
+ needsUpdate: boolean;
38
+ dispose(): void;
39
+ }
40
+ interface LayersLike {
41
+ mask: number;
42
+ }
43
+ export interface NodeLike {
44
+ readonly isMesh?: boolean;
45
+ readonly layers?: LayersLike;
46
+ material?: MaterialLike | MaterialLike[];
47
+ traverse(visit: (node: NodeLike) => void): void;
48
+ }
49
+ interface MatrixLike {
50
+ readonly elements: ArrayLike<number>;
51
+ }
52
+ export interface CameraLike {
53
+ readonly near: number;
54
+ readonly far: number;
55
+ readonly isOrthographicCamera?: boolean;
56
+ readonly matrixWorldInverse?: MatrixLike;
57
+ readonly projectionMatrix?: MatrixLike;
58
+ readonly layers?: LayersLike;
59
+ }
60
+ export interface RendererLike {
61
+ getRenderTarget(): RenderTargetLike | null;
62
+ setRenderTarget(target: RenderTargetLike | null): void;
63
+ render(scene: unknown, camera: unknown): void;
64
+ }
65
+ export interface DisposableLike {
66
+ dispose(): void;
67
+ }
68
+ interface MeshLike {
69
+ frustumCulled: boolean;
70
+ }
71
+ export interface SceneLike {
72
+ add(object: unknown): void;
73
+ }
74
+ /** The parts of keel/lit this module calls. Pass the keel/lit namespace itself. */
75
+ export interface LitLike {
76
+ readonly RenderTarget: new (width: number, height: number, options: Readonly<Record<string, unknown>>) => RenderTargetLike;
77
+ readonly DepthTexture: new (width: number, height: number) => TextureLike;
78
+ readonly CustomMaterial: new (parameters: Readonly<Record<string, unknown>>) => ShaderMaterialLike;
79
+ readonly ToonMaterial: new (parameters: Readonly<Record<string, unknown>>) => MaterialLike;
80
+ readonly DataTexture: new (data: Uint8Array, width: number, height: number, format: string) => TextureLike;
81
+ plane(width: number, height: number): DisposableLike;
82
+ readonly Mesh: new (geometry: unknown, material: unknown) => MeshLike;
83
+ readonly Stage: new () => SceneLike;
84
+ readonly OrthoCamera: new (left: number, right: number, top: number, bottom: number, near: number, far: number) => unknown;
85
+ }
86
+ export {};
@@ -0,0 +1,46 @@
1
+ import type { DitherSettings, PixelGrid } from "./settings.js";
2
+ import type { RaySpec } from "./light.js";
3
+ import type { CameraLike, LitLike, NodeLike, RendererLike } from "./lit.js";
4
+ import type { SignalPart, SignalSpec } from "./signals.js";
5
+ /** A live dithered-voxel look bound to one renderer. */
6
+ export interface VoxelDither {
7
+ readonly settings: DitherSettings;
8
+ readonly grid: PixelGrid;
9
+ /** Replaces the look; returns the normalized settings. Call `shade` again if `shading` or `bands` changed. */
10
+ setSettings(input?: unknown): DitherSettings;
11
+ /**
12
+ * Moves the near/mid and mid/far boundaries (view distances) without re-resolving the look; cheap enough per frame.
13
+ */
14
+ setDepthBands(near: number, far: number): void;
15
+ /** Sizes the grid for a frame of this many CSS pixels. The renderer's canvas must already be that size. */
16
+ setSize(cssWidth: number, cssHeight: number, devicePixelRatio: number): PixelGrid;
17
+ /** Swaps every lit mesh material under `root` to the look's shading (cel toon ramps or the scene's own). */
18
+ shade(root: NodeLike): void;
19
+ /** Sets (or clears, with null) the light the god rays stream from; cheap enough per frame. */
20
+ setRays(rays: RaySpec | null): void;
21
+ /** Sets the clock, in seconds, that rolls the scanlines and times glitch bursts; cheap enough per frame. */
22
+ setTime(seconds: number): void;
23
+ /**
24
+ * Tags every opaque mesh material under `root` as one part, so that part can
25
+ * carry its own signal. Call it again after `shade`, which swaps materials.
26
+ */
27
+ tagSignal(root: NodeLike, part: SignalPart): void;
28
+ /** Sets the signal of parts 1 to 3 (null for none), on top of the look's own whole-frame settings. */
29
+ setSignals(parts: readonly (SignalSpec | null | undefined)[]): void;
30
+ /**
31
+ * Draws everything under `root` on the detail grid (see `detail`), over the
32
+ * world by depth. Meshes added under it later are picked up each frame.
33
+ */
34
+ tagDetail(root: NodeLike): void;
35
+ /** Draws `scene` from `camera` through the look into the renderer's current target. */
36
+ render(scene: unknown, camera: CameraLike): void;
37
+ dispose(): void;
38
+ }
39
+ /**
40
+ * Binds a dithered-voxel look to a renderer.
41
+ *
42
+ * @param lit The keel/lit namespace (WebGL2).
43
+ * @param renderer The WebGLRenderer that owns the canvas.
44
+ * @param input Settings, normalized through `ditherSettings`.
45
+ */
46
+ export declare function createVoxelDither(lit: LitLike, renderer: RendererLike, input?: unknown): VoxelDither;
@@ -0,0 +1,21 @@
1
+ import type { ScreenId } from "./settings.js";
2
+ /** A screen's threshold at an art pixel, 0 to just under 1. The shader computes the same maps. */
3
+ export declare function thresholdAt(screen: ScreenId, x: number, y: number): number;
4
+ /** A screen's step for one channel: `levels` steps, and the threshold deciding where a tone between two lands. */
5
+ export interface ToneStep {
6
+ readonly levels: number;
7
+ readonly threshold: number;
8
+ }
9
+ /** One channel through a screen (see `ToneStep`); `amount` scales the threshold's pull and `snap` the band it holds. */
10
+ export declare function quantizeTone(value: number, step: ToneStep, amount?: number, snap?: number): number;
11
+ /** The stepped light a cel ramp of `bands` steps returns, darkest first (0..255). */
12
+ export declare function celRamp(bands: number): Uint8Array;
13
+ export declare function hexChannels(hex: string): readonly [number, number, number];
14
+ /** An sRGB colour (0..1) in OKLab: lightness, then green-red and blue-yellow. */
15
+ export declare function okLab(rgb: readonly [number, number, number]): [number, number, number];
16
+ /** A palette as the shader's flat vec3[32] (sRGB 0..1) and the same entries in OKLab, plus its length. */
17
+ export declare function paletteUniform(palette: readonly string[]): {
18
+ readonly data: Float32Array;
19
+ readonly lab: Float32Array;
20
+ readonly size: number;
21
+ };