@luma.gl/shadertools 9.0.19 → 9.0.21
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.
- package/dist/dist.dev.js +107 -206
- package/dist/dist.min.js +92 -148
- package/dist/index.cjs +105 -148
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +2 -3
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +7 -3
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +30 -6
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts +13 -6
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms.js +41 -33
- package/dist/modules/lighting/phong-material/phong-material.d.ts +4 -4
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +4 -0
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +0 -39
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +7 -65
- package/package.json +2 -2
- package/src/index.ts +2 -2
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +11 -8
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +32 -10
- package/src/modules/lighting/lights/lighting-uniforms.ts +61 -40
- package/src/modules/lighting/phong-material/phong-material.ts +9 -6
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -89
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +0 -42
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +0 -110
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -144
package/dist/dist.min.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
5
|
else if (typeof exports === 'object') exports['luma'] = factory();
|
|
6
6
|
else root['luma'] = factory();})(globalThis, function () {
|
|
7
|
-
"use strict";var __exports__=(()=>{var to=Object.create;var he=Object.defineProperty;var no=Object.getOwnPropertyDescriptor;var ro=Object.getOwnPropertyNames;var oo=Object.getPrototypeOf,io=Object.prototype.hasOwnProperty;var so=(n,e,t)=>e in n?he(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var ao=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),co=(n,e)=>{for(var t in e)he(n,t,{get:e[t],enumerable:!0})},we=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ro(e))!io.call(n,o)&&o!==t&&he(n,o,{get:()=>e[o],enumerable:!(r=no(e,o))||r.enumerable});return n},Le=(n,e,t)=>(we(n,e,"default"),t&&we(t,e,"default")),
|
|
7
|
+
"use strict";var __exports__=(()=>{var to=Object.create;var he=Object.defineProperty;var no=Object.getOwnPropertyDescriptor;var ro=Object.getOwnPropertyNames;var oo=Object.getPrototypeOf,io=Object.prototype.hasOwnProperty;var so=(n,e,t)=>e in n?he(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var ao=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),co=(n,e)=>{for(var t in e)he(n,t,{get:e[t],enumerable:!0})},we=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ro(e))!io.call(n,o)&&o!==t&&he(n,o,{get:()=>e[o],enumerable:!(r=no(e,o))||r.enumerable});return n},Le=(n,e,t)=>(we(n,e,"default"),t&&we(t,e,"default")),rt=(n,e,t)=>(t=n!=null?to(oo(n)):{},we(e||!n||!n.__esModule?he(t,"default",{value:n,enumerable:!0}):t,n)),lo=n=>we(he({},"__esModule",{value:!0}),n);var pn=(n,e,t)=>(so(n,typeof e!="symbol"?e+"":e,t),t);var ke=ao((Yi,dn)=>{dn.exports=globalThis.luma});var Pe={};co(Pe,{ShaderAssembler:()=>me,ShaderModuleInstance:()=>C,_ShaderModuleInstance:()=>C,_getDependencyGraph:()=>Se,_resolveModules:()=>ne,_warp:()=>fe,assembleShaderPairGLSL:()=>Te,brightnessContrast:()=>Jn,bulgePinch:()=>dr,capitalize:()=>Z,colorHalftone:()=>lr,combineInjects:()=>Ln,convertToVec4:()=>_t,denoise:()=>er,dirlight:()=>Kt,dirlight1:()=>Wr,dotScreen:()=>fr,edgeWork:()=>ur,fp32:()=>Hn,fp64:()=>Ar,fp64arithmetic:()=>nn,fxaa:()=>gr,generateShaderForModule:()=>Bn,geometry1:()=>yr,getPassthroughFS:()=>Un,getQualifierDetails:()=>On,getShaderInfo:()=>Ne,getShaderLayoutFromWGSL:()=>Vn,glsl:()=>mn,gouraudLighting:()=>$r,gouraudMaterial:()=>Zt,hexagonalPixelate:()=>_r,hueSaturation:()=>tr,ink:()=>hr,lighting:()=>Q,lights1:()=>te,magnify:()=>pr,noise:()=>nr,normalizeShaderModule:()=>Rn,pbr:()=>eo,pbrMaterial:()=>Zn,phongLighting:()=>Kr,phongMaterial:()=>Jt,picking:()=>Gn,project1:()=>nt,random:()=>q,sepia:()=>rr,swirl:()=>mr,tiltShift:()=>sr,triangleBlur:()=>ar,typeToChannelCount:()=>Dn,typeToChannelSuffix:()=>zn,vibrance:()=>or,vignette:()=>ir,zoomBlur:()=>cr});Le(Pe,rt(ke(),1));var mn=n=>`${n}`;function D(n,e){if(!n)throw new Error(e||"shadertools: assertion failed.")}var ot={number:{type:"number",validate(n,e){return Number.isFinite(n)&&typeof e=="object"&&(e.max===void 0||n<=e.max)&&(e.min===void 0||n>=e.min)}},array:{type:"array",validate(n,e){return Array.isArray(n)||ArrayBuffer.isView(n)}}};function xn(n){let e={};for(let[t,r]of Object.entries(n))e[t]=fo(r);return e}function vn(n,e,t){let r={};for(let[o,i]of Object.entries(e))n&&o in n&&!i.private?(i.validate&&D(i.validate(n[o],i),`${t}: invalid ${o}`),r[o]=n[o]):r[o]=i.value;return r}function fo(n){let e=gn(n);if(e!=="object")return{value:n,...ot[e],type:e};if(typeof n=="object")return n?n.type!==void 0?{...n,...ot[n.type],type:n.type}:n.value===void 0?{type:"object",value:n}:(e=gn(n.value),{...n,...ot[e],type:e}):{type:"object",value:null};throw new Error("props")}function gn(n){return Array.isArray(n)||ArrayBuffer.isView(n)?"array":typeof n}var An=`#ifdef MODULE_LOGDEPTH
|
|
8
8
|
logdepth_adjustPosition(gl_Position);
|
|
9
9
|
#endif
|
|
10
|
-
`,
|
|
10
|
+
`,yn=`#ifdef MODULE_MATERIAL
|
|
11
11
|
gl_FragColor = material_filterColor(gl_FragColor);
|
|
12
12
|
#endif
|
|
13
13
|
#ifdef MODULE_LIGHTING
|
|
@@ -23,15 +23,15 @@ gl_FragColor = picking_filterPickingColor(gl_FragColor);
|
|
|
23
23
|
#ifdef MODULE_LOGDEPTH
|
|
24
24
|
logdepth_setFragDepth();
|
|
25
25
|
#endif
|
|
26
|
-
`;var uo={vertex:
|
|
26
|
+
`;var uo={vertex:An,fragment:yn},bn=/void\s+main\s*\([^)]*\)\s*\{\n?/,Pn=/}\n?[^{}]*$/,it=[],pe="__LUMA_INJECT_DECLARATIONS__";function wn(n){let e={vertex:{},fragment:{}};for(let t in n){let r=n[t],o=_o(t);typeof r=="string"&&(r={order:0,injection:r}),e[o][t]=r}return e}function _o(n){let e=n.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function de(n,e,t,r=!1){let o=e==="vertex";for(let i in t){let a=t[i];a.sort((u,h)=>u.order-h.order),it.length=a.length;for(let u=0,h=a.length;u<h;++u)it[u]=a[u].injection;let c=`${it.join(`
|
|
27
27
|
`)}
|
|
28
|
-
`;switch(i){case"vs:#decl":o&&(n=n.replace(pe,c));break;case"vs:#main-start":o&&(n=n.replace(
|
|
29
|
-
${t[r]}`:t[r]}),e}var ho=1,C=class{name;vs;fs;getModuleUniforms;dependencies;deprecations;defines;injections;uniforms={};uniformTypes={};static instantiateModules(e){return e.map(t=>{if(t instanceof C)return t;D(typeof t!="string",`Shader module use by name is deprecated. Import shader module '${JSON.stringify(t)}' and use it directly.`),t.name||(console.warn("shader module has no name"),t.name=`shader-module-${ho++}`);let r=new C(t);return r.dependencies=C.instantiateModules(t.dependencies||[]),r})}constructor(e){let{name:t,vs:r,fs:o,dependencies:i=[],uniformTypes:a={},uniformPropTypes:c={},getUniforms:u,deprecations:h=[],defines:p={},inject:d={}}=e;D(typeof t=="string"),this.name=t,this.vs=r,this.fs=o,this.getModuleUniforms=u,this.dependencies=C.instantiateModules(i),this.deprecations=this._parseDeprecationDefinitions(h),this.defines=p,this.injections=
|
|
28
|
+
`;switch(i){case"vs:#decl":o&&(n=n.replace(pe,c));break;case"vs:#main-start":o&&(n=n.replace(bn,u=>u+c));break;case"vs:#main-end":o&&(n=n.replace(Pn,u=>c+u));break;case"fs:#decl":o||(n=n.replace(pe,c));break;case"fs:#main-start":o||(n=n.replace(bn,u=>u+c));break;case"fs:#main-end":o||(n=n.replace(Pn,u=>c+u));break;default:n=n.replace(i,u=>u+c)}}return n=n.replace(pe,""),r&&(n=n.replace(/\}\s*$/,i=>i+uo[e])),n}function Ln(n){let e={};return D(Array.isArray(n)&&n.length>1),n.forEach(t=>{for(let r in t)e[r]=e[r]?`${e[r]}
|
|
29
|
+
${t[r]}`:t[r]}),e}var ho=1,C=class{name;vs;fs;getModuleUniforms;dependencies;deprecations;defines;injections;uniforms={};uniformTypes={};static instantiateModules(e){return e.map(t=>{if(t instanceof C)return t;D(typeof t!="string",`Shader module use by name is deprecated. Import shader module '${JSON.stringify(t)}' and use it directly.`),t.name||(console.warn("shader module has no name"),t.name=`shader-module-${ho++}`);let r=new C(t);return r.dependencies=C.instantiateModules(t.dependencies||[]),r})}constructor(e){let{name:t,vs:r,fs:o,dependencies:i=[],uniformTypes:a={},uniformPropTypes:c={},getUniforms:u,deprecations:h=[],defines:p={},inject:d={}}=e;D(typeof t=="string"),this.name=t,this.vs=r,this.fs=o,this.getModuleUniforms=u,this.dependencies=C.instantiateModules(i),this.deprecations=this._parseDeprecationDefinitions(h),this.defines=p,this.injections=wn(d),this.uniformTypes=a,c&&(this.uniforms=xn(c))}getModuleSource(e){let t;switch(e){case"vertex":t=this.vs||"";break;case"fragment":t=this.fs||"";break;default:D(!1)}let r=this.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");return`// ----- MODULE ${this.name} ---------------
|
|
30
30
|
|
|
31
31
|
#define MODULE_${r}
|
|
32
32
|
${t}
|
|
33
33
|
|
|
34
|
-
`}getUniforms(e,t){return this.getModuleUniforms?this.getModuleUniforms(e,t):
|
|
34
|
+
`}getUniforms(e,t){return this.getModuleUniforms?this.getModuleUniforms(e,t):vn(e,this.uniforms,this.name)}getDefines(){return this.defines}checkDeprecations(e,t){this.deprecations.forEach(r=>{r.regex?.test(e)&&(r.deprecated?t.deprecated(r.old,r.new)():t.removed(r.old,r.new)())})}_parseDeprecationDefinitions(e){return e.forEach(t=>{switch(t.type){case"function":t.regex=new RegExp(`\\b${t.old}\\(`);break;default:t.regex=new RegExp(`${t.type} ${t.old};`)}}),e}_defaultGetUniforms(e={}){let t={},r=this.uniforms;for(let o in r){let i=r[o];o in e&&!i.private?(i.validate&&D(i.validate(e[o],i),`${this.name}: invalid ${o}`),t[o]=e[o]):t[o]=i.value}return t}};function st(n){if(n.source&&n.platformInfo.type==="webgpu")return{...n,vs:void 0,fs:void 0};if(!n.vs)throw new Error("no vertex shader");let e=kn(n.platformInfo,n.vs),t;return n.fs&&(t=kn(n.platformInfo,n.fs)),{...n,vs:e,fs:t}}function kn(n,e){if(typeof e=="string")return e;switch(n.type){case"webgpu":if(e?.wgsl)return e.wgsl;throw new Error("WebGPU does not support GLSL shaders");default:if(e?.glsl)return e.glsl;throw new Error("WebGL does not support WGSL shaders")}}function ne(n){let e=C.instantiateModules(n);return po(e)}function po(n){let e={},t={};return Se({modules:n,level:0,moduleMap:e,moduleDepth:t}),Object.keys(t).sort((r,o)=>t[o]-t[r]).map(r=>e[r])}function Se(n){let{modules:e,level:t,moduleMap:r,moduleDepth:o}=n;if(t>=5)throw new Error("Possible loop in shader dependency graph");for(let i of e)r[i.name]=i,(o[i.name]===void 0||o[i.name]<t)&&(o[i.name]=t);for(let i of e)i.dependencies&&Se({modules:i.dependencies,level:t+1,moduleMap:r,moduleDepth:o})}function Sn(n){switch(n?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
|
|
35
35
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
36
36
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
37
37
|
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
@@ -46,22 +46,22 @@ ${t}
|
|
|
46
46
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
47
47
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
48
48
|
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
49
|
-
`}}function
|
|
50
|
-
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],mo=[...
|
|
49
|
+
`}}function Tn(n,e){if(Number(n.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return n=Nn(n,mo),n;case"fragment":return n=Nn(n,go),n;default:throw new Error(e)}}var En=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
|
|
50
|
+
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],mo=[...En,[at("attribute"),"in $1"],[at("varying"),"out $1"]],go=[...En,[at("varying"),"in $1"]];function Nn(n,e){for(let[t,r]of e)n=n.replace(t,r);return n}function at(n){return new RegExp(`\\b${n}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function ct(n,e){let t="";for(let r in n){let o=n[r];if(t+=`void ${o.signature} {
|
|
51
51
|
`,o.header&&(t+=` ${o.header}`),e[r]){let i=e[r];i.sort((a,c)=>a.order-c.order);for(let a of i)t+=` ${a.injection}
|
|
52
52
|
`}o.footer&&(t+=` ${o.footer}`),t+=`}
|
|
53
|
-
`}return t}function
|
|
53
|
+
`}return t}function lt(n){let e={vertex:{},fragment:{}};for(let t of n){let r,o;typeof t!="string"?(r=t,o=r.hook):(r={},o=t),o=o.trim();let[i,a]=o.split(":"),c=o.replace(/\(.+/,""),u=Object.assign(r,{signature:a});switch(i){case"vs":e.vertex[c]=u;break;case"fs":e.fragment[c]=u;break;default:throw new Error(i)}}return e}function Ne(n,e){return{name:xo(n,e),language:"glsl",version:vo(n)}}function xo(n,e="unnamed"){let r=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(n);return r?r[1]:e}function vo(n){let e=100,t=n.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){let r=parseInt(t[1],10);Number.isFinite(r)&&(e=r)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}var In=`
|
|
54
54
|
|
|
55
55
|
${pe}
|
|
56
56
|
`,Ao=`precision highp float;
|
|
57
|
-
`;function
|
|
57
|
+
`;function Fn(n){let e=ne(n.modules||[]);return{source:ft(n.platformInfo,{...n,source:n.source,stage:"vertex",modules:e}),getUniforms:ut(e)}}function Cn(n){let e=ne(n.modules||[]);return{vs:ft(n.platformInfo,{...n,source:n.vs,stage:"vertex",modules:e}),fs:ft(n.platformInfo,{...n,source:n.fs,stage:"fragment",modules:e}),getUniforms:ut(e)}}function Te(n){let{vs:e,fs:t}=n,r=ne(n.modules||[]);return{vs:Mn(n.platformInfo,{...n,source:e,stage:"vertex",modules:r}),fs:Mn(n.platformInfo,{...n,source:t,stage:"fragment",modules:r}),getUniforms:ut(r)}}function ft(n,e){let{source:t,stage:r,modules:o,hookFunctions:i=[],inject:a={},log:c}=e;D(typeof t=="string","shader source must be a string");let u=t,h="",p=lt(i),d={},m={},x={};for(let g in a){let A=typeof a[g]=="string"?{injection:a[g],order:0}:a[g],L=/^(v|f)s:(#)?([\w-]+)$/.exec(g);if(L){let v=L[2],b=L[3];v?b==="decl"?m[g]=[A]:x[g]=[A]:d[g]=[A]}else x[g]=[A]}let w=n.type!=="webgpu"?o:[];for(let g of w){c&&g.checkDeprecations(u,c);let A=g.getModuleSource(r,"wgsl");h+=A;let L=g.injections[r];for(let v in L){let b=/^(v|f)s:#([\w-]+)$/.exec(v);if(b){let y=b[2]==="decl"?m:x;y[v]=y[v]||[],y[v].push(L[v])}else d[v]=d[v]||[],d[v].push(L[v])}}return h+=In,h=de(h,r,m),h+=ct(p[r],d),h+=u,h=de(h,r,x),h}function Mn(n,e){let{id:t,source:r,stage:o,language:i="glsl",modules:a,defines:c={},hookFunctions:u=[],inject:h={},prologue:p=!0,log:d}=e;D(typeof r=="string","shader source must be a string");let m=i==="glsl"?Ne(r).version:-1,x=n.shaderLanguageVersion,w=m===100?"#version 100":"#version 300 es",A=r.split(`
|
|
58
58
|
`).slice(1).join(`
|
|
59
59
|
`),L={};a.forEach(S=>{Object.assign(L,S.getDefines())}),Object.assign(L,c);let v="";switch(i){case"wgsl":break;case"glsl":v=p?`${w}
|
|
60
60
|
|
|
61
61
|
// ----- PROLOGUE -------------------------
|
|
62
62
|
${yo({id:t,source:r,stage:o})}
|
|
63
63
|
${`#define SHADER_TYPE_${o.toUpperCase()}`}
|
|
64
|
-
${
|
|
64
|
+
${Sn(n)}
|
|
65
65
|
${o==="fragment"?Ao:""}
|
|
66
66
|
|
|
67
67
|
// ----- APPLICATION DEFINES -------------------------
|
|
@@ -69,25 +69,25 @@ ${o==="fragment"?Ao:""}
|
|
|
69
69
|
${bo(L)}
|
|
70
70
|
|
|
71
71
|
`:`${w}
|
|
72
|
-
`;break}let b=
|
|
72
|
+
`;break}let b=lt(u),P={},y={},k={};for(let S in h){let I=typeof h[S]=="string"?{injection:h[S],order:0}:h[S],M=/^(v|f)s:(#)?([\w-]+)$/.exec(S);if(M){let T=M[2],F=M[3];T?F==="decl"?y[S]=[I]:k[S]=[I]:P[S]=[I]}else k[S]=[I]}for(let S of a){d&&S.checkDeprecations(A,d);let I=S.getModuleSource(o);v+=I;let M=S.injections[o];for(let T in M){let F=/^(v|f)s:#([\w-]+)$/.exec(T);if(F){let R=F[2]==="decl"?y:k;R[T]=R[T]||[],R[T].push(M[T])}else P[T]=P[T]||[],P[T].push(M[T])}}return v+="// ----- MAIN SHADER SOURCE -------------------------",v+=In,v=de(v,o,y),v+=ct(b[o],P),v+=A,v=de(v,o,k),i==="glsl"&&m!==x&&(v=Tn(v,o)),v.trim()}function ut(n){return function(t){let r={};for(let o of n){let i=o.getUniforms(t,r);Object.assign(r,i)}return r}}function yo(n){let{id:e,source:t,stage:r}=n;return e&&t.indexOf("SHADER_NAME")===-1?`
|
|
73
73
|
#define SHADER_NAME ${e}_${r}
|
|
74
74
|
|
|
75
75
|
`:""}function bo(n={}){let e="";for(let t in n){let r=n[t];(r||Number.isFinite(r))&&(e+=`#define ${t.toUpperCase()} ${n[t]}
|
|
76
|
-
`)}return e}var re=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return re.defaultShaderAssembler=re.defaultShaderAssembler||new re,re.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){let t=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(r=>r.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleShader(e){let t=this._getModuleList(e.modules),r=this._hookFunctions,o=
|
|
76
|
+
`)}return e}var re=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return re.defaultShaderAssembler=re.defaultShaderAssembler||new re,re.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){let t=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(r=>r.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleShader(e){let t=this._getModuleList(e.modules),r=this._hookFunctions,o=st(e);return{...Fn({platformInfo:e.platformInfo,...o,modules:t,hookFunctions:r}),modules:t}}assembleShaderPair(e){let t=st(e),r=this._getModuleList(e.modules),o=this._hookFunctions,{platformInfo:i}=e;return{...e.platformInfo.shaderLanguage==="wgsl"?Cn({platformInfo:i,...t,modules:r,hookFunctions:o}):Te({platformInfo:i,...t,modules:r,hookFunctions:o}),modules:r}}_getModuleList(e=[]){let t=new Array(this._defaultModules.length+e.length),r={},o=0;for(let i=0,a=this._defaultModules.length;i<a;++i){let c=this._defaultModules[i],u=c.name;t[o++]=c,r[u]=!0}for(let i=0,a=e.length;i<a;++i){let c=e[i],u=c.name;r[u]||(t[o++]=c,r[u]=!0)}return t.length=o,C.instantiateModules(t)}},me=re;pn(me,"defaultShaderAssembler");function Rn(n){if(!n.normalized&&(n.normalized=!0,n.uniformPropTypes&&!n.getUniforms)){let e=new C(n);n.getUniforms=e.getUniforms.bind(e)}return n}var Po=`out vec4 transform_output;
|
|
77
77
|
void main() {
|
|
78
78
|
transform_output = vec4(0);
|
|
79
79
|
}`,wo=`#version 300 es
|
|
80
|
-
${Po}`;function
|
|
80
|
+
${Po}`;function On(n,e){e=Array.isArray(e)?e:[e];let t=n.replace(/^\s+/,"").split(/\s+/),[r,o,i]=t;if(!e.includes(r)||!o||!i)return null;let a=i.split(";")[0];return{qualifier:r,type:o,name:a}}function Un(n){let{input:e,inputChannels:t,output:r}=n||{};if(!e)return wo;if(!t)throw new Error("inputChannels");let o=Lo(t),i=_t(e,t);return`#version 300 es
|
|
81
81
|
in ${o} ${e};
|
|
82
82
|
out vec4 ${r};
|
|
83
83
|
void main() {
|
|
84
84
|
${r} = ${i};
|
|
85
|
-
}`}function
|
|
86
|
-
`)}function So(n){return{f32:"float",i32:"int",u32:"uint","vec2<f32>":"vec2","vec3<f32>":"vec3","vec4<f32>":"vec4","vec2<i32>":"ivec2","vec3<i32>":"ivec3","vec4<i32>":"ivec4","vec2<u32>":"uvec2","vec3<u32>":"uvec3","vec4<u32>":"uvec4","mat2x2<f32>":"mat2","mat2x3<f32>":"mat2x3","mat2x4<f32>":"mat2x4","mat3x2<f32>":"mat3x2","mat3x3<f32>":"mat3","mat3x4<f32>":"mat3x4","mat4x2<f32>":"mat4x2","mat4x3<f32>":"mat4x3","mat4x4<f32>":"mat4"}[n]}function
|
|
87
|
-
`)}function Yn(n,e){switch(e.shaderLanguage){case"glsl":return zn(n,e);case"wgsl":return Dn(n,e)}}var Bn=un(et(),1);var ft=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},B=class{constructor(){}get isAstNode(){return!0}get astNodeType(){return""}evaluate(e){throw new Error("Cannot evaluate node")}evaluateString(e){return this.evaluate(e).toString()}search(e){}searchBlock(e,t){if(e){t(ae.instance);for(let r of e)r instanceof Array?this.searchBlock(r,t):r.search(t);t(ce.instance)}}},ae=class extends B{};ae.instance=new ae;var ce=class extends B{};ce.instance=new ce;var N=class extends B{constructor(){super()}},xe=class extends N{constructor(e,t,r,o,i,a){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=r,this.body=o,this.startLine=i,this.endLine=a}get astNodeType(){return"function"}search(e){this.searchBlock(this.body,e)}},ut=class extends N{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},_t=class extends N{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},ht=class extends N{constructor(e){super(),this.body=e}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},pt=class extends N{constructor(e,t,r,o){super(),this.init=e,this.condition=t,this.increment=r,this.body=o}get astNodeType(){return"for"}search(e){var t,r,o;(t=this.init)===null||t===void 0||t.search(e),(r=this.condition)===null||r===void 0||r.search(e),(o=this.increment)===null||o===void 0||o.search(e),this.searchBlock(this.body,e)}},G=class extends N{constructor(e,t,r,o,i){super(),this.name=e,this.type=t,this.storage=r,this.access=o,this.value=i}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Te=class extends N{constructor(e,t,r){super(),this.name=e,this.type=t,this.value=r}get astNodeType(){return"override"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},ve=class extends N{constructor(e,t,r,o,i){super(),this.name=e,this.type=t,this.storage=r,this.access=o,this.value=i}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ee=class extends N{constructor(e,t,r,o,i){super(),this.name=e,this.type=t,this.storage=r,this.access=o,this.value=i}get astNodeType(){return"const"}evaluate(e){return this.value.evaluate(e)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},le;(function(n){n.increment="++",n.decrement="--"})(le||(le={}));(function(n){function e(t){let r=t;if(r=="parse")throw new Error("Invalid value for IncrementOperator");return n[r]}n.parse=e})(le||(le={}));var dt=class extends N{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}},Ae;(function(n){n.assign="=",n.addAssign="+=",n.subtractAssin="-=",n.multiplyAssign="*=",n.divideAssign="/=",n.moduloAssign="%=",n.andAssign="&=",n.orAssign="|=",n.xorAssign="^=",n.shiftLeftAssign="<<=",n.shiftRightAssign=">>="})(Ae||(Ae={}));(function(n){function e(t){let r=t;if(r=="parse")throw new Error("Invalid value for AssignOperator");return r}n.parse=e})(Ae||(Ae={}));var mt=class extends N{constructor(e,t,r){super(),this.operator=e,this.variable=t,this.value=r}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}},Me=class extends N{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}search(e){for(let t of this.args)t.search(e);e(this)}},gt=class extends N{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}},xt=class extends N{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"body"}},vt=class extends N{constructor(e,t,r,o){super(),this.condition=e,this.body=t,this.elseif=r,this.else=o}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}},At=class extends N{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},yt=class extends N{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},bt=class extends N{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},Pt=class extends N{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}},Ie=class extends N{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}},wt=class extends N{constructor(){super()}get astNodeType(){return"discard"}},Lt=class extends N{constructor(){super()}get astNodeType(){return"break"}},kt=class extends N{constructor(){super()}get astNodeType(){return"continue"}},H=class extends N{constructor(e){super(),this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}},V=class extends H{constructor(e,t,r,o){super(e),this.members=t,this.startLine=r,this.endLine=o}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}},Fe=class extends H{constructor(e,t,r){super(e),this.format=t,this.access=r}get astNodeType(){return"template"}},St=class extends H{constructor(e,t,r,o){super(e),this.storage=t,this.type=r,this.access=o}get astNodeType(){return"pointer"}},Ce=class extends H{constructor(e,t,r,o){super(e),this.attributes=t,this.format=r,this.count=o}get astNodeType(){return"array"}get isArray(){return!0}},J=class extends H{constructor(e,t,r){super(e),this.format=t,this.access=r}get astNodeType(){return"sampler"}},U=class extends B{constructor(){super()}},Re=class extends U{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}evaluateString(){return this.value}},$=class extends U{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){e(this);for(let t of this.args)t.search(e)}},Oe=class extends U{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"callExpr"}evaluate(e){switch(this.name){case"abs":return Math.abs(this.args[0].evaluate(e));case"acos":return Math.acos(this.args[0].evaluate(e));case"acosh":return Math.acosh(this.args[0].evaluate(e));case"asin":return Math.asin(this.args[0].evaluate(e));case"asinh":return Math.asinh(this.args[0].evaluate(e));case"atan":return Math.atan(this.args[0].evaluate(e));case"atan2":return Math.atan2(this.args[0].evaluate(e),this.args[1].evaluate(e));case"atanh":return Math.atanh(this.args[0].evaluate(e));case"ceil":return Math.ceil(this.args[0].evaluate(e));case"clamp":return Math.min(Math.max(this.args[0].evaluate(e),this.args[1].evaluate(e)),this.args[2].evaluate(e));case"cos":return Math.cos(this.args[0].evaluate(e));case"degrees":return this.args[0].evaluate(e)*180/Math.PI;case"distance":return Math.sqrt(Math.pow(this.args[0].evaluate(e)-this.args[1].evaluate(e),2));case"dot":case"exp":return Math.exp(this.args[0].evaluate(e));case"exp2":return Math.pow(2,this.args[0].evaluate(e));case"floor":return Math.floor(this.args[0].evaluate(e));case"fma":return this.args[0].evaluate(e)*this.args[1].evaluate(e)+this.args[2].evaluate(e);case"fract":return this.args[0].evaluate(e)-Math.floor(this.args[0].evaluate(e));case"inverseSqrt":return 1/Math.sqrt(this.args[0].evaluate(e));case"log":return Math.log(this.args[0].evaluate(e));case"log2":return Math.log2(this.args[0].evaluate(e));case"max":return Math.max(this.args[0].evaluate(e),this.args[1].evaluate(e));case"min":return Math.min(this.args[0].evaluate(e),this.args[1].evaluate(e));case"mix":return this.args[0].evaluate(e)*(1-this.args[2].evaluate(e))+this.args[1].evaluate(e)*this.args[2].evaluate(e);case"modf":return this.args[0].evaluate(e)-Math.floor(this.args[0].evaluate(e));case"pow":return Math.pow(this.args[0].evaluate(e),this.args[1].evaluate(e));case"radians":return this.args[0].evaluate(e)*Math.PI/180;case"round":return Math.round(this.args[0].evaluate(e));case"sign":return Math.sign(this.args[0].evaluate(e));case"sin":return Math.sin(this.args[0].evaluate(e));case"sinh":return Math.sinh(this.args[0].evaluate(e));case"saturate":return Math.min(Math.max(this.args[0].evaluate(e),0),1);case"smoothstep":return this.args[0].evaluate(e)*this.args[0].evaluate(e)*(3-2*this.args[0].evaluate(e));case"sqrt":return Math.sqrt(this.args[0].evaluate(e));case"step":return this.args[0].evaluate(e)<this.args[1].evaluate(e)?0:1;case"tan":return Math.tan(this.args[0].evaluate(e));case"tanh":return Math.tanh(this.args[0].evaluate(e));case"trunc":return Math.trunc(this.args[0].evaluate(e));default:throw new Error("Non const function: "+this.name)}}search(e){for(let t of this.args)t.search(e);e(this)}},ye=class extends U{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}evaluate(e){let t=e.constants.get(this.name);if(!t)throw new Error("Cannot evaluate node");return t.evaluate(e)}},Ue=class extends U{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}evaluate(e){var t,r;if(this.initializer instanceof $){let o=(t=this.postfix)===null||t===void 0?void 0:t.evaluateString(e),i=(r=this.initializer.type)===null||r===void 0?void 0:r.name,a=e.structs.get(i),c=a?.getMemberIndex(o);if(c!=-1)return this.initializer.args[c].evaluate(e);console.log(c)}return this.initializer.evaluate(e)}search(e){this.initializer.search(e)}},ze=class extends U{constructor(e){super(),this.value=e}get astNodeType(){return"literalExpr"}evaluate(){return this.value}},Nt=class extends U{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},Tt=class extends U{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"typecastExpr"}evaluate(e){return this.args[0].evaluate(e)}search(e){this.searchBlock(this.args,e)}},De=class extends U{constructor(e){super(),this.contents=e}get astNodeType(){return"groupExpr"}evaluate(e){return this.contents[0].evaluate(e)}search(e){this.searchBlock(this.contents,e)}},Et=class extends U{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Ye=class extends U{constructor(){super()}},Mt=class extends Ye{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}evaluate(e){switch(this.operator){case"+":return this.right.evaluate(e);case"-":return-this.right.evaluate(e);case"!":return this.right.evaluate(e)?0:1;case"~":return~this.right.evaluate(e);default:throw new Error("Unknown unary operator: "+this.operator)}}search(e){this.right.search(e)}},Y=class extends Ye{constructor(e,t,r){super(),this.operator=e,this.left=t,this.right=r}get astNodeType(){return"binaryOp"}evaluate(e){switch(this.operator){case"+":return this.left.evaluate(e)+this.right.evaluate(e);case"-":return this.left.evaluate(e)-this.right.evaluate(e);case"*":return this.left.evaluate(e)*this.right.evaluate(e);case"/":return this.left.evaluate(e)/this.right.evaluate(e);case"%":return this.left.evaluate(e)%this.right.evaluate(e);case"==":return this.left.evaluate(e)==this.right.evaluate(e)?1:0;case"!=":return this.left.evaluate(e)!=this.right.evaluate(e)?1:0;case"<":return this.left.evaluate(e)<this.right.evaluate(e)?1:0;case">":return this.left.evaluate(e)>this.right.evaluate(e)?1:0;case"<=":return this.left.evaluate(e)<=this.right.evaluate(e)?1:0;case">=":return this.left.evaluate(e)>=this.right.evaluate(e)?1:0;case"&&":return this.left.evaluate(e)&&this.right.evaluate(e)?1:0;case"||":return this.left.evaluate(e)||this.right.evaluate(e)?1:0;default:throw new Error(`Unknown operator ${this.operator}`)}}search(e){this.left.search(e),this.right.search(e)}},Xe=class extends B{constructor(){super()}},It=class extends Xe{constructor(e,t){super(),this.selector=e,this.body=t}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},Ft=class extends Xe{constructor(e){super(),this.body=e}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},Ct=class extends B{constructor(e,t,r){super(),this.name=e,this.type=t,this.attributes=r}get astNodeType(){return"argument"}},Rt=class extends B{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},Ot=class extends B{constructor(e,t,r){super(),this.name=e,this.type=t,this.attributes=r}get astNodeType(){return"member"}},Ut=class extends B{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},_,f;(function(n){n[n.token=0]="token",n[n.keyword=1]="keyword",n[n.reserved=2]="reserved"})(f||(f={}));var l=class{constructor(e,t,r){this.name=e,this.type=t,this.rule=r}toString(){return this.name}},s=class{};_=s;s.none=new l("",f.reserved,"");s.eof=new l("EOF",f.token,"");s.reserved={asm:new l("asm",f.reserved,"asm"),bf16:new l("bf16",f.reserved,"bf16"),do:new l("do",f.reserved,"do"),enum:new l("enum",f.reserved,"enum"),f16:new l("f16",f.reserved,"f16"),f64:new l("f64",f.reserved,"f64"),handle:new l("handle",f.reserved,"handle"),i8:new l("i8",f.reserved,"i8"),i16:new l("i16",f.reserved,"i16"),i64:new l("i64",f.reserved,"i64"),mat:new l("mat",f.reserved,"mat"),premerge:new l("premerge",f.reserved,"premerge"),regardless:new l("regardless",f.reserved,"regardless"),typedef:new l("typedef",f.reserved,"typedef"),u8:new l("u8",f.reserved,"u8"),u16:new l("u16",f.reserved,"u16"),u64:new l("u64",f.reserved,"u64"),unless:new l("unless",f.reserved,"unless"),using:new l("using",f.reserved,"using"),vec:new l("vec",f.reserved,"vec"),void:new l("void",f.reserved,"void")};s.keywords={array:new l("array",f.keyword,"array"),atomic:new l("atomic",f.keyword,"atomic"),bool:new l("bool",f.keyword,"bool"),f32:new l("f32",f.keyword,"f32"),i32:new l("i32",f.keyword,"i32"),mat2x2:new l("mat2x2",f.keyword,"mat2x2"),mat2x3:new l("mat2x3",f.keyword,"mat2x3"),mat2x4:new l("mat2x4",f.keyword,"mat2x4"),mat3x2:new l("mat3x2",f.keyword,"mat3x2"),mat3x3:new l("mat3x3",f.keyword,"mat3x3"),mat3x4:new l("mat3x4",f.keyword,"mat3x4"),mat4x2:new l("mat4x2",f.keyword,"mat4x2"),mat4x3:new l("mat4x3",f.keyword,"mat4x3"),mat4x4:new l("mat4x4",f.keyword,"mat4x4"),ptr:new l("ptr",f.keyword,"ptr"),sampler:new l("sampler",f.keyword,"sampler"),sampler_comparison:new l("sampler_comparison",f.keyword,"sampler_comparison"),struct:new l("struct",f.keyword,"struct"),texture_1d:new l("texture_1d",f.keyword,"texture_1d"),texture_2d:new l("texture_2d",f.keyword,"texture_2d"),texture_2d_array:new l("texture_2d_array",f.keyword,"texture_2d_array"),texture_3d:new l("texture_3d",f.keyword,"texture_3d"),texture_cube:new l("texture_cube",f.keyword,"texture_cube"),texture_cube_array:new l("texture_cube_array",f.keyword,"texture_cube_array"),texture_multisampled_2d:new l("texture_multisampled_2d",f.keyword,"texture_multisampled_2d"),texture_storage_1d:new l("texture_storage_1d",f.keyword,"texture_storage_1d"),texture_storage_2d:new l("texture_storage_2d",f.keyword,"texture_storage_2d"),texture_storage_2d_array:new l("texture_storage_2d_array",f.keyword,"texture_storage_2d_array"),texture_storage_3d:new l("texture_storage_3d",f.keyword,"texture_storage_3d"),texture_depth_2d:new l("texture_depth_2d",f.keyword,"texture_depth_2d"),texture_depth_2d_array:new l("texture_depth_2d_array",f.keyword,"texture_depth_2d_array"),texture_depth_cube:new l("texture_depth_cube",f.keyword,"texture_depth_cube"),texture_depth_cube_array:new l("texture_depth_cube_array",f.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new l("texture_depth_multisampled_2d",f.keyword,"texture_depth_multisampled_2d"),texture_external:new l("texture_external",f.keyword,"texture_external"),u32:new l("u32",f.keyword,"u32"),vec2:new l("vec2",f.keyword,"vec2"),vec3:new l("vec3",f.keyword,"vec3"),vec4:new l("vec4",f.keyword,"vec4"),bitcast:new l("bitcast",f.keyword,"bitcast"),block:new l("block",f.keyword,"block"),break:new l("break",f.keyword,"break"),case:new l("case",f.keyword,"case"),continue:new l("continue",f.keyword,"continue"),continuing:new l("continuing",f.keyword,"continuing"),default:new l("default",f.keyword,"default"),diagnostic:new l("diagnostic",f.keyword,"diagnostic"),discard:new l("discard",f.keyword,"discard"),else:new l("else",f.keyword,"else"),enable:new l("enable",f.keyword,"enable"),fallthrough:new l("fallthrough",f.keyword,"fallthrough"),false:new l("false",f.keyword,"false"),fn:new l("fn",f.keyword,"fn"),for:new l("for",f.keyword,"for"),function:new l("function",f.keyword,"function"),if:new l("if",f.keyword,"if"),let:new l("let",f.keyword,"let"),const:new l("const",f.keyword,"const"),loop:new l("loop",f.keyword,"loop"),while:new l("while",f.keyword,"while"),private:new l("private",f.keyword,"private"),read:new l("read",f.keyword,"read"),read_write:new l("read_write",f.keyword,"read_write"),return:new l("return",f.keyword,"return"),requires:new l("requires",f.keyword,"requires"),storage:new l("storage",f.keyword,"storage"),switch:new l("switch",f.keyword,"switch"),true:new l("true",f.keyword,"true"),alias:new l("alias",f.keyword,"alias"),type:new l("type",f.keyword,"type"),uniform:new l("uniform",f.keyword,"uniform"),var:new l("var",f.keyword,"var"),override:new l("override",f.keyword,"override"),workgroup:new l("workgroup",f.keyword,"workgroup"),write:new l("write",f.keyword,"write"),r8unorm:new l("r8unorm",f.keyword,"r8unorm"),r8snorm:new l("r8snorm",f.keyword,"r8snorm"),r8uint:new l("r8uint",f.keyword,"r8uint"),r8sint:new l("r8sint",f.keyword,"r8sint"),r16uint:new l("r16uint",f.keyword,"r16uint"),r16sint:new l("r16sint",f.keyword,"r16sint"),r16float:new l("r16float",f.keyword,"r16float"),rg8unorm:new l("rg8unorm",f.keyword,"rg8unorm"),rg8snorm:new l("rg8snorm",f.keyword,"rg8snorm"),rg8uint:new l("rg8uint",f.keyword,"rg8uint"),rg8sint:new l("rg8sint",f.keyword,"rg8sint"),r32uint:new l("r32uint",f.keyword,"r32uint"),r32sint:new l("r32sint",f.keyword,"r32sint"),r32float:new l("r32float",f.keyword,"r32float"),rg16uint:new l("rg16uint",f.keyword,"rg16uint"),rg16sint:new l("rg16sint",f.keyword,"rg16sint"),rg16float:new l("rg16float",f.keyword,"rg16float"),rgba8unorm:new l("rgba8unorm",f.keyword,"rgba8unorm"),rgba8unorm_srgb:new l("rgba8unorm_srgb",f.keyword,"rgba8unorm_srgb"),rgba8snorm:new l("rgba8snorm",f.keyword,"rgba8snorm"),rgba8uint:new l("rgba8uint",f.keyword,"rgba8uint"),rgba8sint:new l("rgba8sint",f.keyword,"rgba8sint"),bgra8unorm:new l("bgra8unorm",f.keyword,"bgra8unorm"),bgra8unorm_srgb:new l("bgra8unorm_srgb",f.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new l("rgb10a2unorm",f.keyword,"rgb10a2unorm"),rg11b10float:new l("rg11b10float",f.keyword,"rg11b10float"),rg32uint:new l("rg32uint",f.keyword,"rg32uint"),rg32sint:new l("rg32sint",f.keyword,"rg32sint"),rg32float:new l("rg32float",f.keyword,"rg32float"),rgba16uint:new l("rgba16uint",f.keyword,"rgba16uint"),rgba16sint:new l("rgba16sint",f.keyword,"rgba16sint"),rgba16float:new l("rgba16float",f.keyword,"rgba16float"),rgba32uint:new l("rgba32uint",f.keyword,"rgba32uint"),rgba32sint:new l("rgba32sint",f.keyword,"rgba32sint"),rgba32float:new l("rgba32float",f.keyword,"rgba32float"),static_assert:new l("static_assert",f.keyword,"static_assert")};s.tokens={decimal_float_literal:new l("decimal_float_literal",f.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),hex_float_literal:new l("hex_float_literal",f.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),int_literal:new l("int_literal",f.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new l("uint_literal",f.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),ident:new l("ident",f.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new l("and",f.token,"&"),and_and:new l("and_and",f.token,"&&"),arrow:new l("arrow ",f.token,"->"),attr:new l("attr",f.token,"@"),forward_slash:new l("forward_slash",f.token,"/"),bang:new l("bang",f.token,"!"),bracket_left:new l("bracket_left",f.token,"["),bracket_right:new l("bracket_right",f.token,"]"),brace_left:new l("brace_left",f.token,"{"),brace_right:new l("brace_right",f.token,"}"),colon:new l("colon",f.token,":"),comma:new l("comma",f.token,","),equal:new l("equal",f.token,"="),equal_equal:new l("equal_equal",f.token,"=="),not_equal:new l("not_equal",f.token,"!="),greater_than:new l("greater_than",f.token,">"),greater_than_equal:new l("greater_than_equal",f.token,">="),shift_right:new l("shift_right",f.token,">>"),less_than:new l("less_than",f.token,"<"),less_than_equal:new l("less_than_equal",f.token,"<="),shift_left:new l("shift_left",f.token,"<<"),modulo:new l("modulo",f.token,"%"),minus:new l("minus",f.token,"-"),minus_minus:new l("minus_minus",f.token,"--"),period:new l("period",f.token,"."),plus:new l("plus",f.token,"+"),plus_plus:new l("plus_plus",f.token,"++"),or:new l("or",f.token,"|"),or_or:new l("or_or",f.token,"||"),paren_left:new l("paren_left",f.token,"("),paren_right:new l("paren_right",f.token,")"),semicolon:new l("semicolon",f.token,";"),star:new l("star",f.token,"*"),tilde:new l("tilde",f.token,"~"),underscore:new l("underscore",f.token,"_"),xor:new l("xor",f.token,"^"),plus_equal:new l("plus_equal",f.token,"+="),minus_equal:new l("minus_equal",f.token,"-="),times_equal:new l("times_equal",f.token,"*="),division_equal:new l("division_equal",f.token,"/="),modulo_equal:new l("modulo_equal",f.token,"%="),and_equal:new l("and_equal",f.token,"&="),or_equal:new l("or_equal",f.token,"|="),xor_equal:new l("xor_equal",f.token,"^="),shift_right_equal:new l("shift_right_equal",f.token,">>="),shift_left_equal:new l("shift_left_equal",f.token,"<<=")};s.simpleTokens={"@":_.tokens.attr,"{":_.tokens.brace_left,"}":_.tokens.brace_right,":":_.tokens.colon,",":_.tokens.comma,"(":_.tokens.paren_left,")":_.tokens.paren_right,";":_.tokens.semicolon};s.literalTokens={"&":_.tokens.and,"&&":_.tokens.and_and,"->":_.tokens.arrow,"/":_.tokens.forward_slash,"!":_.tokens.bang,"[":_.tokens.bracket_left,"]":_.tokens.bracket_right,"=":_.tokens.equal,"==":_.tokens.equal_equal,"!=":_.tokens.not_equal,">":_.tokens.greater_than,">=":_.tokens.greater_than_equal,">>":_.tokens.shift_right,"<":_.tokens.less_than,"<=":_.tokens.less_than_equal,"<<":_.tokens.shift_left,"%":_.tokens.modulo,"-":_.tokens.minus,"--":_.tokens.minus_minus,".":_.tokens.period,"+":_.tokens.plus,"++":_.tokens.plus_plus,"|":_.tokens.or,"||":_.tokens.or_or,"*":_.tokens.star,"~":_.tokens.tilde,_:_.tokens.underscore,"^":_.tokens.xor,"+=":_.tokens.plus_equal,"-=":_.tokens.minus_equal,"*=":_.tokens.times_equal,"/=":_.tokens.division_equal,"%=":_.tokens.modulo_equal,"&=":_.tokens.and_equal,"|=":_.tokens.or_equal,"^=":_.tokens.xor_equal,">>=":_.tokens.shift_right_equal,"<<=":_.tokens.shift_left_equal};s.regexTokens={decimal_float_literal:_.tokens.decimal_float_literal,hex_float_literal:_.tokens.hex_float_literal,int_literal:_.tokens.int_literal,uint_literal:_.tokens.uint_literal,ident:_.tokens.ident};s.storage_class=[_.keywords.function,_.keywords.private,_.keywords.workgroup,_.keywords.uniform,_.keywords.storage];s.access_mode=[_.keywords.read,_.keywords.write,_.keywords.read_write];s.sampler_type=[_.keywords.sampler,_.keywords.sampler_comparison];s.sampled_texture_type=[_.keywords.texture_1d,_.keywords.texture_2d,_.keywords.texture_2d_array,_.keywords.texture_3d,_.keywords.texture_cube,_.keywords.texture_cube_array];s.multisampled_texture_type=[_.keywords.texture_multisampled_2d];s.storage_texture_type=[_.keywords.texture_storage_1d,_.keywords.texture_storage_2d,_.keywords.texture_storage_2d_array,_.keywords.texture_storage_3d];s.depth_texture_type=[_.keywords.texture_depth_2d,_.keywords.texture_depth_2d_array,_.keywords.texture_depth_cube,_.keywords.texture_depth_cube_array,_.keywords.texture_depth_multisampled_2d];s.texture_external_type=[_.keywords.texture_external];s.any_texture_type=[..._.sampled_texture_type,..._.multisampled_texture_type,..._.storage_texture_type,..._.depth_texture_type,..._.texture_external_type];s.texel_format=[_.keywords.r8unorm,_.keywords.r8snorm,_.keywords.r8uint,_.keywords.r8sint,_.keywords.r16uint,_.keywords.r16sint,_.keywords.r16float,_.keywords.rg8unorm,_.keywords.rg8snorm,_.keywords.rg8uint,_.keywords.rg8sint,_.keywords.r32uint,_.keywords.r32sint,_.keywords.r32float,_.keywords.rg16uint,_.keywords.rg16sint,_.keywords.rg16float,_.keywords.rgba8unorm,_.keywords.rgba8unorm_srgb,_.keywords.rgba8snorm,_.keywords.rgba8uint,_.keywords.rgba8sint,_.keywords.bgra8unorm,_.keywords.bgra8unorm_srgb,_.keywords.rgb10a2unorm,_.keywords.rg11b10float,_.keywords.rg32uint,_.keywords.rg32sint,_.keywords.rg32float,_.keywords.rgba16uint,_.keywords.rgba16sint,_.keywords.rgba16float,_.keywords.rgba32uint,_.keywords.rgba32sint,_.keywords.rgba32float];s.const_literal=[_.tokens.int_literal,_.tokens.uint_literal,_.tokens.decimal_float_literal,_.tokens.hex_float_literal,_.keywords.true,_.keywords.false];s.literal_or_ident=[_.tokens.ident,_.tokens.int_literal,_.tokens.uint_literal,_.tokens.decimal_float_literal,_.tokens.hex_float_literal];s.element_count_expression=[_.tokens.int_literal,_.tokens.uint_literal,_.tokens.ident];s.template_types=[_.keywords.vec2,_.keywords.vec3,_.keywords.vec4,_.keywords.mat2x2,_.keywords.mat2x3,_.keywords.mat2x4,_.keywords.mat3x2,_.keywords.mat3x3,_.keywords.mat3x4,_.keywords.mat4x2,_.keywords.mat4x3,_.keywords.mat4x4,_.keywords.atomic,_.keywords.bitcast,..._.any_texture_type];s.attribute_name=[_.tokens.ident,_.keywords.block,_.keywords.diagnostic];s.assignment_operators=[_.tokens.equal,_.tokens.plus_equal,_.tokens.minus_equal,_.tokens.times_equal,_.tokens.division_equal,_.tokens.modulo_equal,_.tokens.and_equal,_.tokens.or_equal,_.tokens.xor_equal,_.tokens.shift_right_equal,_.tokens.shift_left_equal];s.increment_operators=[_.tokens.plus_plus,_.tokens.minus_minus];var Be=class{constructor(e,t,r){this.type=e,this.lexeme=t,this.line=r}toString(){return this.lexeme}isTemplateType(){return s.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==s.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},zt=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Be(s.eof,"",this._line)),this._tokens}scanToken(){let e=this._advance();if(e==`
|
|
85
|
+
}`}function zn(n){switch(n){case"float":return"x";case"vec2":return"xy";case"vec3":return"xyz";case"vec4":return"xyzw";default:throw new Error(n)}}function Dn(n){switch(n){case"float":return 1;case"vec2":return 2;case"vec3":return 3;case"vec4":return 4;default:throw new Error(n)}}function Lo(n){switch(n){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${n}`)}}function _t(n,e){switch(e){case 1:return`vec4(${n}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${n}, 0.0, 1.0)`;case 3:return`vec4(${n}, 1.0)`;case 4:return n;default:throw new Error(`invalid channels: ${e}`)}}function Z(n){return typeof n=="string"?n.charAt(0).toUpperCase()+n.slice(1):n}function Yn(n,e){return ko(n,e)}function ko(n,e){let t=[];switch(e.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":t.push(`uniform ${Z(n.name)} {`);break;case"uniforms":}for(let[r,o]of Object.entries(n.uniformTypes||{})){let i=So(o);switch(e.uniforms){case"scoped-interface-blocks":t.push(` ${i} ${r};`);break;case"unscoped-interface-blocks":t.push(` ${i} ${n.name}_${r};`);break;case"uniforms":t.push(`uniform ${i} ${n.name}_${r};`)}}switch(e.uniforms){case"scoped-interface-blocks":t.push(`} ${n.name};`);break;case"unscoped-interface-blocks":t.push("};");break;case"uniforms":}return t.push(""),t.join(`
|
|
86
|
+
`)}function So(n){return{f32:"float",i32:"int",u32:"uint","vec2<f32>":"vec2","vec3<f32>":"vec3","vec4<f32>":"vec4","vec2<i32>":"ivec2","vec3<i32>":"ivec3","vec4<i32>":"ivec4","vec2<u32>":"uvec2","vec3<u32>":"uvec3","vec4<u32>":"uvec4","mat2x2<f32>":"mat2","mat2x3<f32>":"mat2x3","mat2x4<f32>":"mat2x4","mat3x2<f32>":"mat3x2","mat3x3<f32>":"mat3","mat3x4<f32>":"mat3x4","mat4x2<f32>":"mat4x2","mat4x3<f32>":"mat4x3","mat4x4<f32>":"mat4"}[n]}function Xn(n,e){return No(n,e)}function No(n,e){let t=[];t.push(`struct ${Z(n.name)} {`);for(let[r,o]of Object.entries(n?.uniformTypes||{})){let i=o;t.push(` ${r} : ${i};`)}return t.push("};"),t.push(`var<uniform> ${n.name} : ${Z(n.name)};`),t.join(`
|
|
87
|
+
`)}function Bn(n,e){switch(e.shaderLanguage){case"glsl":return Yn(n,e);case"wgsl":return Xn(n,e)}}var qn=rt(ke(),1);var ht=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},B=class{constructor(){}get isAstNode(){return!0}get astNodeType(){return""}evaluate(e){throw new Error("Cannot evaluate node")}evaluateString(e){return this.evaluate(e).toString()}search(e){}searchBlock(e,t){if(e){t(ae.instance);for(let r of e)r instanceof Array?this.searchBlock(r,t):r.search(t);t(ce.instance)}}},ae=class extends B{};ae.instance=new ae;var ce=class extends B{};ce.instance=new ce;var N=class extends B{constructor(){super()}},xe=class extends N{constructor(e,t,r,o,i,a){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=r,this.body=o,this.startLine=i,this.endLine=a}get astNodeType(){return"function"}search(e){this.searchBlock(this.body,e)}},pt=class extends N{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},dt=class extends N{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},mt=class extends N{constructor(e){super(),this.body=e}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},gt=class extends N{constructor(e,t,r,o){super(),this.init=e,this.condition=t,this.increment=r,this.body=o}get astNodeType(){return"for"}search(e){var t,r,o;(t=this.init)===null||t===void 0||t.search(e),(r=this.condition)===null||r===void 0||r.search(e),(o=this.increment)===null||o===void 0||o.search(e),this.searchBlock(this.body,e)}},H=class extends N{constructor(e,t,r,o,i){super(),this.name=e,this.type=t,this.storage=r,this.access=o,this.value=i}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ee=class extends N{constructor(e,t,r){super(),this.name=e,this.type=t,this.value=r}get astNodeType(){return"override"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},ve=class extends N{constructor(e,t,r,o,i){super(),this.name=e,this.type=t,this.storage=r,this.access=o,this.value=i}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Me=class extends N{constructor(e,t,r,o,i){super(),this.name=e,this.type=t,this.storage=r,this.access=o,this.value=i}get astNodeType(){return"const"}evaluate(e){return this.value.evaluate(e)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},le;(function(n){n.increment="++",n.decrement="--"})(le||(le={}));(function(n){function e(t){let r=t;if(r=="parse")throw new Error("Invalid value for IncrementOperator");return n[r]}n.parse=e})(le||(le={}));var xt=class extends N{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}},Ae;(function(n){n.assign="=",n.addAssign="+=",n.subtractAssin="-=",n.multiplyAssign="*=",n.divideAssign="/=",n.moduloAssign="%=",n.andAssign="&=",n.orAssign="|=",n.xorAssign="^=",n.shiftLeftAssign="<<=",n.shiftRightAssign=">>="})(Ae||(Ae={}));(function(n){function e(t){let r=t;if(r=="parse")throw new Error("Invalid value for AssignOperator");return r}n.parse=e})(Ae||(Ae={}));var vt=class extends N{constructor(e,t,r){super(),this.operator=e,this.variable=t,this.value=r}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}},Ie=class extends N{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}search(e){for(let t of this.args)t.search(e);e(this)}},At=class extends N{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}},yt=class extends N{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"body"}},bt=class extends N{constructor(e,t,r,o){super(),this.condition=e,this.body=t,this.elseif=r,this.else=o}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}},Pt=class extends N{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},wt=class extends N{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},Lt=class extends N{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},kt=class extends N{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}},Fe=class extends N{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}},St=class extends N{constructor(){super()}get astNodeType(){return"discard"}},Nt=class extends N{constructor(){super()}get astNodeType(){return"break"}},Tt=class extends N{constructor(){super()}get astNodeType(){return"continue"}},G=class extends N{constructor(e){super(),this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}},V=class extends G{constructor(e,t,r,o){super(e),this.members=t,this.startLine=r,this.endLine=o}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}},Ce=class extends G{constructor(e,t,r){super(e),this.format=t,this.access=r}get astNodeType(){return"template"}},Et=class extends G{constructor(e,t,r,o){super(e),this.storage=t,this.type=r,this.access=o}get astNodeType(){return"pointer"}},Re=class extends G{constructor(e,t,r,o){super(e),this.attributes=t,this.format=r,this.count=o}get astNodeType(){return"array"}get isArray(){return!0}},J=class extends G{constructor(e,t,r){super(e),this.format=t,this.access=r}get astNodeType(){return"sampler"}},U=class extends B{constructor(){super()}},Oe=class extends U{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}evaluateString(){return this.value}},$=class extends U{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){e(this);for(let t of this.args)t.search(e)}},Ue=class extends U{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"callExpr"}evaluate(e){switch(this.name){case"abs":return Math.abs(this.args[0].evaluate(e));case"acos":return Math.acos(this.args[0].evaluate(e));case"acosh":return Math.acosh(this.args[0].evaluate(e));case"asin":return Math.asin(this.args[0].evaluate(e));case"asinh":return Math.asinh(this.args[0].evaluate(e));case"atan":return Math.atan(this.args[0].evaluate(e));case"atan2":return Math.atan2(this.args[0].evaluate(e),this.args[1].evaluate(e));case"atanh":return Math.atanh(this.args[0].evaluate(e));case"ceil":return Math.ceil(this.args[0].evaluate(e));case"clamp":return Math.min(Math.max(this.args[0].evaluate(e),this.args[1].evaluate(e)),this.args[2].evaluate(e));case"cos":return Math.cos(this.args[0].evaluate(e));case"degrees":return this.args[0].evaluate(e)*180/Math.PI;case"distance":return Math.sqrt(Math.pow(this.args[0].evaluate(e)-this.args[1].evaluate(e),2));case"dot":case"exp":return Math.exp(this.args[0].evaluate(e));case"exp2":return Math.pow(2,this.args[0].evaluate(e));case"floor":return Math.floor(this.args[0].evaluate(e));case"fma":return this.args[0].evaluate(e)*this.args[1].evaluate(e)+this.args[2].evaluate(e);case"fract":return this.args[0].evaluate(e)-Math.floor(this.args[0].evaluate(e));case"inverseSqrt":return 1/Math.sqrt(this.args[0].evaluate(e));case"log":return Math.log(this.args[0].evaluate(e));case"log2":return Math.log2(this.args[0].evaluate(e));case"max":return Math.max(this.args[0].evaluate(e),this.args[1].evaluate(e));case"min":return Math.min(this.args[0].evaluate(e),this.args[1].evaluate(e));case"mix":return this.args[0].evaluate(e)*(1-this.args[2].evaluate(e))+this.args[1].evaluate(e)*this.args[2].evaluate(e);case"modf":return this.args[0].evaluate(e)-Math.floor(this.args[0].evaluate(e));case"pow":return Math.pow(this.args[0].evaluate(e),this.args[1].evaluate(e));case"radians":return this.args[0].evaluate(e)*Math.PI/180;case"round":return Math.round(this.args[0].evaluate(e));case"sign":return Math.sign(this.args[0].evaluate(e));case"sin":return Math.sin(this.args[0].evaluate(e));case"sinh":return Math.sinh(this.args[0].evaluate(e));case"saturate":return Math.min(Math.max(this.args[0].evaluate(e),0),1);case"smoothstep":return this.args[0].evaluate(e)*this.args[0].evaluate(e)*(3-2*this.args[0].evaluate(e));case"sqrt":return Math.sqrt(this.args[0].evaluate(e));case"step":return this.args[0].evaluate(e)<this.args[1].evaluate(e)?0:1;case"tan":return Math.tan(this.args[0].evaluate(e));case"tanh":return Math.tanh(this.args[0].evaluate(e));case"trunc":return Math.trunc(this.args[0].evaluate(e));default:throw new Error("Non const function: "+this.name)}}search(e){for(let t of this.args)t.search(e);e(this)}},ye=class extends U{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}evaluate(e){let t=e.constants.get(this.name);if(!t)throw new Error("Cannot evaluate node");return t.evaluate(e)}},ze=class extends U{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}evaluate(e){var t,r;if(this.initializer instanceof $){let o=(t=this.postfix)===null||t===void 0?void 0:t.evaluateString(e),i=(r=this.initializer.type)===null||r===void 0?void 0:r.name,a=e.structs.get(i),c=a?.getMemberIndex(o);if(c!=-1)return this.initializer.args[c].evaluate(e);console.log(c)}return this.initializer.evaluate(e)}search(e){this.initializer.search(e)}},De=class extends U{constructor(e){super(),this.value=e}get astNodeType(){return"literalExpr"}evaluate(){return this.value}},Mt=class extends U{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}},It=class extends U{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"typecastExpr"}evaluate(e){return this.args[0].evaluate(e)}search(e){this.searchBlock(this.args,e)}},Ye=class extends U{constructor(e){super(),this.contents=e}get astNodeType(){return"groupExpr"}evaluate(e){return this.contents[0].evaluate(e)}search(e){this.searchBlock(this.contents,e)}},Ft=class extends U{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},Xe=class extends U{constructor(){super()}},Ct=class extends Xe{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}evaluate(e){switch(this.operator){case"+":return this.right.evaluate(e);case"-":return-this.right.evaluate(e);case"!":return this.right.evaluate(e)?0:1;case"~":return~this.right.evaluate(e);default:throw new Error("Unknown unary operator: "+this.operator)}}search(e){this.right.search(e)}},Y=class extends Xe{constructor(e,t,r){super(),this.operator=e,this.left=t,this.right=r}get astNodeType(){return"binaryOp"}evaluate(e){switch(this.operator){case"+":return this.left.evaluate(e)+this.right.evaluate(e);case"-":return this.left.evaluate(e)-this.right.evaluate(e);case"*":return this.left.evaluate(e)*this.right.evaluate(e);case"/":return this.left.evaluate(e)/this.right.evaluate(e);case"%":return this.left.evaluate(e)%this.right.evaluate(e);case"==":return this.left.evaluate(e)==this.right.evaluate(e)?1:0;case"!=":return this.left.evaluate(e)!=this.right.evaluate(e)?1:0;case"<":return this.left.evaluate(e)<this.right.evaluate(e)?1:0;case">":return this.left.evaluate(e)>this.right.evaluate(e)?1:0;case"<=":return this.left.evaluate(e)<=this.right.evaluate(e)?1:0;case">=":return this.left.evaluate(e)>=this.right.evaluate(e)?1:0;case"&&":return this.left.evaluate(e)&&this.right.evaluate(e)?1:0;case"||":return this.left.evaluate(e)||this.right.evaluate(e)?1:0;default:throw new Error(`Unknown operator ${this.operator}`)}}search(e){this.left.search(e),this.right.search(e)}},Be=class extends B{constructor(){super()}},Rt=class extends Be{constructor(e,t){super(),this.selector=e,this.body=t}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},Ot=class extends Be{constructor(e){super(),this.body=e}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},Ut=class extends B{constructor(e,t,r){super(),this.name=e,this.type=t,this.attributes=r}get astNodeType(){return"argument"}},zt=class extends B{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},Dt=class extends B{constructor(e,t,r){super(),this.name=e,this.type=t,this.attributes=r}get astNodeType(){return"member"}},Yt=class extends B{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},_,f;(function(n){n[n.token=0]="token",n[n.keyword=1]="keyword",n[n.reserved=2]="reserved"})(f||(f={}));var l=class{constructor(e,t,r){this.name=e,this.type=t,this.rule=r}toString(){return this.name}},s=class{};_=s;s.none=new l("",f.reserved,"");s.eof=new l("EOF",f.token,"");s.reserved={asm:new l("asm",f.reserved,"asm"),bf16:new l("bf16",f.reserved,"bf16"),do:new l("do",f.reserved,"do"),enum:new l("enum",f.reserved,"enum"),f16:new l("f16",f.reserved,"f16"),f64:new l("f64",f.reserved,"f64"),handle:new l("handle",f.reserved,"handle"),i8:new l("i8",f.reserved,"i8"),i16:new l("i16",f.reserved,"i16"),i64:new l("i64",f.reserved,"i64"),mat:new l("mat",f.reserved,"mat"),premerge:new l("premerge",f.reserved,"premerge"),regardless:new l("regardless",f.reserved,"regardless"),typedef:new l("typedef",f.reserved,"typedef"),u8:new l("u8",f.reserved,"u8"),u16:new l("u16",f.reserved,"u16"),u64:new l("u64",f.reserved,"u64"),unless:new l("unless",f.reserved,"unless"),using:new l("using",f.reserved,"using"),vec:new l("vec",f.reserved,"vec"),void:new l("void",f.reserved,"void")};s.keywords={array:new l("array",f.keyword,"array"),atomic:new l("atomic",f.keyword,"atomic"),bool:new l("bool",f.keyword,"bool"),f32:new l("f32",f.keyword,"f32"),i32:new l("i32",f.keyword,"i32"),mat2x2:new l("mat2x2",f.keyword,"mat2x2"),mat2x3:new l("mat2x3",f.keyword,"mat2x3"),mat2x4:new l("mat2x4",f.keyword,"mat2x4"),mat3x2:new l("mat3x2",f.keyword,"mat3x2"),mat3x3:new l("mat3x3",f.keyword,"mat3x3"),mat3x4:new l("mat3x4",f.keyword,"mat3x4"),mat4x2:new l("mat4x2",f.keyword,"mat4x2"),mat4x3:new l("mat4x3",f.keyword,"mat4x3"),mat4x4:new l("mat4x4",f.keyword,"mat4x4"),ptr:new l("ptr",f.keyword,"ptr"),sampler:new l("sampler",f.keyword,"sampler"),sampler_comparison:new l("sampler_comparison",f.keyword,"sampler_comparison"),struct:new l("struct",f.keyword,"struct"),texture_1d:new l("texture_1d",f.keyword,"texture_1d"),texture_2d:new l("texture_2d",f.keyword,"texture_2d"),texture_2d_array:new l("texture_2d_array",f.keyword,"texture_2d_array"),texture_3d:new l("texture_3d",f.keyword,"texture_3d"),texture_cube:new l("texture_cube",f.keyword,"texture_cube"),texture_cube_array:new l("texture_cube_array",f.keyword,"texture_cube_array"),texture_multisampled_2d:new l("texture_multisampled_2d",f.keyword,"texture_multisampled_2d"),texture_storage_1d:new l("texture_storage_1d",f.keyword,"texture_storage_1d"),texture_storage_2d:new l("texture_storage_2d",f.keyword,"texture_storage_2d"),texture_storage_2d_array:new l("texture_storage_2d_array",f.keyword,"texture_storage_2d_array"),texture_storage_3d:new l("texture_storage_3d",f.keyword,"texture_storage_3d"),texture_depth_2d:new l("texture_depth_2d",f.keyword,"texture_depth_2d"),texture_depth_2d_array:new l("texture_depth_2d_array",f.keyword,"texture_depth_2d_array"),texture_depth_cube:new l("texture_depth_cube",f.keyword,"texture_depth_cube"),texture_depth_cube_array:new l("texture_depth_cube_array",f.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new l("texture_depth_multisampled_2d",f.keyword,"texture_depth_multisampled_2d"),texture_external:new l("texture_external",f.keyword,"texture_external"),u32:new l("u32",f.keyword,"u32"),vec2:new l("vec2",f.keyword,"vec2"),vec3:new l("vec3",f.keyword,"vec3"),vec4:new l("vec4",f.keyword,"vec4"),bitcast:new l("bitcast",f.keyword,"bitcast"),block:new l("block",f.keyword,"block"),break:new l("break",f.keyword,"break"),case:new l("case",f.keyword,"case"),continue:new l("continue",f.keyword,"continue"),continuing:new l("continuing",f.keyword,"continuing"),default:new l("default",f.keyword,"default"),diagnostic:new l("diagnostic",f.keyword,"diagnostic"),discard:new l("discard",f.keyword,"discard"),else:new l("else",f.keyword,"else"),enable:new l("enable",f.keyword,"enable"),fallthrough:new l("fallthrough",f.keyword,"fallthrough"),false:new l("false",f.keyword,"false"),fn:new l("fn",f.keyword,"fn"),for:new l("for",f.keyword,"for"),function:new l("function",f.keyword,"function"),if:new l("if",f.keyword,"if"),let:new l("let",f.keyword,"let"),const:new l("const",f.keyword,"const"),loop:new l("loop",f.keyword,"loop"),while:new l("while",f.keyword,"while"),private:new l("private",f.keyword,"private"),read:new l("read",f.keyword,"read"),read_write:new l("read_write",f.keyword,"read_write"),return:new l("return",f.keyword,"return"),requires:new l("requires",f.keyword,"requires"),storage:new l("storage",f.keyword,"storage"),switch:new l("switch",f.keyword,"switch"),true:new l("true",f.keyword,"true"),alias:new l("alias",f.keyword,"alias"),type:new l("type",f.keyword,"type"),uniform:new l("uniform",f.keyword,"uniform"),var:new l("var",f.keyword,"var"),override:new l("override",f.keyword,"override"),workgroup:new l("workgroup",f.keyword,"workgroup"),write:new l("write",f.keyword,"write"),r8unorm:new l("r8unorm",f.keyword,"r8unorm"),r8snorm:new l("r8snorm",f.keyword,"r8snorm"),r8uint:new l("r8uint",f.keyword,"r8uint"),r8sint:new l("r8sint",f.keyword,"r8sint"),r16uint:new l("r16uint",f.keyword,"r16uint"),r16sint:new l("r16sint",f.keyword,"r16sint"),r16float:new l("r16float",f.keyword,"r16float"),rg8unorm:new l("rg8unorm",f.keyword,"rg8unorm"),rg8snorm:new l("rg8snorm",f.keyword,"rg8snorm"),rg8uint:new l("rg8uint",f.keyword,"rg8uint"),rg8sint:new l("rg8sint",f.keyword,"rg8sint"),r32uint:new l("r32uint",f.keyword,"r32uint"),r32sint:new l("r32sint",f.keyword,"r32sint"),r32float:new l("r32float",f.keyword,"r32float"),rg16uint:new l("rg16uint",f.keyword,"rg16uint"),rg16sint:new l("rg16sint",f.keyword,"rg16sint"),rg16float:new l("rg16float",f.keyword,"rg16float"),rgba8unorm:new l("rgba8unorm",f.keyword,"rgba8unorm"),rgba8unorm_srgb:new l("rgba8unorm_srgb",f.keyword,"rgba8unorm_srgb"),rgba8snorm:new l("rgba8snorm",f.keyword,"rgba8snorm"),rgba8uint:new l("rgba8uint",f.keyword,"rgba8uint"),rgba8sint:new l("rgba8sint",f.keyword,"rgba8sint"),bgra8unorm:new l("bgra8unorm",f.keyword,"bgra8unorm"),bgra8unorm_srgb:new l("bgra8unorm_srgb",f.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new l("rgb10a2unorm",f.keyword,"rgb10a2unorm"),rg11b10float:new l("rg11b10float",f.keyword,"rg11b10float"),rg32uint:new l("rg32uint",f.keyword,"rg32uint"),rg32sint:new l("rg32sint",f.keyword,"rg32sint"),rg32float:new l("rg32float",f.keyword,"rg32float"),rgba16uint:new l("rgba16uint",f.keyword,"rgba16uint"),rgba16sint:new l("rgba16sint",f.keyword,"rgba16sint"),rgba16float:new l("rgba16float",f.keyword,"rgba16float"),rgba32uint:new l("rgba32uint",f.keyword,"rgba32uint"),rgba32sint:new l("rgba32sint",f.keyword,"rgba32sint"),rgba32float:new l("rgba32float",f.keyword,"rgba32float"),static_assert:new l("static_assert",f.keyword,"static_assert")};s.tokens={decimal_float_literal:new l("decimal_float_literal",f.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),hex_float_literal:new l("hex_float_literal",f.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),int_literal:new l("int_literal",f.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new l("uint_literal",f.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),ident:new l("ident",f.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new l("and",f.token,"&"),and_and:new l("and_and",f.token,"&&"),arrow:new l("arrow ",f.token,"->"),attr:new l("attr",f.token,"@"),forward_slash:new l("forward_slash",f.token,"/"),bang:new l("bang",f.token,"!"),bracket_left:new l("bracket_left",f.token,"["),bracket_right:new l("bracket_right",f.token,"]"),brace_left:new l("brace_left",f.token,"{"),brace_right:new l("brace_right",f.token,"}"),colon:new l("colon",f.token,":"),comma:new l("comma",f.token,","),equal:new l("equal",f.token,"="),equal_equal:new l("equal_equal",f.token,"=="),not_equal:new l("not_equal",f.token,"!="),greater_than:new l("greater_than",f.token,">"),greater_than_equal:new l("greater_than_equal",f.token,">="),shift_right:new l("shift_right",f.token,">>"),less_than:new l("less_than",f.token,"<"),less_than_equal:new l("less_than_equal",f.token,"<="),shift_left:new l("shift_left",f.token,"<<"),modulo:new l("modulo",f.token,"%"),minus:new l("minus",f.token,"-"),minus_minus:new l("minus_minus",f.token,"--"),period:new l("period",f.token,"."),plus:new l("plus",f.token,"+"),plus_plus:new l("plus_plus",f.token,"++"),or:new l("or",f.token,"|"),or_or:new l("or_or",f.token,"||"),paren_left:new l("paren_left",f.token,"("),paren_right:new l("paren_right",f.token,")"),semicolon:new l("semicolon",f.token,";"),star:new l("star",f.token,"*"),tilde:new l("tilde",f.token,"~"),underscore:new l("underscore",f.token,"_"),xor:new l("xor",f.token,"^"),plus_equal:new l("plus_equal",f.token,"+="),minus_equal:new l("minus_equal",f.token,"-="),times_equal:new l("times_equal",f.token,"*="),division_equal:new l("division_equal",f.token,"/="),modulo_equal:new l("modulo_equal",f.token,"%="),and_equal:new l("and_equal",f.token,"&="),or_equal:new l("or_equal",f.token,"|="),xor_equal:new l("xor_equal",f.token,"^="),shift_right_equal:new l("shift_right_equal",f.token,">>="),shift_left_equal:new l("shift_left_equal",f.token,"<<=")};s.simpleTokens={"@":_.tokens.attr,"{":_.tokens.brace_left,"}":_.tokens.brace_right,":":_.tokens.colon,",":_.tokens.comma,"(":_.tokens.paren_left,")":_.tokens.paren_right,";":_.tokens.semicolon};s.literalTokens={"&":_.tokens.and,"&&":_.tokens.and_and,"->":_.tokens.arrow,"/":_.tokens.forward_slash,"!":_.tokens.bang,"[":_.tokens.bracket_left,"]":_.tokens.bracket_right,"=":_.tokens.equal,"==":_.tokens.equal_equal,"!=":_.tokens.not_equal,">":_.tokens.greater_than,">=":_.tokens.greater_than_equal,">>":_.tokens.shift_right,"<":_.tokens.less_than,"<=":_.tokens.less_than_equal,"<<":_.tokens.shift_left,"%":_.tokens.modulo,"-":_.tokens.minus,"--":_.tokens.minus_minus,".":_.tokens.period,"+":_.tokens.plus,"++":_.tokens.plus_plus,"|":_.tokens.or,"||":_.tokens.or_or,"*":_.tokens.star,"~":_.tokens.tilde,_:_.tokens.underscore,"^":_.tokens.xor,"+=":_.tokens.plus_equal,"-=":_.tokens.minus_equal,"*=":_.tokens.times_equal,"/=":_.tokens.division_equal,"%=":_.tokens.modulo_equal,"&=":_.tokens.and_equal,"|=":_.tokens.or_equal,"^=":_.tokens.xor_equal,">>=":_.tokens.shift_right_equal,"<<=":_.tokens.shift_left_equal};s.regexTokens={decimal_float_literal:_.tokens.decimal_float_literal,hex_float_literal:_.tokens.hex_float_literal,int_literal:_.tokens.int_literal,uint_literal:_.tokens.uint_literal,ident:_.tokens.ident};s.storage_class=[_.keywords.function,_.keywords.private,_.keywords.workgroup,_.keywords.uniform,_.keywords.storage];s.access_mode=[_.keywords.read,_.keywords.write,_.keywords.read_write];s.sampler_type=[_.keywords.sampler,_.keywords.sampler_comparison];s.sampled_texture_type=[_.keywords.texture_1d,_.keywords.texture_2d,_.keywords.texture_2d_array,_.keywords.texture_3d,_.keywords.texture_cube,_.keywords.texture_cube_array];s.multisampled_texture_type=[_.keywords.texture_multisampled_2d];s.storage_texture_type=[_.keywords.texture_storage_1d,_.keywords.texture_storage_2d,_.keywords.texture_storage_2d_array,_.keywords.texture_storage_3d];s.depth_texture_type=[_.keywords.texture_depth_2d,_.keywords.texture_depth_2d_array,_.keywords.texture_depth_cube,_.keywords.texture_depth_cube_array,_.keywords.texture_depth_multisampled_2d];s.texture_external_type=[_.keywords.texture_external];s.any_texture_type=[..._.sampled_texture_type,..._.multisampled_texture_type,..._.storage_texture_type,..._.depth_texture_type,..._.texture_external_type];s.texel_format=[_.keywords.r8unorm,_.keywords.r8snorm,_.keywords.r8uint,_.keywords.r8sint,_.keywords.r16uint,_.keywords.r16sint,_.keywords.r16float,_.keywords.rg8unorm,_.keywords.rg8snorm,_.keywords.rg8uint,_.keywords.rg8sint,_.keywords.r32uint,_.keywords.r32sint,_.keywords.r32float,_.keywords.rg16uint,_.keywords.rg16sint,_.keywords.rg16float,_.keywords.rgba8unorm,_.keywords.rgba8unorm_srgb,_.keywords.rgba8snorm,_.keywords.rgba8uint,_.keywords.rgba8sint,_.keywords.bgra8unorm,_.keywords.bgra8unorm_srgb,_.keywords.rgb10a2unorm,_.keywords.rg11b10float,_.keywords.rg32uint,_.keywords.rg32sint,_.keywords.rg32float,_.keywords.rgba16uint,_.keywords.rgba16sint,_.keywords.rgba16float,_.keywords.rgba32uint,_.keywords.rgba32sint,_.keywords.rgba32float];s.const_literal=[_.tokens.int_literal,_.tokens.uint_literal,_.tokens.decimal_float_literal,_.tokens.hex_float_literal,_.keywords.true,_.keywords.false];s.literal_or_ident=[_.tokens.ident,_.tokens.int_literal,_.tokens.uint_literal,_.tokens.decimal_float_literal,_.tokens.hex_float_literal];s.element_count_expression=[_.tokens.int_literal,_.tokens.uint_literal,_.tokens.ident];s.template_types=[_.keywords.vec2,_.keywords.vec3,_.keywords.vec4,_.keywords.mat2x2,_.keywords.mat2x3,_.keywords.mat2x4,_.keywords.mat3x2,_.keywords.mat3x3,_.keywords.mat3x4,_.keywords.mat4x2,_.keywords.mat4x3,_.keywords.mat4x4,_.keywords.atomic,_.keywords.bitcast,..._.any_texture_type];s.attribute_name=[_.tokens.ident,_.keywords.block,_.keywords.diagnostic];s.assignment_operators=[_.tokens.equal,_.tokens.plus_equal,_.tokens.minus_equal,_.tokens.times_equal,_.tokens.division_equal,_.tokens.modulo_equal,_.tokens.and_equal,_.tokens.or_equal,_.tokens.xor_equal,_.tokens.shift_right_equal,_.tokens.shift_left_equal];s.increment_operators=[_.tokens.plus_plus,_.tokens.minus_minus];var Qe=class{constructor(e,t,r){this.type=e,this.lexeme=t,this.line=r}toString(){return this.lexeme}isTemplateType(){return s.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==s.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},Xt=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Qe(s.eof,"",this._line)),this._tokens}scanToken(){let e=this._advance();if(e==`
|
|
88
88
|
`)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
|
|
89
89
|
`;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}else if(this._peekAhead()=="*"){this._advance();let a=1;for(;a>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
|
|
90
|
-
`)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}let t=s.simpleTokens[e];if(t)return this._addToken(t),!0;let r=s.none,o=this._isAlpha(e),i=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(o){let a=s.keywords[e];if(a)return this._addToken(a),!0}if(o||i)return this._addToken(s.tokens.ident),!0;for(;;){let a=this._findType(e),c=this._peekAhead();if(e==">"&&(c==">"||c=="=")){let u=!1,h=this._tokens.length-1;for(let p=0;p<5&&h>=0;++p,--h)if(this._tokens[h].type===s.tokens.less_than){h>0&&this._tokens[h-1].isArrayOrTemplateType()&&(u=!0);break}if(u)return this._addToken(a),!0}if(a===s.none){let u=e,h=0,p=2;for(let d=0;d<p;++d)if(u+=this._peekAhead(d),a=this._findType(u),a!==s.none){h=d;break}if(a===s.none)return r===s.none?!1:(this._current--,this._addToken(r),!0);e=u,this._current+=h+1}if(r=a,this._isAtEnd())break;e+=this._advance()}return r===s.none?!1:(this._addToken(r),!0)}_findType(e){for(let r in s.regexTokens){let o=s.regexTokens[r];if(this._match(e,o.rule))return o}let t=s.literalTokens[e];return t||s.none}_match(e,t){let r=t.exec(e);return r&&r.index==0&&r[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"}_isAlphaNumeric(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e=="_"||e>="0"&&e<="9"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let t=this._source.substring(this._start,this._current);this._tokens.push(new Be(e,t,this._line))}},Dt=class{constructor(){this._tokens=[],this._current=0,this._currentLine=0,this._context=new ft,this._deferArrayCountEval=[]}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let t=[];for(;!this._isAtEnd();){let r=this._global_decl_or_directive();if(!r)break;t.push(r)}if(this._deferArrayCountEval.length>0){for(let r of this._deferArrayCountEval){let o=r.arrayType,i=r.countNode;if(i instanceof ye){let c=i.name,u=this._context.constants.get(c);if(u)try{let h=u.evaluate(this._context);o.count=h}catch{}}}this._deferArrayCountEval.length=0}return t}_initialize(e){if(e)if(typeof e=="string"){let t=new zt(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_error(e,t){return{token:e,message:t,toString:function(){return`${t}`}}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==s.eof}_match(e){if(e instanceof l)return this._check(e)?(this._advance(),!0):!1;for(let t=0,r=e.length;t<r;++t){let o=e[t];if(this._check(o))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),t)}_check(e){if(this._isAtEnd())return!1;let t=this._peek();if(e instanceof Array){let r=t.type;return e.indexOf(r)!=-1}return t.type==e}_advance(){var e,t;return this._currentLine=(t=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&t!==void 0?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(s.tokens.semicolon)&&!this._isAtEnd(););if(this._match(s.keywords.alias)){let t=this._type_alias();return this._consume(s.tokens.semicolon,"Expected ';'"),t}if(this._match(s.keywords.diagnostic)){let t=this._diagnostic();return this._consume(s.tokens.semicolon,"Expected ';'"),t}if(this._match(s.keywords.requires)){let t=this._requires_directive();return this._consume(s.tokens.semicolon,"Expected ';'"),t}if(this._match(s.keywords.enable)){let t=this._enable_directive();return this._consume(s.tokens.semicolon,"Expected ';'"),t}let e=this._attribute();if(this._check(s.keywords.var)){let t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),t}if(this._check(s.keywords.override)){let t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),t}if(this._check(s.keywords.let)){let t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),t}if(this._check(s.keywords.const)){let t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),t}if(this._check(s.keywords.struct)){let t=this._struct_decl();return t!=null&&(t.attributes=e),t}if(this._check(s.keywords.fn)){let t=this._function_decl();return t!=null&&(t.attributes=e),t}return null}_function_decl(){if(!this._match(s.keywords.fn))return null;let e=this._currentLine,t=this._consume(s.tokens.ident,"Expected function name.").toString();this._consume(s.tokens.paren_left,"Expected '(' for function arguments.");let r=[];if(!this._check(s.tokens.paren_right))do{if(this._check(s.tokens.paren_right))break;let c=this._attribute(),u=this._consume(s.tokens.ident,"Expected argument name.").toString();this._consume(s.tokens.colon,"Expected ':' for argument type.");let h=this._attribute(),p=this._type_decl();p!=null&&(p.attributes=h,r.push(new Ct(u,p,c)))}while(this._match(s.tokens.comma));this._consume(s.tokens.paren_right,"Expected ')' after function arguments.");let o=null;if(this._match(s.tokens.arrow)){let c=this._attribute();o=this._type_decl(),o!=null&&(o.attributes=c)}let i=this._compound_statement(),a=this._currentLine;return new xe(t,r,o,i,e,a)}_compound_statement(){let e=[];for(this._consume(s.tokens.brace_left,"Expected '{' for block.");!this._check(s.tokens.brace_right);){let t=this._statement();t!==null&&e.push(t)}return this._consume(s.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(s.tokens.semicolon)&&!this._isAtEnd(););if(this._check(s.tokens.attr)&&this._attribute(),this._check(s.keywords.if))return this._if_statement();if(this._check(s.keywords.switch))return this._switch_statement();if(this._check(s.keywords.loop))return this._loop_statement();if(this._check(s.keywords.for))return this._for_statement();if(this._check(s.keywords.while))return this._while_statement();if(this._check(s.keywords.continuing))return this._continuing_statement();if(this._check(s.keywords.static_assert))return this._static_assert_statement();if(this._check(s.tokens.brace_left))return this._compound_statement();let e=null;return this._check(s.keywords.return)?e=this._return_statement():this._check([s.keywords.var,s.keywords.let,s.keywords.const])?e=this._variable_statement():this._match(s.keywords.discard)?e=new wt:this._match(s.keywords.break)?e=new Lt:this._match(s.keywords.continue)?e=new kt:e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement(),e!=null&&this._consume(s.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(s.keywords.static_assert))return null;let e=this._optional_paren_expression();return new ut(e)}_while_statement(){if(!this._match(s.keywords.while))return null;let e=this._optional_paren_expression();this._check(s.tokens.attr)&&this._attribute();let t=this._compound_statement();return new _t(e,t)}_continuing_statement(){if(!this._match(s.keywords.continuing))return null;let e=this._compound_statement();return new ht(e)}_for_statement(){if(!this._match(s.keywords.for))return null;this._consume(s.tokens.paren_left,"Expected '('.");let e=this._check(s.tokens.semicolon)?null:this._for_init();this._consume(s.tokens.semicolon,"Expected ';'.");let t=this._check(s.tokens.semicolon)?null:this._short_circuit_or_expression();this._consume(s.tokens.semicolon,"Expected ';'.");let r=this._check(s.tokens.paren_right)?null:this._for_increment();this._consume(s.tokens.paren_right,"Expected ')'."),this._check(s.tokens.attr)&&this._attribute();let o=this._compound_statement();return new pt(e,t,r,o)}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(s.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(s.tokens.equal)&&(t=this._short_circuit_or_expression()),new G(e.name,e.type,e.storage,e.access,t)}if(this._match(s.keywords.let)){let e=this._consume(s.tokens.ident,"Expected name for let.").toString(),t=null;if(this._match(s.tokens.colon)){let o=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=o)}this._consume(s.tokens.equal,"Expected '=' for let.");let r=this._short_circuit_or_expression();return new ve(e,t,null,null,r)}if(this._match(s.keywords.const)){let e=this._consume(s.tokens.ident,"Expected name for const.").toString(),t=null;if(this._match(s.tokens.colon)){let o=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=o)}this._consume(s.tokens.equal,"Expected '=' for const.");let r=this._short_circuit_or_expression();return new Ee(e,t,null,null,r)}return null}_increment_decrement_statement(){let e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(s.increment_operators))return this._current=e,null;let r=this._consume(s.increment_operators,"Expected increment operator");return new dt(r.type===s.tokens.plus_plus?le.increment:le.decrement,t)}_assignment_statement(){let e=null;if(this._check(s.tokens.brace_right))return null;let t=this._match(s.tokens.underscore);if(t||(e=this._unary_expression()),!t&&e==null)return null;let r=this._consume(s.assignment_operators,"Expected assignment operator."),o=this._short_circuit_or_expression();return new mt(Ae.parse(r.lexeme),e,o)}_func_call_statement(){if(!this._check(s.tokens.ident))return null;let e=this._current,t=this._consume(s.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=e,null):new Me(t.lexeme,r)}_loop_statement(){if(!this._match(s.keywords.loop))return null;this._check(s.tokens.attr)&&this._attribute(),this._consume(s.tokens.brace_left,"Expected '{' for loop.");let e=[],t=this._statement();for(;t!==null;){if(Array.isArray(t))for(let o of t)e.push(o);else e.push(t);t=this._statement()}let r=null;return this._match(s.keywords.continuing)&&(r=this._compound_statement()),this._consume(s.tokens.brace_right,"Expected '}' for loop."),new gt(e,r)}_switch_statement(){if(!this._match(s.keywords.switch))return null;let e=this._optional_paren_expression();this._check(s.tokens.attr)&&this._attribute(),this._consume(s.tokens.brace_left,"Expected '{' for switch.");let t=this._switch_body();if(t==null||t.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(s.tokens.brace_right,"Expected '}' for switch."),new xt(e,t)}_switch_body(){let e=[];if(this._match(s.keywords.case)){let t=this._case_selectors();this._match(s.tokens.colon),this._check(s.tokens.attr)&&this._attribute(),this._consume(s.tokens.brace_left,"Exected '{' for switch case.");let r=this._case_body();this._consume(s.tokens.brace_right,"Exected '}' for switch case."),e.push(new It(t,r))}if(this._match(s.keywords.default)){this._match(s.tokens.colon),this._check(s.tokens.attr)&&this._attribute(),this._consume(s.tokens.brace_left,"Exected '{' for switch default.");let t=this._case_body();this._consume(s.tokens.brace_right,"Exected '}' for switch default."),e.push(new Ft(t))}if(this._check([s.keywords.default,s.keywords.case])){let t=this._switch_body();e.push(t[0])}return e}_case_selectors(){let e=[this._shift_expression()];for(;this._match(s.tokens.comma);)e.push(this._shift_expression());return e}_case_body(){if(this._match(s.keywords.fallthrough))return this._consume(s.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(s.keywords.if))return null;let e=this._optional_paren_expression();this._check(s.tokens.attr)&&this._attribute();let t=this._compound_statement(),r=[];this._match_elseif()&&(this._check(s.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let o=null;return this._match(s.keywords.else)&&(this._check(s.tokens.attr)&&this._attribute(),o=this._compound_statement()),new vt(e,t,r,o)}_match_elseif(){return this._tokens[this._current].type===s.keywords.else&&this._tokens[this._current+1].type===s.keywords.if?(this._advance(),this._advance(),!0):!1}_elseif_statement(e=[]){let t=this._optional_paren_expression(),r=this._compound_statement();return e.push(new Rt(t,r)),this._match_elseif()&&(this._check(s.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(s.keywords.return))return null;let e=this._short_circuit_or_expression();return new At(e)}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(s.tokens.or_or);)e=new Y(this._previous().toString(),e,this._short_circuit_and_expr());return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(s.tokens.and_and);)e=new Y(this._previous().toString(),e,this._inclusive_or_expression());return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(s.tokens.or);)e=new Y(this._previous().toString(),e,this._exclusive_or_expression());return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(s.tokens.xor);)e=new Y(this._previous().toString(),e,this._and_expression());return e}_and_expression(){let e=this._equality_expression();for(;this._match(s.tokens.and);)e=new Y(this._previous().toString(),e,this._equality_expression());return e}_equality_expression(){let e=this._relational_expression();return this._match([s.tokens.equal_equal,s.tokens.not_equal])?new Y(this._previous().toString(),e,this._relational_expression()):e}_relational_expression(){let e=this._shift_expression();for(;this._match([s.tokens.less_than,s.tokens.greater_than,s.tokens.less_than_equal,s.tokens.greater_than_equal]);)e=new Y(this._previous().toString(),e,this._shift_expression());return e}_shift_expression(){let e=this._additive_expression();for(;this._match([s.tokens.shift_left,s.tokens.shift_right]);)e=new Y(this._previous().toString(),e,this._additive_expression());return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([s.tokens.plus,s.tokens.minus]);)e=new Y(this._previous().toString(),e,this._multiplicative_expression());return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([s.tokens.star,s.tokens.forward_slash,s.tokens.modulo]);)e=new Y(this._previous().toString(),e,this._unary_expression());return e}_unary_expression(){return this._match([s.tokens.minus,s.tokens.bang,s.tokens.tilde,s.tokens.star,s.tokens.and])?new Mt(this._previous().toString(),this._unary_expression()):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(s.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(s.tokens.bracket_right,"Expected ']'.");let t=new Et(e),r=this._postfix_expression();return r&&(t.postfix=r),t}if(this._match(s.tokens.period)){let e=this._consume(s.tokens.ident,"Expected member name."),t=this._postfix_expression(),r=new Re(e.lexeme);return t&&(r.postfix=t),r}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_primary_expression(){if(this._match(s.tokens.ident)){let r=this._previous().toString();if(this._check(s.tokens.paren_left)){let o=this._argument_expression_list(),i=this._getStruct(r);return i!=null?new $(i,o):new Oe(r,o)}if(this._context.constants.has(r)){let o=this._context.constants.get(r);return new Ue(r,o.value)}return new ye(r)}if(this._match(s.const_literal))return new ze(parseFloat(this._previous().toString()));if(this._check(s.tokens.paren_left))return this._paren_expression();if(this._match(s.keywords.bitcast)){this._consume(s.tokens.less_than,"Expected '<'.");let r=this._type_decl();this._consume(s.tokens.greater_than,"Expected '>'.");let o=this._paren_expression();return new Nt(r,o)}let e=this._type_decl(),t=this._argument_expression_list();return new Tt(e,t)}_argument_expression_list(){if(!this._match(s.tokens.paren_left))return null;let e=[];do{if(this._check(s.tokens.paren_right))break;let t=this._short_circuit_or_expression();e.push(t)}while(this._match(s.tokens.comma));return this._consume(s.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(s.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(s.tokens.paren_right),new De([e])}_paren_expression(){this._consume(s.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(s.tokens.paren_right,"Expected ')'."),new De([e])}_struct_decl(){if(!this._match(s.keywords.struct))return null;let e=this._currentLine,t=this._consume(s.tokens.ident,"Expected name for struct.").toString();this._consume(s.tokens.brace_left,"Expected '{' for struct body.");let r=[];for(;!this._check(s.tokens.brace_right);){let a=this._attribute(),c=this._consume(s.tokens.ident,"Expected variable name.").toString();this._consume(s.tokens.colon,"Expected ':' for struct member type.");let u=this._attribute(),h=this._type_decl();h!=null&&(h.attributes=u),this._check(s.tokens.brace_right)?this._match(s.tokens.comma):this._consume(s.tokens.comma,"Expected ',' for struct member."),r.push(new Ot(c,h,a))}this._consume(s.tokens.brace_right,"Expected '}' after struct body.");let o=this._currentLine,i=new V(t,r,e,o);return this._context.structs.set(t,i),i}_global_variable_decl(){let e=this._variable_decl();return e&&this._match(s.tokens.equal)&&(e.value=this._const_expression()),e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(s.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){if(!this._match(s.keywords.const))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),t=null;if(this._match(s.tokens.colon)){let i=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=i)}let r=null;if(this._match(s.tokens.equal)){let i=this._short_circuit_or_expression();if(i instanceof $)r=i;else if(i instanceof Ue&&i.initializer instanceof $)r=i.initializer;else try{let a=i.evaluate(this._context);r=new ze(a)}catch{r=i}}let o=new Ee(e.toString(),t,"","",r);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(s.keywords.let))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),t=null;if(this._match(s.tokens.colon)){let o=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=o)}let r=null;return this._match(s.tokens.equal)&&(r=this._const_expression()),new ve(e.toString(),t,"","",r)}_const_expression(){if(this._match(s.const_literal))return new Re(this._previous().toString());let e=this._type_decl();this._consume(s.tokens.paren_left,"Expected '('.");let t=[];for(;!this._check(s.tokens.paren_right)&&(t.push(this._const_expression()),!!this._check(s.tokens.comma));)this._advance();return this._consume(s.tokens.paren_right,"Expected ')'."),new $(e,t)}_variable_decl(){if(!this._match(s.keywords.var))return null;let e="",t="";this._match(s.tokens.less_than)&&(e=this._consume(s.storage_class,"Expected storage_class.").toString(),this._match(s.tokens.comma)&&(t=this._consume(s.access_mode,"Expected access_mode.").toString()),this._consume(s.tokens.greater_than,"Expected '>'."));let r=this._consume(s.tokens.ident,"Expected variable name"),o=null;if(this._match(s.tokens.colon)){let i=this._attribute();o=this._type_decl(),o!=null&&(o.attributes=i)}return new G(r.toString(),o,e,t,null)}_override_decl(){if(!this._match(s.keywords.override))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),t=null;if(this._match(s.tokens.colon)){let r=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=r)}return new Te(e.toString(),t,null)}_diagnostic(){this._consume(s.tokens.paren_left,"Expected '('");let e=this._consume(s.tokens.ident,"Expected severity control name.");this._consume(s.tokens.comma,"Expected ','");let t=this._consume(s.tokens.ident,"Expected diagnostic rule name.");return this._consume(s.tokens.paren_right,"Expected ')'"),new Pt(e.toString(),t.toString())}_enable_directive(){let e=this._consume(s.tokens.ident,"identity expected.");return new yt(e.toString())}_requires_directive(){let e=[this._consume(s.tokens.ident,"identity expected.").toString()];for(;this._match(s.tokens.comma);){let t=this._consume(s.tokens.ident,"identity expected.");e.push(t.toString())}return new bt(e)}_type_alias(){let e=this._consume(s.tokens.ident,"identity expected.");this._consume(s.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(t===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);let r=new Ie(e.toString(),t);return this._context.aliases.set(r.name,r),r}_type_decl(){if(this._check([s.tokens.ident,...s.texel_format,s.keywords.bool,s.keywords.f32,s.keywords.i32,s.keywords.u32])){let r=this._advance(),o=r.toString();return this._context.structs.has(o)?this._context.structs.get(o):this._context.aliases.has(o)?this._context.aliases.get(o).type:new H(r.toString())}let e=this._texture_sampler_types();if(e)return e;if(this._check(s.template_types)){let r=this._advance().toString(),o=null,i=null;return this._match(s.tokens.less_than)&&(o=this._type_decl(),i=null,this._match(s.tokens.comma)&&(i=this._consume(s.access_mode,"Expected access_mode for pointer").toString()),this._consume(s.tokens.greater_than,"Expected '>' for type.")),new Fe(r,o,i)}if(this._match(s.keywords.ptr)){let r=this._previous().toString();this._consume(s.tokens.less_than,"Expected '<' for pointer.");let o=this._consume(s.storage_class,"Expected storage_class for pointer");this._consume(s.tokens.comma,"Expected ',' for pointer.");let i=this._type_decl(),a=null;return this._match(s.tokens.comma)&&(a=this._consume(s.access_mode,"Expected access_mode for pointer").toString()),this._consume(s.tokens.greater_than,"Expected '>' for pointer."),new St(r,o.toString(),i,a)}let t=this._attribute();if(this._match(s.keywords.array)){let r=null,o=-1,i=this._previous(),a=null;if(this._match(s.tokens.less_than)){r=this._type_decl(),this._context.aliases.has(r.name)&&(r=this._context.aliases.get(r.name).type);let u="";if(this._match(s.tokens.comma)){a=this._shift_expression();try{u=a.evaluate(this._context).toString(),a=null}catch{u="1"}}this._consume(s.tokens.greater_than,"Expected '>' for array."),o=u?parseInt(u):0}let c=new Ce(i.toString(),t,r,o);return a&&this._deferArrayCountEval.push({arrayType:c,countNode:a}),c}return null}_texture_sampler_types(){if(this._match(s.sampler_type))return new J(this._previous().toString(),null,null);if(this._match(s.depth_texture_type))return new J(this._previous().toString(),null,null);if(this._match(s.sampled_texture_type)||this._match(s.multisampled_texture_type)){let e=this._previous();this._consume(s.tokens.less_than,"Expected '<' for sampler type.");let t=this._type_decl();return this._consume(s.tokens.greater_than,"Expected '>' for sampler type."),new J(e.toString(),t,null)}if(this._match(s.storage_texture_type)){let e=this._previous();this._consume(s.tokens.less_than,"Expected '<' for sampler type.");let t=this._consume(s.texel_format,"Invalid texel format.").toString();this._consume(s.tokens.comma,"Expected ',' after texel format.");let r=this._consume(s.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(s.tokens.greater_than,"Expected '>' for sampler type."),new J(e.toString(),t,r)}return null}_attribute(){let e=[];for(;this._match(s.tokens.attr);){let t=this._consume(s.attribute_name,"Expected attribute name"),r=new Ut(t.toString(),null);if(this._match(s.tokens.paren_left)){if(r.value=this._consume(s.literal_or_ident,"Expected attribute value").toString(),this._check(s.tokens.comma)){this._advance();do{let o=this._consume(s.literal_or_ident,"Expected attribute value").toString();r.value instanceof Array||(r.value=[r.value]),r.value.push(o)}while(this._match(s.tokens.comma))}this._consume(s.tokens.paren_right,"Expected ')'")}e.push(r)}return e.length==0?null:e}},K=class{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}},Qe=class{constructor(e,t,r){this.name=e,this.type=t,this.attributes=r,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},oe=class extends K{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},ge=class extends K{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}},qe=class extends K{constructor(e,t,r,o){super(e,r),this.format=t,this.access=o}get isTemplate(){return!0}},j;(function(n){n[n.Uniform=0]="Uniform",n[n.Storage=1]="Storage",n[n.Texture=2]="Texture",n[n.Sampler=3]="Sampler",n[n.StorageTexture=4]="StorageTexture"})(j||(j={}));var ie=class{constructor(e,t,r,o,i,a,c){this.name=e,this.type=t,this.group=r,this.binding=o,this.attributes=i,this.resourceType=a,this.access=c}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},Yt=class{constructor(e,t){this.name=e,this.type=t}},se=class{constructor(e,t){this.align=e,this.size=t}},Xt=class{constructor(e,t,r,o){this.name=e,this.type=t,this.locationType=r,this.location=o,this.interpolation=null}},Ve=class{constructor(e,t,r,o){this.name=e,this.type=t,this.locationType=r,this.location=o}},Bt=class{constructor(e,t=null){this.stage=null,this.inputs=[],this.outputs=[],this.resources=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t}},Qt=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},qt=class{constructor(e,t,r,o){this.name=e,this.type=t,this.attributes=r,this.id=o}},Vt=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},X=class{constructor(e){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Qt,this.functions=[],this._types=new Map,this._functions=new Map,e&&this.update(e)}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}update(e){let r=new Dt().parse(e);for(let o of r)o instanceof xe&&this._functions.set(o.name,new Vt(o));for(let o of r)if(o instanceof V){let i=this._getTypeInfo(o,null);i instanceof oe&&this.structs.push(i)}for(let o of r){if(o instanceof Ie){this.aliases.push(this._getAliasInfo(o));continue}if(o instanceof Te){let i=o,a=this._getAttributeNum(i.attributes,"id",0),c=i.type!=null?this._getTypeInfo(i.type,i.attributes):null;this.overrides.push(new qt(i.name,c,i.attributes,a));continue}if(this._isUniformVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),h=new ie(i.name,u,a,c,i.attributes,j.Uniform,i.access);this.uniforms.push(h);continue}if(this._isStorageVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),h=this._isStorageTexture(u),p=new ie(i.name,u,a,c,i.attributes,h?j.StorageTexture:j.Storage,i.access);this.storage.push(p);continue}if(this._isTextureVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),h=this._isStorageTexture(u),p=new ie(i.name,u,a,c,i.attributes,h?j.StorageTexture:j.Texture,i.access);h?this.storage.push(p):this.textures.push(p);continue}if(this._isSamplerVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),h=new ie(i.name,u,a,c,i.attributes,j.Sampler,i.access);this.samplers.push(h);continue}if(o instanceof xe){let i=this._getAttribute(o,"vertex"),a=this._getAttribute(o,"fragment"),c=this._getAttribute(o,"compute"),u=i||a||c,h=new Bt(o.name,u?.name);h.startLine=o.startLine,h.endLine=o.endLine,this.functions.push(h),this._functions.get(o.name).info=h,u&&(this._functions.get(o.name).inUse=!0,h.inUse=!0,h.resources=this._findResources(o,!!u),h.inputs=this._getInputs(o.args),h.outputs=this._getOutputs(o.returnType),this.entry[u.name].push(h));continue}}for(let o of this._functions.values())o.info&&(o.info.inUse=o.inUse,this._addCalls(o.node,o.info.calls));for(let o of this.uniforms)this._markStructsInUse(o.type);for(let o of this.storage)this._markStructsInUse(o.type)}_markStructsInUse(e){if(e.isStruct){e.inUse=!0;for(let t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)this._markStructsInUse(e.format);else{let t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var r;for(let o of e.calls){let i=(r=this._functions.get(o.name))===null||r===void 0?void 0:r.info;i&&t.add(i)}}findResource(e,t){for(let r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(let r of this.storage)if(r.group==e&&r.binding==t)return r;for(let r of this.textures)if(r.group==e&&r.binding==t)return r;for(let r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(let t of this.uniforms)if(t.name==e)return t;for(let t of this.storage)if(t.name==e)return t;for(let t of this.textures)if(t.name==e)return t;for(let t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){let t=this._getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){let r=[],o=this,i=[];return e.search(a=>{if(a instanceof ae)i.push({});else if(a instanceof ce)i.pop();else if(a instanceof G){let c=a;t&&c.type!==null&&this._markStructsFromAST(c.type),i.length>0&&(i[i.length-1][c.name]=c)}else if(a instanceof $){let c=a;t&&c.type!==null&&this._markStructsFromAST(c.type)}else if(a instanceof ve){let c=a;t&&c.type!==null&&this._markStructsFromAST(c.type),i.length>0&&(i[i.length-1][c.name]=c)}else if(a instanceof ye){let c=a;if(i.length>0&&i[i.length-1][c.name])return;let u=o._findResource(c.name);u&&r.push(u)}else if(a instanceof Oe){let c=a,u=o._functions.get(c.name);u&&(t&&(u.inUse=!0),e.calls.add(u.node),u.resources===null&&(u.resources=o._findResources(u.node,t)),r.push(...u.resources))}else if(a instanceof Me){let c=a,u=o._functions.get(c.name);u&&(t&&(u.inUse=!0),e.calls.add(u.node),u.resources===null&&(u.resources=o._findResources(u.node,t)),r.push(...u.resources))}}),[...new Map(r.map(a=>[a.name,a])).values()]}getBindGroups(){let e=[];function t(r,o){r>=e.length&&(e.length=r+1),e[r]===void 0&&(e[r]=[]),o>=e[r].length&&(e[r].length=o+1)}for(let r of this.uniforms){t(r.group,r.binding);let o=e[r.group];o[r.binding]=r}for(let r of this.storage){t(r.group,r.binding);let o=e[r.group];o[r.binding]=r}for(let r of this.textures){t(r.group,r.binding);let o=e[r.group];o[r.binding]=r}for(let r of this.samplers){t(r.group,r.binding);let o=e[r.group];o[r.binding]=r}return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof V)this._getStructOutputs(e,t);else{let r=this._getOutputInfo(e);r!==null&&t.push(r)}return t}_getStructOutputs(e,t){for(let r of e.members)if(r.type instanceof V)this._getStructOutputs(r.type,t);else{let o=this._getAttribute(r,"location")||this._getAttribute(r,"builtin");if(o!==null){let i=this._getTypeInfo(r.type,r.type.attributes),a=this._parseInt(o.value),c=new Ve(r.name,i,o.name,a);t.push(c)}}}_getOutputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let r=this._getTypeInfo(e,e.attributes),o=this._parseInt(t.value);return new Ve("",r,t.name,o)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(let r of e)if(r.type instanceof V)this._getStructInputs(r.type,t);else{let o=this._getInputInfo(r);o!==null&&t.push(o)}return t}_getStructInputs(e,t){for(let r of e.members)if(r.type instanceof V)this._getStructInputs(r.type,t);else{let o=this._getInputInfo(r);o!==null&&t.push(o)}}_getInputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let r=this._getAttribute(e,"interpolation"),o=this._getTypeInfo(e.type,e.attributes),i=this._parseInt(t.value),a=new Xt(e.name,o,t.name,i);return r!==null&&(a.interpolation=this._parseString(r.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(let t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new Yt(e.name,this._getTypeInfo(e.type,null))}_getTypeInfo(e,t){if(this._types.has(e))return this._types.get(e);if(e instanceof Ce){let o=e,i=this._getTypeInfo(o.format,o.attributes),a=new ge(o.name,t);return a.format=i,a.count=o.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof V){let o=e,i=new oe(o.name,t);i.startLine=o.startLine,i.endLine=o.endLine;for(let a of o.members){let c=this._getTypeInfo(a.type,a.attributes);i.members.push(new Qe(a.name,c,a.attributes))}return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof J){let o=e,i=o.format instanceof H,a=o.format?i?this._getTypeInfo(o.format,null):new K(o.format,null):null,c=new qe(o.name,a,t,o.access);return this._types.set(e,c),this._updateTypeInfo(c),c}if(e instanceof Fe){let o=e,i=o.format?this._getTypeInfo(o.format,null):null,a=new qe(o.name,i,t,o.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let r=new K(e.name,t);return this._types.set(e,r),this._updateTypeInfo(r),r}_updateTypeInfo(e){var t,r;let o=this._getTypeSize(e);if(e.size=(t=o?.size)!==null&&t!==void 0?t:0,e instanceof ge){let i=this._getTypeSize(e.format);e.stride=(r=i?.size)!==null&&r!==void 0?r:0,this._updateTypeInfo(e.format)}e instanceof oe&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let r=0,o=0,i=0,a=0;for(let c=0,u=e.members.length;c<u;++c){let h=e.members[c],p=this._getTypeSize(h);if(!p)continue;(t=this._getAlias(h.type.name))!==null&&t!==void 0||h.type;let d=p.align,m=p.size;r=this._roundUp(d,r+o),o=m,i=r,a=Math.max(a,d),h.offset=r,h.size=m,this._updateTypeInfo(h.type)}e.size=this._roundUp(a,i+o),e.align=a}_getTypeSize(e){var t;if(e==null)return null;let r=this._getAttributeNum(e.attributes,"size",0),o=this._getAttributeNum(e.attributes,"align",0);if(e instanceof Qe&&(e=e.type),e instanceof K){let i=this._getAlias(e.name);i!==null&&(e=i)}{let i=X._typeInfo[e.name];if(i!==void 0){let a=e.format==="f16"?2:1;return new se(Math.max(o,i.align/a),Math.max(r,i.size/a))}}{let i=X._typeInfo[e.name.substring(0,e.name.length-1)];if(i){let a=e.name[e.name.length-1]==="h"?2:1;return new se(Math.max(o,i.align/a),Math.max(r,i.size/a))}}if(e instanceof ge){let i=e,a=8,c=8,u=this._getTypeSize(i.format);u!==null&&(c=u.size,a=u.align);let h=i.count,p=this._getAttributeNum((t=e?.attributes)!==null&&t!==void 0?t:null,"stride",this._roundUp(a,c));return c=h*p,r&&(c=r),new se(Math.max(o,a),Math.max(r,c))}if(e instanceof oe){let i=0,a=0,c=0,u=0,h=0;for(let p of e.members){let d=this._getTypeSize(p.type);d!==null&&(i=Math.max(d.align,i),c=this._roundUp(d.align,c+u),u=d.size,h=c)}return a=this._roundUp(i,h+u),new se(Math.max(o,i),Math.max(r,a))}return null}_isUniformVar(e){return e instanceof G&&e.storage=="uniform"}_isStorageVar(e){return e instanceof G&&e.storage=="storage"}_isTextureVar(e){return e instanceof G&&e.type!==null&&X._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof G&&e.type!==null&&X._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){let r=e;if(!r||!r.attributes)return null;let o=r.attributes;for(let i of o)if(i.name==t)return i;return null}_getAttributeNum(e,t,r){if(e===null)return r;for(let o of e)if(o.name==t){let i=o!==null&&o.value!==null?o.value:r;return i instanceof Array&&(i=i[0]),typeof i=="number"?i:typeof i=="string"?parseInt(i):r}return r}_roundUp(e,t){return Math.ceil(t/e)*e}};X._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}};X._textureTypes=s.any_texture_type.map(n=>n.name);X._samplerTypes=s.sampler_type.map(n=>n.name);function Qn(n){let e={attributes:[],bindings:[]},t;try{t=To(n)}catch(i){return Bn.log.error(i.message)(),e}for(let i of t.uniforms){let a=[];for(let c of i.type?.members||[])a.push({name:c.name,type:Xn(c.type)});e.bindings.push({type:"uniform",name:i.name,location:i.binding,group:i.group,members:a})}let r=t.entry.vertex[0],o=r?.inputs.length||0;for(let i=0;i<o;i++){let a=r.inputs[i];if(a.locationType==="location"){let c=Xn(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:c})}}return e}function Xn(n){return n.format?`${n.name}<${n.format.name}>`:n.name}function To(n){try{return new X(n)}catch(e){if(e instanceof Error)throw e;let t="WGSL parse error";throw typeof e=="object"&&e?.message&&(t+=`: ${e.message} `),typeof e=="object"&&e?.token&&(t+=e.token.line||""),new Error(t,{cause:e})}}var Eo=`float random(vec3 scale, float seed) {
|
|
90
|
+
`)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),a--,a==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),a++)}return!0}}let t=s.simpleTokens[e];if(t)return this._addToken(t),!0;let r=s.none,o=this._isAlpha(e),i=e==="_";if(this._isAlphaNumeric(e)){let a=this._peekAhead();for(;this._isAlphaNumeric(a);)e+=this._advance(),a=this._peekAhead()}if(o){let a=s.keywords[e];if(a)return this._addToken(a),!0}if(o||i)return this._addToken(s.tokens.ident),!0;for(;;){let a=this._findType(e),c=this._peekAhead();if(e==">"&&(c==">"||c=="=")){let u=!1,h=this._tokens.length-1;for(let p=0;p<5&&h>=0;++p,--h)if(this._tokens[h].type===s.tokens.less_than){h>0&&this._tokens[h-1].isArrayOrTemplateType()&&(u=!0);break}if(u)return this._addToken(a),!0}if(a===s.none){let u=e,h=0,p=2;for(let d=0;d<p;++d)if(u+=this._peekAhead(d),a=this._findType(u),a!==s.none){h=d;break}if(a===s.none)return r===s.none?!1:(this._current--,this._addToken(r),!0);e=u,this._current+=h+1}if(r=a,this._isAtEnd())break;e+=this._advance()}return r===s.none?!1:(this._addToken(r),!0)}_findType(e){for(let r in s.regexTokens){let o=s.regexTokens[r];if(this._match(e,o.rule))return o}let t=s.literalTokens[e];return t||s.none}_match(e,t){let r=t.exec(e);return r&&r.index==0&&r[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"}_isAlphaNumeric(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e=="_"||e>="0"&&e<="9"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let t=this._source.substring(this._start,this._current);this._tokens.push(new Qe(e,t,this._line))}},Bt=class{constructor(){this._tokens=[],this._current=0,this._currentLine=0,this._context=new ht,this._deferArrayCountEval=[]}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let t=[];for(;!this._isAtEnd();){let r=this._global_decl_or_directive();if(!r)break;t.push(r)}if(this._deferArrayCountEval.length>0){for(let r of this._deferArrayCountEval){let o=r.arrayType,i=r.countNode;if(i instanceof ye){let c=i.name,u=this._context.constants.get(c);if(u)try{let h=u.evaluate(this._context);o.count=h}catch{}}}this._deferArrayCountEval.length=0}return t}_initialize(e){if(e)if(typeof e=="string"){let t=new Xt(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_error(e,t){return{token:e,message:t,toString:function(){return`${t}`}}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==s.eof}_match(e){if(e instanceof l)return this._check(e)?(this._advance(),!0):!1;for(let t=0,r=e.length;t<r;++t){let o=e[t];if(this._check(o))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),t)}_check(e){if(this._isAtEnd())return!1;let t=this._peek();if(e instanceof Array){let r=t.type;return e.indexOf(r)!=-1}return t.type==e}_advance(){var e,t;return this._currentLine=(t=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&t!==void 0?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(s.tokens.semicolon)&&!this._isAtEnd(););if(this._match(s.keywords.alias)){let t=this._type_alias();return this._consume(s.tokens.semicolon,"Expected ';'"),t}if(this._match(s.keywords.diagnostic)){let t=this._diagnostic();return this._consume(s.tokens.semicolon,"Expected ';'"),t}if(this._match(s.keywords.requires)){let t=this._requires_directive();return this._consume(s.tokens.semicolon,"Expected ';'"),t}if(this._match(s.keywords.enable)){let t=this._enable_directive();return this._consume(s.tokens.semicolon,"Expected ';'"),t}let e=this._attribute();if(this._check(s.keywords.var)){let t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),t}if(this._check(s.keywords.override)){let t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),t}if(this._check(s.keywords.let)){let t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),t}if(this._check(s.keywords.const)){let t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(s.tokens.semicolon,"Expected ';'."),t}if(this._check(s.keywords.struct)){let t=this._struct_decl();return t!=null&&(t.attributes=e),t}if(this._check(s.keywords.fn)){let t=this._function_decl();return t!=null&&(t.attributes=e),t}return null}_function_decl(){if(!this._match(s.keywords.fn))return null;let e=this._currentLine,t=this._consume(s.tokens.ident,"Expected function name.").toString();this._consume(s.tokens.paren_left,"Expected '(' for function arguments.");let r=[];if(!this._check(s.tokens.paren_right))do{if(this._check(s.tokens.paren_right))break;let c=this._attribute(),u=this._consume(s.tokens.ident,"Expected argument name.").toString();this._consume(s.tokens.colon,"Expected ':' for argument type.");let h=this._attribute(),p=this._type_decl();p!=null&&(p.attributes=h,r.push(new Ut(u,p,c)))}while(this._match(s.tokens.comma));this._consume(s.tokens.paren_right,"Expected ')' after function arguments.");let o=null;if(this._match(s.tokens.arrow)){let c=this._attribute();o=this._type_decl(),o!=null&&(o.attributes=c)}let i=this._compound_statement(),a=this._currentLine;return new xe(t,r,o,i,e,a)}_compound_statement(){let e=[];for(this._consume(s.tokens.brace_left,"Expected '{' for block.");!this._check(s.tokens.brace_right);){let t=this._statement();t!==null&&e.push(t)}return this._consume(s.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(s.tokens.semicolon)&&!this._isAtEnd(););if(this._check(s.tokens.attr)&&this._attribute(),this._check(s.keywords.if))return this._if_statement();if(this._check(s.keywords.switch))return this._switch_statement();if(this._check(s.keywords.loop))return this._loop_statement();if(this._check(s.keywords.for))return this._for_statement();if(this._check(s.keywords.while))return this._while_statement();if(this._check(s.keywords.continuing))return this._continuing_statement();if(this._check(s.keywords.static_assert))return this._static_assert_statement();if(this._check(s.tokens.brace_left))return this._compound_statement();let e=null;return this._check(s.keywords.return)?e=this._return_statement():this._check([s.keywords.var,s.keywords.let,s.keywords.const])?e=this._variable_statement():this._match(s.keywords.discard)?e=new St:this._match(s.keywords.break)?e=new Nt:this._match(s.keywords.continue)?e=new Tt:e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement(),e!=null&&this._consume(s.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(s.keywords.static_assert))return null;let e=this._optional_paren_expression();return new pt(e)}_while_statement(){if(!this._match(s.keywords.while))return null;let e=this._optional_paren_expression();this._check(s.tokens.attr)&&this._attribute();let t=this._compound_statement();return new dt(e,t)}_continuing_statement(){if(!this._match(s.keywords.continuing))return null;let e=this._compound_statement();return new mt(e)}_for_statement(){if(!this._match(s.keywords.for))return null;this._consume(s.tokens.paren_left,"Expected '('.");let e=this._check(s.tokens.semicolon)?null:this._for_init();this._consume(s.tokens.semicolon,"Expected ';'.");let t=this._check(s.tokens.semicolon)?null:this._short_circuit_or_expression();this._consume(s.tokens.semicolon,"Expected ';'.");let r=this._check(s.tokens.paren_right)?null:this._for_increment();this._consume(s.tokens.paren_right,"Expected ')'."),this._check(s.tokens.attr)&&this._attribute();let o=this._compound_statement();return new gt(e,t,r,o)}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(s.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(s.tokens.equal)&&(t=this._short_circuit_or_expression()),new H(e.name,e.type,e.storage,e.access,t)}if(this._match(s.keywords.let)){let e=this._consume(s.tokens.ident,"Expected name for let.").toString(),t=null;if(this._match(s.tokens.colon)){let o=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=o)}this._consume(s.tokens.equal,"Expected '=' for let.");let r=this._short_circuit_or_expression();return new ve(e,t,null,null,r)}if(this._match(s.keywords.const)){let e=this._consume(s.tokens.ident,"Expected name for const.").toString(),t=null;if(this._match(s.tokens.colon)){let o=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=o)}this._consume(s.tokens.equal,"Expected '=' for const.");let r=this._short_circuit_or_expression();return new Me(e,t,null,null,r)}return null}_increment_decrement_statement(){let e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(s.increment_operators))return this._current=e,null;let r=this._consume(s.increment_operators,"Expected increment operator");return new xt(r.type===s.tokens.plus_plus?le.increment:le.decrement,t)}_assignment_statement(){let e=null;if(this._check(s.tokens.brace_right))return null;let t=this._match(s.tokens.underscore);if(t||(e=this._unary_expression()),!t&&e==null)return null;let r=this._consume(s.assignment_operators,"Expected assignment operator."),o=this._short_circuit_or_expression();return new vt(Ae.parse(r.lexeme),e,o)}_func_call_statement(){if(!this._check(s.tokens.ident))return null;let e=this._current,t=this._consume(s.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=e,null):new Ie(t.lexeme,r)}_loop_statement(){if(!this._match(s.keywords.loop))return null;this._check(s.tokens.attr)&&this._attribute(),this._consume(s.tokens.brace_left,"Expected '{' for loop.");let e=[],t=this._statement();for(;t!==null;){if(Array.isArray(t))for(let o of t)e.push(o);else e.push(t);t=this._statement()}let r=null;return this._match(s.keywords.continuing)&&(r=this._compound_statement()),this._consume(s.tokens.brace_right,"Expected '}' for loop."),new At(e,r)}_switch_statement(){if(!this._match(s.keywords.switch))return null;let e=this._optional_paren_expression();this._check(s.tokens.attr)&&this._attribute(),this._consume(s.tokens.brace_left,"Expected '{' for switch.");let t=this._switch_body();if(t==null||t.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(s.tokens.brace_right,"Expected '}' for switch."),new yt(e,t)}_switch_body(){let e=[];if(this._match(s.keywords.case)){let t=this._case_selectors();this._match(s.tokens.colon),this._check(s.tokens.attr)&&this._attribute(),this._consume(s.tokens.brace_left,"Exected '{' for switch case.");let r=this._case_body();this._consume(s.tokens.brace_right,"Exected '}' for switch case."),e.push(new Rt(t,r))}if(this._match(s.keywords.default)){this._match(s.tokens.colon),this._check(s.tokens.attr)&&this._attribute(),this._consume(s.tokens.brace_left,"Exected '{' for switch default.");let t=this._case_body();this._consume(s.tokens.brace_right,"Exected '}' for switch default."),e.push(new Ot(t))}if(this._check([s.keywords.default,s.keywords.case])){let t=this._switch_body();e.push(t[0])}return e}_case_selectors(){let e=[this._shift_expression()];for(;this._match(s.tokens.comma);)e.push(this._shift_expression());return e}_case_body(){if(this._match(s.keywords.fallthrough))return this._consume(s.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(s.keywords.if))return null;let e=this._optional_paren_expression();this._check(s.tokens.attr)&&this._attribute();let t=this._compound_statement(),r=[];this._match_elseif()&&(this._check(s.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let o=null;return this._match(s.keywords.else)&&(this._check(s.tokens.attr)&&this._attribute(),o=this._compound_statement()),new bt(e,t,r,o)}_match_elseif(){return this._tokens[this._current].type===s.keywords.else&&this._tokens[this._current+1].type===s.keywords.if?(this._advance(),this._advance(),!0):!1}_elseif_statement(e=[]){let t=this._optional_paren_expression(),r=this._compound_statement();return e.push(new zt(t,r)),this._match_elseif()&&(this._check(s.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(s.keywords.return))return null;let e=this._short_circuit_or_expression();return new Pt(e)}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(s.tokens.or_or);)e=new Y(this._previous().toString(),e,this._short_circuit_and_expr());return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(s.tokens.and_and);)e=new Y(this._previous().toString(),e,this._inclusive_or_expression());return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(s.tokens.or);)e=new Y(this._previous().toString(),e,this._exclusive_or_expression());return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(s.tokens.xor);)e=new Y(this._previous().toString(),e,this._and_expression());return e}_and_expression(){let e=this._equality_expression();for(;this._match(s.tokens.and);)e=new Y(this._previous().toString(),e,this._equality_expression());return e}_equality_expression(){let e=this._relational_expression();return this._match([s.tokens.equal_equal,s.tokens.not_equal])?new Y(this._previous().toString(),e,this._relational_expression()):e}_relational_expression(){let e=this._shift_expression();for(;this._match([s.tokens.less_than,s.tokens.greater_than,s.tokens.less_than_equal,s.tokens.greater_than_equal]);)e=new Y(this._previous().toString(),e,this._shift_expression());return e}_shift_expression(){let e=this._additive_expression();for(;this._match([s.tokens.shift_left,s.tokens.shift_right]);)e=new Y(this._previous().toString(),e,this._additive_expression());return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([s.tokens.plus,s.tokens.minus]);)e=new Y(this._previous().toString(),e,this._multiplicative_expression());return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([s.tokens.star,s.tokens.forward_slash,s.tokens.modulo]);)e=new Y(this._previous().toString(),e,this._unary_expression());return e}_unary_expression(){return this._match([s.tokens.minus,s.tokens.bang,s.tokens.tilde,s.tokens.star,s.tokens.and])?new Ct(this._previous().toString(),this._unary_expression()):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(s.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(s.tokens.bracket_right,"Expected ']'.");let t=new Ft(e),r=this._postfix_expression();return r&&(t.postfix=r),t}if(this._match(s.tokens.period)){let e=this._consume(s.tokens.ident,"Expected member name."),t=this._postfix_expression(),r=new Oe(e.lexeme);return t&&(r.postfix=t),r}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_primary_expression(){if(this._match(s.tokens.ident)){let r=this._previous().toString();if(this._check(s.tokens.paren_left)){let o=this._argument_expression_list(),i=this._getStruct(r);return i!=null?new $(i,o):new Ue(r,o)}if(this._context.constants.has(r)){let o=this._context.constants.get(r);return new ze(r,o.value)}return new ye(r)}if(this._match(s.const_literal))return new De(parseFloat(this._previous().toString()));if(this._check(s.tokens.paren_left))return this._paren_expression();if(this._match(s.keywords.bitcast)){this._consume(s.tokens.less_than,"Expected '<'.");let r=this._type_decl();this._consume(s.tokens.greater_than,"Expected '>'.");let o=this._paren_expression();return new Mt(r,o)}let e=this._type_decl(),t=this._argument_expression_list();return new It(e,t)}_argument_expression_list(){if(!this._match(s.tokens.paren_left))return null;let e=[];do{if(this._check(s.tokens.paren_right))break;let t=this._short_circuit_or_expression();e.push(t)}while(this._match(s.tokens.comma));return this._consume(s.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(s.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(s.tokens.paren_right),new Ye([e])}_paren_expression(){this._consume(s.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(s.tokens.paren_right,"Expected ')'."),new Ye([e])}_struct_decl(){if(!this._match(s.keywords.struct))return null;let e=this._currentLine,t=this._consume(s.tokens.ident,"Expected name for struct.").toString();this._consume(s.tokens.brace_left,"Expected '{' for struct body.");let r=[];for(;!this._check(s.tokens.brace_right);){let a=this._attribute(),c=this._consume(s.tokens.ident,"Expected variable name.").toString();this._consume(s.tokens.colon,"Expected ':' for struct member type.");let u=this._attribute(),h=this._type_decl();h!=null&&(h.attributes=u),this._check(s.tokens.brace_right)?this._match(s.tokens.comma):this._consume(s.tokens.comma,"Expected ',' for struct member."),r.push(new Dt(c,h,a))}this._consume(s.tokens.brace_right,"Expected '}' after struct body.");let o=this._currentLine,i=new V(t,r,e,o);return this._context.structs.set(t,i),i}_global_variable_decl(){let e=this._variable_decl();return e&&this._match(s.tokens.equal)&&(e.value=this._const_expression()),e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(s.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){if(!this._match(s.keywords.const))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),t=null;if(this._match(s.tokens.colon)){let i=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=i)}let r=null;if(this._match(s.tokens.equal)){let i=this._short_circuit_or_expression();if(i instanceof $)r=i;else if(i instanceof ze&&i.initializer instanceof $)r=i.initializer;else try{let a=i.evaluate(this._context);r=new De(a)}catch{r=i}}let o=new Me(e.toString(),t,"","",r);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(s.keywords.let))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),t=null;if(this._match(s.tokens.colon)){let o=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=o)}let r=null;return this._match(s.tokens.equal)&&(r=this._const_expression()),new ve(e.toString(),t,"","",r)}_const_expression(){if(this._match(s.const_literal))return new Oe(this._previous().toString());let e=this._type_decl();this._consume(s.tokens.paren_left,"Expected '('.");let t=[];for(;!this._check(s.tokens.paren_right)&&(t.push(this._const_expression()),!!this._check(s.tokens.comma));)this._advance();return this._consume(s.tokens.paren_right,"Expected ')'."),new $(e,t)}_variable_decl(){if(!this._match(s.keywords.var))return null;let e="",t="";this._match(s.tokens.less_than)&&(e=this._consume(s.storage_class,"Expected storage_class.").toString(),this._match(s.tokens.comma)&&(t=this._consume(s.access_mode,"Expected access_mode.").toString()),this._consume(s.tokens.greater_than,"Expected '>'."));let r=this._consume(s.tokens.ident,"Expected variable name"),o=null;if(this._match(s.tokens.colon)){let i=this._attribute();o=this._type_decl(),o!=null&&(o.attributes=i)}return new H(r.toString(),o,e,t,null)}_override_decl(){if(!this._match(s.keywords.override))return null;let e=this._consume(s.tokens.ident,"Expected variable name"),t=null;if(this._match(s.tokens.colon)){let r=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=r)}return new Ee(e.toString(),t,null)}_diagnostic(){this._consume(s.tokens.paren_left,"Expected '('");let e=this._consume(s.tokens.ident,"Expected severity control name.");this._consume(s.tokens.comma,"Expected ','");let t=this._consume(s.tokens.ident,"Expected diagnostic rule name.");return this._consume(s.tokens.paren_right,"Expected ')'"),new kt(e.toString(),t.toString())}_enable_directive(){let e=this._consume(s.tokens.ident,"identity expected.");return new wt(e.toString())}_requires_directive(){let e=[this._consume(s.tokens.ident,"identity expected.").toString()];for(;this._match(s.tokens.comma);){let t=this._consume(s.tokens.ident,"identity expected.");e.push(t.toString())}return new Lt(e)}_type_alias(){let e=this._consume(s.tokens.ident,"identity expected.");this._consume(s.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(t===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);let r=new Fe(e.toString(),t);return this._context.aliases.set(r.name,r),r}_type_decl(){if(this._check([s.tokens.ident,...s.texel_format,s.keywords.bool,s.keywords.f32,s.keywords.i32,s.keywords.u32])){let r=this._advance(),o=r.toString();return this._context.structs.has(o)?this._context.structs.get(o):this._context.aliases.has(o)?this._context.aliases.get(o).type:new G(r.toString())}let e=this._texture_sampler_types();if(e)return e;if(this._check(s.template_types)){let r=this._advance().toString(),o=null,i=null;return this._match(s.tokens.less_than)&&(o=this._type_decl(),i=null,this._match(s.tokens.comma)&&(i=this._consume(s.access_mode,"Expected access_mode for pointer").toString()),this._consume(s.tokens.greater_than,"Expected '>' for type.")),new Ce(r,o,i)}if(this._match(s.keywords.ptr)){let r=this._previous().toString();this._consume(s.tokens.less_than,"Expected '<' for pointer.");let o=this._consume(s.storage_class,"Expected storage_class for pointer");this._consume(s.tokens.comma,"Expected ',' for pointer.");let i=this._type_decl(),a=null;return this._match(s.tokens.comma)&&(a=this._consume(s.access_mode,"Expected access_mode for pointer").toString()),this._consume(s.tokens.greater_than,"Expected '>' for pointer."),new Et(r,o.toString(),i,a)}let t=this._attribute();if(this._match(s.keywords.array)){let r=null,o=-1,i=this._previous(),a=null;if(this._match(s.tokens.less_than)){r=this._type_decl(),this._context.aliases.has(r.name)&&(r=this._context.aliases.get(r.name).type);let u="";if(this._match(s.tokens.comma)){a=this._shift_expression();try{u=a.evaluate(this._context).toString(),a=null}catch{u="1"}}this._consume(s.tokens.greater_than,"Expected '>' for array."),o=u?parseInt(u):0}let c=new Re(i.toString(),t,r,o);return a&&this._deferArrayCountEval.push({arrayType:c,countNode:a}),c}return null}_texture_sampler_types(){if(this._match(s.sampler_type))return new J(this._previous().toString(),null,null);if(this._match(s.depth_texture_type))return new J(this._previous().toString(),null,null);if(this._match(s.sampled_texture_type)||this._match(s.multisampled_texture_type)){let e=this._previous();this._consume(s.tokens.less_than,"Expected '<' for sampler type.");let t=this._type_decl();return this._consume(s.tokens.greater_than,"Expected '>' for sampler type."),new J(e.toString(),t,null)}if(this._match(s.storage_texture_type)){let e=this._previous();this._consume(s.tokens.less_than,"Expected '<' for sampler type.");let t=this._consume(s.texel_format,"Invalid texel format.").toString();this._consume(s.tokens.comma,"Expected ',' after texel format.");let r=this._consume(s.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(s.tokens.greater_than,"Expected '>' for sampler type."),new J(e.toString(),t,r)}return null}_attribute(){let e=[];for(;this._match(s.tokens.attr);){let t=this._consume(s.attribute_name,"Expected attribute name"),r=new Yt(t.toString(),null);if(this._match(s.tokens.paren_left)){if(r.value=this._consume(s.literal_or_ident,"Expected attribute value").toString(),this._check(s.tokens.comma)){this._advance();do{let o=this._consume(s.literal_or_ident,"Expected attribute value").toString();r.value instanceof Array||(r.value=[r.value]),r.value.push(o)}while(this._match(s.tokens.comma))}this._consume(s.tokens.paren_right,"Expected ')'")}e.push(r)}return e.length==0?null:e}},K=class{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}},qe=class{constructor(e,t,r){this.name=e,this.type=t,this.attributes=r,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},oe=class extends K{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},ge=class extends K{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}},Ve=class extends K{constructor(e,t,r,o){super(e,r),this.format=t,this.access=o}get isTemplate(){return!0}},j;(function(n){n[n.Uniform=0]="Uniform",n[n.Storage=1]="Storage",n[n.Texture=2]="Texture",n[n.Sampler=3]="Sampler",n[n.StorageTexture=4]="StorageTexture"})(j||(j={}));var ie=class{constructor(e,t,r,o,i,a,c){this.name=e,this.type=t,this.group=r,this.binding=o,this.attributes=i,this.resourceType=a,this.access=c}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},Qt=class{constructor(e,t){this.name=e,this.type=t}},se=class{constructor(e,t){this.align=e,this.size=t}},qt=class{constructor(e,t,r,o){this.name=e,this.type=t,this.locationType=r,this.location=o,this.interpolation=null}},He=class{constructor(e,t,r,o){this.name=e,this.type=t,this.locationType=r,this.location=o}},Vt=class{constructor(e,t=null){this.stage=null,this.inputs=[],this.outputs=[],this.resources=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t}},Ht=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Gt=class{constructor(e,t,r,o){this.name=e,this.type=t,this.attributes=r,this.id=o}},Wt=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},X=class{constructor(e){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Ht,this.functions=[],this._types=new Map,this._functions=new Map,e&&this.update(e)}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}update(e){let r=new Bt().parse(e);for(let o of r)o instanceof xe&&this._functions.set(o.name,new Wt(o));for(let o of r)if(o instanceof V){let i=this._getTypeInfo(o,null);i instanceof oe&&this.structs.push(i)}for(let o of r){if(o instanceof Fe){this.aliases.push(this._getAliasInfo(o));continue}if(o instanceof Ee){let i=o,a=this._getAttributeNum(i.attributes,"id",0),c=i.type!=null?this._getTypeInfo(i.type,i.attributes):null;this.overrides.push(new Gt(i.name,c,i.attributes,a));continue}if(this._isUniformVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),h=new ie(i.name,u,a,c,i.attributes,j.Uniform,i.access);this.uniforms.push(h);continue}if(this._isStorageVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),h=this._isStorageTexture(u),p=new ie(i.name,u,a,c,i.attributes,h?j.StorageTexture:j.Storage,i.access);this.storage.push(p);continue}if(this._isTextureVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),h=this._isStorageTexture(u),p=new ie(i.name,u,a,c,i.attributes,h?j.StorageTexture:j.Texture,i.access);h?this.storage.push(p):this.textures.push(p);continue}if(this._isSamplerVar(o)){let i=o,a=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),u=this._getTypeInfo(i.type,i.attributes),h=new ie(i.name,u,a,c,i.attributes,j.Sampler,i.access);this.samplers.push(h);continue}if(o instanceof xe){let i=this._getAttribute(o,"vertex"),a=this._getAttribute(o,"fragment"),c=this._getAttribute(o,"compute"),u=i||a||c,h=new Vt(o.name,u?.name);h.startLine=o.startLine,h.endLine=o.endLine,this.functions.push(h),this._functions.get(o.name).info=h,u&&(this._functions.get(o.name).inUse=!0,h.inUse=!0,h.resources=this._findResources(o,!!u),h.inputs=this._getInputs(o.args),h.outputs=this._getOutputs(o.returnType),this.entry[u.name].push(h));continue}}for(let o of this._functions.values())o.info&&(o.info.inUse=o.inUse,this._addCalls(o.node,o.info.calls));for(let o of this.uniforms)this._markStructsInUse(o.type);for(let o of this.storage)this._markStructsInUse(o.type)}_markStructsInUse(e){if(e.isStruct){e.inUse=!0;for(let t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)this._markStructsInUse(e.format);else{let t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var r;for(let o of e.calls){let i=(r=this._functions.get(o.name))===null||r===void 0?void 0:r.info;i&&t.add(i)}}findResource(e,t){for(let r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(let r of this.storage)if(r.group==e&&r.binding==t)return r;for(let r of this.textures)if(r.group==e&&r.binding==t)return r;for(let r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(let t of this.uniforms)if(t.name==e)return t;for(let t of this.storage)if(t.name==e)return t;for(let t of this.textures)if(t.name==e)return t;for(let t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){let t=this._getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){let r=[],o=this,i=[];return e.search(a=>{if(a instanceof ae)i.push({});else if(a instanceof ce)i.pop();else if(a instanceof H){let c=a;t&&c.type!==null&&this._markStructsFromAST(c.type),i.length>0&&(i[i.length-1][c.name]=c)}else if(a instanceof $){let c=a;t&&c.type!==null&&this._markStructsFromAST(c.type)}else if(a instanceof ve){let c=a;t&&c.type!==null&&this._markStructsFromAST(c.type),i.length>0&&(i[i.length-1][c.name]=c)}else if(a instanceof ye){let c=a;if(i.length>0&&i[i.length-1][c.name])return;let u=o._findResource(c.name);u&&r.push(u)}else if(a instanceof Ue){let c=a,u=o._functions.get(c.name);u&&(t&&(u.inUse=!0),e.calls.add(u.node),u.resources===null&&(u.resources=o._findResources(u.node,t)),r.push(...u.resources))}else if(a instanceof Ie){let c=a,u=o._functions.get(c.name);u&&(t&&(u.inUse=!0),e.calls.add(u.node),u.resources===null&&(u.resources=o._findResources(u.node,t)),r.push(...u.resources))}}),[...new Map(r.map(a=>[a.name,a])).values()]}getBindGroups(){let e=[];function t(r,o){r>=e.length&&(e.length=r+1),e[r]===void 0&&(e[r]=[]),o>=e[r].length&&(e[r].length=o+1)}for(let r of this.uniforms){t(r.group,r.binding);let o=e[r.group];o[r.binding]=r}for(let r of this.storage){t(r.group,r.binding);let o=e[r.group];o[r.binding]=r}for(let r of this.textures){t(r.group,r.binding);let o=e[r.group];o[r.binding]=r}for(let r of this.samplers){t(r.group,r.binding);let o=e[r.group];o[r.binding]=r}return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof V)this._getStructOutputs(e,t);else{let r=this._getOutputInfo(e);r!==null&&t.push(r)}return t}_getStructOutputs(e,t){for(let r of e.members)if(r.type instanceof V)this._getStructOutputs(r.type,t);else{let o=this._getAttribute(r,"location")||this._getAttribute(r,"builtin");if(o!==null){let i=this._getTypeInfo(r.type,r.type.attributes),a=this._parseInt(o.value),c=new He(r.name,i,o.name,a);t.push(c)}}}_getOutputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let r=this._getTypeInfo(e,e.attributes),o=this._parseInt(t.value);return new He("",r,t.name,o)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(let r of e)if(r.type instanceof V)this._getStructInputs(r.type,t);else{let o=this._getInputInfo(r);o!==null&&t.push(o)}return t}_getStructInputs(e,t){for(let r of e.members)if(r.type instanceof V)this._getStructInputs(r.type,t);else{let o=this._getInputInfo(r);o!==null&&t.push(o)}}_getInputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let r=this._getAttribute(e,"interpolation"),o=this._getTypeInfo(e.type,e.attributes),i=this._parseInt(t.value),a=new qt(e.name,o,t.name,i);return r!==null&&(a.interpolation=this._parseString(r.value)),a}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(let t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new Qt(e.name,this._getTypeInfo(e.type,null))}_getTypeInfo(e,t){if(this._types.has(e))return this._types.get(e);if(e instanceof Re){let o=e,i=this._getTypeInfo(o.format,o.attributes),a=new ge(o.name,t);return a.format=i,a.count=o.count,this._types.set(e,a),this._updateTypeInfo(a),a}if(e instanceof V){let o=e,i=new oe(o.name,t);i.startLine=o.startLine,i.endLine=o.endLine;for(let a of o.members){let c=this._getTypeInfo(a.type,a.attributes);i.members.push(new qe(a.name,c,a.attributes))}return this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof J){let o=e,i=o.format instanceof G,a=o.format?i?this._getTypeInfo(o.format,null):new K(o.format,null):null,c=new Ve(o.name,a,t,o.access);return this._types.set(e,c),this._updateTypeInfo(c),c}if(e instanceof Ce){let o=e,i=o.format?this._getTypeInfo(o.format,null):null,a=new Ve(o.name,i,t,o.access);return this._types.set(e,a),this._updateTypeInfo(a),a}let r=new K(e.name,t);return this._types.set(e,r),this._updateTypeInfo(r),r}_updateTypeInfo(e){var t,r;let o=this._getTypeSize(e);if(e.size=(t=o?.size)!==null&&t!==void 0?t:0,e instanceof ge){let i=this._getTypeSize(e.format);e.stride=(r=i?.size)!==null&&r!==void 0?r:0,this._updateTypeInfo(e.format)}e instanceof oe&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let r=0,o=0,i=0,a=0;for(let c=0,u=e.members.length;c<u;++c){let h=e.members[c],p=this._getTypeSize(h);if(!p)continue;(t=this._getAlias(h.type.name))!==null&&t!==void 0||h.type;let d=p.align,m=p.size;r=this._roundUp(d,r+o),o=m,i=r,a=Math.max(a,d),h.offset=r,h.size=m,this._updateTypeInfo(h.type)}e.size=this._roundUp(a,i+o),e.align=a}_getTypeSize(e){var t;if(e==null)return null;let r=this._getAttributeNum(e.attributes,"size",0),o=this._getAttributeNum(e.attributes,"align",0);if(e instanceof qe&&(e=e.type),e instanceof K){let i=this._getAlias(e.name);i!==null&&(e=i)}{let i=X._typeInfo[e.name];if(i!==void 0){let a=e.format==="f16"?2:1;return new se(Math.max(o,i.align/a),Math.max(r,i.size/a))}}{let i=X._typeInfo[e.name.substring(0,e.name.length-1)];if(i){let a=e.name[e.name.length-1]==="h"?2:1;return new se(Math.max(o,i.align/a),Math.max(r,i.size/a))}}if(e instanceof ge){let i=e,a=8,c=8,u=this._getTypeSize(i.format);u!==null&&(c=u.size,a=u.align);let h=i.count,p=this._getAttributeNum((t=e?.attributes)!==null&&t!==void 0?t:null,"stride",this._roundUp(a,c));return c=h*p,r&&(c=r),new se(Math.max(o,a),Math.max(r,c))}if(e instanceof oe){let i=0,a=0,c=0,u=0,h=0;for(let p of e.members){let d=this._getTypeSize(p.type);d!==null&&(i=Math.max(d.align,i),c=this._roundUp(d.align,c+u),u=d.size,h=c)}return a=this._roundUp(i,h+u),new se(Math.max(o,i),Math.max(r,a))}return null}_isUniformVar(e){return e instanceof H&&e.storage=="uniform"}_isStorageVar(e){return e instanceof H&&e.storage=="storage"}_isTextureVar(e){return e instanceof H&&e.type!==null&&X._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof H&&e.type!==null&&X._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){let r=e;if(!r||!r.attributes)return null;let o=r.attributes;for(let i of o)if(i.name==t)return i;return null}_getAttributeNum(e,t,r){if(e===null)return r;for(let o of e)if(o.name==t){let i=o!==null&&o.value!==null?o.value:r;return i instanceof Array&&(i=i[0]),typeof i=="number"?i:typeof i=="string"?parseInt(i):r}return r}_roundUp(e,t){return Math.ceil(t/e)*e}};X._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}};X._textureTypes=s.any_texture_type.map(n=>n.name);X._samplerTypes=s.sampler_type.map(n=>n.name);function Vn(n){let e={attributes:[],bindings:[]},t;try{t=To(n)}catch(i){return qn.log.error(i.message)(),e}for(let i of t.uniforms){let a=[];for(let c of i.type?.members||[])a.push({name:c.name,type:Qn(c.type)});e.bindings.push({type:"uniform",name:i.name,location:i.binding,group:i.group,members:a})}let r=t.entry.vertex[0],o=r?.inputs.length||0;for(let i=0;i<o;i++){let a=r.inputs[i];if(a.locationType==="location"){let c=Qn(a.type);e.attributes.push({name:a.name,location:Number(a.location),type:c})}}return e}function Qn(n){return n.format?`${n.name}<${n.format.name}>`:n.name}function To(n){try{return new X(n)}catch(e){if(e instanceof Error)throw e;let t="WGSL parse error";throw typeof e=="object"&&e?.message&&(t+=`: ${e.message} `),typeof e=="object"&&e?.token&&(t+=e.token.line||""),new Error(t,{cause:e})}}var Eo=`float random(vec3 scale, float seed) {
|
|
91
91
|
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
92
92
|
}
|
|
93
93
|
`,q={name:"random",fs:Eo};var Mo=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
@@ -212,7 +212,7 @@ return tan_taylor_fp32(a);
|
|
|
212
212
|
return tan(a);
|
|
213
213
|
#endif
|
|
214
214
|
}
|
|
215
|
-
`,
|
|
215
|
+
`,Hn={name:"fp32",vs:Mo};var Io=[0,1,1,1],Fo=`uniform pickingUniforms {
|
|
216
216
|
float isActive;
|
|
217
217
|
float isAttribute;
|
|
218
218
|
float isHighlightActive;
|
|
@@ -301,7 +301,7 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
301
301
|
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
302
302
|
return picking_filterPickingColor(highlightColor);
|
|
303
303
|
}
|
|
304
|
-
`,
|
|
304
|
+
`,Gn={name:"picking",vs:Fo,fs:Co,uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useFloatColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useFloatColors:!0,highlightedObjectColor:[0,0,0],highlightColor:Io},getUniforms:Ro};function Ro(n={},e){let t={};if(n.highlightedObjectColor!==void 0)if(n.highlightedObjectColor===null)t.isHighlightActive=!1;else{t.isHighlightActive=!0;let r=n.highlightedObjectColor.slice(0,3);t.highlightedObjectColor=r}if(n.highlightColor){let r=Array.from(n.highlightColor,o=>o/255);Number.isFinite(r[3])||(r[3]=1),t.highlightColor=r}return n.isActive!==void 0&&(t.isActive=Boolean(n.isActive),t.isAttribute=Boolean(n.isAttribute)),n.useFloatColors!==void 0&&(t.useFloatColors=Boolean(n.useFloatColors)),t}var jt=`precision highp int;
|
|
305
305
|
struct AmbientLight {
|
|
306
306
|
vec3 color;
|
|
307
307
|
};
|
|
@@ -320,27 +320,51 @@ int lightType;
|
|
|
320
320
|
int directionalLightCount;
|
|
321
321
|
int pointLightCount;
|
|
322
322
|
vec3 ambientColor;
|
|
323
|
-
vec3
|
|
324
|
-
vec3
|
|
325
|
-
vec3
|
|
326
|
-
vec3
|
|
323
|
+
vec3 lightColor0;
|
|
324
|
+
vec3 lightPosition0;
|
|
325
|
+
vec3 lightDirection0;
|
|
326
|
+
vec3 lightAttenuation0;
|
|
327
|
+
vec3 lightColor1;
|
|
328
|
+
vec3 lightPosition1;
|
|
329
|
+
vec3 lightDirection1;
|
|
330
|
+
vec3 lightAttenuation1;
|
|
331
|
+
vec3 lightColor2;
|
|
332
|
+
vec3 lightPosition2;
|
|
333
|
+
vec3 lightDirection2;
|
|
334
|
+
vec3 lightAttenuation2;
|
|
327
335
|
} lighting;
|
|
328
336
|
PointLight lighting_getPointLight(int index) {
|
|
329
|
-
|
|
337
|
+
switch (index) {
|
|
338
|
+
case 0:
|
|
339
|
+
return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
|
|
340
|
+
case 1:
|
|
341
|
+
return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
|
|
342
|
+
case 2:
|
|
343
|
+
default:
|
|
344
|
+
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
345
|
+
}
|
|
330
346
|
}
|
|
331
347
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
332
|
-
|
|
348
|
+
switch (index) {
|
|
349
|
+
case 0:
|
|
350
|
+
return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
|
|
351
|
+
case 1:
|
|
352
|
+
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
353
|
+
case 2:
|
|
354
|
+
default:
|
|
355
|
+
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
356
|
+
}
|
|
333
357
|
}
|
|
334
358
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
335
359
|
return pointLight.attenuation.x
|
|
336
360
|
+ pointLight.attenuation.y * distance
|
|
337
361
|
+ pointLight.attenuation.z * distance * distance;
|
|
338
362
|
}
|
|
339
|
-
`;var
|
|
363
|
+
`;var Wn=rt(ke(),1),jn=3,Oo=255,be;(function(n){n[n.POINT=0]="POINT",n[n.DIRECTIONAL=1]="DIRECTIONAL"})(be||(be={}));var Q={name:"lighting",vs:jt,fs:jt,getUniforms(n,e){return Uo(n)},defines:{MAX_LIGHTS:jn},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientLightColor:"vec3<f32>",lightColor0:"vec3<f32>",lightPosition0:"vec3<f32>",lightDirection0:"vec3<f32>",lightAttenuation0:"vec3<f32>",lightColor1:"vec3<f32>",lightPosition1:"vec3<f32>",lightDirection1:"vec3<f32>",lightAttenuation1:"vec3<f32>",lightColor2:"vec3<f32>",lightPosition2:"vec3<f32>",lightDirection2:"vec3<f32>",lightAttenuation2:"vec3<f32>"},defaultUniforms:{enabled:1,lightType:be.POINT,directionalLightCount:0,pointLightCount:0,ambientLightColor:[.1,.1,.1],lightColor0:[1,1,1],lightPosition0:[1,1,2],lightDirection0:[1,1,1],lightAttenuation0:[1,0,0],lightColor1:[1,1,1],lightPosition1:[1,1,2],lightDirection1:[1,1,1],lightAttenuation1:[1,0,0],lightColor2:[1,1,1],lightPosition2:[1,1,2],lightDirection2:[1,1,1],lightAttenuation2:[1,0,0]}};function Uo(n,e={}){if(n=n&&{...n},!n)return{...Q.defaultUniforms};n.lights&&(n={...n,...Do(n.lights),lights:void 0});let{ambientLight:t,pointLights:r,directionalLights:o}=n||{};if(!(t||r&&r.length>0||o&&o.length>0))return{...Q.defaultUniforms,enabled:0};let a={...Q.defaultUniforms,...e,...zo({ambientLight:t,pointLights:r,directionalLights:o})};return n.enabled!==void 0&&(a.enabled=n.enabled?1:0),a}function zo({ambientLight:n,pointLights:e=[],directionalLights:t=[]}){let r={};r.ambientLightColor=$t(n);let o=0;for(let i of e){r.lightType=be.POINT;let a=o;r[`lightColor${a}`]=$t(i),r[`lightPosition${a}`]=i.position,r[`lightAttenuation${a}`]=i.attenuation||[1,0,0],o++}for(let i of t){r.lightType=be.DIRECTIONAL;let a=o;r[`lightColor${a}`]=$t(i),r[`lightDirection${a}`]=i.direction,o++}return o>jn&&Wn.log.warn("MAX_LIGHTS exceeded")(),r.directionalLightCount=t.length,r.pointLightCount=e.length,r}function Do(n){let e={pointLights:[],directionalLights:[]};for(let t of n||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return e}function $t(n={}){let{color:e=[0,0,0],intensity:t=1}=n;return e.map(r=>r*t/Oo)}var Yo=`out vec3 dirlight_vNormal;
|
|
340
364
|
void dirlight_setNormal(vec3 normal) {
|
|
341
365
|
dirlight_vNormal = normalize(normal);
|
|
342
366
|
}
|
|
343
|
-
`,
|
|
367
|
+
`,Xo=`uniform dirlightUniforms {
|
|
344
368
|
vec3 lightDirection;
|
|
345
369
|
} dirlight;
|
|
346
370
|
in vec3 dirlight_vNormal;
|
|
@@ -348,75 +372,13 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
348
372
|
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
349
373
|
return vec4(color.rgb * d, color.a);
|
|
350
374
|
}
|
|
351
|
-
`,
|
|
352
|
-
uniform float ambient;
|
|
353
|
-
uniform float diffuse;
|
|
354
|
-
uniform float shininess;
|
|
355
|
-
uniform vec3 specularColor;
|
|
356
|
-
} material;
|
|
357
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
358
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
359
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
360
|
-
float specular = 0.0;
|
|
361
|
-
if (lambertian > 0.0) {
|
|
362
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
363
|
-
specular = pow(specular_angle, material.shininess);
|
|
364
|
-
}
|
|
365
|
-
lambertian = max(lambertian, 0.0);
|
|
366
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
367
|
-
}
|
|
368
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
369
|
-
vec3 lightColor = surfaceColor;
|
|
370
|
-
if (lighting.enabled == 0) {
|
|
371
|
-
return lightColor;
|
|
372
|
-
}
|
|
373
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
374
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
375
|
-
if (lighting.lightType == 0) {
|
|
376
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
377
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
378
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
379
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
380
|
-
} else if (lighting.lightType == 1) {
|
|
381
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
382
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
383
|
-
}
|
|
384
|
-
return lightColor;
|
|
385
|
-
}
|
|
386
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
387
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
388
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
389
|
-
if (lighting.enabled == 0) {
|
|
390
|
-
return lightColor;
|
|
391
|
-
}
|
|
392
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
393
|
-
switch (lighting.lightType) {
|
|
394
|
-
case 0:
|
|
395
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
396
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
397
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
398
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
399
|
-
break;
|
|
400
|
-
case 1:
|
|
401
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
402
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
return lightColor;
|
|
406
|
-
}
|
|
407
|
-
`,Hn=`uniform gouraudMaterialUniforms {
|
|
375
|
+
`,Kt={name:"dirlight",dependencies:[],vs:Yo,fs:Xo,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Bo};function Bo(n=Kt.defaultUniforms){let e={};return n.lightDirection&&(e.dirlight_uLightDirection=n.lightDirection),e}var Ge=`uniform phongMaterialUniforms {
|
|
408
376
|
uniform float ambient;
|
|
409
377
|
uniform float diffuse;
|
|
410
378
|
uniform float shininess;
|
|
411
379
|
uniform vec3 specularColor;
|
|
412
380
|
} material;
|
|
413
|
-
|
|
414
|
-
uniform float ambient;
|
|
415
|
-
uniform float diffuse;
|
|
416
|
-
uniform float shininess;
|
|
417
|
-
uniform vec3 specularColor;
|
|
418
|
-
} material;
|
|
419
|
-
`,jn=`uniform phongMaterialUniforms {
|
|
381
|
+
`,We=`uniform phongMaterialUniforms {
|
|
420
382
|
uniform float ambient;
|
|
421
383
|
uniform float diffuse;
|
|
422
384
|
uniform float shininess;
|
|
@@ -440,39 +402,21 @@ return lightColor;
|
|
|
440
402
|
}
|
|
441
403
|
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
442
404
|
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
443
|
-
|
|
444
|
-
PointLight pointLight = lighting_getPointLight(
|
|
405
|
+
for (int i = 0; i < lighting.pointLightCount; i++) {
|
|
406
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
445
407
|
vec3 light_position_worldspace = pointLight.position;
|
|
446
408
|
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
450
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
451
|
-
}
|
|
452
|
-
return lightColor;
|
|
409
|
+
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
|
|
410
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
|
|
453
411
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
if (lighting.enabled == 0) {
|
|
458
|
-
return lightColor;
|
|
459
|
-
}
|
|
460
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
461
|
-
switch (lighting.lightType) {
|
|
462
|
-
case 0:
|
|
463
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
464
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
465
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
466
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
467
|
-
break;
|
|
468
|
-
case 1:
|
|
469
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
412
|
+
int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
|
|
413
|
+
for (int i = lighting.pointLightCount; i < totalLights; i++) {
|
|
414
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(i);
|
|
470
415
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
471
|
-
break;
|
|
472
416
|
}
|
|
473
417
|
return lightColor;
|
|
474
418
|
}
|
|
475
|
-
`;var
|
|
419
|
+
`;var Zt={name:"gouraudMaterial",vs:We.replace("phongMaterial","gouraudMaterial"),fs:Ge.replace("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:1},dependencies:[Q],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(n){let e={...n};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{...Zt.defaultUniforms,...n}}};var Jt={name:"phongMaterial",vs:Ge,fs:We,defines:{LIGHTING_FRAGMENT:1},dependencies:[Q],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(n){let e={...n};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{...Jt.defaultUniforms,...n}}};var $n=`uniform projection {
|
|
476
420
|
mat4 u_MVPMatrix;
|
|
477
421
|
mat4 u_ModelMatrix;
|
|
478
422
|
mat4 u_NormalMatrix;
|
|
@@ -788,7 +732,7 @@ color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);
|
|
|
788
732
|
}
|
|
789
733
|
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
790
734
|
}
|
|
791
|
-
`;var Zn={name:"pbr",vs:$n,fs:Kn,defines:{LIGHTING_FRAGMENT:1,HAS_NORMALMAP:0,HAS_EMISSIVEMAP:0,HAS_OCCLUSIONMAP:0,HAS_BASECOLORMAP:0,HAS_METALROUGHNESSMAP:0,ALPHA_CUTOFF:0,USE_IBL:0,PBR_DEBUG:0},uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>"},dependencies:[Q]};var
|
|
735
|
+
`;var Zn={name:"pbr",vs:$n,fs:Kn,defines:{LIGHTING_FRAGMENT:1,HAS_NORMALMAP:0,HAS_EMISSIVEMAP:0,HAS_OCCLUSIONMAP:0,HAS_BASECOLORMAP:0,HAS_METALROUGHNESSMAP:0,ALPHA_CUTOFF:0,USE_IBL:0,PBR_DEBUG:0},uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>"},dependencies:[Q]};var Qo=`uniform brightnessContrastUniforms {
|
|
792
736
|
float brightness;
|
|
793
737
|
float contrast;
|
|
794
738
|
} brightnessContrast;
|
|
@@ -804,7 +748,7 @@ return color;
|
|
|
804
748
|
vec4 brightnessContrast_filterColor(vec4 color, vec2 texSize, vec2 texCoords) {
|
|
805
749
|
return brightnessContrast_filterColor(color);
|
|
806
750
|
}
|
|
807
|
-
`,Jn={name:"brightnessContrast",uniformTypes:{brightness:"f32",contrast:"f32"},uniformPropTypes:{brightness:{format:"f32",value:0,min:-1,max:1},contrast:{format:"f32",value:0,min:-1,max:1}},fs:
|
|
751
|
+
`,Jn={name:"brightnessContrast",uniformTypes:{brightness:"f32",contrast:"f32"},uniformPropTypes:{brightness:{format:"f32",value:0,min:-1,max:1},contrast:{format:"f32",value:0,min:-1,max:1}},fs:Qo,passes:[{filter:!0}]};var qo=`uniform denoiseUniforms {
|
|
808
752
|
float strength;
|
|
809
753
|
} noise;
|
|
810
754
|
vec4 denoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
@@ -823,7 +767,7 @@ total += weight;
|
|
|
823
767
|
}
|
|
824
768
|
return color / total;
|
|
825
769
|
}
|
|
826
|
-
`,er={name:"denoise",uniformTypes:{strength:"f32"},uniformPropTypes:{strength:{format:"f32",value:.5,min:0,max:1}},fs:
|
|
770
|
+
`,er={name:"denoise",uniformTypes:{strength:"f32"},uniformPropTypes:{strength:{format:"f32",value:.5,min:0,max:1}},fs:qo,passes:[{sampler:!0},{sampler:!0}]};var Vo=`uniform hueSaturationUniforms {
|
|
827
771
|
float hue;
|
|
828
772
|
float saturation;
|
|
829
773
|
} hueSaturation;
|
|
@@ -848,7 +792,7 @@ return color;
|
|
|
848
792
|
vec4 hueSaturation_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
849
793
|
return hueSaturation_filterColor(color);
|
|
850
794
|
}
|
|
851
|
-
`,tr={name:"hueSaturation",uniformTypes:{hue:"f32",saturation:"f32"},uniformPropTypes:{hue:{value:0,min:-1,max:1},saturation:{value:0,min:-1,max:1}},fs:
|
|
795
|
+
`,tr={name:"hueSaturation",uniformTypes:{hue:"f32",saturation:"f32"},uniformPropTypes:{hue:{value:0,min:-1,max:1},saturation:{value:0,min:-1,max:1}},fs:Vo,passes:[{filter:!0}]};var Ho=`uniform noiseUniforms {
|
|
852
796
|
float amount;
|
|
853
797
|
} noise;
|
|
854
798
|
float rand(vec2 co) {
|
|
@@ -864,7 +808,7 @@ return color;
|
|
|
864
808
|
vec4 noise_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
865
809
|
return noise_filterColor(color, texCoord);
|
|
866
810
|
}
|
|
867
|
-
`,nr={name:"noise",uniformTypes:{amount:"f32"},uniformPropTypes:{amount:{value:.5,min:0,max:1}},fs:Ho,passes:[{filter:!0}]};var
|
|
811
|
+
`,nr={name:"noise",uniformTypes:{amount:"f32"},uniformPropTypes:{amount:{value:.5,min:0,max:1}},fs:Ho,passes:[{filter:!0}]};var Go=`uniform sepiaUniforms {
|
|
868
812
|
float amount;
|
|
869
813
|
} sepia;
|
|
870
814
|
vec4 sepia_filterColor(vec4 color) {
|
|
@@ -880,7 +824,7 @@ return color;
|
|
|
880
824
|
vec4 sepia_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
881
825
|
return sepia_filterColor(color);
|
|
882
826
|
}
|
|
883
|
-
`,rr={name:"sepia",uniformTypes:{amount:"f32"},uniformPropTypes:{amount:{value:.5,min:0,max:1}},fs:
|
|
827
|
+
`,rr={name:"sepia",uniformTypes:{amount:"f32"},uniformPropTypes:{amount:{value:.5,min:0,max:1}},fs:Go,passes:[{filter:!0}]};var Wo=`uniform vibranceUniforms {
|
|
884
828
|
float amount;
|
|
885
829
|
} vibrance;
|
|
886
830
|
vec4 vibrance_filterColor(vec4 color) {
|
|
@@ -893,7 +837,7 @@ return color;
|
|
|
893
837
|
vec4 vibrance_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
894
838
|
return vibrance_filterColor(color);
|
|
895
839
|
}
|
|
896
|
-
`,or={name:"vibrance",uniformPropTypes:{amount:{value:0,min:-1,max:1}},fs:
|
|
840
|
+
`,or={name:"vibrance",uniformPropTypes:{amount:{value:0,min:-1,max:1}},fs:Wo,passes:[{filter:!0}]};var jo=`uniform vignetteUniforms {
|
|
897
841
|
float radius;
|
|
898
842
|
float amount;
|
|
899
843
|
} vignette;
|
|
@@ -905,7 +849,7 @@ return color.rgba * ratio + (1.0 - ratio)*vec4(0.0, 0.0, 0.0, 1.0);
|
|
|
905
849
|
vec4 vignette_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
906
850
|
return vignette_filterColor(color, texCoord);
|
|
907
851
|
}
|
|
908
|
-
`,ir={name:"vignette",fs
|
|
852
|
+
`,ir={name:"vignette",fs:jo,uniformTypes:{radius:"f32",amount:"f32"},uniformPropTypes:{radius:{value:.5,min:0,max:1},amount:{value:.5,min:0,max:1}},passes:[{filter:!0}]};var $o=`uniform tiltShiftUniforms {
|
|
909
853
|
float blurRadius;
|
|
910
854
|
float gradientRadius;
|
|
911
855
|
vec2 start;
|
|
@@ -935,7 +879,7 @@ color = color / total;
|
|
|
935
879
|
color.rgb /= color.a + 0.00001;
|
|
936
880
|
return color;
|
|
937
881
|
}
|
|
938
|
-
`,sr={name:"tiltShift",uniformTypes:{blurRadius:"f32",gradientRadius:"f32",start:"vec2<f32>",end:"vec2<f32>",invert:"i32"},uniformPropTypes:{blurRadius:{value:15,min:0,max:50},gradientRadius:{value:200,min:0,max:400},start:{value:[0,0]},end:{value:[1,1]},invert:{value:!1,private:!0}},passes:[{sampler:!0,uniforms:{invert:!1}},{sampler:!0,uniforms:{invert:!0}}],dependencies:[q],fs
|
|
882
|
+
`,sr={name:"tiltShift",uniformTypes:{blurRadius:"f32",gradientRadius:"f32",start:"vec2<f32>",end:"vec2<f32>",invert:"i32"},uniformPropTypes:{blurRadius:{value:15,min:0,max:50},gradientRadius:{value:200,min:0,max:400},start:{value:[0,0]},end:{value:[1,1]},invert:{value:!1,private:!0}},passes:[{sampler:!0,uniforms:{invert:!1}},{sampler:!0,uniforms:{invert:!0}}],dependencies:[q],fs:$o};var Ko=`uniform triangleBlurUniforms {
|
|
939
883
|
float radius;
|
|
940
884
|
vec2 delta;
|
|
941
885
|
} triangleBlur;
|
|
@@ -956,7 +900,7 @@ color = color / total;
|
|
|
956
900
|
color.rgb /= color.a + 0.00001;
|
|
957
901
|
return color;
|
|
958
902
|
}
|
|
959
|
-
`,ar={name:"triangleBlur",uniformTypes:{radius:"f32",delta:"vec2<f32>"},uniformPropTypes:{radius:{value:20,min:0,softMax:100},delta:{value:[1,0],private:!0}},fs:
|
|
903
|
+
`,ar={name:"triangleBlur",uniformTypes:{radius:"f32",delta:"vec2<f32>"},uniformPropTypes:{radius:{value:20,min:0,softMax:100},delta:{value:[1,0],private:!0}},fs:Ko,dependencies:[q],passes:[{sampler:!0,uniforms:{delta:[1,0]}},{sampler:!0,uniforms:{delta:[0,1]}}]};var Zo=`
|
|
960
904
|
uniform zoomBlurUniforms {
|
|
961
905
|
vec2 center;
|
|
962
906
|
float strength;
|
|
@@ -989,7 +933,7 @@ vec4 zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
989
933
|
|
|
990
934
|
return color;
|
|
991
935
|
}
|
|
992
|
-
`,cr={name:"zoomBlur",uniformTypes:{center:"vec2<f32>",strength:"f32"},uniformPropTypes:{center:{value:[.5,.5]},strength:{value:.3,min:0,softMax:1}},fs:
|
|
936
|
+
`,cr={name:"zoomBlur",uniformTypes:{center:"vec2<f32>",strength:"f32"},uniformPropTypes:{center:{value:[.5,.5]},strength:{value:.3,min:0,softMax:1}},fs:Zo,dependencies:[q],passes:[{sampler:!0}]};var Jo=`uniform colorHalftoneUniforms {
|
|
993
937
|
vec2 center;
|
|
994
938
|
float angle;
|
|
995
939
|
float size;
|
|
@@ -1020,7 +964,7 @@ pattern(colorHalftone.angle, scale, texSize, texCoord)
|
|
|
1020
964
|
k = clamp(k * 10.0 - 5.0 + pattern(colorHalftone.angle + 0.78539, scale, texSize, texCoord), 0.0, 1.0);
|
|
1021
965
|
return vec4(1.0 - cmy - k, color.a);
|
|
1022
966
|
}
|
|
1023
|
-
`,lr={name:"colorHalftone",uniformTypes:{center:"vec2<f32>",angle:"f32",size:"f32"},uniformPropTypes:{center:{value:[.5,.5]},angle:{value:1.1,softMin:0,softMax:Math.PI/2},size:{value:4,min:1,softMin:3,softMax:20}},fs:
|
|
967
|
+
`,lr={name:"colorHalftone",uniformTypes:{center:"vec2<f32>",angle:"f32",size:"f32"},uniformPropTypes:{center:{value:[.5,.5]},angle:{value:1.1,softMin:0,softMax:Math.PI/2},size:{value:4,min:1,softMin:3,softMax:20}},fs:Jo,passes:[{filter:!0}]};var ei=`uniform dotScreenUniforms {
|
|
1024
968
|
vec2 center;
|
|
1025
969
|
float angle;
|
|
1026
970
|
float size;
|
|
@@ -1039,7 +983,7 @@ vec4 dotScreen_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
|
1039
983
|
float average = (color.r + color.g + color.b) / 3.0;
|
|
1040
984
|
return vec4(vec3(average * 10.0 - 5.0 + pattern(texSize, texCoord)), color.a);
|
|
1041
985
|
}
|
|
1042
|
-
`,fr={name:"dotScreen",uniformTypes:{center:"vec2<f32>",angle:"f32",size:"f32"},uniformPropTypes:{center:{value:[.5,.5]},angle:{value:1.1,softMin:0,softMax:Math.PI/2},size:{value:3,min:1,softMin:3,softMax:20}},fs:
|
|
986
|
+
`,fr={name:"dotScreen",uniformTypes:{center:"vec2<f32>",angle:"f32",size:"f32"},uniformPropTypes:{center:{value:[.5,.5]},angle:{value:1.1,softMin:0,softMax:Math.PI/2},size:{value:3,min:1,softMin:3,softMax:20}},fs:ei,passes:[{filter:!0}]};var ti=`uniform edgeWorkUniforms {
|
|
1043
987
|
float radius;
|
|
1044
988
|
vec2 delta;
|
|
1045
989
|
} edgeWork;
|
|
@@ -1083,7 +1027,7 @@ total.y += weight;
|
|
|
1083
1027
|
float c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
|
|
1084
1028
|
return vec4(c, c, c, 1.0);
|
|
1085
1029
|
}
|
|
1086
|
-
`,ur={name:"edgeWork",uniformPropTypes:{radius:{value:2,min:1,softMax:50},delta:{value:[1,0],private:!0}},fs:
|
|
1030
|
+
`,ur={name:"edgeWork",uniformPropTypes:{radius:{value:2,min:1,softMax:50},delta:{value:[1,0],private:!0}},fs:ti,dependencies:[q],passes:[{sampler:"edgeWork_sampleColor1",uniformPropTypes:{delta:[1,0]}},{sampler:"edgeWork_sampleColor2",uniformPropTypes:{delta:[0,1]}}]};var ni=`uniform hexagonalPixelateUniforms {
|
|
1087
1031
|
vec2 center;
|
|
1088
1032
|
float scale;
|
|
1089
1033
|
} hexagonalPixelate;
|
|
@@ -1118,7 +1062,7 @@ choice.y *= 0.866025404;
|
|
|
1118
1062
|
choice *= hexagonalPixelate.scale / texSize;
|
|
1119
1063
|
return texture(source, choice + hexagonalPixelate.center);
|
|
1120
1064
|
}
|
|
1121
|
-
`,_r={name:"hexagonalPixelate",uniformTypes:{center:"vec2<f32>",scale:"f32"},uniformPropTypes:{center:{value:[.5,.5],hint:"screenspace"},scale:{value:10,min:1,softMin:5,softMax:50}},fs:
|
|
1065
|
+
`,_r={name:"hexagonalPixelate",uniformTypes:{center:"vec2<f32>",scale:"f32"},uniformPropTypes:{center:{value:[.5,.5],hint:"screenspace"},scale:{value:10,min:1,softMin:5,softMax:50}},fs:ni,passes:[{sampler:!0}]};var ri=`uniform inkUniforms {
|
|
1122
1066
|
float strength;
|
|
1123
1067
|
} ink;
|
|
1124
1068
|
vec4 ink_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
@@ -1144,7 +1088,7 @@ vec3 edge = max(vec3(0.0), bigAverage / bigTotal - smallAverage / smallTotal);
|
|
|
1144
1088
|
float power = ink.strength * ink.strength * ink.strength * ink.strength * ink.strength;
|
|
1145
1089
|
return vec4(color.rgb - dot(edge, edge) * power * 100000.0, color.a);
|
|
1146
1090
|
}
|
|
1147
|
-
`,hr={name:"ink",uniformTypes:{strength:"f32"},uniformPropTypes:{strength:{value:.25,min:0,softMax:1}},fs:
|
|
1091
|
+
`,hr={name:"ink",uniformTypes:{strength:"f32"},uniformPropTypes:{strength:{value:.25,min:0,softMax:1}},fs:ri,passes:[{sampler:!0}]};var oi=`uniform magnifyUniforms {
|
|
1148
1092
|
vec2 screenXY;
|
|
1149
1093
|
float radiusPixels;
|
|
1150
1094
|
float zoom;
|
|
@@ -1162,7 +1106,7 @@ return magnify.borderColor;
|
|
|
1162
1106
|
}
|
|
1163
1107
|
return texture(source, texCoord);
|
|
1164
1108
|
}
|
|
1165
|
-
`,pr={name:"magnify",uniformTypes:{screenXY:"vec2<f32>",radiusPixels:"f32",zoom:"f32",borderWidthPixels:"f32",borderColor:"vec4<f32>"},uniformPropTypes:{screenXY:{value:[0,0]},radiusPixels:200,zoom:2,borderWidthPixels:0,borderColor:{value:[255,255,255,255]}},fs:
|
|
1109
|
+
`,pr={name:"magnify",uniformTypes:{screenXY:"vec2<f32>",radiusPixels:"f32",zoom:"f32",borderWidthPixels:"f32",borderColor:"vec4<f32>"},uniformPropTypes:{screenXY:{value:[0,0]},radiusPixels:200,zoom:2,borderWidthPixels:0,borderColor:{value:[255,255,255,255]}},fs:oi,passes:[{sampler:!0}]};var ii=`vec4 warp_sampleColor(sampler2D source, vec2 texSize, vec2 coord) {
|
|
1166
1110
|
vec4 color = texture(source, coord / texSize);
|
|
1167
1111
|
vec2 clampedCoord = clamp(coord, vec2(0.0), texSize);
|
|
1168
1112
|
if (coord != clampedCoord) {
|
|
@@ -1170,7 +1114,7 @@ color.a *= max(0.0, 1.0 - length(coord - clampedCoord));
|
|
|
1170
1114
|
}
|
|
1171
1115
|
return color;
|
|
1172
1116
|
}
|
|
1173
|
-
`,fe={name:"warp",passes:[],fs:
|
|
1117
|
+
`,fe={name:"warp",passes:[],fs:ii};var si=`uniform bulgePinchUniforms {
|
|
1174
1118
|
float radius;
|
|
1175
1119
|
float strength;
|
|
1176
1120
|
vec2 center;
|
|
@@ -1194,7 +1138,7 @@ vec2 coord = texCoord * texSize;
|
|
|
1194
1138
|
coord = bulgePinch_warp(coord, bulgePinch.center * texSize);
|
|
1195
1139
|
return warp_sampleColor(source, texSize, coord);
|
|
1196
1140
|
}
|
|
1197
|
-
`,dr={name:"bulgePinch",fs:
|
|
1141
|
+
`,dr={name:"bulgePinch",fs:si,uniformTypes:{center:"vec2<f32>",radius:"f32",strength:"f32"},uniformPropTypes:{center:{value:[.5,.5]},radius:{value:200,min:1,softMax:600},strength:{value:.5,min:-1,max:1}},dependencies:[fe],passes:[{sampler:!0}]};var ai=`uniform swirlUniforms {
|
|
1198
1142
|
float radius;
|
|
1199
1143
|
float angle;
|
|
1200
1144
|
vec2 center;
|
|
@@ -1220,7 +1164,7 @@ vec2 coord = texCoord * texSize;
|
|
|
1220
1164
|
coord = swirl_warp(coord, swirl.center * texSize);
|
|
1221
1165
|
return warp_sampleColor(source, texSize, coord);
|
|
1222
1166
|
}
|
|
1223
|
-
`,mr={name:"swirl",fs:
|
|
1167
|
+
`,mr={name:"swirl",fs:ai,uniformTypes:{center:"vec2<f32>",radius:"f32",angle:"f32"},uniformPropTypes:{center:{value:[.5,.5]},radius:{value:200,min:1,softMax:600},angle:{value:3,softMin:-25,softMax:25}},dependencies:[fe],passes:[{sampler:!0}]};var ci=`
|
|
1224
1168
|
#define FXAA_QUALITY_PRESET 29
|
|
1225
1169
|
|
|
1226
1170
|
#if (FXAA_QUALITY_PRESET == 10)
|
|
@@ -1800,7 +1744,7 @@ vec4 fxaa_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
1800
1744
|
fxaa_QualityEdgeThresholdMin
|
|
1801
1745
|
);
|
|
1802
1746
|
}
|
|
1803
|
-
`,gr={name:"fxaa",uniformPropTypes:{},fs:
|
|
1747
|
+
`,gr={name:"fxaa",uniformPropTypes:{},fs:ci,passes:[{sampler:!0}]};function je(n,e=[],t=0){let r=Math.fround(n),o=n-r;return e[t]=r,e[t+1]=o,e}function en(n){return n-Math.fround(n)}function tn(n){let e=new Float32Array(32);for(let t=0;t<4;++t)for(let r=0;r<4;++r){let o=t*4+r;je(n[r*4+t],e,o*2)}return e}var xr=`uniform float ONE;
|
|
1804
1748
|
vec2 split(float a) {
|
|
1805
1749
|
const float SPLIT = 4097.0;
|
|
1806
1750
|
float t = a * SPLIT;
|
|
@@ -2445,7 +2389,7 @@ tmp[j] = b[j + i * 4];
|
|
|
2445
2389
|
vec4_dot_fp64(a, tmp, out_val[i]);
|
|
2446
2390
|
}
|
|
2447
2391
|
}
|
|
2448
|
-
`;var
|
|
2392
|
+
`;var li={ONE:1};function fi(){return li}var nn={name:"fp64-arithmetic",vs:xr,getUniforms:fi,fp64ify:je,fp64LowPart:en,fp64ifyMatrix4:tn},Ar={name:"fp64",vs:vr,dependencies:[nn],fp64ify:je,fp64LowPart:en,fp64ifyMatrix4:tn};var ui=`varying vec4 geometry_vPosition;
|
|
2449
2393
|
varying vec3 geometry_vNormal;
|
|
2450
2394
|
void geometry_setNormal(vec3 normal) {
|
|
2451
2395
|
geometry_vNormal = normal;
|
|
@@ -2456,7 +2400,7 @@ geometry_vPosition = position;
|
|
|
2456
2400
|
void geometry_setPosition(vec3 position) {
|
|
2457
2401
|
geometry_vPosition = vec4(position, 1.);
|
|
2458
2402
|
}
|
|
2459
|
-
`,
|
|
2403
|
+
`,_i=`varying vec4 geometry_vPosition;
|
|
2460
2404
|
varying vec3 geometry_vNormal;
|
|
2461
2405
|
vec4 geometry_getPosition() {
|
|
2462
2406
|
return geometry_vPosition;
|
|
@@ -2464,7 +2408,7 @@ return geometry_vPosition;
|
|
|
2464
2408
|
vec3 geometry_getNormal() {
|
|
2465
2409
|
return geometry_vNormal;
|
|
2466
2410
|
}
|
|
2467
|
-
`,yr={name:"geometry",vs:_i,fs:hi};var Ra=1/Math.PI*180,Oa=1/180*Math.PI,pi={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...pi}};var O=globalThis.mathgl.config;function br(n,{precision:e=O.precision}={}){return n=di(n),`${parseFloat(n.toPrecision(e))}`}function He(n){return Array.isArray(n)||ArrayBuffer.isView(n)&&!(n instanceof DataView)}function en(n,e,t){let r=O.EPSILON;t&&(O.EPSILON=t);try{if(n===e)return!0;if(He(n)&&He(e)){if(n.length!==e.length)return!1;for(let o=0;o<n.length;++o)if(!en(n[o],e[o]))return!1;return!0}return n&&n.equals?n.equals(e):e&&e.equals?e.equals(n):typeof n=="number"&&typeof e=="number"?Math.abs(n-e)<=O.EPSILON*Math.max(1,Math.abs(n),Math.abs(e)):!1}finally{O.EPSILON=r}}function di(n){return Math.round(n/O.EPSILON)*O.EPSILON}var We=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,t=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=e[r+t];return this.check()}toArray(e=[],t=0){for(let r=0;r<this.ELEMENTS;++r)e[t+r]=this[r];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:He(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(O)}formatString(e){let t="";for(let r=0;r<this.ELEMENTS;++r)t+=(r>0?", ":"")+br(this[r],e);return`${e.printTypes?this.constructor.name:""}[${t}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(!en(this[t],e[t]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(this[t]!==e[t])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,t,r){if(r===void 0)return this.lerp(this,e,t);for(let o=0;o<this.ELEMENTS;++o){let i=e[o],a=typeof t=="number"?t:t[o];this[o]=i+r*(a-i)}return this.check()}min(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.min(e[t],this[t]);return this.check()}max(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.max(e[t],this[t]);return this.check()}clamp(e,t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e[r]),t[r]);return this.check()}add(...e){for(let t of e)for(let r=0;r<this.ELEMENTS;++r)this[r]+=t[r];return this.check()}subtract(...e){for(let t of e)for(let r=0;r<this.ELEMENTS;++r)this[r]-=t[r];return this.check()}scale(e){if(typeof e=="number")for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;else for(let t=0;t<this.ELEMENTS&&t<e.length;++t)this[t]*=e[t];return this.check()}multiplyByScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}check(){if(O.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let t=0;t<this.ELEMENTS;++t)e=e&&Number.isFinite(this[t]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=e;return this.check()}addScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e),t);return this.check()}get elements(){return this}};function mi(n,e){if(n.length!==e)return!1;for(let t=0;t<n.length;++t)if(!Number.isFinite(n[t]))return!1;return!0}function Pr(n){if(!Number.isFinite(n))throw new Error(`Invalid number ${JSON.stringify(n)}`);return n}function je(n,e,t=""){if(O.debug&&!mi(n,e))throw new Error(`math.gl: ${t} some fields set to invalid numbers'`);return n}var W=typeof Float32Array<"u"?Float32Array:Array;var Ba=Math.PI/180;function gi(){let n=new W(2);return W!=Float32Array&&(n[0]=0,n[1]=0),n}function kr(n,e,t){let r=e[0],o=e[1];return n[0]=t[0]*r+t[4]*o+t[12],n[1]=t[1]*r+t[5]*o+t[13],n}var Qa=function(){let n=gi();return function(e,t,r,o,i,a){let c,u;for(t||(t=2),r||(r=0),o?u=Math.min(o*t+r,e.length):u=e.length,c=r;c<u;c+=t)n[0]=e[c],n[1]=e[c+1],i(n,n,a),e[c]=n[0],e[c+1]=n[1];return e}}();function Sr(n,e,t){let r=e[0],o=e[1],i=t[3]*r+t[7]*o||1;return n[0]=(t[0]*r+t[4]*o)/i,n[1]=(t[1]*r+t[5]*o)/i,n}function Nr(n,e,t){let r=e[0],o=e[1],i=e[2],a=t[3]*r+t[7]*o+t[11]*i||1;return n[0]=(t[0]*r+t[4]*o+t[8]*i)/a,n[1]=(t[1]*r+t[5]*o+t[9]*i)/a,n[2]=(t[2]*r+t[6]*o+t[10]*i)/a,n}function xi(){let n=new W(3);return W!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0),n}function Tr(n,e,t){let r=e[0],o=e[1],i=e[2],a=t[3]*r+t[7]*o+t[11]*i+t[15];return a=a||1,n[0]=(t[0]*r+t[4]*o+t[8]*i+t[12])/a,n[1]=(t[1]*r+t[5]*o+t[9]*i+t[13])/a,n[2]=(t[2]*r+t[6]*o+t[10]*i+t[14])/a,n}var Ga=function(){let n=xi();return function(e,t,r,o,i,a){let c,u;for(t||(t=3),r||(r=0),o?u=Math.min(o*t+r,e.length):u=e.length,c=r;c<u;c+=t)n[0]=e[c],n[1]=e[c+1],n[2]=e[c+2],i(n,n,a),e[c]=n[0],e[c+1]=n[1],e[c+2]=n[2];return e}}();var $e=class extends We{toString(){let e="[";if(O.printRowMajor){e+="row-major:";for(let t=0;t<this.RANK;++t)for(let r=0;r<this.RANK;++r)e+=` ${this[r*this.RANK+t]}`}else{e+="column-major:";for(let t=0;t<this.ELEMENTS;++t)e+=` ${this[t]}`}return e+="]",e}getElementIndex(e,t){return t*this.RANK+e}getElement(e,t){return this[t*this.RANK+e]}setElement(e,t,r){return this[t*this.RANK+e]=Pr(r),this}getColumn(e,t=new Array(this.RANK).fill(-0)){let r=e*this.RANK;for(let o=0;o<this.RANK;++o)t[o]=this[r+o];return t}setColumn(e,t){let r=e*this.RANK;for(let o=0;o<this.RANK;++o)this[r+o]=t[o];return this}};function vi(n){return n[0]=1,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=1,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=1,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n}function Er(n,e){if(n===e){let t=e[1],r=e[2],o=e[3],i=e[6],a=e[7],c=e[11];n[1]=e[4],n[2]=e[8],n[3]=e[12],n[4]=t,n[6]=e[9],n[7]=e[13],n[8]=r,n[9]=i,n[11]=e[14],n[12]=o,n[13]=a,n[14]=c}else n[0]=e[0],n[1]=e[4],n[2]=e[8],n[3]=e[12],n[4]=e[1],n[5]=e[5],n[6]=e[9],n[7]=e[13],n[8]=e[2],n[9]=e[6],n[10]=e[10],n[11]=e[14],n[12]=e[3],n[13]=e[7],n[14]=e[11],n[15]=e[15];return n}function Mr(n,e){let t=e[0],r=e[1],o=e[2],i=e[3],a=e[4],c=e[5],u=e[6],h=e[7],p=e[8],d=e[9],m=e[10],x=e[11],w=e[12],g=e[13],A=e[14],L=e[15],v=t*c-r*a,b=t*u-o*a,P=t*h-i*a,y=r*u-o*c,k=r*h-i*c,S=o*h-i*u,I=p*g-d*w,M=p*A-m*w,T=p*L-x*w,F=d*A-m*g,z=d*L-x*g,R=m*L-x*A,E=v*R-b*z+P*F+y*T-k*M+S*I;return E?(E=1/E,n[0]=(c*R-u*z+h*F)*E,n[1]=(o*z-r*R-i*F)*E,n[2]=(g*S-A*k+L*y)*E,n[3]=(m*k-d*S-x*y)*E,n[4]=(u*T-a*R-h*M)*E,n[5]=(t*R-o*T+i*M)*E,n[6]=(A*P-w*S-L*b)*E,n[7]=(p*S-m*P+x*b)*E,n[8]=(a*z-c*T+h*I)*E,n[9]=(r*T-t*z-i*I)*E,n[10]=(w*k-g*P+L*v)*E,n[11]=(d*P-p*k-x*v)*E,n[12]=(c*M-a*F-u*I)*E,n[13]=(t*F-r*M+o*I)*E,n[14]=(g*b-w*y-A*v)*E,n[15]=(p*y-d*b+m*v)*E,n):null}function Ir(n){let e=n[0],t=n[1],r=n[2],o=n[3],i=n[4],a=n[5],c=n[6],u=n[7],h=n[8],p=n[9],d=n[10],m=n[11],x=n[12],w=n[13],g=n[14],A=n[15],L=e*a-t*i,v=e*c-r*i,b=t*c-r*a,P=h*w-p*x,y=h*g-d*x,k=p*g-d*w,S=e*k-t*y+r*P,I=i*k-a*y+c*P,M=h*b-p*v+d*L,T=x*b-w*v+g*L;return u*S-o*I+A*M-m*T}function nn(n,e,t){let r=e[0],o=e[1],i=e[2],a=e[3],c=e[4],u=e[5],h=e[6],p=e[7],d=e[8],m=e[9],x=e[10],w=e[11],g=e[12],A=e[13],L=e[14],v=e[15],b=t[0],P=t[1],y=t[2],k=t[3];return n[0]=b*r+P*c+y*d+k*g,n[1]=b*o+P*u+y*m+k*A,n[2]=b*i+P*h+y*x+k*L,n[3]=b*a+P*p+y*w+k*v,b=t[4],P=t[5],y=t[6],k=t[7],n[4]=b*r+P*c+y*d+k*g,n[5]=b*o+P*u+y*m+k*A,n[6]=b*i+P*h+y*x+k*L,n[7]=b*a+P*p+y*w+k*v,b=t[8],P=t[9],y=t[10],k=t[11],n[8]=b*r+P*c+y*d+k*g,n[9]=b*o+P*u+y*m+k*A,n[10]=b*i+P*h+y*x+k*L,n[11]=b*a+P*p+y*w+k*v,b=t[12],P=t[13],y=t[14],k=t[15],n[12]=b*r+P*c+y*d+k*g,n[13]=b*o+P*u+y*m+k*A,n[14]=b*i+P*h+y*x+k*L,n[15]=b*a+P*p+y*w+k*v,n}function Fr(n,e,t){let r=t[0],o=t[1],i=t[2],a,c,u,h,p,d,m,x,w,g,A,L;return e===n?(n[12]=e[0]*r+e[4]*o+e[8]*i+e[12],n[13]=e[1]*r+e[5]*o+e[9]*i+e[13],n[14]=e[2]*r+e[6]*o+e[10]*i+e[14],n[15]=e[3]*r+e[7]*o+e[11]*i+e[15]):(a=e[0],c=e[1],u=e[2],h=e[3],p=e[4],d=e[5],m=e[6],x=e[7],w=e[8],g=e[9],A=e[10],L=e[11],n[0]=a,n[1]=c,n[2]=u,n[3]=h,n[4]=p,n[5]=d,n[6]=m,n[7]=x,n[8]=w,n[9]=g,n[10]=A,n[11]=L,n[12]=a*r+p*o+w*i+e[12],n[13]=c*r+d*o+g*i+e[13],n[14]=u*r+m*o+A*i+e[14],n[15]=h*r+x*o+L*i+e[15]),n}function Cr(n,e,t){let r=t[0],o=t[1],i=t[2];return n[0]=e[0]*r,n[1]=e[1]*r,n[2]=e[2]*r,n[3]=e[3]*r,n[4]=e[4]*o,n[5]=e[5]*o,n[6]=e[6]*o,n[7]=e[7]*o,n[8]=e[8]*i,n[9]=e[9]*i,n[10]=e[10]*i,n[11]=e[11]*i,n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15],n}function Rr(n,e,t,r){let o=r[0],i=r[1],a=r[2],c=Math.sqrt(o*o+i*i+a*a),u,h,p,d,m,x,w,g,A,L,v,b,P,y,k,S,I,M,T,F,z,R,E,_e;return c<1e-6?null:(c=1/c,o*=c,i*=c,a*=c,h=Math.sin(t),u=Math.cos(t),p=1-u,d=e[0],m=e[1],x=e[2],w=e[3],g=e[4],A=e[5],L=e[6],v=e[7],b=e[8],P=e[9],y=e[10],k=e[11],S=o*o*p+u,I=i*o*p+a*h,M=a*o*p-i*h,T=o*i*p-a*h,F=i*i*p+u,z=a*i*p+o*h,R=o*a*p+i*h,E=i*a*p-o*h,_e=a*a*p+u,n[0]=d*S+g*I+b*M,n[1]=m*S+A*I+P*M,n[2]=x*S+L*I+y*M,n[3]=w*S+v*I+k*M,n[4]=d*T+g*F+b*z,n[5]=m*T+A*F+P*z,n[6]=x*T+L*F+y*z,n[7]=w*T+v*F+k*z,n[8]=d*R+g*E+b*_e,n[9]=m*R+A*E+P*_e,n[10]=x*R+L*E+y*_e,n[11]=w*R+v*E+k*_e,e!==n&&(n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15]),n)}function Or(n,e,t){let r=Math.sin(t),o=Math.cos(t),i=e[4],a=e[5],c=e[6],u=e[7],h=e[8],p=e[9],d=e[10],m=e[11];return e!==n&&(n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15]),n[4]=i*o+h*r,n[5]=a*o+p*r,n[6]=c*o+d*r,n[7]=u*o+m*r,n[8]=h*o-i*r,n[9]=p*o-a*r,n[10]=d*o-c*r,n[11]=m*o-u*r,n}function Ur(n,e,t){let r=Math.sin(t),o=Math.cos(t),i=e[0],a=e[1],c=e[2],u=e[3],h=e[8],p=e[9],d=e[10],m=e[11];return e!==n&&(n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15]),n[0]=i*o-h*r,n[1]=a*o-p*r,n[2]=c*o-d*r,n[3]=u*o-m*r,n[8]=i*r+h*o,n[9]=a*r+p*o,n[10]=c*r+d*o,n[11]=u*r+m*o,n}function zr(n,e,t){let r=Math.sin(t),o=Math.cos(t),i=e[0],a=e[1],c=e[2],u=e[3],h=e[4],p=e[5],d=e[6],m=e[7];return e!==n&&(n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15]),n[0]=i*o+h*r,n[1]=a*o+p*r,n[2]=c*o+d*r,n[3]=u*o+m*r,n[4]=h*o-i*r,n[5]=p*o-a*r,n[6]=d*o-c*r,n[7]=m*o-u*r,n}function Dr(n,e){let t=e[0],r=e[1],o=e[2],i=e[3],a=t+t,c=r+r,u=o+o,h=t*a,p=r*a,d=r*c,m=o*a,x=o*c,w=o*u,g=i*a,A=i*c,L=i*u;return n[0]=1-d-w,n[1]=p+L,n[2]=m-A,n[3]=0,n[4]=p-L,n[5]=1-h-w,n[6]=x+g,n[7]=0,n[8]=m+A,n[9]=x-g,n[10]=1-h-d,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n}function Yr(n,e,t,r,o,i,a){let c=1/(t-e),u=1/(o-r),h=1/(i-a);return n[0]=i*2*c,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=i*2*u,n[6]=0,n[7]=0,n[8]=(t+e)*c,n[9]=(o+r)*u,n[10]=(a+i)*h,n[11]=-1,n[12]=0,n[13]=0,n[14]=a*i*2*h,n[15]=0,n}function Ai(n,e,t,r,o){let i=1/Math.tan(e/2);if(n[0]=i/t,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=i,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[11]=-1,n[12]=0,n[13]=0,n[15]=0,o!=null&&o!==1/0){let a=1/(r-o);n[10]=(o+r)*a,n[14]=2*o*r*a}else n[10]=-1,n[14]=-2*r;return n}var Xr=Ai;function yi(n,e,t,r,o,i,a){let c=1/(e-t),u=1/(r-o),h=1/(i-a);return n[0]=-2*c,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=-2*u,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=2*h,n[11]=0,n[12]=(e+t)*c,n[13]=(o+r)*u,n[14]=(a+i)*h,n[15]=1,n}var Br=yi;function Qr(n,e,t,r){let o,i,a,c,u,h,p,d,m,x,w=e[0],g=e[1],A=e[2],L=r[0],v=r[1],b=r[2],P=t[0],y=t[1],k=t[2];return Math.abs(w-P)<1e-6&&Math.abs(g-y)<1e-6&&Math.abs(A-k)<1e-6?vi(n):(d=w-P,m=g-y,x=A-k,o=1/Math.sqrt(d*d+m*m+x*x),d*=o,m*=o,x*=o,i=v*x-b*m,a=b*d-L*x,c=L*m-v*d,o=Math.sqrt(i*i+a*a+c*c),o?(o=1/o,i*=o,a*=o,c*=o):(i=0,a=0,c=0),u=m*c-x*a,h=x*i-d*c,p=d*a-m*i,o=Math.sqrt(u*u+h*h+p*p),o?(o=1/o,u*=o,h*=o,p*=o):(u=0,h=0,p=0),n[0]=i,n[1]=u,n[2]=d,n[3]=0,n[4]=a,n[5]=h,n[6]=m,n[7]=0,n[8]=c,n[9]=p,n[10]=x,n[11]=0,n[12]=-(i*w+a*g+c*A),n[13]=-(u*w+h*g+p*A),n[14]=-(d*w+m*g+x*A),n[15]=1,n)}function bi(){let n=new W(4);return W!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0,n[3]=0),n}function qr(n,e,t){let r=e[0],o=e[1],i=e[2],a=e[3];return n[0]=t[0]*r+t[4]*o+t[8]*i+t[12]*a,n[1]=t[1]*r+t[5]*o+t[9]*i+t[13]*a,n[2]=t[2]*r+t[6]*o+t[10]*i+t[14]*a,n[3]=t[3]*r+t[7]*o+t[11]*i+t[15]*a,n}var Ja=function(){let n=bi();return function(e,t,r,o,i,a){let c,u;for(t||(t=4),r||(r=0),o?u=Math.min(o*t+r,e.length):u=e.length,c=r;c<u;c+=t)n[0]=e[c],n[1]=e[c+1],n[2]=e[c+2],n[3]=e[c+3],i(n,n,a),e[c]=n[0],e[c+1]=n[1],e[c+2]=n[2],e[c+3]=n[3];return e}}();var sn;(function(n){n[n.COL0ROW0=0]="COL0ROW0",n[n.COL0ROW1=1]="COL0ROW1",n[n.COL0ROW2=2]="COL0ROW2",n[n.COL0ROW3=3]="COL0ROW3",n[n.COL1ROW0=4]="COL1ROW0",n[n.COL1ROW1=5]="COL1ROW1",n[n.COL1ROW2=6]="COL1ROW2",n[n.COL1ROW3=7]="COL1ROW3",n[n.COL2ROW0=8]="COL2ROW0",n[n.COL2ROW1=9]="COL2ROW1",n[n.COL2ROW2=10]="COL2ROW2",n[n.COL2ROW3=11]="COL2ROW3",n[n.COL3ROW0=12]="COL3ROW0",n[n.COL3ROW1=13]="COL3ROW1",n[n.COL3ROW2=14]="COL3ROW2",n[n.COL3ROW3=15]="COL3ROW3"})(sn||(sn={}));var Pi=45*Math.PI/180,wi=1,rn=.1,on=500,Li=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),ee=class extends $e{static get IDENTITY(){return Si()}static get ZERO(){return ki()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return sn}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,t,r,o,i,a,c,u,h,p,d,m,x,w,g,A){return this[0]=e,this[1]=t,this[2]=r,this[3]=o,this[4]=i,this[5]=a,this[6]=c,this[7]=u,this[8]=h,this[9]=p,this[10]=d,this[11]=m,this[12]=x,this[13]=w,this[14]=g,this[15]=A,this.check()}setRowMajor(e,t,r,o,i,a,c,u,h,p,d,m,x,w,g,A){return this[0]=e,this[1]=i,this[2]=h,this[3]=x,this[4]=t,this[5]=a,this[6]=p,this[7]=w,this[8]=r,this[9]=c,this[10]=d,this[11]=g,this[12]=o,this[13]=u,this[14]=m,this[15]=A,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(Li)}fromObject(e){return this.check()}fromQuaternion(e){return Dr(this,e),this.check()}frustum(e){let{left:t,right:r,bottom:o,top:i,near:a=rn,far:c=on}=e;return c===1/0?Ni(this,t,r,o,i,a):Yr(this,t,r,o,i,a,c),this.check()}lookAt(e){let{eye:t,center:r=[0,0,0],up:o=[0,1,0]}=e;return Qr(this,t,r,o),this.check()}ortho(e){let{left:t,right:r,bottom:o,top:i,near:a=rn,far:c=on}=e;return Br(this,t,r,o,i,a,c),this.check()}orthographic(e){let{fovy:t=Pi,aspect:r=wi,focalDistance:o=1,near:i=rn,far:a=on}=e;Vr(t);let c=t/2,u=o*Math.tan(c),h=u*r;return this.ortho({left:-h,right:h,bottom:-u,top:u,near:i,far:a})}perspective(e){let{fovy:t=45*Math.PI/180,aspect:r=1,near:o=.1,far:i=500}=e;return Vr(t),Xr(this,t,r,o,i),this.check()}determinant(){return Ir(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let r=this.getScale(t),o=1/r[0],i=1/r[1],a=1/r[2];return e[0]=this[0]*o,e[1]=this[1]*i,e[2]=this[2]*a,e[3]=0,e[4]=this[4]*o,e[5]=this[5]*i,e[6]=this[6]*a,e[7]=0,e[8]=this[8]*o,e[9]=this[9]*i,e[10]=this[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let r=this.getScale(t),o=1/r[0],i=1/r[1],a=1/r[2];return e[0]=this[0]*o,e[1]=this[1]*i,e[2]=this[2]*a,e[3]=this[4]*o,e[4]=this[5]*i,e[5]=this[6]*a,e[6]=this[8]*o,e[7]=this[9]*i,e[8]=this[10]*a,e}transpose(){return Er(this,this),this.check()}invert(){return Mr(this,this),this.check()}multiplyLeft(e){return nn(this,e,this),this.check()}multiplyRight(e){return nn(this,this,e),this.check()}rotateX(e){return Or(this,this,e),this.check()}rotateY(e){return Ur(this,this,e),this.check()}rotateZ(e){return zr(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,t){return Rr(this,this,e,t),this.check()}scale(e){return Cr(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return Fr(this,this,e),this.check()}transform(e,t){return e.length===4?(t=qr(t||[-0,-0,-0,-0],e,this),je(t,4),t):this.transformAsPoint(e,t)}transformAsPoint(e,t){let{length:r}=e,o;switch(r){case 2:o=kr(t||[-0,-0],e,this);break;case 3:o=Tr(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return je(o,e.length),o}transformAsVector(e,t){let r;switch(e.length){case 2:r=Sr(t||[-0,-0],e,this);break;case 3:r=Nr(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return je(r,e.length),r}transformPoint(e,t){return this.transformAsPoint(e,t)}transformVector(e,t){return this.transformAsPoint(e,t)}transformDirection(e,t){return this.transformAsVector(e,t)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,t,r){return this.identity().translate([e,t,r])}},Ke,Ze;function ki(){return Ke||(Ke=new ee([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Ke)),Ke}function Si(){return Ze||(Ze=new ee,Object.freeze(Ze)),Ze}function Vr(n){if(n>Math.PI*2)throw Error("expected radians")}function Ni(n,e,t,r,o,i){let a=2*i/(t-e),c=2*i/(o-r),u=(t+e)/(t-e),h=(o+r)/(o-r),p=-1,d=-1,m=-2*i;return n[0]=a,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=c,n[6]=0,n[7]=0,n[8]=u,n[9]=h,n[10]=p,n[11]=d,n[12]=0,n[13]=0,n[14]=m,n[15]=0,n}var an=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Ti={modelMatrix:an,viewMatrix:an,projectionMatrix:an,cameraPositionWorld:[0,0,0]};function Ei(n=Ti,e={}){let t={};return n.modelMatrix!==void 0&&(t.modelMatrix=n.modelMatrix),n.viewMatrix!==void 0&&(t.viewMatrix=n.viewMatrix),n.projectionMatrix!==void 0&&(t.projectionMatrix=n.projectionMatrix),n.cameraPositionWorld!==void 0&&(t.cameraPositionWorld=n.cameraPositionWorld),(n.projectionMatrix!==void 0||n.viewMatrix!==void 0)&&(t.viewProjectionMatrix=new ee(n.projectionMatrix).multiplyRight(n.viewMatrix)),t}var Gr=`varying vec4 project_vPositionWorld;
|
|
2411
|
+
`,yr={name:"geometry",vs:ui,fs:_i};var Fa=1/Math.PI*180,Ca=1/180*Math.PI,hi={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...hi}};var O=globalThis.mathgl.config;function br(n,{precision:e=O.precision}={}){return n=pi(n),`${parseFloat(n.toPrecision(e))}`}function $e(n){return Array.isArray(n)||ArrayBuffer.isView(n)&&!(n instanceof DataView)}function rn(n,e,t){let r=O.EPSILON;t&&(O.EPSILON=t);try{if(n===e)return!0;if($e(n)&&$e(e)){if(n.length!==e.length)return!1;for(let o=0;o<n.length;++o)if(!rn(n[o],e[o]))return!1;return!0}return n&&n.equals?n.equals(e):e&&e.equals?e.equals(n):typeof n=="number"&&typeof e=="number"?Math.abs(n-e)<=O.EPSILON*Math.max(1,Math.abs(n),Math.abs(e)):!1}finally{O.EPSILON=r}}function pi(n){return Math.round(n/O.EPSILON)*O.EPSILON}var Ke=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,t=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=e[r+t];return this.check()}toArray(e=[],t=0){for(let r=0;r<this.ELEMENTS;++r)e[t+r]=this[r];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:$e(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(O)}formatString(e){let t="";for(let r=0;r<this.ELEMENTS;++r)t+=(r>0?", ":"")+br(this[r],e);return`${e.printTypes?this.constructor.name:""}[${t}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(!rn(this[t],e[t]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(this[t]!==e[t])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,t,r){if(r===void 0)return this.lerp(this,e,t);for(let o=0;o<this.ELEMENTS;++o){let i=e[o],a=typeof t=="number"?t:t[o];this[o]=i+r*(a-i)}return this.check()}min(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.min(e[t],this[t]);return this.check()}max(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.max(e[t],this[t]);return this.check()}clamp(e,t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e[r]),t[r]);return this.check()}add(...e){for(let t of e)for(let r=0;r<this.ELEMENTS;++r)this[r]+=t[r];return this.check()}subtract(...e){for(let t of e)for(let r=0;r<this.ELEMENTS;++r)this[r]-=t[r];return this.check()}scale(e){if(typeof e=="number")for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;else for(let t=0;t<this.ELEMENTS&&t<e.length;++t)this[t]*=e[t];return this.check()}multiplyByScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}check(){if(O.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let t=0;t<this.ELEMENTS;++t)e=e&&Number.isFinite(this[t]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=e;return this.check()}addScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e),t);return this.check()}get elements(){return this}};function di(n,e){if(n.length!==e)return!1;for(let t=0;t<n.length;++t)if(!Number.isFinite(n[t]))return!1;return!0}function Pr(n){if(!Number.isFinite(n))throw new Error(`Invalid number ${JSON.stringify(n)}`);return n}function Ze(n,e,t=""){if(O.debug&&!di(n,e))throw new Error(`math.gl: ${t} some fields set to invalid numbers'`);return n}var W=typeof Float32Array<"u"?Float32Array:Array;var Ya=Math.PI/180;function mi(){let n=new W(2);return W!=Float32Array&&(n[0]=0,n[1]=0),n}function kr(n,e,t){let r=e[0],o=e[1];return n[0]=t[0]*r+t[4]*o+t[12],n[1]=t[1]*r+t[5]*o+t[13],n}var Xa=function(){let n=mi();return function(e,t,r,o,i,a){let c,u;for(t||(t=2),r||(r=0),o?u=Math.min(o*t+r,e.length):u=e.length,c=r;c<u;c+=t)n[0]=e[c],n[1]=e[c+1],i(n,n,a),e[c]=n[0],e[c+1]=n[1];return e}}();function Sr(n,e,t){let r=e[0],o=e[1],i=t[3]*r+t[7]*o||1;return n[0]=(t[0]*r+t[4]*o)/i,n[1]=(t[1]*r+t[5]*o)/i,n}function Nr(n,e,t){let r=e[0],o=e[1],i=e[2],a=t[3]*r+t[7]*o+t[11]*i||1;return n[0]=(t[0]*r+t[4]*o+t[8]*i)/a,n[1]=(t[1]*r+t[5]*o+t[9]*i)/a,n[2]=(t[2]*r+t[6]*o+t[10]*i)/a,n}function gi(){let n=new W(3);return W!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0),n}function Tr(n,e,t){let r=e[0],o=e[1],i=e[2],a=t[3]*r+t[7]*o+t[11]*i+t[15];return a=a||1,n[0]=(t[0]*r+t[4]*o+t[8]*i+t[12])/a,n[1]=(t[1]*r+t[5]*o+t[9]*i+t[13])/a,n[2]=(t[2]*r+t[6]*o+t[10]*i+t[14])/a,n}var qa=function(){let n=gi();return function(e,t,r,o,i,a){let c,u;for(t||(t=3),r||(r=0),o?u=Math.min(o*t+r,e.length):u=e.length,c=r;c<u;c+=t)n[0]=e[c],n[1]=e[c+1],n[2]=e[c+2],i(n,n,a),e[c]=n[0],e[c+1]=n[1],e[c+2]=n[2];return e}}();var Je=class extends Ke{toString(){let e="[";if(O.printRowMajor){e+="row-major:";for(let t=0;t<this.RANK;++t)for(let r=0;r<this.RANK;++r)e+=` ${this[r*this.RANK+t]}`}else{e+="column-major:";for(let t=0;t<this.ELEMENTS;++t)e+=` ${this[t]}`}return e+="]",e}getElementIndex(e,t){return t*this.RANK+e}getElement(e,t){return this[t*this.RANK+e]}setElement(e,t,r){return this[t*this.RANK+e]=Pr(r),this}getColumn(e,t=new Array(this.RANK).fill(-0)){let r=e*this.RANK;for(let o=0;o<this.RANK;++o)t[o]=this[r+o];return t}setColumn(e,t){let r=e*this.RANK;for(let o=0;o<this.RANK;++o)this[r+o]=t[o];return this}};function xi(n){return n[0]=1,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=1,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=1,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n}function Er(n,e){if(n===e){let t=e[1],r=e[2],o=e[3],i=e[6],a=e[7],c=e[11];n[1]=e[4],n[2]=e[8],n[3]=e[12],n[4]=t,n[6]=e[9],n[7]=e[13],n[8]=r,n[9]=i,n[11]=e[14],n[12]=o,n[13]=a,n[14]=c}else n[0]=e[0],n[1]=e[4],n[2]=e[8],n[3]=e[12],n[4]=e[1],n[5]=e[5],n[6]=e[9],n[7]=e[13],n[8]=e[2],n[9]=e[6],n[10]=e[10],n[11]=e[14],n[12]=e[3],n[13]=e[7],n[14]=e[11],n[15]=e[15];return n}function Mr(n,e){let t=e[0],r=e[1],o=e[2],i=e[3],a=e[4],c=e[5],u=e[6],h=e[7],p=e[8],d=e[9],m=e[10],x=e[11],w=e[12],g=e[13],A=e[14],L=e[15],v=t*c-r*a,b=t*u-o*a,P=t*h-i*a,y=r*u-o*c,k=r*h-i*c,S=o*h-i*u,I=p*g-d*w,M=p*A-m*w,T=p*L-x*w,F=d*A-m*g,z=d*L-x*g,R=m*L-x*A,E=v*R-b*z+P*F+y*T-k*M+S*I;return E?(E=1/E,n[0]=(c*R-u*z+h*F)*E,n[1]=(o*z-r*R-i*F)*E,n[2]=(g*S-A*k+L*y)*E,n[3]=(m*k-d*S-x*y)*E,n[4]=(u*T-a*R-h*M)*E,n[5]=(t*R-o*T+i*M)*E,n[6]=(A*P-w*S-L*b)*E,n[7]=(p*S-m*P+x*b)*E,n[8]=(a*z-c*T+h*I)*E,n[9]=(r*T-t*z-i*I)*E,n[10]=(w*k-g*P+L*v)*E,n[11]=(d*P-p*k-x*v)*E,n[12]=(c*M-a*F-u*I)*E,n[13]=(t*F-r*M+o*I)*E,n[14]=(g*b-w*y-A*v)*E,n[15]=(p*y-d*b+m*v)*E,n):null}function Ir(n){let e=n[0],t=n[1],r=n[2],o=n[3],i=n[4],a=n[5],c=n[6],u=n[7],h=n[8],p=n[9],d=n[10],m=n[11],x=n[12],w=n[13],g=n[14],A=n[15],L=e*a-t*i,v=e*c-r*i,b=t*c-r*a,P=h*w-p*x,y=h*g-d*x,k=p*g-d*w,S=e*k-t*y+r*P,I=i*k-a*y+c*P,M=h*b-p*v+d*L,T=x*b-w*v+g*L;return u*S-o*I+A*M-m*T}function sn(n,e,t){let r=e[0],o=e[1],i=e[2],a=e[3],c=e[4],u=e[5],h=e[6],p=e[7],d=e[8],m=e[9],x=e[10],w=e[11],g=e[12],A=e[13],L=e[14],v=e[15],b=t[0],P=t[1],y=t[2],k=t[3];return n[0]=b*r+P*c+y*d+k*g,n[1]=b*o+P*u+y*m+k*A,n[2]=b*i+P*h+y*x+k*L,n[3]=b*a+P*p+y*w+k*v,b=t[4],P=t[5],y=t[6],k=t[7],n[4]=b*r+P*c+y*d+k*g,n[5]=b*o+P*u+y*m+k*A,n[6]=b*i+P*h+y*x+k*L,n[7]=b*a+P*p+y*w+k*v,b=t[8],P=t[9],y=t[10],k=t[11],n[8]=b*r+P*c+y*d+k*g,n[9]=b*o+P*u+y*m+k*A,n[10]=b*i+P*h+y*x+k*L,n[11]=b*a+P*p+y*w+k*v,b=t[12],P=t[13],y=t[14],k=t[15],n[12]=b*r+P*c+y*d+k*g,n[13]=b*o+P*u+y*m+k*A,n[14]=b*i+P*h+y*x+k*L,n[15]=b*a+P*p+y*w+k*v,n}function Fr(n,e,t){let r=t[0],o=t[1],i=t[2],a,c,u,h,p,d,m,x,w,g,A,L;return e===n?(n[12]=e[0]*r+e[4]*o+e[8]*i+e[12],n[13]=e[1]*r+e[5]*o+e[9]*i+e[13],n[14]=e[2]*r+e[6]*o+e[10]*i+e[14],n[15]=e[3]*r+e[7]*o+e[11]*i+e[15]):(a=e[0],c=e[1],u=e[2],h=e[3],p=e[4],d=e[5],m=e[6],x=e[7],w=e[8],g=e[9],A=e[10],L=e[11],n[0]=a,n[1]=c,n[2]=u,n[3]=h,n[4]=p,n[5]=d,n[6]=m,n[7]=x,n[8]=w,n[9]=g,n[10]=A,n[11]=L,n[12]=a*r+p*o+w*i+e[12],n[13]=c*r+d*o+g*i+e[13],n[14]=u*r+m*o+A*i+e[14],n[15]=h*r+x*o+L*i+e[15]),n}function Cr(n,e,t){let r=t[0],o=t[1],i=t[2];return n[0]=e[0]*r,n[1]=e[1]*r,n[2]=e[2]*r,n[3]=e[3]*r,n[4]=e[4]*o,n[5]=e[5]*o,n[6]=e[6]*o,n[7]=e[7]*o,n[8]=e[8]*i,n[9]=e[9]*i,n[10]=e[10]*i,n[11]=e[11]*i,n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15],n}function Rr(n,e,t,r){let o=r[0],i=r[1],a=r[2],c=Math.sqrt(o*o+i*i+a*a),u,h,p,d,m,x,w,g,A,L,v,b,P,y,k,S,I,M,T,F,z,R,E,_e;return c<1e-6?null:(c=1/c,o*=c,i*=c,a*=c,h=Math.sin(t),u=Math.cos(t),p=1-u,d=e[0],m=e[1],x=e[2],w=e[3],g=e[4],A=e[5],L=e[6],v=e[7],b=e[8],P=e[9],y=e[10],k=e[11],S=o*o*p+u,I=i*o*p+a*h,M=a*o*p-i*h,T=o*i*p-a*h,F=i*i*p+u,z=a*i*p+o*h,R=o*a*p+i*h,E=i*a*p-o*h,_e=a*a*p+u,n[0]=d*S+g*I+b*M,n[1]=m*S+A*I+P*M,n[2]=x*S+L*I+y*M,n[3]=w*S+v*I+k*M,n[4]=d*T+g*F+b*z,n[5]=m*T+A*F+P*z,n[6]=x*T+L*F+y*z,n[7]=w*T+v*F+k*z,n[8]=d*R+g*E+b*_e,n[9]=m*R+A*E+P*_e,n[10]=x*R+L*E+y*_e,n[11]=w*R+v*E+k*_e,e!==n&&(n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15]),n)}function Or(n,e,t){let r=Math.sin(t),o=Math.cos(t),i=e[4],a=e[5],c=e[6],u=e[7],h=e[8],p=e[9],d=e[10],m=e[11];return e!==n&&(n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15]),n[4]=i*o+h*r,n[5]=a*o+p*r,n[6]=c*o+d*r,n[7]=u*o+m*r,n[8]=h*o-i*r,n[9]=p*o-a*r,n[10]=d*o-c*r,n[11]=m*o-u*r,n}function Ur(n,e,t){let r=Math.sin(t),o=Math.cos(t),i=e[0],a=e[1],c=e[2],u=e[3],h=e[8],p=e[9],d=e[10],m=e[11];return e!==n&&(n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15]),n[0]=i*o-h*r,n[1]=a*o-p*r,n[2]=c*o-d*r,n[3]=u*o-m*r,n[8]=i*r+h*o,n[9]=a*r+p*o,n[10]=c*r+d*o,n[11]=u*r+m*o,n}function zr(n,e,t){let r=Math.sin(t),o=Math.cos(t),i=e[0],a=e[1],c=e[2],u=e[3],h=e[4],p=e[5],d=e[6],m=e[7];return e!==n&&(n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15]),n[0]=i*o+h*r,n[1]=a*o+p*r,n[2]=c*o+d*r,n[3]=u*o+m*r,n[4]=h*o-i*r,n[5]=p*o-a*r,n[6]=d*o-c*r,n[7]=m*o-u*r,n}function Dr(n,e){let t=e[0],r=e[1],o=e[2],i=e[3],a=t+t,c=r+r,u=o+o,h=t*a,p=r*a,d=r*c,m=o*a,x=o*c,w=o*u,g=i*a,A=i*c,L=i*u;return n[0]=1-d-w,n[1]=p+L,n[2]=m-A,n[3]=0,n[4]=p-L,n[5]=1-h-w,n[6]=x+g,n[7]=0,n[8]=m+A,n[9]=x-g,n[10]=1-h-d,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n}function Yr(n,e,t,r,o,i,a){let c=1/(t-e),u=1/(o-r),h=1/(i-a);return n[0]=i*2*c,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=i*2*u,n[6]=0,n[7]=0,n[8]=(t+e)*c,n[9]=(o+r)*u,n[10]=(a+i)*h,n[11]=-1,n[12]=0,n[13]=0,n[14]=a*i*2*h,n[15]=0,n}function vi(n,e,t,r,o){let i=1/Math.tan(e/2);if(n[0]=i/t,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=i,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[11]=-1,n[12]=0,n[13]=0,n[15]=0,o!=null&&o!==1/0){let a=1/(r-o);n[10]=(o+r)*a,n[14]=2*o*r*a}else n[10]=-1,n[14]=-2*r;return n}var Xr=vi;function Ai(n,e,t,r,o,i,a){let c=1/(e-t),u=1/(r-o),h=1/(i-a);return n[0]=-2*c,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=-2*u,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=2*h,n[11]=0,n[12]=(e+t)*c,n[13]=(o+r)*u,n[14]=(a+i)*h,n[15]=1,n}var Br=Ai;function Qr(n,e,t,r){let o,i,a,c,u,h,p,d,m,x,w=e[0],g=e[1],A=e[2],L=r[0],v=r[1],b=r[2],P=t[0],y=t[1],k=t[2];return Math.abs(w-P)<1e-6&&Math.abs(g-y)<1e-6&&Math.abs(A-k)<1e-6?xi(n):(d=w-P,m=g-y,x=A-k,o=1/Math.sqrt(d*d+m*m+x*x),d*=o,m*=o,x*=o,i=v*x-b*m,a=b*d-L*x,c=L*m-v*d,o=Math.sqrt(i*i+a*a+c*c),o?(o=1/o,i*=o,a*=o,c*=o):(i=0,a=0,c=0),u=m*c-x*a,h=x*i-d*c,p=d*a-m*i,o=Math.sqrt(u*u+h*h+p*p),o?(o=1/o,u*=o,h*=o,p*=o):(u=0,h=0,p=0),n[0]=i,n[1]=u,n[2]=d,n[3]=0,n[4]=a,n[5]=h,n[6]=m,n[7]=0,n[8]=c,n[9]=p,n[10]=x,n[11]=0,n[12]=-(i*w+a*g+c*A),n[13]=-(u*w+h*g+p*A),n[14]=-(d*w+m*g+x*A),n[15]=1,n)}function yi(){let n=new W(4);return W!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0,n[3]=0),n}function qr(n,e,t){let r=e[0],o=e[1],i=e[2],a=e[3];return n[0]=t[0]*r+t[4]*o+t[8]*i+t[12]*a,n[1]=t[1]*r+t[5]*o+t[9]*i+t[13]*a,n[2]=t[2]*r+t[6]*o+t[10]*i+t[14]*a,n[3]=t[3]*r+t[7]*o+t[11]*i+t[15]*a,n}var Ka=function(){let n=yi();return function(e,t,r,o,i,a){let c,u;for(t||(t=4),r||(r=0),o?u=Math.min(o*t+r,e.length):u=e.length,c=r;c<u;c+=t)n[0]=e[c],n[1]=e[c+1],n[2]=e[c+2],n[3]=e[c+3],i(n,n,a),e[c]=n[0],e[c+1]=n[1],e[c+2]=n[2],e[c+3]=n[3];return e}}();var ln;(function(n){n[n.COL0ROW0=0]="COL0ROW0",n[n.COL0ROW1=1]="COL0ROW1",n[n.COL0ROW2=2]="COL0ROW2",n[n.COL0ROW3=3]="COL0ROW3",n[n.COL1ROW0=4]="COL1ROW0",n[n.COL1ROW1=5]="COL1ROW1",n[n.COL1ROW2=6]="COL1ROW2",n[n.COL1ROW3=7]="COL1ROW3",n[n.COL2ROW0=8]="COL2ROW0",n[n.COL2ROW1=9]="COL2ROW1",n[n.COL2ROW2=10]="COL2ROW2",n[n.COL2ROW3=11]="COL2ROW3",n[n.COL3ROW0=12]="COL3ROW0",n[n.COL3ROW1=13]="COL3ROW1",n[n.COL3ROW2=14]="COL3ROW2",n[n.COL3ROW3=15]="COL3ROW3"})(ln||(ln={}));var bi=45*Math.PI/180,Pi=1,an=.1,cn=500,wi=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),ee=class extends Je{static get IDENTITY(){return ki()}static get ZERO(){return Li()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return ln}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,t,r,o,i,a,c,u,h,p,d,m,x,w,g,A){return this[0]=e,this[1]=t,this[2]=r,this[3]=o,this[4]=i,this[5]=a,this[6]=c,this[7]=u,this[8]=h,this[9]=p,this[10]=d,this[11]=m,this[12]=x,this[13]=w,this[14]=g,this[15]=A,this.check()}setRowMajor(e,t,r,o,i,a,c,u,h,p,d,m,x,w,g,A){return this[0]=e,this[1]=i,this[2]=h,this[3]=x,this[4]=t,this[5]=a,this[6]=p,this[7]=w,this[8]=r,this[9]=c,this[10]=d,this[11]=g,this[12]=o,this[13]=u,this[14]=m,this[15]=A,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(wi)}fromObject(e){return this.check()}fromQuaternion(e){return Dr(this,e),this.check()}frustum(e){let{left:t,right:r,bottom:o,top:i,near:a=an,far:c=cn}=e;return c===1/0?Si(this,t,r,o,i,a):Yr(this,t,r,o,i,a,c),this.check()}lookAt(e){let{eye:t,center:r=[0,0,0],up:o=[0,1,0]}=e;return Qr(this,t,r,o),this.check()}ortho(e){let{left:t,right:r,bottom:o,top:i,near:a=an,far:c=cn}=e;return Br(this,t,r,o,i,a,c),this.check()}orthographic(e){let{fovy:t=bi,aspect:r=Pi,focalDistance:o=1,near:i=an,far:a=cn}=e;Vr(t);let c=t/2,u=o*Math.tan(c),h=u*r;return this.ortho({left:-h,right:h,bottom:-u,top:u,near:i,far:a})}perspective(e){let{fovy:t=45*Math.PI/180,aspect:r=1,near:o=.1,far:i=500}=e;return Vr(t),Xr(this,t,r,o,i),this.check()}determinant(){return Ir(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let r=this.getScale(t),o=1/r[0],i=1/r[1],a=1/r[2];return e[0]=this[0]*o,e[1]=this[1]*i,e[2]=this[2]*a,e[3]=0,e[4]=this[4]*o,e[5]=this[5]*i,e[6]=this[6]*a,e[7]=0,e[8]=this[8]*o,e[9]=this[9]*i,e[10]=this[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let r=this.getScale(t),o=1/r[0],i=1/r[1],a=1/r[2];return e[0]=this[0]*o,e[1]=this[1]*i,e[2]=this[2]*a,e[3]=this[4]*o,e[4]=this[5]*i,e[5]=this[6]*a,e[6]=this[8]*o,e[7]=this[9]*i,e[8]=this[10]*a,e}transpose(){return Er(this,this),this.check()}invert(){return Mr(this,this),this.check()}multiplyLeft(e){return sn(this,e,this),this.check()}multiplyRight(e){return sn(this,this,e),this.check()}rotateX(e){return Or(this,this,e),this.check()}rotateY(e){return Ur(this,this,e),this.check()}rotateZ(e){return zr(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,t){return Rr(this,this,e,t),this.check()}scale(e){return Cr(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return Fr(this,this,e),this.check()}transform(e,t){return e.length===4?(t=qr(t||[-0,-0,-0,-0],e,this),Ze(t,4),t):this.transformAsPoint(e,t)}transformAsPoint(e,t){let{length:r}=e,o;switch(r){case 2:o=kr(t||[-0,-0],e,this);break;case 3:o=Tr(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Ze(o,e.length),o}transformAsVector(e,t){let r;switch(e.length){case 2:r=Sr(t||[-0,-0],e,this);break;case 3:r=Nr(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Ze(r,e.length),r}transformPoint(e,t){return this.transformAsPoint(e,t)}transformVector(e,t){return this.transformAsPoint(e,t)}transformDirection(e,t){return this.transformAsVector(e,t)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,t,r){return this.identity().translate([e,t,r])}},et,tt;function Li(){return et||(et=new ee([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(et)),et}function ki(){return tt||(tt=new ee,Object.freeze(tt)),tt}function Vr(n){if(n>Math.PI*2)throw Error("expected radians")}function Si(n,e,t,r,o,i){let a=2*i/(t-e),c=2*i/(o-r),u=(t+e)/(t-e),h=(o+r)/(o-r),p=-1,d=-1,m=-2*i;return n[0]=a,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=c,n[6]=0,n[7]=0,n[8]=u,n[9]=h,n[10]=p,n[11]=d,n[12]=0,n[13]=0,n[14]=m,n[15]=0,n}var fn=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Ni={modelMatrix:fn,viewMatrix:fn,projectionMatrix:fn,cameraPositionWorld:[0,0,0]};function Ti(n=Ni,e={}){let t={};return n.modelMatrix!==void 0&&(t.modelMatrix=n.modelMatrix),n.viewMatrix!==void 0&&(t.viewMatrix=n.viewMatrix),n.projectionMatrix!==void 0&&(t.projectionMatrix=n.projectionMatrix),n.cameraPositionWorld!==void 0&&(t.cameraPositionWorld=n.cameraPositionWorld),(n.projectionMatrix!==void 0||n.viewMatrix!==void 0)&&(t.viewProjectionMatrix=new ee(n.projectionMatrix).multiplyRight(n.viewMatrix)),t}var Hr=`varying vec4 project_vPositionWorld;
|
|
2468
2412
|
varying vec3 project_vNormalWorld;
|
|
2469
2413
|
vec4 project_getPosition_World() {
|
|
2470
2414
|
return project_vPositionWorld;
|
|
@@ -2472,7 +2416,7 @@ return project_vPositionWorld;
|
|
|
2472
2416
|
vec3 project_getNormal_World() {
|
|
2473
2417
|
return project_vNormalWorld;
|
|
2474
2418
|
}
|
|
2475
|
-
`,
|
|
2419
|
+
`,Ei=`${Hr}
|
|
2476
2420
|
|
|
2477
2421
|
// Unprefixed uniforms
|
|
2478
2422
|
uniform mat4 modelMatrix;
|
|
@@ -2525,8 +2469,8 @@ vec4 project_view_to_clipspace(vec3 position) {
|
|
|
2525
2469
|
vec4 project_to_clipspace(vec3 position) {
|
|
2526
2470
|
return viewProjectionMatrix * vec4(position, 1.);
|
|
2527
2471
|
}
|
|
2528
|
-
`,
|
|
2529
|
-
${
|
|
2472
|
+
`,Mi=`
|
|
2473
|
+
${Hr}`,nt={name:"project",getUniforms:Ti,vs:Ei,fs:Mi};var un=`#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
2530
2474
|
struct AmbientLight {
|
|
2531
2475
|
vec3 color;
|
|
2532
2476
|
};
|
|
@@ -2551,13 +2495,13 @@ return pointLight.attenuation.x
|
|
|
2551
2495
|
+ pointLight.attenuation.z * distance * distance;
|
|
2552
2496
|
}
|
|
2553
2497
|
#endif
|
|
2554
|
-
`;var
|
|
2498
|
+
`;var Ii={lightSources:{}};function _n(n={}){let{color:e=[0,0,0],intensity:t=1}=n;return e.map(r=>r*t/255)}function Fi({ambientLight:n,pointLights:e=[],directionalLights:t=[]}){let r={};return n?r["lighting_uAmbientLight.color"]=_n(n):r["lighting_uAmbientLight.color"]=[0,0,0],e.forEach((o,i)=>{r[`lighting_uPointLight[${i}].color`]=_n(o),r[`lighting_uPointLight[${i}].position`]=o.position,r[`lighting_uPointLight[${i}].attenuation`]=o.attenuation||[1,0,0]}),r.lighting_uPointLightCount=e.length,t.forEach((o,i)=>{r[`lighting_uDirectionalLight[${i}].color`]=_n(o),r[`lighting_uDirectionalLight[${i}].direction`]=o.direction}),r.lighting_uDirectionalLightCount=t.length,r}function Gr(n=Ii){if("lightSources"in n){let{ambientLight:e,pointLights:t,directionalLights:r}=n.lightSources||{};return e||t&&t.length>0||r&&r.length>0?Object.assign({},Fi({ambientLight:e,pointLights:t,directionalLights:r}),{lighting_uEnabled:!0}):{lighting_uEnabled:!1}}if("lights"in n){let e={pointLights:[],directionalLights:[]};for(let t of n.lights||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return Gr({lightSources:e})}return{}}var te={name:"lights",vs:un,fs:un,getUniforms:Gr,defines:{MAX_LIGHTS:3}};var Ci={lightDirection:new Float32Array([1,1,2])};function Ri(n=Ci){let e={};return n.lightDirection&&(e.dirlight_uLightDirection=n.lightDirection),e}var Oi=`uniform vec3 dirlight_uLightDirection;
|
|
2555
2499
|
vec4 dirlight_filterColor(vec4 color) {
|
|
2556
2500
|
vec3 normal = project_getNormal_World();
|
|
2557
2501
|
float d = abs(dot(normalize(normal), normalize(dirlight_uLightDirection)));
|
|
2558
2502
|
return vec4(color.rgb * d, color.a);
|
|
2559
2503
|
}
|
|
2560
|
-
`,Wr={name:"dirlight",fs:
|
|
2504
|
+
`,Wr={name:"dirlight",fs:Oi,getUniforms:Ri,dependencies:[nt]};var hn=`uniform float lighting_uAmbient;
|
|
2561
2505
|
uniform float lighting_uDiffuse;
|
|
2562
2506
|
uniform float lighting_uShininess;
|
|
2563
2507
|
uniform vec3 lighting_uSpecularColor;
|
|
@@ -2620,7 +2564,7 @@ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction,
|
|
|
2620
2564
|
}
|
|
2621
2565
|
return lightColor;
|
|
2622
2566
|
}
|
|
2623
|
-
`;var
|
|
2567
|
+
`;var Ui={};function zi(n){let{ambient:e=.35,diffuse:t=.6,shininess:r=32,specularColor:o=[30,30,30]}=n;return{lighting_uAmbient:e,lighting_uDiffuse:t,lighting_uShininess:r,lighting_uSpecularColor:o.map(i=>i/255)}}function jr(n=Ui){if(!("material"in n))return{};let{material:e}=n;return e?zi(e):{lighting_uEnabled:!1}}var $r={name:"gouraud-lighting",dependencies:[te],vs:hn,defines:{LIGHTING_VERTEX:1},getUniforms:jr},Kr={name:"phong-lighting",dependencies:[te],fs:hn,defines:{LIGHTING_FRAGMENT:1},getUniforms:jr};var Zr=`uniform mat4 u_MVPMatrix;
|
|
2624
2568
|
uniform mat4 u_ModelMatrix;
|
|
2625
2569
|
uniform mat4 u_NormalMatrix;
|
|
2626
2570
|
out vec3 pbr_vPosition;
|