Spaces:
Running
Running
(function(){const P=document.createElement("link").relList;if(P&&P.supports&&P.supports("modulepreload"))return;for(const W of document.querySelectorAll('link[rel="modulepreload"]'))Z(W);new MutationObserver(W=>{for(const V of W)if(V.type==="childList")for(const fn of V.addedNodes)fn.tagName==="LINK"&&fn.rel==="modulepreload"&&Z(fn)}).observe(document,{childList:!0,subtree:!0});function E(W){const V={};return W.integrity&&(V.integrity=W.integrity),W.referrerPolicy&&(V.referrerPolicy=W.referrerPolicy),W.crossOrigin==="use-credentials"?V.credentials="include":W.crossOrigin==="anonymous"?V.credentials="omit":V.credentials="same-origin",V}function Z(W){if(W.ep)return;W.ep=!0;const V=E(W);fetch(W.href,V)}})();function It(a,P){return class extends a{constructor(...E){super(...E),P(this)}}}const Et=It(Array,a=>a.fill(0));let b=1e-6;function Ft(a){function P(n=0,s=0){const t=new a(2);return n!==void 0&&(t[0]=n,s!==void 0&&(t[1]=s)),t}const E=P;function Z(n,s,t){const e=t??new a(2);return e[0]=n,e[1]=s,e}function W(n,s){const t=s??new a(2);return t[0]=Math.ceil(n[0]),t[1]=Math.ceil(n[1]),t}function V(n,s){const t=s??new a(2);return t[0]=Math.floor(n[0]),t[1]=Math.floor(n[1]),t}function fn(n,s){const t=s??new a(2);return t[0]=Math.round(n[0]),t[1]=Math.round(n[1]),t}function ln(n,s=0,t=1,e){const u=e??new a(2);return u[0]=Math.min(t,Math.max(s,n[0])),u[1]=Math.min(t,Math.max(s,n[1])),u}function qn(n,s,t){const e=t??new a(2);return e[0]=n[0]+s[0],e[1]=n[1]+s[1],e}function Gn(n,s,t,e){const u=e??new a(2);return u[0]=n[0]+s[0]*t,u[1]=n[1]+s[1]*t,u}function Bn(n,s){const t=n[0],e=n[1],u=s[0],h=s[1],y=Math.sqrt(t*t+e*e),o=Math.sqrt(u*u+h*h),i=y*o,d=i&&vn(n,s)/i;return Math.acos(d)}function dn(n,s,t){const e=t??new a(2);return e[0]=n[0]-s[0],e[1]=n[1]-s[1],e}const In=dn;function en(n,s){return Math.abs(n[0]-s[0])<b&&Math.abs(n[1]-s[1])<b}function Tn(n,s){return n[0]===s[0]&&n[1]===s[1]}function Dn(n,s,t,e){const u=e??new a(2);return u[0]=n[0]+t*(s[0]-n[0]),u[1]=n[1]+t*(s[1]-n[1]),u}function yn(n,s,t,e){const u=e??new a(2);return u[0]=n[0]+t[0]*(s[0]-n[0]),u[1]=n[1]+t[1]*(s[1]-n[1]),u}function En(n,s,t){const e=t??new a(2);return e[0]=Math.max(n[0],s[0]),e[1]=Math.max(n[1],s[1]),e}function xn(n,s,t){const e=t??new a(2);return e[0]=Math.min(n[0],s[0]),e[1]=Math.min(n[1],s[1]),e}function wn(n,s,t){const e=t??new a(2);return e[0]=n[0]*s,e[1]=n[1]*s,e}const Fn=wn;function _n(n,s,t){const e=t??new a(2);return e[0]=n[0]/s,e[1]=n[1]/s,e}function zn(n,s){const t=s??new a(2);return t[0]=1/n[0],t[1]=1/n[1],t}const Un=zn;function An(n,s,t){const e=t??new a(3),u=n[0]*s[1]-n[1]*s[0];return e[0]=0,e[1]=0,e[2]=u,e}function vn(n,s){return n[0]*s[0]+n[1]*s[1]}function C(n){const s=n[0],t=n[1];return Math.sqrt(s*s+t*t)}const Ln=C;function X(n){const s=n[0],t=n[1];return s*s+t*t}const Q=X;function $(n,s){const t=n[0]-s[0],e=n[1]-s[1];return Math.sqrt(t*t+e*e)}const l=$;function v(n,s){const t=n[0]-s[0],e=n[1]-s[1];return t*t+e*e}const g=v;function z(n,s){const t=s??new a(2),e=n[0],u=n[1],h=Math.sqrt(e*e+u*u);return h>1e-5?(t[0]=e/h,t[1]=u/h):(t[0]=0,t[1]=0),t}function T(n,s){const t=s??new a(2);return t[0]=-n[0],t[1]=-n[1],t}function S(n,s){const t=s??new a(2);return t[0]=n[0],t[1]=n[1],t}const F=S;function L(n,s,t){const e=t??new a(2);return e[0]=n[0]*s[0],e[1]=n[1]*s[1],e}const N=L;function O(n,s,t){const e=t??new a(2);return e[0]=n[0]/s[0],e[1]=n[1]/s[1],e}const G=O;function Y(n=1,s){const t=s??new a(2),e=Math.random()*2*Math.PI;return t[0]=Math.cos(e)*n,t[1]=Math.sin(e)*n,t}function M(n){const s=n??new a(2);return s[0]=0,s[1]=0,s}function A(n,s,t){const e=t??new a(2),u=n[0],h=n[1];return e[0]=u*s[0]+h*s[4]+s[12],e[1]=u*s[1]+h*s[5]+s[13],e}function c(n,s,t){const e=t??new a(2),u=n[0],h=n[1];return e[0]=s[0]*u+s[4]*h+s[8],e[1]=s[1]*u+s[5]*h+s[9],e}function r(n,s,t,e){const u=e??new a(2),h=n[0]-s[0],y=n[1]-s[1],o=Math.sin(t),i=Math.cos(t);return u[0]=h*i-y*o+s[0],u[1]=h*o+y*i+s[1],u}function f(n,s,t){const e=t??new a(2);return z(n,e),wn(e,s,e)}function p(n,s,t){const e=t??new a(2);return C(n)>s?f(n,s,e):S(n,e)}function m(n,s,t){const e=t??new a(2);return Dn(n,s,.5,e)}return{create:P,fromValues:E,set:Z,ceil:W,floor:V,round:fn,clamp:ln,add:qn,addScaled:Gn,angle:Bn,subtract:dn,sub:In,equalsApproximately:en,equals:Tn,lerp:Dn,lerpV:yn,max:En,min:xn,mulScalar:wn,scale:Fn,divScalar:_n,inverse:zn,invert:Un,cross:An,dot:vn,length:C,len:Ln,lengthSq:X,lenSq:Q,distance:$,dist:l,distanceSq:v,distSq:g,normalize:z,negate:T,copy:S,clone:F,multiply:L,mul:N,divide:O,div:G,random:Y,zero:M,transformMat4:A,transformMat3:c,rotate:r,setLength:f,truncate:p,midpoint:m}}const lt=new Map;function _t(a){let P=lt.get(a);return P||(P=Ft(a),lt.set(a,P)),P}function Lt(a){const P=_t(a);function E(l,v,g,z,T,S,F,L,N){const O=new a(12);return O[3]=0,O[7]=0,O[11]=0,l!==void 0&&(O[0]=l,v!==void 0&&(O[1]=v,g!==void 0&&(O[2]=g,z!==void 0&&(O[4]=z,T!==void 0&&(O[5]=T,S!==void 0&&(O[6]=S,F!==void 0&&(O[8]=F,L!==void 0&&(O[9]=L,N!==void 0&&(O[10]=N))))))))),O}function Z(l,v,g,z,T,S,F,L,N,O){const G=O??new a(12);return G[0]=l,G[1]=v,G[2]=g,G[3]=0,G[4]=z,G[5]=T,G[6]=S,G[7]=0,G[8]=F,G[9]=L,G[10]=N,G[11]=0,G}function W(l,v){const g=v??new a(12);return g[0]=l[0],g[1]=l[1],g[2]=l[2],g[3]=0,g[4]=l[4],g[5]=l[5],g[6]=l[6],g[7]=0,g[8]=l[8],g[9]=l[9],g[10]=l[10],g[11]=0,g}function V(l,v){const g=v??new a(12),z=l[0],T=l[1],S=l[2],F=l[3],L=z+z,N=T+T,O=S+S,G=z*L,Y=T*L,M=T*N,A=S*L,c=S*N,r=S*O,f=F*L,p=F*N,m=F*O;return g[0]=1-M-r,g[1]=Y+m,g[2]=A-p,g[3]=0,g[4]=Y-m,g[5]=1-G-r,g[6]=c+f,g[7]=0,g[8]=A+p,g[9]=c-f,g[10]=1-G-M,g[11]=0,g}function fn(l,v){const g=v??new a(12);return g[0]=-l[0],g[1]=-l[1],g[2]=-l[2],g[4]=-l[4],g[5]=-l[5],g[6]=-l[6],g[8]=-l[8],g[9]=-l[9],g[10]=-l[10],g}function ln(l,v){const g=v??new a(12);return g[0]=l[0],g[1]=l[1],g[2]=l[2],g[4]=l[4],g[5]=l[5],g[6]=l[6],g[8]=l[8],g[9]=l[9],g[10]=l[10],g}const qn=ln;function Gn(l,v){return Math.abs(l[0]-v[0])<b&&Math.abs(l[1]-v[1])<b&&Math.abs(l[2]-v[2])<b&&Math.abs(l[4]-v[4])<b&&Math.abs(l[5]-v[5])<b&&Math.abs(l[6]-v[6])<b&&Math.abs(l[8]-v[8])<b&&Math.abs(l[9]-v[9])<b&&Math.abs(l[10]-v[10])<b}function Bn(l,v){return l[0]===v[0]&&l[1]===v[1]&&l[2]===v[2]&&l[4]===v[4]&&l[5]===v[5]&&l[6]===v[6]&&l[8]===v[8]&&l[9]===v[9]&&l[10]===v[10]}function dn(l){const v=l??new a(12);return v[0]=1,v[1]=0,v[2]=0,v[4]=0,v[5]=1,v[6]=0,v[8]=0,v[9]=0,v[10]=1,v}function In(l,v){const g=v??new a(12);if(g===l){let M;return M=l[1],l[1]=l[4],l[4]=M,M=l[2],l[2]=l[8],l[8]=M,M=l[6],l[6]=l[9],l[9]=M,g}const z=l[0*4+0],T=l[0*4+1],S=l[0*4+2],F=l[1*4+0],L=l[1*4+1],N=l[1*4+2],O=l[2*4+0],G=l[2*4+1],Y=l[2*4+2];return g[0]=z,g[1]=F,g[2]=O,g[4]=T,g[5]=L,g[6]=G,g[8]=S,g[9]=N,g[10]=Y,g}function en(l,v){const g=v??new a(12),z=l[0*4+0],T=l[0*4+1],S=l[0*4+2],F=l[1*4+0],L=l[1*4+1],N=l[1*4+2],O=l[2*4+0],G=l[2*4+1],Y=l[2*4+2],M=Y*L-N*G,A=-Y*F+N*O,c=G*F-L*O,r=1/(z*M+T*A+S*c);return g[0]=M*r,g[1]=(-Y*T+S*G)*r,g[2]=(N*T-S*L)*r,g[4]=A*r,g[5]=(Y*z-S*O)*r,g[6]=(-N*z+S*F)*r,g[8]=c*r,g[9]=(-G*z+T*O)*r,g[10]=(L*z-T*F)*r,g}function Tn(l){const v=l[0],g=l[0*4+1],z=l[0*4+2],T=l[1*4+0],S=l[1*4+1],F=l[1*4+2],L=l[2*4+0],N=l[2*4+1],O=l[2*4+2];return v*(S*O-N*F)-T*(g*O-N*z)+L*(g*F-S*z)}const Dn=en;function yn(l,v,g){const z=g??new a(12),T=l[0],S=l[1],F=l[2],L=l[4],N=l[5],O=l[6],G=l[8],Y=l[9],M=l[10],A=v[0],c=v[1],r=v[2],f=v[4],p=v[5],m=v[6],n=v[8],s=v[9],t=v[10];return z[0]=T*A+L*c+G*r,z[1]=S*A+N*c+Y*r,z[2]=F*A+O*c+M*r,z[4]=T*f+L*p+G*m,z[5]=S*f+N*p+Y*m,z[6]=F*f+O*p+M*m,z[8]=T*n+L*s+G*t,z[9]=S*n+N*s+Y*t,z[10]=F*n+O*s+M*t,z}const En=yn;function xn(l,v,g){const z=g??dn();return l!==z&&(z[0]=l[0],z[1]=l[1],z[2]=l[2],z[4]=l[4],z[5]=l[5],z[6]=l[6]),z[8]=v[0],z[9]=v[1],z[10]=1,z}function wn(l,v){const g=v??P.create();return g[0]=l[8],g[1]=l[9],g}function Fn(l,v,g){const z=g??P.create(),T=v*4;return z[0]=l[T+0],z[1]=l[T+1],z}function _n(l,v,g,z){const T=z===l?l:ln(l,z),S=g*4;return T[S+0]=v[0],T[S+1]=v[1],T}function zn(l,v){const g=v??P.create(),z=l[0],T=l[1],S=l[4],F=l[5];return g[0]=Math.sqrt(z*z+T*T),g[1]=Math.sqrt(S*S+F*F),g}function Un(l,v){const g=v??new a(12);return g[0]=1,g[1]=0,g[2]=0,g[4]=0,g[5]=1,g[6]=0,g[8]=l[0],g[9]=l[1],g[10]=1,g}function An(l,v,g){const z=g??new a(12),T=v[0],S=v[1],F=l[0],L=l[1],N=l[2],O=l[1*4+0],G=l[1*4+1],Y=l[1*4+2],M=l[2*4+0],A=l[2*4+1],c=l[2*4+2];return l!==z&&(z[0]=F,z[1]=L,z[2]=N,z[4]=O,z[5]=G,z[6]=Y),z[8]=F*T+O*S+M,z[9]=L*T+G*S+A,z[10]=N*T+Y*S+c,z}function vn(l,v){const g=v??new a(12),z=Math.cos(l),T=Math.sin(l);return g[0]=z,g[1]=T,g[2]=0,g[4]=-T,g[5]=z,g[6]=0,g[8]=0,g[9]=0,g[10]=1,g}function C(l,v,g){const z=g??new a(12),T=l[0*4+0],S=l[0*4+1],F=l[0*4+2],L=l[1*4+0],N=l[1*4+1],O=l[1*4+2],G=Math.cos(v),Y=Math.sin(v);return z[0]=G*T+Y*L,z[1]=G*S+Y*N,z[2]=G*F+Y*O,z[4]=G*L-Y*T,z[5]=G*N-Y*S,z[6]=G*O-Y*F,l!==z&&(z[8]=l[8],z[9]=l[9],z[10]=l[10]),z}function Ln(l,v){const g=v??new a(12);return g[0]=l[0],g[1]=0,g[2]=0,g[4]=0,g[5]=l[1],g[6]=0,g[8]=0,g[9]=0,g[10]=1,g}function X(l,v,g){const z=g??new a(12),T=v[0],S=v[1];return z[0]=T*l[0*4+0],z[1]=T*l[0*4+1],z[2]=T*l[0*4+2],z[4]=S*l[1*4+0],z[5]=S*l[1*4+1],z[6]=S*l[1*4+2],l!==z&&(z[8]=l[8],z[9]=l[9],z[10]=l[10]),z}function Q(l,v){const g=v??new a(12);return g[0]=l,g[1]=0,g[2]=0,g[4]=0,g[5]=l,g[6]=0,g[8]=0,g[9]=0,g[10]=1,g}function $(l,v,g){const z=g??new a(12);return z[0]=v*l[0*4+0],z[1]=v*l[0*4+1],z[2]=v*l[0*4+2],z[4]=v*l[1*4+0],z[5]=v*l[1*4+1],z[6]=v*l[1*4+2],l!==z&&(z[8]=l[8],z[9]=l[9],z[10]=l[10]),z}return{clone:qn,create:E,set:Z,fromMat4:W,fromQuat:V,negate:fn,copy:ln,equalsApproximately:Gn,equals:Bn,identity:dn,transpose:In,inverse:en,invert:Dn,determinant:Tn,mul:En,multiply:yn,setTranslation:xn,getTranslation:wn,getAxis:Fn,setAxis:_n,getScaling:zn,translation:Un,translate:An,rotation:vn,rotate:C,scaling:Ln,scale:X,uniformScaling:Q,uniformScale:$}}const dt=new Map;function Vt(a){let P=dt.get(a);return P||(P=Lt(a),dt.set(a,P)),P}function bt(a){function P(o,i,d){const w=new a(3);return o!==void 0&&(w[0]=o,i!==void 0&&(w[1]=i,d!==void 0&&(w[2]=d))),w}const E=P;function Z(o,i,d,w){const x=w??new a(3);return x[0]=o,x[1]=i,x[2]=d,x}function W(o,i){const d=i??new a(3);return d[0]=Math.ceil(o[0]),d[1]=Math.ceil(o[1]),d[2]=Math.ceil(o[2]),d}function V(o,i){const d=i??new a(3);return d[0]=Math.floor(o[0]),d[1]=Math.floor(o[1]),d[2]=Math.floor(o[2]),d}function fn(o,i){const d=i??new a(3);return d[0]=Math.round(o[0]),d[1]=Math.round(o[1]),d[2]=Math.round(o[2]),d}function ln(o,i=0,d=1,w){const x=w??new a(3);return x[0]=Math.min(d,Math.max(i,o[0])),x[1]=Math.min(d,Math.max(i,o[1])),x[2]=Math.min(d,Math.max(i,o[2])),x}function qn(o,i,d){const w=d??new a(3);return w[0]=o[0]+i[0],w[1]=o[1]+i[1],w[2]=o[2]+i[2],w}function Gn(o,i,d,w){const x=w??new a(3);return x[0]=o[0]+i[0]*d,x[1]=o[1]+i[1]*d,x[2]=o[2]+i[2]*d,x}function Bn(o,i){const d=o[0],w=o[1],x=o[2],D=i[0],_=i[1],U=i[2],I=Math.sqrt(d*d+w*w+x*x),q=Math.sqrt(D*D+_*_+U*U),B=I*q,R=B&&vn(o,i)/B;return Math.acos(R)}function dn(o,i,d){const w=d??new a(3);return w[0]=o[0]-i[0],w[1]=o[1]-i[1],w[2]=o[2]-i[2],w}const In=dn;function en(o,i){return Math.abs(o[0]-i[0])<b&&Math.abs(o[1]-i[1])<b&&Math.abs(o[2]-i[2])<b}function Tn(o,i){return o[0]===i[0]&&o[1]===i[1]&&o[2]===i[2]}function Dn(o,i,d,w){const x=w??new a(3);return x[0]=o[0]+d*(i[0]-o[0]),x[1]=o[1]+d*(i[1]-o[1]),x[2]=o[2]+d*(i[2]-o[2]),x}function yn(o,i,d,w){const x=w??new a(3);return x[0]=o[0]+d[0]*(i[0]-o[0]),x[1]=o[1]+d[1]*(i[1]-o[1]),x[2]=o[2]+d[2]*(i[2]-o[2]),x}function En(o,i,d){const w=d??new a(3);return w[0]=Math.max(o[0],i[0]),w[1]=Math.max(o[1],i[1]),w[2]=Math.max(o[2],i[2]),w}function xn(o,i,d){const w=d??new a(3);return w[0]=Math.min(o[0],i[0]),w[1]=Math.min(o[1],i[1]),w[2]=Math.min(o[2],i[2]),w}function wn(o,i,d){const w=d??new a(3);return w[0]=o[0]*i,w[1]=o[1]*i,w[2]=o[2]*i,w}const Fn=wn;function _n(o,i,d){const w=d??new a(3);return w[0]=o[0]/i,w[1]=o[1]/i,w[2]=o[2]/i,w}function zn(o,i){const d=i??new a(3);return d[0]=1/o[0],d[1]=1/o[1],d[2]=1/o[2],d}const Un=zn;function An(o,i,d){const w=d??new a(3),x=o[2]*i[0]-o[0]*i[2],D=o[0]*i[1]-o[1]*i[0];return w[0]=o[1]*i[2]-o[2]*i[1],w[1]=x,w[2]=D,w}function vn(o,i){return o[0]*i[0]+o[1]*i[1]+o[2]*i[2]}function C(o){const i=o[0],d=o[1],w=o[2];return Math.sqrt(i*i+d*d+w*w)}const Ln=C;function X(o){const i=o[0],d=o[1],w=o[2];return i*i+d*d+w*w}const Q=X;function $(o,i){const d=o[0]-i[0],w=o[1]-i[1],x=o[2]-i[2];return Math.sqrt(d*d+w*w+x*x)}const l=$;function v(o,i){const d=o[0]-i[0],w=o[1]-i[1],x=o[2]-i[2];return d*d+w*w+x*x}const g=v;function z(o,i){const d=i??new a(3),w=o[0],x=o[1],D=o[2],_=Math.sqrt(w*w+x*x+D*D);return _>1e-5?(d[0]=w/_,d[1]=x/_,d[2]=D/_):(d[0]=0,d[1]=0,d[2]=0),d}function T(o,i){const d=i??new a(3);return d[0]=-o[0],d[1]=-o[1],d[2]=-o[2],d}function S(o,i){const d=i??new a(3);return d[0]=o[0],d[1]=o[1],d[2]=o[2],d}const F=S;function L(o,i,d){const w=d??new a(3);return w[0]=o[0]*i[0],w[1]=o[1]*i[1],w[2]=o[2]*i[2],w}const N=L;function O(o,i,d){const w=d??new a(3);return w[0]=o[0]/i[0],w[1]=o[1]/i[1],w[2]=o[2]/i[2],w}const G=O;function Y(o=1,i){const d=i??new a(3),w=Math.random()*2*Math.PI,x=Math.random()*2-1,D=Math.sqrt(1-x*x)*o;return d[0]=Math.cos(w)*D,d[1]=Math.sin(w)*D,d[2]=x*o,d}function M(o){const i=o??new a(3);return i[0]=0,i[1]=0,i[2]=0,i}function A(o,i,d){const w=d??new a(3),x=o[0],D=o[1],_=o[2],U=i[3]*x+i[7]*D+i[11]*_+i[15]||1;return w[0]=(i[0]*x+i[4]*D+i[8]*_+i[12])/U,w[1]=(i[1]*x+i[5]*D+i[9]*_+i[13])/U,w[2]=(i[2]*x+i[6]*D+i[10]*_+i[14])/U,w}function c(o,i,d){const w=d??new a(3),x=o[0],D=o[1],_=o[2];return w[0]=x*i[0*4+0]+D*i[1*4+0]+_*i[2*4+0],w[1]=x*i[0*4+1]+D*i[1*4+1]+_*i[2*4+1],w[2]=x*i[0*4+2]+D*i[1*4+2]+_*i[2*4+2],w}function r(o,i,d){const w=d??new a(3),x=o[0],D=o[1],_=o[2];return w[0]=x*i[0]+D*i[4]+_*i[8],w[1]=x*i[1]+D*i[5]+_*i[9],w[2]=x*i[2]+D*i[6]+_*i[10],w}function f(o,i,d){const w=d??new a(3),x=i[0],D=i[1],_=i[2],U=i[3]*2,I=o[0],q=o[1],B=o[2],R=D*B-_*q,H=_*I-x*B,K=x*q-D*I;return w[0]=I+R*U+(D*K-_*H)*2,w[1]=q+H*U+(_*R-x*K)*2,w[2]=B+K*U+(x*H-D*R)*2,w}function p(o,i){const d=i??new a(3);return d[0]=o[12],d[1]=o[13],d[2]=o[14],d}function m(o,i,d){const w=d??new a(3),x=i*4;return w[0]=o[x+0],w[1]=o[x+1],w[2]=o[x+2],w}function n(o,i){const d=i??new a(3),w=o[0],x=o[1],D=o[2],_=o[4],U=o[5],I=o[6],q=o[8],B=o[9],R=o[10];return d[0]=Math.sqrt(w*w+x*x+D*D),d[1]=Math.sqrt(_*_+U*U+I*I),d[2]=Math.sqrt(q*q+B*B+R*R),d}function s(o,i,d,w){const x=w??new a(3),D=[],_=[];return D[0]=o[0]-i[0],D[1]=o[1]-i[1],D[2]=o[2]-i[2],_[0]=D[0],_[1]=D[1]*Math.cos(d)-D[2]*Math.sin(d),_[2]=D[1]*Math.sin(d)+D[2]*Math.cos(d),x[0]=_[0]+i[0],x[1]=_[1]+i[1],x[2]=_[2]+i[2],x}function t(o,i,d,w){const x=w??new a(3),D=[],_=[];return D[0]=o[0]-i[0],D[1]=o[1]-i[1],D[2]=o[2]-i[2],_[0]=D[2]*Math.sin(d)+D[0]*Math.cos(d),_[1]=D[1],_[2]=D[2]*Math.cos(d)-D[0]*Math.sin(d),x[0]=_[0]+i[0],x[1]=_[1]+i[1],x[2]=_[2]+i[2],x}function e(o,i,d,w){const x=w??new a(3),D=[],_=[];return D[0]=o[0]-i[0],D[1]=o[1]-i[1],D[2]=o[2]-i[2],_[0]=D[0]*Math.cos(d)-D[1]*Math.sin(d),_[1]=D[0]*Math.sin(d)+D[1]*Math.cos(d),_[2]=D[2],x[0]=_[0]+i[0],x[1]=_[1]+i[1],x[2]=_[2]+i[2],x}function u(o,i,d){const w=d??new a(3);return z(o,w),wn(w,i,w)}function h(o,i,d){const w=d??new a(3);return C(o)>i?u(o,i,w):S(o,w)}function y(o,i,d){const w=d??new a(3);return Dn(o,i,.5,w)}return{create:P,fromValues:E,set:Z,ceil:W,floor:V,round:fn,clamp:ln,add:qn,addScaled:Gn,angle:Bn,subtract:dn,sub:In,equalsApproximately:en,equals:Tn,lerp:Dn,lerpV:yn,max:En,min:xn,mulScalar:wn,scale:Fn,divScalar:_n,inverse:zn,invert:Un,cross:An,dot:vn,length:C,len:Ln,lengthSq:X,lenSq:Q,distance:$,dist:l,distanceSq:v,distSq:g,normalize:z,negate:T,copy:S,clone:F,multiply:L,mul:N,divide:O,div:G,random:Y,zero:M,transformMat4:A,transformMat4Upper3x3:c,transformMat3:r,transformQuat:f,getTranslation:p,getAxis:m,getScaling:n,rotateX:s,rotateY:t,rotateZ:e,setLength:u,truncate:h,midpoint:y}}const wt=new Map;function ot(a){let P=wt.get(a);return P||(P=bt(a),wt.set(a,P)),P}function Rt(a){const P=ot(a);function E(n,s,t,e,u,h,y,o,i,d,w,x,D,_,U,I){const q=new a(16);return n!==void 0&&(q[0]=n,s!==void 0&&(q[1]=s,t!==void 0&&(q[2]=t,e!==void 0&&(q[3]=e,u!==void 0&&(q[4]=u,h!==void 0&&(q[5]=h,y!==void 0&&(q[6]=y,o!==void 0&&(q[7]=o,i!==void 0&&(q[8]=i,d!==void 0&&(q[9]=d,w!==void 0&&(q[10]=w,x!==void 0&&(q[11]=x,D!==void 0&&(q[12]=D,_!==void 0&&(q[13]=_,U!==void 0&&(q[14]=U,I!==void 0&&(q[15]=I)))))))))))))))),q}function Z(n,s,t,e,u,h,y,o,i,d,w,x,D,_,U,I,q){const B=q??new a(16);return B[0]=n,B[1]=s,B[2]=t,B[3]=e,B[4]=u,B[5]=h,B[6]=y,B[7]=o,B[8]=i,B[9]=d,B[10]=w,B[11]=x,B[12]=D,B[13]=_,B[14]=U,B[15]=I,B}function W(n,s){const t=s??new a(16);return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=0,t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=0,t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function V(n,s){const t=s??new a(16),e=n[0],u=n[1],h=n[2],y=n[3],o=e+e,i=u+u,d=h+h,w=e*o,x=u*o,D=u*i,_=h*o,U=h*i,I=h*d,q=y*o,B=y*i,R=y*d;return t[0]=1-D-I,t[1]=x+R,t[2]=_-B,t[3]=0,t[4]=x-R,t[5]=1-w-I,t[6]=U+q,t[7]=0,t[8]=_+B,t[9]=U-q,t[10]=1-w-D,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function fn(n,s){const t=s??new a(16);return t[0]=-n[0],t[1]=-n[1],t[2]=-n[2],t[3]=-n[3],t[4]=-n[4],t[5]=-n[5],t[6]=-n[6],t[7]=-n[7],t[8]=-n[8],t[9]=-n[9],t[10]=-n[10],t[11]=-n[11],t[12]=-n[12],t[13]=-n[13],t[14]=-n[14],t[15]=-n[15],t}function ln(n,s){const t=s??new a(16);return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],t}const qn=ln;function Gn(n,s){return Math.abs(n[0]-s[0])<b&&Math.abs(n[1]-s[1])<b&&Math.abs(n[2]-s[2])<b&&Math.abs(n[3]-s[3])<b&&Math.abs(n[4]-s[4])<b&&Math.abs(n[5]-s[5])<b&&Math.abs(n[6]-s[6])<b&&Math.abs(n[7]-s[7])<b&&Math.abs(n[8]-s[8])<b&&Math.abs(n[9]-s[9])<b&&Math.abs(n[10]-s[10])<b&&Math.abs(n[11]-s[11])<b&&Math.abs(n[12]-s[12])<b&&Math.abs(n[13]-s[13])<b&&Math.abs(n[14]-s[14])<b&&Math.abs(n[15]-s[15])<b}function Bn(n,s){return n[0]===s[0]&&n[1]===s[1]&&n[2]===s[2]&&n[3]===s[3]&&n[4]===s[4]&&n[5]===s[5]&&n[6]===s[6]&&n[7]===s[7]&&n[8]===s[8]&&n[9]===s[9]&&n[10]===s[10]&&n[11]===s[11]&&n[12]===s[12]&&n[13]===s[13]&&n[14]===s[14]&&n[15]===s[15]}function dn(n){const s=n??new a(16);return s[0]=1,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=1,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s}function In(n,s){const t=s??new a(16);if(t===n){let H;return H=n[1],n[1]=n[4],n[4]=H,H=n[2],n[2]=n[8],n[8]=H,H=n[3],n[3]=n[12],n[12]=H,H=n[6],n[6]=n[9],n[9]=H,H=n[7],n[7]=n[13],n[13]=H,H=n[11],n[11]=n[14],n[14]=H,t}const e=n[0*4+0],u=n[0*4+1],h=n[0*4+2],y=n[0*4+3],o=n[1*4+0],i=n[1*4+1],d=n[1*4+2],w=n[1*4+3],x=n[2*4+0],D=n[2*4+1],_=n[2*4+2],U=n[2*4+3],I=n[3*4+0],q=n[3*4+1],B=n[3*4+2],R=n[3*4+3];return t[0]=e,t[1]=o,t[2]=x,t[3]=I,t[4]=u,t[5]=i,t[6]=D,t[7]=q,t[8]=h,t[9]=d,t[10]=_,t[11]=B,t[12]=y,t[13]=w,t[14]=U,t[15]=R,t}function en(n,s){const t=s??new a(16),e=n[0*4+0],u=n[0*4+1],h=n[0*4+2],y=n[0*4+3],o=n[1*4+0],i=n[1*4+1],d=n[1*4+2],w=n[1*4+3],x=n[2*4+0],D=n[2*4+1],_=n[2*4+2],U=n[2*4+3],I=n[3*4+0],q=n[3*4+1],B=n[3*4+2],R=n[3*4+3],H=_*R,K=B*U,J=d*R,k=B*w,nn=d*U,on=_*w,sn=h*R,cn=B*y,rn=h*U,un=_*y,pn=h*w,hn=d*y,Mn=x*q,gn=I*D,Pn=o*q,mn=I*i,Sn=o*D,Wn=x*i,Hn=e*q,Xn=I*u,Yn=e*D,Zn=x*u,jn=e*i,Qn=o*u,it=H*i+k*D+nn*q-(K*i+J*D+on*q),ut=K*u+sn*D+un*q-(H*u+cn*D+rn*q),at=J*u+cn*i+pn*q-(k*u+sn*i+hn*q),ft=on*u+rn*i+hn*D-(nn*u+un*i+pn*D),an=1/(e*it+o*ut+x*at+I*ft);return t[0]=an*it,t[1]=an*ut,t[2]=an*at,t[3]=an*ft,t[4]=an*(K*o+J*x+on*I-(H*o+k*x+nn*I)),t[5]=an*(H*e+cn*x+rn*I-(K*e+sn*x+un*I)),t[6]=an*(k*e+sn*o+hn*I-(J*e+cn*o+pn*I)),t[7]=an*(nn*e+un*o+pn*x-(on*e+rn*o+hn*x)),t[8]=an*(Mn*w+mn*U+Sn*R-(gn*w+Pn*U+Wn*R)),t[9]=an*(gn*y+Hn*U+Zn*R-(Mn*y+Xn*U+Yn*R)),t[10]=an*(Pn*y+Xn*w+jn*R-(mn*y+Hn*w+Qn*R)),t[11]=an*(Wn*y+Yn*w+Qn*U-(Sn*y+Zn*w+jn*U)),t[12]=an*(Pn*_+Wn*B+gn*d-(Sn*B+Mn*d+mn*_)),t[13]=an*(Yn*B+Mn*h+Xn*_-(Hn*_+Zn*B+gn*h)),t[14]=an*(Hn*d+Qn*B+mn*h-(jn*B+Pn*h+Xn*d)),t[15]=an*(jn*_+Sn*h+Zn*d-(Yn*d+Qn*_+Wn*h)),t}function Tn(n){const s=n[0],t=n[0*4+1],e=n[0*4+2],u=n[0*4+3],h=n[1*4+0],y=n[1*4+1],o=n[1*4+2],i=n[1*4+3],d=n[2*4+0],w=n[2*4+1],x=n[2*4+2],D=n[2*4+3],_=n[3*4+0],U=n[3*4+1],I=n[3*4+2],q=n[3*4+3],B=x*q,R=I*D,H=o*q,K=I*i,J=o*D,k=x*i,nn=e*q,on=I*u,sn=e*D,cn=x*u,rn=e*i,un=o*u,pn=B*y+K*w+J*U-(R*y+H*w+k*U),hn=R*t+nn*w+cn*U-(B*t+on*w+sn*U),Mn=H*t+on*y+rn*U-(K*t+nn*y+un*U),gn=k*t+sn*y+un*w-(J*t+cn*y+rn*w);return s*pn+h*hn+d*Mn+_*gn}const Dn=en;function yn(n,s,t){const e=t??new a(16),u=n[0],h=n[1],y=n[2],o=n[3],i=n[4],d=n[5],w=n[6],x=n[7],D=n[8],_=n[9],U=n[10],I=n[11],q=n[12],B=n[13],R=n[14],H=n[15],K=s[0],J=s[1],k=s[2],nn=s[3],on=s[4],sn=s[5],cn=s[6],rn=s[7],un=s[8],pn=s[9],hn=s[10],Mn=s[11],gn=s[12],Pn=s[13],mn=s[14],Sn=s[15];return e[0]=u*K+i*J+D*k+q*nn,e[1]=h*K+d*J+_*k+B*nn,e[2]=y*K+w*J+U*k+R*nn,e[3]=o*K+x*J+I*k+H*nn,e[4]=u*on+i*sn+D*cn+q*rn,e[5]=h*on+d*sn+_*cn+B*rn,e[6]=y*on+w*sn+U*cn+R*rn,e[7]=o*on+x*sn+I*cn+H*rn,e[8]=u*un+i*pn+D*hn+q*Mn,e[9]=h*un+d*pn+_*hn+B*Mn,e[10]=y*un+w*pn+U*hn+R*Mn,e[11]=o*un+x*pn+I*hn+H*Mn,e[12]=u*gn+i*Pn+D*mn+q*Sn,e[13]=h*gn+d*Pn+_*mn+B*Sn,e[14]=y*gn+w*Pn+U*mn+R*Sn,e[15]=o*gn+x*Pn+I*mn+H*Sn,e}const En=yn;function xn(n,s,t){const e=t??dn();return n!==e&&(e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11]),e[12]=s[0],e[13]=s[1],e[14]=s[2],e[15]=1,e}function wn(n,s){const t=s??P.create();return t[0]=n[12],t[1]=n[13],t[2]=n[14],t}function Fn(n,s,t){const e=t??P.create(),u=s*4;return e[0]=n[u+0],e[1]=n[u+1],e[2]=n[u+2],e}function _n(n,s,t,e){const u=e===n?e:ln(n,e),h=t*4;return u[h+0]=s[0],u[h+1]=s[1],u[h+2]=s[2],u}function zn(n,s){const t=s??P.create(),e=n[0],u=n[1],h=n[2],y=n[4],o=n[5],i=n[6],d=n[8],w=n[9],x=n[10];return t[0]=Math.sqrt(e*e+u*u+h*h),t[1]=Math.sqrt(y*y+o*o+i*i),t[2]=Math.sqrt(d*d+w*w+x*x),t}function Un(n,s,t,e,u){const h=u??new a(16),y=Math.tan(Math.PI*.5-.5*n);if(h[0]=y/s,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=y,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[11]=-1,h[12]=0,h[13]=0,h[15]=0,Number.isFinite(e)){const o=1/(t-e);h[10]=e*o,h[14]=e*t*o}else h[10]=-1,h[14]=-t;return h}function An(n,s,t,e=1/0,u){const h=u??new a(16),y=1/Math.tan(n*.5);if(h[0]=y/s,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=y,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[11]=-1,h[12]=0,h[13]=0,h[15]=0,e===1/0)h[10]=0,h[14]=t;else{const o=1/(e-t);h[10]=t*o,h[14]=e*t*o}return h}function vn(n,s,t,e,u,h,y){const o=y??new a(16);return o[0]=2/(s-n),o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2/(e-t),o[6]=0,o[7]=0,o[8]=0,o[9]=0,o[10]=1/(u-h),o[11]=0,o[12]=(s+n)/(n-s),o[13]=(e+t)/(t-e),o[14]=u/(u-h),o[15]=1,o}function C(n,s,t,e,u,h,y){const o=y??new a(16),i=s-n,d=e-t,w=u-h;return o[0]=2*u/i,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*u/d,o[6]=0,o[7]=0,o[8]=(n+s)/i,o[9]=(e+t)/d,o[10]=h/w,o[11]=-1,o[12]=0,o[13]=0,o[14]=u*h/w,o[15]=0,o}function Ln(n,s,t,e,u,h=1/0,y){const o=y??new a(16),i=s-n,d=e-t;if(o[0]=2*u/i,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*u/d,o[6]=0,o[7]=0,o[8]=(n+s)/i,o[9]=(e+t)/d,o[11]=-1,o[12]=0,o[13]=0,o[15]=0,h===1/0)o[10]=0,o[14]=u;else{const w=1/(h-u);o[10]=u*w,o[14]=h*u*w}return o}const X=P.create(),Q=P.create(),$=P.create();function l(n,s,t,e){const u=e??new a(16);return P.normalize(P.subtract(s,n,$),$),P.normalize(P.cross(t,$,X),X),P.normalize(P.cross($,X,Q),Q),u[0]=X[0],u[1]=X[1],u[2]=X[2],u[3]=0,u[4]=Q[0],u[5]=Q[1],u[6]=Q[2],u[7]=0,u[8]=$[0],u[9]=$[1],u[10]=$[2],u[11]=0,u[12]=n[0],u[13]=n[1],u[14]=n[2],u[15]=1,u}function v(n,s,t,e){const u=e??new a(16);return P.normalize(P.subtract(n,s,$),$),P.normalize(P.cross(t,$,X),X),P.normalize(P.cross($,X,Q),Q),u[0]=X[0],u[1]=X[1],u[2]=X[2],u[3]=0,u[4]=Q[0],u[5]=Q[1],u[6]=Q[2],u[7]=0,u[8]=$[0],u[9]=$[1],u[10]=$[2],u[11]=0,u[12]=n[0],u[13]=n[1],u[14]=n[2],u[15]=1,u}function g(n,s,t,e){const u=e??new a(16);return P.normalize(P.subtract(n,s,$),$),P.normalize(P.cross(t,$,X),X),P.normalize(P.cross($,X,Q),Q),u[0]=X[0],u[1]=Q[0],u[2]=$[0],u[3]=0,u[4]=X[1],u[5]=Q[1],u[6]=$[1],u[7]=0,u[8]=X[2],u[9]=Q[2],u[10]=$[2],u[11]=0,u[12]=-(X[0]*n[0]+X[1]*n[1]+X[2]*n[2]),u[13]=-(Q[0]*n[0]+Q[1]*n[1]+Q[2]*n[2]),u[14]=-($[0]*n[0]+$[1]*n[1]+$[2]*n[2]),u[15]=1,u}function z(n,s){const t=s??new a(16);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function T(n,s,t){const e=t??new a(16),u=s[0],h=s[1],y=s[2],o=n[0],i=n[1],d=n[2],w=n[3],x=n[1*4+0],D=n[1*4+1],_=n[1*4+2],U=n[1*4+3],I=n[2*4+0],q=n[2*4+1],B=n[2*4+2],R=n[2*4+3],H=n[3*4+0],K=n[3*4+1],J=n[3*4+2],k=n[3*4+3];return n!==e&&(e[0]=o,e[1]=i,e[2]=d,e[3]=w,e[4]=x,e[5]=D,e[6]=_,e[7]=U,e[8]=I,e[9]=q,e[10]=B,e[11]=R),e[12]=o*u+x*h+I*y+H,e[13]=i*u+D*h+q*y+K,e[14]=d*u+_*h+B*y+J,e[15]=w*u+U*h+R*y+k,e}function S(n,s){const t=s??new a(16),e=Math.cos(n),u=Math.sin(n);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e,t[6]=u,t[7]=0,t[8]=0,t[9]=-u,t[10]=e,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function F(n,s,t){const e=t??new a(16),u=n[4],h=n[5],y=n[6],o=n[7],i=n[8],d=n[9],w=n[10],x=n[11],D=Math.cos(s),_=Math.sin(s);return e[4]=D*u+_*i,e[5]=D*h+_*d,e[6]=D*y+_*w,e[7]=D*o+_*x,e[8]=D*i-_*u,e[9]=D*d-_*h,e[10]=D*w-_*y,e[11]=D*x-_*o,n!==e&&(e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15]),e}function L(n,s){const t=s??new a(16),e=Math.cos(n),u=Math.sin(n);return t[0]=e,t[1]=0,t[2]=-u,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=u,t[9]=0,t[10]=e,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function N(n,s,t){const e=t??new a(16),u=n[0*4+0],h=n[0*4+1],y=n[0*4+2],o=n[0*4+3],i=n[2*4+0],d=n[2*4+1],w=n[2*4+2],x=n[2*4+3],D=Math.cos(s),_=Math.sin(s);return e[0]=D*u-_*i,e[1]=D*h-_*d,e[2]=D*y-_*w,e[3]=D*o-_*x,e[8]=D*i+_*u,e[9]=D*d+_*h,e[10]=D*w+_*y,e[11]=D*x+_*o,n!==e&&(e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15]),e}function O(n,s){const t=s??new a(16),e=Math.cos(n),u=Math.sin(n);return t[0]=e,t[1]=u,t[2]=0,t[3]=0,t[4]=-u,t[5]=e,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function G(n,s,t){const e=t??new a(16),u=n[0*4+0],h=n[0*4+1],y=n[0*4+2],o=n[0*4+3],i=n[1*4+0],d=n[1*4+1],w=n[1*4+2],x=n[1*4+3],D=Math.cos(s),_=Math.sin(s);return e[0]=D*u+_*i,e[1]=D*h+_*d,e[2]=D*y+_*w,e[3]=D*o+_*x,e[4]=D*i-_*u,e[5]=D*d-_*h,e[6]=D*w-_*y,e[7]=D*x-_*o,n!==e&&(e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15]),e}function Y(n,s,t){const e=t??new a(16);let u=n[0],h=n[1],y=n[2];const o=Math.sqrt(u*u+h*h+y*y);u/=o,h/=o,y/=o;const i=u*u,d=h*h,w=y*y,x=Math.cos(s),D=Math.sin(s),_=1-x;return e[0]=i+(1-i)*x,e[1]=u*h*_+y*D,e[2]=u*y*_-h*D,e[3]=0,e[4]=u*h*_-y*D,e[5]=d+(1-d)*x,e[6]=h*y*_+u*D,e[7]=0,e[8]=u*y*_+h*D,e[9]=h*y*_-u*D,e[10]=w+(1-w)*x,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}const M=Y;function A(n,s,t,e){const u=e??new a(16);let h=s[0],y=s[1],o=s[2];const i=Math.sqrt(h*h+y*y+o*o);h/=i,y/=i,o/=i;const d=h*h,w=y*y,x=o*o,D=Math.cos(t),_=Math.sin(t),U=1-D,I=d+(1-d)*D,q=h*y*U+o*_,B=h*o*U-y*_,R=h*y*U-o*_,H=w+(1-w)*D,K=y*o*U+h*_,J=h*o*U+y*_,k=y*o*U-h*_,nn=x+(1-x)*D,on=n[0],sn=n[1],cn=n[2],rn=n[3],un=n[4],pn=n[5],hn=n[6],Mn=n[7],gn=n[8],Pn=n[9],mn=n[10],Sn=n[11];return u[0]=I*on+q*un+B*gn,u[1]=I*sn+q*pn+B*Pn,u[2]=I*cn+q*hn+B*mn,u[3]=I*rn+q*Mn+B*Sn,u[4]=R*on+H*un+K*gn,u[5]=R*sn+H*pn+K*Pn,u[6]=R*cn+H*hn+K*mn,u[7]=R*rn+H*Mn+K*Sn,u[8]=J*on+k*un+nn*gn,u[9]=J*sn+k*pn+nn*Pn,u[10]=J*cn+k*hn+nn*mn,u[11]=J*rn+k*Mn+nn*Sn,n!==u&&(u[12]=n[12],u[13]=n[13],u[14]=n[14],u[15]=n[15]),u}const c=A;function r(n,s){const t=s??new a(16);return t[0]=n[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=n[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function f(n,s,t){const e=t??new a(16),u=s[0],h=s[1],y=s[2];return e[0]=u*n[0*4+0],e[1]=u*n[0*4+1],e[2]=u*n[0*4+2],e[3]=u*n[0*4+3],e[4]=h*n[1*4+0],e[5]=h*n[1*4+1],e[6]=h*n[1*4+2],e[7]=h*n[1*4+3],e[8]=y*n[2*4+0],e[9]=y*n[2*4+1],e[10]=y*n[2*4+2],e[11]=y*n[2*4+3],n!==e&&(e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15]),e}function p(n,s){const t=s??new a(16);return t[0]=n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function m(n,s,t){const e=t??new a(16);return e[0]=s*n[0*4+0],e[1]=s*n[0*4+1],e[2]=s*n[0*4+2],e[3]=s*n[0*4+3],e[4]=s*n[1*4+0],e[5]=s*n[1*4+1],e[6]=s*n[1*4+2],e[7]=s*n[1*4+3],e[8]=s*n[2*4+0],e[9]=s*n[2*4+1],e[10]=s*n[2*4+2],e[11]=s*n[2*4+3],n!==e&&(e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15]),e}return{create:E,set:Z,fromMat3:W,fromQuat:V,negate:fn,copy:ln,clone:qn,equalsApproximately:Gn,equals:Bn,identity:dn,transpose:In,inverse:en,determinant:Tn,invert:Dn,multiply:yn,mul:En,setTranslation:xn,getTranslation:wn,getAxis:Fn,setAxis:_n,getScaling:zn,perspective:Un,perspectiveReverseZ:An,ortho:vn,frustum:C,frustumReverseZ:Ln,aim:l,cameraAim:v,lookAt:g,translation:z,translate:T,rotationX:S,rotateX:F,rotationY:L,rotateY:N,rotationZ:O,rotateZ:G,axisRotation:Y,rotation:M,axisRotate:A,rotate:c,scaling:r,scale:f,uniformScaling:p,uniformScale:m}}const pt=new Map;function $t(a){let P=pt.get(a);return P||(P=Rt(a),pt.set(a,P)),P}function Nt(a){const P=ot(a);function E(M,A,c,r){const f=new a(4);return M!==void 0&&(f[0]=M,A!==void 0&&(f[1]=A,c!==void 0&&(f[2]=c,r!==void 0&&(f[3]=r)))),f}const Z=E;function W(M,A,c,r,f){const p=f??new a(4);return p[0]=M,p[1]=A,p[2]=c,p[3]=r,p}function V(M,A,c){const r=c??new a(4),f=A*.5,p=Math.sin(f);return r[0]=p*M[0],r[1]=p*M[1],r[2]=p*M[2],r[3]=Math.cos(f),r}function fn(M,A){const c=A??P.create(3),r=Math.acos(M[3])*2,f=Math.sin(r*.5);return f>b?(c[0]=M[0]/f,c[1]=M[1]/f,c[2]=M[2]/f):(c[0]=1,c[1]=0,c[2]=0),{angle:r,axis:c}}function ln(M,A){const c=C(M,A);return Math.acos(2*c*c-1)}function qn(M,A,c){const r=c??new a(4),f=M[0],p=M[1],m=M[2],n=M[3],s=A[0],t=A[1],e=A[2],u=A[3];return r[0]=f*u+n*s+p*e-m*t,r[1]=p*u+n*t+m*s-f*e,r[2]=m*u+n*e+f*t-p*s,r[3]=n*u-f*s-p*t-m*e,r}const Gn=qn;function Bn(M,A,c){const r=c??new a(4),f=A*.5,p=M[0],m=M[1],n=M[2],s=M[3],t=Math.sin(f),e=Math.cos(f);return r[0]=p*e+s*t,r[1]=m*e+n*t,r[2]=n*e-m*t,r[3]=s*e-p*t,r}function dn(M,A,c){const r=c??new a(4),f=A*.5,p=M[0],m=M[1],n=M[2],s=M[3],t=Math.sin(f),e=Math.cos(f);return r[0]=p*e-n*t,r[1]=m*e+s*t,r[2]=n*e+p*t,r[3]=s*e-m*t,r}function In(M,A,c){const r=c??new a(4),f=A*.5,p=M[0],m=M[1],n=M[2],s=M[3],t=Math.sin(f),e=Math.cos(f);return r[0]=p*e+m*t,r[1]=m*e-p*t,r[2]=n*e+s*t,r[3]=s*e-n*t,r}function en(M,A,c,r){const f=r??new a(4),p=M[0],m=M[1],n=M[2],s=M[3];let t=A[0],e=A[1],u=A[2],h=A[3],y=p*t+m*e+n*u+s*h;y<0&&(y=-y,t=-t,e=-e,u=-u,h=-h);let o,i;if(1-y>b){const d=Math.acos(y),w=Math.sin(d);o=Math.sin((1-c)*d)/w,i=Math.sin(c*d)/w}else o=1-c,i=c;return f[0]=o*p+i*t,f[1]=o*m+i*e,f[2]=o*n+i*u,f[3]=o*s+i*h,f}function Tn(M,A){const c=A??new a(4),r=M[0],f=M[1],p=M[2],m=M[3],n=r*r+f*f+p*p+m*m,s=n?1/n:0;return c[0]=-r*s,c[1]=-f*s,c[2]=-p*s,c[3]=m*s,c}function Dn(M,A){const c=A??new a(4);return c[0]=-M[0],c[1]=-M[1],c[2]=-M[2],c[3]=M[3],c}function yn(M,A){const c=A??new a(4),r=M[0]+M[5]+M[10];if(r>0){const f=Math.sqrt(r+1);c[3]=.5*f;const p=.5/f;c[0]=(M[6]-M[9])*p,c[1]=(M[8]-M[2])*p,c[2]=(M[1]-M[4])*p}else{let f=0;M[5]>M[0]&&(f=1),M[10]>M[f*4+f]&&(f=2);const p=(f+1)%3,m=(f+2)%3,n=Math.sqrt(M[f*4+f]-M[p*4+p]-M[m*4+m]+1);c[f]=.5*n;const s=.5/n;c[3]=(M[p*4+m]-M[m*4+p])*s,c[p]=(M[p*4+f]+M[f*4+p])*s,c[m]=(M[m*4+f]+M[f*4+m])*s}return c}function En(M,A,c,r,f){const p=f??new a(4),m=M*.5,n=A*.5,s=c*.5,t=Math.sin(m),e=Math.cos(m),u=Math.sin(n),h=Math.cos(n),y=Math.sin(s),o=Math.cos(s);switch(r){case"xyz":p[0]=t*h*o+e*u*y,p[1]=e*u*o-t*h*y,p[2]=e*h*y+t*u*o,p[3]=e*h*o-t*u*y;break;case"xzy":p[0]=t*h*o-e*u*y,p[1]=e*u*o-t*h*y,p[2]=e*h*y+t*u*o,p[3]=e*h*o+t*u*y;break;case"yxz":p[0]=t*h*o+e*u*y,p[1]=e*u*o-t*h*y,p[2]=e*h*y-t*u*o,p[3]=e*h*o+t*u*y;break;case"yzx":p[0]=t*h*o+e*u*y,p[1]=e*u*o+t*h*y,p[2]=e*h*y-t*u*o,p[3]=e*h*o-t*u*y;break;case"zxy":p[0]=t*h*o-e*u*y,p[1]=e*u*o+t*h*y,p[2]=e*h*y+t*u*o,p[3]=e*h*o-t*u*y;break;case"zyx":p[0]=t*h*o-e*u*y,p[1]=e*u*o+t*h*y,p[2]=e*h*y-t*u*o,p[3]=e*h*o+t*u*y;break;default:throw new Error(`Unknown rotation order: ${r}`)}return p}function xn(M,A){const c=A??new a(4);return c[0]=M[0],c[1]=M[1],c[2]=M[2],c[3]=M[3],c}const wn=xn;function Fn(M,A,c){const r=c??new a(4);return r[0]=M[0]+A[0],r[1]=M[1]+A[1],r[2]=M[2]+A[2],r[3]=M[3]+A[3],r}function _n(M,A,c){const r=c??new a(4);return r[0]=M[0]-A[0],r[1]=M[1]-A[1],r[2]=M[2]-A[2],r[3]=M[3]-A[3],r}const zn=_n;function Un(M,A,c){const r=c??new a(4);return r[0]=M[0]*A,r[1]=M[1]*A,r[2]=M[2]*A,r[3]=M[3]*A,r}const An=Un;function vn(M,A,c){const r=c??new a(4);return r[0]=M[0]/A,r[1]=M[1]/A,r[2]=M[2]/A,r[3]=M[3]/A,r}function C(M,A){return M[0]*A[0]+M[1]*A[1]+M[2]*A[2]+M[3]*A[3]}function Ln(M,A,c,r){const f=r??new a(4);return f[0]=M[0]+c*(A[0]-M[0]),f[1]=M[1]+c*(A[1]-M[1]),f[2]=M[2]+c*(A[2]-M[2]),f[3]=M[3]+c*(A[3]-M[3]),f}function X(M){const A=M[0],c=M[1],r=M[2],f=M[3];return Math.sqrt(A*A+c*c+r*r+f*f)}const Q=X;function $(M){const A=M[0],c=M[1],r=M[2],f=M[3];return A*A+c*c+r*r+f*f}const l=$;function v(M,A){const c=A??new a(4),r=M[0],f=M[1],p=M[2],m=M[3],n=Math.sqrt(r*r+f*f+p*p+m*m);return n>1e-5?(c[0]=r/n,c[1]=f/n,c[2]=p/n,c[3]=m/n):(c[0]=0,c[1]=0,c[2]=0,c[3]=1),c}function g(M,A){return Math.abs(M[0]-A[0])<b&&Math.abs(M[1]-A[1])<b&&Math.abs(M[2]-A[2])<b&&Math.abs(M[3]-A[3])<b}function z(M,A){return M[0]===A[0]&&M[1]===A[1]&&M[2]===A[2]&&M[3]===A[3]}function T(M){const A=M??new a(4);return A[0]=0,A[1]=0,A[2]=0,A[3]=1,A}const S=P.create(),F=P.create(),L=P.create();function N(M,A,c){const r=c??new a(4),f=P.dot(M,A);return f<-.999999?(P.cross(F,M,S),P.len(S)<1e-6&&P.cross(L,M,S),P.normalize(S,S),V(S,Math.PI,r),r):f>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(P.cross(M,A,S),r[0]=S[0],r[1]=S[1],r[2]=S[2],r[3]=1+f,v(r,r))}const O=new a(4),G=new a(4);function Y(M,A,c,r,f,p){const m=p??new a(4);return en(M,r,f,O),en(A,c,f,G),en(O,G,2*f*(1-f),m),m}return{create:E,fromValues:Z,set:W,fromAxisAngle:V,toAxisAngle:fn,angle:ln,multiply:qn,mul:Gn,rotateX:Bn,rotateY:dn,rotateZ:In,slerp:en,inverse:Tn,conjugate:Dn,fromMat:yn,fromEuler:En,copy:xn,clone:wn,add:Fn,subtract:_n,sub:zn,mulScalar:Un,scale:An,divScalar:vn,dot:C,lerp:Ln,length:X,len:Q,lengthSq:$,lenSq:l,normalize:v,equalsApproximately:g,equals:z,identity:T,rotationTo:N,sqlerp:Y}}const ht=new Map;function Wt(a){let P=ht.get(a);return P||(P=Nt(a),ht.set(a,P)),P}function Ht(a){function P(c,r,f,p){const m=new a(4);return c!==void 0&&(m[0]=c,r!==void 0&&(m[1]=r,f!==void 0&&(m[2]=f,p!==void 0&&(m[3]=p)))),m}const E=P;function Z(c,r,f,p,m){const n=m??new a(4);return n[0]=c,n[1]=r,n[2]=f,n[3]=p,n}function W(c,r){const f=r??new a(4);return f[0]=Math.ceil(c[0]),f[1]=Math.ceil(c[1]),f[2]=Math.ceil(c[2]),f[3]=Math.ceil(c[3]),f}function V(c,r){const f=r??new a(4);return f[0]=Math.floor(c[0]),f[1]=Math.floor(c[1]),f[2]=Math.floor(c[2]),f[3]=Math.floor(c[3]),f}function fn(c,r){const f=r??new a(4);return f[0]=Math.round(c[0]),f[1]=Math.round(c[1]),f[2]=Math.round(c[2]),f[3]=Math.round(c[3]),f}function ln(c,r=0,f=1,p){const m=p??new a(4);return m[0]=Math.min(f,Math.max(r,c[0])),m[1]=Math.min(f,Math.max(r,c[1])),m[2]=Math.min(f,Math.max(r,c[2])),m[3]=Math.min(f,Math.max(r,c[3])),m}function qn(c,r,f){const p=f??new a(4);return p[0]=c[0]+r[0],p[1]=c[1]+r[1],p[2]=c[2]+r[2],p[3]=c[3]+r[3],p}function Gn(c,r,f,p){const m=p??new a(4);return m[0]=c[0]+r[0]*f,m[1]=c[1]+r[1]*f,m[2]=c[2]+r[2]*f,m[3]=c[3]+r[3]*f,m}function Bn(c,r,f){const p=f??new a(4);return p[0]=c[0]-r[0],p[1]=c[1]-r[1],p[2]=c[2]-r[2],p[3]=c[3]-r[3],p}const dn=Bn;function In(c,r){return Math.abs(c[0]-r[0])<b&&Math.abs(c[1]-r[1])<b&&Math.abs(c[2]-r[2])<b&&Math.abs(c[3]-r[3])<b}function en(c,r){return c[0]===r[0]&&c[1]===r[1]&&c[2]===r[2]&&c[3]===r[3]}function Tn(c,r,f,p){const m=p??new a(4);return m[0]=c[0]+f*(r[0]-c[0]),m[1]=c[1]+f*(r[1]-c[1]),m[2]=c[2]+f*(r[2]-c[2]),m[3]=c[3]+f*(r[3]-c[3]),m}function Dn(c,r,f,p){const m=p??new a(4);return m[0]=c[0]+f[0]*(r[0]-c[0]),m[1]=c[1]+f[1]*(r[1]-c[1]),m[2]=c[2]+f[2]*(r[2]-c[2]),m[3]=c[3]+f[3]*(r[3]-c[3]),m}function yn(c,r,f){const p=f??new a(4);return p[0]=Math.max(c[0],r[0]),p[1]=Math.max(c[1],r[1]),p[2]=Math.max(c[2],r[2]),p[3]=Math.max(c[3],r[3]),p}function En(c,r,f){const p=f??new a(4);return p[0]=Math.min(c[0],r[0]),p[1]=Math.min(c[1],r[1]),p[2]=Math.min(c[2],r[2]),p[3]=Math.min(c[3],r[3]),p}function xn(c,r,f){const p=f??new a(4);return p[0]=c[0]*r,p[1]=c[1]*r,p[2]=c[2]*r,p[3]=c[3]*r,p}const wn=xn;function Fn(c,r,f){const p=f??new a(4);return p[0]=c[0]/r,p[1]=c[1]/r,p[2]=c[2]/r,p[3]=c[3]/r,p}function _n(c,r){const f=r??new a(4);return f[0]=1/c[0],f[1]=1/c[1],f[2]=1/c[2],f[3]=1/c[3],f}const zn=_n;function Un(c,r){return c[0]*r[0]+c[1]*r[1]+c[2]*r[2]+c[3]*r[3]}function An(c){const r=c[0],f=c[1],p=c[2],m=c[3];return Math.sqrt(r*r+f*f+p*p+m*m)}const vn=An;function C(c){const r=c[0],f=c[1],p=c[2],m=c[3];return r*r+f*f+p*p+m*m}const Ln=C;function X(c,r){const f=c[0]-r[0],p=c[1]-r[1],m=c[2]-r[2],n=c[3]-r[3];return Math.sqrt(f*f+p*p+m*m+n*n)}const Q=X;function $(c,r){const f=c[0]-r[0],p=c[1]-r[1],m=c[2]-r[2],n=c[3]-r[3];return f*f+p*p+m*m+n*n}const l=$;function v(c,r){const f=r??new a(4),p=c[0],m=c[1],n=c[2],s=c[3],t=Math.sqrt(p*p+m*m+n*n+s*s);return t>1e-5?(f[0]=p/t,f[1]=m/t,f[2]=n/t,f[3]=s/t):(f[0]=0,f[1]=0,f[2]=0,f[3]=0),f}function g(c,r){const f=r??new a(4);return f[0]=-c[0],f[1]=-c[1],f[2]=-c[2],f[3]=-c[3],f}function z(c,r){const f=r??new a(4);return f[0]=c[0],f[1]=c[1],f[2]=c[2],f[3]=c[3],f}const T=z;function S(c,r,f){const p=f??new a(4);return p[0]=c[0]*r[0],p[1]=c[1]*r[1],p[2]=c[2]*r[2],p[3]=c[3]*r[3],p}const F=S;function L(c,r,f){const p=f??new a(4);return p[0]=c[0]/r[0],p[1]=c[1]/r[1],p[2]=c[2]/r[2],p[3]=c[3]/r[3],p}const N=L;function O(c){const r=c??new a(4);return r[0]=0,r[1]=0,r[2]=0,r[3]=0,r}function G(c,r,f){const p=f??new a(4),m=c[0],n=c[1],s=c[2],t=c[3];return p[0]=r[0]*m+r[4]*n+r[8]*s+r[12]*t,p[1]=r[1]*m+r[5]*n+r[9]*s+r[13]*t,p[2]=r[2]*m+r[6]*n+r[10]*s+r[14]*t,p[3]=r[3]*m+r[7]*n+r[11]*s+r[15]*t,p}function Y(c,r,f){const p=f??new a(4);return v(c,p),xn(p,r,p)}function M(c,r,f){const p=f??new a(4);return An(c)>r?Y(c,r,p):z(c,p)}function A(c,r,f){const p=f??new a(4);return Tn(c,r,.5,p)}return{create:P,fromValues:E,set:Z,ceil:W,floor:V,round:fn,clamp:ln,add:qn,addScaled:Gn,subtract:Bn,sub:dn,equalsApproximately:In,equals:en,lerp:Tn,lerpV:Dn,max:yn,min:En,mulScalar:xn,scale:wn,divScalar:Fn,inverse:_n,invert:zn,dot:Un,length:An,len:vn,lengthSq:C,lenSq:Ln,distance:X,dist:Q,distanceSq:$,distSq:l,normalize:v,negate:g,copy:z,clone:T,multiply:S,mul:F,divide:L,div:N,zero:O,transformMat4:G,setLength:Y,truncate:M,midpoint:A}}const Mt=new Map;function Xt(a){let P=Mt.get(a);return P||(P=Ht(a),Mt.set(a,P)),P}function st(a,P,E,Z,W,V){return{mat4:$t(a),mat3:Vt(P),quat:Wt(E),vec2:_t(Z),vec3:ot(W),vec4:Xt(V)}}const{mat4:bn,mat3:ie,quat:ue,vec2:ae,vec3:Yt,vec4:fe}=st(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array);st(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array);st(Et,Array,Array,Array,Array,Array);const Cn=`//////////////////////////////////////////////////////////////////////////////// | |
// Utilities | |
//////////////////////////////////////////////////////////////////////////////// | |
var<private> rand_seed : vec2f; | |
fn init_rand(invocation_id : u32, seed : vec4f) { | |
rand_seed = seed.xz; | |
rand_seed = fract(rand_seed * cos(35.456+f32(invocation_id) * seed.yw)); | |
rand_seed = fract(rand_seed * cos(41.235+f32(invocation_id) * seed.xw)); | |
} | |
fn rand() -> f32 { | |
rand_seed.x = fract(cos(dot(rand_seed, vec2f(23.14077926, 232.61690225))) * 136.8168); | |
rand_seed.y = fract(cos(dot(rand_seed, vec2f(54.47856553, 345.84153136))) * 534.7645); | |
return rand_seed.y; | |
} | |
//////////////////////////////////////////////////////////////////////////////// | |
// Vertex shader | |
//////////////////////////////////////////////////////////////////////////////// | |
struct RenderParams { | |
modelViewProjectionMatrix : mat4x4f, | |
right : vec3f, | |
up : vec3f | |
} | |
@binding(0) @group(0) var<uniform> render_params : RenderParams; | |
struct VertexInput { | |
@location(0) position : vec3f, | |
@location(1) color : vec4f, | |
@location(2) quad_pos : vec2f, // -1..+1 | |
} | |
struct VertexOutput { | |
@builtin(position) position : vec4f, | |
@location(0) color : vec4f, | |
@location(1) quad_pos : vec2f, // -1..+1 | |
} | |
@vertex | |
fn vs_main(in : VertexInput) -> VertexOutput { | |
var quad_pos = mat2x3f(render_params.right, render_params.up) * in.quad_pos; | |
var position = in.position + quad_pos * 0.005; | |
var out : VertexOutput; | |
out.position = render_params.modelViewProjectionMatrix * vec4f(position, 1.0); | |
out.color = in.color; | |
out.quad_pos = in.quad_pos; | |
return out; | |
} | |
//////////////////////////////////////////////////////////////////////////////// | |
// Fragment shader | |
//////////////////////////////////////////////////////////////////////////////// | |
@fragment | |
fn fs_main(in : VertexOutput) -> @location(0) vec4f { | |
var color = in.color; | |
// Apply a circular particle alpha mask | |
color.a = color.a * max(1.0 - length(in.quad_pos), 0.0); | |
return color; | |
} | |
//////////////////////////////////////////////////////////////////////////////// | |
// Simulation Compute shader | |
//////////////////////////////////////////////////////////////////////////////// | |
struct SimulationParams { | |
deltaTime : f32, | |
brightnessFactor : f32, | |
seed : vec4f, | |
} | |
struct Particle { | |
position : vec3f, | |
lifetime : f32, | |
color : vec4f, | |
velocity : vec3f, | |
} | |
struct Particles { | |
particles : array<Particle>, | |
} | |
@binding(0) @group(0) var<uniform> sim_params : SimulationParams; | |
@binding(1) @group(0) var<storage, read_write> data : Particles; | |
@binding(2) @group(0) var texture : texture_2d<f32>; | |
@compute @workgroup_size(64) | |
fn simulate(@builtin(global_invocation_id) global_invocation_id : vec3u) { | |
let idx = global_invocation_id.x; | |
init_rand(idx, sim_params.seed); | |
var particle = data.particles[idx]; | |
// Apply gravity | |
particle.velocity.z = particle.velocity.z - sim_params.deltaTime * 0.5; | |
// Basic velocity integration | |
particle.position = particle.position + sim_params.deltaTime * particle.velocity; | |
// Age each particle. Fade out before vanishing. | |
particle.lifetime = particle.lifetime - sim_params.deltaTime; | |
particle.color.a = smoothstep(0.0, 0.5, particle.lifetime); | |
// If the lifetime has gone negative, then the particle is dead and should be | |
// respawned. | |
if (particle.lifetime < 0.0) { | |
// Use the probability map to find where the particle should be spawned. | |
// Starting with the 1x1 mip level. | |
var coord : vec2i; | |
for (var level = u32(textureNumLevels(texture) - 1); level > 0; level--) { | |
// Load the probability value from the mip-level | |
// Generate a random number and using the probabilty values, pick the | |
// next texel in the next largest mip level: | |
// | |
// 0.0 probabilites.r probabilites.g probabilites.b 1.0 | |
// | | | | | | |
// | TOP-LEFT | TOP-RIGHT | BOTTOM-LEFT | BOTTOM_RIGHT | | |
// | |
let probabilites = textureLoad(texture, coord, level); | |
let value = vec4f(rand()); | |
let mask = (value >= vec4f(0.0, probabilites.xyz)) & (value < probabilites); | |
coord = coord * 2; | |
coord.x = coord.x + select(0, 1, any(mask.yw)); // x y | |
coord.y = coord.y + select(0, 1, any(mask.zw)); // z w | |
} | |
let uv = vec2f(coord) / vec2f(textureDimensions(texture)); | |
particle.position = vec3f((uv - 0.5) * 3.0 * vec2f(1.0, -1.0), 0.0); | |
particle.color = textureLoad(texture, coord, 0); | |
particle.color.r *= sim_params.brightnessFactor; | |
particle.color.g *= sim_params.brightnessFactor; | |
particle.color.b *= sim_params.brightnessFactor; | |
particle.velocity.x = (rand() - 0.5) * 0.1; | |
particle.velocity.y = (rand() - 0.5) * 0.1; | |
particle.velocity.z = rand() * 0.3; | |
particle.lifetime = 0.5 + rand() * 3.0; | |
} | |
// Store the new particle value | |
data.particles[idx] = particle; | |
} | |
`,zt=`struct UBO { | |
width : u32, | |
} | |
struct Buffer { | |
weights : array<f32>, | |
} | |
@binding(0) @group(0) var<uniform> ubo : UBO; | |
@binding(1) @group(0) var<storage, read> buf_in : Buffer; | |
@binding(2) @group(0) var<storage, read_write> buf_out : Buffer; | |
@binding(3) @group(0) var tex_in : texture_2d<f32>; | |
@binding(3) @group(0) var tex_out : texture_storage_2d<rgba8unorm, write>; | |
//////////////////////////////////////////////////////////////////////////////// | |
// import_level | |
// | |
// Loads the alpha channel from a texel of the source image, and writes it to | |
// the buf_out.weights. | |
//////////////////////////////////////////////////////////////////////////////// | |
@compute @workgroup_size(64) | |
fn import_level(@builtin(global_invocation_id) coord : vec3u) { | |
_ = &buf_in; | |
let offset = coord.x + coord.y * ubo.width; | |
buf_out.weights[offset] = textureLoad(tex_in, vec2i(coord.xy), 0).w; | |
} | |
//////////////////////////////////////////////////////////////////////////////// | |
// export_level | |
// | |
// Loads 4 f32 weight values from buf_in.weights, and stores summed value into | |
// buf_out.weights, along with the calculated 'probabilty' vec4 values into the | |
// mip level of tex_out. See simulate() in particle.wgsl to understand the | |
// probability logic. | |
//////////////////////////////////////////////////////////////////////////////// | |
@compute @workgroup_size(64) | |
fn export_level(@builtin(global_invocation_id) coord : vec3u) { | |
if (all(coord.xy < vec2u(textureDimensions(tex_out)))) { | |
let dst_offset = coord.x + coord.y * ubo.width; | |
let src_offset = coord.x*2u + coord.y*2u * ubo.width; | |
let a = buf_in.weights[src_offset + 0u]; | |
let b = buf_in.weights[src_offset + 1u]; | |
let c = buf_in.weights[src_offset + 0u + ubo.width]; | |
let d = buf_in.weights[src_offset + 1u + ubo.width]; | |
let sum = dot(vec4f(a, b, c, d), vec4f(1.0)); | |
buf_out.weights[dst_offset] = sum / 4.0; | |
let probabilities = vec4f(a, a+b, a+b+c, sum) / max(sum, 0.0001); | |
textureStore(tex_out, vec2i(coord.xy), probabilities); | |
} | |
} | |
`;function Zt(a){"gpu"in navigator||$n("navigator.gpu is not defined - WebGPU not available in this browser"),a||$n("requestAdapter returned null - this sample can't run on this system")}function jt(a,P){if(!P){Zt(a),$n("Unable to get a device for an unknown reason");return}P.lost.then(E=>{$n(`Device lost ("${E.reason}"): | |
${E.message}`)}),P.onuncapturederror=E=>{$n(`Uncaptured error: | |
${E.error.message}`)}}const $n=(()=>{function a(){if(typeof document>"u")return{show(V){console.error(V)}};const E=document.createElement("dialog");E.close(),document.body.append(E);const Z=document.createElement("pre");Z.style.whiteSpace="pre-wrap",E.append(Z);const W=document.createElement("button");return W.textContent="OK",W.onclick=()=>E.close(),E.append(W),{show(V){E.open||(Z.textContent=V,E.showModal())}}}let P;return E=>{throw P||(P=a()),P.show(E),new Error(E)}})(),Kn=5e4,Qt=0,Kt=4*4,ct=3*4+1*4+4*4+3*4+1*4+0,Vn=document.querySelector("canvas"),At=await navigator.gpu?.requestAdapter(),j=await At?.requestDevice();jt(At,j);const vt=Vn.getContext("webgpu"),Pt=window.devicePixelRatio;Vn.width=Vn.clientWidth*Pt;Vn.height=Vn.clientHeight*Pt;const mt="rgba16float";function Jt(){vt.configure({device:j,format:mt,toneMapping:{mode:et.toneMappingMode},alphaMode:"premultiplied"})}const St=j.createBuffer({size:Kn*ct,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE}),qt=j.createRenderPipeline({layout:"auto",vertex:{module:j.createShaderModule({code:Cn}),buffers:[{arrayStride:ct,stepMode:"instance",attributes:[{shaderLocation:0,offset:Qt,format:"float32x3"},{shaderLocation:1,offset:Kt,format:"float32x4"}]},{arrayStride:2*4,stepMode:"vertex",attributes:[{shaderLocation:2,offset:0,format:"float32x2"}]}]},fragment:{module:j.createShaderModule({code:Cn}),targets:[{format:mt,blend:{color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"},alpha:{srcFactor:"zero",dstFactor:"one",operation:"add"}}}]},primitive:{topology:"triangle-list"},depthStencil:{depthWriteEnabled:!1,depthCompare:"less",format:"depth24plus"}}),kt=j.createTexture({size:[Vn.width,Vn.height],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT}),Ct=4*4*4+3*4+4+3*4+4+0,Bt=j.createBuffer({size:Ct,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),ne=j.createBindGroup({layout:qt.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:Bt}}]}),kn={colorAttachments:[{view:void 0,clearValue:[0,0,0,1],loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:kt.createView(),depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}},rt=j.createBuffer({size:6*2*4,usage:GPUBufferUsage.VERTEX,mappedAtCreation:!0}),te=[-1,-1,1,-1,-1,1,-1,1,1,-1,1,1];new Float32Array(rt.getMappedRange()).set(te);rt.unmap();let Jn,Rn=1,Nn=1,nt=1;{const a=await fetch("./5m.png"),P=await createImageBitmap(await a.blob());for(;Rn<P.width||Nn<P.height;)Rn*=2,Nn*=2,nt++;Jn=j.createTexture({size:[P.width,P.height,1],mipLevelCount:nt,format:"rgba8unorm",usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT}),j.queue.copyExternalImageToTexture({source:P},{texture:Jn},[P.width,P.height])}const gt=j.createComputePipeline({layout:"auto",compute:{module:j.createShaderModule({code:zt}),entryPoint:"import_level"}}),xt=j.createComputePipeline({layout:"auto",compute:{module:j.createShaderModule({code:zt}),entryPoint:"export_level"}}),ee=1*4+3*4+0,Tt=j.createBuffer({size:ee,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),Dt=j.createBuffer({size:Rn*Nn*4,usage:GPUBufferUsage.STORAGE}),yt=j.createBuffer({size:Rn*Nn*4,usage:GPUBufferUsage.STORAGE});j.queue.writeBuffer(Tt,0,new Int32Array([Rn]));const tt=j.createCommandEncoder();for(let a=0;a<nt;a++){const P=Rn>>a,E=Nn>>a,Z=a==0?gt.getBindGroupLayout(0):xt.getBindGroupLayout(0),W=j.createBindGroup({layout:Z,entries:[{binding:0,resource:{buffer:Tt}},{binding:1,resource:{buffer:a&1?Dt:yt}},{binding:2,resource:{buffer:a&1?yt:Dt}},{binding:3,resource:Jn.createView({format:"rgba8unorm",dimension:"2d",baseMipLevel:a,mipLevelCount:1})}]});if(a==0){const V=tt.beginComputePass();V.setPipeline(gt),V.setBindGroup(0,W),V.dispatchWorkgroups(Math.ceil(P/64),E),V.end()}else{const V=tt.beginComputePass();V.setPipeline(xt),V.setBindGroup(0,W),V.dispatchWorkgroups(Math.ceil(P/64),E),V.end()}}j.queue.submit([tt.finish()]);const et={simulate:!0,deltaTime:.04,toneMappingMode:"standard",brightnessFactor:1},oe=1*4+1*4+3*4+4*4+0,Ut=j.createBuffer({size:oe,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),Ot=j.createComputePipeline({layout:"auto",compute:{module:j.createShaderModule({code:Cn}),entryPoint:"simulate"}}),se=j.createBindGroup({layout:Ot.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:Ut}},{binding:1,resource:{buffer:St,offset:0,size:Kn*ct}},{binding:2,resource:Jn.createView()}]}),ce=Vn.width/Vn.height,re=bn.perspective(2*Math.PI/5,ce,1,100),On=bn.create(),tn=bn.create();function Gt(){j.queue.writeBuffer(Ut,0,new Float32Array([et.deltaTime,et.brightnessFactor,0,0,0,Math.random()*100,Math.random()*100,1+Math.random(),1+Math.random()])),bn.identity(On),bn.translate(On,Yt.fromValues(0,0,-3),On),bn.rotateX(On,Math.PI*-.2,On),bn.multiply(re,On,tn),j.queue.writeBuffer(Bt,0,new Float32Array([tn[0],tn[1],tn[2],tn[3],tn[4],tn[5],tn[6],tn[7],tn[8],tn[9],tn[10],tn[11],tn[12],tn[13],tn[14],tn[15],On[0],On[4],On[8],0,On[1],On[5],On[9],0]));const a=vt.getCurrentTexture(),P=Array.from(kn.colorAttachments);P[0].view=a.createView(),kn.colorAttachments=P;const E=j.createCommandEncoder();{const Z=E.beginComputePass();Z.setPipeline(Ot),Z.setBindGroup(0,se),Z.dispatchWorkgroups(Math.ceil(Kn/64)),Z.end()}{const Z=E.beginRenderPass(kn);Z.setPipeline(qt),Z.setBindGroup(0,ne),Z.setVertexBuffer(0,St),Z.setVertexBuffer(1,rt),Z.draw(6,Kn,0,0),Z.end()}j.queue.submit([E.finish()]),requestAnimationFrame(Gt)}Jt();requestAnimationFrame(Gt); | |