@luma.gl/shadertools 9.3.0-alpha.2 → 9.3.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/dist.dev.js +2114 -198
  2. package/dist/dist.min.js +315 -184
  3. package/dist/index.cjs +463 -199
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
  10. package/dist/lib/preprocessor/preprocessor.js +33 -7
  11. package/dist/lib/preprocessor/preprocessor.js.map +1 -1
  12. package/dist/lib/shader-assembler.d.ts.map +1 -1
  13. package/dist/lib/shader-assembler.js +8 -1
  14. package/dist/lib/shader-assembler.js.map +1 -1
  15. package/dist/lib/shader-module/shader-module.d.ts +1 -1
  16. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  17. package/dist/lib/utils/assert.d.ts.map +1 -1
  18. package/dist/lib/utils/assert.js +3 -1
  19. package/dist/lib/utils/assert.js.map +1 -1
  20. package/dist/modules/engine/skin/skin.d.ts +29 -0
  21. package/dist/modules/engine/skin/skin.d.ts.map +1 -0
  22. package/dist/modules/engine/skin/skin.js +88 -0
  23. package/dist/modules/engine/skin/skin.js.map +1 -0
  24. package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
  25. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
  26. package/dist/modules/lighting/lights/lighting-glsl.js +20 -2
  27. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
  28. package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
  29. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
  30. package/dist/modules/lighting/lights/lighting-wgsl.js +63 -13
  31. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
  32. package/dist/modules/lighting/lights/lighting.d.ts +27 -3
  33. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  34. package/dist/modules/lighting/lights/lighting.js +32 -6
  35. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  36. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +1 -1
  37. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  38. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +106 -79
  39. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  40. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +20 -4
  41. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  42. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
  43. package/dist/modules/lighting/pbr-material/pbr-projection.js +12 -1
  44. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
  45. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
  46. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
  47. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +40 -76
  48. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
  49. package/dist/modules/math/random/random.d.ts +1 -1
  50. package/dist/modules/math/random/random.d.ts.map +1 -1
  51. package/dist/modules/math/random/random.js +2 -3
  52. package/dist/modules/math/random/random.js.map +1 -1
  53. package/package.json +2 -2
  54. package/src/index.ts +1 -0
  55. package/src/lib/preprocessor/preprocessor.ts +40 -7
  56. package/src/lib/shader-assembler.ts +8 -1
  57. package/src/lib/shader-module/shader-module.ts +1 -1
  58. package/src/lib/utils/assert.ts +3 -1
  59. package/src/modules/engine/skin/skin.ts +116 -0
  60. package/src/modules/lighting/lights/lighting-glsl.ts +20 -2
  61. package/src/modules/lighting/lights/lighting-wgsl.ts +63 -13
  62. package/src/modules/lighting/lights/lighting.ts +45 -9
  63. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +106 -79
  64. package/src/modules/lighting/pbr-material/pbr-projection.ts +13 -1
  65. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +40 -77
  66. package/src/modules/math/random/random.ts +2 -3
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 pt=Object.create;var O=Object.defineProperty;var _t=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty;var ht=(e,t,o)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var vt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var o in t)O(e,o,{get:t[o],enumerable:!0})},z=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of mt(t))!dt.call(e,n)&&n!==o&&O(e,n,{get:()=>t[n],enumerable:!(i=_t(t,n))||i.enumerable});return e},q=(e,t,o)=>(z(e,t,"default"),o&&z(o,t,"default")),de=(e,t,o)=>(o=e!=null?pt(gt(e)):{},z(t||!e||!e.__esModule?O(o,"default",{value:e,enumerable:!0}):o,e)),At=e=>z(O({},"__esModule",{value:!0}),e);var he=(e,t,o)=>(ht(e,typeof t!="symbol"?t+"":t,o),o);var te=vt((fo,ve)=>{ve.exports=globalThis.luma});var H={};bt(H,{ShaderAssembler:()=>w,_getDependencyGraph:()=>D,_resolveModules:()=>Ne,assembleGLSLShaderPair:()=>K,capitalize:()=>E,checkShaderModuleDeprecations:()=>F,combineInjects:()=>Ce,convertToVec4:()=>le,dirlight:()=>pe,fp32:()=>Qe,fp64:()=>ot,fp64LowPart:()=>B,fp64arithmetic:()=>ce,fp64ify:()=>R,fp64ifyMatrix4:()=>U,fromHalfFloat:()=>Ye,generateShaderForModule:()=>ze,getPassthroughFS:()=>ke,getQualifierDetails:()=>Ue,getShaderInfo:()=>$,getShaderModuleDependencies:()=>y,getShaderModuleSource:()=>X,getShaderModuleUniforms:()=>Re,gouraudMaterial:()=>_e,initializeShaderModule:()=>W,initializeShaderModules:()=>v,lighting:()=>g,pbrMaterial:()=>ut,phongMaterial:()=>me,picking:()=>it,preprocess:()=>Y,random:()=>Ze,toHalfFloat:()=>Xe,typeToChannelCount:()=>Ge,typeToChannelSuffix:()=>He});q(H,de(te(),1));function S(e,t){if(!e)throw new Error(t||"shadertools: assertion failed.")}var oe={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 Ae(e){let t={};for(let[o,i]of Object.entries(e))t[o]=St(i);return t}function Se(e,t,o){let i={};for(let[n,r]of Object.entries(t))e&&n in e&&!r.private?(r.validate&&S(r.validate(e[n],r),`${o}: invalid ${n}`),i[n]=e[n]):i[n]=r.value;return i}function St(e){let t=be(e);if(t!=="object")return{value:e,...oe[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...oe[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=be(e.value),{...e,...oe[t],type:t}):{type:"object",value:null};throw new Error("props")}function be(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}var Ie=`#ifdef MODULE_LOGDEPTH
7
+ "use strict";var __exports__=(()=>{var on=Object.create;var j=Object.defineProperty;var sn=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var an=Object.getPrototypeOf,ln=Object.prototype.hasOwnProperty;var fn=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var pn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),hn=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},ne=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of cn(t))!ln.call(e,r)&&r!==n&&j(e,r,{get:()=>t[r],enumerable:!(i=sn(t,r))||i.enumerable});return e},ie=(e,t,n)=>(ne(e,t,"default"),n&&ne(n,t,"default")),Be=(e,t,n)=>(n=e!=null?on(an(e)):{},ne(t||!e||!e.__esModule?j(n,"default",{value:e,enumerable:!0}):n,e)),gn=e=>ne(j({},"__esModule",{value:!0}),e);var ze=(e,t,n)=>(fn(e,typeof t!="symbol"?t+"":t,n),n);var xe=pn((Ai,He)=>{He.exports=globalThis.luma});var te={};hn(te,{ShaderAssembler:()=>X,_getDependencyGraph:()=>K,_resolveModules:()=>Je,assembleGLSLShaderPair:()=>se,capitalize:()=>D,checkShaderModuleDeprecations:()=>$,combineInjects:()=>Xe,convertToVec4:()=>Ee,dirlight:()=>ke,fp32:()=>jt,fp64:()=>$t,fp64LowPart:()=>Z,fp64arithmetic:()=>Te,fp64ify:()=>G,fp64ifyMatrix4:()=>J,fromHalfFloat:()=>Ht,generateShaderForModule:()=>gt,getPassthroughFS:()=>at,getQualifierDetails:()=>ct,getShaderInfo:()=>oe,getShaderModuleDependencies:()=>Y,getShaderModuleSource:()=>ce,getShaderModuleUniforms:()=>Ze,gouraudMaterial:()=>De,initializeShaderModule:()=>re,initializeShaderModules:()=>T,lighting:()=>y,pbrMaterial:()=>rn,phongMaterial:()=>Ue,picking:()=>Yt,preprocess:()=>ae,random:()=>Vt,skin:()=>Kt,toHalfFloat:()=>zt,typeToChannelCount:()=>ft,typeToChannelSuffix:()=>lt});ie(te,Be(xe(),1));function F(e,t){if(!e){let n=new Error(t||"shadertools: assertion failed.");throw Error.captureStackTrace?.(n,F),n}}var be={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 Ve(e){let t={};for(let[n,i]of Object.entries(e))t[n]=mn(i);return t}function je(e,t,n){let i={};for(let[r,o]of Object.entries(t))e&&r in e&&!o.private?(o.validate&&F(o.validate(e[r],o),`${n}: invalid ${r}`),i[r]=e[r]):i[r]=o.value;return i}function mn(e){let t=Ge(e);if(t!=="object")return{value:e,...be[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...be[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=Ge(e.value),{...e,...be[t],type:t}):{type:"object",value:null};throw new Error("props")}function Ge(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}var qe=`#ifdef MODULE_LOGDEPTH
8
8
  logdepth_adjustPosition(gl_Position);
9
9
  #endif
10
- `,Le=`#ifdef MODULE_MATERIAL
10
+ `,We=`#ifdef MODULE_MATERIAL
11
11
  fragColor = material_filterColor(fragColor);
12
12
  #endif
13
13
 
@@ -27,10 +27,10 @@
27
27
  #ifdef MODULE_LOGDEPTH
28
28
  logdepth_setFragDepth();
29
29
  #endif
30
- `;var It={vertex:Ie,fragment:Le},Ee=/void\s+main\s*\([^)]*\)\s*\{\n?/,xe=/}\n?[^{}]*$/,ie=[],M="__LUMA_INJECT_DECLARATIONS__";function Pe(e){let t={vertex:{},fragment:{}};for(let o in e){let i=e[o],n=Lt(o);typeof i=="string"&&(i={order:0,injection:i}),t[n][o]=i}return t}function Lt(e){let t=e.slice(0,2);switch(t){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(t)}}function T(e,t,o,i=!1){let n=t==="vertex";for(let r in o){let a=o[r];a.sort((l,f)=>l.order-f.order),ie.length=a.length;for(let l=0,f=a.length;l<f;++l)ie[l]=a[l].injection;let s=`${ie.join(`
30
+ `;var _n={vertex:qe,fragment:We},$e=/void\s+main\s*\([^)]*\)\s*\{\n?/,Ye=/}\n?[^{}]*$/,Me=[],q="__LUMA_INJECT_DECLARATIONS__";function Ke(e){let t={vertex:{},fragment:{}};for(let n in e){let i=e[n],r=un(n);typeof i=="string"&&(i={order:0,injection:i}),t[r][n]=i}return t}function un(e){let t=e.slice(0,2);switch(t){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(t)}}function W(e,t,n,i=!1){let r=t==="vertex";for(let o in n){let s=n[o];s.sort((a,l)=>a.order-l.order),Me.length=s.length;for(let a=0,l=s.length;a<l;++a)Me[a]=s[a].injection;let c=`${Me.join(`
31
31
  `)}
32
- `;switch(r){case"vs:#decl":n&&(e=e.replace(M,s));break;case"vs:#main-start":n&&(e=e.replace(Ee,l=>l+s));break;case"vs:#main-end":n&&(e=e.replace(xe,l=>s+l));break;case"fs:#decl":n||(e=e.replace(M,s));break;case"fs:#main-start":n||(e=e.replace(Ee,l=>l+s));break;case"fs:#main-end":n||(e=e.replace(xe,l=>s+l));break;default:e=e.replace(r,l=>l+s)}}return e=e.replace(M,""),i&&(e=e.replace(/\}\s*$/,r=>r+It[t])),e}function Ce(e){let t={};return S(Array.isArray(e)&&e.length>1),e.forEach(o=>{for(let i in o)t[i]=t[i]?`${t[i]}
33
- ${o[i]}`:o[i]}),t}function v(e){e.map(t=>W(t))}function W(e){if(e.instance)return;v(e.dependencies||[]);let{propTypes:t={},deprecations:o=[],inject:i={}}=e,n={normalizedInjections:Pe(i),parsedDeprecations:Et(o)};t&&(n.propValidators=Ae(t)),e.instance=n;let r={};t&&(r=Object.entries(t).reduce((a,[s,l])=>{let f=l?.value;return f&&(a[s]=f),a},{})),e.defaultUniforms={...e.defaultUniforms,...r}}function Re(e,t,o){W(e);let i=o||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,i):Se(t,e.instance?.propValidators,e.name)}function F(e,t,o){e.deprecations?.forEach(i=>{i.regex?.test(t)&&(i.deprecated?o.deprecated(i.old,i.new)():o.removed(i.old,i.new)())})}function Et(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 y(e){v(e);let t={},o={};D({modules:e,level:0,moduleMap:t,moduleDepth:o});let i=Object.keys(o).sort((n,r)=>o[r]-o[n]).map(n=>t[n]);return v(i),i}function D(e){let{modules:t,level:o,moduleMap:i,moduleDepth:n}=e;if(o>=5)throw new Error("Possible loop in shader dependency graph");for(let r of t)i[r.name]=r,(n[r.name]===void 0||n[r.name]<o)&&(n[r.name]=o);for(let r of t)r.dependencies&&D({modules:r.dependencies,level:o+1,moduleMap:i,moduleDepth:n})}function xt(e){v(e);let t={},o={};return D({modules:e,level:0,moduleMap:t,moduleDepth:o}),e=Object.keys(o).sort((i,n)=>o[n]-o[i]).map(i=>t[i]),v(e),e}function Ne(e){return xt(e)}function Oe(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
32
+ `;switch(o){case"vs:#decl":r&&(e=e.replace(q,c));break;case"vs:#main-start":r&&(e=e.replace($e,a=>a+c));break;case"vs:#main-end":r&&(e=e.replace(Ye,a=>c+a));break;case"fs:#decl":r||(e=e.replace(q,c));break;case"fs:#main-start":r||(e=e.replace($e,a=>a+c));break;case"fs:#main-end":r||(e=e.replace(Ye,a=>c+a));break;default:e=e.replace(o,a=>a+c)}}return e=e.replace(q,""),i&&(e=e.replace(/\}\s*$/,o=>o+_n[t])),e}function Xe(e){let t={};return F(Array.isArray(e)&&e.length>1),e.forEach(n=>{for(let i in n)t[i]=t[i]?`${t[i]}
33
+ ${n[i]}`:n[i]}),t}function T(e){e.map(t=>re(t))}function re(e){if(e.instance)return;T(e.dependencies||[]);let{propTypes:t={},deprecations:n=[],inject:i={}}=e,r={normalizedInjections:Ke(i),parsedDeprecations:dn(n)};t&&(r.propValidators=Ve(t)),e.instance=r;let o={};t&&(o=Object.entries(t).reduce((s,[c,a])=>{let l=a?.value;return l&&(s[c]=l),s},{})),e.defaultUniforms={...e.defaultUniforms,...o}}function Ze(e,t,n){re(e);let i=n||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,i):je(t,e.instance?.propValidators,e.name)}function $(e,t,n){e.deprecations?.forEach(i=>{i.regex?.test(t)&&(i.deprecated?n.deprecated(i.old,i.new)():n.removed(i.old,i.new)())})}function dn(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 Y(e){T(e);let t={},n={};K({modules:e,level:0,moduleMap:t,moduleDepth:n});let i=Object.keys(n).sort((r,o)=>n[o]-n[r]).map(r=>t[r]);return T(i),i}function K(e){let{modules:t,level:n,moduleMap:i,moduleDepth:r}=e;if(n>=5)throw new Error("Possible loop in shader dependency graph");for(let o of t)i[o.name]=o,(r[o.name]===void 0||r[o.name]<n)&&(r[o.name]=n);for(let o of t)o.dependencies&&K({modules:o.dependencies,level:n+1,moduleMap:i,moduleDepth:r})}function vn(e){T(e);let t={},n={};return K({modules:e,level:0,moduleMap:t,moduleDepth:n}),e=Object.keys(n).sort((i,r)=>n[r]-n[i]).map(i=>t[i]),T(e),e}function Je(e){return vn(e)}function Qe(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
34
34
  // Apple optimizes away the calculation necessary for emulated fp64
35
35
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
36
36
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
@@ -54,56 +54,55 @@ ${o[i]}`:o[i]}),t}function v(e){e.map(t=>W(t))}function W(e){if(e.instance)retur
54
54
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
55
55
  // If the GPU doesn't have full 32 bits precision, will causes overflow
56
56
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
57
- `}}function Te(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=Me(e,Pt),e;case"fragment":return e=Me(e,Ct),e;default:throw new Error(t)}}var Fe=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
58
- `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Pt=[...Fe,[re("attribute"),"in $1"],[re("varying"),"out $1"]],Ct=[...Fe,[re("varying"),"in $1"]];function Me(e,t){for(let[o,i]of t)e=e.replace(o,i);return e}function re(e){return new RegExp(`\\b${e}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function ne(e,t){let o="";for(let i in e){let n=e[i];if(o+=`void ${n.signature} {
59
- `,n.header&&(o+=` ${n.header}`),t[i]){let r=t[i];r.sort((a,s)=>a.order-s.order);for(let a of r)o+=` ${a.injection}
60
- `}n.footer&&(o+=` ${n.footer}`),o+=`}
61
- `}return o}function ae(e){let t={vertex:{},fragment:{}};for(let o of e){let i,n;typeof o!="string"?(i=o,n=i.hook):(i={},n=o),n=n.trim();let[r,a]=n.split(":"),s=n.replace(/\(.+/,""),l=Object.assign(i,{signature:a});switch(r){case"vs":t.vertex[s]=l;break;case"fs":t.fragment[s]=l;break;default:throw new Error(r)}}return t}function $(e,t){return{name:Rt(e,t),language:"glsl",version:Nt(e)}}function Rt(e,t="unnamed"){let i=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(e);return i?i[1]:t}function Nt(e){let t=100,o=e.match(/[^\s]+/g);if(o&&o.length>=2&&o[0]==="#version"){let i=parseInt(o[1],10);Number.isFinite(i)&&(t=i)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}var De=`
62
-
63
- ${M}
64
- `,Ot=`precision highp float;
65
- `;function we(e){let t=y(e.modules||[]);return{source:Mt(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t}),getUniforms:Be(t)}}function K(e){let{vs:t,fs:o}=e,i=y(e.modules||[]);return{vs:ye(e.platformInfo,{...e,source:t,stage:"vertex",modules:i}),fs:ye(e.platformInfo,{...e,source:o,stage:"fragment",modules:i}),getUniforms:Be(i)}}function Mt(e,t){let{source:o,stage:i,modules:n,hookFunctions:r=[],inject:a={},log:s}=t;S(typeof o=="string","shader source must be a string");let l=o,f="",G=ae(r),b={},N={},I={};for(let u in a){let d=typeof a[u]=="string"?{injection:a[u],order:0}:a[u],c=/^(v|f)s:(#)?([\w-]+)$/.exec(u);if(c){let _=c[2],h=c[3];_?h==="decl"?N[u]=[d]:I[u]=[d]:b[u]=[d]}else I[u]=[d]}let ge=n;for(let u of ge){s&&F(u,l,s);let d=X(u,"wgsl");f+=d;let c=u.injections?.[i]||{};for(let _ in c){let h=/^(v|f)s:#([\w-]+)$/.exec(_);if(h){let A=h[2]==="decl"?N:I;A[_]=A[_]||[],A[_].push(c[_])}else b[_]=b[_]||[],b[_].push(c[_])}}return f+=De,f=T(f,i,N),f+=ne(G[i],b),f+=l,f=T(f,i,I),f}function ye(e,t){let{source:o,stage:i,language:n="glsl",modules:r,defines:a={},hookFunctions:s=[],inject:l={},prologue:f=!0,log:G}=t;S(typeof o=="string","shader source must be a string");let b=n==="glsl"?$(o).version:-1,N=e.shaderLanguageVersion,I=b===100?"#version 100":"#version 300 es",u=o.split(`
57
+ `}}function tt(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=et(e,xn),e;case"fragment":return e=et(e,bn),e;default:throw new Error(t)}}var nt=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
58
+ `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],xn=[...nt,[Ae("attribute"),"in $1"],[Ae("varying"),"out $1"]],bn=[...nt,[Ae("varying"),"in $1"]];function et(e,t){for(let[n,i]of t)e=e.replace(n,i);return e}function Ae(e){return new RegExp(`\\b${e}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function Le(e,t){let n="";for(let i in e){let r=e[i];if(n+=`void ${r.signature} {
59
+ `,r.header&&(n+=` ${r.header}`),t[i]){let o=t[i];o.sort((s,c)=>s.order-c.order);for(let s of o)n+=` ${s.injection}
60
+ `}r.footer&&(n+=` ${r.footer}`),n+=`}
61
+ `}return n}function Se(e){let t={vertex:{},fragment:{}};for(let n of e){let i,r;typeof n!="string"?(i=n,r=i.hook):(i={},r=n),r=r.trim();let[o,s]=r.split(":"),c=r.replace(/\(.+/,""),a=Object.assign(i,{signature:s});switch(o){case"vs":t.vertex[c]=a;break;case"fs":t.fragment[c]=a;break;default:throw new Error(o)}}return t}function oe(e,t){return{name:Mn(e,t),language:"glsl",version:An(e)}}function Mn(e,t="unnamed"){let i=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(e);return i?i[1]:t}function An(e){let t=100,n=e.match(/[^\s]+/g);if(n&&n.length>=2&&n[0]==="#version"){let i=parseInt(n[1],10);Number.isFinite(i)&&(t=i)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}var rt=`
62
+
63
+ ${q}
64
+ `,Ln=`precision highp float;
65
+ `;function ot(e){let t=Y(e.modules||[]);return{source:Sn(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t}),getUniforms:st(t)}}function se(e){let{vs:t,fs:n}=e,i=Y(e.modules||[]);return{vs:it(e.platformInfo,{...e,source:t,stage:"vertex",modules:i}),fs:it(e.platformInfo,{...e,source:n,stage:"fragment",modules:i}),getUniforms:st(i)}}function Sn(e,t){let{source:n,stage:i,modules:r,hookFunctions:o=[],inject:s={},log:c}=t;F(typeof n=="string","shader source must be a string");let a=n,l="",h=Se(o),f={},p={},m={};for(let _ in s){let d=typeof s[_]=="string"?{injection:s[_],order:0}:s[_],g=/^(v|f)s:(#)?([\w-]+)$/.exec(_);if(g){let A=g[2],v=g[3];A?v==="decl"?p[_]=[d]:m[_]=[d]:f[_]=[d]}else m[_]=[d]}let x=r;for(let _ of x){c&&$(_,a,c);let d=ce(_,"wgsl");l+=d;let g=_.injections?.[i]||{};for(let A in g){let v=/^(v|f)s:#([\w-]+)$/.exec(A);if(v){let b=v[2]==="decl"?p:m;b[A]=b[A]||[],b[A].push(g[A])}else f[A]=f[A]||[],f[A].push(g[A])}}return l+=rt,l=W(l,i,p),l+=Le(h[i],f),l+=a,l=W(l,i,m),l}function it(e,t){let{source:n,stage:i,language:r="glsl",modules:o,defines:s={},hookFunctions:c=[],inject:a={},prologue:l=!0,log:h}=t;F(typeof n=="string","shader source must be a string");let f=r==="glsl"?oe(n).version:-1,p=e.shaderLanguageVersion,m=f===100?"#version 100":"#version 300 es",_=n.split(`
66
66
  `).slice(1).join(`
67
- `),d={};r.forEach(p=>{Object.assign(d,p.defines)}),Object.assign(d,a);let c="";switch(n){case"wgsl":break;case"glsl":c=f?`${I}
67
+ `),d={};o.forEach(u=>{Object.assign(d,u.defines)}),Object.assign(d,s);let g="";switch(r){case"wgsl":break;case"glsl":g=l?`${m}
68
68
 
69
69
  // ----- PROLOGUE -------------------------
70
70
  ${`#define SHADER_TYPE_${i.toUpperCase()}`}
71
71
 
72
- ${Oe(e)}
73
- ${i==="fragment"?Ot:""}
72
+ ${Qe(e)}
73
+ ${i==="fragment"?Ln:""}
74
74
 
75
75
  // ----- APPLICATION DEFINES -------------------------
76
76
 
77
- ${Tt(d)}
77
+ ${En(d)}
78
78
 
79
- `:`${I}
80
- `;break}let _=ae(s),h={},V={},A={};for(let p in l){let P=typeof l[p]=="string"?{injection:l[p],order:0}:l[p],L=/^(v|f)s:(#)?([\w-]+)$/.exec(p);if(L){let m=L[2],j=L[3];m?j==="decl"?V[p]=[P]:A[p]=[P]:h[p]=[P]}else A[p]=[P]}for(let p of r){G&&F(p,u,G);let P=X(p,i);c+=P;let L=p.instance?.normalizedInjections[i]||{};for(let m in L){let j=/^(v|f)s:#([\w-]+)$/.exec(m);if(j){let ee=j[2]==="decl"?V:A;ee[m]=ee[m]||[],ee[m].push(L[m])}else h[m]=h[m]||[],h[m].push(L[m])}}return c+="// ----- MAIN SHADER SOURCE -------------------------",c+=De,c=T(c,i,V),c+=ne(_[i],h),c+=u,c=T(c,i,A),n==="glsl"&&b!==N&&(c=Te(c,i)),c.trim()}function Be(e){return function(o){let i={};for(let n of e){let r=n.getUniforms?.(o,i);Object.assign(i,r)}return i}}function Tt(e={}){let t="";for(let o in e){let i=e[o];(i||Number.isFinite(i))&&(t+=`#define ${o.toUpperCase()} ${e[o]}
81
- `)}return t}function X(e,t){let o;switch(t){case"vertex":o=e.vs||"";break;case"fragment":o=e.fs||"";break;case"wgsl":o=e.source||"";break;default:S(!1)}if(!e.name)throw new Error("Shader module must have a name");let i=e.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),n=`// ----- MODULE ${e.name} ---------------
79
+ `:`${m}
80
+ `;break}let A=Se(c),v={},M={},b={};for(let u in a){let I=typeof a[u]=="string"?{injection:a[u],order:0}:a[u],E=/^(v|f)s:(#)?([\w-]+)$/.exec(u);if(E){let L=E[2],P=E[3];L?P==="decl"?M[u]=[I]:b[u]=[I]:v[u]=[I]}else b[u]=[I]}for(let u of o){h&&$(u,_,h);let I=ce(u,i);g+=I;let E=u.instance?.normalizedInjections[i]||{};for(let L in E){let P=/^(v|f)s:#([\w-]+)$/.exec(L);if(P){let R=P[2]==="decl"?M:b;R[L]=R[L]||[],R[L].push(E[L])}else v[L]=v[L]||[],v[L].push(E[L])}}return g+="// ----- MAIN SHADER SOURCE -------------------------",g+=rt,g=W(g,i,M),g+=Le(A[i],v),g+=_,g=W(g,i,b),r==="glsl"&&f!==p&&(g=tt(g,i)),g.trim()}function st(e){return function(n){let i={};for(let r of e){let o=r.getUniforms?.(n,i);Object.assign(i,o)}return i}}function En(e={}){let t="";for(let n in e){let i=e[n];(i||Number.isFinite(i))&&(t+=`#define ${n.toUpperCase()} ${e[n]}
81
+ `)}return t}function ce(e,t){let n;switch(t){case"vertex":n=e.vs||"";break;case"fragment":n=e.fs||"";break;case"wgsl":n=e.source||"";break;default:F(!1)}if(!e.name)throw new Error("Shader module must have a name");let i=e.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),r=`// ----- MODULE ${e.name} ---------------
82
82
 
83
- `;return t!=="wgsl"&&(n+=`#define MODULE_${i}
84
- `),n+=`${o}
85
- `,n}var Ft=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,yt=/^\s*\#\s*endif\s*$/;function Y(e,t){let o=e.split(`
86
- `),i=[],n=!0,r=null;for(let a of o){let s=a.match(Ft),l=a.match(yt);s?(r=s[1],n=Boolean(t?.defines?.[r])):l?n=!0:n&&i.push(a)}return i.join(`
87
- `)}var C=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return C.defaultShaderAssembler=C.defaultShaderAssembler||new C,C.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(o=>o.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let o=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(i=>i.name!==o)}addShaderHook(t,o){o&&(t=Object.assign(o,{hook:t})),this._hookFunctions.push(t)}assembleWGSLShader(t){let o=this._getModuleList(t.modules),i=this._hookFunctions,{source:n,getUniforms:r}=we({...t,source:t.source,modules:o,hookFunctions:i});return{source:t.platformInfo.shaderLanguage==="wgsl"?Y(n):n,getUniforms:r,modules:o}}assembleGLSLShaderPair(t){let o=this._getModuleList(t.modules),i=this._hookFunctions;return{...K({...t,vs:t.vs,fs:t.fs,modules:o,hookFunctions:i}),modules:o}}_getModuleList(t=[]){let o=new Array(this._defaultModules.length+t.length),i={},n=0;for(let r=0,a=this._defaultModules.length;r<a;++r){let s=this._defaultModules[r],l=s.name;o[n++]=s,i[l]=!0}for(let r=0,a=t.length;r<a;++r){let s=t[r],l=s.name;i[l]||(o[n++]=s,i[l]=!0)}return o.length=n,v(o),o}},w=C;he(w,"defaultShaderAssembler");var Dt=`out vec4 transform_output;
83
+ `;return t!=="wgsl"&&(r+=`#define MODULE_${i}
84
+ `),r+=`${n}
85
+ `,r}var In=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Pn=/^\s*\#\s*ifndef\s*([a-zA-Z_]+)\s*(?:\/\/.*)?$/,Rn=/^\s*\#\s*else\s*(?:\/\/.*)?$/,Cn=/^\s*\#\s*endif\s*$/,On=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*(?:\/\/.*)?$/,Nn=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function ae(e,t){let n=e.split(`
86
+ `),i=[],r=[],o=!0;for(let s of n){let c=s.match(On)||s.match(In),a=s.match(Pn),l=s.match(Rn),h=s.match(Nn)||s.match(Cn);if(c||a){let f=(c||a)?.[1],p=Boolean(t?.defines?.[f]),m=c?p:!p,x=o&&m;r.push({parentActive:o,branchTaken:m,active:x}),o=x}else if(l){let f=r[r.length-1];if(!f)throw new Error("Encountered #else without matching #ifdef or #ifndef");f.active=f.parentActive&&!f.branchTaken,f.branchTaken=!0,o=f.active}else h?(r.pop(),o=r.length?r[r.length-1].active:!0):o&&i.push(s)}if(r.length>0)throw new Error("Unterminated conditional block in shader source");return i.join(`
87
+ `)}var B=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return B.defaultShaderAssembler=B.defaultShaderAssembler||new B,B.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(n=>n.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let n=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(i=>i.name!==n)}addShaderHook(t,n){n&&(t=Object.assign(n,{hook:t})),this._hookFunctions.push(t)}assembleWGSLShader(t){let n=this._getModuleList(t.modules),i=this._hookFunctions,{source:r,getUniforms:o}=ot({...t,source:t.source,modules:n,hookFunctions:i}),s={...n.reduce((a,l)=>(Object.assign(a,l.defines),a),{}),...t.defines};return{source:t.platformInfo.shaderLanguage==="wgsl"?ae(r,{defines:s}):r,getUniforms:o,modules:n}}assembleGLSLShaderPair(t){let n=this._getModuleList(t.modules),i=this._hookFunctions;return{...se({...t,vs:t.vs,fs:t.fs,modules:n,hookFunctions:i}),modules:n}}_getModuleList(t=[]){let n=new Array(this._defaultModules.length+t.length),i={},r=0;for(let o=0,s=this._defaultModules.length;o<s;++o){let c=this._defaultModules[o],a=c.name;n[r++]=c,i[a]=!0}for(let o=0,s=t.length;o<s;++o){let c=t[o],a=c.name;i[a]||(n[r++]=c,i[a]=!0)}return n.length=r,T(n),n}},X=B;ze(X,"defaultShaderAssembler");var yn=`out vec4 transform_output;
88
88
  void main() {
89
89
  transform_output = vec4(0);
90
- }`,wt=`#version 300 es
91
- ${Dt}`;function Ue(e,t){t=Array.isArray(t)?t:[t];let o=e.replace(/^\s+/,"").split(/\s+/),[i,n,r]=o;if(!t.includes(i)||!n||!r)return null;let a=r.split(";")[0];return{qualifier:i,type:n,name:a}}function ke(e){let{input:t,inputChannels:o,output:i}=e||{};if(!t)return wt;if(!o)throw new Error("inputChannels");let n=Bt(o),r=le(t,o);return`#version 300 es
92
- in ${n} ${t};
90
+ }`,Tn=`#version 300 es
91
+ ${yn}`;function ct(e,t){t=Array.isArray(t)?t:[t];let n=e.replace(/^\s+/,"").split(/\s+/),[i,r,o]=n;if(!t.includes(i)||!r||!o)return null;let s=o.split(";")[0];return{qualifier:i,type:r,name:s}}function at(e){let{input:t,inputChannels:n,output:i}=e||{};if(!t)return Tn;if(!n)throw new Error("inputChannels");let r=Fn(n),o=Ee(t,n);return`#version 300 es
92
+ in ${r} ${t};
93
93
  out vec4 ${i};
94
94
  void main() {
95
- ${i} = ${r};
96
- }`}function He(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 Ge(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 Bt(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 le(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 E(e){return typeof e=="string"?e.charAt(0).toUpperCase()+e.slice(1):e}function Ve(e,t){return Ut(e,t)}function Ut(e,t){let o=[];switch(t.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":o.push(`uniform ${E(e.name)} {`);break;case"uniforms":}for(let[i,n]of Object.entries(e.uniformTypes||{})){let r=kt(n);switch(t.uniforms){case"scoped-interface-blocks":o.push(` ${r} ${i};`);break;case"unscoped-interface-blocks":o.push(` ${r} ${e.name}_${i};`);break;case"uniforms":o.push(`uniform ${r} ${e.name}_${i};`)}}switch(t.uniforms){case"scoped-interface-blocks":o.push(`} ${e.name};`);break;case"unscoped-interface-blocks":o.push("};");break;case"uniforms":}return o.push(""),o.join(`
97
- `)}function kt(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 je(e,t){return Ht(e,t)}function Ht(e,t){let o=[];o.push(`struct ${E(e.name)} {`);for(let[i,n]of Object.entries(e?.uniformTypes||{})){let r=n;o.push(` ${i} : ${r};`)}return o.push("};"),o.push(`var<uniform> ${e.name} : ${E(e.name)};`),o.join(`
98
- `)}function ze(e,t){switch(t.shaderLanguage){case"glsl":return Ve(e,t);case"wgsl":return je(e,t)}}var Zo=1/Math.PI*180,Qo=1/180*Math.PI,Gt={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Gt}};var Vt=globalThis.mathgl.config;function qe(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function se(e,t,o){return zt(e,i=>Math.max(t,Math.min(o,i)))}function jt(e){return e.clone?e.clone():new Array(e.length)}function zt(e,t,o){if(qe(e)){let i=e;o=o||jt(i);for(let n=0;n<o.length&&n<i.length;++n){let r=typeof e=="number"?e:e[n];o[n]=t(r,n,o)}return o}return t(e)}var x=null,We=new ArrayBuffer(4),$e=new Float32Array(We),Ke=new Uint32Array(We);function Xe(e){x||=Je(),e=se(e,-65504,65504),$e[0]=e;let t=Ke[0],o=t>>23&511;return x.baseTable[o]+((t&8388607)>>x.shiftTable[o])}function Ye(e){x||=Je();let t=e>>10;return Ke[0]=x.mantissaTable[x.offsetTable[t]+(e&1023)]+x.exponentTable[t],$e[0]}function Je(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let r=0;r<256;++r){let a=r-127;a<-27?(e[r]=0,e[r|256]=32768,t[r]=24,t[r|256]=24):a<-14?(e[r]=1024>>-a-14,e[r|256]=1024>>-a-14|32768,t[r]=-a-1,t[r|256]=-a-1):a<=15?(e[r]=a+15<<10,e[r|256]=a+15<<10|32768,t[r]=13,t[r|256]=13):a<128?(e[r]=31744,e[r|256]=64512,t[r]=24,t[r|256]=24):(e[r]=31744,e[r|256]=64512,t[r]=13,t[r|256]=13)}let o=new Uint32Array(2048),i=new Uint32Array(64),n=new Uint32Array(64);for(let r=1;r<1024;++r){let a=r<<13,s=0;for(;!(a&8388608);)a<<=1,s-=8388608;a&=-8388609,s+=947912704,o[r]=a|s}for(let r=1024;r<2048;++r)o[r]=939524096+(r-1024<<13);for(let r=1;r<31;++r)i[r]=r<<23;i[31]=1199570944,i[32]=2147483648;for(let r=33;r<63;++r)i[r]=2147483648+(r-32<<23);i[63]=3347054592;for(let r=1;r<64;++r)r!==32&&(n[r]=1024);return{baseTable:e,shiftTable:t,mantissaTable:o,exponentTable:i,offsetTable:n}}function R(e,t=[],o=0){let i=Math.fround(e),n=e-i;return t[o]=i,t[o+1]=n,t}function B(e){return e-Math.fround(e)}function U(e){let t=new Float32Array(32);for(let o=0;o<4;++o)for(let i=0;i<4;++i){let n=o*4+i;R(e[i*4+o],t,n*2)}return t}var qt=`fn random(scale: vec3f, seed: float) -> f32 {
99
- /* use the fragment position for a different seed per-pixel */
100
- return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
95
+ ${i} = ${o};
96
+ }`}function lt(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 ft(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 Fn(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 Ee(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 pt(e,t){return wn(e,t)}function wn(e,t){let n=[];switch(t.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":n.push(`uniform ${D(e.name)} {`);break;case"uniforms":}for(let[i,r]of Object.entries(e.uniformTypes||{})){let o=kn(r);switch(t.uniforms){case"scoped-interface-blocks":n.push(` ${o} ${i};`);break;case"unscoped-interface-blocks":n.push(` ${o} ${e.name}_${i};`);break;case"uniforms":n.push(`uniform ${o} ${e.name}_${i};`)}}switch(t.uniforms){case"scoped-interface-blocks":n.push(`} ${e.name};`);break;case"unscoped-interface-blocks":n.push("};");break;case"uniforms":}return n.push(""),n.join(`
97
+ `)}function kn(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 ht(e,t){return Dn(e,t)}function Dn(e,t){let n=[];n.push(`struct ${D(e.name)} {`);for(let[i,r]of Object.entries(e?.uniformTypes||{})){let o=r;n.push(` ${i} : ${o};`)}return n.push("};"),n.push(`var<uniform> ${e.name} : ${D(e.name)};`),n.join(`
98
+ `)}function gt(e,t){switch(t.shaderLanguage){case"glsl":return pt(e,t);case"wgsl":return ht(e,t)}}var lr=1/Math.PI*180,fr=1/180*Math.PI,Un={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Un}};var C=globalThis.mathgl.config;function Ie(e,{precision:t=C.precision}={}){return e=Bn(e),`${parseFloat(e.toPrecision(t))}`}function z(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Pe(e,t,n){return Hn(e,i=>Math.max(t,Math.min(n,i)))}function le(e,t,n){let i=C.EPSILON;n&&(C.EPSILON=n);try{if(e===t)return!0;if(z(e)&&z(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;++r)if(!le(e[r],t[r]))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)<=C.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{C.EPSILON=i}}function Bn(e){return Math.round(e/C.EPSILON)*C.EPSILON}function zn(e){return e.clone?e.clone():new Array(e.length)}function Hn(e,t,n){if(z(e)){let i=e;n=n||zn(i);for(let r=0;r<n.length&&r<i.length;++r){let o=typeof e=="number"?e:e[r];n[r]=t(o,r,n)}return n}return t(e)}var fe=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,n=0){for(let i=0;i<this.ELEMENTS;++i)this[i]=t[i+n];return this.check()}toArray(t=[],n=0){for(let i=0;i<this.ELEMENTS;++i)t[n+i]=this[i];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:z(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(C)}formatString(t){let n="";for(let i=0;i<this.ELEMENTS;++i)n+=(i>0?", ":"")+Ie(this[i],t);return`${t.printTypes?this.constructor.name:""}[${n}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(!le(this[n],t[n]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==t[n])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,n,i){if(i===void 0)return this.lerp(this,t,n);for(let r=0;r<this.ELEMENTS;++r){let o=t[r],s=typeof n=="number"?n:n[r];this[r]=o+i*(s-o)}return this.check()}min(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(t[n],this[n]);return this.check()}max(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(t[n],this[n]);return this.check()}clamp(t,n){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.min(Math.max(this[i],t[i]),n[i]);return this.check()}add(...t){for(let n of t)for(let i=0;i<this.ELEMENTS;++i)this[i]+=n[i];return this.check()}subtract(...t){for(let n of t)for(let i=0;i<this.ELEMENTS;++i)this[i]-=n[i];return this.check()}scale(t){if(typeof t=="number")for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;else for(let n=0;n<this.ELEMENTS&&n<t.length;++n)this[n]*=t[n];return this.check()}multiplyByScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}check(){if(C.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 n=0;n<this.ELEMENTS;++n)t=t&&Number.isFinite(this[n]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=t;return this.check()}addScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,n){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.min(Math.max(this[i],t),n);return this.check()}get elements(){return this}};function Gn(e,t){if(e.length!==t)return!1;for(let n=0;n<e.length;++n)if(!Number.isFinite(e[n]))return!1;return!0}function mt(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function pe(e,t,n=""){if(C.debug&&!Gn(e,t))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return e}var w=typeof Float32Array<"u"?Float32Array:Array;var ur=Math.PI/180;function Vn(){let e=new w(2);return w!=Float32Array&&(e[0]=0,e[1]=0),e}function dt(e,t,n){let i=t[0],r=t[1];return e[0]=n[0]*i+n[4]*r+n[12],e[1]=n[1]*i+n[5]*r+n[13],e}var dr=function(){let e=Vn();return function(t,n,i,r,o,s){let c,a;for(n||(n=2),i||(i=0),r?a=Math.min(r*n+i,t.length):a=t.length,c=i;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],o(e,e,s),t[c]=e[0],t[c+1]=e[1];return t}}();function vt(e,t,n){let i=t[0],r=t[1],o=n[3]*i+n[7]*r||1;return e[0]=(n[0]*i+n[4]*r)/o,e[1]=(n[1]*i+n[5]*r)/o,e}function xt(e,t,n){let i=t[0],r=t[1],o=t[2],s=n[3]*i+n[7]*r+n[11]*o||1;return e[0]=(n[0]*i+n[4]*r+n[8]*o)/s,e[1]=(n[1]*i+n[5]*r+n[9]*o)/s,e[2]=(n[2]*i+n[6]*r+n[10]*o)/s,e}function jn(){let e=new w(3);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function bt(e,t,n){let i=t[0],r=t[1],o=t[2],s=n[3]*i+n[7]*r+n[11]*o+n[15];return s=s||1,e[0]=(n[0]*i+n[4]*r+n[8]*o+n[12])/s,e[1]=(n[1]*i+n[5]*r+n[9]*o+n[13])/s,e[2]=(n[2]*i+n[6]*r+n[10]*o+n[14])/s,e}var br=function(){let e=jn();return function(t,n,i,r,o,s){let c,a;for(n||(n=3),i||(i=0),r?a=Math.min(r*n+i,t.length):a=t.length,c=i;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],e[2]=t[c+2],o(e,e,s),t[c]=e[0],t[c+1]=e[1],t[c+2]=e[2];return t}}();var he=class extends fe{toString(){let t="[";if(C.printRowMajor){t+="row-major:";for(let n=0;n<this.RANK;++n)for(let i=0;i<this.RANK;++i)t+=` ${this[i*this.RANK+n]}`}else{t+="column-major:";for(let n=0;n<this.ELEMENTS;++n)t+=` ${this[n]}`}return t+="]",t}getElementIndex(t,n){return n*this.RANK+t}getElement(t,n){return this[n*this.RANK+t]}setElement(t,n,i){return this[n*this.RANK+t]=mt(i),this}getColumn(t,n=new Array(this.RANK).fill(-0)){let i=t*this.RANK;for(let r=0;r<this.RANK;++r)n[r]=this[i+r];return n}setColumn(t,n){let i=t*this.RANK;for(let r=0;r<this.RANK;++r)this[i+r]=n[r];return this}};function qn(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 Mt(e,t){if(e===t){let n=t[1],i=t[2],r=t[3],o=t[6],s=t[7],c=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=i,e[9]=o,e[11]=t[14],e[12]=r,e[13]=s,e[14]=c}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 At(e,t){let n=t[0],i=t[1],r=t[2],o=t[3],s=t[4],c=t[5],a=t[6],l=t[7],h=t[8],f=t[9],p=t[10],m=t[11],x=t[12],_=t[13],d=t[14],g=t[15],A=n*c-i*s,v=n*a-r*s,M=n*l-o*s,b=i*a-r*c,u=i*l-o*c,I=r*l-o*a,E=h*_-f*x,L=h*d-p*x,P=h*g-m*x,O=f*d-p*_,R=f*g-m*_,N=p*g-m*d,S=A*N-v*R+M*O+b*P-u*L+I*E;return S?(S=1/S,e[0]=(c*N-a*R+l*O)*S,e[1]=(r*R-i*N-o*O)*S,e[2]=(_*I-d*u+g*b)*S,e[3]=(p*u-f*I-m*b)*S,e[4]=(a*P-s*N-l*L)*S,e[5]=(n*N-r*P+o*L)*S,e[6]=(d*M-x*I-g*v)*S,e[7]=(h*I-p*M+m*v)*S,e[8]=(s*R-c*P+l*E)*S,e[9]=(i*P-n*R-o*E)*S,e[10]=(x*u-_*M+g*A)*S,e[11]=(f*M-h*u-m*A)*S,e[12]=(c*L-s*O-a*E)*S,e[13]=(n*O-i*L+r*E)*S,e[14]=(_*v-x*b-d*A)*S,e[15]=(h*b-f*v+p*A)*S,e):null}function Lt(e){let t=e[0],n=e[1],i=e[2],r=e[3],o=e[4],s=e[5],c=e[6],a=e[7],l=e[8],h=e[9],f=e[10],p=e[11],m=e[12],x=e[13],_=e[14],d=e[15],g=t*s-n*o,A=t*c-i*o,v=n*c-i*s,M=l*x-h*m,b=l*_-f*m,u=h*_-f*x,I=t*u-n*b+i*M,E=o*u-s*b+c*M,L=l*v-h*A+f*g,P=m*v-x*A+_*g;return a*I-r*E+d*L-p*P}function Ce(e,t,n){let i=t[0],r=t[1],o=t[2],s=t[3],c=t[4],a=t[5],l=t[6],h=t[7],f=t[8],p=t[9],m=t[10],x=t[11],_=t[12],d=t[13],g=t[14],A=t[15],v=n[0],M=n[1],b=n[2],u=n[3];return e[0]=v*i+M*c+b*f+u*_,e[1]=v*r+M*a+b*p+u*d,e[2]=v*o+M*l+b*m+u*g,e[3]=v*s+M*h+b*x+u*A,v=n[4],M=n[5],b=n[6],u=n[7],e[4]=v*i+M*c+b*f+u*_,e[5]=v*r+M*a+b*p+u*d,e[6]=v*o+M*l+b*m+u*g,e[7]=v*s+M*h+b*x+u*A,v=n[8],M=n[9],b=n[10],u=n[11],e[8]=v*i+M*c+b*f+u*_,e[9]=v*r+M*a+b*p+u*d,e[10]=v*o+M*l+b*m+u*g,e[11]=v*s+M*h+b*x+u*A,v=n[12],M=n[13],b=n[14],u=n[15],e[12]=v*i+M*c+b*f+u*_,e[13]=v*r+M*a+b*p+u*d,e[14]=v*o+M*l+b*m+u*g,e[15]=v*s+M*h+b*x+u*A,e}function St(e,t,n){let i=n[0],r=n[1],o=n[2],s,c,a,l,h,f,p,m,x,_,d,g;return t===e?(e[12]=t[0]*i+t[4]*r+t[8]*o+t[12],e[13]=t[1]*i+t[5]*r+t[9]*o+t[13],e[14]=t[2]*i+t[6]*r+t[10]*o+t[14],e[15]=t[3]*i+t[7]*r+t[11]*o+t[15]):(s=t[0],c=t[1],a=t[2],l=t[3],h=t[4],f=t[5],p=t[6],m=t[7],x=t[8],_=t[9],d=t[10],g=t[11],e[0]=s,e[1]=c,e[2]=a,e[3]=l,e[4]=h,e[5]=f,e[6]=p,e[7]=m,e[8]=x,e[9]=_,e[10]=d,e[11]=g,e[12]=s*i+h*r+x*o+t[12],e[13]=c*i+f*r+_*o+t[13],e[14]=a*i+p*r+d*o+t[14],e[15]=l*i+m*r+g*o+t[15]),e}function Et(e,t,n){let i=n[0],r=n[1],o=n[2];return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*r,e[5]=t[5]*r,e[6]=t[6]*r,e[7]=t[7]*r,e[8]=t[8]*o,e[9]=t[9]*o,e[10]=t[10]*o,e[11]=t[11]*o,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function It(e,t,n,i){let r=i[0],o=i[1],s=i[2],c=Math.sqrt(r*r+o*o+s*s),a,l,h,f,p,m,x,_,d,g,A,v,M,b,u,I,E,L,P,O,R,N,S,V;return c<1e-6?null:(c=1/c,r*=c,o*=c,s*=c,l=Math.sin(n),a=Math.cos(n),h=1-a,f=t[0],p=t[1],m=t[2],x=t[3],_=t[4],d=t[5],g=t[6],A=t[7],v=t[8],M=t[9],b=t[10],u=t[11],I=r*r*h+a,E=o*r*h+s*l,L=s*r*h-o*l,P=r*o*h-s*l,O=o*o*h+a,R=s*o*h+r*l,N=r*s*h+o*l,S=o*s*h-r*l,V=s*s*h+a,e[0]=f*I+_*E+v*L,e[1]=p*I+d*E+M*L,e[2]=m*I+g*E+b*L,e[3]=x*I+A*E+u*L,e[4]=f*P+_*O+v*R,e[5]=p*P+d*O+M*R,e[6]=m*P+g*O+b*R,e[7]=x*P+A*O+u*R,e[8]=f*N+_*S+v*V,e[9]=p*N+d*S+M*V,e[10]=m*N+g*S+b*V,e[11]=x*N+A*S+u*V,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function Pt(e,t,n){let i=Math.sin(n),r=Math.cos(n),o=t[4],s=t[5],c=t[6],a=t[7],l=t[8],h=t[9],f=t[10],p=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]=o*r+l*i,e[5]=s*r+h*i,e[6]=c*r+f*i,e[7]=a*r+p*i,e[8]=l*r-o*i,e[9]=h*r-s*i,e[10]=f*r-c*i,e[11]=p*r-a*i,e}function Rt(e,t,n){let i=Math.sin(n),r=Math.cos(n),o=t[0],s=t[1],c=t[2],a=t[3],l=t[8],h=t[9],f=t[10],p=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]=o*r-l*i,e[1]=s*r-h*i,e[2]=c*r-f*i,e[3]=a*r-p*i,e[8]=o*i+l*r,e[9]=s*i+h*r,e[10]=c*i+f*r,e[11]=a*i+p*r,e}function Ct(e,t,n){let i=Math.sin(n),r=Math.cos(n),o=t[0],s=t[1],c=t[2],a=t[3],l=t[4],h=t[5],f=t[6],p=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]=o*r+l*i,e[1]=s*r+h*i,e[2]=c*r+f*i,e[3]=a*r+p*i,e[4]=l*r-o*i,e[5]=h*r-s*i,e[6]=f*r-c*i,e[7]=p*r-a*i,e}function Ot(e,t){let n=t[0],i=t[1],r=t[2],o=t[3],s=n+n,c=i+i,a=r+r,l=n*s,h=i*s,f=i*c,p=r*s,m=r*c,x=r*a,_=o*s,d=o*c,g=o*a;return e[0]=1-f-x,e[1]=h+g,e[2]=p-d,e[3]=0,e[4]=h-g,e[5]=1-l-x,e[6]=m+_,e[7]=0,e[8]=p+d,e[9]=m-_,e[10]=1-l-f,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Nt(e,t,n,i,r,o,s){let c=1/(n-t),a=1/(r-i),l=1/(o-s);return e[0]=o*2*c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o*2*a,e[6]=0,e[7]=0,e[8]=(n+t)*c,e[9]=(r+i)*a,e[10]=(s+o)*l,e[11]=-1,e[12]=0,e[13]=0,e[14]=s*o*2*l,e[15]=0,e}function Wn(e,t,n,i,r){let o=1/Math.tan(t/2);if(e[0]=o/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,r!=null&&r!==1/0){let s=1/(i-r);e[10]=(r+i)*s,e[14]=2*r*i*s}else e[10]=-1,e[14]=-2*i;return e}var yt=Wn;function $n(e,t,n,i,r,o,s){let c=1/(t-n),a=1/(i-r),l=1/(o-s);return e[0]=-2*c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*a,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+n)*c,e[13]=(r+i)*a,e[14]=(s+o)*l,e[15]=1,e}var Tt=$n;function Ft(e,t,n,i){let r,o,s,c,a,l,h,f,p,m,x=t[0],_=t[1],d=t[2],g=i[0],A=i[1],v=i[2],M=n[0],b=n[1],u=n[2];return Math.abs(x-M)<1e-6&&Math.abs(_-b)<1e-6&&Math.abs(d-u)<1e-6?qn(e):(f=x-M,p=_-b,m=d-u,r=1/Math.sqrt(f*f+p*p+m*m),f*=r,p*=r,m*=r,o=A*m-v*p,s=v*f-g*m,c=g*p-A*f,r=Math.sqrt(o*o+s*s+c*c),r?(r=1/r,o*=r,s*=r,c*=r):(o=0,s=0,c=0),a=p*c-m*s,l=m*o-f*c,h=f*s-p*o,r=Math.sqrt(a*a+l*l+h*h),r?(r=1/r,a*=r,l*=r,h*=r):(a=0,l=0,h=0),e[0]=o,e[1]=a,e[2]=f,e[3]=0,e[4]=s,e[5]=l,e[6]=p,e[7]=0,e[8]=c,e[9]=h,e[10]=m,e[11]=0,e[12]=-(o*x+s*_+c*d),e[13]=-(a*x+l*_+h*d),e[14]=-(f*x+p*_+m*d),e[15]=1,e)}function Yn(){let e=new w(4);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function wt(e,t,n){let i=t[0],r=t[1],o=t[2],s=t[3];return e[0]=n[0]*i+n[4]*r+n[8]*o+n[12]*s,e[1]=n[1]*i+n[5]*r+n[9]*o+n[13]*s,e[2]=n[2]*i+n[6]*r+n[10]*o+n[14]*s,e[3]=n[3]*i+n[7]*r+n[11]*o+n[15]*s,e}var Pr=function(){let e=Yn();return function(t,n,i,r,o,s){let c,a;for(n||(n=4),i||(i=0),r?a=Math.min(r*n+i,t.length):a=t.length,c=i;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],e[2]=t[c+2],e[3]=t[c+3],o(e,e,s),t[c]=e[0],t[c+1]=e[1],t[c+2]=e[2],t[c+3]=e[3];return t}}();var ye;(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"})(ye||(ye={}));var Kn=45*Math.PI/180,Xn=1,Oe=.1,Ne=500,Zn=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),k=class extends he{static get IDENTITY(){return Qn()}static get ZERO(){return Jn()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return ye}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,n,i,r,o,s,c,a,l,h,f,p,m,x,_,d){return this[0]=t,this[1]=n,this[2]=i,this[3]=r,this[4]=o,this[5]=s,this[6]=c,this[7]=a,this[8]=l,this[9]=h,this[10]=f,this[11]=p,this[12]=m,this[13]=x,this[14]=_,this[15]=d,this.check()}setRowMajor(t,n,i,r,o,s,c,a,l,h,f,p,m,x,_,d){return this[0]=t,this[1]=o,this[2]=l,this[3]=m,this[4]=n,this[5]=s,this[6]=h,this[7]=x,this[8]=i,this[9]=c,this[10]=f,this[11]=_,this[12]=r,this[13]=a,this[14]=p,this[15]=d,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(Zn)}fromObject(t){return this.check()}fromQuaternion(t){return Ot(this,t),this.check()}frustum(t){let{left:n,right:i,bottom:r,top:o,near:s=Oe,far:c=Ne}=t;return c===1/0?ei(this,n,i,r,o,s):Nt(this,n,i,r,o,s,c),this.check()}lookAt(t){let{eye:n,center:i=[0,0,0],up:r=[0,1,0]}=t;return Ft(this,n,i,r),this.check()}ortho(t){let{left:n,right:i,bottom:r,top:o,near:s=Oe,far:c=Ne}=t;return Tt(this,n,i,r,o,s,c),this.check()}orthographic(t){let{fovy:n=Kn,aspect:i=Xn,focalDistance:r=1,near:o=Oe,far:s=Ne}=t;kt(n);let c=n/2,a=r*Math.tan(c),l=a*i;return this.ortho({left:-l,right:l,bottom:-a,top:a,near:o,far:s})}perspective(t){let{fovy:n=45*Math.PI/180,aspect:i=1,near:r=.1,far:o=500}=t;return kt(n),yt(this,n,i,r,o),this.check()}determinant(){return Lt(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,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let i=this.getScale(n),r=1/i[0],o=1/i[1],s=1/i[2];return t[0]=this[0]*r,t[1]=this[1]*o,t[2]=this[2]*s,t[3]=0,t[4]=this[4]*r,t[5]=this[5]*o,t[6]=this[6]*s,t[7]=0,t[8]=this[8]*r,t[9]=this[9]*o,t[10]=this[10]*s,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let i=this.getScale(n),r=1/i[0],o=1/i[1],s=1/i[2];return t[0]=this[0]*r,t[1]=this[1]*o,t[2]=this[2]*s,t[3]=this[4]*r,t[4]=this[5]*o,t[5]=this[6]*s,t[6]=this[8]*r,t[7]=this[9]*o,t[8]=this[10]*s,t}transpose(){return Mt(this,this),this.check()}invert(){return At(this,this),this.check()}multiplyLeft(t){return Ce(this,t,this),this.check()}multiplyRight(t){return Ce(this,this,t),this.check()}rotateX(t){return Pt(this,this,t),this.check()}rotateY(t){return Rt(this,this,t),this.check()}rotateZ(t){return Ct(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,n){return It(this,this,t,n),this.check()}scale(t){return Et(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return St(this,this,t),this.check()}transform(t,n){return t.length===4?(n=wt(n||[-0,-0,-0,-0],t,this),pe(n,4),n):this.transformAsPoint(t,n)}transformAsPoint(t,n){let{length:i}=t,r;switch(i){case 2:r=dt(n||[-0,-0],t,this);break;case 3:r=bt(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return pe(r,t.length),r}transformAsVector(t,n){let i;switch(t.length){case 2:i=vt(n||[-0,-0],t,this);break;case 3:i=xt(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return pe(i,t.length),i}transformPoint(t,n){return this.transformAsPoint(t,n)}transformVector(t,n){return this.transformAsPoint(t,n)}transformDirection(t,n){return this.transformAsVector(t,n)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,n,i){return this.identity().translate([t,n,i])}},ge,me;function Jn(){return ge||(ge=new k([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(ge)),ge}function Qn(){return me||(me=new k,Object.freeze(me)),me}function kt(e){if(e>Math.PI*2)throw Error("expected radians")}function ei(e,t,n,i,r,o){let s=2*o/(n-t),c=2*o/(r-i),a=(n+t)/(n-t),l=(r+i)/(r-i),h=-1,f=-1,p=-2*o;return e[0]=s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=c,e[6]=0,e[7]=0,e[8]=a,e[9]=l,e[10]=h,e[11]=f,e[12]=0,e[13]=0,e[14]=p,e[15]=0,e}var U=null,Dt=new ArrayBuffer(4),Ut=new Float32Array(Dt),Bt=new Uint32Array(Dt);function zt(e){U||=Gt(),e=Pe(e,-65504,65504),Ut[0]=e;let t=Bt[0],n=t>>23&511;return U.baseTable[n]+((t&8388607)>>U.shiftTable[n])}function Ht(e){U||=Gt();let t=e>>10;return Bt[0]=U.mantissaTable[U.offsetTable[t]+(e&1023)]+U.exponentTable[t],Ut[0]}function Gt(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let o=0;o<256;++o){let s=o-127;s<-27?(e[o]=0,e[o|256]=32768,t[o]=24,t[o|256]=24):s<-14?(e[o]=1024>>-s-14,e[o|256]=1024>>-s-14|32768,t[o]=-s-1,t[o|256]=-s-1):s<=15?(e[o]=s+15<<10,e[o|256]=s+15<<10|32768,t[o]=13,t[o|256]=13):s<128?(e[o]=31744,e[o|256]=64512,t[o]=24,t[o|256]=24):(e[o]=31744,e[o|256]=64512,t[o]=13,t[o|256]=13)}let n=new Uint32Array(2048),i=new Uint32Array(64),r=new Uint32Array(64);for(let o=1;o<1024;++o){let s=o<<13,c=0;for(;!(s&8388608);)s<<=1,c-=8388608;s&=-8388609,c+=947912704,n[o]=s|c}for(let o=1024;o<2048;++o)n[o]=939524096+(o-1024<<13);for(let o=1;o<31;++o)i[o]=o<<23;i[31]=1199570944,i[32]=2147483648;for(let o=33;o<63;++o)i[o]=2147483648+(o-32<<23);i[63]=3347054592;for(let o=1;o<64;++o)o!==32&&(r[o]=1024);return{baseTable:e,shiftTable:t,mantissaTable:n,exponentTable:i,offsetTable:r}}function G(e,t=[],n=0){let i=Math.fround(e),r=e-i;return t[n]=i,t[n+1]=r,t}function Z(e){return e-Math.fround(e)}function J(e){let t=new Float32Array(32);for(let n=0;n<4;++n)for(let i=0;i<4;++i){let r=n*4+i;G(e[i*4+n],t,r*2)}return t}var ti=`fn random(scale: vec3f, seed: f32) -> f32 {
99
+ return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
101
100
  }
102
- `,Wt=`float random(vec3 scale, float seed) {
101
+ `,ni=`float random(vec3 scale, float seed) {
103
102
  /* use the fragment position for a different seed per-pixel */
104
103
  return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
105
104
  }
106
- `,Ze={name:"random",source:qt,fs:Wt};var $t=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
105
+ `,Vt={name:"random",source:ti,fs:ni};var ii=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
107
106
 
108
107
  // All these functions are for substituting tan() function from Intel GPU only
109
108
  const float TWO_PI = 6.2831854820251465;
@@ -253,7 +252,7 @@ float tan_fp32(float a) {
253
252
  return tan(a);
254
253
  #endif
255
254
  }
256
- `,Qe={name:"fp32",vs:$t};var et=`
255
+ `,jt={name:"fp32",vs:ii};var qt=`
257
256
  uniform fp64arithmeticUniforms {
258
257
  uniform float ONE;
259
258
  } fp64;
@@ -421,7 +420,7 @@ vec2 sqrt_fp64(vec2 a) {
421
420
  return sum_fp64(vec2(yn, 0.0), prod);
422
421
  #endif
423
422
  }
424
- `;var tt=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
423
+ `;var Wt=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
425
424
  const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
426
425
  const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
427
426
  const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
@@ -1090,7 +1089,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
1090
1089
  vec4_dot_fp64(a, tmp, out_val[i]);
1091
1090
  }
1092
1091
  }
1093
- `;var Kt={ONE:1},ce={name:"fp64arithmetic",vs:et,defaultUniforms:Kt,uniformTypes:{ONE:"f32"},fp64ify:R,fp64LowPart:B,fp64ifyMatrix4:U},ot={name:"fp64",vs:tt,dependencies:[ce],fp64ify:R,fp64LowPart:B,fp64ifyMatrix4:U};var Xt=[0,1,1,1],Yt=`uniform pickingUniforms {
1092
+ `;var ri={ONE:1},Te={name:"fp64arithmetic",vs:qt,defaultUniforms:ri,uniformTypes:{ONE:"f32"},fp64ify:G,fp64LowPart:Z,fp64ifyMatrix4:J},$t={name:"fp64",vs:Wt,dependencies:[Te],fp64ify:G,fp64LowPart:Z,fp64ifyMatrix4:J};var oi=[0,1,1,1],si=`uniform pickingUniforms {
1094
1093
  float isActive;
1095
1094
  float isAttribute;
1096
1095
  float isHighlightActive;
@@ -1161,7 +1160,7 @@ void picking_setPickingAttribute(vec3 value) {
1161
1160
  picking_vRGBcolor_Avalid.rgb = value;
1162
1161
  }
1163
1162
  }
1164
- `,Jt=`uniform pickingUniforms {
1163
+ `,ci=`uniform pickingUniforms {
1165
1164
  float isActive;
1166
1165
  float isAttribute;
1167
1166
  float isHighlightActive;
@@ -1217,7 +1216,32 @@ vec4 picking_filterColor(vec4 color) {
1217
1216
  vec4 highlightColor = picking_filterHighlightColor(color);
1218
1217
  return picking_filterPickingColor(highlightColor);
1219
1218
  }
1220
- `,it={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useFloatColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useFloatColors:!0,highlightedObjectColor:[0,0,0],highlightColor:Xt},vs:Yt,fs:Jt,getUniforms:Zt};function Zt(e={},t){let o={};if(e.highlightedObjectColor!==void 0)if(e.highlightedObjectColor===null)o.isHighlightActive=!1;else{o.isHighlightActive=!0;let i=e.highlightedObjectColor.slice(0,3);o.highlightedObjectColor=i}if(e.highlightColor){let i=Array.from(e.highlightColor,n=>n/255);Number.isFinite(i[3])||(i[3]=1),o.highlightColor=i}return e.isActive!==void 0&&(o.isActive=Boolean(e.isActive),o.isAttribute=Boolean(e.isAttribute)),e.useFloatColors!==void 0&&(o.useFloatColors=Boolean(e.useFloatColors)),o}var nt=de(te(),1);var fe=`precision highp int;
1219
+ `,Yt={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useFloatColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useFloatColors:!0,highlightedObjectColor:[0,0,0],highlightColor:oi},vs:si,fs:ci,getUniforms:ai};function ai(e={},t){let n={};if(e.highlightedObjectColor!==void 0)if(e.highlightedObjectColor===null)n.isHighlightActive=!1;else{n.isHighlightActive=!0;let i=e.highlightedObjectColor.slice(0,3);n.highlightedObjectColor=i}if(e.highlightColor){let i=Array.from(e.highlightColor,r=>r/255);Number.isFinite(i[3])||(i[3]=1),n.highlightColor=i}return e.isActive!==void 0&&(n.isActive=Boolean(e.isActive),n.isAttribute=Boolean(e.isAttribute)),e.useFloatColors!==void 0&&(n.useFloatColors=Boolean(e.useFloatColors)),n}var Q=20,li=`
1220
+ struct skinUniforms {
1221
+ jointMatrix: array<mat4x4<f32>, ${Q}>,
1222
+ };
1223
+
1224
+ @binding(19) @group(0) var<uniform> skin: skinUniforms;
1225
+
1226
+ fn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {
1227
+ return (weights.x * skin.jointMatrix[joints.x])
1228
+ + (weights.y * skin.jointMatrix[joints.y])
1229
+ + (weights.z * skin.jointMatrix[joints.z])
1230
+ + (weights.w * skin.jointMatrix[joints.w]);
1231
+ }
1232
+ `,fi=`
1233
+ uniform skinUniforms {
1234
+ mat4 jointMatrix[SKIN_MAX_JOINTS];
1235
+ } skin;
1236
+
1237
+ mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
1238
+ return (weights.x * skin.jointMatrix[joints.x])
1239
+ + (weights.y * skin.jointMatrix[joints.y])
1240
+ + (weights.z * skin.jointMatrix[joints.z])
1241
+ + (weights.w * skin.jointMatrix[joints.w]);
1242
+ }
1243
+
1244
+ `,pi="",Kt={props:{},uniforms:{},name:"skin",dependencies:[],source:li,vs:fi,fs:pi,defines:{SKIN_MAX_JOINTS:Q},getUniforms:(e={},t)=>{let{scenegraphsFromGLTF:n}=e;if(!n?.gltf?.skins?.[0])return{jointMatrix:[]};let{inverseBindMatrices:i,joints:r,skeleton:o}=n.gltf.skins[0],s=[],c=i.value.length/16;for(let f=0;f<c;f++){let p=i.value.subarray(f*16,f*16+16);s.push(new k(Array.from(p)))}let a=n.gltfNodeIndexToNodeMap.get(o),l={};a.preorderTraversal((f,{worldMatrix:p})=>{l[f.id]=p});let h=new Float32Array(Q*16);for(let f=0;f<Q;++f){let p=r[f];if(p===void 0)break;let m=l[n.gltfNodeIndexToNodeMap.get(p).id],x=s[f],_=new k().copy(m).multiplyRight(x),d=f*16;for(let g=0;g<16;g++)h[d+g]=_[g]}return{jointMatrix:h}},uniformTypes:{jointMatrix:"mat4x4<f32>"},uniformSizes:{jointMatrix:Q}};var Zt=Be(xe(),1);var Fe=`precision highp int;
1221
1245
 
1222
1246
  // #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1223
1247
  struct AmbientLight {
@@ -1258,6 +1282,16 @@ uniform lightingUniforms {
1258
1282
  vec3 lightPosition2;
1259
1283
  vec3 lightDirection2;
1260
1284
  vec3 lightAttenuation2;
1285
+
1286
+ vec3 lightColor3;
1287
+ vec3 lightPosition3;
1288
+ vec3 lightDirection3;
1289
+ vec3 lightAttenuation3;
1290
+
1291
+ vec3 lightColor4;
1292
+ vec3 lightPosition4;
1293
+ vec3 lightDirection4;
1294
+ vec3 lightAttenuation4;
1261
1295
  } lighting;
1262
1296
 
1263
1297
  PointLight lighting_getPointLight(int index) {
@@ -1267,8 +1301,12 @@ PointLight lighting_getPointLight(int index) {
1267
1301
  case 1:
1268
1302
  return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
1269
1303
  case 2:
1270
- default:
1271
1304
  return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
1305
+ case 3:
1306
+ return PointLight(lighting.lightColor3, lighting.lightPosition3, lighting.lightAttenuation3);
1307
+ case 4:
1308
+ default:
1309
+ return PointLight(lighting.lightColor4, lighting.lightPosition4, lighting.lightAttenuation4);
1272
1310
  }
1273
1311
  }
1274
1312
 
@@ -1279,8 +1317,12 @@ DirectionalLight lighting_getDirectionalLight(int index) {
1279
1317
  case 1:
1280
1318
  return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
1281
1319
  case 2:
1282
- default:
1283
1320
  return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
1321
+ case 3:
1322
+ return DirectionalLight(lighting.lightColor3, lighting.lightDirection3);
1323
+ case 4:
1324
+ default:
1325
+ return DirectionalLight(lighting.lightColor4, lighting.lightDirection4);
1284
1326
  }
1285
1327
  }
1286
1328
 
@@ -1291,7 +1333,9 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
1291
1333
  }
1292
1334
 
1293
1335
  // #endif
1294
- `;var rt=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1336
+ `;var Xt=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1337
+ const MAX_LIGHTS: i32 = 5;
1338
+
1295
1339
  struct AmbientLight {
1296
1340
  color: vec3<f32>,
1297
1341
  };
@@ -1309,32 +1353,80 @@ struct DirectionalLight {
1309
1353
 
1310
1354
  struct lightingUniforms {
1311
1355
  enabled: i32,
1312
- pointLightCount: i32,
1356
+ lightType: i32,
1357
+
1313
1358
  directionalLightCount: i32,
1359
+ pointLightCount: i32,
1314
1360
 
1315
1361
  ambientColor: vec3<f32>,
1316
1362
 
1317
- // TODO - support multiple lights by uncommenting arrays below
1318
- lightType: i32,
1319
- lightColor: vec3<f32>,
1320
- lightDirection: vec3<f32>,
1321
- lightPosition: vec3<f32>,
1322
- lightAttenuation: vec3<f32>,
1323
-
1324
- // AmbientLight ambientLight;
1325
- // PointLight pointLight[MAX_LIGHTS];
1326
- // DirectionalLight directionalLight[MAX_LIGHTS];
1363
+ lightColor0: vec3<f32>,
1364
+ lightPosition0: vec3<f32>,
1365
+ lightDirection0: vec3<f32>,
1366
+ lightAttenuation0: vec3<f32>,
1367
+
1368
+ lightColor1: vec3<f32>,
1369
+ lightPosition1: vec3<f32>,
1370
+ lightDirection1: vec3<f32>,
1371
+ lightAttenuation1: vec3<f32>,
1372
+
1373
+ lightColor2: vec3<f32>,
1374
+ lightPosition2: vec3<f32>,
1375
+ lightDirection2: vec3<f32>,
1376
+ lightAttenuation2: vec3<f32>,
1377
+
1378
+ lightColor3: vec3<f32>,
1379
+ lightPosition3: vec3<f32>,
1380
+ lightDirection3: vec3<f32>,
1381
+ lightAttenuation3: vec3<f32>,
1382
+
1383
+ lightColor4: vec3<f32>,
1384
+ lightPosition4: vec3<f32>,
1385
+ lightDirection4: vec3<f32>,
1386
+ lightAttenuation4: vec3<f32>,
1327
1387
  };
1328
1388
 
1329
1389
  // Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)
1330
1390
  @binding(1) @group(0) var<uniform> lighting : lightingUniforms;
1331
1391
 
1332
1392
  fn lighting_getPointLight(index: i32) -> PointLight {
1333
- return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
1393
+ switch (index) {
1394
+ case 0: {
1395
+ return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
1396
+ }
1397
+ case 1: {
1398
+ return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
1399
+ }
1400
+ case 2: {
1401
+ return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
1402
+ }
1403
+ case 3: {
1404
+ return PointLight(lighting.lightColor3, lighting.lightPosition3, lighting.lightAttenuation3);
1405
+ }
1406
+ case 4, default: {
1407
+ return PointLight(lighting.lightColor4, lighting.lightPosition4, lighting.lightAttenuation4);
1408
+ }
1409
+ }
1334
1410
  }
1335
1411
 
1336
1412
  fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
1337
- return DirectionalLight(lighting.lightColor, lighting.lightDirection);
1413
+ switch (index) {
1414
+ case 0: {
1415
+ return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
1416
+ }
1417
+ case 1: {
1418
+ return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
1419
+ }
1420
+ case 2: {
1421
+ return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
1422
+ }
1423
+ case 3: {
1424
+ return DirectionalLight(lighting.lightColor3, lighting.lightDirection3);
1425
+ }
1426
+ case 4, default: {
1427
+ return DirectionalLight(lighting.lightColor4, lighting.lightDirection4);
1428
+ }
1429
+ }
1338
1430
  }
1339
1431
 
1340
1432
  fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
@@ -1342,7 +1434,7 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
1342
1434
  + pointLight.attenuation.y * distance
1343
1435
  + pointLight.attenuation.z * distance * distance;
1344
1436
  }
1345
- `;var Qt=5,eo=255,k;(function(e){e[e.POINT=0]="POINT",e[e.DIRECTIONAL=1]="DIRECTIONAL"})(k||(k={}));var g={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientColor:"vec3<f32>",lightColor0:"vec3<f32>",lightPosition0:"vec3<f32>",lightDirection0:"vec3<f32>",lightAttenuation0:"vec3<f32>",lightColor1:"vec3<f32>",lightPosition1:"vec3<f32>",lightDirection1:"vec3<f32>",lightAttenuation1:"vec3<f32>",lightColor2:"vec3<f32>",lightPosition2:"vec3<f32>",lightDirection2:"vec3<f32>",lightAttenuation2:"vec3<f32>"},defaultUniforms:{enabled:1,lightType:k.POINT,directionalLightCount:0,pointLightCount:0,ambientColor:[.1,.1,.1],lightColor0:[1,1,1],lightPosition0:[1,1,2],lightDirection0:[1,1,1],lightAttenuation0:[1,0,0],lightColor1:[1,1,1],lightPosition1:[1,1,2],lightDirection1:[1,1,1],lightAttenuation1:[1,0,0],lightColor2:[1,1,1],lightPosition2:[1,1,2],lightDirection2:[1,1,1],lightAttenuation2:[1,0,0]},source:rt,vs:fe,fs:fe,getUniforms:to};function to(e,t={}){if(e=e&&{...e},!e)return{...g.defaultUniforms};e.lights&&(e={...e,...io(e.lights),lights:void 0});let{ambientLight:o,pointLights:i,directionalLights:n}=e||{};if(!(o||i&&i.length>0||n&&n.length>0))return{...g.defaultUniforms,enabled:0};let a={...g.defaultUniforms,...t,...oo({ambientLight:o,pointLights:i,directionalLights:n})};return e.enabled!==void 0&&(a.enabled=e.enabled?1:0),a}function oo({ambientLight:e,pointLights:t=[],directionalLights:o=[]}){let i={};i.ambientColor=ue(e);let n=0;for(let r of t){i.lightType=k.POINT;let a=n;i[`lightColor${a}`]=ue(r),i[`lightPosition${a}`]=r.position,i[`lightAttenuation${a}`]=r.attenuation||[1,0,0],n++}for(let r of o){i.lightType=k.DIRECTIONAL;let a=n;i[`lightColor${a}`]=ue(r),i[`lightDirection${a}`]=r.direction,n++}return n>Qt&&nt.log.warn("MAX_LIGHTS exceeded")(),i.directionalLightCount=o.length,i.pointLightCount=t.length,i}function io(e){let t={pointLights:[],directionalLights:[]};for(let o of e||[])switch(o.type){case"ambient":t.ambientLight=o;break;case"directional":t.directionalLights?.push(o);break;case"point":t.pointLights?.push(o);break;default:}return t}function ue(e={}){let{color:t=[0,0,0],intensity:o=1}=e;return t.map(i=>i*o/eo)}var ro=`
1437
+ `;var _e=5,hi=255,ee;(function(e){e[e.POINT=0]="POINT",e[e.DIRECTIONAL=1]="DIRECTIONAL"})(ee||(ee={}));var y={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientColor:"vec3<f32>",lightColor0:"vec3<f32>",lightPosition0:"vec3<f32>",lightDirection0:"vec3<f32>",lightAttenuation0:"vec3<f32>",lightColor1:"vec3<f32>",lightPosition1:"vec3<f32>",lightDirection1:"vec3<f32>",lightAttenuation1:"vec3<f32>",lightColor2:"vec3<f32>",lightPosition2:"vec3<f32>",lightDirection2:"vec3<f32>",lightAttenuation2:"vec3<f32>",lightColor3:"vec3<f32>",lightPosition3:"vec3<f32>",lightDirection3:"vec3<f32>",lightAttenuation3:"vec3<f32>",lightColor4:"vec3<f32>",lightPosition4:"vec3<f32>",lightDirection4:"vec3<f32>",lightAttenuation4:"vec3<f32>"},defaultUniforms:{enabled:1,lightType:ee.POINT,directionalLightCount:0,pointLightCount:0,ambientColor:[.1,.1,.1],lightColor0:[1,1,1],lightPosition0:[1,1,2],lightDirection0:[1,1,1],lightAttenuation0:[1,0,0],lightColor1:[1,1,1],lightPosition1:[1,1,2],lightDirection1:[1,1,1],lightAttenuation1:[1,0,0],lightColor2:[1,1,1],lightPosition2:[1,1,2],lightDirection2:[1,1,1],lightAttenuation2:[1,0,0],lightColor3:[1,1,1],lightPosition3:[1,1,2],lightDirection3:[1,1,1],lightAttenuation3:[1,0,0],lightColor4:[1,1,1],lightPosition4:[1,1,2],lightDirection4:[1,1,1],lightAttenuation4:[1,0,0]},source:Xt,vs:Fe,fs:Fe,getUniforms:gi};function gi(e,t={}){if(e=e&&{...e},!e)return{...y.defaultUniforms};e.lights&&(e={...e,..._i(e.lights),lights:void 0});let{ambientLight:n,pointLights:i,directionalLights:r}=e||{};if(!(n||i&&i.length>0||r&&r.length>0))return{...y.defaultUniforms,enabled:0};let s={...y.defaultUniforms,...t,...mi({ambientLight:n,pointLights:i,directionalLights:r})};return e.enabled!==void 0&&(s.enabled=e.enabled?1:0),s}function mi({ambientLight:e,pointLights:t=[],directionalLights:n=[]}){let i={};i.ambientColor=we(e);let r=0,o=0,s=0;for(let c of t){if(r>=_e)break;i.lightType=ee.POINT;let a=r;i[`lightColor${a}`]=we(c),i[`lightPosition${a}`]=c.position,i[`lightAttenuation${a}`]=c.attenuation||[1,0,0],r++,o++}for(let c of n){if(r>=_e)break;i.lightType=ee.DIRECTIONAL;let a=r;i[`lightColor${a}`]=we(c),i[`lightDirection${a}`]=c.direction,r++,s++}return t.length+n.length>_e&&Zt.log.warn(`MAX_LIGHTS exceeded, truncating to ${_e}`)(),i.directionalLightCount=s,i.pointLightCount=o,i}function _i(e){let t={pointLights:[],directionalLights:[]};for(let n of e||[])switch(n.type){case"ambient":t.ambientLight=n;break;case"directional":t.directionalLights?.push(n);break;case"point":t.pointLights?.push(n);break;default:}return t}function we(e={}){let{color:t=[0,0,0],intensity:n=1}=e;return t.map(i=>i*n/hi)}var ui=`
1346
1438
  struct dirlightUniforms {
1347
1439
  lightDirection: vec3<f32>,
1348
1440
  };
@@ -1368,12 +1460,12 @@ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
1368
1460
  let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
1369
1461
  return vec4<f32>(color.rgb * d, color.a);
1370
1462
  }
1371
- `,no=`out vec3 dirlight_vNormal;
1463
+ `,di=`out vec3 dirlight_vNormal;
1372
1464
 
1373
1465
  void dirlight_setNormal(vec3 normal) {
1374
1466
  dirlight_vNormal = normalize(normal);
1375
1467
  }
1376
- `,ao=`uniform dirlightUniforms {
1468
+ `,vi=`uniform dirlightUniforms {
1377
1469
  vec3 lightDirection;
1378
1470
  } dirlight;
1379
1471
 
@@ -1384,13 +1476,13 @@ vec4 dirlight_filterColor(vec4 color) {
1384
1476
  float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
1385
1477
  return vec4(color.rgb * d, color.a);
1386
1478
  }
1387
- `,pe={props:{},uniforms:{},name:"dirlight",dependencies:[],source:ro,vs:no,fs:ao,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:lo};function lo(e=pe.defaultUniforms){let t={};return e.lightDirection&&(t.lightDirection=e.lightDirection),t}var J=`uniform phongMaterialUniforms {
1479
+ `,ke={props:{},uniforms:{},name:"dirlight",dependencies:[],source:ui,vs:di,fs:vi,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:xi};function xi(e=ke.defaultUniforms){let t={};return e.lightDirection&&(t.lightDirection=e.lightDirection),t}var ue=`uniform phongMaterialUniforms {
1388
1480
  uniform float ambient;
1389
1481
  uniform float diffuse;
1390
1482
  uniform float shininess;
1391
1483
  uniform vec3 specularColor;
1392
1484
  } material;
1393
- `,Z=`#define MAX_LIGHTS 3
1485
+ `,de=`#define MAX_LIGHTS 3
1394
1486
 
1395
1487
  uniform phongMaterialUniforms {
1396
1488
  uniform float ambient;
@@ -1437,7 +1529,7 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
1437
1529
 
1438
1530
  return lightColor;
1439
1531
  }
1440
- `;var Q=`struct phongMaterialUniforms {
1532
+ `;var ve=`struct phongMaterialUniforms {
1441
1533
  ambient: f32,
1442
1534
  diffuse: f32,
1443
1535
  shininess: f32,
@@ -1468,61 +1560,65 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
1468
1560
  let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
1469
1561
  lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;
1470
1562
 
1471
- if (lighting.lightType == 0) {
1472
- let pointLight: PointLight = lighting_getPointLight(0);
1563
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
1564
+ let pointLight: PointLight = lighting_getPointLight(i);
1473
1565
  let light_position_worldspace: vec3<f32> = pointLight.position;
1474
1566
  let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1475
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
1476
- } else if (lighting.lightType == 1) {
1477
- var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
1478
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1479
- }
1480
-
1481
- return lightColor;
1482
- /*
1483
- for (int i = 0; i < MAX_LIGHTS; i++) {
1484
- if (i >= lighting.pointLightCount) {
1485
- break;
1486
- }
1487
- PointLight pointLight = lighting.pointLight[i];
1488
- vec3 light_position_worldspace = pointLight.position;
1489
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
1490
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
1567
+ let light_attenuation = getPointLightAttenuation(
1568
+ pointLight,
1569
+ distance(light_position_worldspace, position_worldspace)
1570
+ );
1571
+ lightColor += lighting_getLightColor(
1572
+ surfaceColor,
1573
+ light_direction,
1574
+ view_direction,
1575
+ normal_worldspace,
1576
+ pointLight.color / light_attenuation
1577
+ );
1491
1578
  }
1492
1579
 
1493
- for (int i = 0; i < MAX_LIGHTS; i++) {
1494
- if (i >= lighting.directionalLightCount) {
1495
- break;
1496
- }
1497
- DirectionalLight directionalLight = lighting.directionalLight[i];
1580
+ let totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
1581
+ for (var i: i32 = lighting.pointLightCount; i < totalLights; i++) {
1582
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
1498
1583
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1499
- }
1500
- */
1584
+ }
1585
+
1586
+ return lightColor;
1501
1587
  }
1502
1588
 
1503
1589
  fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{
1504
1590
  var lightColor = vec3<f32>(0, 0, 0);
1505
1591
  let surfaceColor = vec3<f32>(0, 0, 0);
1506
1592
 
1507
- if (lighting.enabled == 0) {
1593
+ if (lighting.enabled != 0) {
1508
1594
  let view_direction = normalize(cameraPosition - position_worldspace);
1509
1595
 
1510
- switch (lighting.lightType) {
1511
- case 0, default: {
1512
- let pointLight: PointLight = lighting_getPointLight(0);
1513
- let light_position_worldspace: vec3<f32> = pointLight.position;
1514
- let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1515
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
1516
- }
1517
- case 1: {
1518
- let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
1596
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
1597
+ let pointLight: PointLight = lighting_getPointLight(i);
1598
+ let light_position_worldspace: vec3<f32> = pointLight.position;
1599
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1600
+ let light_attenuation = getPointLightAttenuation(
1601
+ pointLight,
1602
+ distance(light_position_worldspace, position_worldspace)
1603
+ );
1604
+ lightColor += lighting_getLightColor(
1605
+ surfaceColor,
1606
+ light_direction,
1607
+ view_direction,
1608
+ normal_worldspace,
1609
+ pointLight.color / light_attenuation
1610
+ );
1611
+ }
1612
+
1613
+ let totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
1614
+ for (var i: i32 = lighting.pointLightCount; i < totalLights; i++) {
1615
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
1519
1616
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1520
- }
1521
1617
  }
1522
1618
  }
1523
1619
  return lightColor;
1524
1620
  }
1525
- `;var _e={props:{},name:"gouraudMaterial",vs:Z.replace("phongMaterial","gouraudMaterial"),fs:J.replace("phongMaterial","gouraudMaterial"),source:Q.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[g],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(e){let t={...e};return t.specularColor&&(t.specularColor=t.specularColor.map(o=>o/255)),{..._e.defaultUniforms,...t}}};var me={name:"phongMaterial",dependencies:[g],source:Q,vs:J,fs:Z,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(e){let t={...e};return t.specularColor&&(t.specularColor=t.specularColor.map(o=>o/255)),{...me.defaultUniforms,...t}}};var at=`out vec3 pbr_vPosition;
1621
+ `;var De={props:{},name:"gouraudMaterial",vs:de.replace("phongMaterial","gouraudMaterial"),fs:ue.replace("phongMaterial","gouraudMaterial"),source:ve.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[y],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(e){let t={...e};return t.specularColor&&(t.specularColor=t.specularColor.map(n=>n/255)),{...De.defaultUniforms,...t}}};var Ue={name:"phongMaterial",dependencies:[y],source:ve,vs:ue,fs:de,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(e){let t={...e};return t.specularColor&&(t.specularColor=t.specularColor.map(n=>n/255)),{...Ue.defaultUniforms,...t}}};var Jt=`out vec3 pbr_vPosition;
1526
1622
  out vec2 pbr_vUV;
1527
1623
 
1528
1624
  #ifdef HAS_NORMALS
@@ -1555,7 +1651,7 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
1555
1651
  pbr_vUV = vec2(0.,0.);
1556
1652
  #endif
1557
1653
  }
1558
- `,lt=`precision highp float;
1654
+ `,Qt=`precision highp float;
1559
1655
 
1560
1656
  uniform pbrMaterialUniforms {
1561
1657
  // Material is unlit
@@ -2013,54 +2109,58 @@ vec4 pbr_filterColor(vec4 colorUnused)
2013
2109
 
2014
2110
  return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
2015
2111
  }
2016
- `;var st=`struct PBRFragmentInputs {
2112
+ `;var en=`struct PBRFragmentInputs {
2017
2113
  pbr_vPosition: vec3f,
2018
2114
  pbr_vUV: vec2f,
2019
- pbr_vTBN: mat3f,
2115
+ pbr_vTBN: mat3x3f,
2020
2116
  pbr_vNormal: vec3f
2021
2117
  };
2022
2118
 
2023
- var fragmentInputs: PBRFragmentInputs;
2119
+ var<private> fragmentInputs: PBRFragmentInputs;
2024
2120
 
2025
2121
  fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)
2026
2122
  {
2027
2123
  var pos: vec4f = pbrProjection.modelMatrix * position;
2028
- fragmentInputs.pbr_vPosition = vec3(pos.xyz) / pos.w;
2124
+ fragmentInputs.pbr_vPosition = pos.xyz / pos.w;
2125
+ fragmentInputs.pbr_vNormal = vec3f(0.0, 0.0, 1.0);
2126
+ fragmentInputs.pbr_vTBN = mat3x3f(
2127
+ vec3f(1.0, 0.0, 0.0),
2128
+ vec3f(0.0, 1.0, 0.0),
2129
+ vec3f(0.0, 0.0, 1.0)
2130
+ );
2131
+ fragmentInputs.pbr_vUV = vec2f(0.0, 0.0);
2029
2132
 
2030
2133
  #ifdef HAS_NORMALS
2134
+ let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);
2135
+ fragmentInputs.pbr_vNormal = normalW;
2031
2136
  #ifdef HAS_TANGENTS
2032
- let normalW: vec3f = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
2033
- let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
2137
+ let tangentW: vec3f = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);
2034
2138
  let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;
2035
- fragmentInputs.pbr_vTBN = mat3(tangentW, bitangentW, normalW);
2036
- #else // HAS_TANGENTS != 1
2037
- fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
2139
+ fragmentInputs.pbr_vTBN = mat3x3f(tangentW, bitangentW, normalW);
2038
2140
  #endif
2039
2141
  #endif
2040
2142
 
2041
2143
  #ifdef HAS_UV
2042
2144
  fragmentInputs.pbr_vUV = uv;
2043
- #else
2044
- fragmentInputs.pbr_vUV = vec2(0.,0.);
2045
2145
  #endif
2046
2146
  }
2047
2147
 
2048
2148
  struct pbrMaterialUniforms {
2049
2149
  // Material is unlit
2050
- unlit: uint32,
2150
+ unlit: u32,
2051
2151
 
2052
2152
  // Base color map
2053
- baseColorMapEnabled: uint32,
2153
+ baseColorMapEnabled: u32,
2054
2154
  baseColorFactor: vec4f,
2055
2155
 
2056
- normalMapEnabled : uint32,
2156
+ normalMapEnabled : u32,
2057
2157
  normalScale: f32, // #ifdef HAS_NORMALMAP
2058
2158
 
2059
- emissiveMapEnabled: uint32,
2159
+ emissiveMapEnabled: u32,
2060
2160
  emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP
2061
2161
 
2062
2162
  metallicRoughnessValues: vec2f,
2063
- metallicRoughnessMapEnabled: uint32,
2163
+ metallicRoughnessMapEnabled: u32,
2064
2164
 
2065
2165
  occlusionMapEnabled: i32,
2066
2166
  occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP
@@ -2075,7 +2175,7 @@ struct pbrMaterialUniforms {
2075
2175
  // debugging flags used for shader output of intermediate PBR variables
2076
2176
  // #ifdef PBR_DEBUG
2077
2177
  scaleDiffBaseMR: vec4f,
2078
- scaleFGDSpec: vec4f
2178
+ scaleFGDSpec: vec4f,
2079
2179
  // #endif
2080
2180
  }
2081
2181
 
@@ -2083,24 +2183,32 @@ struct pbrMaterialUniforms {
2083
2183
 
2084
2184
  // Samplers
2085
2185
  #ifdef HAS_BASECOLORMAP
2086
- uniform sampler2D pbr_baseColorSampler;
2186
+ @binding(3) @group(0) var pbr_baseColorSampler: texture_2d<f32>;
2187
+ @binding(4) @group(0) var pbr_baseColorSamplerSampler: sampler;
2087
2188
  #endif
2088
2189
  #ifdef HAS_NORMALMAP
2089
- uniform sampler2D pbr_normalSampler;
2190
+ @binding(5) @group(0) var pbr_normalSampler: texture_2d<f32>;
2191
+ @binding(6) @group(0) var pbr_normalSamplerSampler: sampler;
2090
2192
  #endif
2091
2193
  #ifdef HAS_EMISSIVEMAP
2092
- uniform sampler2D pbr_emissiveSampler;
2194
+ @binding(7) @group(0) var pbr_emissiveSampler: texture_2d<f32>;
2195
+ @binding(8) @group(0) var pbr_emissiveSamplerSampler: sampler;
2093
2196
  #endif
2094
2197
  #ifdef HAS_METALROUGHNESSMAP
2095
- uniform sampler2D pbr_metallicRoughnessSampler;
2198
+ @binding(9) @group(0) var pbr_metallicRoughnessSampler: texture_2d<f32>;
2199
+ @binding(10) @group(0) var pbr_metallicRoughnessSamplerSampler: sampler;
2096
2200
  #endif
2097
2201
  #ifdef HAS_OCCLUSIONMAP
2098
- uniform sampler2D pbr_occlusionSampler;
2202
+ @binding(11) @group(0) var pbr_occlusionSampler: texture_2d<f32>;
2203
+ @binding(12) @group(0) var pbr_occlusionSamplerSampler: sampler;
2099
2204
  #endif
2100
2205
  #ifdef USE_IBL
2101
- uniform samplerCube pbr_diffuseEnvSampler;
2102
- uniform samplerCube pbr_specularEnvSampler;
2103
- uniform sampler2D pbr_brdfLUT;
2206
+ @binding(13) @group(0) var pbr_diffuseEnvSampler: texture_cube<f32>;
2207
+ @binding(14) @group(0) var pbr_diffuseEnvSamplerSampler: sampler;
2208
+ @binding(15) @group(0) var pbr_specularEnvSampler: texture_cube<f32>;
2209
+ @binding(16) @group(0) var pbr_specularEnvSamplerSampler: sampler;
2210
+ @binding(17) @group(0) var pbr_BrdfLUT: texture_2d<f32>;
2211
+ @binding(18) @group(0) var pbr_BrdfLUTSampler: sampler;
2104
2212
  #endif
2105
2213
 
2106
2214
  // Encapsulate the various inputs used by the various functions in the shading equation
@@ -2128,17 +2236,19 @@ const c_MinRoughness = 0.04;
2128
2236
 
2129
2237
  fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
2130
2238
  {
2239
+ var linOut: vec3f = srgbIn.xyz;
2131
2240
  #ifdef MANUAL_SRGB
2241
+ let bLess: vec3f = step(vec3f(0.04045), srgbIn.xyz);
2242
+ linOut = mix(
2243
+ srgbIn.xyz / vec3f(12.92),
2244
+ pow((srgbIn.xyz + vec3f(0.055)) / vec3f(1.055), vec3f(2.4)),
2245
+ bLess
2246
+ );
2132
2247
  #ifdef SRGB_FAST_APPROXIMATION
2133
- var linOut: vec3f = pow(srgbIn.xyz,vec3(2.2));
2134
- #else // SRGB_FAST_APPROXIMATION
2135
- var bLess: vec3f = step(vec3(0.04045),srgbIn.xyz);
2136
- var linOut: vec3f = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
2137
- #endif //SRGB_FAST_APPROXIMATION
2138
- return vec4f(linOut,srgbIn.w);;
2139
- #else //MANUAL_SRGB
2140
- return srgbIn;
2141
- #endif //MANUAL_SRGB
2248
+ linOut = pow(srgbIn.xyz, vec3f(2.2));
2249
+ #endif
2250
+ #endif
2251
+ return vec4f(linOut, srgbIn.w);
2142
2252
  }
2143
2253
 
2144
2254
  // Find the normal for this fragment, pulling either from a predefined normal map
@@ -2146,32 +2256,28 @@ fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
2146
2256
  fn getNormal() -> vec3f
2147
2257
  {
2148
2258
  // Retrieve the tangent space matrix
2149
- #ifndef HAS_TANGENTS
2150
- var pos_dx: vec3f = dFdx(fragmentInputs.pbr_vPosition);
2151
- var pos_dy: vec3f = dFdy(fragmentInputs.pbr_vPosition);
2152
- var tex_dx: vec3f = dFdx(vec3(fragmentInputs.pbr_vUV, 0.0));
2153
- var tex_dy: vec3f = dFdy(vec3(fragmentInputs.pbr_vUV, 0.0));
2154
- var t: vec3f = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
2259
+ let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);
2260
+ let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);
2261
+ let tex_dx: vec3f = dpdx(vec3f(fragmentInputs.pbr_vUV, 0.0));
2262
+ let tex_dy: vec3f = dpdy(vec3f(fragmentInputs.pbr_vUV, 0.0));
2263
+ var t: vec3f = (tex_dy.y * pos_dx - tex_dx.y * pos_dy) / (tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y);
2155
2264
 
2156
- #ifdef HAS_NORMALS
2157
- var ng: vec3f = normalize(fragmentInputs.pbr_vNormal);
2158
- #else
2159
2265
  var ng: vec3f = cross(pos_dx, pos_dy);
2266
+ #ifdef HAS_NORMALS
2267
+ ng = normalize(fragmentInputs.pbr_vNormal);
2160
2268
  #endif
2161
-
2162
2269
  t = normalize(t - ng * dot(ng, t));
2163
2270
  var b: vec3f = normalize(cross(ng, t));
2164
- var tbn: mat3f = mat3f(t, b, ng);
2165
- #else // HAS_TANGENTS
2166
- var tbn: mat3f = fragmentInputs.pbr_vTBN;
2271
+ var tbn: mat3x3f = mat3x3f(t, b, ng);
2272
+ #ifdef HAS_TANGENTS
2273
+ tbn = fragmentInputs.pbr_vTBN;
2167
2274
  #endif
2168
2275
 
2169
- #ifdef HAS_NORMALMAP
2170
- vec3 n = texture(pbr_normalSampler, fragmentInputs.pbr_vUV).rgb;
2171
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
2172
- #else
2173
2276
  // The tbn matrix is linearly interpolated, so we need to re-normalize
2174
- vec3 n = normalize(tbn[2].xyz);
2277
+ var n: vec3f = normalize(tbn[2].xyz);
2278
+ #ifdef HAS_NORMALMAP
2279
+ n = textureSample(pbr_normalSampler, pbr_normalSamplerSampler, fragmentInputs.pbr_vUV).rgb;
2280
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3f(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
2175
2281
  #endif
2176
2282
 
2177
2283
  return n;
@@ -2181,27 +2287,37 @@ fn getNormal() -> vec3f
2181
2287
  // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
2182
2288
  // See our README.md on Environment Maps [3] for additional discussion.
2183
2289
  #ifdef USE_IBL
2184
- fn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f
2290
+ fn getIBLContribution(pbrInfo: PBRInfo, n: vec3f, reflection: vec3f) -> vec3f
2185
2291
  {
2186
- float mipCount = 9.0; // resolution of 512x512
2187
- float lod = (pbrInfo.perceptualRoughness * mipCount);
2292
+ let mipCount: f32 = 9.0; // resolution of 512x512
2293
+ let lod: f32 = pbrInfo.perceptualRoughness * mipCount;
2188
2294
  // retrieve a scale and bias to F0. See [1], Figure 3
2189
- vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
2190
- vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
2191
- vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
2192
-
2295
+ let brdf = SRGBtoLINEAR(
2296
+ textureSample(
2297
+ pbr_BrdfLUT,
2298
+ pbr_BrdfLUTSampler,
2299
+ vec2f(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness)
2300
+ )
2301
+ ).rgb;
2302
+ let diffuseLight =
2303
+ SRGBtoLINEAR(textureSample(pbr_diffuseEnvSampler, pbr_diffuseEnvSamplerSampler, n)).rgb;
2304
+ let specularLightDefault =
2305
+ SRGBtoLINEAR(textureSample(pbr_specularEnvSampler, pbr_specularEnvSamplerSampler, reflection)).rgb;
2306
+ var specularLight = specularLightDefault;
2193
2307
  #ifdef USE_TEX_LOD
2194
- vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
2195
- #else
2196
- vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
2308
+ specularLight = SRGBtoLINEAR(
2309
+ textureSampleLevel(
2310
+ pbr_specularEnvSampler,
2311
+ pbr_specularEnvSamplerSampler,
2312
+ reflection,
2313
+ lod
2314
+ )
2315
+ ).rgb;
2197
2316
  #endif
2198
2317
 
2199
- vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
2200
- vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
2201
-
2202
- // For presentation, this allows us to disable IBL terms
2203
- diffuse *= pbrMaterial.scaleIBLAmbient.x;
2204
- specular *= pbrMaterial.scaleIBLAmbient.y;
2318
+ let diffuse = diffuseLight * pbrInfo.diffuseColor * pbrMaterial.scaleIBLAmbient.x;
2319
+ let specular =
2320
+ specularLight * (pbrInfo.specularColor * brdf.x + brdf.y) * pbrMaterial.scaleIBLAmbient.y;
2205
2321
 
2206
2322
  return diffuse + specular;
2207
2323
  }
@@ -2245,7 +2361,7 @@ fn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {
2245
2361
  fn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {
2246
2362
  let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
2247
2363
  let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
2248
- return roughnessSq / (PI * f * f);
2364
+ return roughnessSq / (M_PI * f * f);
2249
2365
  }
2250
2366
 
2251
2367
  fn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {
@@ -2287,11 +2403,11 @@ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
2287
2403
 
2288
2404
  fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2289
2405
  // The albedo may be defined from a base texture or a flat color
2290
- var baseColor: vec4<f32>;
2406
+ var baseColor: vec4<f32> = pbrMaterial.baseColorFactor;
2291
2407
  #ifdef HAS_BASECOLORMAP
2292
- baseColor = SRGBtoLINEAR(textureSample(pbr_baseColorSampler, pbr_baseColorSampler, fragmentInputs.pbr_vUV)) * pbrMaterial.baseColorFactor;
2293
- #else
2294
- baseColor = pbrMaterial.baseColorFactor;
2408
+ baseColor = SRGBtoLINEAR(
2409
+ textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, fragmentInputs.pbr_vUV)
2410
+ ) * pbrMaterial.baseColorFactor;
2295
2411
  #endif
2296
2412
 
2297
2413
  #ifdef ALPHA_CUTOFF
@@ -2302,7 +2418,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2302
2418
 
2303
2419
  var color = vec3<f32>(0.0, 0.0, 0.0);
2304
2420
 
2305
- if (pbrMaterial.unlit) {
2421
+ if (pbrMaterial.unlit != 0u) {
2306
2422
  color = baseColor.rgb;
2307
2423
  } else {
2308
2424
  // Metallic and Roughness material properties are packed together
@@ -2313,7 +2429,11 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2313
2429
  #ifdef HAS_METALROUGHNESSMAP
2314
2430
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
2315
2431
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
2316
- let mrSample = textureSample(pbr_metallicRoughnessSampler, pbr_metallicRoughnessSampler, fragmentInputs.pbr_vUV);
2432
+ let mrSample = textureSample(
2433
+ pbr_metallicRoughnessSampler,
2434
+ pbr_metallicRoughnessSamplerSampler,
2435
+ fragmentInputs.pbr_vUV
2436
+ );
2317
2437
  perceptualRoughness = mrSample.g * perceptualRoughness;
2318
2438
  metallic = mrSample.b * metallic;
2319
2439
  #endif
@@ -2390,22 +2510,25 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2390
2510
 
2391
2511
  // Calculate lighting contribution from image based lighting source (IBL)
2392
2512
  #ifdef USE_IBL
2393
- if (pbrMaterial.IBLenabled) {
2513
+ if (pbrMaterial.IBLenabled != 0) {
2394
2514
  color += getIBLContribution(pbrInfo, n, reflection);
2395
2515
  }
2396
2516
  #endif
2397
2517
 
2398
2518
  // Apply optional PBR terms for additional (optional) shading
2399
2519
  #ifdef HAS_OCCLUSIONMAP
2400
- if (pbrMaterial.occlusionMapEnabled) {
2401
- let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSampler, fragmentInputs.pbr_vUV).r;
2520
+ if (pbrMaterial.occlusionMapEnabled != 0) {
2521
+ let ao =
2522
+ textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, fragmentInputs.pbr_vUV).r;
2402
2523
  color = mix(color, color * ao, pbrMaterial.occlusionStrength);
2403
2524
  }
2404
2525
  #endif
2405
2526
 
2406
2527
  #ifdef HAS_EMISSIVEMAP
2407
- if (pbrMaterial.emissiveMapEnabled) {
2408
- let emissive = SRGBtoLINEAR(textureSample(pbr_emissiveSampler, pbr_emissiveSampler, fragmentInputs.pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
2528
+ if (pbrMaterial.emissiveMapEnabled != 0u) {
2529
+ let emissive = SRGBtoLINEAR(
2530
+ textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, fragmentInputs.pbr_vUV)
2531
+ ).rgb * pbrMaterial.emissiveFactor;
2409
2532
  color += emissive;
2410
2533
  }
2411
2534
  #endif
@@ -2429,12 +2552,20 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2429
2552
 
2430
2553
  return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);
2431
2554
  }
2432
- `;var ct=`uniform pbrProjectionUniforms {
2555
+ `;var tn=`uniform pbrProjectionUniforms {
2433
2556
  mat4 modelViewProjectionMatrix;
2434
2557
  mat4 modelMatrix;
2435
2558
  mat4 normalMatrix;
2436
2559
  vec3 camera;
2437
2560
  } pbrProjection;
2438
- `,ft={name:"pbrProjection",vs:ct,fs:ct,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<i32>"}};var ut={props:{},uniforms:{},name:"pbrMaterial",dependencies:[g,ft],source:st,vs:at,fs:lt,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_CLEARCOATMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_ANISOTROPYMAP:!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",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<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",sheenColorFactor:"vec3<f32>",sheenRoughnessFactor:"f32",sheenColorMapEnabled:"i32",iridescenceFactor:"f32",iridescenceIor:"f32",iridescenceThicknessRange:"vec2<f32>",iridescenceMapEnabled:"i32",anisotropyStrength:"f32",anisotropyRotation:"f32",anisotropyDirection:"vec2<f32>",anisotropyMapEnabled:"i32",emissiveStrength:"f32"}};return At(H);})();
2561
+ `,bi=`struct pbrProjectionUniforms {
2562
+ modelViewProjectionMatrix: mat4x4<f32>,
2563
+ modelMatrix: mat4x4<f32>,
2564
+ normalMatrix: mat4x4<f32>,
2565
+ camera: vec3<f32>
2566
+ };
2567
+
2568
+ @binding(0) @group(0) var<uniform> pbrProjection: pbrProjectionUniforms;
2569
+ `,nn={name:"pbrProjection",source:bi,vs:tn,fs:tn,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}};var rn={props:{},uniforms:{},name:"pbrMaterial",dependencies:[y,nn],source:en,vs:Jt,fs:Qt,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_CLEARCOATMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_ANISOTROPYMAP:!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",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<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",sheenColorFactor:"vec3<f32>",sheenRoughnessFactor:"f32",sheenColorMapEnabled:"i32",iridescenceFactor:"f32",iridescenceIor:"f32",iridescenceThicknessRange:"vec2<f32>",iridescenceMapEnabled:"i32",anisotropyStrength:"f32",anisotropyRotation:"f32",anisotropyDirection:"vec2<f32>",anisotropyMapEnabled:"i32",emissiveStrength:"f32"}};return gn(te);})();
2439
2570
  return __exports__;
2440
2571
  });