@luma.gl/shadertools 9.3.1 → 9.3.2
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 +15 -28
- package/dist/dist.min.js +51 -48
- package/dist/index.cjs +15 -22
- package/dist/index.cjs.map +3 -3
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +0 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +6 -11
- package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.d.ts +0 -1
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +6 -11
- package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +4 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
- package/package.json +2 -2
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +7 -15
- package/src/modules/lighting/phong-material/phong-material.ts +7 -15
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +4 -1
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 Kr=Object.create;var Q=Object.defineProperty;var Yr=Object.getOwnPropertyDescriptor;var Xr=Object.getOwnPropertyNames;var Zr=Object.getPrototypeOf,Qr=Object.prototype.hasOwnProperty;var Jr=(e,t,r)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var en=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),tn=(e,t)=>{for(var r in t)Q(e,r,{get:t[r],enumerable:!0})},
|
|
7
|
+
"use strict";var __exports__=(()=>{var Kr=Object.create;var Q=Object.defineProperty;var Yr=Object.getOwnPropertyDescriptor;var Xr=Object.getOwnPropertyNames;var Zr=Object.getPrototypeOf,Qr=Object.prototype.hasOwnProperty;var Jr=(e,t,r)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var en=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),tn=(e,t)=>{for(var r in t)Q(e,r,{get:t[r],enumerable:!0})},pe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xr(t))!Qr.call(e,o)&&o!==r&&Q(e,o,{get:()=>t[o],enumerable:!(n=Yr(t,o))||n.enumerable});return e},ue=(e,t,r)=>(pe(e,t,"default"),r&&pe(r,t,"default")),ut=(e,t,r)=>(r=e!=null?Kr(Zr(e)):{},pe(t||!e||!e.__esModule?Q(r,"default",{value:e,enumerable:!0}):r,e)),rn=e=>pe(Q({},"__esModule",{value:!0}),e);var ht=(e,t,r)=>(Jr(e,typeof t!="symbol"?t+"":t,r),r);var Be=en((Ko,mt)=>{mt.exports=globalThis.luma});var fe={};tn(fe,{ShaderAssembler:()=>ie,_getDependencyGraph:()=>ne,_resolveModules:()=>Rt,assembleGLSLShaderPair:()=>Me,capitalize:()=>D,checkShaderModuleDeprecations:()=>te,combineInjects:()=>Lt,convertToVec4:()=>Ze,dirlight:()=>lt,floatColors:()=>X,fp32:()=>Rr,fp64:()=>Cr,fp64LowPart:()=>ae,fp64arithmetic:()=>at,fp64ify:()=>K,fp64ifyMatrix4:()=>se,fromHalfFloat:()=>Mr,generateShaderForModule:()=>Kt,getGLSLUniformBlocks:()=>de,getPassthroughFS:()=>Ht,getQualifierDetails:()=>Gt,getShaderInfo:()=>be,getShaderModuleDependencies:()=>re,getShaderModuleSource:()=>Le,getShaderModuleUniformBlockFields:()=>ze,getShaderModuleUniformBlockName:()=>me,getShaderModuleUniformLayoutValidationResult:()=>Ge,getShaderModuleUniforms:()=>At,gouraudMaterial:()=>ft,ibl:()=>Ue,initializeShaderModule:()=>he,initializeShaderModules:()=>F,lambertMaterial:()=>ct,lighting:()=>V,normalizeByteColor3:()=>le,normalizeByteColor4:()=>Pe,pbrMaterial:()=>$r,pbrScene:()=>qr,phongMaterial:()=>pt,picking:()=>Nr,preprocess:()=>Ae,random:()=>Ar,resolveUseByteColors:()=>Y,skin:()=>Pr,toHalfFloat:()=>xr,typeToChannelCount:()=>Wt,typeToChannelSuffix:()=>$t,validateShaderModuleUniformLayout:()=>ge,warnIfGLSLUniformBlocksAreNotStd140:()=>_e});ue(fe,ut(Be(),1));function U(e,t){if(!e){let r=new Error(t||"shadertools: assertion failed.");throw Error.captureStackTrace?.(r,U),r}}var ke={number:{type:"number",validate(e,t){return Number.isFinite(e)&&typeof t=="object"&&(t.max===void 0||e<=t.max)&&(t.min===void 0||e>=t.min)}},array:{type:"array",validate(e,t){return Array.isArray(e)||ArrayBuffer.isView(e)}}};function dt(e){let t={};for(let[r,n]of Object.entries(e))t[r]=nn(n);return t}function _t(e,t,r){let n={};for(let[o,i]of Object.entries(t))e&&o in e&&!i.private?(i.validate&&U(i.validate(e[o],i),`${r}: invalid ${o}`),n[o]=e[o]):n[o]=i.value;return n}function nn(e){let t=gt(e);if(t!=="object")return{value:e,...ke[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...ke[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=gt(e.value),{...e,...ke[t],type:t}):{type:"object",value:null};throw new Error("props")}function gt(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}var bt=`#ifdef MODULE_LOGDEPTH
|
|
8
8
|
logdepth_adjustPosition(gl_Position);
|
|
9
9
|
#endif
|
|
10
|
-
`,
|
|
10
|
+
`,vt=`#ifdef MODULE_MATERIAL
|
|
11
11
|
fragColor = material_filterColor(fragColor);
|
|
12
12
|
#endif
|
|
13
13
|
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
#ifdef MODULE_LOGDEPTH
|
|
28
28
|
logdepth_setFragDepth();
|
|
29
29
|
#endif
|
|
30
|
-
`;var on={vertex:
|
|
30
|
+
`;var on={vertex:bt,fragment:vt},St=/void\s+main\s*\([^)]*\)\s*\{\n?/,xt=/}\n?[^{}]*$/,De=[],J="__LUMA_INJECT_DECLARATIONS__";function Mt(e){let t={vertex:{},fragment:{}};for(let r in e){let n=e[r],o=an(r);typeof n=="string"&&(n={order:0,injection:n}),t[o][r]=n}return t}function an(e){let t=e.slice(0,2);switch(t){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(t)}}function ee(e,t,r,n=!1){let o=t==="vertex";for(let i in r){let a=r[i];a.sort((l,c)=>l.order-c.order),De.length=a.length;for(let l=0,c=a.length;l<c;++l)De[l]=a[l].injection;let s=`${De.join(`
|
|
31
31
|
`)}
|
|
32
|
-
`;switch(i){case"vs:#decl":o&&(e=e.replace(J,s));break;case"vs:#main-start":o&&(e=e.replace(
|
|
33
|
-
${r[n]}`:r[n]}),t}function F(e){e.map(t=>
|
|
34
|
-
`)){let a=i.replace(/\/\/.*$/,"").trim();if(!a||a.startsWith("#"))continue;let s=t==="wgsl"?a.match(/^([A-Za-z0-9_]+)\s*:/):a.match(cn);s&&o.push(s[1])}return o}function un(e,t){let r=new RegExp(`\\bstruct\\s+${t}\\b`,"m").exec(e);if(!r)return null;let n=e.indexOf("{",r.index);if(n<0)return null;let o=0;for(let i=n;i<e.length;i++){let a=e[i];if(a==="{"){o++;continue}if(a==="}"&&(o--,o===0))return e.slice(n+1,i)}return null}function hn(e,t){return
|
|
32
|
+
`;switch(i){case"vs:#decl":o&&(e=e.replace(J,s));break;case"vs:#main-start":o&&(e=e.replace(St,l=>l+s));break;case"vs:#main-end":o&&(e=e.replace(xt,l=>s+l));break;case"fs:#decl":o||(e=e.replace(J,s));break;case"fs:#main-start":o||(e=e.replace(St,l=>l+s));break;case"fs:#main-end":o||(e=e.replace(xt,l=>s+l));break;default:e=e.replace(i,l=>l+s)}}return e=e.replace(J,""),n&&(e=e.replace(/\}\s*$/,i=>i+on[t])),e}function Lt(e){let t={};return U(Array.isArray(e)&&e.length>1),e.forEach(r=>{for(let n in r)t[n]=t[n]?`${t[n]}
|
|
33
|
+
${r[n]}`:r[n]}),t}function F(e){e.map(t=>he(t))}function he(e){if(e.instance)return;F(e.dependencies||[]);let{propTypes:t={},deprecations:r=[],inject:n={}}=e,o={normalizedInjections:Mt(n),parsedDeprecations:sn(r)};t&&(o.propValidators=dt(t)),e.instance=o;let i={};t&&(i=Object.entries(t).reduce((a,[s,l])=>{let c=l?.value;return c&&(a[s]=c),a},{})),e.defaultUniforms={...e.defaultUniforms,...i}}function At(e,t,r){he(e);let n=r||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,n):_t(t,e.instance?.propValidators,e.name)}function te(e,t,r){e.deprecations?.forEach(n=>{n.regex?.test(t)&&(n.deprecated?r.deprecated(n.old,n.new)():r.removed(n.old,n.new)())})}function sn(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}function re(e){F(e);let t={},r={};ne({modules:e,level:0,moduleMap:t,moduleDepth:r});let n=Object.keys(r).sort((o,i)=>r[i]-r[o]).map(o=>t[o]);return F(n),n}function ne(e){let{modules:t,level:r,moduleMap:n,moduleDepth:o}=e;if(r>=5)throw new Error("Possible loop in shader dependency graph");for(let i of t)n[i.name]=i,(o[i.name]===void 0||o[i.name]<r)&&(o[i.name]=r);for(let i of t)i.dependencies&&ne({modules:i.dependencies,level:r+1,moduleMap:n,moduleDepth:o})}function ln(e){F(e);let t={},r={};return ne({modules:e,level:0,moduleMap:t,moduleDepth:r}),e=Object.keys(r).sort((n,o)=>r[o]-r[n]).map(n=>t[n]),F(e),e}function Rt(e){return ln(e)}var cn=/^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/,fn=/((?:layout\s*\([^)]*\)\s*)*)uniform\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\}\s*([A-Za-z_][A-Za-z0-9_]*)?\s*;/g;function me(e){return`${e.name}Uniforms`}function ze(e,t){let r=t==="wgsl"?e.source:t==="vertex"?e.vs:e.fs;if(!r)return null;let n=me(e);return pn(r,t==="wgsl"?"wgsl":"glsl",n)}function Ge(e,t){let r=Object.keys(e.uniformTypes||{});if(!r.length)return null;let n=ze(e,t);return n?{moduleName:e.name,uniformBlockName:me(e),stage:t,expectedUniformNames:r,actualUniformNames:n,matches:mn(r,n)}:null}function ge(e,t,r={}){let n=Ge(e,t);if(!n||n.matches)return n;let o=gn(n);return r.log?.error?.(o,n)(),r.throwOnError!==!1&&U(!1,o),n}function de(e){let t=[],r=dn(e);for(let n of r.matchAll(fn)){let o=n[1]?.trim()||null;t.push({blockName:n[2],body:n[3],instanceName:n[4]||null,layoutQualifier:o,hasLayoutQualifier:Boolean(o),isStd140:Boolean(o&&/\blayout\s*\([^)]*\bstd140\b[^)]*\)/.exec(o))})}return t}function _e(e,t,r,n){let o=de(e).filter(a=>!a.isStd140),i=new Set;for(let a of o){if(i.has(a.blockName))continue;i.add(a.blockName);let s=n?.label?`${n.label} `:"",l=a.hasLayoutQualifier?`declares ${_n(a.layoutQualifier)} instead of layout(std140)`:"does not declare layout(std140)",c=`${s}${t} shader uniform block ${a.blockName} ${l}. luma.gl host-side shader block packing assumes explicit layout(std140) for GLSL uniform blocks. Add \`layout(std140)\` to the block declaration.`;r?.warn?.(c,a)()}return o}function pn(e,t,r){let n=t==="wgsl"?un(e,r):hn(e,r);if(!n)return null;let o=[];for(let i of n.split(`
|
|
34
|
+
`)){let a=i.replace(/\/\/.*$/,"").trim();if(!a||a.startsWith("#"))continue;let s=t==="wgsl"?a.match(/^([A-Za-z0-9_]+)\s*:/):a.match(cn);s&&o.push(s[1])}return o}function un(e,t){let r=new RegExp(`\\bstruct\\s+${t}\\b`,"m").exec(e);if(!r)return null;let n=e.indexOf("{",r.index);if(n<0)return null;let o=0;for(let i=n;i<e.length;i++){let a=e[i];if(a==="{"){o++;continue}if(a==="}"&&(o--,o===0))return e.slice(n+1,i)}return null}function hn(e,t){return de(e).find(n=>n.blockName===t)?.body||null}function mn(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function gn(e){let{expectedUniformNames:t,actualUniformNames:r}=e,n=t.filter(s=>!r.includes(s)),o=r.filter(s=>!t.includes(s)),i=[`Expected ${t.length} fields, found ${r.length}.`],a=bn(t,r);return a&&i.push(a),n.length&&i.push(`Missing from shader block (${n.length}): ${Et(n)}.`),o.length&&i.push(`Unexpected in shader block (${o.length}): ${Et(o)}.`),t.length<=12&&r.length<=12&&(n.length||o.length)&&(i.push(`Expected: ${t.join(", ")}.`),i.push(`Actual: ${r.join(", ")}.`)),`${e.moduleName}: ${e.stage} shader uniform block ${e.uniformBlockName} does not match module.uniformTypes. ${i.join(" ")}`}function dn(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function _n(e){return e.replace(/\s+/g," ").trim()}function bn(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)if(e[n]!==t[n])return`First mismatch at field ${n+1}: expected ${e[n]}, found ${t[n]}.`;return e.length>t.length?`Shader block ends after field ${t.length}; expected next field ${e[t.length]}.`:t.length>e.length?`Shader block has extra field ${t.length}: ${t[e.length]}.`:null}function Et(e,t=8){if(e.length<=t)return e.join(", ");let r=e.length-t;return`${e.slice(0,t).join(", ")}, ... (${r} more)`}function It(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
|
|
35
35
|
// Apple optimizes away the calculation necessary for emulated fp64
|
|
36
36
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
37
37
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
@@ -55,60 +55,60 @@ ${r[n]}`:r[n]}),t}function F(e){e.map(t=>ue(t))}function ue(e){if(e.instance)ret
|
|
|
55
55
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
56
56
|
// If the GPU doesn't have full 32 bits precision, will causes overflow
|
|
57
57
|
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
58
|
-
`}}function
|
|
59
|
-
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],vn=[...
|
|
58
|
+
`}}function yt(e,t){if(Number(e.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(t){case"vertex":return e=Ct(e,vn),e;case"fragment":return e=Ct(e,Sn),e;default:throw new Error(t)}}var Nt=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
|
|
59
|
+
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],vn=[...Nt,[He("attribute"),"in $1"],[He("varying"),"out $1"]],Sn=[...Nt,[He("varying"),"in $1"]];function Ct(e,t){for(let[r,n]of t)e=e.replace(r,n);return e}function He(e){return new RegExp(`\\b${e}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function $e(e,t){let r="";for(let n in e){let o=e[n];if(r+=`void ${o.signature} {
|
|
60
60
|
`,o.header&&(r+=` ${o.header}`),t[n]){let i=t[n];i.sort((a,s)=>a.order-s.order);for(let a of i)r+=` ${a.injection}
|
|
61
61
|
`}o.footer&&(r+=` ${o.footer}`),r+=`}
|
|
62
|
-
`}return r}function
|
|
62
|
+
`}return r}function We(e){let t={vertex:{},fragment:{}};for(let r of e){let n,o;typeof r!="string"?(n=r,o=n.hook):(n={},o=r),o=o.trim();let[i,a]=o.split(":"),s=o.replace(/\(.+/,""),l=Object.assign(n,{signature:a});switch(i){case"vs":t.vertex[s]=l;break;case"fs":t.fragment[s]=l;break;default:throw new Error(i)}}return t}function be(e,t){return{name:xn(e,t),language:"glsl",version:Mn(e)}}function xn(e,t="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(e);return n?n[1]:t}function Mn(e){let t=100,r=e.match(/[^\s]+/g);if(r&&r.length>=2&&r[0]==="#version"){let n=parseInt(r[1],10);Number.isFinite(n)&&(t=n)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}var N="(?:var<\\s*(uniform|storage(?:\\s*,\\s*[A-Za-z_][A-Za-z0-9_]*)?)\\s*>|var)\\s+([A-Za-z_][A-Za-z0-9_]*)",T="\\s*",H=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(auto|\\d+)\\s*\\)${T}${N}`,"g")],ve=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(auto|\\d+)\\s*\\)${T}${N}`,"g")],Pt=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g")],Ln=[new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)\\s*${N}`,"g"),new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${N}`,"g")];function Se(e){let t=e.split(""),r=0,n=0,o=!1,i=!1,a=!1;for(;r<e.length;){let s=e[r],l=e[r+1];if(i){a?a=!1:s==="\\"?a=!0:s==='"'&&(i=!1),r++;continue}if(o){s===`
|
|
63
63
|
`||s==="\r"?o=!1:t[r]=" ",r++;continue}if(n>0){if(s==="/"&&l==="*"){t[r]=" ",t[r+1]=" ",n++,r+=2;continue}if(s==="*"&&l==="/"){t[r]=" ",t[r+1]=" ",n--,r+=2;continue}s!==`
|
|
64
|
-
`&&s!=="\r"&&(t[r]=" "),r++;continue}if(s==='"'){i=!0,r++;continue}if(s==="/"&&l==="/"){t[r]=" ",t[r+1]=" ",o=!0,r+=2;continue}if(s==="/"&&l==="*"){t[r]=" ",t[r+1]=" ",n=1,r+=2;continue}r++}return t.join("")}function
|
|
64
|
+
`&&s!=="\r"&&(t[r]=" "),r++;continue}if(s==='"'){i=!0,r++;continue}if(s==="/"&&l==="/"){t[r]=" ",t[r+1]=" ",o=!0,r+=2;continue}if(s==="/"&&l==="*"){t[r]=" ",t[r+1]=" ",n=1,r+=2;continue}r++}return t.join("")}function k(e,t){let r=Se(e),n=[];for(let o of t){o.lastIndex=0;let i;for(i=o.exec(r);i;){let a=o===t[0],s=i.index,l=i[0].length;n.push({match:e.slice(s,s+l),index:s,length:l,bindingToken:i[a?1:2],groupToken:i[a?2:1],accessDeclaration:i[3]?.trim(),name:i[4]}),i=o.exec(r)}}return n.sort((o,i)=>o.index-i.index)}function je(e,t,r){let n=k(e,t);if(!n.length)return e;let o="",i=0;for(let a of n)o+=e.slice(i,a.index),o+=r(a),i=a.index+a.length;return o+=e.slice(i),o}function qe(e){return/@binding\(\s*auto\s*\)/.test(Se(e))}function Tt(e,t){return k(e,t===H||t===ve?Ln:t).find(n=>n.bindingToken==="auto")}var Ot=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${N}\\s*:\\s*([^;]+);`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${N}\\s*:\\s*([^;]+);`,"g")];function xe(e,t=[]){let r=Se(e),n=new Map;for(let i of t)n.set(Ut(i.name,i.group,i.location),i.moduleName);let o=[];for(let i of Ot){i.lastIndex=0;let a;for(a=i.exec(r);a;){let s=i===Ot[0],l=Number(a[s?1:2]),c=Number(a[s?2:1]),f=a[3]?.trim(),p=a[4],u=a[5].trim(),h=n.get(Ut(p,c,l));o.push(An({name:p,group:c,binding:l,owner:h?"module":"application",moduleName:h,accessDeclaration:f,resourceType:u})),a=i.exec(r)}}return o.sort((i,a)=>i.group!==a.group?i.group-a.group:i.binding!==a.binding?i.binding-a.binding:i.name.localeCompare(a.name))}function An(e){let t={name:e.name,group:e.group,binding:e.binding,owner:e.owner,kind:"unknown",moduleName:e.moduleName,resourceType:e.resourceType};if(e.accessDeclaration){let r=e.accessDeclaration.split(",").map(n=>n.trim());if(r[0]==="uniform")return{...t,kind:"uniform",access:"uniform"};if(r[0]==="storage"){let n=r[1]||"read_write";return{...t,kind:n==="read"?"read-only-storage":"storage",access:n}}}return e.resourceType==="sampler"||e.resourceType==="sampler_comparison"?{...t,kind:"sampler",samplerKind:e.resourceType==="sampler_comparison"?"comparison":"filtering"}:e.resourceType.startsWith("texture_storage_")?{...t,kind:"storage-texture",access:En(e.resourceType),viewDimension:Ft(e.resourceType)}:e.resourceType.startsWith("texture_")?{...t,kind:"texture",viewDimension:Ft(e.resourceType),sampleType:Rn(e.resourceType),multisampled:e.resourceType.startsWith("texture_multisampled_")}:t}function Ut(e,t,r){return`${t}:${r}:${e}`}function Ft(e){if(e.includes("cube_array"))return"cube-array";if(e.includes("2d_array"))return"2d-array";if(e.includes("cube"))return"cube";if(e.includes("3d"))return"3d";if(e.includes("2d"))return"2d";if(e.includes("1d"))return"1d"}function Rn(e){if(e.startsWith("texture_depth_"))return"depth";if(e.includes("<i32>"))return"sint";if(e.includes("<u32>"))return"uint";if(e.includes("<f32>"))return"float"}function En(e){return/,\s*([A-Za-z_][A-Za-z0-9_]*)\s*>$/.exec(e)?.[1]}var Ke=`
|
|
65
65
|
|
|
66
66
|
${J}
|
|
67
|
-
`,oe=100,
|
|
68
|
-
`;function
|
|
67
|
+
`,oe=100,In=`precision highp float;
|
|
68
|
+
`;function kt(e){let t=re(e.modules||[]),{source:r,bindingAssignments:n}=Cn(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t});return{source:r,getUniforms:Dt(t),bindingAssignments:n,bindingTable:xe(r,n)}}function Me(e){let{vs:t,fs:r}=e,n=re(e.modules||[]);return{vs:Vt(e.platformInfo,{...e,source:t,stage:"vertex",modules:n}),fs:Vt(e.platformInfo,{...e,source:r,stage:"fragment",modules:n}),getUniforms:Dt(n)}}function Cn(e,t){let{source:r,stage:n,modules:o,hookFunctions:i=[],inject:a={},log:s}=t;U(typeof r=="string","shader source must be a string");let l=r,c="",f=We(i),p={},u={},h={};for(let d in a){let b=typeof a[d]=="string"?{injection:a[d],order:0}:a[d],v=/^(v|f)s:(#)?([\w-]+)$/.exec(d);if(v){let m=v[2],M=v[3];m?M==="decl"?u[d]=[b]:h[d]=[b]:p[d]=[b]}else h[d]=[b]}let g=o,S=Pn(l),x=Nn(S.source),_=Fn(g,t._bindingRegistry,x),L=[];for(let d of g){s&&te(d,l,s);let b=Tn(Le(d,"wgsl",s),d,{usedBindingsByGroup:x,bindingRegistry:t._bindingRegistry,reservedBindingKeysByGroup:_});L.push(...b.bindingAssignments);let v=b.source;c+=v;let m=d.injections?.[n]||{};for(let M in m){let E=/^(v|f)s:#([\w-]+)$/.exec(M);if(E){let I=E[2]==="decl"?u:h;I[M]=I[M]||[],I[M].push(m[M])}else p[M]=p[M]||[],p[M].push(m[M])}}return c+=Ke,c=ee(c,n,u),c+=$e(f[n],p),c+=Dn(L),c+=S.source,c=ee(c,n,h),kn(c),{source:c,bindingAssignments:L}}function Vt(e,t){let{source:r,stage:n,language:o="glsl",modules:i,defines:a={},hookFunctions:s=[],inject:l={},prologue:c=!0,log:f}=t;U(typeof r=="string","shader source must be a string");let p=o==="glsl"?be(r).version:-1,u=e.shaderLanguageVersion,h=p===100?"#version 100":"#version 300 es",S=r.split(`
|
|
69
69
|
`).slice(1).join(`
|
|
70
70
|
`),x={};i.forEach(m=>{Object.assign(x,m.defines)}),Object.assign(x,a);let _="";switch(o){case"wgsl":break;case"glsl":_=c?`${h}
|
|
71
71
|
|
|
72
72
|
// ----- PROLOGUE -------------------------
|
|
73
73
|
${`#define SHADER_TYPE_${n.toUpperCase()}`}
|
|
74
74
|
|
|
75
|
-
${
|
|
76
|
-
${n==="fragment"?
|
|
75
|
+
${It(e)}
|
|
76
|
+
${n==="fragment"?In:""}
|
|
77
77
|
|
|
78
78
|
// ----- APPLICATION DEFINES -------------------------
|
|
79
79
|
|
|
80
80
|
${yn(x)}
|
|
81
81
|
|
|
82
82
|
`:`${h}
|
|
83
|
-
`;break}let L
|
|
84
|
-
`)}return t}function
|
|
83
|
+
`;break}let L=We(s),d={},b={},v={};for(let m in l){let M=typeof l[m]=="string"?{injection:l[m],order:0}:l[m],E=/^(v|f)s:(#)?([\w-]+)$/.exec(m);if(E){let A=E[2],I=E[3];A?I==="decl"?b[m]=[M]:v[m]=[M]:d[m]=[M]}else v[m]=[M]}for(let m of i){f&&te(m,S,f);let M=Le(m,n,f);_+=M;let E=m.instance?.normalizedInjections[n]||{};for(let A in E){let I=/^(v|f)s:#([\w-]+)$/.exec(A);if(I){let C=I[2]==="decl"?b:v;C[A]=C[A]||[],C[A].push(E[A])}else d[A]=d[A]||[],d[A].push(E[A])}}return _+="// ----- MAIN SHADER SOURCE -------------------------",_+=Ke,_=ee(_,n,b),_+=$e(L[n],d),_+=S,_=ee(_,n,v),o==="glsl"&&p!==u&&(_=yt(_,n)),o==="glsl"&&_e(_,n,f),_.trim()}function Dt(e){return function(r){let n={};for(let o of e){let i=o.getUniforms?.(r,n);Object.assign(n,i)}return n}}function yn(e={}){let t="";for(let r in e){let n=e[r];(n||Number.isFinite(n))&&(t+=`#define ${r.toUpperCase()} ${e[r]}
|
|
84
|
+
`)}return t}function Le(e,t,r){let n;switch(t){case"vertex":n=e.vs||"";break;case"fragment":n=e.fs||"";break;case"wgsl":n=e.source||"";break;default:U(!1)}if(!e.name)throw new Error("Shader module must have a name");ge(e,t,{log:r});let o=e.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),i=`// ----- MODULE ${e.name} ---------------
|
|
85
85
|
|
|
86
86
|
`;return t!=="wgsl"&&(i+=`#define MODULE_${o}
|
|
87
87
|
`),i+=`${n}
|
|
88
|
-
`,i}function Nn(e){let t=new Map;for(let r of
|
|
88
|
+
`,i}function Nn(e){let t=new Map;for(let r of k(e,Pt)){let n=Number(r.bindingToken),o=Number(r.groupToken);Ye(o,n,r.name),$(t,o,n,`application binding "${r.name}"`)}return t}function Pn(e){let t=k(e,ve),r=new Map;for(let i of t){if(i.bindingToken==="auto")continue;let a=Number(i.bindingToken),s=Number(i.groupToken);Ye(s,a,i.name),$(r,s,a,`application binding "${i.name}"`)}let n={sawSupportedBindingDeclaration:t.length>0},o=je(e,ve,i=>Un(i,r,n));if(qe(e)&&!n.sawSupportedBindingDeclaration)throw new Error('Unsupported @binding(auto) declaration form in application WGSL. Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.');return{source:o}}function Tn(e,t,r){let n=[],i={sawSupportedBindingDeclaration:k(e,H).length>0,nextHintedBindingLocation:typeof t.firstBindingSlot=="number"?t.firstBindingSlot:null},a=je(e,H,s=>On(s,{module:t,context:r,bindingAssignments:n,relocationState:i}));if(qe(e)&&!i.sawSupportedBindingDeclaration)throw new Error(`Unsupported @binding(auto) declaration form in module "${t.name}". Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.`);return{source:a,bindingAssignments:n}}function On(e,t){let{module:r,context:n,bindingAssignments:o,relocationState:i}=t,{match:a,bindingToken:s,groupToken:l,name:c}=e,f=Number(l);if(s==="auto"){let u=zt(f,r.name,c),h=n.bindingRegistry?.get(u),g=h!==void 0?h:i.nextHintedBindingLocation===null?Bt(f,n.usedBindingsByGroup):Bt(f,n.usedBindingsByGroup,i.nextHintedBindingLocation);return wt(r.name,f,g,c),h!==void 0&&Vn(n.reservedBindingKeysByGroup,f,g,u)?(o.push({moduleName:r.name,name:c,group:f,location:g}),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${g})`)):($(n.usedBindingsByGroup,f,g,`module "${r.name}" binding "${c}"`),n.bindingRegistry?.set(u,g),o.push({moduleName:r.name,name:c,group:f,location:g}),i.nextHintedBindingLocation!==null&&h===void 0&&(i.nextHintedBindingLocation=g+1),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${g})`))}let p=Number(s);return wt(r.name,f,p,c),$(n.usedBindingsByGroup,f,p,`module "${r.name}" binding "${c}"`),o.push({moduleName:r.name,name:c,group:f,location:p}),a}function Un(e,t,r){let{match:n,bindingToken:o,groupToken:i,name:a}=e,s=Number(i);if(o==="auto"){let l=Bn(s,t);return Ye(s,l,a),$(t,s,l,`application binding "${a}"`),n.replace(/@binding\(\s*auto\s*\)/,`@binding(${l})`)}return r.sawSupportedBindingDeclaration=!0,n}function Fn(e,t,r){let n=new Map;if(!t)return n;for(let o of e)for(let i of wn(o)){let a=zt(i.group,o.name,i.name),s=t.get(a);if(s!==void 0){let l=n.get(i.group)||new Map,c=l.get(s);if(c&&c!==a)throw new Error(`Duplicate WGSL binding reservation for modules "${c}" and "${a}": group ${i.group}, binding ${s}.`);$(r,i.group,s,`registered module binding "${a}"`),l.set(s,a),n.set(i.group,l)}}return n}function Vn(e,t,r,n){let o=e.get(t);if(!o)return!1;let i=o.get(r);if(!i)return!1;if(i!==n)throw new Error(`Registered module binding "${n}" collided with "${i}": group ${t}, binding ${r}.`);return!0}function wn(e){let t=[],r=e.source||"";for(let n of k(r,H))t.push({name:n.name,group:Number(n.groupToken)});return t}function Ye(e,t,r){if(e===0&&t>=oe)throw new Error(`Application binding "${r}" in group 0 uses reserved binding ${t}. Application-owned explicit group-0 bindings must stay below ${oe}.`)}function wt(e,t,r,n){if(t===0&&r<oe)throw new Error(`Module "${e}" binding "${n}" in group 0 uses reserved application binding ${r}. Module-owned explicit group-0 bindings must be ${oe} or higher.`)}function $(e,t,r,n){let o=e.get(t)||new Set;if(o.has(r))throw new Error(`Duplicate WGSL binding assignment for ${n}: group ${t}, binding ${r}.`);o.add(r),e.set(t,o)}function Bt(e,t,r){let n=t.get(e)||new Set,o=r??(e===0?oe:n.size>0?Math.max(...n)+1:0);for(;n.has(o);)o++;return o}function Bn(e,t){let r=t.get(e)||new Set,n=0;for(;r.has(n);)n++;return n}function kn(e){let t=Tt(e,H);if(!t)return;let r=zn(e,t.index);throw r?new Error(`Unresolved @binding(auto) for module "${r}" binding "${t.name}" remained in assembled WGSL source.`):Gn(e,t.index)?new Error(`Unresolved @binding(auto) for application binding "${t.name}" remained in assembled WGSL source.`):new Error(`Unresolved @binding(auto) remained in assembled WGSL source near "${Hn(t.match)}".`)}function Dn(e){if(e.length===0)return"";let t=`// ----- MODULE WGSL BINDING ASSIGNMENTS ---------------
|
|
89
89
|
`;for(let r of e)t+=`// ${r.moduleName}.${r.name} -> @group(${r.group}) @binding(${r.location})
|
|
90
90
|
`;return t+=`
|
|
91
|
-
`,t}function
|
|
91
|
+
`,t}function zt(e,t,r){return`${e}:${t}:${r}`}function zn(e,t){let r=/^\/\/ ----- MODULE ([^\n]+) ---------------$/gm,n,o;for(o=r.exec(e);o&&o.index<=t;)n=o[1],o=r.exec(e);return n}function Gn(e,t){let r=e.indexOf(Ke);return r>=0?t>r:!0}function Hn(e){return e.replace(/\s+/g," ").trim()}var Xe="([a-zA-Z_][a-zA-Z0-9_]*)",$n=new RegExp(`^\\s*\\#\\s*ifdef\\s*${Xe}\\s*$`),Wn=new RegExp(`^\\s*\\#\\s*ifndef\\s*${Xe}\\s*(?:\\/\\/.*)?$`),jn=/^\s*\#\s*else\s*(?:\/\/.*)?$/,qn=/^\s*\#\s*endif\s*$/,Kn=new RegExp(`^\\s*\\#\\s*ifdef\\s*${Xe}\\s*(?:\\/\\/.*)?$`),Yn=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function Ae(e,t){let r=e.split(`
|
|
92
92
|
`),n=[],o=[],i=!0;for(let a of r){let s=a.match(Kn)||a.match($n),l=a.match(Wn),c=a.match(jn),f=a.match(Yn)||a.match(qn);if(s||l){let p=(s||l)?.[1],u=Boolean(t?.defines?.[p]),h=s?u:!u,g=i&&h;o.push({parentActive:i,branchTaken:h,active:g}),i=g}else if(c){let p=o[o.length-1];if(!p)throw new Error("Encountered #else without matching #ifdef or #ifndef");p.active=p.parentActive&&!p.branchTaken,p.branchTaken=!0,i=p.active}else f?(o.pop(),i=o.length?o[o.length-1].active:!0):i&&n.push(a)}if(o.length>0)throw new Error("Unterminated conditional block in shader source");return n.join(`
|
|
93
|
-
`)}var
|
|
93
|
+
`)}var W=class{_hookFunctions=[];_defaultModules=[];_wgslBindingRegistry=new Map;static getDefaultShaderAssembler(){return W.defaultShaderAssembler=W.defaultShaderAssembler||new W,W.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(r=>r.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let r=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==r)}addShaderHook(t,r){r&&(t=Object.assign(r,{hook:t})),this._hookFunctions.push(t)}assembleWGSLShader(t){let r=this._getModuleList(t.modules),n=this._hookFunctions,{source:o,getUniforms:i,bindingAssignments:a}=kt({...t,source:t.source,_bindingRegistry:this._wgslBindingRegistry,modules:r,hookFunctions:n}),s={...r.reduce((c,f)=>(Object.assign(c,f.defines),c),{}),...t.defines},l=t.platformInfo.shaderLanguage==="wgsl"?Ae(o,{defines:s}):o;return{source:l,getUniforms:i,modules:r,bindingAssignments:a,bindingTable:xe(l,a)}}assembleGLSLShaderPair(t){let r=this._getModuleList(t.modules),n=this._hookFunctions;return{...Me({...t,vs:t.vs,fs:t.fs,modules:r,hookFunctions:n}),modules:r}}_getModuleList(t=[]){let r=new Array(this._defaultModules.length+t.length),n={},o=0;for(let i=0,a=this._defaultModules.length;i<a;++i){let s=this._defaultModules[i],l=s.name;r[o++]=s,n[l]=!0}for(let i=0,a=t.length;i<a;++i){let s=t[i],l=s.name;n[l]||(r[o++]=s,n[l]=!0)}return r.length=o,F(r),r}},ie=W;ht(ie,"defaultShaderAssembler");var Xn=`out vec4 transform_output;
|
|
94
94
|
void main() {
|
|
95
95
|
transform_output = vec4(0);
|
|
96
96
|
}`,Zn=`#version 300 es
|
|
97
|
-
${Xn}`;function
|
|
97
|
+
${Xn}`;function Gt(e,t){t=Array.isArray(t)?t:[t];let r=e.replace(/^\s+/,"").split(/\s+/),[n,o,i]=r;if(!t.includes(n)||!o||!i)return null;let a=i.split(";")[0];return{qualifier:n,type:o,name:a}}function Ht(e){let{input:t,inputChannels:r,output:n}=e||{};if(!t)return Zn;if(!r)throw new Error("inputChannels");let o=Qn(r),i=Ze(t,r);return`#version 300 es
|
|
98
98
|
in ${o} ${t};
|
|
99
99
|
out vec4 ${n};
|
|
100
100
|
void main() {
|
|
101
101
|
${n} = ${i};
|
|
102
|
-
}`}function
|
|
103
|
-
`)}function eo(e){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"}[e]}function
|
|
104
|
-
`)}function qt(e,t){switch(t.shaderLanguage){case"glsl":return Wt(e,t);case"wgsl":return jt(e,t)}}var Gi=1/Math.PI*180,Hi=1/180*Math.PI,ro={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...ro}};var y=globalThis.mathgl.config;function Ze(e,{precision:t=y.precision}={}){return e=no(e),`${parseFloat(e.toPrecision(t))}`}function K(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Qe(e,t,r){return io(e,n=>Math.max(t,Math.min(r,n)))}function Ae(e,t,r){let n=y.EPSILON;r&&(y.EPSILON=r);try{if(e===t)return!0;if(K(e)&&K(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(!Ae(e[o],t[o]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=y.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{y.EPSILON=n}}function no(e){return Math.round(e/y.EPSILON)*y.EPSILON}function oo(e){return e.clone?e.clone():new Array(e.length)}function io(e,t,r){if(K(e)){let n=e;r=r||oo(n);for(let o=0;o<r.length&&o<n.length;++o){let i=typeof e=="number"?e:e[o];r[o]=t(i,o,r)}return r}return t(e)}var Re=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,r=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+r];return this.check()}toArray(t=[],r=0){for(let n=0;n<this.ELEMENTS;++n)t[r+n]=this[n];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:K(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(y)}formatString(t){let r="";for(let n=0;n<this.ELEMENTS;++n)r+=(n>0?", ":"")+Ze(this[n],t);return`${t.printTypes?this.constructor.name:""}[${r}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(!Ae(this[r],t[r]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(this[r]!==t[r])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,r,n){if(n===void 0)return this.lerp(this,t,r);for(let o=0;o<this.ELEMENTS;++o){let i=t[o],a=typeof r=="number"?r:r[o];this[o]=i+n*(a-i)}return this.check()}min(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(t[r],this[r]);return this.check()}max(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.max(t[r],this[r]);return this.check()}clamp(t,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),r[n]);return this.check()}add(...t){for(let r of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=r[n];return this.check()}subtract(...t){for(let r of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=r[n];return this.check()}scale(t){if(typeof t=="number")for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;else for(let r=0;r<this.ELEMENTS&&r<t.length;++r)this[r]*=t[r];return this.check()}multiplyByScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;return this.check()}check(){if(y.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let r=0;r<this.ELEMENTS;++r)t=t&&Number.isFinite(this[r]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=t;return this.check()}addScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t),r);return this.check()}get elements(){return this}};function ao(e,t){if(e.length!==t)return!1;for(let r=0;r<e.length;++r)if(!Number.isFinite(e[r]))return!1;return!0}function Kt(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Ee(e,t,r=""){if(y.debug&&!ao(e,t))throw new Error(`math.gl: ${r} some fields set to invalid numbers'`);return e}var w=typeof Float32Array<"u"?Float32Array:Array;var Yi=Math.PI/180;function so(){let e=new w(2);return w!=Float32Array&&(e[0]=0,e[1]=0),e}function Zt(e,t,r){let n=t[0],o=t[1];return e[0]=r[0]*n+r[4]*o+r[12],e[1]=r[1]*n+r[5]*o+r[13],e}var Xi=function(){let e=so();return function(t,r,n,o,i,a){let s,l;for(r||(r=2),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],i(e,e,a),t[s]=e[0],t[s+1]=e[1];return t}}();function Qt(e,t,r){let n=t[0],o=t[1],i=r[3]*n+r[7]*o||1;return e[0]=(r[0]*n+r[4]*o)/i,e[1]=(r[1]*n+r[5]*o)/i,e}function Jt(e,t,r){let n=t[0],o=t[1],i=t[2],a=r[3]*n+r[7]*o+r[11]*i||1;return e[0]=(r[0]*n+r[4]*o+r[8]*i)/a,e[1]=(r[1]*n+r[5]*o+r[9]*i)/a,e[2]=(r[2]*n+r[6]*o+r[10]*i)/a,e}function lo(){let e=new w(3);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function er(e,t,r){let n=t[0],o=t[1],i=t[2],a=r[3]*n+r[7]*o+r[11]*i+r[15];return a=a||1,e[0]=(r[0]*n+r[4]*o+r[8]*i+r[12])/a,e[1]=(r[1]*n+r[5]*o+r[9]*i+r[13])/a,e[2]=(r[2]*n+r[6]*o+r[10]*i+r[14])/a,e}var Ji=function(){let e=lo();return function(t,r,n,o,i,a){let s,l;for(r||(r=3),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2];return t}}();var Ce=class extends Re{toString(){let t="[";if(y.printRowMajor){t+="row-major:";for(let r=0;r<this.RANK;++r)for(let n=0;n<this.RANK;++n)t+=` ${this[n*this.RANK+r]}`}else{t+="column-major:";for(let r=0;r<this.ELEMENTS;++r)t+=` ${this[r]}`}return t+="]",t}getElementIndex(t,r){return r*this.RANK+t}getElement(t,r){return this[r*this.RANK+t]}setElement(t,r,n){return this[r*this.RANK+t]=Kt(n),this}getColumn(t,r=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let o=0;o<this.RANK;++o)r[o]=this[n+o];return r}setColumn(t,r){let n=t*this.RANK;for(let o=0;o<this.RANK;++o)this[n+o]=r[o];return this}};function co(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function tr(e,t){if(e===t){let r=t[1],n=t[2],o=t[3],i=t[6],a=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=r,e[6]=t[9],e[7]=t[13],e[8]=n,e[9]=i,e[11]=t[14],e[12]=o,e[13]=a,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function rr(e,t){let r=t[0],n=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],f=t[8],p=t[9],u=t[10],h=t[11],g=t[12],S=t[13],x=t[14],_=t[15],L=r*s-n*a,d=r*l-o*a,b=r*c-i*a,v=n*l-o*s,m=n*c-i*s,M=o*c-i*l,E=f*S-p*g,A=f*x-u*g,C=f*_-h*g,P=p*x-u*S,I=p*_-h*S,O=u*_-h*x,R=L*O-d*I+b*P+v*C-m*A+M*E;return R?(R=1/R,e[0]=(s*O-l*I+c*P)*R,e[1]=(o*I-n*O-i*P)*R,e[2]=(S*M-x*m+_*v)*R,e[3]=(u*m-p*M-h*v)*R,e[4]=(l*C-a*O-c*A)*R,e[5]=(r*O-o*C+i*A)*R,e[6]=(x*b-g*M-_*d)*R,e[7]=(f*M-u*b+h*d)*R,e[8]=(a*I-s*C+c*E)*R,e[9]=(n*C-r*I-i*E)*R,e[10]=(g*m-S*b+_*L)*R,e[11]=(p*b-f*m-h*L)*R,e[12]=(s*A-a*P-l*E)*R,e[13]=(r*P-n*A+o*E)*R,e[14]=(S*d-g*v-x*L)*R,e[15]=(f*v-p*d+u*L)*R,e):null}function nr(e){let t=e[0],r=e[1],n=e[2],o=e[3],i=e[4],a=e[5],s=e[6],l=e[7],c=e[8],f=e[9],p=e[10],u=e[11],h=e[12],g=e[13],S=e[14],x=e[15],_=t*a-r*i,L=t*s-n*i,d=r*s-n*a,b=c*g-f*h,v=c*S-p*h,m=f*S-p*g,M=t*m-r*v+n*b,E=i*m-a*v+s*b,A=c*d-f*L+p*_,C=h*d-g*L+S*_;return l*M-o*E+x*A-u*C}function et(e,t,r){let n=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],f=t[7],p=t[8],u=t[9],h=t[10],g=t[11],S=t[12],x=t[13],_=t[14],L=t[15],d=r[0],b=r[1],v=r[2],m=r[3];return e[0]=d*n+b*s+v*p+m*S,e[1]=d*o+b*l+v*u+m*x,e[2]=d*i+b*c+v*h+m*_,e[3]=d*a+b*f+v*g+m*L,d=r[4],b=r[5],v=r[6],m=r[7],e[4]=d*n+b*s+v*p+m*S,e[5]=d*o+b*l+v*u+m*x,e[6]=d*i+b*c+v*h+m*_,e[7]=d*a+b*f+v*g+m*L,d=r[8],b=r[9],v=r[10],m=r[11],e[8]=d*n+b*s+v*p+m*S,e[9]=d*o+b*l+v*u+m*x,e[10]=d*i+b*c+v*h+m*_,e[11]=d*a+b*f+v*g+m*L,d=r[12],b=r[13],v=r[14],m=r[15],e[12]=d*n+b*s+v*p+m*S,e[13]=d*o+b*l+v*u+m*x,e[14]=d*i+b*c+v*h+m*_,e[15]=d*a+b*f+v*g+m*L,e}function or(e,t,r){let n=r[0],o=r[1],i=r[2],a,s,l,c,f,p,u,h,g,S,x,_;return t===e?(e[12]=t[0]*n+t[4]*o+t[8]*i+t[12],e[13]=t[1]*n+t[5]*o+t[9]*i+t[13],e[14]=t[2]*n+t[6]*o+t[10]*i+t[14],e[15]=t[3]*n+t[7]*o+t[11]*i+t[15]):(a=t[0],s=t[1],l=t[2],c=t[3],f=t[4],p=t[5],u=t[6],h=t[7],g=t[8],S=t[9],x=t[10],_=t[11],e[0]=a,e[1]=s,e[2]=l,e[3]=c,e[4]=f,e[5]=p,e[6]=u,e[7]=h,e[8]=g,e[9]=S,e[10]=x,e[11]=_,e[12]=a*n+f*o+g*i+t[12],e[13]=s*n+p*o+S*i+t[13],e[14]=l*n+u*o+x*i+t[14],e[15]=c*n+h*o+_*i+t[15]),e}function ir(e,t,r){let n=r[0],o=r[1],i=r[2];return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*o,e[5]=t[5]*o,e[6]=t[6]*o,e[7]=t[7]*o,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function ar(e,t,r,n){let o=n[0],i=n[1],a=n[2],s=Math.sqrt(o*o+i*i+a*a),l,c,f,p,u,h,g,S,x,_,L,d,b,v,m,M,E,A,C,P,I,O,R,Z;return s<1e-6?null:(s=1/s,o*=s,i*=s,a*=s,c=Math.sin(r),l=Math.cos(r),f=1-l,p=t[0],u=t[1],h=t[2],g=t[3],S=t[4],x=t[5],_=t[6],L=t[7],d=t[8],b=t[9],v=t[10],m=t[11],M=o*o*f+l,E=i*o*f+a*c,A=a*o*f-i*c,C=o*i*f-a*c,P=i*i*f+l,I=a*i*f+o*c,O=o*a*f+i*c,R=i*a*f-o*c,Z=a*a*f+l,e[0]=p*M+S*E+d*A,e[1]=u*M+x*E+b*A,e[2]=h*M+_*E+v*A,e[3]=g*M+L*E+m*A,e[4]=p*C+S*P+d*I,e[5]=u*C+x*P+b*I,e[6]=h*C+_*P+v*I,e[7]=g*C+L*P+m*I,e[8]=p*O+S*R+d*Z,e[9]=u*O+x*R+b*Z,e[10]=h*O+_*R+v*Z,e[11]=g*O+L*R+m*Z,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function sr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[4],a=t[5],s=t[6],l=t[7],c=t[8],f=t[9],p=t[10],u=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*o+c*n,e[5]=a*o+f*n,e[6]=s*o+p*n,e[7]=l*o+u*n,e[8]=c*o-i*n,e[9]=f*o-a*n,e[10]=p*o-s*n,e[11]=u*o-l*n,e}function lr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[0],a=t[1],s=t[2],l=t[3],c=t[8],f=t[9],p=t[10],u=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o-c*n,e[1]=a*o-f*n,e[2]=s*o-p*n,e[3]=l*o-u*n,e[8]=i*n+c*o,e[9]=a*n+f*o,e[10]=s*n+p*o,e[11]=l*n+u*o,e}function cr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[0],a=t[1],s=t[2],l=t[3],c=t[4],f=t[5],p=t[6],u=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o+c*n,e[1]=a*o+f*n,e[2]=s*o+p*n,e[3]=l*o+u*n,e[4]=c*o-i*n,e[5]=f*o-a*n,e[6]=p*o-s*n,e[7]=u*o-l*n,e}function fr(e,t){let r=t[0],n=t[1],o=t[2],i=t[3],a=r+r,s=n+n,l=o+o,c=r*a,f=n*a,p=n*s,u=o*a,h=o*s,g=o*l,S=i*a,x=i*s,_=i*l;return e[0]=1-p-g,e[1]=f+_,e[2]=u-x,e[3]=0,e[4]=f-_,e[5]=1-c-g,e[6]=h+S,e[7]=0,e[8]=u+x,e[9]=h-S,e[10]=1-c-p,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function pr(e,t,r,n,o,i,a){let s=1/(r-t),l=1/(o-n),c=1/(i-a);return e[0]=i*2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i*2*l,e[6]=0,e[7]=0,e[8]=(r+t)*s,e[9]=(o+n)*l,e[10]=(a+i)*c,e[11]=-1,e[12]=0,e[13]=0,e[14]=a*i*2*c,e[15]=0,e}function fo(e,t,r,n,o){let i=1/Math.tan(t/2);if(e[0]=i/r,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,o!=null&&o!==1/0){let a=1/(n-o);e[10]=(o+n)*a,e[14]=2*o*n*a}else e[10]=-1,e[14]=-2*n;return e}var ur=fo;function po(e,t,r,n,o,i,a){let s=1/(t-r),l=1/(n-o),c=1/(i-a);return e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*l,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*c,e[11]=0,e[12]=(t+r)*s,e[13]=(o+n)*l,e[14]=(a+i)*c,e[15]=1,e}var hr=po;function mr(e,t,r,n){let o,i,a,s,l,c,f,p,u,h,g=t[0],S=t[1],x=t[2],_=n[0],L=n[1],d=n[2],b=r[0],v=r[1],m=r[2];return Math.abs(g-b)<1e-6&&Math.abs(S-v)<1e-6&&Math.abs(x-m)<1e-6?co(e):(p=g-b,u=S-v,h=x-m,o=1/Math.sqrt(p*p+u*u+h*h),p*=o,u*=o,h*=o,i=L*h-d*u,a=d*p-_*h,s=_*u-L*p,o=Math.sqrt(i*i+a*a+s*s),o?(o=1/o,i*=o,a*=o,s*=o):(i=0,a=0,s=0),l=u*s-h*a,c=h*i-p*s,f=p*a-u*i,o=Math.sqrt(l*l+c*c+f*f),o?(o=1/o,l*=o,c*=o,f*=o):(l=0,c=0,f=0),e[0]=i,e[1]=l,e[2]=p,e[3]=0,e[4]=a,e[5]=c,e[6]=u,e[7]=0,e[8]=s,e[9]=f,e[10]=h,e[11]=0,e[12]=-(i*g+a*S+s*x),e[13]=-(l*g+c*S+f*x),e[14]=-(p*g+u*S+h*x),e[15]=1,e)}function uo(){let e=new w(4);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function gr(e,t,r){let n=t[0],o=t[1],i=t[2],a=t[3];return e[0]=r[0]*n+r[4]*o+r[8]*i+r[12]*a,e[1]=r[1]*n+r[5]*o+r[9]*i+r[13]*a,e[2]=r[2]*n+r[6]*o+r[10]*i+r[14]*a,e[3]=r[3]*n+r[7]*o+r[11]*i+r[15]*a,e}var aa=function(){let e=uo();return function(t,r,n,o,i,a){let s,l;for(r||(r=4),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],e[3]=t[s+3],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2],t[s+3]=e[3];return t}}();var nt;(function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL0ROW3=3]="COL0ROW3",e[e.COL1ROW0=4]="COL1ROW0",e[e.COL1ROW1=5]="COL1ROW1",e[e.COL1ROW2=6]="COL1ROW2",e[e.COL1ROW3=7]="COL1ROW3",e[e.COL2ROW0=8]="COL2ROW0",e[e.COL2ROW1=9]="COL2ROW1",e[e.COL2ROW2=10]="COL2ROW2",e[e.COL2ROW3=11]="COL2ROW3",e[e.COL3ROW0=12]="COL3ROW0",e[e.COL3ROW1=13]="COL3ROW1",e[e.COL3ROW2=14]="COL3ROW2",e[e.COL3ROW3=15]="COL3ROW3"})(nt||(nt={}));var ho=45*Math.PI/180,mo=1,tt=.1,rt=500,go=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),D=class extends Ce{static get IDENTITY(){return bo()}static get ZERO(){return _o()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return nt}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,r,n,o,i,a,s,l,c,f,p,u,h,g,S,x){return this[0]=t,this[1]=r,this[2]=n,this[3]=o,this[4]=i,this[5]=a,this[6]=s,this[7]=l,this[8]=c,this[9]=f,this[10]=p,this[11]=u,this[12]=h,this[13]=g,this[14]=S,this[15]=x,this.check()}setRowMajor(t,r,n,o,i,a,s,l,c,f,p,u,h,g,S,x){return this[0]=t,this[1]=i,this[2]=c,this[3]=h,this[4]=r,this[5]=a,this[6]=f,this[7]=g,this[8]=n,this[9]=s,this[10]=p,this[11]=S,this[12]=o,this[13]=l,this[14]=u,this[15]=x,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(go)}fromObject(t){return this.check()}fromQuaternion(t){return fr(this,t),this.check()}frustum(t){let{left:r,right:n,bottom:o,top:i,near:a=tt,far:s=rt}=t;return s===1/0?vo(this,r,n,o,i,a):pr(this,r,n,o,i,a,s),this.check()}lookAt(t){let{eye:r,center:n=[0,0,0],up:o=[0,1,0]}=t;return mr(this,r,n,o),this.check()}ortho(t){let{left:r,right:n,bottom:o,top:i,near:a=tt,far:s=rt}=t;return hr(this,r,n,o,i,a,s),this.check()}orthographic(t){let{fovy:r=ho,aspect:n=mo,focalDistance:o=1,near:i=tt,far:a=rt}=t;dr(r);let s=r/2,l=o*Math.tan(s),c=l*n;return this.ortho({left:-c,right:c,bottom:-l,top:l,near:i,far:a})}perspective(t){let{fovy:r=45*Math.PI/180,aspect:n=1,near:o=.1,far:i=500}=t;return dr(r),ur(this,r,n,o,i),this.check()}determinant(){return nr(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,r){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=0,t[4]=this[4]*o,t[5]=this[5]*i,t[6]=this[6]*a,t[7]=0,t[8]=this[8]*o,t[9]=this[9]*i,t[10]=this[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,r){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=this[4]*o,t[4]=this[5]*i,t[5]=this[6]*a,t[6]=this[8]*o,t[7]=this[9]*i,t[8]=this[10]*a,t}transpose(){return tr(this,this),this.check()}invert(){return rr(this,this),this.check()}multiplyLeft(t){return et(this,t,this),this.check()}multiplyRight(t){return et(this,this,t),this.check()}rotateX(t){return sr(this,this,t),this.check()}rotateY(t){return lr(this,this,t),this.check()}rotateZ(t){return cr(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,r){return ar(this,this,t,r),this.check()}scale(t){return ir(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return or(this,this,t),this.check()}transform(t,r){return t.length===4?(r=gr(r||[-0,-0,-0,-0],t,this),Ee(r,4),r):this.transformAsPoint(t,r)}transformAsPoint(t,r){let{length:n}=t,o;switch(n){case 2:o=Zt(r||[-0,-0],t,this);break;case 3:o=er(r||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ee(o,t.length),o}transformAsVector(t,r){let n;switch(t.length){case 2:n=Qt(r||[-0,-0],t,this);break;case 3:n=Jt(r||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ee(n,t.length),n}transformPoint(t,r){return this.transformAsPoint(t,r)}transformVector(t,r){return this.transformAsPoint(t,r)}transformDirection(t,r){return this.transformAsVector(t,r)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,r,n){return this.identity().translate([t,r,n])}},Ie,ye;function _o(){return Ie||(Ie=new D([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Ie)),Ie}function bo(){return ye||(ye=new D,Object.freeze(ye)),ye}function dr(e){if(e>Math.PI*2)throw Error("expected radians")}function vo(e,t,r,n,o,i){let a=2*i/(r-t),s=2*i/(o-n),l=(r+t)/(r-t),c=(o+n)/(o-n),f=-1,p=-1,u=-2*i;return e[0]=a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=l,e[9]=c,e[10]=f,e[11]=p,e[12]=0,e[13]=0,e[14]=u,e[15]=0,e}var H=null,_r=new ArrayBuffer(4),br=new Float32Array(_r),vr=new Uint32Array(_r);function Sr(e){H||=Mr(),e=Qe(e,-65504,65504),br[0]=e;let t=vr[0],r=t>>23&511;return H.baseTable[r]+((t&8388607)>>H.shiftTable[r])}function xr(e){H||=Mr();let t=e>>10;return vr[0]=H.mantissaTable[H.offsetTable[t]+(e&1023)]+H.exponentTable[t],br[0]}function Mr(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let i=0;i<256;++i){let a=i-127;a<-27?(e[i]=0,e[i|256]=32768,t[i]=24,t[i|256]=24):a<-14?(e[i]=1024>>-a-14,e[i|256]=1024>>-a-14|32768,t[i]=-a-1,t[i|256]=-a-1):a<=15?(e[i]=a+15<<10,e[i|256]=a+15<<10|32768,t[i]=13,t[i|256]=13):a<128?(e[i]=31744,e[i|256]=64512,t[i]=24,t[i|256]=24):(e[i]=31744,e[i|256]=64512,t[i]=13,t[i|256]=13)}let r=new Uint32Array(2048),n=new Uint32Array(64),o=new Uint32Array(64);for(let i=1;i<1024;++i){let a=i<<13,s=0;for(;!(a&8388608);)a<<=1,s-=8388608;a&=-8388609,s+=947912704,r[i]=a|s}for(let i=1024;i<2048;++i)r[i]=939524096+(i-1024<<13);for(let i=1;i<31;++i)n[i]=i<<23;n[31]=1199570944,n[32]=2147483648;for(let i=33;i<63;++i)n[i]=2147483648+(i-32<<23);n[63]=3347054592;for(let i=1;i<64;++i)i!==32&&(o[i]=1024);return{baseTable:e,shiftTable:t,mantissaTable:r,exponentTable:n,offsetTable:o}}function X(e,t=[],r=0){let n=Math.fround(e),o=e-n;return t[r]=n,t[r+1]=o,t}function ae(e){return e-Math.fround(e)}function se(e){let t=new Float32Array(32);for(let r=0;r<4;++r)for(let n=0;n<4;++n){let o=r*4+n;X(e[n*4+r],t,o*2)}return t}function V(e,t=!0){return e??t}function k(e=[0,0,0],t=!0){return t?e.map(r=>r/255):[...e]}function Ne(e,t=!0){let r=k(e.slice(0,3),t),n=Number.isFinite(e[3]),o=n?e[3]:1;return[r[0],r[1],r[2],t&&n?o/255:o]}var So=`fn random(scale: vec3f, seed: f32) -> f32 {
|
|
102
|
+
}`}function $t(e){switch(e){case"float":return"x";case"vec2":return"xy";case"vec3":return"xyz";case"vec4":return"xyzw";default:throw new Error(e)}}function Wt(e){switch(e){case"float":return 1;case"vec2":return 2;case"vec3":return 3;case"vec4":return 4;default:throw new Error(e)}}function Qn(e){switch(e){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${e}`)}}function Ze(e,t){switch(t){case 1:return`vec4(${e}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${e}, 0.0, 1.0)`;case 3:return`vec4(${e}, 1.0)`;case 4:return e;default:throw new Error(`invalid channels: ${t}`)}}function D(e){return typeof e=="string"?e.charAt(0).toUpperCase()+e.slice(1):e}function jt(e,t){return Jn(e,t)}function Jn(e,t){let r=[];switch(t.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":r.push(`layout(std140) uniform ${D(e.name)} {`);break;case"uniforms":}for(let[n,o]of Object.entries(e.uniformTypes||{})){if(typeof o!="string")throw new Error(`Composite uniform types are not supported by GLSL shader generation: ${e.name}.${n}`);let i=eo(o);switch(t.uniforms){case"scoped-interface-blocks":r.push(` ${i} ${n};`);break;case"unscoped-interface-blocks":r.push(` ${i} ${e.name}_${n};`);break;case"uniforms":r.push(`uniform ${i} ${e.name}_${n};`)}}switch(t.uniforms){case"scoped-interface-blocks":r.push(`} ${e.name};`);break;case"unscoped-interface-blocks":r.push("};");break;case"uniforms":}return r.push(""),r.join(`
|
|
103
|
+
`)}function eo(e){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"}[e]}function qt(e,t){return to(e,t)}function to(e,t){let r=[];r.push(`struct ${D(e.name)} {`);for(let[n,o]of Object.entries(e?.uniformTypes||{})){if(typeof o!="string")throw new Error(`Composite uniform types are not supported by WGSL shader generation: ${e.name}.${n}`);let i=o;r.push(` ${n} : ${i};`)}return r.push("};"),r.push(`var<uniform> ${e.name} : ${D(e.name)};`),r.join(`
|
|
104
|
+
`)}function Kt(e,t){switch(t.shaderLanguage){case"glsl":return jt(e,t);case"wgsl":return qt(e,t)}}var $i=1/Math.PI*180,Wi=1/180*Math.PI,ro={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...ro}};var y=globalThis.mathgl.config;function Qe(e,{precision:t=y.precision}={}){return e=no(e),`${parseFloat(e.toPrecision(t))}`}function j(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Je(e,t,r){return io(e,n=>Math.max(t,Math.min(r,n)))}function Re(e,t,r){let n=y.EPSILON;r&&(y.EPSILON=r);try{if(e===t)return!0;if(j(e)&&j(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(!Re(e[o],t[o]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=y.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{y.EPSILON=n}}function no(e){return Math.round(e/y.EPSILON)*y.EPSILON}function oo(e){return e.clone?e.clone():new Array(e.length)}function io(e,t,r){if(j(e)){let n=e;r=r||oo(n);for(let o=0;o<r.length&&o<n.length;++o){let i=typeof e=="number"?e:e[o];r[o]=t(i,o,r)}return r}return t(e)}var Ee=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,r=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+r];return this.check()}toArray(t=[],r=0){for(let n=0;n<this.ELEMENTS;++n)t[r+n]=this[n];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:j(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(y)}formatString(t){let r="";for(let n=0;n<this.ELEMENTS;++n)r+=(n>0?", ":"")+Qe(this[n],t);return`${t.printTypes?this.constructor.name:""}[${r}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(!Re(this[r],t[r]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(this[r]!==t[r])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,r,n){if(n===void 0)return this.lerp(this,t,r);for(let o=0;o<this.ELEMENTS;++o){let i=t[o],a=typeof r=="number"?r:r[o];this[o]=i+n*(a-i)}return this.check()}min(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(t[r],this[r]);return this.check()}max(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.max(t[r],this[r]);return this.check()}clamp(t,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),r[n]);return this.check()}add(...t){for(let r of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=r[n];return this.check()}subtract(...t){for(let r of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=r[n];return this.check()}scale(t){if(typeof t=="number")for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;else for(let r=0;r<this.ELEMENTS&&r<t.length;++r)this[r]*=t[r];return this.check()}multiplyByScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;return this.check()}check(){if(y.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let r=0;r<this.ELEMENTS;++r)t=t&&Number.isFinite(this[r]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=t;return this.check()}addScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t),r);return this.check()}get elements(){return this}};function ao(e,t){if(e.length!==t)return!1;for(let r=0;r<e.length;++r)if(!Number.isFinite(e[r]))return!1;return!0}function Yt(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Ie(e,t,r=""){if(y.debug&&!ao(e,t))throw new Error(`math.gl: ${r} some fields set to invalid numbers'`);return e}var w=typeof Float32Array<"u"?Float32Array:Array;var Zi=Math.PI/180;function so(){let e=new w(2);return w!=Float32Array&&(e[0]=0,e[1]=0),e}function Qt(e,t,r){let n=t[0],o=t[1];return e[0]=r[0]*n+r[4]*o+r[12],e[1]=r[1]*n+r[5]*o+r[13],e}var Qi=function(){let e=so();return function(t,r,n,o,i,a){let s,l;for(r||(r=2),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],i(e,e,a),t[s]=e[0],t[s+1]=e[1];return t}}();function Jt(e,t,r){let n=t[0],o=t[1],i=r[3]*n+r[7]*o||1;return e[0]=(r[0]*n+r[4]*o)/i,e[1]=(r[1]*n+r[5]*o)/i,e}function er(e,t,r){let n=t[0],o=t[1],i=t[2],a=r[3]*n+r[7]*o+r[11]*i||1;return e[0]=(r[0]*n+r[4]*o+r[8]*i)/a,e[1]=(r[1]*n+r[5]*o+r[9]*i)/a,e[2]=(r[2]*n+r[6]*o+r[10]*i)/a,e}function lo(){let e=new w(3);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function tr(e,t,r){let n=t[0],o=t[1],i=t[2],a=r[3]*n+r[7]*o+r[11]*i+r[15];return a=a||1,e[0]=(r[0]*n+r[4]*o+r[8]*i+r[12])/a,e[1]=(r[1]*n+r[5]*o+r[9]*i+r[13])/a,e[2]=(r[2]*n+r[6]*o+r[10]*i+r[14])/a,e}var ta=function(){let e=lo();return function(t,r,n,o,i,a){let s,l;for(r||(r=3),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2];return t}}();var Ce=class extends Ee{toString(){let t="[";if(y.printRowMajor){t+="row-major:";for(let r=0;r<this.RANK;++r)for(let n=0;n<this.RANK;++n)t+=` ${this[n*this.RANK+r]}`}else{t+="column-major:";for(let r=0;r<this.ELEMENTS;++r)t+=` ${this[r]}`}return t+="]",t}getElementIndex(t,r){return r*this.RANK+t}getElement(t,r){return this[r*this.RANK+t]}setElement(t,r,n){return this[r*this.RANK+t]=Yt(n),this}getColumn(t,r=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let o=0;o<this.RANK;++o)r[o]=this[n+o];return r}setColumn(t,r){let n=t*this.RANK;for(let o=0;o<this.RANK;++o)this[n+o]=r[o];return this}};function co(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function rr(e,t){if(e===t){let r=t[1],n=t[2],o=t[3],i=t[6],a=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=r,e[6]=t[9],e[7]=t[13],e[8]=n,e[9]=i,e[11]=t[14],e[12]=o,e[13]=a,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function nr(e,t){let r=t[0],n=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],f=t[8],p=t[9],u=t[10],h=t[11],g=t[12],S=t[13],x=t[14],_=t[15],L=r*s-n*a,d=r*l-o*a,b=r*c-i*a,v=n*l-o*s,m=n*c-i*s,M=o*c-i*l,E=f*S-p*g,A=f*x-u*g,I=f*_-h*g,P=p*x-u*S,C=p*_-h*S,O=u*_-h*x,R=L*O-d*C+b*P+v*I-m*A+M*E;return R?(R=1/R,e[0]=(s*O-l*C+c*P)*R,e[1]=(o*C-n*O-i*P)*R,e[2]=(S*M-x*m+_*v)*R,e[3]=(u*m-p*M-h*v)*R,e[4]=(l*I-a*O-c*A)*R,e[5]=(r*O-o*I+i*A)*R,e[6]=(x*b-g*M-_*d)*R,e[7]=(f*M-u*b+h*d)*R,e[8]=(a*C-s*I+c*E)*R,e[9]=(n*I-r*C-i*E)*R,e[10]=(g*m-S*b+_*L)*R,e[11]=(p*b-f*m-h*L)*R,e[12]=(s*A-a*P-l*E)*R,e[13]=(r*P-n*A+o*E)*R,e[14]=(S*d-g*v-x*L)*R,e[15]=(f*v-p*d+u*L)*R,e):null}function or(e){let t=e[0],r=e[1],n=e[2],o=e[3],i=e[4],a=e[5],s=e[6],l=e[7],c=e[8],f=e[9],p=e[10],u=e[11],h=e[12],g=e[13],S=e[14],x=e[15],_=t*a-r*i,L=t*s-n*i,d=r*s-n*a,b=c*g-f*h,v=c*S-p*h,m=f*S-p*g,M=t*m-r*v+n*b,E=i*m-a*v+s*b,A=c*d-f*L+p*_,I=h*d-g*L+S*_;return l*M-o*E+x*A-u*I}function tt(e,t,r){let n=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],f=t[7],p=t[8],u=t[9],h=t[10],g=t[11],S=t[12],x=t[13],_=t[14],L=t[15],d=r[0],b=r[1],v=r[2],m=r[3];return e[0]=d*n+b*s+v*p+m*S,e[1]=d*o+b*l+v*u+m*x,e[2]=d*i+b*c+v*h+m*_,e[3]=d*a+b*f+v*g+m*L,d=r[4],b=r[5],v=r[6],m=r[7],e[4]=d*n+b*s+v*p+m*S,e[5]=d*o+b*l+v*u+m*x,e[6]=d*i+b*c+v*h+m*_,e[7]=d*a+b*f+v*g+m*L,d=r[8],b=r[9],v=r[10],m=r[11],e[8]=d*n+b*s+v*p+m*S,e[9]=d*o+b*l+v*u+m*x,e[10]=d*i+b*c+v*h+m*_,e[11]=d*a+b*f+v*g+m*L,d=r[12],b=r[13],v=r[14],m=r[15],e[12]=d*n+b*s+v*p+m*S,e[13]=d*o+b*l+v*u+m*x,e[14]=d*i+b*c+v*h+m*_,e[15]=d*a+b*f+v*g+m*L,e}function ir(e,t,r){let n=r[0],o=r[1],i=r[2],a,s,l,c,f,p,u,h,g,S,x,_;return t===e?(e[12]=t[0]*n+t[4]*o+t[8]*i+t[12],e[13]=t[1]*n+t[5]*o+t[9]*i+t[13],e[14]=t[2]*n+t[6]*o+t[10]*i+t[14],e[15]=t[3]*n+t[7]*o+t[11]*i+t[15]):(a=t[0],s=t[1],l=t[2],c=t[3],f=t[4],p=t[5],u=t[6],h=t[7],g=t[8],S=t[9],x=t[10],_=t[11],e[0]=a,e[1]=s,e[2]=l,e[3]=c,e[4]=f,e[5]=p,e[6]=u,e[7]=h,e[8]=g,e[9]=S,e[10]=x,e[11]=_,e[12]=a*n+f*o+g*i+t[12],e[13]=s*n+p*o+S*i+t[13],e[14]=l*n+u*o+x*i+t[14],e[15]=c*n+h*o+_*i+t[15]),e}function ar(e,t,r){let n=r[0],o=r[1],i=r[2];return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*o,e[5]=t[5]*o,e[6]=t[6]*o,e[7]=t[7]*o,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function sr(e,t,r,n){let o=n[0],i=n[1],a=n[2],s=Math.sqrt(o*o+i*i+a*a),l,c,f,p,u,h,g,S,x,_,L,d,b,v,m,M,E,A,I,P,C,O,R,Z;return s<1e-6?null:(s=1/s,o*=s,i*=s,a*=s,c=Math.sin(r),l=Math.cos(r),f=1-l,p=t[0],u=t[1],h=t[2],g=t[3],S=t[4],x=t[5],_=t[6],L=t[7],d=t[8],b=t[9],v=t[10],m=t[11],M=o*o*f+l,E=i*o*f+a*c,A=a*o*f-i*c,I=o*i*f-a*c,P=i*i*f+l,C=a*i*f+o*c,O=o*a*f+i*c,R=i*a*f-o*c,Z=a*a*f+l,e[0]=p*M+S*E+d*A,e[1]=u*M+x*E+b*A,e[2]=h*M+_*E+v*A,e[3]=g*M+L*E+m*A,e[4]=p*I+S*P+d*C,e[5]=u*I+x*P+b*C,e[6]=h*I+_*P+v*C,e[7]=g*I+L*P+m*C,e[8]=p*O+S*R+d*Z,e[9]=u*O+x*R+b*Z,e[10]=h*O+_*R+v*Z,e[11]=g*O+L*R+m*Z,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function lr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[4],a=t[5],s=t[6],l=t[7],c=t[8],f=t[9],p=t[10],u=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*o+c*n,e[5]=a*o+f*n,e[6]=s*o+p*n,e[7]=l*o+u*n,e[8]=c*o-i*n,e[9]=f*o-a*n,e[10]=p*o-s*n,e[11]=u*o-l*n,e}function cr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[0],a=t[1],s=t[2],l=t[3],c=t[8],f=t[9],p=t[10],u=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o-c*n,e[1]=a*o-f*n,e[2]=s*o-p*n,e[3]=l*o-u*n,e[8]=i*n+c*o,e[9]=a*n+f*o,e[10]=s*n+p*o,e[11]=l*n+u*o,e}function fr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[0],a=t[1],s=t[2],l=t[3],c=t[4],f=t[5],p=t[6],u=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o+c*n,e[1]=a*o+f*n,e[2]=s*o+p*n,e[3]=l*o+u*n,e[4]=c*o-i*n,e[5]=f*o-a*n,e[6]=p*o-s*n,e[7]=u*o-l*n,e}function pr(e,t){let r=t[0],n=t[1],o=t[2],i=t[3],a=r+r,s=n+n,l=o+o,c=r*a,f=n*a,p=n*s,u=o*a,h=o*s,g=o*l,S=i*a,x=i*s,_=i*l;return e[0]=1-p-g,e[1]=f+_,e[2]=u-x,e[3]=0,e[4]=f-_,e[5]=1-c-g,e[6]=h+S,e[7]=0,e[8]=u+x,e[9]=h-S,e[10]=1-c-p,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function ur(e,t,r,n,o,i,a){let s=1/(r-t),l=1/(o-n),c=1/(i-a);return e[0]=i*2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i*2*l,e[6]=0,e[7]=0,e[8]=(r+t)*s,e[9]=(o+n)*l,e[10]=(a+i)*c,e[11]=-1,e[12]=0,e[13]=0,e[14]=a*i*2*c,e[15]=0,e}function fo(e,t,r,n,o){let i=1/Math.tan(t/2);if(e[0]=i/r,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,o!=null&&o!==1/0){let a=1/(n-o);e[10]=(o+n)*a,e[14]=2*o*n*a}else e[10]=-1,e[14]=-2*n;return e}var hr=fo;function po(e,t,r,n,o,i,a){let s=1/(t-r),l=1/(n-o),c=1/(i-a);return e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*l,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*c,e[11]=0,e[12]=(t+r)*s,e[13]=(o+n)*l,e[14]=(a+i)*c,e[15]=1,e}var mr=po;function gr(e,t,r,n){let o,i,a,s,l,c,f,p,u,h,g=t[0],S=t[1],x=t[2],_=n[0],L=n[1],d=n[2],b=r[0],v=r[1],m=r[2];return Math.abs(g-b)<1e-6&&Math.abs(S-v)<1e-6&&Math.abs(x-m)<1e-6?co(e):(p=g-b,u=S-v,h=x-m,o=1/Math.sqrt(p*p+u*u+h*h),p*=o,u*=o,h*=o,i=L*h-d*u,a=d*p-_*h,s=_*u-L*p,o=Math.sqrt(i*i+a*a+s*s),o?(o=1/o,i*=o,a*=o,s*=o):(i=0,a=0,s=0),l=u*s-h*a,c=h*i-p*s,f=p*a-u*i,o=Math.sqrt(l*l+c*c+f*f),o?(o=1/o,l*=o,c*=o,f*=o):(l=0,c=0,f=0),e[0]=i,e[1]=l,e[2]=p,e[3]=0,e[4]=a,e[5]=c,e[6]=u,e[7]=0,e[8]=s,e[9]=f,e[10]=h,e[11]=0,e[12]=-(i*g+a*S+s*x),e[13]=-(l*g+c*S+f*x),e[14]=-(p*g+u*S+h*x),e[15]=1,e)}function uo(){let e=new w(4);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function dr(e,t,r){let n=t[0],o=t[1],i=t[2],a=t[3];return e[0]=r[0]*n+r[4]*o+r[8]*i+r[12]*a,e[1]=r[1]*n+r[5]*o+r[9]*i+r[13]*a,e[2]=r[2]*n+r[6]*o+r[10]*i+r[14]*a,e[3]=r[3]*n+r[7]*o+r[11]*i+r[15]*a,e}var la=function(){let e=uo();return function(t,r,n,o,i,a){let s,l;for(r||(r=4),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],e[3]=t[s+3],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2],t[s+3]=e[3];return t}}();var ot;(function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL0ROW3=3]="COL0ROW3",e[e.COL1ROW0=4]="COL1ROW0",e[e.COL1ROW1=5]="COL1ROW1",e[e.COL1ROW2=6]="COL1ROW2",e[e.COL1ROW3=7]="COL1ROW3",e[e.COL2ROW0=8]="COL2ROW0",e[e.COL2ROW1=9]="COL2ROW1",e[e.COL2ROW2=10]="COL2ROW2",e[e.COL2ROW3=11]="COL2ROW3",e[e.COL3ROW0=12]="COL3ROW0",e[e.COL3ROW1=13]="COL3ROW1",e[e.COL3ROW2=14]="COL3ROW2",e[e.COL3ROW3=15]="COL3ROW3"})(ot||(ot={}));var ho=45*Math.PI/180,mo=1,rt=.1,nt=500,go=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),B=class extends Ce{static get IDENTITY(){return bo()}static get ZERO(){return _o()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return ot}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,r,n,o,i,a,s,l,c,f,p,u,h,g,S,x){return this[0]=t,this[1]=r,this[2]=n,this[3]=o,this[4]=i,this[5]=a,this[6]=s,this[7]=l,this[8]=c,this[9]=f,this[10]=p,this[11]=u,this[12]=h,this[13]=g,this[14]=S,this[15]=x,this.check()}setRowMajor(t,r,n,o,i,a,s,l,c,f,p,u,h,g,S,x){return this[0]=t,this[1]=i,this[2]=c,this[3]=h,this[4]=r,this[5]=a,this[6]=f,this[7]=g,this[8]=n,this[9]=s,this[10]=p,this[11]=S,this[12]=o,this[13]=l,this[14]=u,this[15]=x,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(go)}fromObject(t){return this.check()}fromQuaternion(t){return pr(this,t),this.check()}frustum(t){let{left:r,right:n,bottom:o,top:i,near:a=rt,far:s=nt}=t;return s===1/0?vo(this,r,n,o,i,a):ur(this,r,n,o,i,a,s),this.check()}lookAt(t){let{eye:r,center:n=[0,0,0],up:o=[0,1,0]}=t;return gr(this,r,n,o),this.check()}ortho(t){let{left:r,right:n,bottom:o,top:i,near:a=rt,far:s=nt}=t;return mr(this,r,n,o,i,a,s),this.check()}orthographic(t){let{fovy:r=ho,aspect:n=mo,focalDistance:o=1,near:i=rt,far:a=nt}=t;_r(r);let s=r/2,l=o*Math.tan(s),c=l*n;return this.ortho({left:-c,right:c,bottom:-l,top:l,near:i,far:a})}perspective(t){let{fovy:r=45*Math.PI/180,aspect:n=1,near:o=.1,far:i=500}=t;return _r(r),hr(this,r,n,o,i),this.check()}determinant(){return or(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,r){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=0,t[4]=this[4]*o,t[5]=this[5]*i,t[6]=this[6]*a,t[7]=0,t[8]=this[8]*o,t[9]=this[9]*i,t[10]=this[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,r){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=this[4]*o,t[4]=this[5]*i,t[5]=this[6]*a,t[6]=this[8]*o,t[7]=this[9]*i,t[8]=this[10]*a,t}transpose(){return rr(this,this),this.check()}invert(){return nr(this,this),this.check()}multiplyLeft(t){return tt(this,t,this),this.check()}multiplyRight(t){return tt(this,this,t),this.check()}rotateX(t){return lr(this,this,t),this.check()}rotateY(t){return cr(this,this,t),this.check()}rotateZ(t){return fr(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,r){return sr(this,this,t,r),this.check()}scale(t){return ar(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return ir(this,this,t),this.check()}transform(t,r){return t.length===4?(r=dr(r||[-0,-0,-0,-0],t,this),Ie(r,4),r):this.transformAsPoint(t,r)}transformAsPoint(t,r){let{length:n}=t,o;switch(n){case 2:o=Qt(r||[-0,-0],t,this);break;case 3:o=tr(r||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ie(o,t.length),o}transformAsVector(t,r){let n;switch(t.length){case 2:n=Jt(r||[-0,-0],t,this);break;case 3:n=er(r||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ie(n,t.length),n}transformPoint(t,r){return this.transformAsPoint(t,r)}transformVector(t,r){return this.transformAsPoint(t,r)}transformDirection(t,r){return this.transformAsVector(t,r)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,r,n){return this.identity().translate([t,r,n])}},ye,Ne;function _o(){return ye||(ye=new B([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(ye)),ye}function bo(){return Ne||(Ne=new B,Object.freeze(Ne)),Ne}function _r(e){if(e>Math.PI*2)throw Error("expected radians")}function vo(e,t,r,n,o,i){let a=2*i/(r-t),s=2*i/(o-n),l=(r+t)/(r-t),c=(o+n)/(o-n),f=-1,p=-1,u=-2*i;return e[0]=a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=l,e[9]=c,e[10]=f,e[11]=p,e[12]=0,e[13]=0,e[14]=u,e[15]=0,e}var z=null,br=new ArrayBuffer(4),vr=new Float32Array(br),Sr=new Uint32Array(br);function xr(e){z||=Lr(),e=Je(e,-65504,65504),vr[0]=e;let t=Sr[0],r=t>>23&511;return z.baseTable[r]+((t&8388607)>>z.shiftTable[r])}function Mr(e){z||=Lr();let t=e>>10;return Sr[0]=z.mantissaTable[z.offsetTable[t]+(e&1023)]+z.exponentTable[t],vr[0]}function Lr(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let i=0;i<256;++i){let a=i-127;a<-27?(e[i]=0,e[i|256]=32768,t[i]=24,t[i|256]=24):a<-14?(e[i]=1024>>-a-14,e[i|256]=1024>>-a-14|32768,t[i]=-a-1,t[i|256]=-a-1):a<=15?(e[i]=a+15<<10,e[i|256]=a+15<<10|32768,t[i]=13,t[i|256]=13):a<128?(e[i]=31744,e[i|256]=64512,t[i]=24,t[i|256]=24):(e[i]=31744,e[i|256]=64512,t[i]=13,t[i|256]=13)}let r=new Uint32Array(2048),n=new Uint32Array(64),o=new Uint32Array(64);for(let i=1;i<1024;++i){let a=i<<13,s=0;for(;!(a&8388608);)a<<=1,s-=8388608;a&=-8388609,s+=947912704,r[i]=a|s}for(let i=1024;i<2048;++i)r[i]=939524096+(i-1024<<13);for(let i=1;i<31;++i)n[i]=i<<23;n[31]=1199570944,n[32]=2147483648;for(let i=33;i<63;++i)n[i]=2147483648+(i-32<<23);n[63]=3347054592;for(let i=1;i<64;++i)i!==32&&(o[i]=1024);return{baseTable:e,shiftTable:t,mantissaTable:r,exponentTable:n,offsetTable:o}}function K(e,t=[],r=0){let n=Math.fround(e),o=e-n;return t[r]=n,t[r+1]=o,t}function ae(e){return e-Math.fround(e)}function se(e){let t=new Float32Array(32);for(let r=0;r<4;++r)for(let n=0;n<4;++n){let o=r*4+n;K(e[n*4+r],t,o*2)}return t}function Y(e,t=!0){return e??t}function le(e=[0,0,0],t=!0){return t?e.map(r=>r/255):[...e]}function Pe(e,t=!0){let r=le(e.slice(0,3),t),n=Number.isFinite(e[3]),o=n?e[3]:1;return[r[0],r[1],r[2],t&&n?o/255:o]}var So=`fn random(scale: vec3f, seed: f32) -> f32 {
|
|
105
105
|
return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
|
|
106
106
|
}
|
|
107
107
|
`,xo=`float random(vec3 scale, float seed) {
|
|
108
108
|
/* use the fragment position for a different seed per-pixel */
|
|
109
109
|
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
110
110
|
}
|
|
111
|
-
`,
|
|
111
|
+
`,Ar={name:"random",source:So,fs:xo};var Mo=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
112
112
|
|
|
113
113
|
// All these functions are for substituting tan() function from Intel GPU only
|
|
114
114
|
const float TWO_PI = 6.2831854820251465;
|
|
@@ -258,7 +258,7 @@ float tan_fp32(float a) {
|
|
|
258
258
|
return tan(a);
|
|
259
259
|
#endif
|
|
260
260
|
}
|
|
261
|
-
`,
|
|
261
|
+
`,Rr={name:"fp32",vs:Mo};var it=`
|
|
262
262
|
layout(std140) uniform fp64arithmeticUniforms {
|
|
263
263
|
uniform float ONE;
|
|
264
264
|
uniform float SPLIT;
|
|
@@ -457,7 +457,7 @@ vec2 sqrt_fp64(vec2 a) {
|
|
|
457
457
|
return sum_fp64(vec2(yn, 0.0), prod);
|
|
458
458
|
#endif
|
|
459
459
|
}
|
|
460
|
-
`;var
|
|
460
|
+
`;var Er=`struct Fp64ArithmeticUniforms {
|
|
461
461
|
ONE: f32,
|
|
462
462
|
SPLIT: f32,
|
|
463
463
|
};
|
|
@@ -663,7 +663,7 @@ fn sqrt_fp64(a: vec2f) -> vec2f {
|
|
|
663
663
|
return sum_fp64(vec2f(yn, 0.0), prod);
|
|
664
664
|
#endif
|
|
665
665
|
}
|
|
666
|
-
`;var
|
|
666
|
+
`;var Ir=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
|
|
667
667
|
const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
|
|
668
668
|
const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
|
|
669
669
|
const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
|
|
@@ -1332,7 +1332,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
|
|
|
1332
1332
|
vec4_dot_fp64(a, tmp, out_val[i]);
|
|
1333
1333
|
}
|
|
1334
1334
|
}
|
|
1335
|
-
`;var Lo={ONE:1,SPLIT:4097},
|
|
1335
|
+
`;var Lo={ONE:1,SPLIT:4097},at={name:"fp64arithmetic",source:Er,fs:it,vs:it,defaultUniforms:Lo,uniformTypes:{ONE:"f32",SPLIT:"f32"},fp64ify:K,fp64LowPart:ae,fp64ifyMatrix4:se},Cr={name:"fp64",vs:Ir,dependencies:[at],fp64ify:K,fp64LowPart:ae,fp64ifyMatrix4:se};var yr=`layout(std140) uniform floatColorsUniforms {
|
|
1336
1336
|
float useByteColors;
|
|
1337
1337
|
} floatColors;
|
|
1338
1338
|
|
|
@@ -1392,7 +1392,7 @@ fn floatColors_premultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
|
1392
1392
|
fn floatColors_unpremultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
1393
1393
|
return floatColors_unpremultiplyAlpha(inputColor);
|
|
1394
1394
|
}
|
|
1395
|
-
`,
|
|
1395
|
+
`,X={name:"floatColors",props:{},uniforms:{},vs:yr,fs:yr,source:Ao,uniformTypes:{useByteColors:"f32"},defaultUniforms:{useByteColors:!0}};var Ro=[0,1,1,1],Eo=`layout(std140) uniform pickingUniforms {
|
|
1396
1396
|
float isActive;
|
|
1397
1397
|
float isAttribute;
|
|
1398
1398
|
float isHighlightActive;
|
|
@@ -1463,7 +1463,7 @@ void picking_setPickingAttribute(vec3 value) {
|
|
|
1463
1463
|
picking_vRGBcolor_Avalid.rgb = value;
|
|
1464
1464
|
}
|
|
1465
1465
|
}
|
|
1466
|
-
`,
|
|
1466
|
+
`,Io=`layout(std140) uniform pickingUniforms {
|
|
1467
1467
|
float isActive;
|
|
1468
1468
|
float isAttribute;
|
|
1469
1469
|
float isHighlightActive;
|
|
@@ -1519,9 +1519,9 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
1519
1519
|
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
1520
1520
|
return picking_filterPickingColor(highlightColor);
|
|
1521
1521
|
}
|
|
1522
|
-
`,Nr={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useByteColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useByteColors:!0,highlightedObjectColor:[0,0,0],highlightColor:Ro},vs:Eo,fs:
|
|
1522
|
+
`,Nr={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useByteColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useByteColors:!0,highlightedObjectColor:[0,0,0],highlightColor:Ro},vs:Eo,fs:Io,getUniforms:Co};function Co(e={},t){let r={},n=Y(e.useByteColors,!0);if(e.highlightedObjectColor!==void 0)if(e.highlightedObjectColor===null)r.isHighlightActive=!1;else{r.isHighlightActive=!0;let o=e.highlightedObjectColor.slice(0,3);r.highlightedObjectColor=o}return e.highlightColor&&(r.highlightColor=Pe(e.highlightColor,n)),e.isActive!==void 0&&(r.isActive=Boolean(e.isActive),r.isAttribute=Boolean(e.isAttribute)),e.useByteColors!==void 0&&(r.useByteColors=Boolean(e.useByteColors)),r}var ce=20,yo=`
|
|
1523
1523
|
struct skinUniforms {
|
|
1524
|
-
jointMatrix: array<mat4x4<f32>, ${
|
|
1524
|
+
jointMatrix: array<mat4x4<f32>, ${ce}>,
|
|
1525
1525
|
};
|
|
1526
1526
|
|
|
1527
1527
|
@group(0) @binding(auto) var<uniform> skin: skinUniforms;
|
|
@@ -1544,7 +1544,7 @@ mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
|
|
|
1544
1544
|
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
1545
1545
|
}
|
|
1546
1546
|
|
|
1547
|
-
`,Po="",Pr={props:{},uniforms:{},name:"skin",bindingLayout:[{name:"skin",group:0}],dependencies:[],source:yo,vs:No,fs:Po,defines:{SKIN_MAX_JOINTS:
|
|
1547
|
+
`,Po="",Pr={props:{},uniforms:{},name:"skin",bindingLayout:[{name:"skin",group:0}],dependencies:[],source:yo,vs:No,fs:Po,defines:{SKIN_MAX_JOINTS:ce},getUniforms:(e={},t)=>{let{scenegraphsFromGLTF:r}=e;if(!r?.gltf?.skins?.[0])return{jointMatrix:[]};let{inverseBindMatrices:n,joints:o,skeleton:i}=r.gltf.skins[0],a=[],s=n.value.length/16;for(let p=0;p<s;p++){let u=n.value.subarray(p*16,p*16+16);a.push(new B(Array.from(u)))}let l=r.gltfNodeIndexToNodeMap.get(i),c={};l.preorderTraversal((p,{worldMatrix:u})=>{c[p.id]=u});let f=new Float32Array(ce*16);for(let p=0;p<ce;++p){let u=o[p];if(u===void 0)break;let h=c[r.gltfNodeIndexToNodeMap.get(u).id],g=a[p],S=new B().copy(h).multiplyRight(g),x=p*16;for(let _=0;_<16;_++)f[x+_]=S[_]}return{jointMatrix:f}},uniformTypes:{jointMatrix:["mat4x4<f32>",ce]}};var Or=ut(Be(),1);var st=`precision highp int;
|
|
1548
1548
|
|
|
1549
1549
|
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
1550
1550
|
struct AmbientLight {
|
|
@@ -1703,7 +1703,7 @@ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>)
|
|
|
1703
1703
|
);
|
|
1704
1704
|
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
1705
1705
|
}
|
|
1706
|
-
`;var
|
|
1706
|
+
`;var G=5,To={color:"vec3<f32>",position:"vec3<f32>",direction:"vec3<f32>",attenuation:"vec3<f32>",coneCos:"vec2<f32>"},V={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",directionalLightCount:"i32",pointLightCount:"i32",spotLightCount:"i32",ambientColor:"vec3<f32>",lights:[To,G]},defaultUniforms:Oe(),bindingLayout:[{name:"lighting",group:2}],firstBindingSlot:0,source:Tr,vs:st,fs:st,getUniforms:Oo};function Oo(e,t={}){if(e=e&&{...e},!e)return Oe();e.lights&&(e={...e,...Fo(e.lights),lights:void 0});let{useByteColors:r,ambientLight:n,pointLights:o,spotLights:i,directionalLights:a}=e||{};if(!(n||o&&o.length>0||i&&i.length>0||a&&a.length>0))return{...Oe(),enabled:0};let l={...Oe(),...Uo({useByteColors:r,ambientLight:n,pointLights:o,spotLights:i,directionalLights:a})};return e.enabled!==void 0&&(l.enabled=e.enabled?1:0),l}function Uo({useByteColors:e,ambientLight:t,pointLights:r=[],spotLights:n=[],directionalLights:o=[]}){let i=Ur(),a=0,s=0,l=0,c=0;for(let f of r){if(a>=G)break;i[a]={...i[a],color:Te(f,e),position:f.position,attenuation:f.attenuation||[1,0,0]},a++,s++}for(let f of n){if(a>=G)break;i[a]={...i[a],color:Te(f,e),position:f.position,direction:f.direction,attenuation:f.attenuation||[1,0,0],coneCos:wo(f)},a++,l++}for(let f of o){if(a>=G)break;i[a]={...i[a],color:Te(f,e),direction:f.direction},a++,c++}return r.length+n.length+o.length>G&&Or.log.warn(`MAX_LIGHTS exceeded, truncating to ${G}`)(),{ambientColor:Te(t,e),directionalLightCount:c,pointLightCount:s,spotLightCount:l,lights:i}}function Fo(e){let t={pointLights:[],spotLights:[],directionalLights:[]};for(let r of e||[])switch(r.type){case"ambient":t.ambientLight=r;break;case"directional":t.directionalLights?.push(r);break;case"point":t.pointLights?.push(r);break;case"spot":t.spotLights?.push(r);break;default:}return t}function Te(e={},t){let{color:r=[0,0,0],intensity:n=1}=e;return le(r,Y(t,!0)).map(i=>i*n)}function Oe(){return{enabled:1,directionalLightCount:0,pointLightCount:0,spotLightCount:0,ambientColor:[.1,.1,.1],lights:Ur()}}function Ur(){return Array.from({length:G},()=>Vo())}function Vo(){return{color:[1,1,1],position:[1,1,2],direction:[1,1,1],attenuation:[1,0,0],coneCos:[1,0]}}function wo(e){let t=e.innerConeAngle??0,r=e.outerConeAngle??Math.PI/4;return[Math.cos(t),Math.cos(r)]}var Bo=`#ifdef USE_IBL
|
|
1707
1707
|
@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;
|
|
1708
1708
|
@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;
|
|
1709
1709
|
@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;
|
|
@@ -1716,7 +1716,7 @@ uniform samplerCube pbr_diffuseEnvSampler;
|
|
|
1716
1716
|
uniform samplerCube pbr_specularEnvSampler;
|
|
1717
1717
|
uniform sampler2D pbr_brdfLUT;
|
|
1718
1718
|
#endif
|
|
1719
|
-
`,
|
|
1719
|
+
`,Ue={name:"ibl",firstBindingSlot:32,bindingLayout:[{name:"pbr_diffuseEnvSampler",group:2},{name:"pbr_specularEnvSampler",group:2},{name:"pbr_brdfLUT",group:2}],source:Bo,vs:Fr,fs:Fr};var ko=`struct dirlightUniforms {
|
|
1720
1720
|
lightDirection: vec3<f32>,
|
|
1721
1721
|
};
|
|
1722
1722
|
|
|
@@ -1757,7 +1757,7 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
1757
1757
|
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
1758
1758
|
return vec4(color.rgb * d, color.a);
|
|
1759
1759
|
}
|
|
1760
|
-
`,
|
|
1760
|
+
`,lt={props:{},uniforms:{},name:"dirlight",bindingLayout:[{name:"dirlight",group:2}],firstBindingSlot:16,dependencies:[],source:ko,vs:Do,fs:zo,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Go};function Go(e=lt.defaultUniforms){let t={};return e.lightDirection&&(t.lightDirection=e.lightDirection),t}var Vr=`struct lambertMaterialUniforms {
|
|
1761
1761
|
unlit: u32,
|
|
1762
1762
|
ambient: f32,
|
|
1763
1763
|
diffuse: f32,
|
|
@@ -1824,12 +1824,12 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
|
|
|
1824
1824
|
|
|
1825
1825
|
return lightColor;
|
|
1826
1826
|
}
|
|
1827
|
-
`;var
|
|
1827
|
+
`;var wr=`layout(std140) uniform lambertMaterialUniforms {
|
|
1828
1828
|
uniform bool unlit;
|
|
1829
1829
|
uniform float ambient;
|
|
1830
1830
|
uniform float diffuse;
|
|
1831
1831
|
} material;
|
|
1832
|
-
`,
|
|
1832
|
+
`,Br=`layout(std140) uniform lambertMaterialUniforms {
|
|
1833
1833
|
uniform bool unlit;
|
|
1834
1834
|
uniform float ambient;
|
|
1835
1835
|
uniform float diffuse;
|
|
@@ -1876,14 +1876,14 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
1876
1876
|
|
|
1877
1877
|
return lightColor;
|
|
1878
1878
|
}
|
|
1879
|
-
`;var
|
|
1879
|
+
`;var ct={name:"lambertMaterial",firstBindingSlot:0,bindingLayout:[{name:"lambertMaterial",group:3}],dependencies:[V],source:Vr,vs:wr,fs:Br,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6},getUniforms(e){return{...ct.defaultUniforms,...e}}};var Fe=`layout(std140) uniform phongMaterialUniforms {
|
|
1880
1880
|
uniform bool unlit;
|
|
1881
1881
|
uniform float ambient;
|
|
1882
1882
|
uniform float diffuse;
|
|
1883
1883
|
uniform float shininess;
|
|
1884
1884
|
uniform vec3 specularColor;
|
|
1885
1885
|
} material;
|
|
1886
|
-
`,
|
|
1886
|
+
`,Ve=`layout(std140) uniform phongMaterialUniforms {
|
|
1887
1887
|
uniform bool unlit;
|
|
1888
1888
|
uniform float ambient;
|
|
1889
1889
|
uniform float diffuse;
|
|
@@ -1900,7 +1900,7 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
|
|
|
1900
1900
|
specular = pow(specular_angle, material.shininess);
|
|
1901
1901
|
}
|
|
1902
1902
|
lambertian = max(lambertian, 0.0);
|
|
1903
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
1903
|
+
return (lambertian * material.diffuse * surfaceColor + specular * floatColors_normalize(material.specularColor)) * color;
|
|
1904
1904
|
}
|
|
1905
1905
|
|
|
1906
1906
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
@@ -1940,7 +1940,7 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
1940
1940
|
|
|
1941
1941
|
return lightColor;
|
|
1942
1942
|
}
|
|
1943
|
-
`;var
|
|
1943
|
+
`;var we=`struct phongMaterialUniforms {
|
|
1944
1944
|
unlit: u32,
|
|
1945
1945
|
ambient: f32,
|
|
1946
1946
|
diffuse: f32,
|
|
@@ -1959,7 +1959,10 @@ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, v
|
|
|
1959
1959
|
specular = pow(specular_angle, phongMaterial.shininess);
|
|
1960
1960
|
}
|
|
1961
1961
|
lambertian = max(lambertian, 0.0);
|
|
1962
|
-
return (
|
|
1962
|
+
return (
|
|
1963
|
+
lambertian * phongMaterial.diffuse * surfaceColor +
|
|
1964
|
+
specular * floatColors_normalize(phongMaterial.specularColor)
|
|
1965
|
+
) * color;
|
|
1963
1966
|
}
|
|
1964
1967
|
|
|
1965
1968
|
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
@@ -2060,7 +2063,7 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
|
|
|
2060
2063
|
}
|
|
2061
2064
|
return lightColor;
|
|
2062
2065
|
}
|
|
2063
|
-
`;var
|
|
2066
|
+
`;var Ho=[38.25,38.25,38.25],ft={props:{},name:"gouraudMaterial",bindingLayout:[{name:"gouraudMaterial",group:3}],vs:Ve.replace("phongMaterial","gouraudMaterial"),fs:Fe.replace("phongMaterial","gouraudMaterial"),source:we.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[V,X],uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:Ho},getUniforms(e){return{...ft.defaultUniforms,...e}}};var $o=[38.25,38.25,38.25],pt={name:"phongMaterial",firstBindingSlot:0,bindingLayout:[{name:"phongMaterial",group:3}],dependencies:[V,X],source:we,vs:Fe,fs:Ve,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:$o},getUniforms(e){return{...pt.defaultUniforms,...e}}};var kr=`out vec3 pbr_vPosition;
|
|
2064
2067
|
out vec2 pbr_vUV0;
|
|
2065
2068
|
out vec2 pbr_vUV1;
|
|
2066
2069
|
|
|
@@ -4344,7 +4347,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4344
4347
|
mat4 normalMatrix;
|
|
4345
4348
|
vec3 camera;
|
|
4346
4349
|
} pbrProjection;
|
|
4347
|
-
`,
|
|
4350
|
+
`,Wo=`struct pbrProjectionUniforms {
|
|
4348
4351
|
modelViewProjectionMatrix: mat4x4<f32>,
|
|
4349
4352
|
modelMatrix: mat4x4<f32>,
|
|
4350
4353
|
normalMatrix: mat4x4<f32>,
|
|
@@ -4352,7 +4355,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4352
4355
|
};
|
|
4353
4356
|
|
|
4354
4357
|
@group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;
|
|
4355
|
-
`,Hr={name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:
|
|
4358
|
+
`,Hr={name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:Wo,vs:Gr,fs:Gr,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}};var $r={props:{},uniforms:{},defaultUniforms:{unlit:!1,baseColorMapEnabled:!1,baseColorFactor:[1,1,1,1],normalMapEnabled:!1,normalScale:1,emissiveMapEnabled:!1,emissiveFactor:[0,0,0],metallicRoughnessValues:[1,1],metallicRoughnessMapEnabled:!1,occlusionMapEnabled:!1,occlusionStrength:1,alphaCutoffEnabled:!1,alphaCutoff:.5,IBLenabled:!1,scaleIBLAmbient:[1,1],scaleDiffBaseMR:[0,0,0,0],scaleFGDSpec:[0,0,0,0],specularColorFactor:[1,1,1],specularIntensityFactor:1,specularColorMapEnabled:!1,specularIntensityMapEnabled:!1,ior:1.5,transmissionFactor:0,transmissionMapEnabled:!1,thicknessFactor:0,attenuationDistance:1e9,attenuationColor:[1,1,1],clearcoatFactor:0,clearcoatRoughnessFactor:0,clearcoatMapEnabled:!1,clearcoatRoughnessMapEnabled:!1,sheenColorFactor:[0,0,0],sheenRoughnessFactor:0,sheenColorMapEnabled:!1,sheenRoughnessMapEnabled:!1,iridescenceFactor:0,iridescenceIor:1.3,iridescenceThicknessRange:[100,400],iridescenceMapEnabled:!1,anisotropyStrength:0,anisotropyRotation:0,anisotropyDirection:[1,0],anisotropyMapEnabled:!1,emissiveStrength:1,baseColorUVSet:0,baseColorUVTransform:[1,0,0,0,1,0,0,0,1],metallicRoughnessUVSet:0,metallicRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],normalUVSet:0,normalUVTransform:[1,0,0,0,1,0,0,0,1],occlusionUVSet:0,occlusionUVTransform:[1,0,0,0,1,0,0,0,1],emissiveUVSet:0,emissiveUVTransform:[1,0,0,0,1,0,0,0,1],specularColorUVSet:0,specularColorUVTransform:[1,0,0,0,1,0,0,0,1],specularIntensityUVSet:0,specularIntensityUVTransform:[1,0,0,0,1,0,0,0,1],transmissionUVSet:0,transmissionUVTransform:[1,0,0,0,1,0,0,0,1],thicknessUVSet:0,thicknessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatUVSet:0,clearcoatUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatRoughnessUVSet:0,clearcoatRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatNormalUVSet:0,clearcoatNormalUVTransform:[1,0,0,0,1,0,0,0,1],sheenColorUVSet:0,sheenColorUVTransform:[1,0,0,0,1,0,0,0,1],sheenRoughnessUVSet:0,sheenRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceUVSet:0,iridescenceUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceThicknessUVSet:0,iridescenceThicknessUVTransform:[1,0,0,0,1,0,0,0,1],anisotropyUVSet:0,anisotropyUVTransform:[1,0,0,0,1,0,0,0,1]},name:"pbrMaterial",firstBindingSlot:0,bindingLayout:[{name:"pbrMaterial",group:3},{name:"pbr_baseColorSampler",group:3},{name:"pbr_normalSampler",group:3},{name:"pbr_emissiveSampler",group:3},{name:"pbr_metallicRoughnessSampler",group:3},{name:"pbr_occlusionSampler",group:3},{name:"pbr_specularColorSampler",group:3},{name:"pbr_specularIntensitySampler",group:3},{name:"pbr_transmissionSampler",group:3},{name:"pbr_thicknessSampler",group:3},{name:"pbr_clearcoatSampler",group:3},{name:"pbr_clearcoatRoughnessSampler",group:3},{name:"pbr_clearcoatNormalSampler",group:3},{name:"pbr_sheenColorSampler",group:3},{name:"pbr_sheenRoughnessSampler",group:3},{name:"pbr_iridescenceSampler",group:3},{name:"pbr_iridescenceThicknessSampler",group:3},{name:"pbr_anisotropySampler",group:3}],dependencies:[V,Ue,Hr],source:zr,vs:kr,fs:Dr,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,HAS_SPECULARCOLORMAP:!1,HAS_SPECULARINTENSITYMAP:!1,HAS_TRANSMISSIONMAP:!1,HAS_THICKNESSMAP:!1,HAS_CLEARCOATMAP:!1,HAS_CLEARCOATROUGHNESSMAP:!1,HAS_CLEARCOATNORMALMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_SHEENROUGHNESSMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_IRIDESCENCETHICKNESSMAP:!1,HAS_ANISOTROPYMAP:!1,USE_MATERIAL_EXTENSIONS:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:e=>e,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",specularColorFactor:"vec3<f32>",specularIntensityFactor:"f32",specularColorMapEnabled:"i32",specularIntensityMapEnabled:"i32",ior:"f32",transmissionFactor:"f32",transmissionMapEnabled:"i32",thicknessFactor:"f32",attenuationDistance:"f32",attenuationColor:"vec3<f32>",clearcoatFactor:"f32",clearcoatRoughnessFactor:"f32",clearcoatMapEnabled:"i32",clearcoatRoughnessMapEnabled:"i32",sheenColorFactor:"vec3<f32>",sheenRoughnessFactor:"f32",sheenColorMapEnabled:"i32",sheenRoughnessMapEnabled:"i32",iridescenceFactor:"f32",iridescenceIor:"f32",iridescenceThicknessRange:"vec2<f32>",iridescenceMapEnabled:"i32",anisotropyStrength:"f32",anisotropyRotation:"f32",anisotropyDirection:"vec2<f32>",anisotropyMapEnabled:"i32",emissiveStrength:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>",baseColorUVSet:"i32",baseColorUVTransform:"mat3x3<f32>",metallicRoughnessUVSet:"i32",metallicRoughnessUVTransform:"mat3x3<f32>",normalUVSet:"i32",normalUVTransform:"mat3x3<f32>",occlusionUVSet:"i32",occlusionUVTransform:"mat3x3<f32>",emissiveUVSet:"i32",emissiveUVTransform:"mat3x3<f32>",specularColorUVSet:"i32",specularColorUVTransform:"mat3x3<f32>",specularIntensityUVSet:"i32",specularIntensityUVTransform:"mat3x3<f32>",transmissionUVSet:"i32",transmissionUVTransform:"mat3x3<f32>",thicknessUVSet:"i32",thicknessUVTransform:"mat3x3<f32>",clearcoatUVSet:"i32",clearcoatUVTransform:"mat3x3<f32>",clearcoatRoughnessUVSet:"i32",clearcoatRoughnessUVTransform:"mat3x3<f32>",clearcoatNormalUVSet:"i32",clearcoatNormalUVTransform:"mat3x3<f32>",sheenColorUVSet:"i32",sheenColorUVTransform:"mat3x3<f32>",sheenRoughnessUVSet:"i32",sheenRoughnessUVTransform:"mat3x3<f32>",iridescenceUVSet:"i32",iridescenceUVTransform:"mat3x3<f32>",iridescenceThicknessUVSet:"i32",iridescenceThicknessUVTransform:"mat3x3<f32>",anisotropyUVSet:"i32",anisotropyUVTransform:"mat3x3<f32>"}};var Wr=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],jr=`layout(std140) uniform pbrSceneUniforms {
|
|
4356
4359
|
float exposure;
|
|
4357
4360
|
int toneMapMode;
|
|
4358
4361
|
float environmentIntensity;
|
|
@@ -4365,7 +4368,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4365
4368
|
#ifdef USE_TRANSMISSION_FRAMEBUFFER
|
|
4366
4369
|
uniform sampler2D pbr_transmissionFramebufferSampler;
|
|
4367
4370
|
#endif
|
|
4368
|
-
|
|
4371
|
+
`,jo=`struct pbrSceneUniforms {
|
|
4369
4372
|
exposure: f32,
|
|
4370
4373
|
toneMapMode: i32,
|
|
4371
4374
|
environmentIntensity: f32,
|
|
@@ -4381,6 +4384,6 @@ uniform sampler2D pbr_transmissionFramebufferSampler;
|
|
|
4381
4384
|
@group(1) @binding(auto) var pbr_transmissionFramebufferSampler: texture_2d<f32>;
|
|
4382
4385
|
@group(1) @binding(auto) var pbr_transmissionFramebufferSamplerSampler: sampler;
|
|
4383
4386
|
#endif
|
|
4384
|
-
`,qr={name:"pbrScene",bindingLayout:[{name:"pbrScene",group:1},{name:"pbr_transmissionFramebufferSampler",group:1}],source
|
|
4387
|
+
`,qr={name:"pbrScene",bindingLayout:[{name:"pbrScene",group:1},{name:"pbr_transmissionFramebufferSampler",group:1}],source:jo,vs:jr,fs:jr,getUniforms:e=>e,uniformTypes:{exposure:"f32",toneMapMode:"i32",environmentIntensity:"f32",environmentRotation:"f32",framebufferSize:"vec2<f32>",viewMatrix:"mat4x4<f32>",projectionMatrix:"mat4x4<f32>"},defaultUniforms:{exposure:1,toneMapMode:2,environmentIntensity:1,environmentRotation:Math.PI*.5,framebufferSize:[1,1],viewMatrix:Wr,projectionMatrix:Wr}};return rn(fe);})();
|
|
4385
4388
|
return __exports__;
|
|
4386
4389
|
});
|