@luma.gl/shadertools 9.2.6 → 9.3.0-alpha.11

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 (182) hide show
  1. package/dist/dist.dev.js +5388 -6438
  2. package/dist/dist.min.js +2264 -322
  3. package/dist/index.cjs +3601 -566
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +12 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/glsl-utils/shader-utils.js +4 -4
  10. package/dist/lib/glsl-utils/shader-utils.js.map +1 -1
  11. package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
  12. package/dist/lib/preprocessor/preprocessor.js +35 -8
  13. package/dist/lib/preprocessor/preprocessor.js.map +1 -1
  14. package/dist/lib/shader-assembler.d.ts +10 -0
  15. package/dist/lib/shader-assembler.d.ts.map +1 -1
  16. package/dist/lib/shader-assembler.js +20 -3
  17. package/dist/lib/shader-assembler.js.map +1 -1
  18. package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
  19. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  20. package/dist/lib/shader-assembly/assemble-shaders.js +265 -12
  21. package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
  22. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
  23. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
  24. package/dist/lib/shader-assembly/wgsl-binding-debug.js +144 -0
  25. package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
  26. package/dist/lib/shader-assembly/wgsl-binding-scan.d.ts +19 -0
  27. package/dist/lib/shader-assembly/wgsl-binding-scan.d.ts.map +1 -0
  28. package/dist/lib/shader-assembly/wgsl-binding-scan.js +151 -0
  29. package/dist/lib/shader-assembly/wgsl-binding-scan.js.map +1 -0
  30. package/dist/lib/shader-generator/glsl/generate-glsl.js +7 -4
  31. package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
  32. package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
  33. package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
  34. package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
  35. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +91 -0
  36. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
  37. package/dist/lib/shader-module/shader-module-uniform-layout.js +253 -0
  38. package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
  39. package/dist/lib/shader-module/shader-module.d.ts +12 -6
  40. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  41. package/dist/lib/shader-module/shader-module.js.map +1 -1
  42. package/dist/lib/utils/assert.d.ts.map +1 -1
  43. package/dist/lib/utils/assert.js +3 -1
  44. package/dist/lib/utils/assert.js.map +1 -1
  45. package/dist/lib/utils/uniform-types.d.ts +11 -7
  46. package/dist/lib/utils/uniform-types.d.ts.map +1 -1
  47. package/dist/modules/engine/picking/picking.d.ts +5 -2
  48. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  49. package/dist/modules/engine/picking/picking.js +5 -2
  50. package/dist/modules/engine/picking/picking.js.map +1 -1
  51. package/dist/modules/engine/project/project.d.ts +1 -1
  52. package/dist/modules/engine/project/project.js +1 -1
  53. package/dist/modules/engine/skin/skin.d.ts +30 -0
  54. package/dist/modules/engine/skin/skin.d.ts.map +1 -0
  55. package/dist/modules/engine/skin/skin.js +86 -0
  56. package/dist/modules/engine/skin/skin.js.map +1 -0
  57. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
  58. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  59. package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
  60. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
  61. package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
  62. package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
  63. package/dist/modules/lighting/ibl/ibl.js +33 -0
  64. package/dist/modules/lighting/ibl/ibl.js.map +1 -0
  65. package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
  66. package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
  67. package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
  68. package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
  69. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
  70. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
  71. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
  72. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
  73. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
  74. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
  75. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
  76. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
  77. package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
  78. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
  79. package/dist/modules/lighting/lights/lighting-glsl.js +44 -38
  80. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
  81. package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
  82. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
  83. package/dist/modules/lighting/lights/lighting-wgsl.js +46 -18
  84. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
  85. package/dist/modules/lighting/lights/lighting.d.ts +104 -62
  86. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  87. package/dist/modules/lighting/lights/lighting.js +107 -68
  88. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  89. package/dist/modules/lighting/no-material/dirlight.d.ts +8 -3
  90. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  91. package/dist/modules/lighting/no-material/dirlight.js +5 -3
  92. package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
  93. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +2 -2
  94. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
  95. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +694 -38
  96. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
  97. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
  98. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  99. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +956 -109
  100. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  101. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +242 -43
  102. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  103. package/dist/modules/lighting/pbr-material/pbr-material.js +178 -2
  104. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
  105. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
  106. package/dist/modules/lighting/pbr-material/pbr-projection.js +14 -2
  107. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
  108. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +40 -0
  109. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
  110. package/dist/modules/lighting/pbr-material/pbr-scene.js +67 -0
  111. package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
  112. package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
  113. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  114. package/dist/modules/lighting/phong-material/phong-material.js +4 -0
  115. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
  116. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  117. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  118. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +17 -6
  119. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
  120. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
  121. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
  122. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
  123. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
  124. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  125. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  126. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +42 -11
  127. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
  128. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
  129. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
  130. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
  131. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
  132. package/dist/modules/math/fp64/fp64.d.ts +1 -0
  133. package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
  134. package/dist/modules/math/fp64/fp64.js +8 -2
  135. package/dist/modules/math/fp64/fp64.js.map +1 -1
  136. package/dist/modules/math/random/random.d.ts +1 -1
  137. package/dist/modules/math/random/random.d.ts.map +1 -1
  138. package/dist/modules/math/random/random.js +2 -3
  139. package/dist/modules/math/random/random.js.map +1 -1
  140. package/package.json +4 -5
  141. package/src/index.ts +37 -6
  142. package/src/lib/glsl-utils/shader-utils.ts +4 -4
  143. package/src/lib/preprocessor/preprocessor.ts +44 -8
  144. package/src/lib/shader-assembler.ts +25 -3
  145. package/src/lib/shader-assembly/assemble-shaders.ts +506 -13
  146. package/src/lib/shader-assembly/wgsl-binding-debug.ts +227 -0
  147. package/src/lib/shader-assembly/wgsl-binding-scan.ts +228 -0
  148. package/src/lib/shader-generator/glsl/generate-glsl.ts +11 -5
  149. package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
  150. package/src/lib/shader-module/shader-module-uniform-layout.ts +420 -0
  151. package/src/lib/shader-module/shader-module.ts +17 -7
  152. package/src/lib/utils/assert.ts +3 -1
  153. package/src/lib/utils/uniform-types.ts +24 -9
  154. package/src/modules/engine/picking/picking.ts +5 -2
  155. package/src/modules/engine/project/project.ts +1 -1
  156. package/src/modules/engine/skin/skin.ts +114 -0
  157. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  158. package/src/modules/lighting/ibl/ibl.ts +44 -0
  159. package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
  160. package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
  161. package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
  162. package/src/modules/lighting/lights/lighting-glsl.ts +44 -38
  163. package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
  164. package/src/modules/lighting/lights/lighting.ts +198 -99
  165. package/src/modules/lighting/no-material/dirlight.ts +5 -3
  166. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +694 -38
  167. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +956 -109
  168. package/src/modules/lighting/pbr-material/pbr-material.ts +294 -7
  169. package/src/modules/lighting/pbr-material/pbr-projection.ts +15 -2
  170. package/src/modules/lighting/pbr-material/pbr-scene.ts +91 -0
  171. package/src/modules/lighting/phong-material/phong-material.ts +5 -0
  172. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +17 -6
  173. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
  174. package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +42 -11
  175. package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
  176. package/src/modules/math/fp64/fp64.ts +9 -3
  177. package/src/modules/math/random/random.ts +2 -3
  178. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts +0 -8
  179. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +0 -1
  180. package/dist/lib/wgsl/get-shader-layout-wgsl.js +0 -95
  181. package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +0 -1
  182. package/src/lib/wgsl/get-shader-layout-wgsl.ts +0 -105
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 yr=Object.create;var Ee=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var kr=Object.getOwnPropertyNames;var Ir=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var Ar=(a,e,t)=>e in a?Ee(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var Tr=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),Lr=(a,e)=>{for(var t in e)Ee(a,t,{get:e[t],enumerable:!0})},Qe=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of kr(e))!Sr.call(a,r)&&r!==t&&Ee(a,r,{get:()=>e[r],enumerable:!(n=wr(e,r))||n.enumerable});return a},Ye=(a,e,t)=>(Qe(a,e,"default"),t&&Qe(t,e,"default")),Rt=(a,e,t)=>(t=a!=null?yr(Ir(a)):{},Qe(e||!a||!a.__esModule?Ee(t,"default",{value:a,enumerable:!0}):t,a)),Er=a=>Qe(Ee({},"__esModule",{value:!0}),a);var vn=(a,e,t)=>(Ar(a,typeof e!="symbol"?e+"":e,t),t);var Je=Tr((Es,bn)=>{bn.exports=globalThis.luma});var Ze={};Lr(Ze,{ShaderAssembler:()=>De,_getDependencyGraph:()=>Fe,_resolveModules:()=>Cn,assembleGLSLShaderPair:()=>nt,capitalize:()=>pe,checkShaderModuleDeprecations:()=>Oe,combineInjects:()=>Ln,convertToVec4:()=>Gt,dirlight:()=>mn,fp32:()=>lr,fp64:()=>fr,fp64LowPart:()=>je,fp64arithmetic:()=>hn,fp64ify:()=>Te,fp64ifyMatrix4:()=>Xe,fromHalfFloat:()=>or,generateShaderForModule:()=>zn,getPassthroughFS:()=>Un,getQualifierDetails:()=>Vn,getShaderInfo:()=>tt,getShaderLayoutFromWGSL:()=>Jn,getShaderModuleDependencies:()=>Pe,getShaderModuleSource:()=>rt,getShaderModuleUniforms:()=>En,gouraudMaterial:()=>_n,initializeShaderModule:()=>et,initializeShaderModules:()=>ne,lighting:()=>te,pbrMaterial:()=>xr,phongMaterial:()=>gn,picking:()=>hr,preprocess:()=>st,random:()=>ar,toHalfFloat:()=>sr,typeToChannelCount:()=>Hn,typeToChannelSuffix:()=>$n});Ye(Ze,Rt(Je(),1));function le(a,e){if(!a)throw new Error(e||"shadertools: assertion failed.")}var Bt={number:{type:"number",validate(a,e){return Number.isFinite(a)&&typeof e=="object"&&(e.max===void 0||a<=e.max)&&(e.min===void 0||a>=e.min)}},array:{type:"array",validate(a,e){return Array.isArray(a)||ArrayBuffer.isView(a)}}};function yn(a){let e={};for(let[t,n]of Object.entries(a))e[t]=Cr(n);return e}function wn(a,e,t){let n={};for(let[r,s]of Object.entries(e))a&&r in a&&!s.private?(s.validate&&le(s.validate(a[r],s),`${t}: invalid ${r}`),n[r]=a[r]):n[r]=s.value;return n}function Cr(a){let e=xn(a);if(e!=="object")return{value:a,...Bt[e],type:e};if(typeof a=="object")return a?a.type!==void 0?{...a,...Bt[a.type],type:a.type}:a.value===void 0?{type:"object",value:a}:(e=xn(a.value),{...a,...Bt[e],type:e}):{type:"object",value:null};throw new Error("props")}function xn(a){return Array.isArray(a)||ArrayBuffer.isView(a)?"array":typeof a}var kn=`#ifdef MODULE_LOGDEPTH
7
+ "use strict";var __exports__=(()=>{var $n=Object.create;var X=Object.defineProperty;var Wn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var qn=Object.getPrototypeOf,Kn=Object.prototype.hasOwnProperty;var Yn=(e,t,n)=>t in e?X(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Xn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Zn=(e,t)=>{for(var n in t)X(e,n,{get:t[n],enumerable:!0})},ce=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of jn(t))!Kn.call(e,o)&&o!==n&&X(e,o,{get:()=>t[o],enumerable:!(r=Wn(t,o))||r.enumerable});return e},le=(e,t,n)=>(ce(e,t,"default"),n&&ce(n,t,"default")),ct=(e,t,n)=>(n=e!=null?$n(qn(e)):{},ce(t||!e||!e.__esModule?X(n,"default",{value:e,enumerable:!0}):n,e)),Qn=e=>ce(X({},"__esModule",{value:!0}),e);var lt=(e,t,n)=>(Yn(e,typeof t!="symbol"?t+"":t,n),n);var Ue=Xn((zo,ft)=>{ft.exports=globalThis.luma});var se={};Zn(se,{ShaderAssembler:()=>re,_getDependencyGraph:()=>te,_resolveModules:()=>xt,assembleGLSLShaderPair:()=>ve,capitalize:()=>D,checkShaderModuleDeprecations:()=>J,combineInjects:()=>vt,convertToVec4:()=>qe,dirlight:()=>ot,fp32:()=>Mn,fp64:()=>En,fp64LowPart:()=>oe,fp64arithmetic:()=>nt,fp64ify:()=>K,fp64ifyMatrix4:()=>ie,fromHalfFloat:()=>vn,generateShaderForModule:()=>$t,getGLSLUniformBlocks:()=>he,getPassthroughFS:()=>kt,getQualifierDetails:()=>Bt,getShaderInfo:()=>me,getShaderModuleDependencies:()=>ee,getShaderModuleSource:()=>Se,getShaderModuleUniformBlockFields:()=>we,getShaderModuleUniformBlockName:()=>pe,getShaderModuleUniformLayoutValidationResult:()=>Be,getShaderModuleUniforms:()=>St,gouraudMaterial:()=>at,ibl:()=>Ne,initializeShaderModule:()=>fe,initializeShaderModules:()=>F,lambertMaterial:()=>it,lighting:()=>V,pbrMaterial:()=>Dn,pbrScene:()=>Hn,phongMaterial:()=>st,picking:()=>An,preprocess:()=>xe,random:()=>xn,skin:()=>In,toHalfFloat:()=>bn,typeToChannelCount:()=>zt,typeToChannelSuffix:()=>Dt,validateShaderModuleUniformLayout:()=>ue,warnIfGLSLUniformBlocksAreNotStd140:()=>ge});le(se,ct(Ue(),1));function U(e,t){if(!e){let n=new Error(t||"shadertools: assertion failed.");throw Error.captureStackTrace?.(n,U),n}}var Fe={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 ut(e){let t={};for(let[n,r]of Object.entries(e))t[n]=Jn(r);return t}function ht(e,t,n){let r={};for(let[o,i]of Object.entries(t))e&&o in e&&!i.private?(i.validate&&U(i.validate(e[o],i),`${n}: invalid ${o}`),r[o]=e[o]):r[o]=i.value;return r}function Jn(e){let t=pt(e);if(t!=="object")return{value:e,...Fe[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...Fe[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=pt(e.value),{...e,...Fe[t],type:t}):{type:"object",value:null};throw new Error("props")}function pt(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}var gt=`#ifdef MODULE_LOGDEPTH
8
8
  logdepth_adjustPosition(gl_Position);
9
9
  #endif
10
- `,In=`#ifdef MODULE_MATERIAL
10
+ `,mt=`#ifdef MODULE_MATERIAL
11
11
  fragColor = material_filterColor(fragColor);
12
12
  #endif
13
13
 
@@ -27,10 +27,11 @@
27
27
  #ifdef MODULE_LOGDEPTH
28
28
  logdepth_setFragDepth();
29
29
  #endif
30
- `;var Nr={vertex:kn,fragment:In},Sn=/void\s+main\s*\([^)]*\)\s*\{\n?/,An=/}\n?[^{}]*$/,Vt=[],Ce="__LUMA_INJECT_DECLARATIONS__";function Tn(a){let e={vertex:{},fragment:{}};for(let t in a){let n=a[t],r=Or(t);typeof n=="string"&&(n={order:0,injection:n}),e[r][t]=n}return e}function Or(a){let e=a.slice(0,2);switch(e){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(e)}}function Ne(a,e,t,n=!1){let r=e==="vertex";for(let s in t){let i=t[s];i.sort((l,c)=>l.order-c.order),Vt.length=i.length;for(let l=0,c=i.length;l<c;++l)Vt[l]=i[l].injection;let o=`${Vt.join(`
30
+ `;var er={vertex:gt,fragment:mt},dt=/void\s+main\s*\([^)]*\)\s*\{\n?/,_t=/}\n?[^{}]*$/,Ve=[],Z="__LUMA_INJECT_DECLARATIONS__";function bt(e){let t={vertex:{},fragment:{}};for(let n in e){let r=e[n],o=tr(n);typeof r=="string"&&(r={order:0,injection:r}),t[o][n]=r}return t}function tr(e){let t=e.slice(0,2);switch(t){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(t)}}function Q(e,t,n,r=!1){let o=t==="vertex";for(let i in n){let a=n[i];a.sort((c,l)=>c.order-l.order),Ve.length=a.length;for(let c=0,l=a.length;c<l;++c)Ve[c]=a[c].injection;let s=`${Ve.join(`
31
31
  `)}
32
- `;switch(s){case"vs:#decl":r&&(a=a.replace(Ce,o));break;case"vs:#main-start":r&&(a=a.replace(Sn,l=>l+o));break;case"vs:#main-end":r&&(a=a.replace(An,l=>o+l));break;case"fs:#decl":r||(a=a.replace(Ce,o));break;case"fs:#main-start":r||(a=a.replace(Sn,l=>l+o));break;case"fs:#main-end":r||(a=a.replace(An,l=>o+l));break;default:a=a.replace(s,l=>l+o)}}return a=a.replace(Ce,""),n&&(a=a.replace(/\}\s*$/,s=>s+Nr[e])),a}function Ln(a){let e={};return le(Array.isArray(a)&&a.length>1),a.forEach(t=>{for(let n in t)e[n]=e[n]?`${e[n]}
33
- ${t[n]}`:t[n]}),e}function ne(a){a.map(e=>et(e))}function et(a){if(a.instance)return;ne(a.dependencies||[]);let{propTypes:e={},deprecations:t=[],inject:n={}}=a,r={normalizedInjections:Tn(n),parsedDeprecations:Pr(t)};e&&(r.propValidators=yn(e)),a.instance=r;let s={};e&&(s=Object.entries(e).reduce((i,[o,l])=>{let c=l?.value;return c&&(i[o]=c),i},{})),a.defaultUniforms={...a.defaultUniforms,...s}}function En(a,e,t){et(a);let n=t||{...a.defaultUniforms};return e&&a.getUniforms?a.getUniforms(e,n):wn(e,a.instance?.propValidators,a.name)}function Oe(a,e,t){a.deprecations?.forEach(n=>{n.regex?.test(e)&&(n.deprecated?t.deprecated(n.old,n.new)():t.removed(n.old,n.new)())})}function Pr(a){return a.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),a}function Pe(a){ne(a);let e={},t={};Fe({modules:a,level:0,moduleMap:e,moduleDepth:t});let n=Object.keys(t).sort((r,s)=>t[s]-t[r]).map(r=>e[r]);return ne(n),n}function Fe(a){let{modules:e,level:t,moduleMap:n,moduleDepth:r}=a;if(t>=5)throw new Error("Possible loop in shader dependency graph");for(let s of e)n[s.name]=s,(r[s.name]===void 0||r[s.name]<t)&&(r[s.name]=t);for(let s of e)s.dependencies&&Fe({modules:s.dependencies,level:t+1,moduleMap:n,moduleDepth:r})}function Fr(a){ne(a);let e={},t={};return Fe({modules:a,level:0,moduleMap:e,moduleDepth:t}),a=Object.keys(t).sort((n,r)=>t[r]-t[n]).map(n=>e[n]),ne(a),a}function Cn(a){return Fr(a)}function Nn(a){switch(a?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
32
+ `;switch(i){case"vs:#decl":o&&(e=e.replace(Z,s));break;case"vs:#main-start":o&&(e=e.replace(dt,c=>c+s));break;case"vs:#main-end":o&&(e=e.replace(_t,c=>s+c));break;case"fs:#decl":o||(e=e.replace(Z,s));break;case"fs:#main-start":o||(e=e.replace(dt,c=>c+s));break;case"fs:#main-end":o||(e=e.replace(_t,c=>s+c));break;default:e=e.replace(i,c=>c+s)}}return e=e.replace(Z,""),r&&(e=e.replace(/\}\s*$/,i=>i+er[t])),e}function vt(e){let t={};return U(Array.isArray(e)&&e.length>1),e.forEach(n=>{for(let r in n)t[r]=t[r]?`${t[r]}
33
+ ${n[r]}`:n[r]}),t}function F(e){e.map(t=>fe(t))}function fe(e){if(e.instance)return;F(e.dependencies||[]);let{propTypes:t={},deprecations:n=[],inject:r={}}=e,o={normalizedInjections:bt(r),parsedDeprecations:nr(n)};t&&(o.propValidators=ut(t)),e.instance=o;let i={};t&&(i=Object.entries(t).reduce((a,[s,c])=>{let l=c?.value;return l&&(a[s]=l),a},{})),e.defaultUniforms={...e.defaultUniforms,...i}}function St(e,t,n){fe(e);let r=n||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,r):ht(t,e.instance?.propValidators,e.name)}function J(e,t,n){e.deprecations?.forEach(r=>{r.regex?.test(t)&&(r.deprecated?n.deprecated(r.old,r.new)():n.removed(r.old,r.new)())})}function nr(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 ee(e){F(e);let t={},n={};te({modules:e,level:0,moduleMap:t,moduleDepth:n});let r=Object.keys(n).sort((o,i)=>n[i]-n[o]).map(o=>t[o]);return F(r),r}function te(e){let{modules:t,level:n,moduleMap:r,moduleDepth:o}=e;if(n>=5)throw new Error("Possible loop in shader dependency graph");for(let i of t)r[i.name]=i,(o[i.name]===void 0||o[i.name]<n)&&(o[i.name]=n);for(let i of t)i.dependencies&&te({modules:i.dependencies,level:n+1,moduleMap:r,moduleDepth:o})}function rr(e){F(e);let t={},n={};return te({modules:e,level:0,moduleMap:t,moduleDepth:n}),e=Object.keys(n).sort((r,o)=>n[o]-n[r]).map(r=>t[r]),F(e),e}function xt(e){return rr(e)}var or=/^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/,ir=/((?:layout\s*\([^)]*\)\s*)*)uniform\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\}\s*([A-Za-z_][A-Za-z0-9_]*)?\s*;/g;function pe(e){return`${e.name}Uniforms`}function we(e,t){let n=t==="wgsl"?e.source:t==="vertex"?e.vs:e.fs;if(!n)return null;let r=pe(e);return ar(n,t==="wgsl"?"wgsl":"glsl",r)}function Be(e,t){let n=Object.keys(e.uniformTypes||{});if(!n.length)return null;let r=we(e,t);return r?{moduleName:e.name,uniformBlockName:pe(e),stage:t,expectedUniformNames:n,actualUniformNames:r,matches:lr(n,r)}:null}function ue(e,t,n={}){let r=Be(e,t);if(!r||r.matches)return r;let o=fr(r);return n.log?.error?.(o,r)(),n.throwOnError!==!1&&U(!1,o),r}function he(e){let t=[],n=pr(e);for(let r of n.matchAll(ir)){let o=r[1]?.trim()||null;t.push({blockName:r[2],body:r[3],instanceName:r[4]||null,layoutQualifier:o,hasLayoutQualifier:Boolean(o),isStd140:Boolean(o&&/\blayout\s*\([^)]*\bstd140\b[^)]*\)/.exec(o))})}return t}function ge(e,t,n,r){let o=he(e).filter(a=>!a.isStd140),i=new Set;for(let a of o){if(i.has(a.blockName))continue;i.add(a.blockName);let s=r?.label?`${r.label} `:"",c=a.hasLayoutQualifier?`declares ${ur(a.layoutQualifier)} instead of layout(std140)`:"does not declare layout(std140)",l=`${s}${t} shader uniform block ${a.blockName} ${c}. luma.gl host-side shader block packing assumes explicit layout(std140) for GLSL uniform blocks. Add \`layout(std140)\` to the block declaration.`;n?.warn?.(l,a)()}return o}function ar(e,t,n){let r=t==="wgsl"?sr(e,n):cr(e,n);if(!r)return null;let o=[];for(let i of r.split(`
34
+ `)){let a=i.replace(/\/\/.*$/,"").trim();if(!a||a.startsWith("#"))continue;let s=t==="wgsl"?a.match(/^([A-Za-z0-9_]+)\s*:/):a.match(or);s&&o.push(s[1])}return o}function sr(e,t){let n=new RegExp(`\\bstruct\\s+${t}\\b`,"m").exec(e);if(!n)return null;let r=e.indexOf("{",n.index);if(r<0)return null;let o=0;for(let i=r;i<e.length;i++){let a=e[i];if(a==="{"){o++;continue}if(a==="}"&&(o--,o===0))return e.slice(r+1,i)}return null}function cr(e,t){return he(e).find(r=>r.blockName===t)?.body||null}function lr(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function fr(e){let{expectedUniformNames:t,actualUniformNames:n}=e,r=t.filter(s=>!n.includes(s)),o=n.filter(s=>!t.includes(s)),i=[`Expected ${t.length} fields, found ${n.length}.`],a=hr(t,n);return a&&i.push(a),r.length&&i.push(`Missing from shader block (${r.length}): ${Mt(r)}.`),o.length&&i.push(`Unexpected in shader block (${o.length}): ${Mt(o)}.`),t.length<=12&&n.length<=12&&(r.length||o.length)&&(i.push(`Expected: ${t.join(", ")}.`),i.push(`Actual: ${n.join(", ")}.`)),`${e.moduleName}: ${e.stage} shader uniform block ${e.uniformBlockName} does not match module.uniformTypes. ${i.join(" ")}`}function pr(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function ur(e){return e.replace(/\s+/g," ").trim()}function hr(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return`First mismatch at field ${r+1}: expected ${e[r]}, found ${t[r]}.`;return e.length>t.length?`Shader block ends after field ${t.length}; expected next field ${e[t.length]}.`:t.length>e.length?`Shader block has extra field ${t.length}: ${t[e.length]}.`:null}function Mt(e,t=8){if(e.length<=t)return e.join(", ");let n=e.length-t;return`${e.slice(0,t).join(", ")}, ... (${n} more)`}function Lt(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
34
35
  // Apple optimizes away the calculation necessary for emulated fp64
35
36
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
36
37
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
@@ -54,60 +55,60 @@ ${t[n]}`:t[n]}),e}function ne(a){a.map(e=>et(e))}function et(a){if(a.instance)re
54
55
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
55
56
  // If the GPU doesn't have full 32 bits precision, will causes overflow
56
57
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
57
- `}}function Pn(a,e){if(Number(a.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(e){case"vertex":return a=On(a,Dr),a;case"fragment":return a=On(a,Mr),a;default:throw new Error(e)}}var Fn=[[/^(#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("]],Dr=[...Fn,[Ut("attribute"),"in $1"],[Ut("varying"),"out $1"]],Mr=[...Fn,[Ut("varying"),"in $1"]];function On(a,e){for(let[t,n]of e)a=a.replace(t,n);return a}function Ut(a){return new RegExp(`\\b${a}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function $t(a,e){let t="";for(let n in a){let r=a[n];if(t+=`void ${r.signature} {
59
- `,r.header&&(t+=` ${r.header}`),e[n]){let s=e[n];s.sort((i,o)=>i.order-o.order);for(let i of s)t+=` ${i.injection}
60
- `}r.footer&&(t+=` ${r.footer}`),t+=`}
61
- `}return t}function Ht(a){let e={vertex:{},fragment:{}};for(let t of a){let n,r;typeof t!="string"?(n=t,r=n.hook):(n={},r=t),r=r.trim();let[s,i]=r.split(":"),o=r.replace(/\(.+/,""),l=Object.assign(n,{signature:i});switch(s){case"vs":e.vertex[o]=l;break;case"fs":e.fragment[o]=l;break;default:throw new Error(s)}}return e}function tt(a,e){return{name:Rr(a,e),language:"glsl",version:Br(a)}}function Rr(a,e="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(a);return n?n[1]:e}function Br(a){let e=100,t=a.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){let n=parseInt(t[1],10);Number.isFinite(n)&&(e=n)}if(e!==100&&e!==300)throw new Error(`Invalid GLSL version ${e}`);return e}var Mn=`
62
-
63
- ${Ce}
64
- `,Vr=`precision highp float;
65
- `;function Rn(a){let e=Pe(a.modules||[]);return{source:Ur(a.platformInfo,{...a,source:a.source,stage:"vertex",modules:e}),getUniforms:Bn(e)}}function nt(a){let{vs:e,fs:t}=a,n=Pe(a.modules||[]);return{vs:Dn(a.platformInfo,{...a,source:e,stage:"vertex",modules:n}),fs:Dn(a.platformInfo,{...a,source:t,stage:"fragment",modules:n}),getUniforms:Bn(n)}}function Ur(a,e){let{source:t,stage:n,modules:r,hookFunctions:s=[],inject:i={},log:o}=e;le(typeof t=="string","shader source must be a string");let l=t,c="",u=Ht(s),h={},b={},y={};for(let E in i){let T=typeof i[E]=="string"?{injection:i[E],order:0}:i[E],L=/^(v|f)s:(#)?([\w-]+)$/.exec(E);if(L){let P=L[2],k=L[3];P?k==="decl"?b[E]=[T]:y[E]=[T]:h[E]=[T]}else y[E]=[T]}let S=r;for(let E of S){o&&Oe(E,l,o);let T=rt(E,"wgsl");c+=T;let L=E.injections?.[n]||{};for(let P in L){let k=/^(v|f)s:#([\w-]+)$/.exec(P);if(k){let B=k[2]==="decl"?b:y;B[P]=B[P]||[],B[P].push(L[P])}else h[P]=h[P]||[],h[P].push(L[P])}}return c+=Mn,c=Ne(c,n,b),c+=$t(u[n],h),c+=l,c=Ne(c,n,y),c}function Dn(a,e){let{source:t,stage:n,language:r="glsl",modules:s,defines:i={},hookFunctions:o=[],inject:l={},prologue:c=!0,log:u}=e;le(typeof t=="string","shader source must be a string");let h=r==="glsl"?tt(t).version:-1,b=a.shaderLanguageVersion,y=h===100?"#version 100":"#version 300 es",E=t.split(`
58
+ `}}function Et(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=Rt(e,gr),e;case"fragment":return e=Rt(e,mr),e;default:throw new Error(t)}}var At=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
59
+ `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],gr=[...At,[ke("attribute"),"in $1"],[ke("varying"),"out $1"]],mr=[...At,[ke("varying"),"in $1"]];function Rt(e,t){for(let[n,r]of t)e=e.replace(n,r);return e}function ke(e){return new RegExp(`\\b${e}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function De(e,t){let n="";for(let r in e){let o=e[r];if(n+=`void ${o.signature} {
60
+ `,o.header&&(n+=` ${o.header}`),t[r]){let i=t[r];i.sort((a,s)=>a.order-s.order);for(let a of i)n+=` ${a.injection}
61
+ `}o.footer&&(n+=` ${o.footer}`),n+=`}
62
+ `}return n}function ze(e){let t={vertex:{},fragment:{}};for(let n of e){let r,o;typeof n!="string"?(r=n,o=r.hook):(r={},o=n),o=o.trim();let[i,a]=o.split(":"),s=o.replace(/\(.+/,""),c=Object.assign(r,{signature:a});switch(i){case"vs":t.vertex[s]=c;break;case"fs":t.fragment[s]=c;break;default:throw new Error(i)}}return t}function me(e,t){return{name:dr(e,t),language:"glsl",version:_r(e)}}function dr(e,t="unnamed"){let r=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(e);return r?r[1]:t}function _r(e){let t=100,n=e.match(/[^\s]+/g);if(n&&n.length>=2&&n[0]==="#version"){let r=parseInt(n[1],10);Number.isFinite(r)&&(t=r)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}var N="(?:var<\\s*(uniform|storage(?:\\s*,\\s*[A-Za-z_][A-Za-z0-9_]*)?)\\s*>|var)\\s+([A-Za-z_][A-Za-z0-9_]*)",T="\\s*",H=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(auto|\\d+)\\s*\\)${T}${N}`,"g")],de=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(auto|\\d+)\\s*\\)${T}${N}`,"g")],It=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g")],br=[new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)\\s*${N}`,"g"),new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${N}`,"g")];function _e(e){let t=e.split(""),n=0,r=0,o=!1,i=!1,a=!1;for(;n<e.length;){let s=e[n],c=e[n+1];if(i){a?a=!1:s==="\\"?a=!0:s==='"'&&(i=!1),n++;continue}if(o){s===`
63
+ `||s==="\r"?o=!1:t[n]=" ",n++;continue}if(r>0){if(s==="/"&&c==="*"){t[n]=" ",t[n+1]=" ",r++,n+=2;continue}if(s==="*"&&c==="/"){t[n]=" ",t[n+1]=" ",r--,n+=2;continue}s!==`
64
+ `&&s!=="\r"&&(t[n]=" "),n++;continue}if(s==='"'){i=!0,n++;continue}if(s==="/"&&c==="/"){t[n]=" ",t[n+1]=" ",o=!0,n+=2;continue}if(s==="/"&&c==="*"){t[n]=" ",t[n+1]=" ",r=1,n+=2;continue}n++}return t.join("")}function k(e,t){let n=_e(e),r=[];for(let o of t){o.lastIndex=0;let i;for(i=o.exec(n);i;){let a=o===t[0],s=i.index,c=i[0].length;r.push({match:e.slice(s,s+c),index:s,length:c,bindingToken:i[a?1:2],groupToken:i[a?2:1],accessDeclaration:i[3]?.trim(),name:i[4]}),i=o.exec(n)}}return r.sort((o,i)=>o.index-i.index)}function Ge(e,t,n){let r=k(e,t);if(!r.length)return e;let o="",i=0;for(let a of r)o+=e.slice(i,a.index),o+=n(a),i=a.index+a.length;return o+=e.slice(i),o}function He(e){return/@binding\(\s*auto\s*\)/.test(_e(e))}function Ct(e,t){return k(e,t===H||t===de?br:t).find(r=>r.bindingToken==="auto")}var yt=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${N}\\s*:\\s*([^;]+);`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${N}\\s*:\\s*([^;]+);`,"g")];function be(e,t=[]){let n=_e(e),r=new Map;for(let i of t)r.set(Nt(i.name,i.group,i.location),i.moduleName);let o=[];for(let i of yt){i.lastIndex=0;let a;for(a=i.exec(n);a;){let s=i===yt[0],c=Number(a[s?1:2]),l=Number(a[s?2:1]),p=a[3]?.trim(),f=a[4],u=a[5].trim(),h=r.get(Nt(f,l,c));o.push(vr({name:f,group:l,binding:c,owner:h?"module":"application",moduleName:h,accessDeclaration:p,resourceType:u})),a=i.exec(n)}}return o.sort((i,a)=>i.group!==a.group?i.group-a.group:i.binding!==a.binding?i.binding-a.binding:i.name.localeCompare(a.name))}function vr(e){let t={name:e.name,group:e.group,binding:e.binding,owner:e.owner,kind:"unknown",moduleName:e.moduleName,resourceType:e.resourceType};if(e.accessDeclaration){let n=e.accessDeclaration.split(",").map(r=>r.trim());if(n[0]==="uniform")return{...t,kind:"uniform",access:"uniform"};if(n[0]==="storage"){let r=n[1]||"read_write";return{...t,kind:r==="read"?"read-only-storage":"storage",access:r}}}return e.resourceType==="sampler"||e.resourceType==="sampler_comparison"?{...t,kind:"sampler",samplerKind:e.resourceType==="sampler_comparison"?"comparison":"filtering"}:e.resourceType.startsWith("texture_storage_")?{...t,kind:"storage-texture",access:xr(e.resourceType),viewDimension:Pt(e.resourceType)}:e.resourceType.startsWith("texture_")?{...t,kind:"texture",viewDimension:Pt(e.resourceType),sampleType:Sr(e.resourceType),multisampled:e.resourceType.startsWith("texture_multisampled_")}:t}function Nt(e,t,n){return`${t}:${n}:${e}`}function Pt(e){if(e.includes("cube_array"))return"cube-array";if(e.includes("2d_array"))return"2d-array";if(e.includes("cube"))return"cube";if(e.includes("3d"))return"3d";if(e.includes("2d"))return"2d";if(e.includes("1d"))return"1d"}function Sr(e){if(e.startsWith("texture_depth_"))return"depth";if(e.includes("<i32>"))return"sint";if(e.includes("<u32>"))return"uint";if(e.includes("<f32>"))return"float"}function xr(e){return/,\s*([A-Za-z_][A-Za-z0-9_]*)\s*>$/.exec(e)?.[1]}var $e=`
65
+
66
+ ${Z}
67
+ `,ne=100,Mr=`precision highp float;
68
+ `;function Ft(e){let t=ee(e.modules||[]),{source:n,bindingAssignments:r}=Lr(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t});return{source:n,getUniforms:Vt(t),bindingAssignments:r,bindingTable:be(n,r)}}function ve(e){let{vs:t,fs:n}=e,r=ee(e.modules||[]);return{vs:Tt(e.platformInfo,{...e,source:t,stage:"vertex",modules:r}),fs:Tt(e.platformInfo,{...e,source:n,stage:"fragment",modules:r}),getUniforms:Vt(r)}}function Lr(e,t){let{source:n,stage:r,modules:o,hookFunctions:i=[],inject:a={},log:s}=t;U(typeof n=="string","shader source must be a string");let c=n,l="",p=ze(i),f={},u={},h={};for(let d in a){let b=typeof a[d]=="string"?{injection:a[d],order:0}:a[d],v=/^(v|f)s:(#)?([\w-]+)$/.exec(d);if(v){let g=v[2],M=v[3];g?M==="decl"?u[d]=[b]:h[d]=[b]:f[d]=[b]}else h[d]=[b]}let m=o,S=Ar(c),x=Er(S.source),_=Nr(m,t._bindingRegistry,x),L=[];for(let d of m){s&&J(d,c,s);let b=Ir(Se(d,"wgsl",s),d,{usedBindingsByGroup:x,bindingRegistry:t._bindingRegistry,reservedBindingKeysByGroup:_});L.push(...b.bindingAssignments);let v=b.source;l+=v;let g=d.injections?.[r]||{};for(let M in g){let A=/^(v|f)s:#([\w-]+)$/.exec(M);if(A){let I=A[2]==="decl"?u:h;I[M]=I[M]||[],I[M].push(g[M])}else f[M]=f[M]||[],f[M].push(g[M])}}return l+=$e,l=Q(l,r,u),l+=De(p[r],f),l+=Fr(L),l+=S.source,l=Q(l,r,h),Ur(l),{source:l,bindingAssignments:L}}function Tt(e,t){let{source:n,stage:r,language:o="glsl",modules:i,defines:a={},hookFunctions:s=[],inject:c={},prologue:l=!0,log:p}=t;U(typeof n=="string","shader source must be a string");let f=o==="glsl"?me(n).version:-1,u=e.shaderLanguageVersion,h=f===100?"#version 100":"#version 300 es",S=n.split(`
66
69
  `).slice(1).join(`
67
- `),T={};s.forEach(O=>{Object.assign(T,O.defines)}),Object.assign(T,i);let L="";switch(r){case"wgsl":break;case"glsl":L=c?`${y}
70
+ `),x={};i.forEach(g=>{Object.assign(x,g.defines)}),Object.assign(x,a);let _="";switch(o){case"wgsl":break;case"glsl":_=l?`${h}
68
71
 
69
72
  // ----- PROLOGUE -------------------------
70
- ${`#define SHADER_TYPE_${n.toUpperCase()}`}
73
+ ${`#define SHADER_TYPE_${r.toUpperCase()}`}
71
74
 
72
- ${Nn(a)}
73
- ${n==="fragment"?Vr:""}
75
+ ${Lt(e)}
76
+ ${r==="fragment"?Mr:""}
74
77
 
75
78
  // ----- APPLICATION DEFINES -------------------------
76
79
 
77
- ${$r(T)}
80
+ ${Rr(x)}
78
81
 
79
- `:`${y}
80
- `;break}let P=Ht(o),k={},A={},B={};for(let O in l){let oe=typeof l[O]=="string"?{injection:l[O],order:0}:l[O],X=/^(v|f)s:(#)?([\w-]+)$/.exec(O);if(X){let U=X[2],he=X[3];U?he==="decl"?A[O]=[oe]:B[O]=[oe]:k[O]=[oe]}else B[O]=[oe]}for(let O of s){u&&Oe(O,E,u);let oe=rt(O,n);L+=oe;let X=O.instance?.normalizedInjections[n]||{};for(let U in X){let he=/^(v|f)s:#([\w-]+)$/.exec(U);if(he){let Mt=he[2]==="decl"?A:B;Mt[U]=Mt[U]||[],Mt[U].push(X[U])}else k[U]=k[U]||[],k[U].push(X[U])}}return L+="// ----- MAIN SHADER SOURCE -------------------------",L+=Mn,L=Ne(L,n,A),L+=$t(P[n],k),L+=E,L=Ne(L,n,B),r==="glsl"&&h!==b&&(L=Pn(L,n)),L.trim()}function Bn(a){return function(t){let n={};for(let r of a){let s=r.getUniforms?.(t,n);Object.assign(n,s)}return n}}function $r(a={}){let e="";for(let t in a){let n=a[t];(n||Number.isFinite(n))&&(e+=`#define ${t.toUpperCase()} ${a[t]}
81
- `)}return e}function rt(a,e){let t;switch(e){case"vertex":t=a.vs||"";break;case"fragment":t=a.fs||"";break;case"wgsl":t=a.source||"";break;default:le(!1)}if(!a.name)throw new Error("Shader module must have a name");let n=a.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),r=`// ----- MODULE ${a.name} ---------------
82
+ `:`${h}
83
+ `;break}let L=ze(s),d={},b={},v={};for(let g in c){let M=typeof c[g]=="string"?{injection:c[g],order:0}:c[g],A=/^(v|f)s:(#)?([\w-]+)$/.exec(g);if(A){let R=A[2],I=A[3];R?I==="decl"?b[g]=[M]:v[g]=[M]:d[g]=[M]}else v[g]=[M]}for(let g of i){p&&J(g,S,p);let M=Se(g,r,p);_+=M;let A=g.instance?.normalizedInjections[r]||{};for(let R in A){let I=/^(v|f)s:#([\w-]+)$/.exec(R);if(I){let C=I[2]==="decl"?b:v;C[R]=C[R]||[],C[R].push(A[R])}else d[R]=d[R]||[],d[R].push(A[R])}}return _+="// ----- MAIN SHADER SOURCE -------------------------",_+=$e,_=Q(_,r,b),_+=De(L[r],d),_+=S,_=Q(_,r,v),o==="glsl"&&f!==u&&(_=Et(_,r)),o==="glsl"&&ge(_,r,p),_.trim()}function Vt(e){return function(n){let r={};for(let o of e){let i=o.getUniforms?.(n,r);Object.assign(r,i)}return r}}function Rr(e={}){let t="";for(let n in e){let r=e[n];(r||Number.isFinite(r))&&(t+=`#define ${n.toUpperCase()} ${e[n]}
84
+ `)}return t}function Se(e,t,n){let r;switch(t){case"vertex":r=e.vs||"";break;case"fragment":r=e.fs||"";break;case"wgsl":r=e.source||"";break;default:U(!1)}if(!e.name)throw new Error("Shader module must have a name");ue(e,t,{log:n});let o=e.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),i=`// ----- MODULE ${e.name} ---------------
82
85
 
83
- `;return e!=="wgsl"&&(r+=`#define MODULE_${n}
84
- `),r+=`${t}
85
- `,r}var Hr=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,Gr=/^\s*\#\s*endif\s*$/;function st(a,e){let t=a.split(`
86
- `),n=[],r=!0,s=null;for(let i of t){let o=i.match(Hr),l=i.match(Gr);o?(s=o[1],r=Boolean(e?.defines?.[s])):l?r=!0:r&&n.push(i)}return n.join(`
87
- `)}var be=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return be.defaultShaderAssembler=be.defaultShaderAssembler||new be,be.defaultShaderAssembler}addDefaultModule(e){this._defaultModules.find(t=>t.name===(typeof e=="string"?e:e.name))||this._defaultModules.push(e)}removeDefaultModule(e){let t=typeof e=="string"?e:e.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==t)}addShaderHook(e,t){t&&(e=Object.assign(t,{hook:e})),this._hookFunctions.push(e)}assembleWGSLShader(e){let t=this._getModuleList(e.modules),n=this._hookFunctions,{source:r,getUniforms:s}=Rn({...e,source:e.source,modules:t,hookFunctions:n});return{source:e.platformInfo.shaderLanguage==="wgsl"?st(r):r,getUniforms:s,modules:t}}assembleGLSLShaderPair(e){let t=this._getModuleList(e.modules),n=this._hookFunctions;return{...nt({...e,vs:e.vs,fs:e.fs,modules:t,hookFunctions:n}),modules:t}}_getModuleList(e=[]){let t=new Array(this._defaultModules.length+e.length),n={},r=0;for(let s=0,i=this._defaultModules.length;s<i;++s){let o=this._defaultModules[s],l=o.name;t[r++]=o,n[l]=!0}for(let s=0,i=e.length;s<i;++s){let o=e[s],l=o.name;n[l]||(t[r++]=o,n[l]=!0)}return t.length=r,ne(t),t}},De=be;vn(De,"defaultShaderAssembler");var Wr=`out vec4 transform_output;
86
+ `;return t!=="wgsl"&&(i+=`#define MODULE_${o}
87
+ `),i+=`${r}
88
+ `,i}function Er(e){let t=new Map;for(let n of k(e,It)){let r=Number(n.bindingToken),o=Number(n.groupToken);We(o,r,n.name),$(t,o,r,`application binding "${n.name}"`)}return t}function Ar(e){let t=k(e,de),n=new Map;for(let i of t){if(i.bindingToken==="auto")continue;let a=Number(i.bindingToken),s=Number(i.groupToken);We(s,a,i.name),$(n,s,a,`application binding "${i.name}"`)}let r={sawSupportedBindingDeclaration:t.length>0},o=Ge(e,de,i=>yr(i,n,r));if(He(e)&&!r.sawSupportedBindingDeclaration)throw new Error('Unsupported @binding(auto) declaration form in application WGSL. Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.');return{source:o}}function Ir(e,t,n){let r=[],i={sawSupportedBindingDeclaration:k(e,H).length>0,nextHintedBindingLocation:typeof t.firstBindingSlot=="number"?t.firstBindingSlot:null},a=Ge(e,H,s=>Cr(s,{module:t,context:n,bindingAssignments:r,relocationState:i}));if(He(e)&&!i.sawSupportedBindingDeclaration)throw new Error(`Unsupported @binding(auto) declaration form in module "${t.name}". Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.`);return{source:a,bindingAssignments:r}}function Cr(e,t){let{module:n,context:r,bindingAssignments:o,relocationState:i}=t,{match:a,bindingToken:s,groupToken:c,name:l}=e,p=Number(c);if(s==="auto"){let u=wt(p,n.name,l),h=r.bindingRegistry?.get(u),m=h!==void 0?h:i.nextHintedBindingLocation===null?Ut(p,r.usedBindingsByGroup):Ut(p,r.usedBindingsByGroup,i.nextHintedBindingLocation);return Ot(n.name,p,m,l),h!==void 0&&Pr(r.reservedBindingKeysByGroup,p,m,u)?(o.push({moduleName:n.name,name:l,group:p,location:m}),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${m})`)):($(r.usedBindingsByGroup,p,m,`module "${n.name}" binding "${l}"`),r.bindingRegistry?.set(u,m),o.push({moduleName:n.name,name:l,group:p,location:m}),i.nextHintedBindingLocation!==null&&h===void 0&&(i.nextHintedBindingLocation=m+1),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${m})`))}let f=Number(s);return Ot(n.name,p,f,l),$(r.usedBindingsByGroup,p,f,`module "${n.name}" binding "${l}"`),o.push({moduleName:n.name,name:l,group:p,location:f}),a}function yr(e,t,n){let{match:r,bindingToken:o,groupToken:i,name:a}=e,s=Number(i);if(o==="auto"){let c=Or(s,t);return We(s,c,a),$(t,s,c,`application binding "${a}"`),r.replace(/@binding\(\s*auto\s*\)/,`@binding(${c})`)}return n.sawSupportedBindingDeclaration=!0,r}function Nr(e,t,n){let r=new Map;if(!t)return r;for(let o of e)for(let i of Tr(o)){let a=wt(i.group,o.name,i.name),s=t.get(a);if(s!==void 0){let c=r.get(i.group)||new Map,l=c.get(s);if(l&&l!==a)throw new Error(`Duplicate WGSL binding reservation for modules "${l}" and "${a}": group ${i.group}, binding ${s}.`);$(n,i.group,s,`registered module binding "${a}"`),c.set(s,a),r.set(i.group,c)}}return r}function Pr(e,t,n,r){let o=e.get(t);if(!o)return!1;let i=o.get(n);if(!i)return!1;if(i!==r)throw new Error(`Registered module binding "${r}" collided with "${i}": group ${t}, binding ${n}.`);return!0}function Tr(e){let t=[],n=e.source||"";for(let r of k(n,H))t.push({name:r.name,group:Number(r.groupToken)});return t}function We(e,t,n){if(e===0&&t>=ne)throw new Error(`Application binding "${n}" in group 0 uses reserved binding ${t}. Application-owned explicit group-0 bindings must stay below ${ne}.`)}function Ot(e,t,n,r){if(t===0&&n<ne)throw new Error(`Module "${e}" binding "${r}" in group 0 uses reserved application binding ${n}. Module-owned explicit group-0 bindings must be ${ne} or higher.`)}function $(e,t,n,r){let o=e.get(t)||new Set;if(o.has(n))throw new Error(`Duplicate WGSL binding assignment for ${r}: group ${t}, binding ${n}.`);o.add(n),e.set(t,o)}function Ut(e,t,n){let r=t.get(e)||new Set,o=n??(e===0?ne:r.size>0?Math.max(...r)+1:0);for(;r.has(o);)o++;return o}function Or(e,t){let n=t.get(e)||new Set,r=0;for(;n.has(r);)r++;return r}function Ur(e){let t=Ct(e,H);if(!t)return;let n=Vr(e,t.index);throw n?new Error(`Unresolved @binding(auto) for module "${n}" binding "${t.name}" remained in assembled WGSL source.`):wr(e,t.index)?new Error(`Unresolved @binding(auto) for application binding "${t.name}" remained in assembled WGSL source.`):new Error(`Unresolved @binding(auto) remained in assembled WGSL source near "${Br(t.match)}".`)}function Fr(e){if(e.length===0)return"";let t=`// ----- MODULE WGSL BINDING ASSIGNMENTS ---------------
89
+ `;for(let n of e)t+=`// ${n.moduleName}.${n.name} -> @group(${n.group}) @binding(${n.location})
90
+ `;return t+=`
91
+ `,t}function wt(e,t,n){return`${e}:${t}:${n}`}function Vr(e,t){let n=/^\/\/ ----- MODULE ([^\n]+) ---------------$/gm,r,o;for(o=n.exec(e);o&&o.index<=t;)r=o[1],o=n.exec(e);return r}function wr(e,t){let n=e.indexOf($e);return n>=0?t>n:!0}function Br(e){return e.replace(/\s+/g," ").trim()}var je="([a-zA-Z_][a-zA-Z0-9_]*)",kr=new RegExp(`^\\s*\\#\\s*ifdef\\s*${je}\\s*$`),Dr=new RegExp(`^\\s*\\#\\s*ifndef\\s*${je}\\s*(?:\\/\\/.*)?$`),zr=/^\s*\#\s*else\s*(?:\/\/.*)?$/,Gr=/^\s*\#\s*endif\s*$/,Hr=new RegExp(`^\\s*\\#\\s*ifdef\\s*${je}\\s*(?:\\/\\/.*)?$`),$r=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function xe(e,t){let n=e.split(`
92
+ `),r=[],o=[],i=!0;for(let a of n){let s=a.match(Hr)||a.match(kr),c=a.match(Dr),l=a.match(zr),p=a.match($r)||a.match(Gr);if(s||c){let f=(s||c)?.[1],u=Boolean(t?.defines?.[f]),h=s?u:!u,m=i&&h;o.push({parentActive:i,branchTaken:h,active:m}),i=m}else if(l){let f=o[o.length-1];if(!f)throw new Error("Encountered #else without matching #ifdef or #ifndef");f.active=f.parentActive&&!f.branchTaken,f.branchTaken=!0,i=f.active}else p?(o.pop(),i=o.length?o[o.length-1].active:!0):i&&r.push(a)}if(o.length>0)throw new Error("Unterminated conditional block in shader source");return r.join(`
93
+ `)}var W=class{_hookFunctions=[];_defaultModules=[];_wgslBindingRegistry=new Map;static getDefaultShaderAssembler(){return W.defaultShaderAssembler=W.defaultShaderAssembler||new W,W.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(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(r=>r.name!==n)}addShaderHook(t,n){n&&(t=Object.assign(n,{hook:t})),this._hookFunctions.push(t)}assembleWGSLShader(t){let n=this._getModuleList(t.modules),r=this._hookFunctions,{source:o,getUniforms:i,bindingAssignments:a}=Ft({...t,source:t.source,_bindingRegistry:this._wgslBindingRegistry,modules:n,hookFunctions:r}),s={...n.reduce((l,p)=>(Object.assign(l,p.defines),l),{}),...t.defines},c=t.platformInfo.shaderLanguage==="wgsl"?xe(o,{defines:s}):o;return{source:c,getUniforms:i,modules:n,bindingAssignments:a,bindingTable:be(c,a)}}assembleGLSLShaderPair(t){let n=this._getModuleList(t.modules),r=this._hookFunctions;return{...ve({...t,vs:t.vs,fs:t.fs,modules:n,hookFunctions:r}),modules:n}}_getModuleList(t=[]){let n=new Array(this._defaultModules.length+t.length),r={},o=0;for(let i=0,a=this._defaultModules.length;i<a;++i){let s=this._defaultModules[i],c=s.name;n[o++]=s,r[c]=!0}for(let i=0,a=t.length;i<a;++i){let s=t[i],c=s.name;r[c]||(n[o++]=s,r[c]=!0)}return n.length=o,F(n),n}},re=W;lt(re,"defaultShaderAssembler");var Wr=`out vec4 transform_output;
88
94
  void main() {
89
95
  transform_output = vec4(0);
90
- }`,zr=`#version 300 es
91
- ${Wr}`;function Vn(a,e){e=Array.isArray(e)?e:[e];let t=a.replace(/^\s+/,"").split(/\s+/),[n,r,s]=t;if(!e.includes(n)||!r||!s)return null;let i=s.split(";")[0];return{qualifier:n,type:r,name:i}}function Un(a){let{input:e,inputChannels:t,output:n}=a||{};if(!e)return zr;if(!t)throw new Error("inputChannels");let r=qr(t),s=Gt(e,t);return`#version 300 es
92
- in ${r} ${e};
93
- out vec4 ${n};
96
+ }`,jr=`#version 300 es
97
+ ${Wr}`;function Bt(e,t){t=Array.isArray(t)?t:[t];let n=e.replace(/^\s+/,"").split(/\s+/),[r,o,i]=n;if(!t.includes(r)||!o||!i)return null;let a=i.split(";")[0];return{qualifier:r,type:o,name:a}}function kt(e){let{input:t,inputChannels:n,output:r}=e||{};if(!t)return jr;if(!n)throw new Error("inputChannels");let o=qr(n),i=qe(t,n);return`#version 300 es
98
+ in ${o} ${t};
99
+ out vec4 ${r};
94
100
  void main() {
95
- ${n} = ${s};
96
- }`}function $n(a){switch(a){case"float":return"x";case"vec2":return"xy";case"vec3":return"xyz";case"vec4":return"xyzw";default:throw new Error(a)}}function Hn(a){switch(a){case"float":return 1;case"vec2":return 2;case"vec3":return 3;case"vec4":return 4;default:throw new Error(a)}}function qr(a){switch(a){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${a}`)}}function Gt(a,e){switch(e){case 1:return`vec4(${a}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${a}, 0.0, 1.0)`;case 3:return`vec4(${a}, 1.0)`;case 4:return a;default:throw new Error(`invalid channels: ${e}`)}}function pe(a){return typeof a=="string"?a.charAt(0).toUpperCase()+a.slice(1):a}function Gn(a,e){return jr(a,e)}function jr(a,e){let t=[];switch(e.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":t.push(`uniform ${pe(a.name)} {`);break;case"uniforms":}for(let[n,r]of Object.entries(a.uniformTypes||{})){let s=Xr(r);switch(e.uniforms){case"scoped-interface-blocks":t.push(` ${s} ${n};`);break;case"unscoped-interface-blocks":t.push(` ${s} ${a.name}_${n};`);break;case"uniforms":t.push(`uniform ${s} ${a.name}_${n};`)}}switch(e.uniforms){case"scoped-interface-blocks":t.push(`} ${a.name};`);break;case"unscoped-interface-blocks":t.push("};");break;case"uniforms":}return t.push(""),t.join(`
97
- `)}function Xr(a){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"}[a]}function Wn(a,e){return Kr(a,e)}function Kr(a,e){let t=[];t.push(`struct ${pe(a.name)} {`);for(let[n,r]of Object.entries(a?.uniformTypes||{})){let s=r;t.push(` ${n} : ${s};`)}return t.push("};"),t.push(`var<uniform> ${a.name} : ${pe(a.name)};`),t.join(`
98
- `)}function zn(a,e){switch(e.shaderLanguage){case"glsl":return Gn(a,e);case"wgsl":return Wn(a,e)}}var Yn=Rt(Je(),1);var W=class{constructor(e,t){this.name=e,this.attributes=t,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}getTypeName(){return this.name}},ot=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},re=class extends W{constructor(e,t){super(e,t),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},se=class extends W{constructor(e,t){super(e,t),this.count=0,this.stride=0}get isArray(){return!0}},ie=class extends W{constructor(e,t,n,r){super(e,n),this.format=t,this.access=r}get isTemplate(){return!0}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}},ce;(a=>{a[a.Uniform=0]="Uniform",a[a.Storage=1]="Storage",a[a.Texture=2]="Texture",a[a.Sampler=3]="Sampler",a[a.StorageTexture=4]="StorageTexture"})(ce||(ce={}));var xe=class{constructor(e,t,n,r,s,i,o){this.name=e,this.type=t,this.group=n,this.binding=r,this.attributes=s,this.resourceType=i,this.access=o}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray||this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},qt=class{constructor(e,t){this.name=e,this.type=t}},jt=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r,this.interpolation=null}},it=class{constructor(e,t,n,r){this.name=e,this.type=t,this.locationType=n,this.location=r}},Xt=class{constructor(e,t,n,r){this.name=e,this.type=t,this.attributes=n,this.id=r}},Kt=class{constructor(e,t,n){this.name=e,this.type=t,this.attributes=n}},Zt=class{constructor(e,t=null,n){this.stage=null,this.inputs=[],this.outputs=[],this.arguments=[],this.returnType=null,this.resources=[],this.overrides=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=e,this.stage=t,this.attributes=n}},Qt=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Xn=new Float32Array(1),Zr=new Int32Array(Xn.buffer),$=new Uint16Array(1);function Qr(a){Xn[0]=a;let e=Zr[0],t=e>>31&1,n=e>>23&255,r=8388607&e;if(n===255)return $[0]=t<<15|31744|(r!==0?512:0),$[0];if(n===0){if(r===0)return $[0]=t<<15,$[0];r|=8388608;let s=113;for(;!(8388608&r);)r<<=1,s--;return n=127-s,r&=8388607,n>0?(r=(r>>126-n)+(r>>127-n&1),$[0]=t<<15|n<<10|r>>13,$[0]):($[0]=t<<15,$[0])}return n=n-127+15,n>=31?($[0]=t<<15|31744,$[0]):n<=0?n<-10?($[0]=t<<15,$[0]):(r=(8388608|r)>>1-n,$[0]=t<<15|r>>13,$[0]):(r>>=13,$[0]=t<<15|n<<10|r,$[0])}var un=new Uint32Array(1),Kn=new Float32Array(un.buffer,0,1);function qn(a){let e=112+(a>>6&31)<<23|(63&a)<<17;return un[0]=e,Kn[0]}function Yr(a,e,t,n,r,s,i,o,l){let c=n*(i>>=r)*(s>>=r)+t*i+e*o;switch(l){case"r8unorm":return[C(a,c,"8unorm",1)[0]];case"r8snorm":return[C(a,c,"8snorm",1)[0]];case"r8uint":return[C(a,c,"8uint",1)[0]];case"r8sint":return[C(a,c,"8sint",1)[0]];case"rg8unorm":{let u=C(a,c,"8unorm",2);return[u[0],u[1]]}case"rg8snorm":{let u=C(a,c,"8snorm",2);return[u[0],u[1]]}case"rg8uint":{let u=C(a,c,"8uint",2);return[u[0],u[1]]}case"rg8sint":{let u=C(a,c,"8sint",2);return[u[0],u[1]]}case"rgba8unorm-srgb":case"rgba8unorm":{let u=C(a,c,"8unorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8snorm":{let u=C(a,c,"8snorm",4);return[u[0],u[1],u[2],u[3]]}case"rgba8uint":{let u=C(a,c,"8uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba8sint":{let u=C(a,c,"8sint",4);return[u[0],u[1],u[2],u[3]]}case"bgra8unorm-srgb":case"bgra8unorm":{let u=C(a,c,"8unorm",4);return[u[2],u[1],u[0],u[3]]}case"r16uint":return[C(a,c,"16uint",1)[0]];case"r16sint":return[C(a,c,"16sint",1)[0]];case"r16float":return[C(a,c,"16float",1)[0]];case"rg16uint":{let u=C(a,c,"16uint",2);return[u[0],u[1]]}case"rg16sint":{let u=C(a,c,"16sint",2);return[u[0],u[1]]}case"rg16float":{let u=C(a,c,"16float",2);return[u[0],u[1]]}case"rgba16uint":{let u=C(a,c,"16uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16sint":{let u=C(a,c,"16sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba16float":{let u=C(a,c,"16float",4);return[u[0],u[1],u[2],u[3]]}case"r32uint":return[C(a,c,"32uint",1)[0]];case"r32sint":return[C(a,c,"32sint",1)[0]];case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return[C(a,c,"32float",1)[0]];case"rg32uint":{let u=C(a,c,"32uint",2);return[u[0],u[1]]}case"rg32sint":{let u=C(a,c,"32sint",2);return[u[0],u[1]]}case"rg32float":{let u=C(a,c,"32float",2);return[u[0],u[1]]}case"rgba32uint":{let u=C(a,c,"32uint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32sint":{let u=C(a,c,"32sint",4);return[u[0],u[1],u[2],u[3]]}case"rgba32float":{let u=C(a,c,"32float",4);return[u[0],u[1],u[2],u[3]]}case"rg11b10ufloat":{let u=new Uint32Array(a.buffer,c,1)[0],h=(4192256&u)>>11,b=(4290772992&u)>>22;return[qn(2047&u),qn(h),function(y){let S=112+(y>>5&31)<<23|(31&y)<<18;return un[0]=S,Kn[0]}(b),1]}}return null}function C(a,e,t,n){let r=[0,0,0,0];for(let c=0;c<n;++c)switch(t){case"8unorm":r[c]=a[e]/255,e++;break;case"8snorm":r[c]=a[e]/255*2-1,e++;break;case"8uint":r[c]=a[e],e++;break;case"8sint":r[c]=a[e]-127,e++;break;case"16uint":r[c]=a[e]|a[e+1]<<8,e+=2;break;case"16sint":r[c]=(a[e]|a[e+1]<<8)-32768,e+=2;break;case"16float":r[c]=(s=a[e]|a[e+1]<<8,i=void 0,o=void 0,l=void 0,i=(32768&s)>>15,l=1023&s,(o=(31744&s)>>10)==0?(i?-1:1)*Math.pow(2,-14)*(l/Math.pow(2,10)):o==31?l?NaN:1/0*(i?-1:1):(i?-1:1)*Math.pow(2,o-15)*(1+l/Math.pow(2,10))),e+=2;break;case"32uint":case"32sint":r[c]=a[e]|a[e+1]<<8|a[e+2]<<16|a[e+3]<<24,e+=4;break;case"32float":r[c]=new Float32Array(a.buffer,e,1)[0],e+=4}var s,i,o,l;return r}function N(a,e,t,n,r){for(let s=0;s<n;++s)switch(t){case"8unorm":a[e]=255*r[s],e++;break;case"8snorm":a[e]=.5*(r[s]+1)*255,e++;break;case"8uint":a[e]=r[s],e++;break;case"8sint":a[e]=r[s]+127,e++;break;case"16uint":new Uint16Array(a.buffer,e,1)[0]=r[s],e+=2;break;case"16sint":new Int16Array(a.buffer,e,1)[0]=r[s],e+=2;break;case"16float":{let i=Qr(r[s]);new Uint16Array(a.buffer,e,1)[0]=i,e+=2;break}case"32uint":new Uint32Array(a.buffer,e,1)[0]=r[s],e+=4;break;case"32sint":new Int32Array(a.buffer,e,1)[0]=r[s],e+=4;break;case"32float":new Float32Array(a.buffer,e,1)[0]=r[s],e+=4}return r}var Wt={r8unorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8snorm:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8uint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r8sint:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg8unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8snorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg8sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"rgba8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8snorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba8sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},bgra8unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bgra8unorm-srgb":{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r16uint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16sint:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r16float:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg16uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg16float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba16uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba16float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},r32uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32sint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},r32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:1},rg32uint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32sint:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rg32float:{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,channels:2},rgba32uint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32sint:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgba32float:{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2uint:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rgb10a2unorm:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},rg11b10ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},stencil8:{bytesPerBlock:1,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!1,hasStencil:!0,channels:1},depth16unorm:{bytesPerBlock:2,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},depth24plus:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,depthOnlyFormat:"depth32float",channels:1},"depth24plus-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,depthOnlyFormat:"depth32float",channels:1},depth32float:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!1,channels:1},"depth32float-stencil8":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!1,isDepthStencil:!0,hasDepth:!0,hasStencil:!0,stencilOnlyFormat:"depth32float",channels:1},rgb9e5ufloat:{bytesPerBlock:4,blockWidth:1,blockHeight:1,isCompressed:!1,channels:4},"bc1-rgba-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc1-rgba-unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc2-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc3-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc4-r-unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc4-r-snorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:1},"bc5-rg-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc5-rg-snorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:2},"bc6h-rgb-ufloat":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc6h-rgb-float":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"bc7-rgba-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgb8a1unorm-srgb":{bytesPerBlock:8,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"etc2-rgba8unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"eac-r11unorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-r11snorm":{bytesPerBlock:8,blockWidth:1,blockHeight:1,isCompressed:!0,channels:1},"eac-rg11unorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"eac-rg11snorm":{bytesPerBlock:16,blockWidth:1,blockHeight:1,isCompressed:!0,channels:2},"astc-4x4-unorm":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-4x4-unorm-srgb":{bytesPerBlock:16,blockWidth:4,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x4-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:4,isCompressed:!0,channels:4},"astc-5x5-unorm":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-5x5-unorm-srgb":{bytesPerBlock:16,blockWidth:5,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x5-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:5,isCompressed:!0,channels:4},"astc-6x6-unorm":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-6x6-unorm-srgb":{bytesPerBlock:16,blockWidth:6,blockHeight:6,isCompressed:!0,channels:4},"astc-8x5-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x5-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:5,isCompressed:!0,channels:4},"astc-8x6-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x6-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:6,isCompressed:!0,channels:4},"astc-8x8-unorm":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-8x8-unorm-srgb":{bytesPerBlock:16,blockWidth:8,blockHeight:8,isCompressed:!0,channels:4},"astc-10x5-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x5-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:5,isCompressed:!0,channels:4},"astc-10x6-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x6-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:6,isCompressed:!0,channels:4},"astc-10x8-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x8-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:8,isCompressed:!0,channels:4},"astc-10x10-unorm":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-10x10-unorm-srgb":{bytesPerBlock:16,blockWidth:10,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x10-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:10,isCompressed:!0,channels:4},"astc-12x12-unorm":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4},"astc-12x12-unorm-srgb":{bytesPerBlock:16,blockWidth:12,blockHeight:12,isCompressed:!0,channels:4}},z=class{constructor(){this.id=z._id++,this.line=0}get isAstNode(){return!0}get astNodeType(){return""}search(e){e(this)}searchBlock(e,t){if(e){t(Se.instance);for(let n of e)n instanceof Array?this.searchBlock(n,t):n.search(t);t(Ae.instance)}}constEvaluate(e,t){throw new Error("Cannot evaluate node")}constEvaluateString(e){return this.constEvaluate(e).toString()}};z._id=0;var Se=class extends z{};Se.instance=new Se;var Ae=class extends z{};Ae.instance=new Ae;var Zn=new Set(["all","all","any","select","arrayLength","abs","acos","acosh","asin","asinh","atan","atanh","atan2","ceil","clamp","cos","cosh","countLeadingZeros","countOneBits","countTrailingZeros","cross","degrees","determinant","distance","dot","dot4U8Packed","dot4I8Packed","exp","exp2","extractBits","faceForward","firstLeadingBit","firstTrailingBit","floor","fma","fract","frexp","insertBits","inverseSqrt","ldexp","length","log","log2","max","min","mix","modf","normalize","pow","quantizeToF16","radians","reflect","refract","reverseBits","round","saturate","sign","sin","sinh","smoothStep","sqrt","step","tan","tanh","transpose","trunc","dpdx","dpdxCoarse","dpdxFine","dpdy","dpdyCoarse","dpdyFine","fwidth","fwidthCoarse","fwidthFine","textureDimensions","textureGather","textureGatherCompare","textureLoad","textureNumLayers","textureNumLevels","textureNumSamples","textureSample","textureSampleBias","textureSampleCompare","textureSampleCompareLevel","textureSampleGrad","textureSampleLevel","textureSampleBaseClampToEdge","textureStore","atomicLoad","atomicStore","atomicAdd","atomicSub","atomicMax","atomicMin","atomicAnd","atomicOr","atomicXor","atomicExchange","atomicCompareExchangeWeak","pack4x8snorm","pack4x8unorm","pack4xI8","pack4xU8","pack4x8Clamp","pack4xU8Clamp","pack2x16snorm","pack2x16unorm","pack2x16float","unpack4x8snorm","unpack4x8unorm","unpack4xI8","unpack4xU8","unpack2x16snorm","unpack2x16unorm","unpack2x16float","storageBarrier","textureBarrier","workgroupBarrier","workgroupUniformLoad","subgroupAdd","subgroupExclusiveAdd","subgroupInclusiveAdd","subgroupAll","subgroupAnd","subgroupAny","subgroupBallot","subgroupBroadcast","subgroupBroadcastFirst","subgroupElect","subgroupMax","subgroupMin","subgroupMul","subgroupExclusiveMul","subgroupInclusiveMul","subgroupOr","subgroupShuffle","subgroupShuffleDown","subgroupShuffleUp","subgroupShuffleXor","subgroupXor","quadBroadcast","quadSwapDiagonal","quadSwapX","quadSwapY"]),F=class extends z{constructor(){super()}},ge=class extends F{constructor(e,t,n,r,s,i){super(),this.calls=new Set,this.name=e,this.args=t,this.returnType=n,this.body=r,this.startLine=s,this.endLine=i}get astNodeType(){return"function"}search(e){if(this.attributes)for(let t of this.attributes)e(t);e(this);for(let t of this.args)e(t);this.searchBlock(this.body,e)}},Yt=class extends F{constructor(e){super(),this.expression=e}get astNodeType(){return"staticAssert"}search(e){this.expression.search(e)}},at=class extends F{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"while"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},Be=class extends F{constructor(e,t){super(),this.body=e,this.loopId=t}get astNodeType(){return"continuing"}search(e){this.searchBlock(this.body,e)}},lt=class extends F{constructor(e,t,n,r){super(),this.init=e,this.condition=t,this.increment=n,this.body=r}get astNodeType(){return"for"}search(e){var t,n,r;(t=this.init)===null||t===void 0||t.search(e),(n=this.condition)===null||n===void 0||n.search(e),(r=this.increment)===null||r===void 0||r.search(e),this.searchBlock(this.body,e)}},ee=class extends F{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"var"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},Ve=class extends F{constructor(e,t,n){super(),this.attributes=null,this.name=e,this.type=t,this.value=n}get astNodeType(){return"override"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},me=class extends F{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"let"}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},ke=class extends F{constructor(e,t,n,r,s){super(),this.attributes=null,this.name=e,this.type=t,this.storage=n,this.access=r,this.value=s}get astNodeType(){return"const"}constEvaluate(e,t){return this.value.constEvaluate(e,t)}search(e){var t;e(this),(t=this.value)===null||t===void 0||t.search(e)}},ye,Me,v,_;(a=>{a.increment="++",a.decrement="--"})(ye||(ye={})),(a=>{a.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for IncrementOperator");return a[t]}})(ye||(ye={}));var ct=class extends F{constructor(e,t){super(),this.operator=e,this.variable=t}get astNodeType(){return"increment"}search(e){this.variable.search(e)}};(a=>{a.assign="=",a.addAssign="+=",a.subtractAssin="-=",a.multiplyAssign="*=",a.divideAssign="/=",a.moduloAssign="%=",a.andAssign="&=",a.orAssign="|=",a.xorAssign="^=",a.shiftLeftAssign="<<=",a.shiftRightAssign=">>="})(Me||(Me={})),(a=>{a.parse=function(e){let t=e;if(t=="parse")throw new Error("Invalid value for AssignOperator");return t}})(Me||(Me={}));var ut=class extends F{constructor(e,t,n){super(),this.operator=e,this.variable=t,this.value=n}get astNodeType(){return"assign"}search(e){this.variable.search(e),this.value.search(e)}},Ue=class extends F{constructor(e,t){super(),this.name=e,this.args=t}get astNodeType(){return"call"}isBuiltin(){return Zn.has(this.name)}search(e){for(let t of this.args)t.search(e);e(this)}},ft=class extends F{constructor(e,t){super(),this.body=e,this.continuing=t}get astNodeType(){return"loop"}},ht=class extends F{constructor(e,t){super(),this.condition=e,this.cases=t}get astNodeType(){return"switch"}},pt=class extends F{constructor(e,t,n,r){super(),this.condition=e,this.body=t,this.elseif=n,this.else=r}get astNodeType(){return"if"}search(e){this.condition.search(e),this.searchBlock(this.body,e),this.searchBlock(this.elseif,e),this.searchBlock(this.else,e)}},dt=class extends F{constructor(e){super(),this.value=e}get astNodeType(){return"return"}search(e){var t;(t=this.value)===null||t===void 0||t.search(e)}},Jt=class extends F{constructor(e){super(),this.name=e}get astNodeType(){return"enable"}},en=class extends F{constructor(e){super(),this.extensions=e}get astNodeType(){return"requires"}},mt=class extends F{constructor(e,t){super(),this.severity=e,this.rule=t}get astNodeType(){return"diagnostic"}},$e=class extends F{constructor(e,t){super(),this.name=e,this.type=t}get astNodeType(){return"alias"}},tn=class extends F{constructor(){super()}get astNodeType(){return"discard"}},_t=class extends F{constructor(){super(),this.condition=null,this.loopId=-1}get astNodeType(){return"break"}},gt=class extends F{constructor(){super(),this.loopId=-1}get astNodeType(){return"continue"}},x=class extends F{constructor(e){super(),this.attributes=null,this.name=e}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}static maxFormatType(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=x._priority.get(t.name);x._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?x.i32:t}getTypeName(){return this.name}};x.x32=new x("x32"),x.f32=new x("f32"),x.i32=new x("i32"),x.u32=new x("u32"),x.f16=new x("f16"),x.bool=new x("bool"),x.void=new x("void"),x._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var vt=class extends x{constructor(e){super(e)}},Y=class extends x{constructor(e,t,n,r){super(e),this.members=t,this.startLine=n,this.endLine=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(e){for(let t=0;t<this.members.length;t++)if(this.members[t].name==e)return t;return-1}search(e){for(let t of this.members)e(t)}},g=class extends x{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"template"}getTypeName(){let e=this.name;if(this.format!==null){if(e==="vec2"||e==="vec3"||e==="vec4"||e==="mat2x2"||e==="mat2x3"||e==="mat2x4"||e==="mat3x2"||e==="mat3x3"||e==="mat3x4"||e==="mat4x2"||e==="mat4x3"||e==="mat4x4"){if(this.format.name==="f32")return e+="f",e;if(this.format.name==="i32")return e+="i",e;if(this.format.name==="u32")return e+="u",e;if(this.format.name==="bool")return e+="b",e;if(this.format.name==="f16")return e+="h",e}e+=`<${this.format.name}>`}else if(e==="vec2"||e==="vec3"||e==="vec4")return e;return e}};g.vec2f=new g("vec2",x.f32,null),g.vec3f=new g("vec3",x.f32,null),g.vec4f=new g("vec4",x.f32,null),g.vec2i=new g("vec2",x.i32,null),g.vec3i=new g("vec3",x.i32,null),g.vec4i=new g("vec4",x.i32,null),g.vec2u=new g("vec2",x.u32,null),g.vec3u=new g("vec3",x.u32,null),g.vec4u=new g("vec4",x.u32,null),g.vec2h=new g("vec2",x.f16,null),g.vec3h=new g("vec3",x.f16,null),g.vec4h=new g("vec4",x.f16,null),g.vec2b=new g("vec2",x.bool,null),g.vec3b=new g("vec3",x.bool,null),g.vec4b=new g("vec4",x.bool,null),g.mat2x2f=new g("mat2x2",x.f32,null),g.mat2x3f=new g("mat2x3",x.f32,null),g.mat2x4f=new g("mat2x4",x.f32,null),g.mat3x2f=new g("mat3x2",x.f32,null),g.mat3x3f=new g("mat3x3",x.f32,null),g.mat3x4f=new g("mat3x4",x.f32,null),g.mat4x2f=new g("mat4x2",x.f32,null),g.mat4x3f=new g("mat4x3",x.f32,null),g.mat4x4f=new g("mat4x4",x.f32,null),g.mat2x2h=new g("mat2x2",x.f16,null),g.mat2x3h=new g("mat2x3",x.f16,null),g.mat2x4h=new g("mat2x4",x.f16,null),g.mat3x2h=new g("mat3x2",x.f16,null),g.mat3x3h=new g("mat3x3",x.f16,null),g.mat3x4h=new g("mat3x4",x.f16,null),g.mat4x2h=new g("mat4x2",x.f16,null),g.mat4x3h=new g("mat4x3",x.f16,null),g.mat4x4h=new g("mat4x4",x.f16,null),g.mat2x2i=new g("mat2x2",x.i32,null),g.mat2x3i=new g("mat2x3",x.i32,null),g.mat2x4i=new g("mat2x4",x.i32,null),g.mat3x2i=new g("mat3x2",x.i32,null),g.mat3x3i=new g("mat3x3",x.i32,null),g.mat3x4i=new g("mat3x4",x.i32,null),g.mat4x2i=new g("mat4x2",x.i32,null),g.mat4x3i=new g("mat4x3",x.i32,null),g.mat4x4i=new g("mat4x4",x.i32,null),g.mat2x2u=new g("mat2x2",x.u32,null),g.mat2x3u=new g("mat2x3",x.u32,null),g.mat2x4u=new g("mat2x4",x.u32,null),g.mat3x2u=new g("mat3x2",x.u32,null),g.mat3x3u=new g("mat3x3",x.u32,null),g.mat3x4u=new g("mat3x4",x.u32,null),g.mat4x2u=new g("mat4x2",x.u32,null),g.mat4x3u=new g("mat4x3",x.u32,null),g.mat4x4u=new g("mat4x4",x.u32,null);var Re=class extends x{constructor(e,t,n,r){super(e),this.storage=t,this.type=n,this.access=r}get astNodeType(){return"pointer"}},_e=class extends x{constructor(e,t,n,r){super(e),this.attributes=t,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},de=class extends x{constructor(e,t,n){super(e),this.format=t,this.access=n}get astNodeType(){return"sampler"}},Q=class extends z{constructor(){super(),this.postfix=null}},ae=class extends Q{constructor(e){super(),this.value=e}get astNodeType(){return"stringExpr"}toString(){return this.value}constEvaluateString(){return this.value}},K=class extends Q{constructor(e,t){super(),this.type=e,this.args=t}get astNodeType(){return"createExpr"}search(e){if(e(this),this.args)for(let t of this.args)t.search(e)}constEvaluate(e,t){return t&&(t[0]=this.type),e.evalExpression(this,e.context)}},He=class extends Q{constructor(e,t){super(),this.cachedReturnValue=null,this.name=e,this.args=t}get astNodeType(){return"callExpr"}setCachedReturnValue(e){this.cachedReturnValue=e}get isBuiltin(){return Zn.has(this.name)}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){for(let t of this.args)t.search(e);e(this)}},G=class extends Q{constructor(e){super(),this.name=e}get astNodeType(){return"varExpr"}search(e){e(this),this.postfix&&this.postfix.search(e)}constEvaluate(e,t){return e.evalExpression(this,e.context)}},bt=class extends Q{constructor(e,t){super(),this.name=e,this.initializer=t}get astNodeType(){return"constExpr"}constEvaluate(e,t){if(this.initializer){let n=e.evalExpression(this.initializer,e.context);return n!==null&&this.postfix?n.getSubData(e,this.postfix,e.context):n}return null}search(e){this.initializer.search(e)}},R=class extends Q{constructor(e,t){super(),this.value=e,this.type=t}get astNodeType(){return"literalExpr"}constEvaluate(e,t){return t!==void 0&&(t[0]=this.type),this.value}get isScalar(){return this.value instanceof d}get isVector(){return this.value instanceof p||this.value instanceof I}get scalarValue(){return this.value instanceof d?this.value.value:(console.error("Value is not scalar."),0)}get vectorValue(){return this.value instanceof p||this.value instanceof I?this.value.data:(console.error("Value is not a vector or matrix."),new Float32Array(0))}},xt=class extends Q{constructor(e,t){super(),this.type=e,this.value=t}get astNodeType(){return"bitcastExpr"}search(e){this.value.search(e)}};var fe=class extends Q{constructor(e){super(),this.index=e}search(e){this.index.search(e)}},yt=class extends Q{constructor(){super()}},M=class extends yt{constructor(e,t){super(),this.operator=e,this.right=t}get astNodeType(){return"unaryOp"}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.right.search(e)}},j=class extends yt{constructor(e,t,n){super(),this.operator=e,this.left=t,this.right=n}get astNodeType(){return"binaryOp"}_getPromotedType(e,t){return e.name===t.name?e:e.name==="f32"||t.name==="f32"?x.f32:e.name==="u32"||t.name==="u32"?x.u32:x.i32}constEvaluate(e,t){return e.evalExpression(this,e.context)}search(e){this.left.search(e),this.right.search(e)}},wt=class extends z{constructor(e){super(),this.body=e}},Ie=class extends Q{constructor(){super()}get astNodeType(){return"default"}},kt=class extends wt{constructor(e,t){super(t),this.selectors=e}get astNodeType(){return"case"}search(e){this.searchBlock(this.body,e)}},It=class extends wt{constructor(e){super(e)}get astNodeType(){return"default"}search(e){this.searchBlock(this.body,e)}},St=class extends z{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"argument"}},nn=class extends z{constructor(e,t){super(),this.condition=e,this.body=t}get astNodeType(){return"elseif"}search(e){this.condition.search(e),this.searchBlock(this.body,e)}},At=class extends z{constructor(e,t,n){super(),this.name=e,this.type=t,this.attributes=n}get astNodeType(){return"member"}},Tt=class extends z{constructor(e,t){super(),this.name=e,this.value=t}get astNodeType(){return"attribute"}},q=class{constructor(e,t){this.parent=null,this.typeInfo=e,this.parent=t,this.id=q._id++}clone(){throw`Clone: Not implemented for ${this.constructor.name}`}setDataValue(e,t,n,r){console.error(`SetDataValue: Not implemented for ${this.constructor.name}`)}getSubData(e,t,n){return console.error(`GetDataValue: Not implemented for ${this.constructor.name}`),null}toString(){return`<${this.typeInfo.name}>`}};q._id=0;var Ge=class extends q{constructor(){super(new W("void",null),null)}toString(){return"void"}};Ge.void=new Ge;var ue=class extends q{constructor(e){super(new W("pointer",null),null),this.reference=e}clone(){return this}setDataValue(e,t,n,r){this.reference.setDataValue(e,t,n,r)}getSubData(e,t,n){return t?this.reference.getSubData(e,t,n):this}},d=class extends q{constructor(e,t,n=null){super(t,n),e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array?this.data=e:this.typeInfo.name==="x32"?e-Math.floor(e)!=0?this.data=new Float32Array([e]):this.data=e>=0?new Uint32Array([e]):new Int32Array([e]):this.typeInfo.name==="i32"||this.typeInfo.name==="bool"?this.data=new Int32Array([e]):this.typeInfo.name==="u32"?this.data=new Uint32Array([e]):this.typeInfo.name==="f32"||this.typeInfo.name==="f16"?this.data=new Float32Array([e]):console.error("ScalarData2: Invalid type",t)}clone(){if(this.data instanceof Float32Array)return new d(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new d(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new d(new Uint32Array(this.data),this.typeInfo,null);throw"ScalarData: Invalid data type"}get value(){return this.data[0]}set value(e){this.data[0]=e}setDataValue(e,t,n,r){if(n)return void console.error("SetDataValue: Scalar data does not support postfix",n);if(!(t instanceof d))return void console.error("SetDataValue: Invalid value",t);let s=t.data[0];this.typeInfo.name==="i32"||this.typeInfo.name==="u32"?s=Math.floor(s):this.typeInfo.name==="bool"&&(s=s?1:0),this.data[0]=s}getSubData(e,t,n){return t?(console.error("getSubData: Scalar data does not support postfix",t),null):this}toString(){return`${this.value}`}};function Jr(a,e,t){let n=e.length;return n===2?t==="f32"?new p(new Float32Array(e),a.getTypeInfo("vec2f")):t==="i32"||t==="bool"?new p(new Int32Array(e),a.getTypeInfo("vec2i")):t==="u32"?new p(new Uint32Array(e),a.getTypeInfo("vec2u")):t==="f16"?new p(new Float32Array(e),a.getTypeInfo("vec2h")):(console.error(`getSubData: Unknown format ${t}`),null):n===3?t==="f32"?new p(new Float32Array(e),a.getTypeInfo("vec3f")):t==="i32"||t==="bool"?new p(new Int32Array(e),a.getTypeInfo("vec3i")):t==="u32"?new p(new Uint32Array(e),a.getTypeInfo("vec3u")):t==="f16"?new p(new Float32Array(e),a.getTypeInfo("vec3h")):(console.error(`getSubData: Unknown format ${t}`),null):n===4?t==="f32"?new p(new Float32Array(e),a.getTypeInfo("vec4f")):t==="i32"||t==="bool"?new p(new Int32Array(e),a.getTypeInfo("vec4i")):t==="u32"?new p(new Uint32Array(e),a.getTypeInfo("vec4u")):t==="f16"?new p(new Float32Array(e),a.getTypeInfo("vec4h")):(console.error(`getSubData: Unknown format ${t}`),null):(console.error(`getSubData: Invalid vector size ${e.length}`),null)}var p=class extends q{constructor(e,t,n=null){if(super(t,n),e instanceof Float32Array||e instanceof Uint32Array||e instanceof Int32Array)this.data=e;else{let r=this.typeInfo.name;r==="vec2f"||r==="vec3f"||r==="vec4f"?this.data=new Float32Array(e):r==="vec2i"||r==="vec3i"||r==="vec4i"?this.data=new Int32Array(e):r==="vec2u"||r==="vec3u"||r==="vec4u"?this.data=new Uint32Array(e):r==="vec2h"||r==="vec3h"||r==="vec4h"?this.data=new Float32Array(e):r==="vec2b"||r==="vec3b"||r==="vec4b"?this.data=new Int32Array(e):r==="vec2"||r==="vec3"||r==="vec4"?this.data=new Float32Array(e):console.error(`VectorData: Invalid type ${r}`)}}clone(){if(this.data instanceof Float32Array)return new p(new Float32Array(this.data),this.typeInfo,null);if(this.data instanceof Int32Array)return new p(new Int32Array(this.data),this.typeInfo,null);if(this.data instanceof Uint32Array)return new p(new Uint32Array(this.data),this.typeInfo,null);throw"VectorData: Invalid data type"}setDataValue(e,t,n,r){n instanceof ae?console.error("TODO: Set vector postfix"):t instanceof p?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=e.getTypeInfo("f32");if(this.typeInfo instanceof ie)r=this.typeInfo.format||r;else{let i=this.typeInfo.name;i==="vec2f"||i==="vec3f"||i==="vec4f"?r=e.getTypeInfo("f32"):i==="vec2i"||i==="vec3i"||i==="vec4i"?r=e.getTypeInfo("i32"):i==="vec2b"||i==="vec3b"||i==="vec4b"?r=e.getTypeInfo("bool"):i==="vec2u"||i==="vec3u"||i==="vec4u"?r=e.getTypeInfo("u32"):i==="vec2h"||i==="vec3h"||i==="vec4h"?r=e.getTypeInfo("f16"):console.error(`GetSubData: Unknown type ${i}`)}let s=this;for(;t!==null&&s!==null;){if(t instanceof fe){let i=t.index,o=-1;if(i instanceof R){if(!(i.value instanceof d))return console.error(`GetSubData: Invalid array index ${i.value}`),null;o=i.value.value}else{let l=e.evalExpression(i,n);if(!(l instanceof d))return console.error("GetSubData: Unknown index type",i),null;o=l.value}if(o<0||o>=s.data.length)return console.error("GetSubData: Index out of range",o),null;if(s.data instanceof Float32Array){let l=new Float32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new d(l,r)}if(s.data instanceof Int32Array){let l=new Int32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new d(l,r)}if(s.data instanceof Uint32Array){let l=new Uint32Array(s.data.buffer,s.data.byteOffset+4*o,1);return new d(l,r)}throw"GetSubData: Invalid data type"}if(!(t instanceof ae))return console.error("GetSubData: Unknown postfix",t),null;{let i=t.value.toLowerCase();if(i.length===1){let l=0;if(i==="x"||i==="r")l=0;else if(i==="y"||i==="g")l=1;else if(i==="z"||i==="b")l=2;else{if(i!=="w"&&i!=="a")return console.error(`GetSubData: Unknown member ${i}`),null;l=3}if(this.data instanceof Float32Array){let c=new Float32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new d(c,r,this)}if(this.data instanceof Int32Array){let c=new Int32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new d(c,r,this)}if(this.data instanceof Uint32Array){let c=new Uint32Array(this.data.buffer,this.data.byteOffset+4*l,1);return new d(c,r,this)}}let o=[];for(let l of i)l==="x"||l==="r"?o.push(this.data[0]):l==="y"||l==="g"?o.push(this.data[1]):l==="z"||l==="b"?o.push(this.data[2]):l==="w"||l==="a"?o.push(this.data[3]):console.error(`GetDataValue: Unknown member ${l}`);s=Jr(e,o,r.name)}t=t.postfix}return s}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},I=class extends q{constructor(e,t,n=null){super(t,n),e instanceof Float32Array?this.data=e:this.data=new Float32Array(e)}clone(){return new I(new Float32Array(this.data),this.typeInfo,null)}setDataValue(e,t,n,r){n instanceof ae?console.error("TODO: Set matrix postfix"):t instanceof I?this.data=t.data:console.error("SetDataValue: Invalid value",t)}getSubData(e,t,n){if(t===null)return this;let r=this.typeInfo.name;if(e.getTypeInfo("f32"),this.typeInfo instanceof ie)this.typeInfo.format;else if(r.endsWith("f"))e.getTypeInfo("f32");else if(r.endsWith("i"))e.getTypeInfo("i32");else if(r.endsWith("u"))e.getTypeInfo("u32");else{if(!r.endsWith("h"))return console.error(`GetDataValue: Unknown type ${r}`),null;e.getTypeInfo("f16")}if(t instanceof fe){let s=t.index,i=-1;if(s instanceof R){if(!(s.value instanceof d))return console.error(`GetDataValue: Invalid array index ${s.value}`),null;i=s.value.value}else{let c=e.evalExpression(s,n);if(!(c instanceof d))return console.error("GetDataValue: Unknown index type",s),null;i=c.value}if(i<0||i>=this.data.length)return console.error("GetDataValue: Index out of range",i),null;let o=r.endsWith("h")?"h":"f",l;if(r==="mat2x2"||r==="mat2x2f"||r==="mat2x2h"||r==="mat3x2"||r==="mat3x2f"||r==="mat3x2h"||r==="mat4x2"||r==="mat4x2f"||r==="mat4x2h")l=new p(new Float32Array(this.data.buffer,this.data.byteOffset+2*i*4,2),e.getTypeInfo(`vec2${o}`));else if(r==="mat2x3"||r==="mat2x3f"||r==="mat2x3h"||r==="mat3x3"||r==="mat3x3f"||r==="mat3x3h"||r==="mat4x3"||r==="mat4x3f"||r==="mat4x3h")l=new p(new Float32Array(this.data.buffer,this.data.byteOffset+3*i*4,3),e.getTypeInfo(`vec3${o}`));else{if(r!=="mat2x4"&&r!=="mat2x4f"&&r!=="mat2x4h"&&r!=="mat3x4"&&r!=="mat3x4f"&&r!=="mat3x4h"&&r!=="mat4x4"&&r!=="mat4x4f"&&r!=="mat4x4h")return console.error(`GetDataValue: Unknown type ${r}`),null;l=new p(new Float32Array(this.data.buffer,this.data.byteOffset+4*i*4,4),e.getTypeInfo(`vec4${o}`))}return t.postfix?l.getSubData(e,t.postfix,n):l}return console.error("GetDataValue: Invalid postfix",t),null}toString(){let e=`${this.data[0]}`;for(let t=1;t<this.data.length;++t)e+=`, ${this.data[t]}`;return e}},D=class extends q{constructor(e,t,n=0,r=null){super(t,r),this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.offset=n}clone(){let e=new Uint8Array(new Uint8Array(this.buffer,this.offset,this.typeInfo.size));return new D(e.buffer,this.typeInfo,0,null)}setDataValue(e,t,n,r){if(t===null)return void console.log("setDataValue: NULL data.");let s=this.offset,i=this.typeInfo;for(;n;){if(n instanceof fe)if(i instanceof se){let o=n.index;if(o instanceof R){if(!(o.value instanceof d))return void console.error(`SetDataValue: Invalid index type ${o.value}`);s+=o.value.value*i.stride}else{let l=e.evalExpression(o,r);if(!(l instanceof d))return void console.error("SetDataValue: Unknown index type",o);s+=l.value*i.stride}i=i.format}else console.error(`SetDataValue: Type ${i.getTypeName()} is not an array`);else{if(!(n instanceof ae))return void console.error("SetDataValue: Unknown postfix type",n);{let o=n.value;if(i instanceof re){let l=!1;for(let c of i.members)if(c.name===o){s+=c.offset,i=c.type,l=!0;break}if(!l)return void console.error(`SetDataValue: Member ${o} not found`)}else if(i instanceof W){let l=i.getTypeName(),c=0;if(o==="x"||o==="r")c=0;else if(o==="y"||o==="g")c=1;else if(o==="z"||o==="b")c=2;else{if(o!=="w"&&o!=="a")return void console.error(`SetDataValue: Unknown member ${o}`);c=3}if(!(t instanceof d))return void console.error("SetDataValue: Invalid value",t);let u=t.value;return l==="vec2f"?void(new Float32Array(this.buffer,s,2)[c]=u):l==="vec3f"?void(new Float32Array(this.buffer,s,3)[c]=u):l==="vec4f"?void(new Float32Array(this.buffer,s,4)[c]=u):l==="vec2i"?void(new Int32Array(this.buffer,s,2)[c]=u):l==="vec3i"?void(new Int32Array(this.buffer,s,3)[c]=u):l==="vec4i"?void(new Int32Array(this.buffer,s,4)[c]=u):l==="vec2u"?void(new Uint32Array(this.buffer,s,2)[c]=u):l==="vec3u"?void(new Uint32Array(this.buffer,s,3)[c]=u):l==="vec4u"?void(new Uint32Array(this.buffer,s,4)[c]=u):void console.error(`SetDataValue: Type ${l} is not a struct`)}}}n=n.postfix}this.setData(e,t,i,s,r)}setData(e,t,n,r,s){let i=n.getTypeName();if(i!=="f32"&&i!=="f16")if(i!=="i32"&&i!=="atomic<i32>"&&i!=="x32")if(i!=="u32"&&i!=="atomic<u32>")if(i!=="bool")if(i!=="vec2f"&&i!=="vec2h")if(i!=="vec3f"&&i!=="vec3h")if(i!=="vec4f"&&i!=="vec4h")if(i!=="vec2i")if(i!=="vec3i")if(i!=="vec4i")if(i!=="vec2u")if(i!=="vec3u")if(i!=="vec4u")if(i!=="vec2b")if(i!=="vec3b")if(i!=="vec4b")if(i!=="mat2x2f"&&i!=="mat2x2h")if(i!=="mat2x3f"&&i!=="mat2x3h")if(i!=="mat2x4f"&&i!=="mat2x4h")if(i!=="mat3x2f"&&i!=="mat3x2h")if(i!=="mat3x3f"&&i!=="mat3x3h")if(i!=="mat3x4f"&&i!=="mat3x4h")if(i!=="mat4x2f"&&i!=="mat4x2h")if(i!=="mat4x3f"&&i!=="mat4x3h")if(i!=="mat4x4f"&&i!=="mat4x4h")if(t instanceof D){if(n===t.typeInfo)return void new Uint8Array(this.buffer,r,t.buffer.byteLength).set(new Uint8Array(t.buffer));console.error("SetDataValue: Type mismatch",i,t.typeInfo.getTypeName())}else console.error(`SetData: Unknown type ${i}`);else{let o=new Float32Array(this.buffer,r,16);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11],o[12]=t.data[12],o[13]=t.data[13],o[14]=t.data[14],o[15]=t.data[15]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11],o[12]=t[12],o[13]=t[13],o[14]=t[14],o[15]=t[15])}else{let o=new Float32Array(this.buffer,r,12);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11])}else{let o=new Float32Array(this.buffer,r,8);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7])}else{let o=new Float32Array(this.buffer,r,12);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8],o[9]=t.data[9],o[10]=t.data[10],o[11]=t.data[11]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8],o[9]=t[9],o[10]=t[10],o[11]=t[11])}else{let o=new Float32Array(this.buffer,r,9);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7],o[8]=t.data[8]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7],o[8]=t[8])}else{let o=new Float32Array(this.buffer,r,6);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5])}else{let o=new Float32Array(this.buffer,r,8);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5],o[6]=t.data[6],o[7]=t.data[7]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5],o[6]=t[6],o[7]=t[7])}else{let o=new Float32Array(this.buffer,r,6);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3],o[4]=t.data[4],o[5]=t.data[5]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3],o[4]=t[4],o[5]=t[5])}else{let o=new Float32Array(this.buffer,r,4);t instanceof I?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Uint32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Uint32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Uint32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Uint32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Int32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Int32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Int32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else{let o=new Float32Array(this.buffer,r,4);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2],o[3]=t.data[3]):(o[0]=t[0],o[1]=t[1],o[2]=t[2],o[3]=t[3])}else{let o=new Float32Array(this.buffer,r,3);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1],o[2]=t.data[2]):(o[0]=t[0],o[1]=t[1],o[2]=t[2])}else{let o=new Float32Array(this.buffer,r,2);t instanceof p?(o[0]=t.data[0],o[1]=t.data[1]):(o[0]=t[0],o[1]=t[1])}else t instanceof d&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Uint32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Int32Array(this.buffer,r,1)[0]=t.value);else t instanceof d&&(new Float32Array(this.buffer,r,1)[0]=t.value)}getSubData(e,t,n){var r,s,i;if(t===null)return this;let o=this.offset,l=this.typeInfo;for(;t;){if(t instanceof fe){let u=t.index,h=e.evalExpression(u,n),b=0;if(h instanceof d?b=h.value:console.error("GetDataValue: Invalid index type",u),l instanceof se)o+=b*l.stride,l=l.format;else{let y=l.getTypeName();y==="mat4x4"||y==="mat4x4f"||y==="mat4x4h"?(o+=16*b,l=e.getTypeInfo("vec4f")):console.error(`getDataValue: Type ${l.getTypeName()} is not an array`)}}else{if(!(t instanceof ae))return console.error("GetDataValue: Unknown postfix type",t),null;{let u=t.value;if(l instanceof re){let h=!1;for(let b of l.members)if(b.name===u){o+=b.offset,l=b.type,h=!0;break}if(!h)return console.error(`GetDataValue: Member ${u} not found`),null}else if(l instanceof W){let h=l.getTypeName();if(h==="vec2f"||h==="vec3f"||h==="vec4f"||h==="vec2i"||h==="vec3i"||h==="vec4i"||h==="vec2u"||h==="vec3u"||h==="vec4u"||h==="vec2b"||h==="vec3b"||h==="vec4b"||h==="vec2h"||h==="vec3h"||h==="vec4h"||h==="vec2"||h==="vec3"||h==="vec4"){if(u.length>0&&u.length<5){let b="f",y=[];for(let S=0;S<u.length;++S){let E=u[S].toLowerCase(),T=0;if(E==="x"||E==="r")T=0;else if(E==="y"||E==="g")T=1;else if(E==="z"||E==="b")T=2;else{if(E!=="w"&&E!=="a")return console.error(`Unknown member ${u}`),null;T=3}if(u.length===1){if(h.endsWith("f"))return this.buffer.byteLength<o+4*T+4?(console.log("Insufficient buffer data"),null):new d(new Float32Array(this.buffer,o+4*T,1),e.getTypeInfo("f32"),this);if(h.endsWith("h"))return new d(new Float32Array(this.buffer,o+4*T,1),e.getTypeInfo("f16"),this);if(h.endsWith("i"))return new d(new Int32Array(this.buffer,o+4*T,1),e.getTypeInfo("i32"),this);if(h.endsWith("b"))return new d(new Int32Array(this.buffer,o+4*T,1),e.getTypeInfo("bool"),this);if(h.endsWith("u"))return new d(new Uint32Array(this.buffer,o+4*T,1),e.getTypeInfo("i32"),this)}if(h==="vec2f")y.push(new Float32Array(this.buffer,o,2)[T]);else if(h==="vec3f"){if(o+12>=this.buffer.byteLength)return console.log("Insufficient buffer data"),null;let L=new Float32Array(this.buffer,o,3);y.push(L[T])}else if(h==="vec4f")y.push(new Float32Array(this.buffer,o,4)[T]);else if(h==="vec2i")b="i",y.push(new Int32Array(this.buffer,o,2)[T]);else if(h==="vec3i")b="i",y.push(new Int32Array(this.buffer,o,3)[T]);else if(h==="vec4i")b="i",y.push(new Int32Array(this.buffer,o,4)[T]);else if(h==="vec2u"){b="u";let L=new Uint32Array(this.buffer,o,2);y.push(L[T])}else h==="vec3u"?(b="u",y.push(new Uint32Array(this.buffer,o,3)[T])):h==="vec4u"&&(b="u",y.push(new Uint32Array(this.buffer,o,4)[T]))}return y.length===2?l=e.getTypeInfo(`vec2${b}`):y.length===3?l=e.getTypeInfo(`vec3${b}`):y.length===4?l=e.getTypeInfo(`vec4${b}`):console.error(`GetDataValue: Invalid vector length ${y.length}`),new p(y,l,null)}return console.error(`GetDataValue: Unknown member ${u}`),null}return console.error(`GetDataValue: Type ${h} is not a struct`),null}}}t=t.postfix}let c=l.getTypeName();return c==="f32"?new d(new Float32Array(this.buffer,o,1),l,this):c==="i32"?new d(new Int32Array(this.buffer,o,1),l,this):c==="u32"?new d(new Uint32Array(this.buffer,o,1),l,this):c==="vec2f"?new p(new Float32Array(this.buffer,o,2),l,this):c==="vec3f"?new p(new Float32Array(this.buffer,o,3),l,this):c==="vec4f"?new p(new Float32Array(this.buffer,o,4),l,this):c==="vec2i"?new p(new Int32Array(this.buffer,o,2),l,this):c==="vec3i"?new p(new Int32Array(this.buffer,o,3),l,this):c==="vec4i"?new p(new Int32Array(this.buffer,o,4),l,this):c==="vec2u"?new p(new Uint32Array(this.buffer,o,2),l,this):c==="vec3u"?new p(new Uint32Array(this.buffer,o,3),l,this):c==="vec4u"?new p(new Uint32Array(this.buffer,o,4),l,this):l instanceof ie&&l.name==="atomic"?((r=l.format)===null||r===void 0?void 0:r.name)==="u32"?new d(new Uint32Array(this.buffer,o,1)[0],l.format,this):((s=l.format)===null||s===void 0?void 0:s.name)==="i32"?new d(new Int32Array(this.buffer,o,1)[0],l.format,this):(console.error(`GetDataValue: Invalid atomic format ${(i=l.format)===null||i===void 0?void 0:i.name}`),null):new D(this.buffer,l,o,this)}toString(){let e="";if(this.typeInfo instanceof se)if(this.typeInfo.format.name==="f32"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="i32"){let t=new Int32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="u32"){let t=new Uint32Array(this.buffer,this.offset);e=`[${t[0]}`;for(let n=1;n<t.length;++n)e+=`, ${t[n]}`}else if(this.typeInfo.format.name==="vec2f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}]`;for(let n=1;n<t.length/2;++n)e+=`, [${t[2*n]}, ${t[2*n+1]}]`}else if(this.typeInfo.format.name==="vec3f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}]`}else if(this.typeInfo.format.name==="vec4f"){let t=new Float32Array(this.buffer,this.offset);e=`[${t[0]}, ${t[1]}, ${t[2]}, ${t[3]}]`;for(let n=4;n<t.length;n+=4)e+=`, [${t[n]}, ${t[n+1]}, ${t[n+2]}, ${t[n+3]}]`}else e="[...]";else this.typeInfo instanceof re?e+="{...}":e="[...]";return e}},J=class extends q{constructor(e,t,n,r){super(t,null),this.data=e,this.descriptor=n,this.view=r}clone(){return new J(this.data,this.typeInfo,this.descriptor,this.view)}get width(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>0?(e=n[0])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.width)!==null&&t!==void 0?t:0}get height(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>1?(e=n[1])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.height)!==null&&t!==void 0?t:0}get depthOrArrayLayers(){var e,t;let n=this.descriptor.size;return n instanceof Array&&n.length>2?(e=n[2])!==null&&e!==void 0?e:0:n instanceof Object&&(t=n.depthOrArrayLayers)!==null&&t!==void 0?t:0}get format(){var e;return this.descriptor&&(e=this.descriptor.format)!==null&&e!==void 0?e:"rgba8unorm"}get sampleCount(){var e;return this.descriptor&&(e=this.descriptor.sampleCount)!==null&&e!==void 0?e:1}get mipLevelCount(){var e;return this.descriptor&&(e=this.descriptor.mipLevelCount)!==null&&e!==void 0?e:1}get dimension(){var e;return this.descriptor&&(e=this.descriptor.dimension)!==null&&e!==void 0?e:"2d"}getMipLevelSize(e){if(e>=this.mipLevelCount)return[0,0,0];let t=[this.width,this.height,this.depthOrArrayLayers];for(let n=0;n<t.length;++n)t[n]=Math.max(1,t[n]>>e);return t}get texelByteSize(){let e=this.format,t=Wt[e];return t?t.isDepthStencil?4:t.bytesPerBlock:0}get bytesPerRow(){return this.width*this.texelByteSize}get isDepthStencil(){let e=this.format,t=Wt[e];return!!t&&t.isDepthStencil}getGpuSize(){let e=this.format,t=Wt[e],n=this.width;if(!e||n<=0||!t)return-1;let r=this.height,s=this.depthOrArrayLayers,i=this.dimension;return n/t.blockWidth*(i==="1d"?1:r/t.blockHeight)*t.bytesPerBlock*s}getPixel(e,t,n=0,r=0){let s=this.texelByteSize,i=this.bytesPerRow,o=this.height,l=this.data[r];return Yr(new Uint8Array(l),e,t,n,r,o,i,s,this.format)}setPixel(e,t,n,r,s){let i=this.texelByteSize,o=this.bytesPerRow,l=this.height,c=this.data[r];(function(u,h,b,y,S,E,T,L,P,k){let A=y*(T>>=S)*(E>>=S)+b*T+h*L;switch(P){case"r8unorm":return void N(u,A,"8unorm",1,k);case"r8snorm":return void N(u,A,"8snorm",1,k);case"r8uint":return void N(u,A,"8uint",1,k);case"r8sint":return void N(u,A,"8sint",1,k);case"rg8unorm":return void N(u,A,"8unorm",2,k);case"rg8snorm":return void N(u,A,"8snorm",2,k);case"rg8uint":return void N(u,A,"8uint",2,k);case"rg8sint":return void N(u,A,"8sint",2,k);case"rgba8unorm-srgb":case"rgba8unorm":case"bgra8unorm-srgb":case"bgra8unorm":return void N(u,A,"8unorm",4,k);case"rgba8snorm":return void N(u,A,"8snorm",4,k);case"rgba8uint":return void N(u,A,"8uint",4,k);case"rgba8sint":return void N(u,A,"8sint",4,k);case"r16uint":return void N(u,A,"16uint",1,k);case"r16sint":return void N(u,A,"16sint",1,k);case"r16float":return void N(u,A,"16float",1,k);case"rg16uint":return void N(u,A,"16uint",2,k);case"rg16sint":return void N(u,A,"16sint",2,k);case"rg16float":return void N(u,A,"16float",2,k);case"rgba16uint":return void N(u,A,"16uint",4,k);case"rgba16sint":return void N(u,A,"16sint",4,k);case"rgba16float":return void N(u,A,"16float",4,k);case"r32uint":return void N(u,A,"32uint",1,k);case"r32sint":return void N(u,A,"32sint",1,k);case"depth16unorm":case"depth24plus":case"depth24plus-stencil8":case"depth32float":case"depth32float-stencil8":case"r32float":return void N(u,A,"32float",1,k);case"rg32uint":return void N(u,A,"32uint",2,k);case"rg32sint":return void N(u,A,"32sint",2,k);case"rg32float":return void N(u,A,"32float",2,k);case"rgba32uint":return void N(u,A,"32uint",4,k);case"rgba32sint":return void N(u,A,"32sint",4,k);case"rgba32float":return void N(u,A,"32float",4,k);case"rg11b10ufloat":console.error("TODO: rg11b10ufloat not supported for writing")}})(new Uint8Array(c),e,t,n,r,l,o,i,this.format,s)}};(a=>{a[a.token=0]="token",a[a.keyword=1]="keyword",a[a.reserved=2]="reserved"})(_||(_={}));var m=class{constructor(e,t,n){this.name=e,this.type=t,this.rule=n}toString(){return this.name}},f=class{};v=f,f.none=new m("",_.reserved,""),f.eof=new m("EOF",_.token,""),f.reserved={asm:new m("asm",_.reserved,"asm"),bf16:new m("bf16",_.reserved,"bf16"),do:new m("do",_.reserved,"do"),enum:new m("enum",_.reserved,"enum"),f16:new m("f16",_.reserved,"f16"),f64:new m("f64",_.reserved,"f64"),handle:new m("handle",_.reserved,"handle"),i8:new m("i8",_.reserved,"i8"),i16:new m("i16",_.reserved,"i16"),i64:new m("i64",_.reserved,"i64"),mat:new m("mat",_.reserved,"mat"),premerge:new m("premerge",_.reserved,"premerge"),regardless:new m("regardless",_.reserved,"regardless"),typedef:new m("typedef",_.reserved,"typedef"),u8:new m("u8",_.reserved,"u8"),u16:new m("u16",_.reserved,"u16"),u64:new m("u64",_.reserved,"u64"),unless:new m("unless",_.reserved,"unless"),using:new m("using",_.reserved,"using"),vec:new m("vec",_.reserved,"vec"),void:new m("void",_.reserved,"void")},f.keywords={array:new m("array",_.keyword,"array"),atomic:new m("atomic",_.keyword,"atomic"),bool:new m("bool",_.keyword,"bool"),f32:new m("f32",_.keyword,"f32"),i32:new m("i32",_.keyword,"i32"),mat2x2:new m("mat2x2",_.keyword,"mat2x2"),mat2x3:new m("mat2x3",_.keyword,"mat2x3"),mat2x4:new m("mat2x4",_.keyword,"mat2x4"),mat3x2:new m("mat3x2",_.keyword,"mat3x2"),mat3x3:new m("mat3x3",_.keyword,"mat3x3"),mat3x4:new m("mat3x4",_.keyword,"mat3x4"),mat4x2:new m("mat4x2",_.keyword,"mat4x2"),mat4x3:new m("mat4x3",_.keyword,"mat4x3"),mat4x4:new m("mat4x4",_.keyword,"mat4x4"),ptr:new m("ptr",_.keyword,"ptr"),sampler:new m("sampler",_.keyword,"sampler"),sampler_comparison:new m("sampler_comparison",_.keyword,"sampler_comparison"),struct:new m("struct",_.keyword,"struct"),texture_1d:new m("texture_1d",_.keyword,"texture_1d"),texture_2d:new m("texture_2d",_.keyword,"texture_2d"),texture_2d_array:new m("texture_2d_array",_.keyword,"texture_2d_array"),texture_3d:new m("texture_3d",_.keyword,"texture_3d"),texture_cube:new m("texture_cube",_.keyword,"texture_cube"),texture_cube_array:new m("texture_cube_array",_.keyword,"texture_cube_array"),texture_multisampled_2d:new m("texture_multisampled_2d",_.keyword,"texture_multisampled_2d"),texture_storage_1d:new m("texture_storage_1d",_.keyword,"texture_storage_1d"),texture_storage_2d:new m("texture_storage_2d",_.keyword,"texture_storage_2d"),texture_storage_2d_array:new m("texture_storage_2d_array",_.keyword,"texture_storage_2d_array"),texture_storage_3d:new m("texture_storage_3d",_.keyword,"texture_storage_3d"),texture_depth_2d:new m("texture_depth_2d",_.keyword,"texture_depth_2d"),texture_depth_2d_array:new m("texture_depth_2d_array",_.keyword,"texture_depth_2d_array"),texture_depth_cube:new m("texture_depth_cube",_.keyword,"texture_depth_cube"),texture_depth_cube_array:new m("texture_depth_cube_array",_.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new m("texture_depth_multisampled_2d",_.keyword,"texture_depth_multisampled_2d"),texture_external:new m("texture_external",_.keyword,"texture_external"),u32:new m("u32",_.keyword,"u32"),vec2:new m("vec2",_.keyword,"vec2"),vec3:new m("vec3",_.keyword,"vec3"),vec4:new m("vec4",_.keyword,"vec4"),bitcast:new m("bitcast",_.keyword,"bitcast"),block:new m("block",_.keyword,"block"),break:new m("break",_.keyword,"break"),case:new m("case",_.keyword,"case"),continue:new m("continue",_.keyword,"continue"),continuing:new m("continuing",_.keyword,"continuing"),default:new m("default",_.keyword,"default"),diagnostic:new m("diagnostic",_.keyword,"diagnostic"),discard:new m("discard",_.keyword,"discard"),else:new m("else",_.keyword,"else"),enable:new m("enable",_.keyword,"enable"),fallthrough:new m("fallthrough",_.keyword,"fallthrough"),false:new m("false",_.keyword,"false"),fn:new m("fn",_.keyword,"fn"),for:new m("for",_.keyword,"for"),function:new m("function",_.keyword,"function"),if:new m("if",_.keyword,"if"),let:new m("let",_.keyword,"let"),const:new m("const",_.keyword,"const"),loop:new m("loop",_.keyword,"loop"),while:new m("while",_.keyword,"while"),private:new m("private",_.keyword,"private"),read:new m("read",_.keyword,"read"),read_write:new m("read_write",_.keyword,"read_write"),return:new m("return",_.keyword,"return"),requires:new m("requires",_.keyword,"requires"),storage:new m("storage",_.keyword,"storage"),switch:new m("switch",_.keyword,"switch"),true:new m("true",_.keyword,"true"),alias:new m("alias",_.keyword,"alias"),type:new m("type",_.keyword,"type"),uniform:new m("uniform",_.keyword,"uniform"),var:new m("var",_.keyword,"var"),override:new m("override",_.keyword,"override"),workgroup:new m("workgroup",_.keyword,"workgroup"),write:new m("write",_.keyword,"write"),r8unorm:new m("r8unorm",_.keyword,"r8unorm"),r8snorm:new m("r8snorm",_.keyword,"r8snorm"),r8uint:new m("r8uint",_.keyword,"r8uint"),r8sint:new m("r8sint",_.keyword,"r8sint"),r16uint:new m("r16uint",_.keyword,"r16uint"),r16sint:new m("r16sint",_.keyword,"r16sint"),r16float:new m("r16float",_.keyword,"r16float"),rg8unorm:new m("rg8unorm",_.keyword,"rg8unorm"),rg8snorm:new m("rg8snorm",_.keyword,"rg8snorm"),rg8uint:new m("rg8uint",_.keyword,"rg8uint"),rg8sint:new m("rg8sint",_.keyword,"rg8sint"),r32uint:new m("r32uint",_.keyword,"r32uint"),r32sint:new m("r32sint",_.keyword,"r32sint"),r32float:new m("r32float",_.keyword,"r32float"),rg16uint:new m("rg16uint",_.keyword,"rg16uint"),rg16sint:new m("rg16sint",_.keyword,"rg16sint"),rg16float:new m("rg16float",_.keyword,"rg16float"),rgba8unorm:new m("rgba8unorm",_.keyword,"rgba8unorm"),rgba8unorm_srgb:new m("rgba8unorm_srgb",_.keyword,"rgba8unorm_srgb"),rgba8snorm:new m("rgba8snorm",_.keyword,"rgba8snorm"),rgba8uint:new m("rgba8uint",_.keyword,"rgba8uint"),rgba8sint:new m("rgba8sint",_.keyword,"rgba8sint"),bgra8unorm:new m("bgra8unorm",_.keyword,"bgra8unorm"),bgra8unorm_srgb:new m("bgra8unorm_srgb",_.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new m("rgb10a2unorm",_.keyword,"rgb10a2unorm"),rg11b10float:new m("rg11b10float",_.keyword,"rg11b10float"),rg32uint:new m("rg32uint",_.keyword,"rg32uint"),rg32sint:new m("rg32sint",_.keyword,"rg32sint"),rg32float:new m("rg32float",_.keyword,"rg32float"),rgba16uint:new m("rgba16uint",_.keyword,"rgba16uint"),rgba16sint:new m("rgba16sint",_.keyword,"rgba16sint"),rgba16float:new m("rgba16float",_.keyword,"rgba16float"),rgba32uint:new m("rgba32uint",_.keyword,"rgba32uint"),rgba32sint:new m("rgba32sint",_.keyword,"rgba32sint"),rgba32float:new m("rgba32float",_.keyword,"rgba32float"),static_assert:new m("static_assert",_.keyword,"static_assert")},f.tokens={decimal_float_literal:new m("decimal_float_literal",_.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?[fh]?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+[fh]?)|(-?[0-9]+[fh])/),hex_float_literal:new m("hex_float_literal",_.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+[fh]?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+[fh]?))/),int_literal:new m("int_literal",_.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new m("uint_literal",_.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),name:new m("name",_.token,/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/u),ident:new m("ident",_.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new m("and",_.token,"&"),and_and:new m("and_and",_.token,"&&"),arrow:new m("arrow ",_.token,"->"),attr:new m("attr",_.token,"@"),forward_slash:new m("forward_slash",_.token,"/"),bang:new m("bang",_.token,"!"),bracket_left:new m("bracket_left",_.token,"["),bracket_right:new m("bracket_right",_.token,"]"),brace_left:new m("brace_left",_.token,"{"),brace_right:new m("brace_right",_.token,"}"),colon:new m("colon",_.token,":"),comma:new m("comma",_.token,","),equal:new m("equal",_.token,"="),equal_equal:new m("equal_equal",_.token,"=="),not_equal:new m("not_equal",_.token,"!="),greater_than:new m("greater_than",_.token,">"),greater_than_equal:new m("greater_than_equal",_.token,">="),shift_right:new m("shift_right",_.token,">>"),less_than:new m("less_than",_.token,"<"),less_than_equal:new m("less_than_equal",_.token,"<="),shift_left:new m("shift_left",_.token,"<<"),modulo:new m("modulo",_.token,"%"),minus:new m("minus",_.token,"-"),minus_minus:new m("minus_minus",_.token,"--"),period:new m("period",_.token,"."),plus:new m("plus",_.token,"+"),plus_plus:new m("plus_plus",_.token,"++"),or:new m("or",_.token,"|"),or_or:new m("or_or",_.token,"||"),paren_left:new m("paren_left",_.token,"("),paren_right:new m("paren_right",_.token,")"),semicolon:new m("semicolon",_.token,";"),star:new m("star",_.token,"*"),tilde:new m("tilde",_.token,"~"),underscore:new m("underscore",_.token,"_"),xor:new m("xor",_.token,"^"),plus_equal:new m("plus_equal",_.token,"+="),minus_equal:new m("minus_equal",_.token,"-="),times_equal:new m("times_equal",_.token,"*="),division_equal:new m("division_equal",_.token,"/="),modulo_equal:new m("modulo_equal",_.token,"%="),and_equal:new m("and_equal",_.token,"&="),or_equal:new m("or_equal",_.token,"|="),xor_equal:new m("xor_equal",_.token,"^="),shift_right_equal:new m("shift_right_equal",_.token,">>="),shift_left_equal:new m("shift_left_equal",_.token,"<<=")},f.simpleTokens={"@":v.tokens.attr,"{":v.tokens.brace_left,"}":v.tokens.brace_right,":":v.tokens.colon,",":v.tokens.comma,"(":v.tokens.paren_left,")":v.tokens.paren_right,";":v.tokens.semicolon},f.literalTokens={"&":v.tokens.and,"&&":v.tokens.and_and,"->":v.tokens.arrow,"/":v.tokens.forward_slash,"!":v.tokens.bang,"[":v.tokens.bracket_left,"]":v.tokens.bracket_right,"=":v.tokens.equal,"==":v.tokens.equal_equal,"!=":v.tokens.not_equal,">":v.tokens.greater_than,">=":v.tokens.greater_than_equal,">>":v.tokens.shift_right,"<":v.tokens.less_than,"<=":v.tokens.less_than_equal,"<<":v.tokens.shift_left,"%":v.tokens.modulo,"-":v.tokens.minus,"--":v.tokens.minus_minus,".":v.tokens.period,"+":v.tokens.plus,"++":v.tokens.plus_plus,"|":v.tokens.or,"||":v.tokens.or_or,"*":v.tokens.star,"~":v.tokens.tilde,_:v.tokens.underscore,"^":v.tokens.xor,"+=":v.tokens.plus_equal,"-=":v.tokens.minus_equal,"*=":v.tokens.times_equal,"/=":v.tokens.division_equal,"%=":v.tokens.modulo_equal,"&=":v.tokens.and_equal,"|=":v.tokens.or_equal,"^=":v.tokens.xor_equal,">>=":v.tokens.shift_right_equal,"<<=":v.tokens.shift_left_equal},f.regexTokens={decimal_float_literal:v.tokens.decimal_float_literal,hex_float_literal:v.tokens.hex_float_literal,int_literal:v.tokens.int_literal,uint_literal:v.tokens.uint_literal,ident:v.tokens.ident},f.storage_class=[v.keywords.function,v.keywords.private,v.keywords.workgroup,v.keywords.uniform,v.keywords.storage],f.access_mode=[v.keywords.read,v.keywords.write,v.keywords.read_write],f.sampler_type=[v.keywords.sampler,v.keywords.sampler_comparison],f.sampled_texture_type=[v.keywords.texture_1d,v.keywords.texture_2d,v.keywords.texture_2d_array,v.keywords.texture_3d,v.keywords.texture_cube,v.keywords.texture_cube_array],f.multisampled_texture_type=[v.keywords.texture_multisampled_2d],f.storage_texture_type=[v.keywords.texture_storage_1d,v.keywords.texture_storage_2d,v.keywords.texture_storage_2d_array,v.keywords.texture_storage_3d],f.depth_texture_type=[v.keywords.texture_depth_2d,v.keywords.texture_depth_2d_array,v.keywords.texture_depth_cube,v.keywords.texture_depth_cube_array,v.keywords.texture_depth_multisampled_2d],f.texture_external_type=[v.keywords.texture_external],f.any_texture_type=[...v.sampled_texture_type,...v.multisampled_texture_type,...v.storage_texture_type,...v.depth_texture_type,...v.texture_external_type],f.texel_format=[v.keywords.r8unorm,v.keywords.r8snorm,v.keywords.r8uint,v.keywords.r8sint,v.keywords.r16uint,v.keywords.r16sint,v.keywords.r16float,v.keywords.rg8unorm,v.keywords.rg8snorm,v.keywords.rg8uint,v.keywords.rg8sint,v.keywords.r32uint,v.keywords.r32sint,v.keywords.r32float,v.keywords.rg16uint,v.keywords.rg16sint,v.keywords.rg16float,v.keywords.rgba8unorm,v.keywords.rgba8unorm_srgb,v.keywords.rgba8snorm,v.keywords.rgba8uint,v.keywords.rgba8sint,v.keywords.bgra8unorm,v.keywords.bgra8unorm_srgb,v.keywords.rgb10a2unorm,v.keywords.rg11b10float,v.keywords.rg32uint,v.keywords.rg32sint,v.keywords.rg32float,v.keywords.rgba16uint,v.keywords.rgba16sint,v.keywords.rgba16float,v.keywords.rgba32uint,v.keywords.rgba32sint,v.keywords.rgba32float],f.const_literal=[v.tokens.int_literal,v.tokens.uint_literal,v.tokens.decimal_float_literal,v.tokens.hex_float_literal,v.keywords.true,v.keywords.false],f.literal_or_ident=[v.tokens.ident,v.tokens.int_literal,v.tokens.uint_literal,v.tokens.decimal_float_literal,v.tokens.hex_float_literal,v.tokens.name],f.element_count_expression=[v.tokens.int_literal,v.tokens.uint_literal,v.tokens.ident],f.template_types=[v.keywords.vec2,v.keywords.vec3,v.keywords.vec4,v.keywords.mat2x2,v.keywords.mat2x3,v.keywords.mat2x4,v.keywords.mat3x2,v.keywords.mat3x3,v.keywords.mat3x4,v.keywords.mat4x2,v.keywords.mat4x3,v.keywords.mat4x4,v.keywords.atomic,v.keywords.bitcast,...v.any_texture_type],f.attribute_name=[v.tokens.ident,v.keywords.block,v.keywords.diagnostic],f.assignment_operators=[v.tokens.equal,v.tokens.plus_equal,v.tokens.minus_equal,v.tokens.times_equal,v.tokens.division_equal,v.tokens.modulo_equal,v.tokens.and_equal,v.tokens.or_equal,v.tokens.xor_equal,v.tokens.shift_right_equal,v.tokens.shift_left_equal],f.increment_operators=[v.tokens.plus_plus,v.tokens.minus_minus];var Lt=class{constructor(e,t,n,r,s){this.type=e,this.lexeme=t,this.line=n,this.start=r,this.end=s}toString(){return this.lexeme}isTemplateType(){return f.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==f.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},rn=class{constructor(e){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=e??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Lt(f.eof,"",this._line,this._current,this._current)),this._tokens}scanToken(){let e=this._advance();if(e==`
99
- `)return this._line++,!0;if(this._isWhitespace(e))return!0;if(e=="/"){if(this._peekAhead()=="/"){for(;e!=`
100
- `;){if(this._isAtEnd())return!0;e=this._advance()}return this._line++,!0}if(this._peekAhead()=="*"){this._advance();let i=1;for(;i>0;){if(this._isAtEnd())return!0;if(e=this._advance(),e==`
101
- `)this._line++;else if(e=="*"){if(this._peekAhead()=="/"&&(this._advance(),i--,i==0))return!0}else e=="/"&&this._peekAhead()=="*"&&(this._advance(),i++)}return!0}}let t=f.simpleTokens[e];if(t)return this._addToken(t),!0;let n=f.none,r=this._isAlpha(e),s=e==="_";if(this._isAlphaNumeric(e)){let i=this._peekAhead();for(;this._isAlphaNumeric(i);)e+=this._advance(),i=this._peekAhead()}if(r){let i=f.keywords[e];if(i)return this._addToken(i),!0}if(r||s)return this._addToken(f.tokens.ident),!0;for(;;){let i=this._findType(e),o=this._peekAhead();if(e=="-"&&this._tokens.length>0){if(o=="=")return this._current++,e+=o,this._addToken(f.tokens.minus_equal),!0;if(o=="-")return this._current++,e+=o,this._addToken(f.tokens.minus_minus),!0;let l=this._tokens.length-1;if((f.literal_or_ident.indexOf(this._tokens[l].type)!=-1||this._tokens[l].type==f.tokens.paren_right)&&o!=">")return this._addToken(i),!0}if(e==">"&&(o==">"||o=="=")){let l=!1,c=this._tokens.length-1;for(let u=0;u<5&&c>=0&&f.assignment_operators.indexOf(this._tokens[c].type)===-1;++u,--c)if(this._tokens[c].type===f.tokens.less_than){c>0&&this._tokens[c-1].isArrayOrTemplateType()&&(l=!0);break}if(l)return this._addToken(i),!0}if(i===f.none){let l=e,c=0,u=2;for(let h=0;h<u;++h)if(l+=this._peekAhead(h),i=this._findType(l),i!==f.none){c=h;break}if(i===f.none)return n!==f.none&&(this._current--,this._addToken(n),!0);e=l,this._current+=c+1}if(n=i,this._isAtEnd())break;e+=this._advance()}return n!==f.none&&(this._addToken(n),!0)}_findType(e){for(let n in f.regexTokens){let r=f.regexTokens[n];if(this._match(e,r.rule))return r}return f.literalTokens[e]||f.none}_match(e,t){let n=t.exec(e);return n&&n.index==0&&n[0]==e}_isAtEnd(){return this._current>=this._source.length}_isAlpha(e){return!this._isNumeric(e)&&!this._isWhitespace(e)&&e!=="_"&&e!=="."&&e!=="("&&e!==")"&&e!=="["&&e!=="]"&&e!=="{"&&e!=="}"&&e!==","&&e!==";"&&e!==":"&&e!=="="&&e!=="!"&&e!=="<"&&e!==">"&&e!=="+"&&e!=="-"&&e!=="*"&&e!=="/"&&e!=="%"&&e!=="&"&&e!=="|"&&e!=="^"&&e!=="~"&&e!=="@"&&e!=="#"&&e!=="?"&&e!=="'"&&e!=="`"&&e!=='"'&&e!=="\\"&&e!==`
102
- `&&e!=="\r"&&e!==" "&&e!=="\0"}_isNumeric(e){return e>="0"&&e<="9"}_isAlphaNumeric(e){return this._isAlpha(e)||this._isNumeric(e)||e==="_"}_isWhitespace(e){return e==" "||e==" "||e=="\r"}_advance(e=0){let t=this._source[this._current];return e=e||0,e++,this._current+=e,t}_peekAhead(e=0){return e=e||0,this._current+e>=this._source.length?"\0":this._source[this._current+e]}_addToken(e){let t=this._source.substring(this._start,this._current);this._tokens.push(new Lt(e,t,this._line,this._start,this._current))}};function w(a){return Array.isArray(a)||a?.buffer instanceof ArrayBuffer}var Et=new Float32Array(1),es=new Uint32Array(Et.buffer),ts=new Uint32Array(Et.buffer),Ct=new Int32Array(1),ns=new Float32Array(Ct.buffer),rs=new Uint32Array(Ct.buffer),Nt=new Uint32Array(1),ss=new Float32Array(Nt.buffer),os=new Int32Array(Nt.buffer);function jn(a,e,t){if(e===t)return a;if(e==="f32"){if(t==="i32"||t==="x32")return Et[0]=a,es[0];if(t==="u32")return Et[0]=a,ts[0]}else if(e==="i32"||e==="x32"){if(t==="f32")return Ct[0]=a,ns[0];if(t==="u32")return Ct[0]=a,rs[0]}else if(e==="u32"){if(t==="f32")return Nt[0]=a,ss[0];if(t==="i32"||t==="x32")return Nt[0]=a,os[0]}return console.error(`Unsupported cast from ${e} to ${t}`),a}var sn=class{constructor(e){this.resources=null,this.inUse=!1,this.info=null,this.node=e}},we=class{constructor(e,t){this.align=e,this.size=t}},Z=class{constructor(){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Qt,this.functions=[],this._types=new Map,this._functions=new Map}_isStorageTexture(e){return e.name=="texture_storage_1d"||e.name=="texture_storage_2d"||e.name=="texture_storage_2d_array"||e.name=="texture_storage_3d"}updateAST(e){for(let t of e)t instanceof ge&&this._functions.set(t.name,new sn(t));for(let t of e)if(t instanceof Y){let n=this.getTypeInfo(t,null);n instanceof re&&this.structs.push(n)}for(let t of e)if(t instanceof $e)this.aliases.push(this._getAliasInfo(t));else if(t instanceof Ve){let n=t,r=this._getAttributeNum(n.attributes,"id",0),s=n.type!=null?this.getTypeInfo(n.type,n.attributes):null;this.overrides.push(new Xt(n.name,s,n.attributes,r))}else if(this._isUniformVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),i=this.getTypeInfo(n.type,n.attributes),o=new xe(n.name,i,r,s,n.attributes,ce.Uniform,n.access);o.access||(o.access="read"),this.uniforms.push(o)}else if(this._isStorageVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),i=this.getTypeInfo(n.type,n.attributes),o=this._isStorageTexture(i),l=new xe(n.name,i,r,s,n.attributes,o?ce.StorageTexture:ce.Storage,n.access);l.access||(l.access="read"),this.storage.push(l)}else if(this._isTextureVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),i=this.getTypeInfo(n.type,n.attributes),o=this._isStorageTexture(i),l=new xe(n.name,i,r,s,n.attributes,o?ce.StorageTexture:ce.Texture,n.access);l.access||(l.access="read"),o?this.storage.push(l):this.textures.push(l)}else if(this._isSamplerVar(t)){let n=t,r=this._getAttributeNum(n.attributes,"group",0),s=this._getAttributeNum(n.attributes,"binding",0),i=this.getTypeInfo(n.type,n.attributes),o=new xe(n.name,i,r,s,n.attributes,ce.Sampler,n.access);this.samplers.push(o)}else if(t instanceof ge){let n=this._getAttribute(t,"vertex"),r=this._getAttribute(t,"fragment"),s=this._getAttribute(t,"compute"),i=n||r||s,o=new Zt(t.name,i?.name,t.attributes);o.attributes=t.attributes,o.startLine=t.startLine,o.endLine=t.endLine,this.functions.push(o),this._functions.get(t.name).info=o,i&&(this._functions.get(t.name).inUse=!0,o.inUse=!0,o.resources=this._findResources(t,!!i),o.inputs=this._getInputs(t.args),o.outputs=this._getOutputs(t.returnType),this.entry[i.name].push(o)),o.arguments=t.args.map(l=>new Kt(l.name,this.getTypeInfo(l.type,l.attributes),l.attributes)),o.returnType=t.returnType?this.getTypeInfo(t.returnType,t.attributes):null}for(let t of this._functions.values())t.info&&(t.info.inUse=t.inUse,this._addCalls(t.node,t.info.calls));for(let t of this._functions.values())t.node.search(n=>{var r,s,i;if(n instanceof Tt){if(n.value)if(w(n.value))for(let o of n.value)for(let l of this.overrides)o===l.name&&((r=t.info)===null||r===void 0||r.overrides.push(l));else for(let o of this.overrides)n.value===o.name&&((s=t.info)===null||s===void 0||s.overrides.push(o))}else if(n instanceof G)for(let o of this.overrides)n.name===o.name&&((i=t.info)===null||i===void 0||i.overrides.push(o))});for(let t of this.uniforms)this._markStructsInUse(t.type);for(let t of this.storage)this._markStructsInUse(t.type)}getStructInfo(e){for(let t of this.structs)if(t.name==e)return t;return null}getOverrideInfo(e){for(let t of this.overrides)if(t.name==e)return t;return null}_markStructsInUse(e){if(e)if(e.isStruct){if(e.inUse=!0,e.members)for(let t of e.members)this._markStructsInUse(t.type)}else if(e.isArray)this._markStructsInUse(e.format);else if(e.isTemplate)e.format&&this._markStructsInUse(e.format);else{let t=this._getAlias(e.name);t&&this._markStructsInUse(t)}}_addCalls(e,t){var n;for(let r of e.calls){let s=(n=this._functions.get(r.name))===null||n===void 0?void 0:n.info;s&&t.add(s)}}findResource(e,t,n){if(n){for(let r of this.entry.compute)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.vertex)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}for(let r of this.entry.fragment)if(r.name===n){for(let s of r.resources)if(s.group==e&&s.binding==t)return s}}for(let r of this.uniforms)if(r.group==e&&r.binding==t)return r;for(let r of this.storage)if(r.group==e&&r.binding==t)return r;for(let r of this.textures)if(r.group==e&&r.binding==t)return r;for(let r of this.samplers)if(r.group==e&&r.binding==t)return r;return null}_findResource(e){for(let t of this.uniforms)if(t.name==e)return t;for(let t of this.storage)if(t.name==e)return t;for(let t of this.textures)if(t.name==e)return t;for(let t of this.samplers)if(t.name==e)return t;return null}_markStructsFromAST(e){let t=this.getTypeInfo(e,null);this._markStructsInUse(t)}_findResources(e,t){let n=[],r=this,s=[];return e.search(i=>{if(i instanceof Se)s.push({});else if(i instanceof Ae)s.pop();else if(i instanceof ee){let o=i;t&&o.type!==null&&this._markStructsFromAST(o.type),s.length>0&&(s[s.length-1][o.name]=o)}else if(i instanceof K){let o=i;t&&o.type!==null&&this._markStructsFromAST(o.type)}else if(i instanceof me){let o=i;t&&o.type!==null&&this._markStructsFromAST(o.type),s.length>0&&(s[s.length-1][o.name]=o)}else if(i instanceof G){let o=i;if(s.length>0&&s[s.length-1][o.name])return;let l=r._findResource(o.name);l&&n.push(l)}else if(i instanceof He){let o=i,l=r._functions.get(o.name);l&&(t&&(l.inUse=!0),e.calls.add(l.node),l.resources===null&&(l.resources=r._findResources(l.node,t)),n.push(...l.resources))}else if(i instanceof Ue){let o=i,l=r._functions.get(o.name);l&&(t&&(l.inUse=!0),e.calls.add(l.node),l.resources===null&&(l.resources=r._findResources(l.node,t)),n.push(...l.resources))}}),[...new Map(n.map(i=>[i.name,i])).values()]}getBindGroups(){let e=[];function t(n,r){n>=e.length&&(e.length=n+1),e[n]===void 0&&(e[n]=[]),r>=e[n].length&&(e[n].length=r+1)}for(let n of this.uniforms)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.storage)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.textures)t(n.group,n.binding),e[n.group][n.binding]=n;for(let n of this.samplers)t(n.group,n.binding),e[n.group][n.binding]=n;return e}_getOutputs(e,t=void 0){if(t===void 0&&(t=[]),e instanceof Y)this._getStructOutputs(e,t);else{let n=this._getOutputInfo(e);n!==null&&t.push(n)}return t}_getStructOutputs(e,t){for(let n of e.members)if(n.type instanceof Y)this._getStructOutputs(n.type,t);else{let r=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(r!==null){let s=this.getTypeInfo(n.type,n.type.attributes),i=this._parseInt(r.value),o=new it(n.name,s,r.name,i);t.push(o)}}}_getOutputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this.getTypeInfo(e,e.attributes),r=this._parseInt(t.value);return new it("",n,t.name,r)}return null}_getInputs(e,t=void 0){t===void 0&&(t=[]);for(let n of e)if(n.type instanceof Y)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}return t}_getStructInputs(e,t){for(let n of e.members)if(n.type instanceof Y)this._getStructInputs(n.type,t);else{let r=this._getInputInfo(n);r!==null&&t.push(r)}}_getInputInfo(e){let t=this._getAttribute(e,"location")||this._getAttribute(e,"builtin");if(t!==null){let n=this._getAttribute(e,"interpolation"),r=this.getTypeInfo(e.type,e.attributes),s=this._parseInt(t.value),i=new jt(e.name,r,t.name,s);return n!==null&&(i.interpolation=this._parseString(n.value)),i}return null}_parseString(e){return e instanceof Array&&(e=e[0]),e}_parseInt(e){e instanceof Array&&(e=e[0]);let t=parseInt(e);return isNaN(t)?e:t}_getAlias(e){for(let t of this.aliases)if(t.name==e)return t.type;return null}_getAliasInfo(e){return new qt(e.name,this.getTypeInfo(e.type,null))}getTypeInfoByName(e){for(let t of this.structs)if(t.name==e)return t;for(let t of this.aliases)if(t.name==e)return t.type;return null}getTypeInfo(e,t=null){if(this._types.has(e))return this._types.get(e);if(e instanceof _e){let r=e,s=r.format?this.getTypeInfo(r.format,r.attributes):null,i=new se(r.name,t);return i.format=s,i.count=r.count,this._types.set(e,i),this._updateTypeInfo(i),i}if(e instanceof Y){let r=e,s=new re(r.name,t);s.startLine=r.startLine,s.endLine=r.endLine;for(let i of r.members){let o=this.getTypeInfo(i.type,i.attributes);s.members.push(new ot(i.name,o,i.attributes))}return this._types.set(e,s),this._updateTypeInfo(s),s}if(e instanceof de){let r=e,s=r.format instanceof x,i=r.format?s?this.getTypeInfo(r.format,null):new W(r.format,null):null,o=new ie(r.name,i,t,r.access);return this._types.set(e,o),this._updateTypeInfo(o),o}if(e instanceof g){let r=e,s=r.format?this.getTypeInfo(r.format,null):null,i=new ie(r.name,s,t,r.access);return this._types.set(e,i),this._updateTypeInfo(i),i}let n=new W(e.name,t);return this._types.set(e,n),this._updateTypeInfo(n),n}_updateTypeInfo(e){var t,n,r;let s=this._getTypeSize(e);if(e.size=(t=s?.size)!==null&&t!==void 0?t:0,e instanceof se&&e.format){let i=this._getTypeSize(e.format);e.stride=Math.max((n=i?.size)!==null&&n!==void 0?n:0,(r=i?.align)!==null&&r!==void 0?r:0),this._updateTypeInfo(e.format)}e instanceof re&&this._updateStructInfo(e)}_updateStructInfo(e){var t;let n=0,r=0,s=0,i=0;for(let o=0,l=e.members.length;o<l;++o){let c=e.members[o],u=this._getTypeSize(c);if(!u)continue;(t=this._getAlias(c.type.name))!==null&&t!==void 0||c.type;let h=u.align,b=u.size;n=this._roundUp(h,n+r),r=b,s=n,i=Math.max(i,h),c.offset=n,c.size=b,this._updateTypeInfo(c.type)}e.size=this._roundUp(i,s+r),e.align=i}_getTypeSize(e){var t,n;if(e==null)return null;let r=this._getAttributeNum(e.attributes,"size",0),s=this._getAttributeNum(e.attributes,"align",0);if(e instanceof ot&&(e=e.type),e instanceof W){let i=this._getAlias(e.name);i!==null&&(e=i)}{let i=Z._typeInfo[e.name];if(i!==void 0){let o=((t=e.format)===null||t===void 0?void 0:t.name)==="f16"?2:1;return new we(Math.max(s,i.align/o),Math.max(r,i.size/o))}}{let i=Z._typeInfo[e.name.substring(0,e.name.length-1)];if(i){let o=e.name[e.name.length-1]==="h"?2:1;return new we(Math.max(s,i.align/o),Math.max(r,i.size/o))}}if(e instanceof se){let i=e,o=8,l=8,c=this._getTypeSize(i.format);return c!==null&&(l=c.size,o=c.align),l=i.count*this._getAttributeNum((n=e?.attributes)!==null&&n!==void 0?n:null,"stride",this._roundUp(o,l)),r&&(l=r),new we(Math.max(s,o),Math.max(r,l))}if(e instanceof re){let i=0,o=0,l=0,c=0,u=0;for(let h of e.members){let b=this._getTypeSize(h.type);b!==null&&(i=Math.max(b.align,i),l=this._roundUp(b.align,l+c),c=b.size,u=l)}return o=this._roundUp(i,u+c),new we(Math.max(s,i),Math.max(r,o))}return null}_isUniformVar(e){return e instanceof ee&&e.storage=="uniform"}_isStorageVar(e){return e instanceof ee&&e.storage=="storage"}_isTextureVar(e){return e instanceof ee&&e.type!==null&&Z._textureTypes.indexOf(e.type.name)!=-1}_isSamplerVar(e){return e instanceof ee&&e.type!==null&&Z._samplerTypes.indexOf(e.type.name)!=-1}_getAttribute(e,t){let n=e;if(!n||!n.attributes)return null;let r=n.attributes;for(let s of r)if(s.name==t)return s;return null}_getAttributeNum(e,t,n){if(e===null)return n;for(let r of e)if(r.name==t){let s=r!==null&&r.value!==null?r.value:n;return s instanceof Array&&(s=s[0]),typeof s=="number"?s:typeof s=="string"?parseInt(s):n}return n}_roundUp(e,t){return Math.ceil(t/e)*e}};Z._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}},Z._textureTypes=f.any_texture_type.map(a=>a.name),Z._samplerTypes=f.sampler_type.map(a=>a.name);var We=class{constructor(e,t,n){this.name=e,this.value=t,this.node=n}clone(){return new We(this.name,this.value,this.node)}},ze=class{constructor(e){this.name=e.name,this.node=e}clone(){return new ze(this.node)}},qe=class{constructor(e){this.parent=null,this.variables=new Map,this.functions=new Map,this.currentFunctionName="",e&&(this.parent=e,this.currentFunctionName=e.currentFunctionName)}getVariable(e){var t;return this.variables.has(e)?(t=this.variables.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getVariable(e):null}getFunction(e){var t;return this.functions.has(e)?(t=this.functions.get(e))!==null&&t!==void 0?t:null:this.parent?this.parent.getFunction(e):null}createVariable(e,t,n){this.variables.set(e,new We(e,t,n??null))}setVariable(e,t,n){let r=this.getVariable(e);r!==null?r.value=t:this.createVariable(e,t,n)}getVariableValue(e){var t;let n=this.getVariable(e);return(t=n?.value)!==null&&t!==void 0?t:null}clone(){return new qe(this)}},on=class{evalExpression(e,t){return null}getTypeInfo(e){return null}getVariableName(e,t){return""}},an=class{constructor(e){this.exec=e}getTypeInfo(e){return this.exec.getTypeInfo(e)}All(e,t){let n=this.exec.evalExpression(e.args[0],t),r=!0;if(n instanceof p)return n.data.forEach(s=>{s||(r=!1)}),new d(r?1:0,this.getTypeInfo("bool"));throw new Error(`All() expects a vector argument. Line ${e.line}`)}Any(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=n.data.some(s=>s);return new d(r?1:0,this.getTypeInfo("bool"))}throw new Error(`Any() expects a vector argument. Line ${e.line}`)}Select(e,t){let n=this.exec.evalExpression(e.args[2],t);if(!(n instanceof d))throw new Error(`Select() expects a bool condition. Line ${e.line}`);return n.value?this.exec.evalExpression(e.args[1],t):this.exec.evalExpression(e.args[0],t)}ArrayLength(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.evalExpression(n,t);if(r instanceof D&&r.typeInfo.size===0){let s=r.typeInfo,i=r.buffer.byteLength/s.stride;return new d(i,this.getTypeInfo("u32"))}return new d(r.typeInfo.size,this.getTypeInfo("u32"))}Abs(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.abs(s)),n.typeInfo);let r=n;return new d(Math.abs(r.value),r.typeInfo)}Acos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acos(s)),n.typeInfo);let r=n;return new d(Math.acos(r.value),n.typeInfo)}Acosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.acosh(s)),n.typeInfo);let r=n;return new d(Math.acosh(r.value),n.typeInfo)}Asin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asin(s)),n.typeInfo);let r=n;return new d(Math.asin(r.value),n.typeInfo)}Asinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.asinh(s)),n.typeInfo);let r=n;return new d(Math.asinh(r.value),n.typeInfo)}Atan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atan(s)),n.typeInfo);let r=n;return new d(Math.atan(r.value),n.typeInfo)}Atanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.atanh(s)),n.typeInfo);let r=n;return new d(Math.atanh(r.value),n.typeInfo)}Atan2(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,l)=>Math.atan2(o,r.data[l])),n.typeInfo);let s=n,i=r;return new d(Math.atan2(s.value,i.value),n.typeInfo)}Ceil(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.ceil(s)),n.typeInfo);let r=n;return new d(Math.ceil(r.value),n.typeInfo)}_clamp(e,t,n){return Math.min(Math.max(e,t),n)}Clamp(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((c,u)=>this._clamp(c,r.data[u],s.data[u])),n.typeInfo);let i=n,o=r,l=s;return new d(this._clamp(i.value,o.value,l.value),n.typeInfo)}Cos(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cos(s)),n.typeInfo);let r=n;return new d(Math.cos(r.value),n.typeInfo)}Cosh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.cosh(s)),n.typeInfo);let r=n;return new d(Math.cos(r.value),n.typeInfo)}CountLeadingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.clz32(s)),n.typeInfo);let r=n;return new d(Math.clz32(r.value),n.typeInfo)}_countOneBits(e){let t=0;for(;e!==0;)1&e&&t++,e>>=1;return t}CountOneBits(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countOneBits(s)),n.typeInfo);let r=n;return new d(this._countOneBits(r.value),n.typeInfo)}_countTrailingZeros(e){if(e===0)return 32;let t=0;for(;!(1&e);)e>>=1,t++;return t}CountTrailingZeros(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._countTrailingZeros(s)),n.typeInfo);let r=n;return new d(this._countTrailingZeros(r.value),n.typeInfo)}Cross(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){if(n.data.length!==3||r.data.length!==3)return console.error(`Cross() expects 3D vectors. Line ${e.line}`),null;let s=n.data,i=r.data;return new p([s[1]*i[2]-i[1]*s[2],s[2]*i[0]-i[2]*s[0],s[0]*i[1]-i[0]*s[1]],n.typeInfo)}return console.error(`Cross() expects vector arguments. Line ${e.line}`),null}Degrees(e,t){let n=this.exec.evalExpression(e.args[0],t),r=180/Math.PI;return n instanceof p?new p(n.data.map(s=>s*r),n.typeInfo):new d(n.value*r,this.getTypeInfo("f32"))}Determinant(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof I){let r=n.data,s=n.typeInfo.getTypeName(),i=s.endsWith("h")?this.getTypeInfo("f16"):this.getTypeInfo("f32");if(s==="mat2x2"||s==="mat2x2f"||s==="mat2x2h")return new d(r[0]*r[3]-r[1]*r[2],i);if(s==="mat2x3"||s==="mat2x3f"||s==="mat2x3h")return new d(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),i);if(s==="mat2x4"||s==="mat2x4f"||s==="mat2x4h")console.error(`TODO: Determinant for ${s}`);else if(s==="mat3x2"||s==="mat3x2f"||s==="mat3x2h")console.error(`TODO: Determinant for ${s}`);else{if(s==="mat3x3"||s==="mat3x3f"||s==="mat3x3h")return new d(r[0]*(r[4]*r[8]-r[5]*r[7])-r[1]*(r[3]*r[8]-r[5]*r[6])+r[2]*(r[3]*r[7]-r[4]*r[6]),i);s==="mat3x4"||s==="mat3x4f"||s==="mat3x4h"||s==="mat4x2"||s==="mat4x2f"||s==="mat4x2h"||s==="mat4x3"||s==="mat4x3f"||s==="mat4x3h"?console.error(`TODO: Determinant for ${s}`):s!=="mat4x4"&&s!=="mat4x4f"&&s!=="mat4x4h"||console.error(`TODO: Determinant for ${s}`)}}return console.error(`Determinant expects a matrix argument. Line ${e.line}`),null}Distance(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let o=0;for(let l=0;l<n.data.length;++l)o+=(n.data[l]-r.data[l])*(n.data[l]-r.data[l]);return new d(Math.sqrt(o),this.getTypeInfo("f32"))}let s=n,i=r;return new d(Math.abs(s.value-i.value),n.typeInfo)}_dot(e,t){let n=0;for(let r=0;r<e.length;++r)n+=t[r]*e[r];return n}Dot(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);return n instanceof p&&r instanceof p?new d(this._dot(n.data,r.data),this.getTypeInfo("f32")):(console.error(`Dot() expects vector arguments. Line ${e.line}`),null)}Dot4U8Packed(e,t){return console.error(`TODO: dot4U8Packed. Line ${e.line}`),null}Dot4I8Packed(e,t){return console.error(`TODO: dot4I8Packed. Line ${e.line}`),null}Exp(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.exp(s)),n.typeInfo);let r=n;return new d(Math.exp(r.value),n.typeInfo)}Exp2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.pow(2,s)),n.typeInfo);let r=n;return new d(Math.pow(2,r.value),n.typeInfo)}ExtractBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(r.typeInfo.name!=="u32"&&r.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 offset argument. Line ${e.line}`),null;if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 count argument. Line ${e.line}`),null;let i=r.value,o=s.value;if(n instanceof p)return new p(n.data.map(c=>c>>i&(1<<o)-1),n.typeInfo);if(n.typeInfo.name!=="i32"&&n.typeInfo.name!=="x32")return console.error(`ExtractBits() expects an i32 argument. Line ${e.line}`),null;let l=n.value;return new d(l>>i&(1<<o)-1,this.getTypeInfo("i32"))}FaceForward(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p){let i=this._dot(r.data,s.data);return new p(i<0?Array.from(n.data):n.data.map(o=>-o),n.typeInfo)}return console.error(`FaceForward() expects vector arguments. Line ${e.line}`),null}_firstLeadingBit(e){return e===0?-1:31-Math.clz32(e)}FirstLeadingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstLeadingBit(s)),n.typeInfo);let r=n;return new d(this._firstLeadingBit(r.value),n.typeInfo)}_firstTrailingBit(e){return e===0?-1:Math.log2(e&-e)}FirstTrailingBit(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>this._firstTrailingBit(s)),n.typeInfo);let r=n;return new d(this._firstTrailingBit(r.value),n.typeInfo)}Floor(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.floor(s)),n.typeInfo);let r=n;return new d(Math.floor(r.value),n.typeInfo)}Fma(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return n.data.length!==r.data.length||n.data.length!==s.data.length?(console.error(`Fma() expects vectors of the same length. Line ${e.line}`),null):new p(n.data.map((c,u)=>c*r.data[u]+s.data[u]),n.typeInfo);let i=n,o=r,l=s;return new d(i.value*o.value+l.value,i.typeInfo)}Fract(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>s-Math.floor(s)),n.typeInfo);let r=n;return new d(r.value-Math.floor(r.value),n.typeInfo)}Frexp(e,t){return console.error(`TODO: frexp. Line ${e.line}`),null}InsertBits(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t),i=this.exec.evalExpression(e.args[3],t);if(s.typeInfo.name!=="u32"&&s.typeInfo.name!=="x32")return console.error(`InsertBits() expects an i32 offset argument. Line ${e.line}`),null;let o=s.value,l=(1<<i.value)-1<<o,c=~l;if(n instanceof p&&r instanceof p)return new p(n.data.map((b,y)=>b&c|r.data[y]<<o&l),n.typeInfo);let u=n.value,h=r.value;return new d(u&c|h<<o&l,n.typeInfo)}InverseSqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>1/Math.sqrt(s)),n.typeInfo);let r=n;return new d(1/Math.sqrt(r.value),n.typeInfo)}Ldexp(e,t){return console.error(`TODO: ldexp. Line ${e.line}`),null}Length(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let s=0;return n.data.forEach(i=>{s+=i*i}),new d(Math.sqrt(s),this.getTypeInfo("f32"))}let r=n;return new d(Math.abs(r.value),n.typeInfo)}Log(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log(s)),n.typeInfo);let r=n;return new d(Math.log(r.value),n.typeInfo)}Log2(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.log2(s)),n.typeInfo);let r=n;return new d(Math.log2(r.value),n.typeInfo)}Max(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,l)=>Math.max(o,r.data[l])),n.typeInfo);let s=n,i=r;return new d(Math.max(s.value,i.value),n.typeInfo)}Min(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,l)=>Math.min(o,r.data[l])),n.typeInfo);let s=n,i=r;return new d(Math.min(s.value,i.value),n.typeInfo)}Mix(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof p)return new p(n.data.map((l,c)=>n.data[c]*(1-s.data[c])+r.data[c]*s.data[c]),n.typeInfo);let i=r,o=s;return new d(n.value*(1-o.value)+i.value*o.value,n.typeInfo)}Modf(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((i,o)=>i%r.data[o]),n.typeInfo);let s=r;return new d(n.value%s.value,n.typeInfo)}Normalize(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p){let r=this.Length(e,t).value;return new p(n.data.map(s=>s/r),n.typeInfo)}return console.error(`Normalize() expects a vector argument. Line ${e.line}`),null}Pow(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p)return new p(n.data.map((o,l)=>Math.pow(o,r.data[l])),n.typeInfo);let s=n,i=r;return new d(Math.pow(s.value,i.value),n.typeInfo)}QuantizeToF16(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r),n.typeInfo):new d(n.value,n.typeInfo)}Radians(e,t){let n=this.exec.evalExpression(e.args[0],t);return n instanceof p?new p(n.data.map(r=>r*Math.PI/180),n.typeInfo):new d(n.value*Math.PI/180,this.getTypeInfo("f32"))}Reflect(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(n instanceof p&&r instanceof p){let s=this._dot(n.data,r.data);return new p(n.data.map((i,o)=>i-2*s*r.data[o]),n.typeInfo)}return console.error(`Reflect() expects vector arguments. Line ${e.line}`),null}Refract(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(n instanceof p&&r instanceof p&&s instanceof d){let i=this._dot(r.data,n.data);return new p(n.data.map((o,l)=>{let c=1-s.value*s.value*(1-i*i);if(c<0)return 0;let u=Math.sqrt(c);return s.value*o-(s.value*i+u)*r.data[l]}),n.typeInfo)}return console.error(`Refract() expects vector arguments and a scalar argument. Line ${e.line}`),null}ReverseBits(e,t){return console.error(`TODO: reverseBits. Line ${e.line}`),null}Round(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.round(s)),n.typeInfo);let r=n;return new d(Math.round(r.value),n.typeInfo)}Saturate(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.min(Math.max(s,0),1)),n.typeInfo);let r=n;return new d(Math.min(Math.max(r.value,0),1),n.typeInfo)}Sign(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sign(s)),n.typeInfo);let r=n;return new d(Math.sign(r.value),n.typeInfo)}Sin(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sin(s)),n.typeInfo);let r=n;return new d(Math.sin(r.value),n.typeInfo)}Sinh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sinh(s)),n.typeInfo);let r=n;return new d(Math.sinh(r.value),n.typeInfo)}_smoothstep(e,t,n){let r=Math.min(Math.max((n-e)/(t-e),0),1);return r*r*(3-2*r)}SmoothStep(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t),s=this.exec.evalExpression(e.args[2],t);if(s instanceof p&&n instanceof p&&r instanceof p)return new p(s.data.map((c,u)=>this._smoothstep(n.data[u],r.data[u],c)),s.typeInfo);let i=n,o=r,l=s;return new d(this._smoothstep(i.value,o.value,l.value),s.typeInfo)}Sqrt(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.sqrt(s)),n.typeInfo);let r=n;return new d(Math.sqrt(r.value),n.typeInfo)}Step(e,t){let n=this.exec.evalExpression(e.args[0],t),r=this.exec.evalExpression(e.args[1],t);if(r instanceof p&&n instanceof p)return new p(r.data.map((i,o)=>i<n.data[o]?0:1),r.typeInfo);let s=n;return new d(r.value<s.value?0:1,s.typeInfo)}Tan(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tan(s)),n.typeInfo);let r=n;return new d(Math.tan(r.value),n.typeInfo)}Tanh(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.tanh(s)),n.typeInfo);let r=n;return new d(Math.tanh(r.value),n.typeInfo)}_getTransposeType(e){let t=e.getTypeName();return t==="mat2x2f"||t==="mat2x2h"?e:t==="mat2x3f"?this.getTypeInfo("mat3x2f"):t==="mat2x3h"?this.getTypeInfo("mat3x2h"):t==="mat2x4f"?this.getTypeInfo("mat4x2f"):t==="mat2x4h"?this.getTypeInfo("mat4x2h"):t==="mat3x2f"?this.getTypeInfo("mat2x3f"):t==="mat3x2h"?this.getTypeInfo("mat2x3h"):t==="mat3x3f"||t==="mat3x3h"?e:t==="mat3x4f"?this.getTypeInfo("mat4x3f"):t==="mat3x4h"?this.getTypeInfo("mat4x3h"):t==="mat4x2f"?this.getTypeInfo("mat2x4f"):t==="mat4x2h"?this.getTypeInfo("mat2x4h"):t==="mat4x3f"?this.getTypeInfo("mat3x4f"):t==="mat4x3h"?this.getTypeInfo("mat3x4h"):(t==="mat4x4f"||t==="mat4x4h"||console.error(`Invalid matrix type ${t}`),e)}Transpose(e,t){let n=this.exec.evalExpression(e.args[0],t);if(!(n instanceof I))return console.error(`Transpose() expects a matrix argument. Line ${e.line}`),null;let r=this._getTransposeType(n.typeInfo);if(n.typeInfo.name==="mat2x2"||n.typeInfo.name==="mat2x2f"||n.typeInfo.name==="mat2x2h"){let s=n.data;return new I([s[0],s[2],s[1],s[3]],r)}if(n.typeInfo.name==="mat2x3"||n.typeInfo.name==="mat2x3f"||n.typeInfo.name==="mat2x3h"){let s=n.data;return new I([s[0],s[3],s[6],s[1],s[4],s[7]],r)}if(n.typeInfo.name==="mat2x4"||n.typeInfo.name==="mat2x4f"||n.typeInfo.name==="mat2x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13]],r)}if(n.typeInfo.name==="mat3x2"||n.typeInfo.name==="mat3x2f"||n.typeInfo.name==="mat3x2h"){let s=n.data;return new I([s[0],s[3],s[1],s[4],s[2],s[5]],r)}if(n.typeInfo.name==="mat3x3"||n.typeInfo.name==="mat3x3f"||n.typeInfo.name==="mat3x3h"){let s=n.data;return new I([s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]],r)}if(n.typeInfo.name==="mat3x4"||n.typeInfo.name==="mat3x4f"||n.typeInfo.name==="mat3x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14]],r)}if(n.typeInfo.name==="mat4x2"||n.typeInfo.name==="mat4x2f"||n.typeInfo.name==="mat4x2h"){let s=n.data;return new I([s[0],s[4],s[1],s[5],s[2],s[6]],r)}if(n.typeInfo.name==="mat4x3"||n.typeInfo.name==="mat4x3f"||n.typeInfo.name==="mat4x3h"){let s=n.data;return new I([s[0],s[4],s[8],s[1],s[5],s[9],s[2],s[6],s[10]],r)}if(n.typeInfo.name==="mat4x4"||n.typeInfo.name==="mat4x4f"||n.typeInfo.name==="mat4x4h"){let s=n.data;return new I([s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]],r)}return console.error(`Invalid matrix type ${n.typeInfo.name}`),null}Trunc(e,t){let n=this.exec.evalExpression(e.args[0],t);if(n instanceof p)return new p(n.data.map(s=>Math.trunc(s)),n.typeInfo);let r=n;return new d(Math.trunc(r.value),n.typeInfo)}Dpdx(e,t){return console.error(`TODO: dpdx. Line ${e.line}`),null}DpdxCoarse(e,t){return console.error(`TODO: dpdxCoarse. Line ${e.line}`),null}DpdxFine(e,t){return console.error("TODO: dpdxFine"),null}Dpdy(e,t){return console.error("TODO: dpdy"),null}DpdyCoarse(e,t){return console.error("TODO: dpdyCoarse"),null}DpdyFine(e,t){return console.error("TODO: dpdyFine"),null}Fwidth(e,t){return console.error("TODO: fwidth"),null}FwidthCoarse(e,t){return console.error("TODO: fwidthCoarse"),null}FwidthFine(e,t){return console.error("TODO: fwidthFine"),null}TextureDimensions(e,t){let n=e.args[0],r=e.args.length>1?this.exec.evalExpression(e.args[1],t).value:0;if(n instanceof G){let s=n.name,i=t.getVariableValue(s);if(i instanceof J){if(r<0||r>=i.mipLevelCount)return console.error(`Invalid mip level for textureDimensions. Line ${e.line}`),null;let o=i.getMipLevelSize(r),l=i.dimension;return l==="1d"?new d(o[0],this.getTypeInfo("u32")):l==="3d"?new p(o,this.getTypeInfo("vec3u")):l==="2d"?new p(o.slice(0,2),this.getTypeInfo("vec2u")):(console.error(`Invalid texture dimension ${l} not found. Line ${e.line}`),null)}return console.error(`Texture ${s} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureDimensions. Line ${e.line}`),null}TextureGather(e,t){return console.error("TODO: textureGather"),null}TextureGatherCompare(e,t){return console.error("TODO: textureGatherCompare"),null}TextureLoad(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length>2?this.exec.evalExpression(e.args[2],t).value:0;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureLoad. Line ${e.line}`),null;if(n instanceof G){let i=n.name,o=t.getVariableValue(i);if(o instanceof J){let l=Math.floor(r.data[0]),c=Math.floor(r.data[1]);if(l<0||l>=o.width||c<0||c>=o.height)return console.error(`Texture ${i} out of bounds. Line ${e.line}`),null;let u=o.getPixel(l,c,0,s);return u===null?(console.error(`Invalid texture format for textureLoad. Line ${e.line}`),null):new p(u,this.getTypeInfo("vec4f"))}return console.error(`Texture ${i} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureLoad. Line ${e.line}`),null}TextureNumLayers(e,t){let n=e.args[0];if(n instanceof G){let r=n.name,s=t.getVariableValue(r);return s instanceof J?new d(s.depthOrArrayLayers,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLayers. Line ${e.line}`),null}TextureNumLevels(e,t){let n=e.args[0];if(n instanceof G){let r=n.name,s=t.getVariableValue(r);return s instanceof J?new d(s.mipLevelCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumLevels. Line ${e.line}`),null}TextureNumSamples(e,t){let n=e.args[0];if(n instanceof G){let r=n.name,s=t.getVariableValue(r);return s instanceof J?new d(s.sampleCount,this.getTypeInfo("u32")):(console.error(`Texture ${r} not found. Line ${e.line}`),null)}return console.error(`Invalid texture argument for textureNumSamples. Line ${e.line}`),null}TextureSample(e,t){return console.error("TODO: textureSample"),null}TextureSampleBias(e,t){return console.error("TODO: textureSampleBias"),null}TextureSampleCompare(e,t){return console.error("TODO: textureSampleCompare"),null}TextureSampleCompareLevel(e,t){return console.error("TODO: textureSampleCompareLevel"),null}TextureSampleGrad(e,t){return console.error("TODO: textureSampleGrad"),null}TextureSampleLevel(e,t){return console.error("TODO: textureSampleLevel"),null}TextureSampleBaseClampToEdge(e,t){return console.error("TODO: textureSampleBaseClampToEdge"),null}TextureStore(e,t){let n=e.args[0],r=this.exec.evalExpression(e.args[1],t),s=e.args.length===4?this.exec.evalExpression(e.args[2],t).value:0,i=e.args.length===4?this.exec.evalExpression(e.args[3],t).data:this.exec.evalExpression(e.args[2],t).data;if(i.length!==4)return console.error(`Invalid value argument for textureStore. Line ${e.line}`),null;if(!(r instanceof p)||r.data.length!==2)return console.error(`Invalid UV argument for textureStore. Line ${e.line}`),null;if(n instanceof G){let o=n.name,l=t.getVariableValue(o);if(l instanceof J){let c=l.getMipLevelSize(0),u=Math.floor(r.data[0]),h=Math.floor(r.data[1]);return u<0||u>=c[0]||h<0||h>=c[1]?(console.error(`Texture ${o} out of bounds. Line ${e.line}`),null):(l.setPixel(u,h,0,s,Array.from(i)),null)}return console.error(`Texture ${o} not found. Line ${e.line}`),null}return console.error(`Invalid texture argument for textureStore. Line ${e.line}`),null}AtomicLoad(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t);return t.getVariable(r).value.getSubData(this.exec,n.postfix,t)}AtomicStore(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t);return l instanceof d&&o instanceof d&&(l.value=o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),null}AtomicAdd(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value+=o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicSub(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value-=o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicMax(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=Math.max(l.value,o.value)),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicMin(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=Math.min(l.value,o.value)),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicAnd(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=l.value&o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicOr(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=l.value|o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicXor(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=l.value^o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicExchange(e,t){let n=e.args[0];n instanceof M&&(n=n.right);let r=this.exec.getVariableName(n,t),s=t.getVariable(r),i=e.args[1],o=this.exec.evalExpression(i,t),l=s.value.getSubData(this.exec,n.postfix,t),c=new d(l.value,l.typeInfo);return l instanceof d&&o instanceof d&&(l.value=o.value),s.value instanceof D&&s.value.setDataValue(this.exec,l,n.postfix,t),c}AtomicCompareExchangeWeak(e,t){return console.error("TODO: atomicCompareExchangeWeak"),null}Pack4x8snorm(e,t){return console.error("TODO: pack4x8snorm"),null}Pack4x8unorm(e,t){return console.error("TODO: pack4x8unorm"),null}Pack4xI8(e,t){return console.error("TODO: pack4xI8"),null}Pack4xU8(e,t){return console.error("TODO: pack4xU8"),null}Pack4x8Clamp(e,t){return console.error("TODO: pack4x8Clamp"),null}Pack4xU8Clamp(e,t){return console.error("TODO: pack4xU8Clamp"),null}Pack2x16snorm(e,t){return console.error("TODO: pack2x16snorm"),null}Pack2x16unorm(e,t){return console.error("TODO: pack2x16unorm"),null}Pack2x16float(e,t){return console.error("TODO: pack2x16float"),null}Unpack4x8snorm(e,t){return console.error("TODO: unpack4x8snorm"),null}Unpack4x8unorm(e,t){return console.error("TODO: unpack4x8unorm"),null}Unpack4xI8(e,t){return console.error("TODO: unpack4xI8"),null}Unpack4xU8(e,t){return console.error("TODO: unpack4xU8"),null}Unpack2x16snorm(e,t){return console.error("TODO: unpack2x16snorm"),null}Unpack2x16unorm(e,t){return console.error("TODO: unpack2x16unorm"),null}Unpack2x16float(e,t){return console.error("TODO: unpack2x16float"),null}StorageBarrier(e,t){return null}TextureBarrier(e,t){return null}WorkgroupBarrier(e,t){return null}WorkgroupUniformLoad(e,t){return null}SubgroupAdd(e,t){return console.error("TODO: subgroupAdd"),null}SubgroupExclusiveAdd(e,t){return console.error("TODO: subgroupExclusiveAdd"),null}SubgroupInclusiveAdd(e,t){return console.error("TODO: subgroupInclusiveAdd"),null}SubgroupAll(e,t){return console.error("TODO: subgroupAll"),null}SubgroupAnd(e,t){return console.error("TODO: subgroupAnd"),null}SubgroupAny(e,t){return console.error("TODO: subgroupAny"),null}SubgroupBallot(e,t){return console.error("TODO: subgroupBallot"),null}SubgroupBroadcast(e,t){return console.error("TODO: subgroupBroadcast"),null}SubgroupBroadcastFirst(e,t){return console.error("TODO: subgroupBroadcastFirst"),null}SubgroupElect(e,t){return console.error("TODO: subgroupElect"),null}SubgroupMax(e,t){return console.error("TODO: subgroupMax"),null}SubgroupMin(e,t){return console.error("TODO: subgroupMin"),null}SubgroupMul(e,t){return console.error("TODO: subgroupMul"),null}SubgroupExclusiveMul(e,t){return console.error("TODO: subgroupExclusiveMul"),null}SubgroupInclusiveMul(e,t){return console.error("TODO: subgroupInclusiveMul"),null}SubgroupOr(e,t){return console.error("TODO: subgroupOr"),null}SubgroupShuffle(e,t){return console.error("TODO: subgroupShuffle"),null}SubgroupShuffleDown(e,t){return console.error("TODO: subgroupShuffleDown"),null}SubgroupShuffleUp(e,t){return console.error("TODO: subgroupShuffleUp"),null}SubgroupShuffleXor(e,t){return console.error("TODO: subgroupShuffleXor"),null}SubgroupXor(e,t){return console.error("TODO: subgroupXor"),null}QuadBroadcast(e,t){return console.error("TODO: quadBroadcast"),null}QuadSwapDiagonal(e,t){return console.error("TODO: quadSwapDiagonal"),null}QuadSwapX(e,t){return console.error("TODO: quadSwapX"),null}QuadSwapY(e,t){return console.error("TODO: quadSwapY"),null}},zt={vec2:2,vec2f:2,vec2i:2,vec2u:2,vec2b:2,vec2h:2,vec3:3,vec3f:3,vec3i:3,vec3u:3,vec3b:3,vec3h:3,vec4:4,vec4f:4,vec4i:4,vec4u:4,vec4b:4,vec4h:4},H={mat2x2:[2,2,4],mat2x2f:[2,2,4],mat2x2h:[2,2,4],mat2x3:[2,3,6],mat2x3f:[2,3,6],mat2x3h:[2,3,6],mat2x4:[2,4,8],mat2x4f:[2,4,8],mat2x4h:[2,4,8],mat3x2:[3,2,6],mat3x2f:[3,2,6],mat3x2h:[3,2,6],mat3x3:[3,3,9],mat3x3f:[3,3,9],mat3x3h:[3,3,9],mat3x4:[3,4,12],mat3x4f:[3,4,12],mat3x4h:[3,4,12],mat4x2:[4,2,8],mat4x2f:[4,2,8],mat4x2h:[4,2,8],mat4x3:[4,3,12],mat4x3f:[4,3,12],mat4x3h:[4,3,12],mat4x4:[4,4,16],mat4x4f:[4,4,16],mat4x4h:[4,4,16]},V=class extends on{constructor(e,t){var n;super(),this.ast=e??[],this.reflection=new Z,this.reflection.updateAST(this.ast),this.context=(n=t?.clone())!==null&&n!==void 0?n:new qe,this.builtins=new an(this),this.typeInfo={bool:this.getTypeInfo(x.bool),i32:this.getTypeInfo(x.i32),u32:this.getTypeInfo(x.u32),f32:this.getTypeInfo(x.f32),f16:this.getTypeInfo(x.f16),vec2f:this.getTypeInfo(g.vec2f),vec2u:this.getTypeInfo(g.vec2u),vec2i:this.getTypeInfo(g.vec2i),vec2h:this.getTypeInfo(g.vec2h),vec3f:this.getTypeInfo(g.vec3f),vec3u:this.getTypeInfo(g.vec3u),vec3i:this.getTypeInfo(g.vec3i),vec3h:this.getTypeInfo(g.vec3h),vec4f:this.getTypeInfo(g.vec4f),vec4u:this.getTypeInfo(g.vec4u),vec4i:this.getTypeInfo(g.vec4i),vec4h:this.getTypeInfo(g.vec4h),mat2x2f:this.getTypeInfo(g.mat2x2f),mat2x3f:this.getTypeInfo(g.mat2x3f),mat2x4f:this.getTypeInfo(g.mat2x4f),mat3x2f:this.getTypeInfo(g.mat3x2f),mat3x3f:this.getTypeInfo(g.mat3x3f),mat3x4f:this.getTypeInfo(g.mat3x4f),mat4x2f:this.getTypeInfo(g.mat4x2f),mat4x3f:this.getTypeInfo(g.mat4x3f),mat4x4f:this.getTypeInfo(g.mat4x4f)}}getVariableValue(e){var t,n;let r=(n=(t=this.context.getVariable(e))===null||t===void 0?void 0:t.value)!==null&&n!==void 0?n:null;if(r===null)return null;if(r instanceof d)return r.value;if(r instanceof p||r instanceof I)return Array.from(r.data);if(r instanceof D&&r.typeInfo instanceof se){if(r.typeInfo.format.name==="u32")return Array.from(new Uint32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="i32")return Array.from(new Int32Array(r.buffer,r.offset,r.typeInfo.count));if(r.typeInfo.format.name==="f32")return Array.from(new Float32Array(r.buffer,r.offset,r.typeInfo.count))}return console.error(`Unsupported return variable type ${r.typeInfo.name}`),null}execute(e){(e=e??{}).constants&&this._setOverrides(e.constants,this.context),this._execStatements(this.ast,this.context)}dispatchWorkgroups(e,t,n,r){let s=this.context.clone();(r=r??{}).constants&&this._setOverrides(r.constants,s),this._execStatements(this.ast,s);let i=s.getFunction(e);if(!i)return void console.error(`Function ${e} not found`);if(typeof t=="number")t=[t,1,1];else{if(t.length===0)return void console.error("Invalid dispatch count");t.length===1?t=[t[0],1,1]:t.length===2?t=[t[0],t[1],1]:t.length>3&&(t=[t[0],t[1],t[2]])}let o=t[0],l=t[1],c=t[2],u=this.getTypeInfo("vec3u");s.setVariable("@num_workgroups",new p(t,u));for(let h in n)for(let b in n[h]){let y=n[h][b];s.variables.forEach(S=>{var E;let T=S.node;if(T?.attributes){let L=null,P=null;for(let k of T.attributes)k.name==="binding"?L=k.value:k.name==="group"&&(P=k.value);if(b==L&&h==P)if(y.texture!==void 0&&y.descriptor!==void 0){let k=new J(y.texture,this.getTypeInfo(T.type),y.descriptor,(E=y.texture.view)!==null&&E!==void 0?E:null);S.value=k}else y.uniform!==void 0?S.value=new D(y.uniform,this.getTypeInfo(T.type)):S.value=new D(y,this.getTypeInfo(T.type))}})}for(let h=0;h<c;++h)for(let b=0;b<l;++b)for(let y=0;y<o;++y)s.setVariable("@workgroup_id",new p([y,b,h],this.getTypeInfo("vec3u"))),this._dispatchWorkgroup(i,[y,b,h],s)}execStatement(e,t){if(e instanceof dt)return this.evalExpression(e.value,t);if(e instanceof _t){if(e.condition){let n=this.evalExpression(e.condition,t);if(!(n instanceof d))throw new Error("Invalid break-if condition");if(!n.value)return null}return V._breakObj}if(e instanceof gt)return V._continueObj;if(e instanceof me)this._let(e,t);else if(e instanceof ee)this._var(e,t);else if(e instanceof ke)this._const(e,t);else if(e instanceof ge)this._function(e,t);else{if(e instanceof pt)return this._if(e,t);if(e instanceof ht)return this._switch(e,t);if(e instanceof lt)return this._for(e,t);if(e instanceof at)return this._while(e,t);if(e instanceof ft)return this._loop(e,t);if(e instanceof Be){let n=t.clone();return n.currentFunctionName=t.currentFunctionName,this._execStatements(e.body,n)}if(e instanceof ut)this._assign(e,t);else if(e instanceof ct)this._increment(e,t);else{if(e instanceof Y)return null;if(e instanceof Ve){let n=e.name;t.getVariable(n)===null&&t.setVariable(n,new d(0,this.getTypeInfo("u32")))}else if(e instanceof Ue)this._call(e,t);else{if(e instanceof mt||e instanceof $e)return null;console.error("Invalid statement type.",e,`Line ${e.line}`)}}}return null}evalExpression(e,t){return e instanceof j?this._evalBinaryOp(e,t):e instanceof R?this._evalLiteral(e,t):e instanceof G?this._evalVariable(e,t):e instanceof He?this._evalCall(e,t):e instanceof K?this._evalCreate(e,t):e instanceof bt?this._evalConst(e,t):e instanceof xt?this._evalBitcast(e,t):e instanceof M?this._evalUnaryOp(e,t):(console.error("Invalid expression type",e,`Line ${e.line}`),null)}getTypeInfo(e){var t;if(e instanceof x){let r=this.reflection.getTypeInfo(e);if(r!==null)return r}let n=(t=this.typeInfo[e])!==null&&t!==void 0?t:null;return n!==null||(n=this.reflection.getTypeInfoByName(e)),n}_setOverrides(e,t){for(let n in e){let r=e[n],s=this.reflection.getOverrideInfo(n);s!==null?(s.type===null&&(s.type=this.getTypeInfo("u32")),s.type.name==="u32"||s.type.name==="i32"||s.type.name==="f32"||s.type.name==="f16"?t.setVariable(n,new d(r,s.type)):s.type.name==="bool"?t.setVariable(n,new d(r?1:0,s.type)):s.type.name==="vec2"||s.type.name==="vec3"||s.type.name==="vec4"||s.type.name==="vec2f"||s.type.name==="vec3f"||s.type.name==="vec4f"||s.type.name==="vec2i"||s.type.name==="vec3i"||s.type.name==="vec4i"||s.type.name==="vec2u"||s.type.name==="vec3u"||s.type.name==="vec4u"||s.type.name==="vec2h"||s.type.name==="vec3h"||s.type.name==="vec4h"?t.setVariable(n,new p(r,s.type)):console.error(`Invalid constant type for ${n}`)):console.error(`Override ${n} does not exist in the shader.`)}}_dispatchWorkgroup(e,t,n){let r=[1,1,1];for(let u of e.node.attributes)if(u.name==="workgroup_size"){if(u.value.length>0){let h=n.getVariableValue(u.value[0]);r[0]=h instanceof d?h.value:parseInt(u.value[0])}if(u.value.length>1){let h=n.getVariableValue(u.value[1]);r[1]=h instanceof d?h.value:parseInt(u.value[1])}if(u.value.length>2){let h=n.getVariableValue(u.value[2]);r[2]=h instanceof d?h.value:parseInt(u.value[2])}}let s=this.getTypeInfo("vec3u"),i=this.getTypeInfo("u32");n.setVariable("@workgroup_size",new p(r,s));let o=r[0],l=r[1],c=r[2];for(let u=0,h=0;u<c;++u)for(let b=0;b<l;++b)for(let y=0;y<o;++y,++h){let S=[y,b,u],E=[y+t[0]*r[0],b+t[1]*r[1],u+t[2]*r[2]];n.setVariable("@local_invocation_id",new p(S,s)),n.setVariable("@global_invocation_id",new p(E,s)),n.setVariable("@local_invocation_index",new d(h,i)),this._dispatchExec(e,n)}}_dispatchExec(e,t){for(let n of e.node.args)for(let r of n.attributes)if(r.name==="builtin"){let s=`@${r.value}`,i=t.getVariable(s);i!==void 0&&t.variables.set(n.name,i)}this._execStatements(e.node.body,t)}getVariableName(e,t){for(;e instanceof M;)e=e.right;return e instanceof G?e.name:(console.error("Unknown variable type",e,"Line",e.line),null)}_execStatements(e,t){for(let n of e){if(n instanceof Array){let s=t.clone(),i=this._execStatements(n,s);if(i)return i;continue}let r=this.execStatement(n,t);if(r)return r}return null}_call(e,t){let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(r){for(let s=0;s<r.node.args.length;++s){let i=r.node.args[s],o=this.evalExpression(e.args[s],n);n.setVariable(i.name,o,i)}this._execStatements(r.node.body,n)}else e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)&&this._evalCreate(e,t)}_increment(e,t){let n=this.getVariableName(e.variable,t),r=t.getVariable(n);r?e.operator==="++"?r.value instanceof d?r.value.value++:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):e.operator==="--"?r.value instanceof d?r.value.value--:console.error(`Variable ${n} is not a scalar. Line ${e.line}`):console.error(`Unknown increment operator ${e.operator}. Line ${e.line}`):console.error(`Variable ${n} not found. Line ${e.line}`)}_getVariableData(e,t){if(e instanceof G){let n=this.getVariableName(e,t),r=t.getVariable(n);return r===null?(console.error(`Variable ${n} not found. Line ${e.line}`),null):r.value.getSubData(this,e.postfix,t)}if(e instanceof M){if(e.operator==="*"){let n=this._getVariableData(e.right,t);return n instanceof ue?n.reference.getSubData(this,e.postfix,t):(console.error(`Variable ${e.right} is not a pointer. Line ${e.line}`),null)}if(e.operator==="&"){let n=this._getVariableData(e.right,t);return new ue(n)}}return null}_assign(e,t){let n=null,r="<var>",s=null;if(e.variable instanceof M){let l=this._getVariableData(e.variable,t),c=this.evalExpression(e.value,t),u=e.operator;if(u==="="){if(l instanceof d||l instanceof p||l instanceof I){if(c instanceof d||c instanceof p||c instanceof I&&l.data.length===c.data.length)return void l.data.set(c.data);console.error(`Invalid assignment. Line ${e.line}`)}else if(l instanceof D&&c instanceof D&&l.buffer.byteLength-l.offset>=c.buffer.byteLength-c.offset)return void(l.buffer.byteLength%4==0?new Uint32Array(l.buffer,l.offset,l.typeInfo.size/4).set(new Uint32Array(c.buffer,c.offset,c.typeInfo.size/4)):new Uint8Array(l.buffer,l.offset,l.typeInfo.size).set(new Uint8Array(c.buffer,c.offset,c.typeInfo.size)));return console.error(`Invalid assignment. Line ${e.line}`),null}if(u==="+=")return l instanceof d||l instanceof p||l instanceof I?c instanceof d||c instanceof p||c instanceof I?void l.data.set(c.data.map((h,b)=>l.data[b]+h)):void console.error(`Invalid assignment . Line ${e.line}`):void console.error(`Invalid assignment. Line ${e.line}`);if(u==="-=")return(l instanceof d||l instanceof p||l instanceof I)&&(c instanceof d||c instanceof p||c instanceof I)?void l.data.set(c.data.map((h,b)=>l.data[b]-h)):void console.error(`Invalid assignment. Line ${e.line}`)}if(e.variable instanceof M){if(e.variable.operator==="*"){r=this.getVariableName(e.variable.right,t);let l=t.getVariable(r);if(!(l&&l.value instanceof ue))return void console.error(`Variable ${r} is not a pointer. Line ${e.line}`);n=l.value.reference;let c=e.variable.postfix;if(!c){let u=e.variable.right;for(;u instanceof M;){if(u.postfix){c=u.postfix;break}u=u.right}}c&&(n=n.getSubData(this,c,t))}}else{s=e.variable.postfix,r=this.getVariableName(e.variable,t);let l=t.getVariable(r);if(l===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);n=l.value}if(n instanceof ue&&(n=n.reference),n===null)return void console.error(`Variable ${r} not found. Line ${e.line}`);let i=this.evalExpression(e.value,t),o=e.operator;if(o==="=")if(n instanceof D)n.setDataValue(this,i,s,t);else if(s){if(!(n instanceof p||n instanceof I))return void console.error(`Variable ${r} is not a vector or matrix. Line ${e.line}`);if(s instanceof fe){let l=this.evalExpression(s.index,t).value;if(n instanceof p){if(!(i instanceof d))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[l]=i.value}else{if(!(n instanceof I))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let c=this.evalExpression(s.index,t).value;if(c<0)return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(i instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);{let u=n.typeInfo.getTypeName();if(u==="mat2x2"||u==="mat2x2f"||u==="mat2x2h"){if(!(c<2&&i.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=i.data[0],n.data[2*c+1]=i.data[1]}else if(u==="mat2x3"||u==="mat2x3f"||u==="mat2x3h"){if(!(c<2&&i.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=i.data[0],n.data[3*c+1]=i.data[1],n.data[3*c+2]=i.data[2]}else if(u==="mat2x4"||u==="mat2x4f"||u==="mat2x4h"){if(!(c<2&&i.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=i.data[0],n.data[4*c+1]=i.data[1],n.data[4*c+2]=i.data[2],n.data[4*c+3]=i.data[3]}else if(u==="mat3x2"||u==="mat3x2f"||u==="mat3x2h"){if(!(c<3&&i.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=i.data[0],n.data[2*c+1]=i.data[1]}else if(u==="mat3x3"||u==="mat3x3f"||u==="mat3x3h"){if(!(c<3&&i.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=i.data[0],n.data[3*c+1]=i.data[1],n.data[3*c+2]=i.data[2]}else if(u==="mat3x4"||u==="mat3x4f"||u==="mat3x4h"){if(!(c<3&&i.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=i.data[0],n.data[4*c+1]=i.data[1],n.data[4*c+2]=i.data[2],n.data[4*c+3]=i.data[3]}else if(u==="mat4x2"||u==="mat4x2f"||u==="mat4x2h"){if(!(c<4&&i.data.length===2))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[2*c]=i.data[0],n.data[2*c+1]=i.data[1]}else if(u==="mat4x3"||u==="mat4x3f"||u==="mat4x3h"){if(!(c<4&&i.data.length===3))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[3*c]=i.data[0],n.data[3*c+1]=i.data[1],n.data[3*c+2]=i.data[2]}else{if(u!=="mat4x4"&&u!=="mat4x4f"&&u!=="mat4x4h")return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(!(c<4&&i.data.length===4))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);n.data[4*c]=i.data[0],n.data[4*c+1]=i.data[1],n.data[4*c+2]=i.data[2],n.data[4*c+3]=i.data[3]}}}}}else if(s instanceof ae){let l=s.value;if(!(n instanceof p))return void console.error(`Invalid assignment to ${l}. Variable ${r} is not a vector. Line ${e.line}`);if(i instanceof d){if(l.length>1)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);if(l==="x")n.data[0]=i.value;else if(l==="y"){if(n.data.length<2)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[1]=i.value}else if(l==="z"){if(n.data.length<3)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[2]=i.value}else if(l==="w"){if(n.data.length<4)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);n.data[3]=i.value}}else{if(!(i instanceof p))return void console.error(`Invalid assignment to ${r}. Line ${e.line}`);if(l.length!==i.data.length)return void console.error(`Invalid assignment to ${l} for variable ${r}. Line ${e.line}`);for(let c=0;c<l.length;++c){let u=l[c];if(u==="x"||u==="r")n.data[0]=i.data[c];else if(u==="y"||u==="g"){if(i.data.length<2)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[1]=i.data[c]}else if(u==="z"||u==="b"){if(i.data.length<3)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[2]=i.data[c]}else{if(u!=="w"&&u!=="a")return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);if(i.data.length<4)return void console.error(`Invalid assignment to ${u} for variable ${r}. Line ${e.line}`);n.data[3]=i.data[c]}}}}}else n instanceof d&&i instanceof d?n.value=i.value:n instanceof p&&i instanceof p||n instanceof I&&i instanceof I?n.data.set(i.data):console.error(`Invalid assignment to ${r}. Line ${e.line}`);else{let l=n.getSubData(this,s,t);if(l instanceof p&&i instanceof d){let c=l.data,u=i.value;if(o==="+=")for(let h=0;h<c.length;++h)c[h]+=u;else if(o==="-=")for(let h=0;h<c.length;++h)c[h]-=u;else if(o==="*=")for(let h=0;h<c.length;++h)c[h]*=u;else if(o==="/=")for(let h=0;h<c.length;++h)c[h]/=u;else if(o==="%=")for(let h=0;h<c.length;++h)c[h]%=u;else if(o==="&=")for(let h=0;h<c.length;++h)c[h]&=u;else if(o==="|=")for(let h=0;h<c.length;++h)c[h]|=u;else if(o==="^=")for(let h=0;h<c.length;++h)c[h]^=u;else if(o==="<<=")for(let h=0;h<c.length;++h)c[h]<<=u;else if(o===">>=")for(let h=0;h<c.length;++h)c[h]>>=u;else console.error(`Invalid operator ${o}. Line ${e.line}`)}else if(l instanceof p&&i instanceof p){let c=l.data,u=i.data;if(c.length!==u.length)return void console.error(`Vector length mismatch. Line ${e.line}`);if(o==="+=")for(let h=0;h<c.length;++h)c[h]+=u[h];else if(o==="-=")for(let h=0;h<c.length;++h)c[h]-=u[h];else if(o==="*=")for(let h=0;h<c.length;++h)c[h]*=u[h];else if(o==="/=")for(let h=0;h<c.length;++h)c[h]/=u[h];else if(o==="%=")for(let h=0;h<c.length;++h)c[h]%=u[h];else if(o==="&=")for(let h=0;h<c.length;++h)c[h]&=u[h];else if(o==="|=")for(let h=0;h<c.length;++h)c[h]|=u[h];else if(o==="^=")for(let h=0;h<c.length;++h)c[h]^=u[h];else if(o==="<<=")for(let h=0;h<c.length;++h)c[h]<<=u[h];else if(o===">>=")for(let h=0;h<c.length;++h)c[h]>>=u[h];else console.error(`Invalid operator ${o}. Line ${e.line}`)}else{if(!(l instanceof d&&i instanceof d))return void console.error(`Invalid type for ${e.operator} operator. Line ${e.line}`);o==="+="?l.value+=i.value:o==="-="?l.value-=i.value:o==="*="?l.value*=i.value:o==="/="?l.value/=i.value:o==="%="?l.value%=i.value:o==="&="?l.value&=i.value:o==="|="?l.value|=i.value:o==="^="?l.value^=i.value:o==="<<="?l.value<<=i.value:o===">>="?l.value>>=i.value:console.error(`Invalid operator ${o}. Line ${e.line}`)}n instanceof D&&n.setDataValue(this,l,s,t)}}_function(e,t){let n=new ze(e);t.functions.set(e.name,n)}_const(e,t){let n=null;e.value!==null&&(n=this.evalExpression(e.value,t)),t.createVariable(e.name,n,e)}_let(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof M||(n=n.clone())}else{let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||r==="array"){let s=new K(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_var(e,t){let n=null;if(e.value!==null){if(n=this.evalExpression(e.value,t),n===null)return void console.error(`Invalid value for variable ${e.name}. Line ${e.line}`);e.value instanceof M||(n=n.clone())}else{if(e.type===null)return void console.error(`Variable ${e.name} has no type. Line ${e.line}`);let r=e.type.name;if(r==="f32"||r==="i32"||r==="u32"||r==="bool"||r==="f16"||r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2b"||r==="vec3b"||r==="vec4b"||r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"||e.type instanceof _e||e.type instanceof Y||e.type instanceof g){let s=new K(e.type,[]);n=this._evalCreate(s,t)}}t.createVariable(e.name,n,e)}_switch(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;let r=null;for(let s of e.cases)if(s instanceof kt)for(let i of s.selectors){if(i instanceof Ie){r=s;continue}let o=this.evalExpression(i,t);if(!(o instanceof d))return console.error(`Invalid case selector. Line ${e.line}`),null;if(o.value===n.value)return this._execStatements(s.body,t)}else s instanceof It&&(r=s);return r?this._execStatements(r.body,t):null}_if(e,t){t=t.clone();let n=this.evalExpression(e.condition,t);if(!(n instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;if(n.value)return this._execStatements(e.body,t);for(let r of e.elseif){let s=this.evalExpression(r.condition,t);if(!(s instanceof d))return console.error(`Invalid if condition. Line ${e.line}`),null;if(s.value)return this._execStatements(r.body,t)}return e.else?this._execStatements(e.else,t):null}_getScalarValue(e){return e instanceof d?e.value:(console.error("Expected scalar value.",e),0)}_for(e,t){for(t=t.clone(),this.execStatement(e.init,t);this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===V._breakObj)break;if(n!==null&&n!==V._continueObj)return n;this.execStatement(e.increment,t)}return null}_loop(e,t){for(t=t.clone();;){let n=this._execStatements(e.body,t);if(n===V._breakObj)break;if(n===V._continueObj){if(e.continuing&&this._execStatements(e.continuing.body,t)===V._breakObj)break}else if(n!==null)return n}return null}_while(e,t){for(t=t.clone();this._getScalarValue(this.evalExpression(e.condition,t));){let n=this._execStatements(e.body,t);if(n===V._breakObj)break;if(n!==V._continueObj&&n!==null)return n}return null}_evalBitcast(e,t){let n=this.evalExpression(e.value,t),r=e.type;if(n instanceof d){let s=jn(n.value,n.typeInfo.name,r.name);return new d(s,this.getTypeInfo(r))}if(n instanceof p){let s=n.typeInfo.getTypeName(),i="";if(s.endsWith("f"))i="f32";else if(s.endsWith("i"))i="i32";else if(s.endsWith("u"))i="u32";else if(s.endsWith("b"))i="bool";else{if(!s.endsWith("h"))return console.error(`Unknown vector type ${s}. Line ${e.line}`),null;i="f16"}let o=r.getTypeName(),l="";if(o.endsWith("f"))l="f32";else if(o.endsWith("i"))l="i32";else if(o.endsWith("u"))l="u32";else if(o.endsWith("b"))l="bool";else{if(!o.endsWith("h"))return console.error(`Unknown vector type ${l}. Line ${e.line}`),null;l="f16"}let c=function(u,h,b){if(h===b)return u;let y=new Array(u.length);for(let S=0;S<u.length;S++)y[S]=jn(u[S],h,b);return y}(Array.from(n.data),i,l);return new p(c,this.getTypeInfo(r))}return console.error(`TODO: bitcast for ${n.typeInfo.name}. Line ${e.line}`),null}_evalConst(e,t){return t.getVariableValue(e.name).clone().getSubData(this,e.postfix,t)}_evalCreate(e,t){var n;if(e instanceof K){if(e.type===null)return Ge.void;switch(e.type.getTypeName()){case"bool":case"i32":case"u32":case"f32":case"f16":return this._callConstructorValue(e,t);case"vec2":case"vec3":case"vec4":case"vec2f":case"vec3f":case"vec4f":case"vec2h":case"vec3h":case"vec4h":case"vec2i":case"vec3i":case"vec4i":case"vec2u":case"vec3u":case"vec4u":case"vec2b":case"vec3b":case"vec4b":return this._callConstructorVec(e,t);case"mat2x2":case"mat2x2f":case"mat2x2h":case"mat2x3":case"mat2x3f":case"mat2x3h":case"mat2x4":case"mat2x4f":case"mat2x4h":case"mat3x2":case"mat3x2f":case"mat3x2h":case"mat3x3":case"mat3x3f":case"mat3x3h":case"mat3x4":case"mat3x4f":case"mat3x4h":case"mat4x2":case"mat4x2f":case"mat4x2h":case"mat4x3":case"mat4x3f":case"mat4x3h":case"mat4x4":case"mat4x4f":case"mat4x4h":return this._callConstructorMatrix(e,t)}}let r=e instanceof K?e.type.name:e.name,s=e instanceof K?this.getTypeInfo(e.type):this.getTypeInfo(e.name);if(s===null)return console.error(`Unknown type ${r}. Line ${e.line}`),null;if(s.size===0)return null;let i=new D(new ArrayBuffer(s.size),s,0);if(s instanceof re){if(e.args)for(let o=0;o<e.args.length;++o){let l=s.members[o],c=e.args[o],u=this.evalExpression(c,t);i.setData(this,u,l.type,l.offset,t)}}else if(s instanceof se){let o=0;if(e.args)for(let l=0;l<e.args.length;++l){let c=e.args[l],u=this.evalExpression(c,t);s.format===null&&(((n=u.typeInfo)===null||n===void 0?void 0:n.name)==="x32"?s.format=this.getTypeInfo("i32"):s.format=u.typeInfo),i.setData(this,u,s.format,o,t),o+=s.stride}}else console.error(`Unknown type "${r}". Line ${e.line}`);return e instanceof K?i.getSubData(this,e.postfix,t):i}_evalLiteral(e,t){let n=this.getTypeInfo(e.type),r=n.name;return r==="x32"||r==="u32"||r==="f32"||r==="f16"||r==="i32"||r==="bool"?new d(e.scalarValue,n):r==="vec2"||r==="vec3"||r==="vec4"||r==="vec2f"||r==="vec3f"||r==="vec4f"||r==="vec2h"||r==="vec3h"||r==="vec4h"||r==="vec2i"||r==="vec3i"||r==="vec4i"||r==="vec2u"||r==="vec3u"||r==="vec4u"?this._callConstructorVec(e,t):r==="mat2x2"||r==="mat2x3"||r==="mat2x4"||r==="mat3x2"||r==="mat3x3"||r==="mat3x4"||r==="mat4x2"||r==="mat4x3"||r==="mat4x4"||r==="mat2x2f"||r==="mat2x3f"||r==="mat2x4f"||r==="mat3x2f"||r==="mat3x3f"||r==="mat3x4f"||r==="mat4x2f"||r==="mat4x3f"||r==="mat4x4f"||r==="mat2x2h"||r==="mat2x3h"||r==="mat2x4h"||r==="mat3x2h"||r==="mat3x3h"||r==="mat3x4h"||r==="mat4x2h"||r==="mat4x3h"||r==="mat4x4h"?this._callConstructorMatrix(e,t):e.value}_evalVariable(e,t){let n=t.getVariableValue(e.name);return n===null?n:n.getSubData(this,e.postfix,t)}_maxFormatTypeInfo(e){let t=e[0];if(t.name==="f32")return t;for(let n=1;n<e.length;++n){let r=V._priority.get(t.name);V._priority.get(e[n].name)<r&&(t=e[n])}return t.name==="x32"?this.getTypeInfo("i32"):t}_evalUnaryOp(e,t){let n=this.evalExpression(e.right,t);if(e.operator==="&")return new ue(n);if(e.operator==="*")return n instanceof ue?n.reference.getSubData(this,e.postfix,t):(console.error(`Invalid dereference. Line ${e.line}`),null);let r=n instanceof d?n.value:n instanceof p?Array.from(n.data):null;switch(e.operator){case"+":{if(w(r)){let o=r.map((l,c)=>+l);return new p(o,n.typeInfo)}let s=r,i=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(+s,i)}case"-":{if(w(r)){let o=r.map((l,c)=>-l);return new p(o,n.typeInfo)}let s=r,i=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(-s,i)}case"!":{if(w(r)){let o=r.map((l,c)=>l?0:1);return new p(o,n.typeInfo)}let s=r,i=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(s?0:1,i)}case"~":{if(w(r)){let o=r.map((l,c)=>~l);return new p(o,n.typeInfo)}let s=r,i=this._maxFormatTypeInfo([n.typeInfo,n.typeInfo]);return new d(~s,i)}}return console.error(`Invalid unary operator ${e.operator}. Line ${e.line}`),null}_evalBinaryOp(e,t){let n=this.evalExpression(e.left,t),r=this.evalExpression(e.right,t),s=n instanceof d?n.value:n instanceof p||n instanceof I?Array.from(n.data):null,i=r instanceof d?r.value:r instanceof p||r instanceof I?Array.from(r.data):null;switch(e.operator){case"+":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y+h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b+u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u+b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o+l,c)}case"-":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y-h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b-u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u-b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o-l,c)}case"*":{if(w(s)&&w(i)){let u=s,h=i;if(n instanceof I&&r instanceof I){let b=function(T,L,P,k){if(H[L.name]===void 0||H[k.name]===void 0)return null;let A=H[L.name][0],B=H[L.name][1],O=H[k.name][0];if(A!==H[k.name][1])return null;let oe=new Array(O*B);for(let X=0;X<B;X++)for(let U=0;U<O;U++){let he=0;for(let Le=0;Le<A;Le++)he+=T[Le*B+X]*P[U*A+Le];oe[X*O+U]=he}return oe}(u,n.typeInfo,h,r.typeInfo);if(b===null)return console.error(`Matrix multiplication failed. Line ${e.line}.`),null;let y=H[r.typeInfo.name][0],S=H[n.typeInfo.name][1],E=this.getTypeInfo(`mat${y}x${S}f`);return new I(b,E)}if(n instanceof I&&r instanceof p){let b=function(y,S,E,T){if(H[S.name]===void 0||zt[T.name]===void 0)return null;let L=H[S.name][0],P=H[S.name][1];if(L!==E.length)return null;let k=new Array(P);for(let A=0;A<P;A++){let B=0;for(let O=0;O<L;O++)B+=y[O*P+A]*E[O];k[A]=B}return k}(u,n.typeInfo,h,r.typeInfo);return b===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(b,r.typeInfo)}if(n instanceof p&&r instanceof I){let b=function(y,S,E,T){if(zt[S.name]===void 0||H[T.name]===void 0)return null;let L=H[T.name][0],P=H[T.name][1];if(P!==y.length)return null;let k=[];for(let A=0;A<L;A++){let B=0;for(let O=0;O<P;O++)B+=y[O]*E[O*L+A];k[A]=B}return k}(u,n.typeInfo,h,r.typeInfo);return b===null?(console.error(`Matrix vector multiplication failed. Line ${e.line}.`),null):new p(b,n.typeInfo)}{if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y*h[S]);return new p(b,n.typeInfo)}}if(w(s)){let u=i,h=s.map((b,y)=>b*u);return n instanceof I?new I(h,n.typeInfo):new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u*b);return r instanceof I?new I(h,r.typeInfo):new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o*l,c)}case"%":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y%h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b%u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u%b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o%l,c)}case"/":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y/h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b/u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u/b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o/l,c)}case"&":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y&h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b&u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u&b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o&l,c)}case"|":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y|h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b|u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u|b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o|l,c)}case"^":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y^h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b^u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u^b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o^l,c)}case"<<":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y<<h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b<<u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u<<b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o<<l,c)}case">>":{if(w(s)&&w(i)){let u=s,h=i;if(u.length!==h.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let b=u.map((y,S)=>y>>h[S]);return new p(b,n.typeInfo)}if(w(s)){let u=i,h=s.map((b,y)=>b>>u);return new p(h,n.typeInfo)}if(w(i)){let u=s,h=i.map((b,y)=>u>>b);return new p(h,r.typeInfo)}let o=s,l=i,c=this._maxFormatTypeInfo([n.typeInfo,r.typeInfo]);return new d(o>>l,c)}case">":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u>l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c>o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o>c?1:0);return new p(l,r.typeInfo)}return new d(s>i?1:0,this.getTypeInfo("bool"));case"<":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u<l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c<o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o<c?1:0);return new p(l,r.typeInfo)}return new d(s<i?1:0,this.getTypeInfo("bool"));case"==":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u===l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c==o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o==c?1:0);return new p(l,r.typeInfo)}return new d(s===i?1:0,this.getTypeInfo("bool"));case"!=":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u!==l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c!==o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o!==c?1:0);return new p(l,r.typeInfo)}return new d(s!==i?1:0,this.getTypeInfo("bool"));case">=":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u>=l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c>=o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o>=c?1:0);return new p(l,r.typeInfo)}return new d(s>=i?1:0,this.getTypeInfo("bool"));case"<=":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u<=l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c<=o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o<=c?1:0);return new p(l,r.typeInfo)}return new d(s<=i?1:0,this.getTypeInfo("bool"));case"&&":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u&&l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c&&o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o&&c?1:0);return new p(l,r.typeInfo)}return new d(s&&i?1:0,this.getTypeInfo("bool"));case"||":if(w(s)&&w(i)){let o=s,l=i;if(o.length!==l.length)return console.error(`Vector length mismatch. Line ${e.line}.`),null;let c=o.map((u,h)=>u||l[h]?1:0);return new p(c,n.typeInfo)}if(w(s)){let o=i,l=s.map((c,u)=>c||o?1:0);return new p(l,n.typeInfo)}if(w(i)){let o=s,l=i.map((c,u)=>o||c?1:0);return new p(l,r.typeInfo)}return new d(s||i?1:0,this.getTypeInfo("bool"))}return console.error(`Unknown operator ${e.operator}. Line ${e.line}`),null}_evalCall(e,t){if(e.cachedReturnValue!==null)return e.cachedReturnValue;let n=t.clone();n.currentFunctionName=e.name;let r=t.getFunction(e.name);if(!r)return e.isBuiltin?this._callBuiltinFunction(e,n):this.getTypeInfo(e.name)?this._evalCreate(e,t):(console.error(`Unknown function "${e.name}". Line ${e.line}`),null);for(let s=0;s<r.node.args.length;++s){let i=r.node.args[s],o=this.evalExpression(e.args[s],n);n.createVariable(i.name,o,i)}return this._execStatements(r.node.body,n)}_callBuiltinFunction(e,t){switch(e.name){case"all":return this.builtins.All(e,t);case"any":return this.builtins.Any(e,t);case"select":return this.builtins.Select(e,t);case"arrayLength":return this.builtins.ArrayLength(e,t);case"abs":return this.builtins.Abs(e,t);case"acos":return this.builtins.Acos(e,t);case"acosh":return this.builtins.Acosh(e,t);case"asin":return this.builtins.Asin(e,t);case"asinh":return this.builtins.Asinh(e,t);case"atan":return this.builtins.Atan(e,t);case"atanh":return this.builtins.Atanh(e,t);case"atan2":return this.builtins.Atan2(e,t);case"ceil":return this.builtins.Ceil(e,t);case"clamp":return this.builtins.Clamp(e,t);case"cos":return this.builtins.Cos(e,t);case"cosh":return this.builtins.Cosh(e,t);case"countLeadingZeros":return this.builtins.CountLeadingZeros(e,t);case"countOneBits":return this.builtins.CountOneBits(e,t);case"countTrailingZeros":return this.builtins.CountTrailingZeros(e,t);case"cross":return this.builtins.Cross(e,t);case"degrees":return this.builtins.Degrees(e,t);case"determinant":return this.builtins.Determinant(e,t);case"distance":return this.builtins.Distance(e,t);case"dot":return this.builtins.Dot(e,t);case"dot4U8Packed":return this.builtins.Dot4U8Packed(e,t);case"dot4I8Packed":return this.builtins.Dot4I8Packed(e,t);case"exp":return this.builtins.Exp(e,t);case"exp2":return this.builtins.Exp2(e,t);case"extractBits":return this.builtins.ExtractBits(e,t);case"faceForward":return this.builtins.FaceForward(e,t);case"firstLeadingBit":return this.builtins.FirstLeadingBit(e,t);case"firstTrailingBit":return this.builtins.FirstTrailingBit(e,t);case"floor":return this.builtins.Floor(e,t);case"fma":return this.builtins.Fma(e,t);case"fract":return this.builtins.Fract(e,t);case"frexp":return this.builtins.Frexp(e,t);case"insertBits":return this.builtins.InsertBits(e,t);case"inverseSqrt":return this.builtins.InverseSqrt(e,t);case"ldexp":return this.builtins.Ldexp(e,t);case"length":return this.builtins.Length(e,t);case"log":return this.builtins.Log(e,t);case"log2":return this.builtins.Log2(e,t);case"max":return this.builtins.Max(e,t);case"min":return this.builtins.Min(e,t);case"mix":return this.builtins.Mix(e,t);case"modf":return this.builtins.Modf(e,t);case"normalize":return this.builtins.Normalize(e,t);case"pow":return this.builtins.Pow(e,t);case"quantizeToF16":return this.builtins.QuantizeToF16(e,t);case"radians":return this.builtins.Radians(e,t);case"reflect":return this.builtins.Reflect(e,t);case"refract":return this.builtins.Refract(e,t);case"reverseBits":return this.builtins.ReverseBits(e,t);case"round":return this.builtins.Round(e,t);case"saturate":return this.builtins.Saturate(e,t);case"sign":return this.builtins.Sign(e,t);case"sin":return this.builtins.Sin(e,t);case"sinh":return this.builtins.Sinh(e,t);case"smoothStep":return this.builtins.SmoothStep(e,t);case"sqrt":return this.builtins.Sqrt(e,t);case"step":return this.builtins.Step(e,t);case"tan":return this.builtins.Tan(e,t);case"tanh":return this.builtins.Tanh(e,t);case"transpose":return this.builtins.Transpose(e,t);case"trunc":return this.builtins.Trunc(e,t);case"dpdx":return this.builtins.Dpdx(e,t);case"dpdxCoarse":return this.builtins.DpdxCoarse(e,t);case"dpdxFine":return this.builtins.DpdxFine(e,t);case"dpdy":return this.builtins.Dpdy(e,t);case"dpdyCoarse":return this.builtins.DpdyCoarse(e,t);case"dpdyFine":return this.builtins.DpdyFine(e,t);case"fwidth":return this.builtins.Fwidth(e,t);case"fwidthCoarse":return this.builtins.FwidthCoarse(e,t);case"fwidthFine":return this.builtins.FwidthFine(e,t);case"textureDimensions":return this.builtins.TextureDimensions(e,t);case"textureGather":return this.builtins.TextureGather(e,t);case"textureGatherCompare":return this.builtins.TextureGatherCompare(e,t);case"textureLoad":return this.builtins.TextureLoad(e,t);case"textureNumLayers":return this.builtins.TextureNumLayers(e,t);case"textureNumLevels":return this.builtins.TextureNumLevels(e,t);case"textureNumSamples":return this.builtins.TextureNumSamples(e,t);case"textureSample":return this.builtins.TextureSample(e,t);case"textureSampleBias":return this.builtins.TextureSampleBias(e,t);case"textureSampleCompare":return this.builtins.TextureSampleCompare(e,t);case"textureSampleCompareLevel":return this.builtins.TextureSampleCompareLevel(e,t);case"textureSampleGrad":return this.builtins.TextureSampleGrad(e,t);case"textureSampleLevel":return this.builtins.TextureSampleLevel(e,t);case"textureSampleBaseClampToEdge":return this.builtins.TextureSampleBaseClampToEdge(e,t);case"textureStore":return this.builtins.TextureStore(e,t);case"atomicLoad":return this.builtins.AtomicLoad(e,t);case"atomicStore":return this.builtins.AtomicStore(e,t);case"atomicAdd":return this.builtins.AtomicAdd(e,t);case"atomicSub":return this.builtins.AtomicSub(e,t);case"atomicMax":return this.builtins.AtomicMax(e,t);case"atomicMin":return this.builtins.AtomicMin(e,t);case"atomicAnd":return this.builtins.AtomicAnd(e,t);case"atomicOr":return this.builtins.AtomicOr(e,t);case"atomicXor":return this.builtins.AtomicXor(e,t);case"atomicExchange":return this.builtins.AtomicExchange(e,t);case"atomicCompareExchangeWeak":return this.builtins.AtomicCompareExchangeWeak(e,t);case"pack4x8snorm":return this.builtins.Pack4x8snorm(e,t);case"pack4x8unorm":return this.builtins.Pack4x8unorm(e,t);case"pack4xI8":return this.builtins.Pack4xI8(e,t);case"pack4xU8":return this.builtins.Pack4xU8(e,t);case"pack4x8Clamp":return this.builtins.Pack4x8Clamp(e,t);case"pack4xU8Clamp":return this.builtins.Pack4xU8Clamp(e,t);case"pack2x16snorm":return this.builtins.Pack2x16snorm(e,t);case"pack2x16unorm":return this.builtins.Pack2x16unorm(e,t);case"pack2x16float":return this.builtins.Pack2x16float(e,t);case"unpack4x8snorm":return this.builtins.Unpack4x8snorm(e,t);case"unpack4x8unorm":return this.builtins.Unpack4x8unorm(e,t);case"unpack4xI8":return this.builtins.Unpack4xI8(e,t);case"unpack4xU8":return this.builtins.Unpack4xU8(e,t);case"unpack2x16snorm":return this.builtins.Unpack2x16snorm(e,t);case"unpack2x16unorm":return this.builtins.Unpack2x16unorm(e,t);case"unpack2x16float":return this.builtins.Unpack2x16float(e,t);case"storageBarrier":return this.builtins.StorageBarrier(e,t);case"textureBarrier":return this.builtins.TextureBarrier(e,t);case"workgroupBarrier":return this.builtins.WorkgroupBarrier(e,t);case"workgroupUniformLoad":return this.builtins.WorkgroupUniformLoad(e,t);case"subgroupAdd":return this.builtins.SubgroupAdd(e,t);case"subgroupExclusiveAdd":return this.builtins.SubgroupExclusiveAdd(e,t);case"subgroupInclusiveAdd":return this.builtins.SubgroupInclusiveAdd(e,t);case"subgroupAll":return this.builtins.SubgroupAll(e,t);case"subgroupAnd":return this.builtins.SubgroupAnd(e,t);case"subgroupAny":return this.builtins.SubgroupAny(e,t);case"subgroupBallot":return this.builtins.SubgroupBallot(e,t);case"subgroupBroadcast":return this.builtins.SubgroupBroadcast(e,t);case"subgroupBroadcastFirst":return this.builtins.SubgroupBroadcastFirst(e,t);case"subgroupElect":return this.builtins.SubgroupElect(e,t);case"subgroupMax":return this.builtins.SubgroupMax(e,t);case"subgroupMin":return this.builtins.SubgroupMin(e,t);case"subgroupMul":return this.builtins.SubgroupMul(e,t);case"subgroupExclusiveMul":return this.builtins.SubgroupExclusiveMul(e,t);case"subgroupInclusiveMul":return this.builtins.SubgroupInclusiveMul(e,t);case"subgroupOr":return this.builtins.SubgroupOr(e,t);case"subgroupShuffle":return this.builtins.SubgroupShuffle(e,t);case"subgroupShuffleDown":return this.builtins.SubgroupShuffleDown(e,t);case"subgroupShuffleUp":return this.builtins.SubgroupShuffleUp(e,t);case"subgroupShuffleXor":return this.builtins.SubgroupShuffleXor(e,t);case"subgroupXor":return this.builtins.SubgroupXor(e,t);case"quadBroadcast":return this.builtins.QuadBroadcast(e,t);case"quadSwapDiagonal":return this.builtins.QuadSwapDiagonal(e,t);case"quadSwapX":return this.builtins.QuadSwapX(e,t);case"quadSwapY":return this.builtins.QuadSwapY(e,t)}let n=t.getFunction(e.name);if(n){let r=t.clone();for(let s=0;s<n.node.args.length;++s){let i=n.node.args[s],o=this.evalExpression(e.args[s],r);r.setVariable(i.name,o,i)}return this._execStatements(n.node.body,r)}return null}_callConstructorValue(e,t){if(!e.args||e.args.length===0)return new d(0,this.getTypeInfo(e.type));let n=this.evalExpression(e.args[0],t);return n.typeInfo=this.getTypeInfo(e.type),n.getSubData(this,e.postfix,t).clone()}_callConstructorVec(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=zt[r];if(s===void 0)return console.error(`Invalid vec constructor ${r}. Line ${e.line}`),null;let i=[];if(e instanceof R)if(e.isVector){let o=e.vectorValue;for(let l of o)i.push(l)}else i.push(e.scalarValue);else if(e.args)for(let o of e.args){let l=this.evalExpression(o,t);if(l instanceof p){let c=l.data;for(let u=0;u<c.length;++u){let h=c[u];i.push(h)}}else if(l instanceof d){let c=l.value;i.push(c)}}if(e.type instanceof g&&e.type.format===null&&(e.type.format=g.f32),i.length===0){let o=new Array(s).fill(0);return new p(o,n).getSubData(this,e.postfix,t)}if(i.length===1)for(;i.length<s;)i.push(i[0]);return i.length<s?(console.error(`Invalid vec constructor. Line ${e.line}`),null):new p(i.length>s?i.slice(0,s):i,n).getSubData(this,e.postfix,t)}_callConstructorMatrix(e,t){let n=this.getTypeInfo(e.type),r=e.type.getTypeName(),s=H[r];if(s===void 0)return console.error(`Invalid matrix constructor ${r}. Line ${e.line}`),null;let i=[];if(e instanceof R)if(e.isVector){let o=e.vectorValue;for(let l of o)i.push(l)}else i.push(e.scalarValue);else if(e.args)for(let o of e.args){let l=this.evalExpression(o,t);l instanceof p?i.push(...l.data):l instanceof d?i.push(l.value):l instanceof I&&i.push(...l.data)}if(n instanceof ie&&n.format===null&&(n.format=this.getTypeInfo("f32")),i.length===0){let o=new Array(s[2]).fill(0);return new I(o,n).getSubData(this,e.postfix,t)}return i.length!==s[2]?(console.error(`Invalid matrix constructor. Line ${e.line}`),null):new I(i,n).getSubData(this,e.postfix,t)}};V._breakObj=new q(new W("BREAK",null),null),V._continueObj=new q(new W("CONTINUE",null),null),V._priority=new Map([["f32",0],["f16",1],["u32",2],["i32",3],["x32",3]]);var ln=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},cn=class{constructor(){this._tokens=[],this._current=0,this._currentLine=1,this._deferArrayCountEval=[],this._currentLoop=[],this._context=new ln,this._exec=new V,this._forwardTypeCount=0}parse(e){this._initialize(e),this._deferArrayCountEval.length=0;let t=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;t.push(n)}if(this._deferArrayCountEval.length>0){for(let n of this._deferArrayCountEval){let r=n.arrayType,s=n.countNode;if(s instanceof G){let i=s.name,o=this._context.constants.get(i);if(o)try{let l=o.constEvaluate(this._exec);r.count=l}catch{}}}this._deferArrayCountEval.length=0}if(this._forwardTypeCount>0)for(let n of t)n.search(r=>{r instanceof At||r instanceof Re?r.type=this._forwardType(r.type):r instanceof _e?r.format=this._forwardType(r.format):r instanceof ee||r instanceof me||r instanceof ke?r.type=this._forwardType(r.type):r instanceof ge?r.returnType=this._forwardType(r.returnType):r instanceof St&&(r.type=this._forwardType(r.type))});return t}_forwardType(e){if(e instanceof vt){let t=this._getType(e.name);if(t)return t}else e instanceof Re?e.type=this._forwardType(e.type):e instanceof _e&&(e.format=this._forwardType(e.format));return e}_initialize(e){if(e)if(typeof e=="string"){let t=new rn(e);this._tokens=t.scanTokens()}else this._tokens=e;else this._tokens=[];this._current=0}_updateNode(e,t){return e.line=t??this._currentLine,e}_error(e,t){return{token:e,message:t,toString:()=>`${t}`}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==f.eof}_match(e){if(e instanceof m)return!!this._check(e)&&(this._advance(),!0);for(let t=0,n=e.length;t<n;++t){let r=e[t];if(this._check(r))return this._advance(),!0}return!1}_consume(e,t){if(this._check(e))return this._advance();throw this._error(this._peek(),`${t}. Line:${this._currentLine}`)}_check(e){if(this._isAtEnd())return!1;let t=this._peek();if(e instanceof Array){let n=t.type,r=!1;for(let s of e){if(n===s)return!0;s===f.tokens.name&&(r=!0)}if(r){let s=f.tokens.name.rule.exec(t.lexeme);if(s&&s.index==0&&s[0]==t.lexeme)return!0}return!1}if(t.type===e)return!0;if(e===f.tokens.name){let n=f.tokens.name.rule.exec(t.lexeme);return n&&n.index==0&&n[0]==t.lexeme}return!1}_advance(){var e,t;return this._currentLine=(t=(e=this._peek())===null||e===void 0?void 0:e.line)!==null&&t!==void 0?t:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(f.tokens.semicolon)&&!this._isAtEnd(););if(this._match(f.keywords.alias)){let t=this._type_alias();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.diagnostic)){let t=this._diagnostic();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.requires)){let t=this._requires_directive();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}if(this._match(f.keywords.enable)){let t=this._enable_directive();return this._consume(f.tokens.semicolon,"Expected ';'"),this._exec.reflection.updateAST([t]),t}let e=this._attribute();if(this._check(f.keywords.var)){let t=this._global_variable_decl();return t!=null&&(t.attributes=e),this._consume(f.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.override)){let t=this._override_variable_decl();return t!=null&&(t.attributes=e),this._consume(f.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.let)){let t=this._global_let_decl();return t!=null&&(t.attributes=e),this._consume(f.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.const)){let t=this._global_const_decl();return t!=null&&(t.attributes=e),this._consume(f.tokens.semicolon,"Expected ';'."),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.struct)){let t=this._struct_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}if(this._check(f.keywords.fn)){let t=this._function_decl();return t!=null&&(t.attributes=e),this._exec.reflection.updateAST([t]),t}return null}_function_decl(){if(!this._match(f.keywords.fn))return null;let e=this._currentLine,t=this._consume(f.tokens.ident,"Expected function name.").toString();this._consume(f.tokens.paren_left,"Expected '(' for function arguments.");let n=[];if(!this._check(f.tokens.paren_right))do{if(this._check(f.tokens.paren_right))break;let o=this._attribute(),l=this._consume(f.tokens.name,"Expected argument name.").toString();this._consume(f.tokens.colon,"Expected ':' for argument type.");let c=this._attribute(),u=this._type_decl();u!=null&&(u.attributes=c,n.push(this._updateNode(new St(l,u,o))))}while(this._match(f.tokens.comma));this._consume(f.tokens.paren_right,"Expected ')' after function arguments.");let r=null;if(this._match(f.tokens.arrow)){let o=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=o)}let s=this._compound_statement(),i=this._currentLine;return this._updateNode(new ge(t,n,r,s,e,i),e)}_compound_statement(){let e=[];for(this._consume(f.tokens.brace_left,"Expected '{' for block.");!this._check(f.tokens.brace_right);){let t=this._statement();t!==null&&e.push(t)}return this._consume(f.tokens.brace_right,"Expected '}' for block."),e}_statement(){for(;this._match(f.tokens.semicolon)&&!this._isAtEnd(););if(this._check(f.tokens.attr)&&this._attribute(),this._check(f.keywords.if))return this._if_statement();if(this._check(f.keywords.switch))return this._switch_statement();if(this._check(f.keywords.loop))return this._loop_statement();if(this._check(f.keywords.for))return this._for_statement();if(this._check(f.keywords.while))return this._while_statement();if(this._check(f.keywords.continuing))return this._continuing_statement();if(this._check(f.keywords.static_assert))return this._static_assert_statement();if(this._check(f.tokens.brace_left))return this._compound_statement();let e=null;if(this._check(f.keywords.return))e=this._return_statement();else if(this._check([f.keywords.var,f.keywords.let,f.keywords.const]))e=this._variable_statement();else if(this._match(f.keywords.discard))e=this._updateNode(new tn);else if(this._match(f.keywords.break)){let t=this._updateNode(new _t);if(this._currentLoop.length>0){let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t,this._check(f.keywords.if)&&(this._advance(),t.condition=this._optional_paren_expression())}else if(this._match(f.keywords.continue)){let t=this._updateNode(new gt);if(!(this._currentLoop.length>0))throw this._error(this._peek(),`Continue statement must be inside a loop. Line: ${t.line}`);{let n=this._currentLoop[this._currentLoop.length-1];t.loopId=n.id}e=t}else e=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement();return e!=null&&this._consume(f.tokens.semicolon,"Expected ';' after statement."),e}_static_assert_statement(){if(!this._match(f.keywords.static_assert))return null;let e=this._currentLine,t=this._optional_paren_expression();return this._updateNode(new Yt(t),e)}_while_statement(){if(!this._match(f.keywords.while))return null;let e=this._updateNode(new at(null,null));return this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(f.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_continuing_statement(){let e=this._currentLoop.length>0?this._currentLoop[this._currentLoop.length-1].id:-1;if(!this._match(f.keywords.continuing))return null;let t=this._currentLine,n=this._compound_statement();return this._updateNode(new Be(n,e),t)}_for_statement(){if(!this._match(f.keywords.for))return null;this._consume(f.tokens.paren_left,"Expected '('.");let e=this._updateNode(new lt(null,null,null,null));return this._currentLoop.push(e),e.init=this._check(f.tokens.semicolon)?null:this._for_init(),this._consume(f.tokens.semicolon,"Expected ';'."),e.condition=this._check(f.tokens.semicolon)?null:this._short_circuit_or_expression(),this._consume(f.tokens.semicolon,"Expected ';'."),e.increment=this._check(f.tokens.paren_right)?null:this._for_increment(),this._consume(f.tokens.paren_right,"Expected ')'."),this._check(f.tokens.attr)&&this._attribute(),e.body=this._compound_statement(),this._currentLoop.pop(),e}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(f.keywords.var)){let e=this._variable_decl();if(e===null)throw this._error(this._peek(),"Variable declaration expected.");let t=null;return this._match(f.tokens.equal)&&(t=this._short_circuit_or_expression()),this._updateNode(new ee(e.name,e.type,e.storage,e.access,t),e.line)}if(this._match(f.keywords.let)){let e=this._currentLine,t=this._consume(f.tokens.name,"Expected name for let.").toString(),n=null;if(this._match(f.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(f.tokens.equal,"Expected '=' for let.");let r=this._short_circuit_or_expression();return this._updateNode(new me(t,n,null,null,r),e)}if(this._match(f.keywords.const)){let e=this._currentLine,t=this._consume(f.tokens.name,"Expected name for const.").toString(),n=null;if(this._match(f.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}this._consume(f.tokens.equal,"Expected '=' for const.");let r=this._short_circuit_or_expression();return n===null&&r instanceof R&&(n=r.type),this._updateNode(new ke(t,n,null,null,r),e)}return null}_increment_decrement_statement(){let e=this._current,t=this._unary_expression();if(t==null)return null;if(!this._check(f.increment_operators))return this._current=e,null;let n=this._consume(f.increment_operators,"Expected increment operator");return this._updateNode(new ct(n.type===f.tokens.plus_plus?ye.increment:ye.decrement,t))}_assignment_statement(){let e=null,t=this._currentLine;if(this._check(f.tokens.brace_right))return null;let n=this._match(f.tokens.underscore);if(n||(e=this._unary_expression()),!n&&e==null)return null;let r=this._consume(f.assignment_operators,"Expected assignment operator."),s=this._short_circuit_or_expression();return this._updateNode(new ut(Me.parse(r.lexeme),e,s),t)}_func_call_statement(){if(!this._check(f.tokens.ident))return null;let e=this._currentLine,t=this._current,n=this._consume(f.tokens.ident,"Expected function name."),r=this._argument_expression_list();return r===null?(this._current=t,null):this._updateNode(new Ue(n.lexeme,r),e)}_loop_statement(){if(!this._match(f.keywords.loop))return null;this._check(f.tokens.attr)&&this._attribute(),this._consume(f.tokens.brace_left,"Expected '{' for loop.");let e=this._updateNode(new ft([],null));this._currentLoop.push(e);let t=this._statement();for(;t!==null;){if(Array.isArray(t))for(let n of t)e.body.push(n);else e.body.push(t);if(t instanceof Be){e.continuing=t;break}t=this._statement()}return this._currentLoop.pop(),this._consume(f.tokens.brace_right,"Expected '}' for loop."),e}_switch_statement(){if(!this._match(f.keywords.switch))return null;let e=this._updateNode(new ht(null,[]));if(this._currentLoop.push(e),e.condition=this._optional_paren_expression(),this._check(f.tokens.attr)&&this._attribute(),this._consume(f.tokens.brace_left,"Expected '{' for switch."),e.cases=this._switch_body(),e.cases==null||e.cases.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(f.tokens.brace_right,"Expected '}' for switch."),this._currentLoop.pop(),e}_switch_body(){let e=[],t=!1;for(;this._check([f.keywords.default,f.keywords.case]);){if(this._match(f.keywords.case)){let n=this._case_selectors();for(let s of n)if(s instanceof Ie){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");t=!0;break}this._match(f.tokens.colon),this._check(f.tokens.attr)&&this._attribute(),this._consume(f.tokens.brace_left,"Exected '{' for switch case.");let r=this._case_body();this._consume(f.tokens.brace_right,"Exected '}' for switch case."),e.push(this._updateNode(new kt(n,r)))}if(this._match(f.keywords.default)){if(t)throw this._error(this._previous(),"Multiple default cases in switch statement.");this._match(f.tokens.colon),this._check(f.tokens.attr)&&this._attribute(),this._consume(f.tokens.brace_left,"Exected '{' for switch default.");let n=this._case_body();this._consume(f.tokens.brace_right,"Exected '}' for switch default."),e.push(this._updateNode(new It(n)))}}return e}_case_selectors(){let e=[];for(this._match(f.keywords.default)?e.push(this._updateNode(new Ie)):e.push(this._shift_expression());this._match(f.tokens.comma);)this._match(f.keywords.default)?e.push(this._updateNode(new Ie)):e.push(this._shift_expression());return e}_case_body(){if(this._match(f.keywords.fallthrough))return this._consume(f.tokens.semicolon,"Expected ';'"),[];let e=this._statement();if(e==null)return[];e instanceof Array||(e=[e]);let t=this._case_body();return t.length==0?e:[...e,t[0]]}_if_statement(){if(!this._match(f.keywords.if))return null;let e=this._currentLine,t=this._optional_paren_expression();this._check(f.tokens.attr)&&this._attribute();let n=this._compound_statement(),r=[];this._match_elseif()&&(this._check(f.tokens.attr)&&this._attribute(),r=this._elseif_statement(r));let s=null;return this._match(f.keywords.else)&&(this._check(f.tokens.attr)&&this._attribute(),s=this._compound_statement()),this._updateNode(new pt(t,n,r,s),e)}_match_elseif(){return this._tokens[this._current].type===f.keywords.else&&this._tokens[this._current+1].type===f.keywords.if&&(this._advance(),this._advance(),!0)}_elseif_statement(e=[]){let t=this._optional_paren_expression(),n=this._compound_statement();return e.push(this._updateNode(new nn(t,n))),this._match_elseif()&&(this._check(f.tokens.attr)&&this._attribute(),this._elseif_statement(e)),e}_return_statement(){if(!this._match(f.keywords.return))return null;let e=this._short_circuit_or_expression();return this._updateNode(new dt(e))}_short_circuit_or_expression(){let e=this._short_circuit_and_expr();for(;this._match(f.tokens.or_or);)e=this._updateNode(new j(this._previous().toString(),e,this._short_circuit_and_expr()));return e}_short_circuit_and_expr(){let e=this._inclusive_or_expression();for(;this._match(f.tokens.and_and);)e=this._updateNode(new j(this._previous().toString(),e,this._inclusive_or_expression()));return e}_inclusive_or_expression(){let e=this._exclusive_or_expression();for(;this._match(f.tokens.or);)e=this._updateNode(new j(this._previous().toString(),e,this._exclusive_or_expression()));return e}_exclusive_or_expression(){let e=this._and_expression();for(;this._match(f.tokens.xor);)e=this._updateNode(new j(this._previous().toString(),e,this._and_expression()));return e}_and_expression(){let e=this._equality_expression();for(;this._match(f.tokens.and);)e=this._updateNode(new j(this._previous().toString(),e,this._equality_expression()));return e}_equality_expression(){let e=this._relational_expression();return this._match([f.tokens.equal_equal,f.tokens.not_equal])?this._updateNode(new j(this._previous().toString(),e,this._relational_expression())):e}_relational_expression(){let e=this._shift_expression();for(;this._match([f.tokens.less_than,f.tokens.greater_than,f.tokens.less_than_equal,f.tokens.greater_than_equal]);)e=this._updateNode(new j(this._previous().toString(),e,this._shift_expression()));return e}_shift_expression(){let e=this._additive_expression();for(;this._match([f.tokens.shift_left,f.tokens.shift_right]);)e=this._updateNode(new j(this._previous().toString(),e,this._additive_expression()));return e}_additive_expression(){let e=this._multiplicative_expression();for(;this._match([f.tokens.plus,f.tokens.minus]);)e=this._updateNode(new j(this._previous().toString(),e,this._multiplicative_expression()));return e}_multiplicative_expression(){let e=this._unary_expression();for(;this._match([f.tokens.star,f.tokens.forward_slash,f.tokens.modulo]);)e=this._updateNode(new j(this._previous().toString(),e,this._unary_expression()));return e}_unary_expression(){return this._match([f.tokens.minus,f.tokens.bang,f.tokens.tilde,f.tokens.star,f.tokens.and])?this._updateNode(new M(this._previous().toString(),this._unary_expression())):this._singular_expression()}_singular_expression(){let e=this._primary_expression(),t=this._postfix_expression();return t&&(e.postfix=t),e}_postfix_expression(){if(this._match(f.tokens.bracket_left)){let e=this._short_circuit_or_expression();this._consume(f.tokens.bracket_right,"Expected ']'.");let t=this._updateNode(new fe(e)),n=this._postfix_expression();return n&&(t.postfix=n),t}if(this._match(f.tokens.period)){let e=this._consume(f.tokens.name,"Expected member name."),t=this._postfix_expression(),n=this._updateNode(new ae(e.lexeme));return t&&(n.postfix=t),n}return null}_getStruct(e){return this._context.aliases.has(e)?this._context.aliases.get(e).type:this._context.structs.has(e)?this._context.structs.get(e):null}_getType(e){let t=this._getStruct(e);if(t!==null)return t;switch(e){case"void":return x.void;case"bool":return x.bool;case"i32":return x.i32;case"u32":return x.u32;case"f32":return x.f32;case"f16":return x.f16;case"vec2f":return g.vec2f;case"vec3f":return g.vec3f;case"vec4f":return g.vec4f;case"vec2i":return g.vec2i;case"vec3i":return g.vec3i;case"vec4i":return g.vec4i;case"vec2u":return g.vec2u;case"vec3u":return g.vec3u;case"vec4u":return g.vec4u;case"vec2h":return g.vec2h;case"vec3h":return g.vec3h;case"vec4h":return g.vec4h;case"mat2x2f":return g.mat2x2f;case"mat2x3f":return g.mat2x3f;case"mat2x4f":return g.mat2x4f;case"mat3x2f":return g.mat3x2f;case"mat3x3f":return g.mat3x3f;case"mat3x4f":return g.mat3x4f;case"mat4x2f":return g.mat4x2f;case"mat4x3f":return g.mat4x3f;case"mat4x4f":return g.mat4x4f;case"mat2x2h":return g.mat2x2h;case"mat2x3h":return g.mat2x3h;case"mat2x4h":return g.mat2x4h;case"mat3x2h":return g.mat3x2h;case"mat3x3h":return g.mat3x3h;case"mat3x4h":return g.mat3x4h;case"mat4x2h":return g.mat4x2h;case"mat4x3h":return g.mat4x3h;case"mat4x4h":return g.mat4x4h;case"mat2x2i":return g.mat2x2i;case"mat2x3i":return g.mat2x3i;case"mat2x4i":return g.mat2x4i;case"mat3x2i":return g.mat3x2i;case"mat3x3i":return g.mat3x3i;case"mat3x4i":return g.mat3x4i;case"mat4x2i":return g.mat4x2i;case"mat4x3i":return g.mat4x3i;case"mat4x4i":return g.mat4x4i;case"mat2x2u":return g.mat2x2u;case"mat2x3u":return g.mat2x3u;case"mat2x4u":return g.mat2x4u;case"mat3x2u":return g.mat3x2u;case"mat3x3u":return g.mat3x3u;case"mat3x4u":return g.mat3x4u;case"mat4x2u":return g.mat4x2u;case"mat4x3u":return g.mat4x3u;case"mat4x4u":return g.mat4x4u}return null}_validateTypeRange(e,t){if(t.name==="i32"){if(e<-2147483648||e>2147483647)throw this._error(this._previous(),`Value out of range for i32: ${e}. Line: ${this._currentLine}.`)}else if(t.name==="u32"&&(e<0||e>4294967295))throw this._error(this._previous(),`Value out of range for u32: ${e}. Line: ${this._currentLine}.`)}_primary_expression(){if(this._match(f.tokens.ident)){let n=this._previous().toString();if(this._check(f.tokens.paren_left)){let r=this._argument_expression_list(),s=this._getType(n);return s!==null?this._updateNode(new K(s,r)):this._updateNode(new He(n,r))}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return this._updateNode(new bt(n,r.value))}return this._updateNode(new G(n))}if(this._match(f.tokens.int_literal)){let n=this._previous().toString(),r=n.endsWith("i")||n.endsWith("i")?x.i32:n.endsWith("u")||n.endsWith("U")?x.u32:x.x32,s=parseInt(n);return this._validateTypeRange(s,r),this._updateNode(new R(new d(s,this._exec.getTypeInfo(r)),r))}if(this._match(f.tokens.uint_literal)){let n=parseInt(this._previous().toString());return this._validateTypeRange(n,x.u32),this._updateNode(new R(new d(n,this._exec.getTypeInfo(x.u32)),x.u32))}if(this._match([f.tokens.decimal_float_literal,f.tokens.hex_float_literal])){let n=this._previous().toString(),r=n.endsWith("h");r&&(n=n.substring(0,n.length-1));let s=parseFloat(n);this._validateTypeRange(s,r?x.f16:x.f32);let i=r?x.f16:x.f32;return this._updateNode(new R(new d(s,this._exec.getTypeInfo(i)),i))}if(this._match([f.keywords.true,f.keywords.false])){let n=this._previous().toString()===f.keywords.true.rule;return this._updateNode(new R(new d(n?1:0,this._exec.getTypeInfo(x.bool)),x.bool))}if(this._check(f.tokens.paren_left))return this._paren_expression();if(this._match(f.keywords.bitcast)){this._consume(f.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(f.tokens.greater_than,"Expected '>'.");let r=this._paren_expression();return this._updateNode(new xt(n,r))}let e=this._type_decl(),t=this._argument_expression_list();return this._updateNode(new K(e,t))}_argument_expression_list(){if(!this._match(f.tokens.paren_left))return null;let e=[];do{if(this._check(f.tokens.paren_right))break;let t=this._short_circuit_or_expression();e.push(t)}while(this._match(f.tokens.comma));return this._consume(f.tokens.paren_right,"Expected ')' for agument list"),e}_optional_paren_expression(){this._match(f.tokens.paren_left);let e=this._short_circuit_or_expression();return this._match(f.tokens.paren_right),e}_paren_expression(){this._consume(f.tokens.paren_left,"Expected '('.");let e=this._short_circuit_or_expression();return this._consume(f.tokens.paren_right,"Expected ')'."),e}_struct_decl(){if(!this._match(f.keywords.struct))return null;let e=this._currentLine,t=this._consume(f.tokens.ident,"Expected name for struct.").toString();this._consume(f.tokens.brace_left,"Expected '{' for struct body.");let n=[];for(;!this._check(f.tokens.brace_right);){let i=this._attribute(),o=this._consume(f.tokens.name,"Expected variable name.").toString();this._consume(f.tokens.colon,"Expected ':' for struct member type.");let l=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=l),this._check(f.tokens.brace_right)?this._match(f.tokens.comma):this._consume(f.tokens.comma,"Expected ',' for struct member."),n.push(this._updateNode(new At(o,c,i)))}this._consume(f.tokens.brace_right,"Expected '}' after struct body.");let r=this._currentLine,s=this._updateNode(new Y(t,n,e,r),e);return this._context.structs.set(t,s),s}_global_variable_decl(){let e=this._variable_decl();if(!e)return null;if(this._match(f.tokens.equal)){let t=this._const_expression();e.value=t}if(e.type!==null&&e.value instanceof R){if(e.value.type.name!=="x32"&&e.type.getTypeName()!==e.value.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${e.value.type.name} to ${e.type.name}. Line:${this._currentLine}`);e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type),e.value.type=e.type}else e.type===null&&e.value instanceof R&&(e.type=e.value.type.name==="x32"?x.i32:e.value.type,e.value.isScalar&&this._validateTypeRange(e.value.scalarValue,e.type));return e}_override_variable_decl(){let e=this._override_decl();return e&&this._match(f.tokens.equal)&&(e.value=this._const_expression()),e}_global_const_decl(){var e;if(!this._match(f.keywords.const))return null;let t=this._consume(f.tokens.name,"Expected variable name"),n=this._currentLine,r=null;if(this._match(f.tokens.colon)){let l=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=l)}let s=null;this._consume(f.tokens.equal,"const declarations require an assignment");let i=this._short_circuit_or_expression();try{let l=[x.f32],c=i.constEvaluate(this._exec,l);c instanceof d&&this._validateTypeRange(c.value,l[0]),l[0]instanceof g&&l[0].format===null&&c.typeInfo instanceof ie&&c.typeInfo.format!==null&&(c.typeInfo.format.name==="f16"?l[0].format=x.f16:c.typeInfo.format.name==="f32"?l[0].format=x.f32:c.typeInfo.format.name==="i32"?l[0].format=x.i32:c.typeInfo.format.name==="u32"?l[0].format=x.u32:c.typeInfo.format.name==="bool"?l[0].format=x.bool:console.error(`TODO: impelement template format type ${c.typeInfo.format.name}`)),s=this._updateNode(new R(c,l[0])),this._exec.context.setVariable(t.toString(),c)}catch{s=i}if(r!==null&&s instanceof R){if(s.type.name!=="x32"&&r.getTypeName()!==s.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${s.type.name} to ${r.name}. Line:${this._currentLine}`);s.type=r,s.isScalar&&this._validateTypeRange(s.scalarValue,s.type)}else r===null&&s instanceof R&&(r=(e=s?.type)!==null&&e!==void 0?e:x.f32,r===x.x32&&(r=x.i32));let o=this._updateNode(new ke(t.toString(),r,"","",s),n);return this._context.constants.set(o.name,o),o}_global_let_decl(){if(!this._match(f.keywords.let))return null;let e=this._currentLine,t=this._consume(f.tokens.name,"Expected variable name"),n=null;if(this._match(f.tokens.colon)){let s=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=s)}let r=null;if(this._match(f.tokens.equal)&&(r=this._const_expression()),n!==null&&r instanceof R){if(r.type.name!=="x32"&&n.getTypeName()!==r.type.getTypeName())throw this._error(this._peek(),`Invalid cast from ${r.type.name} to ${n.name}. Line:${this._currentLine}`);r.type=n}else n===null&&r instanceof R&&(n=r.type.name==="x32"?x.i32:r.type);return r instanceof R&&r.isScalar&&this._validateTypeRange(r.scalarValue,n),this._updateNode(new me(t.toString(),n,"","",r),e)}_const_expression(){return this._short_circuit_or_expression()}_variable_decl(){if(!this._match(f.keywords.var))return null;let e=this._currentLine,t="",n="";this._match(f.tokens.less_than)&&(t=this._consume(f.storage_class,"Expected storage_class.").toString(),this._match(f.tokens.comma)&&(n=this._consume(f.access_mode,"Expected access_mode.").toString()),this._consume(f.tokens.greater_than,"Expected '>'."));let r=this._consume(f.tokens.name,"Expected variable name"),s=null;if(this._match(f.tokens.colon)){let i=this._attribute();s=this._type_decl(),s!=null&&(s.attributes=i)}return this._updateNode(new ee(r.toString(),s,t,n,null),e)}_override_decl(){if(!this._match(f.keywords.override))return null;let e=this._consume(f.tokens.name,"Expected variable name"),t=null;if(this._match(f.tokens.colon)){let n=this._attribute();t=this._type_decl(),t!=null&&(t.attributes=n)}return this._updateNode(new Ve(e.toString(),t,null))}_diagnostic(){this._consume(f.tokens.paren_left,"Expected '('");let e=this._consume(f.tokens.ident,"Expected severity control name.");this._consume(f.tokens.comma,"Expected ','");let t=this._consume(f.tokens.ident,"Expected diagnostic rule name.").toString();return this._match(f.tokens.period)&&(t+=`.${this._consume(f.tokens.ident,"Expected diagnostic message.").toString()}`),this._consume(f.tokens.paren_right,"Expected ')'"),this._updateNode(new mt(e.toString(),t))}_enable_directive(){let e=this._consume(f.tokens.ident,"identity expected.");return this._updateNode(new Jt(e.toString()))}_requires_directive(){let e=[this._consume(f.tokens.ident,"identity expected.").toString()];for(;this._match(f.tokens.comma);){let t=this._consume(f.tokens.ident,"identity expected.");e.push(t.toString())}return this._updateNode(new en(e))}_type_alias(){let e=this._consume(f.tokens.ident,"identity expected.");this._consume(f.tokens.equal,"Expected '=' for type alias.");let t=this._type_decl();if(t===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(t.name)&&(t=this._context.aliases.get(t.name).type);let n=this._updateNode(new $e(e.toString(),t));return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([f.tokens.ident,...f.texel_format,f.keywords.bool,f.keywords.f32,f.keywords.i32,f.keywords.u32])){let n=this._advance().toString();if(this._context.structs.has(n))return this._context.structs.get(n);if(this._context.aliases.has(n))return this._context.aliases.get(n).type;if(!this._getType(n)){let r=this._updateNode(new vt(n));return this._forwardTypeCount++,r}return this._updateNode(new x(n))}let e=this._texture_sampler_types();if(e)return e;if(this._check(f.template_types)){let n=this._advance().toString(),r=null,s=null;return this._match(f.tokens.less_than)&&(r=this._type_decl(),s=null,this._match(f.tokens.comma)&&(s=this._consume(f.access_mode,"Expected access_mode for pointer").toString()),this._consume(f.tokens.greater_than,"Expected '>' for type.")),this._updateNode(new g(n,r,s))}if(this._match(f.keywords.ptr)){let n=this._previous().toString();this._consume(f.tokens.less_than,"Expected '<' for pointer.");let r=this._consume(f.storage_class,"Expected storage_class for pointer");this._consume(f.tokens.comma,"Expected ',' for pointer.");let s=this._type_decl(),i=null;return this._match(f.tokens.comma)&&(i=this._consume(f.access_mode,"Expected access_mode for pointer").toString()),this._consume(f.tokens.greater_than,"Expected '>' for pointer."),this._updateNode(new Re(n,r.toString(),s,i))}let t=this._attribute();if(this._match(f.keywords.array)){let n=null,r=-1,s=this._previous(),i=null;if(this._match(f.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let l="";if(this._match(f.tokens.comma)){i=this._shift_expression();try{l=i.constEvaluate(this._exec).toString(),i=null}catch{l="1"}}this._consume(f.tokens.greater_than,"Expected '>' for array."),r=l?parseInt(l):0}let o=this._updateNode(new _e(s.toString(),t,n,r));return i&&this._deferArrayCountEval.push({arrayType:o,countNode:i}),o}return null}_texture_sampler_types(){if(this._match(f.sampler_type))return this._updateNode(new de(this._previous().toString(),null,null));if(this._match(f.depth_texture_type))return this._updateNode(new de(this._previous().toString(),null,null));if(this._match(f.sampled_texture_type)||this._match(f.multisampled_texture_type)){let e=this._previous();this._consume(f.tokens.less_than,"Expected '<' for sampler type.");let t=this._type_decl();return this._consume(f.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new de(e.toString(),t,null))}if(this._match(f.storage_texture_type)){let e=this._previous();this._consume(f.tokens.less_than,"Expected '<' for sampler type.");let t=this._consume(f.texel_format,"Invalid texel format.").toString();this._consume(f.tokens.comma,"Expected ',' after texel format.");let n=this._consume(f.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(f.tokens.greater_than,"Expected '>' for sampler type."),this._updateNode(new de(e.toString(),t,n))}return null}_attribute(){let e=[];for(;this._match(f.tokens.attr);){let t=this._consume(f.attribute_name,"Expected attribute name"),n=this._updateNode(new Tt(t.toString(),null));if(this._match(f.tokens.paren_left)){if(n.value=this._consume(f.literal_or_ident,"Expected attribute value").toString(),this._check(f.tokens.comma)){this._advance();do{let r=this._consume(f.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(r)}while(this._match(f.tokens.comma))}this._consume(f.tokens.paren_right,"Expected ')'")}e.push(n)}return e.length==0?null:e}},Ot=class extends Z{constructor(e){super(),e&&this.update(e)}update(e){let t=new cn().parse(e);this.updateAST(t)}};function Jn(a){let e={attributes:[],bindings:[]},t;try{t=is(a)}catch(s){return Yn.log.error(s.message)(),e}for(let s of t.uniforms){let i=[];for(let o of s.type?.members||[])i.push({name:o.name,type:Qn(o.type)});e.bindings.push({type:"uniform",name:s.name,group:s.group,location:s.binding,members:i})}for(let s of t.textures)e.bindings.push({type:"texture",name:s.name,group:s.group,location:s.binding});for(let s of t.samplers)e.bindings.push({type:"sampler",name:s.name,group:s.group,location:s.binding});let n=t.entry.vertex[0],r=n?.inputs.length||0;for(let s=0;s<r;s++){let i=n.inputs[s];if(i.locationType==="location"){let o=Qn(i.type);e.attributes.push({name:i.name,location:Number(i.location),type:o})}}return e}function Qn(a){return a?.format?`${a.name}<${a.format.name}>`:a.name}function is(a){try{return new Ot(a)}catch(e){if(e instanceof Error)throw e;let t="WGSL parse error";throw typeof e=="object"&&e?.message&&(t+=`: ${e.message} `),typeof e=="object"&&e?.token&&(t+=e.token.line||""),new Error(t,{cause:e})}}var xo=1/Math.PI*180,yo=1/180*Math.PI,as={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...as}};var ls=globalThis.mathgl.config;function er(a){return Array.isArray(a)||ArrayBuffer.isView(a)&&!(a instanceof DataView)}function fn(a,e,t){return us(a,n=>Math.max(e,Math.min(t,n)))}function cs(a){return a.clone?a.clone():new Array(a.length)}function us(a,e,t){if(er(a)){let n=a;t=t||cs(n);for(let r=0;r<t.length&&r<n.length;++r){let s=typeof a=="number"?a:a[r];t[r]=e(s,r,t)}return t}return e(a)}var ve=null,tr=new ArrayBuffer(4),nr=new Float32Array(tr),rr=new Uint32Array(tr);function sr(a){ve||=ir(),a=fn(a,-65504,65504),nr[0]=a;let e=rr[0],t=e>>23&511;return ve.baseTable[t]+((e&8388607)>>ve.shiftTable[t])}function or(a){ve||=ir();let e=a>>10;return rr[0]=ve.mantissaTable[ve.offsetTable[e]+(a&1023)]+ve.exponentTable[e],nr[0]}function ir(){let a=new Uint32Array(512),e=new Uint32Array(512);for(let s=0;s<256;++s){let i=s-127;i<-27?(a[s]=0,a[s|256]=32768,e[s]=24,e[s|256]=24):i<-14?(a[s]=1024>>-i-14,a[s|256]=1024>>-i-14|32768,e[s]=-i-1,e[s|256]=-i-1):i<=15?(a[s]=i+15<<10,a[s|256]=i+15<<10|32768,e[s]=13,e[s|256]=13):i<128?(a[s]=31744,a[s|256]=64512,e[s]=24,e[s|256]=24):(a[s]=31744,a[s|256]=64512,e[s]=13,e[s|256]=13)}let t=new Uint32Array(2048),n=new Uint32Array(64),r=new Uint32Array(64);for(let s=1;s<1024;++s){let i=s<<13,o=0;for(;!(i&8388608);)i<<=1,o-=8388608;i&=-8388609,o+=947912704,t[s]=i|o}for(let s=1024;s<2048;++s)t[s]=939524096+(s-1024<<13);for(let s=1;s<31;++s)n[s]=s<<23;n[31]=1199570944,n[32]=2147483648;for(let s=33;s<63;++s)n[s]=2147483648+(s-32<<23);n[63]=3347054592;for(let s=1;s<64;++s)s!==32&&(r[s]=1024);return{baseTable:a,shiftTable:e,mantissaTable:t,exponentTable:n,offsetTable:r}}function Te(a,e=[],t=0){let n=Math.fround(a),r=a-n;return e[t]=n,e[t+1]=r,e}function je(a){return a-Math.fround(a)}function Xe(a){let e=new Float32Array(32);for(let t=0;t<4;++t)for(let n=0;n<4;++n){let r=t*4+n;Te(a[n*4+t],e,r*2)}return e}var fs=`fn random(scale: vec3f, seed: float) -> f32 {
103
- /* use the fragment position for a different seed per-pixel */
104
- return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
101
+ ${r} = ${i};
102
+ }`}function Dt(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 zt(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 qr(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 qe(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 Gt(e,t){return Kr(e,t)}function Kr(e,t){let n=[];switch(t.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":n.push(`layout(std140) uniform ${D(e.name)} {`);break;case"uniforms":}for(let[r,o]of Object.entries(e.uniformTypes||{})){if(typeof o!="string")throw new Error(`Composite uniform types are not supported by GLSL shader generation: ${e.name}.${r}`);let i=Yr(o);switch(t.uniforms){case"scoped-interface-blocks":n.push(` ${i} ${r};`);break;case"unscoped-interface-blocks":n.push(` ${i} ${e.name}_${r};`);break;case"uniforms":n.push(`uniform ${i} ${e.name}_${r};`)}}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(`
103
+ `)}function Yr(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 Xr(e,t)}function Xr(e,t){let n=[];n.push(`struct ${D(e.name)} {`);for(let[r,o]of Object.entries(e?.uniformTypes||{})){if(typeof o!="string")throw new Error(`Composite uniform types are not supported by WGSL shader generation: ${e.name}.${r}`);let i=o;n.push(` ${r} : ${i};`)}return n.push("};"),n.push(`var<uniform> ${e.name} : ${D(e.name)};`),n.join(`
104
+ `)}function $t(e,t){switch(t.shaderLanguage){case"glsl":return Gt(e,t);case"wgsl":return Ht(e,t)}}var wi=1/Math.PI*180,Bi=1/180*Math.PI,Zr={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Zr}};var y=globalThis.mathgl.config;function Ke(e,{precision:t=y.precision}={}){return e=Qr(e),`${parseFloat(e.toPrecision(t))}`}function j(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Ye(e,t,n){return eo(e,r=>Math.max(t,Math.min(n,r)))}function Me(e,t,n){let r=y.EPSILON;n&&(y.EPSILON=n);try{if(e===t)return!0;if(j(e)&&j(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(!Me(e[o],t[o]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=y.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{y.EPSILON=r}}function Qr(e){return Math.round(e/y.EPSILON)*y.EPSILON}function Jr(e){return e.clone?e.clone():new Array(e.length)}function eo(e,t,n){if(j(e)){let r=e;n=n||Jr(r);for(let o=0;o<n.length&&o<r.length;++o){let i=typeof e=="number"?e:e[o];n[o]=t(i,o,n)}return n}return t(e)}var Le=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,n=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=t[r+n];return this.check()}toArray(t=[],n=0){for(let r=0;r<this.ELEMENTS;++r)t[n+r]=this[r];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:j(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(y)}formatString(t){let n="";for(let r=0;r<this.ELEMENTS;++r)n+=(r>0?", ":"")+Ke(this[r],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(!Me(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,r){if(r===void 0)return this.lerp(this,t,n);for(let o=0;o<this.ELEMENTS;++o){let i=t[o],a=typeof n=="number"?n:n[o];this[o]=i+r*(a-i)}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 r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t[r]),n[r]);return this.check()}add(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]+=n[r];return this.check()}subtract(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]-=n[r];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(y.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let 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 r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t),n);return this.check()}get elements(){return this}};function to(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 Wt(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Re(e,t,n=""){if(y.debug&&!to(e,t))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return e}var w=typeof Float32Array<"u"?Float32Array:Array;var $i=Math.PI/180;function no(){let e=new w(2);return w!=Float32Array&&(e[0]=0,e[1]=0),e}function Kt(e,t,n){let r=t[0],o=t[1];return e[0]=n[0]*r+n[4]*o+n[12],e[1]=n[1]*r+n[5]*o+n[13],e}var Wi=function(){let e=no();return function(t,n,r,o,i,a){let s,c;for(n||(n=2),r||(r=0),o?c=Math.min(o*n+r,t.length):c=t.length,s=r;s<c;s+=n)e[0]=t[s],e[1]=t[s+1],i(e,e,a),t[s]=e[0],t[s+1]=e[1];return t}}();function Yt(e,t,n){let r=t[0],o=t[1],i=n[3]*r+n[7]*o||1;return e[0]=(n[0]*r+n[4]*o)/i,e[1]=(n[1]*r+n[5]*o)/i,e}function Xt(e,t,n){let r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i||1;return e[0]=(n[0]*r+n[4]*o+n[8]*i)/a,e[1]=(n[1]*r+n[5]*o+n[9]*i)/a,e[2]=(n[2]*r+n[6]*o+n[10]*i)/a,e}function ro(){let e=new w(3);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Zt(e,t,n){let r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*r+n[4]*o+n[8]*i+n[12])/a,e[1]=(n[1]*r+n[5]*o+n[9]*i+n[13])/a,e[2]=(n[2]*r+n[6]*o+n[10]*i+n[14])/a,e}var Ki=function(){let e=ro();return function(t,n,r,o,i,a){let s,c;for(n||(n=3),r||(r=0),o?c=Math.min(o*n+r,t.length):c=t.length,s=r;s<c;s+=n)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2];return t}}();var Ee=class extends Le{toString(){let t="[";if(y.printRowMajor){t+="row-major:";for(let n=0;n<this.RANK;++n)for(let r=0;r<this.RANK;++r)t+=` ${this[r*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,r){return this[n*this.RANK+t]=Wt(r),this}getColumn(t,n=new Array(this.RANK).fill(-0)){let r=t*this.RANK;for(let o=0;o<this.RANK;++o)n[o]=this[r+o];return n}setColumn(t,n){let r=t*this.RANK;for(let o=0;o<this.RANK;++o)this[r+o]=n[o];return this}};function oo(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 Qt(e,t){if(e===t){let n=t[1],r=t[2],o=t[3],i=t[6],a=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=i,e[11]=t[14],e[12]=o,e[13]=a,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function Jt(e,t){let n=t[0],r=t[1],o=t[2],i=t[3],a=t[4],s=t[5],c=t[6],l=t[7],p=t[8],f=t[9],u=t[10],h=t[11],m=t[12],S=t[13],x=t[14],_=t[15],L=n*s-r*a,d=n*c-o*a,b=n*l-i*a,v=r*c-o*s,g=r*l-i*s,M=o*l-i*c,A=p*S-f*m,R=p*x-u*m,I=p*_-h*m,P=f*x-u*S,C=f*_-h*S,O=u*_-h*x,E=L*O-d*C+b*P+v*I-g*R+M*A;return E?(E=1/E,e[0]=(s*O-c*C+l*P)*E,e[1]=(o*C-r*O-i*P)*E,e[2]=(S*M-x*g+_*v)*E,e[3]=(u*g-f*M-h*v)*E,e[4]=(c*I-a*O-l*R)*E,e[5]=(n*O-o*I+i*R)*E,e[6]=(x*b-m*M-_*d)*E,e[7]=(p*M-u*b+h*d)*E,e[8]=(a*C-s*I+l*A)*E,e[9]=(r*I-n*C-i*A)*E,e[10]=(m*g-S*b+_*L)*E,e[11]=(f*b-p*g-h*L)*E,e[12]=(s*R-a*P-c*A)*E,e[13]=(n*P-r*R+o*A)*E,e[14]=(S*d-m*v-x*L)*E,e[15]=(p*v-f*d+u*L)*E,e):null}function en(e){let t=e[0],n=e[1],r=e[2],o=e[3],i=e[4],a=e[5],s=e[6],c=e[7],l=e[8],p=e[9],f=e[10],u=e[11],h=e[12],m=e[13],S=e[14],x=e[15],_=t*a-n*i,L=t*s-r*i,d=n*s-r*a,b=l*m-p*h,v=l*S-f*h,g=p*S-f*m,M=t*g-n*v+r*b,A=i*g-a*v+s*b,R=l*d-p*L+f*_,I=h*d-m*L+S*_;return c*M-o*A+x*R-u*I}function Ze(e,t,n){let r=t[0],o=t[1],i=t[2],a=t[3],s=t[4],c=t[5],l=t[6],p=t[7],f=t[8],u=t[9],h=t[10],m=t[11],S=t[12],x=t[13],_=t[14],L=t[15],d=n[0],b=n[1],v=n[2],g=n[3];return e[0]=d*r+b*s+v*f+g*S,e[1]=d*o+b*c+v*u+g*x,e[2]=d*i+b*l+v*h+g*_,e[3]=d*a+b*p+v*m+g*L,d=n[4],b=n[5],v=n[6],g=n[7],e[4]=d*r+b*s+v*f+g*S,e[5]=d*o+b*c+v*u+g*x,e[6]=d*i+b*l+v*h+g*_,e[7]=d*a+b*p+v*m+g*L,d=n[8],b=n[9],v=n[10],g=n[11],e[8]=d*r+b*s+v*f+g*S,e[9]=d*o+b*c+v*u+g*x,e[10]=d*i+b*l+v*h+g*_,e[11]=d*a+b*p+v*m+g*L,d=n[12],b=n[13],v=n[14],g=n[15],e[12]=d*r+b*s+v*f+g*S,e[13]=d*o+b*c+v*u+g*x,e[14]=d*i+b*l+v*h+g*_,e[15]=d*a+b*p+v*m+g*L,e}function tn(e,t,n){let r=n[0],o=n[1],i=n[2],a,s,c,l,p,f,u,h,m,S,x,_;return t===e?(e[12]=t[0]*r+t[4]*o+t[8]*i+t[12],e[13]=t[1]*r+t[5]*o+t[9]*i+t[13],e[14]=t[2]*r+t[6]*o+t[10]*i+t[14],e[15]=t[3]*r+t[7]*o+t[11]*i+t[15]):(a=t[0],s=t[1],c=t[2],l=t[3],p=t[4],f=t[5],u=t[6],h=t[7],m=t[8],S=t[9],x=t[10],_=t[11],e[0]=a,e[1]=s,e[2]=c,e[3]=l,e[4]=p,e[5]=f,e[6]=u,e[7]=h,e[8]=m,e[9]=S,e[10]=x,e[11]=_,e[12]=a*r+p*o+m*i+t[12],e[13]=s*r+f*o+S*i+t[13],e[14]=c*r+u*o+x*i+t[14],e[15]=l*r+h*o+_*i+t[15]),e}function nn(e,t,n){let r=n[0],o=n[1],i=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*o,e[5]=t[5]*o,e[6]=t[6]*o,e[7]=t[7]*o,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function rn(e,t,n,r){let o=r[0],i=r[1],a=r[2],s=Math.sqrt(o*o+i*i+a*a),c,l,p,f,u,h,m,S,x,_,L,d,b,v,g,M,A,R,I,P,C,O,E,Y;return s<1e-6?null:(s=1/s,o*=s,i*=s,a*=s,l=Math.sin(n),c=Math.cos(n),p=1-c,f=t[0],u=t[1],h=t[2],m=t[3],S=t[4],x=t[5],_=t[6],L=t[7],d=t[8],b=t[9],v=t[10],g=t[11],M=o*o*p+c,A=i*o*p+a*l,R=a*o*p-i*l,I=o*i*p-a*l,P=i*i*p+c,C=a*i*p+o*l,O=o*a*p+i*l,E=i*a*p-o*l,Y=a*a*p+c,e[0]=f*M+S*A+d*R,e[1]=u*M+x*A+b*R,e[2]=h*M+_*A+v*R,e[3]=m*M+L*A+g*R,e[4]=f*I+S*P+d*C,e[5]=u*I+x*P+b*C,e[6]=h*I+_*P+v*C,e[7]=m*I+L*P+g*C,e[8]=f*O+S*E+d*Y,e[9]=u*O+x*E+b*Y,e[10]=h*O+_*E+v*Y,e[11]=m*O+L*E+g*Y,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function on(e,t,n){let r=Math.sin(n),o=Math.cos(n),i=t[4],a=t[5],s=t[6],c=t[7],l=t[8],p=t[9],f=t[10],u=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*o+l*r,e[5]=a*o+p*r,e[6]=s*o+f*r,e[7]=c*o+u*r,e[8]=l*o-i*r,e[9]=p*o-a*r,e[10]=f*o-s*r,e[11]=u*o-c*r,e}function an(e,t,n){let r=Math.sin(n),o=Math.cos(n),i=t[0],a=t[1],s=t[2],c=t[3],l=t[8],p=t[9],f=t[10],u=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o-l*r,e[1]=a*o-p*r,e[2]=s*o-f*r,e[3]=c*o-u*r,e[8]=i*r+l*o,e[9]=a*r+p*o,e[10]=s*r+f*o,e[11]=c*r+u*o,e}function sn(e,t,n){let r=Math.sin(n),o=Math.cos(n),i=t[0],a=t[1],s=t[2],c=t[3],l=t[4],p=t[5],f=t[6],u=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o+l*r,e[1]=a*o+p*r,e[2]=s*o+f*r,e[3]=c*o+u*r,e[4]=l*o-i*r,e[5]=p*o-a*r,e[6]=f*o-s*r,e[7]=u*o-c*r,e}function cn(e,t){let n=t[0],r=t[1],o=t[2],i=t[3],a=n+n,s=r+r,c=o+o,l=n*a,p=r*a,f=r*s,u=o*a,h=o*s,m=o*c,S=i*a,x=i*s,_=i*c;return e[0]=1-f-m,e[1]=p+_,e[2]=u-x,e[3]=0,e[4]=p-_,e[5]=1-l-m,e[6]=h+S,e[7]=0,e[8]=u+x,e[9]=h-S,e[10]=1-l-f,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function ln(e,t,n,r,o,i,a){let s=1/(n-t),c=1/(o-r),l=1/(i-a);return e[0]=i*2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i*2*c,e[6]=0,e[7]=0,e[8]=(n+t)*s,e[9]=(o+r)*c,e[10]=(a+i)*l,e[11]=-1,e[12]=0,e[13]=0,e[14]=a*i*2*l,e[15]=0,e}function io(e,t,n,r,o){let i=1/Math.tan(t/2);if(e[0]=i/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,o!=null&&o!==1/0){let a=1/(r-o);e[10]=(o+r)*a,e[14]=2*o*r*a}else e[10]=-1,e[14]=-2*r;return e}var fn=io;function ao(e,t,n,r,o,i,a){let s=1/(t-n),c=1/(r-o),l=1/(i-a);return e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+n)*s,e[13]=(o+r)*c,e[14]=(a+i)*l,e[15]=1,e}var pn=ao;function un(e,t,n,r){let o,i,a,s,c,l,p,f,u,h,m=t[0],S=t[1],x=t[2],_=r[0],L=r[1],d=r[2],b=n[0],v=n[1],g=n[2];return Math.abs(m-b)<1e-6&&Math.abs(S-v)<1e-6&&Math.abs(x-g)<1e-6?oo(e):(f=m-b,u=S-v,h=x-g,o=1/Math.sqrt(f*f+u*u+h*h),f*=o,u*=o,h*=o,i=L*h-d*u,a=d*f-_*h,s=_*u-L*f,o=Math.sqrt(i*i+a*a+s*s),o?(o=1/o,i*=o,a*=o,s*=o):(i=0,a=0,s=0),c=u*s-h*a,l=h*i-f*s,p=f*a-u*i,o=Math.sqrt(c*c+l*l+p*p),o?(o=1/o,c*=o,l*=o,p*=o):(c=0,l=0,p=0),e[0]=i,e[1]=c,e[2]=f,e[3]=0,e[4]=a,e[5]=l,e[6]=u,e[7]=0,e[8]=s,e[9]=p,e[10]=h,e[11]=0,e[12]=-(i*m+a*S+s*x),e[13]=-(c*m+l*S+p*x),e[14]=-(f*m+u*S+h*x),e[15]=1,e)}function so(){let e=new w(4);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function hn(e,t,n){let r=t[0],o=t[1],i=t[2],a=t[3];return e[0]=n[0]*r+n[4]*o+n[8]*i+n[12]*a,e[1]=n[1]*r+n[5]*o+n[9]*i+n[13]*a,e[2]=n[2]*r+n[6]*o+n[10]*i+n[14]*a,e[3]=n[3]*r+n[7]*o+n[11]*i+n[15]*a,e}var ta=function(){let e=so();return function(t,n,r,o,i,a){let s,c;for(n||(n=4),r||(r=0),o?c=Math.min(o*n+r,t.length):c=t.length,s=r;s<c;s+=n)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],e[3]=t[s+3],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2],t[s+3]=e[3];return t}}();var et;(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"})(et||(et={}));var co=45*Math.PI/180,lo=1,Qe=.1,Je=500,fo=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),B=class extends Ee{static get IDENTITY(){return uo()}static get ZERO(){return po()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return et}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,r,o,i,a,s,c,l,p,f,u,h,m,S,x){return this[0]=t,this[1]=n,this[2]=r,this[3]=o,this[4]=i,this[5]=a,this[6]=s,this[7]=c,this[8]=l,this[9]=p,this[10]=f,this[11]=u,this[12]=h,this[13]=m,this[14]=S,this[15]=x,this.check()}setRowMajor(t,n,r,o,i,a,s,c,l,p,f,u,h,m,S,x){return this[0]=t,this[1]=i,this[2]=l,this[3]=h,this[4]=n,this[5]=a,this[6]=p,this[7]=m,this[8]=r,this[9]=s,this[10]=f,this[11]=S,this[12]=o,this[13]=c,this[14]=u,this[15]=x,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(fo)}fromObject(t){return this.check()}fromQuaternion(t){return cn(this,t),this.check()}frustum(t){let{left:n,right:r,bottom:o,top:i,near:a=Qe,far:s=Je}=t;return s===1/0?ho(this,n,r,o,i,a):ln(this,n,r,o,i,a,s),this.check()}lookAt(t){let{eye:n,center:r=[0,0,0],up:o=[0,1,0]}=t;return un(this,n,r,o),this.check()}ortho(t){let{left:n,right:r,bottom:o,top:i,near:a=Qe,far:s=Je}=t;return pn(this,n,r,o,i,a,s),this.check()}orthographic(t){let{fovy:n=co,aspect:r=lo,focalDistance:o=1,near:i=Qe,far:a=Je}=t;gn(n);let s=n/2,c=o*Math.tan(s),l=c*r;return this.ortho({left:-l,right:l,bottom:-c,top:c,near:i,far:a})}perspective(t){let{fovy:n=45*Math.PI/180,aspect:r=1,near:o=.1,far:i=500}=t;return gn(n),fn(this,n,r,o,i),this.check()}determinant(){return en(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 r=this.getScale(n),o=1/r[0],i=1/r[1],a=1/r[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=0,t[4]=this[4]*o,t[5]=this[5]*i,t[6]=this[6]*a,t[7]=0,t[8]=this[8]*o,t[9]=this[9]*i,t[10]=this[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),o=1/r[0],i=1/r[1],a=1/r[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=this[4]*o,t[4]=this[5]*i,t[5]=this[6]*a,t[6]=this[8]*o,t[7]=this[9]*i,t[8]=this[10]*a,t}transpose(){return Qt(this,this),this.check()}invert(){return Jt(this,this),this.check()}multiplyLeft(t){return Ze(this,t,this),this.check()}multiplyRight(t){return Ze(this,this,t),this.check()}rotateX(t){return on(this,this,t),this.check()}rotateY(t){return an(this,this,t),this.check()}rotateZ(t){return sn(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,n){return rn(this,this,t,n),this.check()}scale(t){return nn(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return tn(this,this,t),this.check()}transform(t,n){return t.length===4?(n=hn(n||[-0,-0,-0,-0],t,this),Re(n,4),n):this.transformAsPoint(t,n)}transformAsPoint(t,n){let{length:r}=t,o;switch(r){case 2:o=Kt(n||[-0,-0],t,this);break;case 3:o=Zt(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Re(o,t.length),o}transformAsVector(t,n){let r;switch(t.length){case 2:r=Yt(n||[-0,-0],t,this);break;case 3:r=Xt(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Re(r,t.length),r}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,r){return this.identity().translate([t,n,r])}},Ae,Ie;function po(){return Ae||(Ae=new B([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Ae)),Ae}function uo(){return Ie||(Ie=new B,Object.freeze(Ie)),Ie}function gn(e){if(e>Math.PI*2)throw Error("expected radians")}function ho(e,t,n,r,o,i){let a=2*i/(n-t),s=2*i/(o-r),c=(n+t)/(n-t),l=(o+r)/(o-r),p=-1,f=-1,u=-2*i;return e[0]=a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=c,e[9]=l,e[10]=p,e[11]=f,e[12]=0,e[13]=0,e[14]=u,e[15]=0,e}var z=null,mn=new ArrayBuffer(4),dn=new Float32Array(mn),_n=new Uint32Array(mn);function bn(e){z||=Sn(),e=Ye(e,-65504,65504),dn[0]=e;let t=_n[0],n=t>>23&511;return z.baseTable[n]+((t&8388607)>>z.shiftTable[n])}function vn(e){z||=Sn();let t=e>>10;return _n[0]=z.mantissaTable[z.offsetTable[t]+(e&1023)]+z.exponentTable[t],dn[0]}function Sn(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let i=0;i<256;++i){let a=i-127;a<-27?(e[i]=0,e[i|256]=32768,t[i]=24,t[i|256]=24):a<-14?(e[i]=1024>>-a-14,e[i|256]=1024>>-a-14|32768,t[i]=-a-1,t[i|256]=-a-1):a<=15?(e[i]=a+15<<10,e[i|256]=a+15<<10|32768,t[i]=13,t[i|256]=13):a<128?(e[i]=31744,e[i|256]=64512,t[i]=24,t[i|256]=24):(e[i]=31744,e[i|256]=64512,t[i]=13,t[i|256]=13)}let n=new Uint32Array(2048),r=new Uint32Array(64),o=new Uint32Array(64);for(let i=1;i<1024;++i){let a=i<<13,s=0;for(;!(a&8388608);)a<<=1,s-=8388608;a&=-8388609,s+=947912704,n[i]=a|s}for(let i=1024;i<2048;++i)n[i]=939524096+(i-1024<<13);for(let i=1;i<31;++i)r[i]=i<<23;r[31]=1199570944,r[32]=2147483648;for(let i=33;i<63;++i)r[i]=2147483648+(i-32<<23);r[63]=3347054592;for(let i=1;i<64;++i)i!==32&&(o[i]=1024);return{baseTable:e,shiftTable:t,mantissaTable:n,exponentTable:r,offsetTable:o}}function K(e,t=[],n=0){let r=Math.fround(e),o=e-r;return t[n]=r,t[n+1]=o,t}function oe(e){return e-Math.fround(e)}function ie(e){let t=new Float32Array(32);for(let n=0;n<4;++n)for(let r=0;r<4;++r){let o=n*4+r;K(e[r*4+n],t,o*2)}return t}var go=`fn random(scale: vec3f, seed: f32) -> f32 {
105
+ return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
105
106
  }
106
- `,hs=`float random(vec3 scale, float seed) {
107
+ `,mo=`float random(vec3 scale, float seed) {
107
108
  /* use the fragment position for a different seed per-pixel */
108
109
  return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
109
110
  }
110
- `,ar={name:"random",source:fs,fs:hs};var ps=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
111
+ `,xn={name:"random",source:go,fs:mo};var _o=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
111
112
 
112
113
  // All these functions are for substituting tan() function from Intel GPU only
113
114
  const float TWO_PI = 6.2831854820251465;
@@ -257,9 +258,10 @@ float tan_fp32(float a) {
257
258
  return tan(a);
258
259
  #endif
259
260
  }
260
- `,lr={name:"fp32",vs:ps};var cr=`
261
- uniform fp64arithmeticUniforms {
261
+ `,Mn={name:"fp32",vs:_o};var tt=`
262
+ layout(std140) uniform fp64arithmeticUniforms {
262
263
  uniform float ONE;
264
+ uniform float SPLIT;
263
265
  } fp64;
264
266
 
265
267
  /*
@@ -269,6 +271,12 @@ The purpose of this workaround is to prevent shader compilers from
269
271
  optimizing away necessary arithmetic operations by swapping their sequences
270
272
  or transform the equation to some 'equivalent' form.
271
273
 
274
+ These helpers implement Dekker/Veltkamp-style error tracking. If the compiler
275
+ folds constants or reassociates the arithmetic, the high/low split can stop
276
+ tracking the rounding error correctly. That failure mode tends to look fine in
277
+ simple coordinate setup, but then breaks down inside iterative arithmetic such
278
+ as fp64 Mandelbrot loops.
279
+
272
280
  The method is to multiply an artifical variable, ONE, which will be known to
273
281
  the compiler to be 1 only at runtime. The whole expression is then represented
274
282
  as a polynomial with respective to ONE. In the coefficients of all terms, only one a
@@ -277,17 +285,23 @@ and one b should appear
277
285
  err = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE
278
286
  */
279
287
 
280
- // Divide float number to high and low floats to extend fraction bits
281
- vec2 split(float a) {
282
- const float SPLIT = 4097.0;
283
- float t = a * SPLIT;
288
+ float prevent_fp64_optimization(float value) {
284
289
  #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
285
- float a_hi = t * fp64.ONE - (t - a);
286
- float a_lo = a * fp64.ONE - a_hi;
290
+ return value + fp64.ONE * 0.0;
287
291
  #else
288
- float a_hi = t - (t - a);
289
- float a_lo = a - a_hi;
292
+ return value;
290
293
  #endif
294
+ }
295
+
296
+ // Divide float number to high and low floats to extend fraction bits
297
+ vec2 split(float a) {
298
+ // Keep SPLIT as a runtime uniform so the compiler cannot fold the Dekker
299
+ // split into a constant expression and reassociate the recovery steps.
300
+ float split = prevent_fp64_optimization(fp64.SPLIT);
301
+ float t = prevent_fp64_optimization(a * split);
302
+ float temp = t - a;
303
+ float a_hi = t - temp;
304
+ float a_lo = a - a_hi;
291
305
  return vec2(a_hi, a_lo);
292
306
  }
293
307
 
@@ -351,8 +365,26 @@ vec2 twoProd(float a, float b) {
351
365
  float prod = a * b;
352
366
  vec2 a_fp64 = split(a);
353
367
  vec2 b_fp64 = split(b);
354
- float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +
355
- a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;
368
+ // twoProd is especially sensitive because mul_fp64 and div_fp64 both depend
369
+ // on the split terms and cross terms staying in the original evaluation
370
+ // order. If the compiler folds or reassociates them, the low part tends to
371
+ // collapse to zero or NaN on some drivers.
372
+ float highProduct = prevent_fp64_optimization(a_fp64.x * b_fp64.x);
373
+ float crossProduct1 = prevent_fp64_optimization(a_fp64.x * b_fp64.y);
374
+ float crossProduct2 = prevent_fp64_optimization(a_fp64.y * b_fp64.x);
375
+ float lowProduct = prevent_fp64_optimization(a_fp64.y * b_fp64.y);
376
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
377
+ float err1 = (highProduct - prod) * fp64.ONE;
378
+ float err2 = crossProduct1 * fp64.ONE * fp64.ONE;
379
+ float err3 = crossProduct2 * fp64.ONE * fp64.ONE * fp64.ONE;
380
+ float err4 = lowProduct * fp64.ONE * fp64.ONE * fp64.ONE * fp64.ONE;
381
+ #else
382
+ float err1 = highProduct - prod;
383
+ float err2 = crossProduct1;
384
+ float err3 = crossProduct2;
385
+ float err4 = lowProduct;
386
+ #endif
387
+ float err = ((err1 + err2) + err3) + err4;
356
388
  return vec2(prod, err);
357
389
  }
358
390
 
@@ -425,7 +457,213 @@ vec2 sqrt_fp64(vec2 a) {
425
457
  return sum_fp64(vec2(yn, 0.0), prod);
426
458
  #endif
427
459
  }
428
- `;var ur=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
460
+ `;var Ln=`struct Fp64ArithmeticUniforms {
461
+ ONE: f32,
462
+ SPLIT: f32,
463
+ };
464
+
465
+ @group(0) @binding(auto) var<uniform> fp64arithmetic : Fp64ArithmeticUniforms;
466
+
467
+ fn fp64_nan(seed: f32) -> f32 {
468
+ let nanBits = 0x7fc00000u | select(0u, 1u, seed < 0.0);
469
+ return bitcast<f32>(nanBits);
470
+ }
471
+
472
+ fn fp64_runtime_zero() -> f32 {
473
+ return fp64arithmetic.ONE * 0.0;
474
+ }
475
+
476
+ fn prevent_fp64_optimization(value: f32) -> f32 {
477
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
478
+ return value + fp64_runtime_zero();
479
+ #else
480
+ return value;
481
+ #endif
482
+ }
483
+
484
+ fn split(a: f32) -> vec2f {
485
+ let splitValue = prevent_fp64_optimization(fp64arithmetic.SPLIT + fp64_runtime_zero());
486
+ let t = prevent_fp64_optimization(a * splitValue);
487
+ let temp = prevent_fp64_optimization(t - a);
488
+ let aHi = prevent_fp64_optimization(t - temp);
489
+ let aLo = prevent_fp64_optimization(a - aHi);
490
+ return vec2f(aHi, aLo);
491
+ }
492
+
493
+ fn split2(a: vec2f) -> vec2f {
494
+ var b = split(a.x);
495
+ b.y = b.y + a.y;
496
+ return b;
497
+ }
498
+
499
+ fn quickTwoSum(a: f32, b: f32) -> vec2f {
500
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
501
+ let sum = prevent_fp64_optimization((a + b) * fp64arithmetic.ONE);
502
+ let err = prevent_fp64_optimization(b - (sum - a) * fp64arithmetic.ONE);
503
+ #else
504
+ let sum = prevent_fp64_optimization(a + b);
505
+ let err = prevent_fp64_optimization(b - (sum - a));
506
+ #endif
507
+ return vec2f(sum, err);
508
+ }
509
+
510
+ fn twoSum(a: f32, b: f32) -> vec2f {
511
+ let s = prevent_fp64_optimization(a + b);
512
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
513
+ let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
514
+ let err =
515
+ prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
516
+ fp64arithmetic.ONE *
517
+ fp64arithmetic.ONE *
518
+ fp64arithmetic.ONE) +
519
+ prevent_fp64_optimization(b - v);
520
+ #else
521
+ let v = prevent_fp64_optimization(s - a);
522
+ let err = prevent_fp64_optimization(a - (s - v)) + prevent_fp64_optimization(b - v);
523
+ #endif
524
+ return vec2f(s, err);
525
+ }
526
+
527
+ fn twoSub(a: f32, b: f32) -> vec2f {
528
+ let s = prevent_fp64_optimization(a - b);
529
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
530
+ let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
531
+ let err =
532
+ prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
533
+ fp64arithmetic.ONE *
534
+ fp64arithmetic.ONE *
535
+ fp64arithmetic.ONE) -
536
+ prevent_fp64_optimization(b + v);
537
+ #else
538
+ let v = prevent_fp64_optimization(s - a);
539
+ let err = prevent_fp64_optimization(a - (s - v)) - prevent_fp64_optimization(b + v);
540
+ #endif
541
+ return vec2f(s, err);
542
+ }
543
+
544
+ fn twoSqr(a: f32) -> vec2f {
545
+ let prod = prevent_fp64_optimization(a * a);
546
+ let aFp64 = split(a);
547
+ let highProduct = prevent_fp64_optimization(aFp64.x * aFp64.x);
548
+ let crossProduct = prevent_fp64_optimization(2.0 * aFp64.x * aFp64.y);
549
+ let lowProduct = prevent_fp64_optimization(aFp64.y * aFp64.y);
550
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
551
+ let err =
552
+ (prevent_fp64_optimization(highProduct - prod) * fp64arithmetic.ONE +
553
+ crossProduct * fp64arithmetic.ONE * fp64arithmetic.ONE) +
554
+ lowProduct * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
555
+ #else
556
+ let err = ((prevent_fp64_optimization(highProduct - prod) + crossProduct) + lowProduct);
557
+ #endif
558
+ return vec2f(prod, err);
559
+ }
560
+
561
+ fn twoProd(a: f32, b: f32) -> vec2f {
562
+ let prod = prevent_fp64_optimization(a * b);
563
+ let aFp64 = split(a);
564
+ let bFp64 = split(b);
565
+ let highProduct = prevent_fp64_optimization(aFp64.x * bFp64.x);
566
+ let crossProduct1 = prevent_fp64_optimization(aFp64.x * bFp64.y);
567
+ let crossProduct2 = prevent_fp64_optimization(aFp64.y * bFp64.x);
568
+ let lowProduct = prevent_fp64_optimization(aFp64.y * bFp64.y);
569
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
570
+ let err1 = (highProduct - prod) * fp64arithmetic.ONE;
571
+ let err2 = crossProduct1 * fp64arithmetic.ONE * fp64arithmetic.ONE;
572
+ let err3 = crossProduct2 * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
573
+ let err4 =
574
+ lowProduct *
575
+ fp64arithmetic.ONE *
576
+ fp64arithmetic.ONE *
577
+ fp64arithmetic.ONE *
578
+ fp64arithmetic.ONE;
579
+ #else
580
+ let err1 = highProduct - prod;
581
+ let err2 = crossProduct1;
582
+ let err3 = crossProduct2;
583
+ let err4 = lowProduct;
584
+ #endif
585
+ let err12InputA = prevent_fp64_optimization(err1);
586
+ let err12InputB = prevent_fp64_optimization(err2);
587
+ let err12 = prevent_fp64_optimization(err12InputA + err12InputB);
588
+ let err123InputA = prevent_fp64_optimization(err12);
589
+ let err123InputB = prevent_fp64_optimization(err3);
590
+ let err123 = prevent_fp64_optimization(err123InputA + err123InputB);
591
+ let err1234InputA = prevent_fp64_optimization(err123);
592
+ let err1234InputB = prevent_fp64_optimization(err4);
593
+ let err = prevent_fp64_optimization(err1234InputA + err1234InputB);
594
+ return vec2f(prod, err);
595
+ }
596
+
597
+ fn sum_fp64(a: vec2f, b: vec2f) -> vec2f {
598
+ var s = twoSum(a.x, b.x);
599
+ let t = twoSum(a.y, b.y);
600
+ s.y = prevent_fp64_optimization(s.y + t.x);
601
+ s = quickTwoSum(s.x, s.y);
602
+ s.y = prevent_fp64_optimization(s.y + t.y);
603
+ s = quickTwoSum(s.x, s.y);
604
+ return s;
605
+ }
606
+
607
+ fn sub_fp64(a: vec2f, b: vec2f) -> vec2f {
608
+ var s = twoSub(a.x, b.x);
609
+ let t = twoSub(a.y, b.y);
610
+ s.y = prevent_fp64_optimization(s.y + t.x);
611
+ s = quickTwoSum(s.x, s.y);
612
+ s.y = prevent_fp64_optimization(s.y + t.y);
613
+ s = quickTwoSum(s.x, s.y);
614
+ return s;
615
+ }
616
+
617
+ fn mul_fp64(a: vec2f, b: vec2f) -> vec2f {
618
+ var prod = twoProd(a.x, b.x);
619
+ let crossProduct1 = prevent_fp64_optimization(a.x * b.y);
620
+ prod.y = prevent_fp64_optimization(prod.y + crossProduct1);
621
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
622
+ prod = split2(prod);
623
+ #endif
624
+ prod = quickTwoSum(prod.x, prod.y);
625
+ let crossProduct2 = prevent_fp64_optimization(a.y * b.x);
626
+ prod.y = prevent_fp64_optimization(prod.y + crossProduct2);
627
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
628
+ prod = split2(prod);
629
+ #endif
630
+ prod = quickTwoSum(prod.x, prod.y);
631
+ return prod;
632
+ }
633
+
634
+ fn div_fp64(a: vec2f, b: vec2f) -> vec2f {
635
+ let xn = prevent_fp64_optimization(1.0 / b.x);
636
+ let yn = mul_fp64(a, vec2f(xn, fp64_runtime_zero()));
637
+ let diff = prevent_fp64_optimization(sub_fp64(a, mul_fp64(b, yn)).x);
638
+ let prod = twoProd(xn, diff);
639
+ return sum_fp64(yn, prod);
640
+ }
641
+
642
+ fn sqrt_fp64(a: vec2f) -> vec2f {
643
+ if (a.x == 0.0 && a.y == 0.0) {
644
+ return vec2f(0.0, 0.0);
645
+ }
646
+ if (a.x < 0.0) {
647
+ let nanValue = fp64_nan(a.x);
648
+ return vec2f(nanValue, nanValue);
649
+ }
650
+
651
+ let x = prevent_fp64_optimization(1.0 / sqrt(a.x));
652
+ let yn = prevent_fp64_optimization(a.x * x);
653
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
654
+ let ynSqr = twoSqr(yn) * fp64arithmetic.ONE;
655
+ #else
656
+ let ynSqr = twoSqr(yn);
657
+ #endif
658
+ let diff = prevent_fp64_optimization(sub_fp64(a, ynSqr).x);
659
+ let prod = twoProd(prevent_fp64_optimization(x * 0.5), diff);
660
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
661
+ return sum_fp64(split(yn), prod);
662
+ #else
663
+ return sum_fp64(vec2f(yn, 0.0), prod);
664
+ #endif
665
+ }
666
+ `;var Rn=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
429
667
  const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
430
668
  const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
431
669
  const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
@@ -1094,7 +1332,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
1094
1332
  vec4_dot_fp64(a, tmp, out_val[i]);
1095
1333
  }
1096
1334
  }
1097
- `;var ds={ONE:1},hn={name:"fp64arithmetic",vs:cr,defaultUniforms:ds,uniformTypes:{ONE:"f32"},fp64ify:Te,fp64LowPart:je,fp64ifyMatrix4:Xe},fr={name:"fp64",vs:ur,dependencies:[hn],fp64ify:Te,fp64LowPart:je,fp64ifyMatrix4:Xe};var ms=[0,1,1,1],_s=`uniform pickingUniforms {
1335
+ `;var bo={ONE:1,SPLIT:4097},nt={name:"fp64arithmetic",source:Ln,fs:tt,vs:tt,defaultUniforms:bo,uniformTypes:{ONE:"f32",SPLIT:"f32"},fp64ify:K,fp64LowPart:oe,fp64ifyMatrix4:ie},En={name:"fp64",vs:Rn,dependencies:[nt],fp64ify:K,fp64LowPart:oe,fp64ifyMatrix4:ie};var vo=[0,1,1,1],So=`layout(std140) uniform pickingUniforms {
1098
1336
  float isActive;
1099
1337
  float isAttribute;
1100
1338
  float isHighlightActive;
@@ -1165,7 +1403,7 @@ void picking_setPickingAttribute(vec3 value) {
1165
1403
  picking_vRGBcolor_Avalid.rgb = value;
1166
1404
  }
1167
1405
  }
1168
- `,gs=`uniform pickingUniforms {
1406
+ `,xo=`layout(std140) uniform pickingUniforms {
1169
1407
  float isActive;
1170
1408
  float isAttribute;
1171
1409
  float isHighlightActive;
@@ -1221,7 +1459,32 @@ vec4 picking_filterColor(vec4 color) {
1221
1459
  vec4 highlightColor = picking_filterHighlightColor(color);
1222
1460
  return picking_filterPickingColor(highlightColor);
1223
1461
  }
1224
- `,hr={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:ms},vs:_s,fs:gs,getUniforms:vs};function vs(a={},e){let t={};if(a.highlightedObjectColor!==void 0)if(a.highlightedObjectColor===null)t.isHighlightActive=!1;else{t.isHighlightActive=!0;let n=a.highlightedObjectColor.slice(0,3);t.highlightedObjectColor=n}if(a.highlightColor){let n=Array.from(a.highlightColor,r=>r/255);Number.isFinite(n[3])||(n[3]=1),t.highlightColor=n}return a.isActive!==void 0&&(t.isActive=Boolean(a.isActive),t.isAttribute=Boolean(a.isAttribute)),a.useFloatColors!==void 0&&(t.useFloatColors=Boolean(a.useFloatColors)),t}var dr=Rt(Je(),1);var pn=`precision highp int;
1462
+ `,An={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:vo},vs:So,fs:xo,getUniforms:Mo};function Mo(e={},t){let n={};if(e.highlightedObjectColor!==void 0)if(e.highlightedObjectColor===null)n.isHighlightActive=!1;else{n.isHighlightActive=!0;let r=e.highlightedObjectColor.slice(0,3);n.highlightedObjectColor=r}if(e.highlightColor){let r=Array.from(e.highlightColor,o=>o/255);Number.isFinite(r[3])||(r[3]=1),n.highlightColor=r}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 ae=20,Lo=`
1463
+ struct skinUniforms {
1464
+ jointMatrix: array<mat4x4<f32>, ${ae}>,
1465
+ };
1466
+
1467
+ @group(0) @binding(auto) var<uniform> skin: skinUniforms;
1468
+
1469
+ fn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {
1470
+ return (weights.x * skin.jointMatrix[joints.x])
1471
+ + (weights.y * skin.jointMatrix[joints.y])
1472
+ + (weights.z * skin.jointMatrix[joints.z])
1473
+ + (weights.w * skin.jointMatrix[joints.w]);
1474
+ }
1475
+ `,Ro=`
1476
+ layout(std140) uniform skinUniforms {
1477
+ mat4 jointMatrix[SKIN_MAX_JOINTS];
1478
+ } skin;
1479
+
1480
+ mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
1481
+ return (weights.x * skin.jointMatrix[joints.x])
1482
+ + (weights.y * skin.jointMatrix[joints.y])
1483
+ + (weights.z * skin.jointMatrix[joints.z])
1484
+ + (weights.w * skin.jointMatrix[joints.w]);
1485
+ }
1486
+
1487
+ `,Eo="",In={props:{},uniforms:{},name:"skin",bindingLayout:[{name:"skin",group:0}],dependencies:[],source:Lo,vs:Ro,fs:Eo,defines:{SKIN_MAX_JOINTS:ae},getUniforms:(e={},t)=>{let{scenegraphsFromGLTF:n}=e;if(!n?.gltf?.skins?.[0])return{jointMatrix:[]};let{inverseBindMatrices:r,joints:o,skeleton:i}=n.gltf.skins[0],a=[],s=r.value.length/16;for(let f=0;f<s;f++){let u=r.value.subarray(f*16,f*16+16);a.push(new B(Array.from(u)))}let c=n.gltfNodeIndexToNodeMap.get(i),l={};c.preorderTraversal((f,{worldMatrix:u})=>{l[f.id]=u});let p=new Float32Array(ae*16);for(let f=0;f<ae;++f){let u=o[f];if(u===void 0)break;let h=l[n.gltfNodeIndexToNodeMap.get(u).id],m=a[f],S=new B().copy(h).multiplyRight(m),x=f*16;for(let _=0;_<16;_++)p[x+_]=S[_]}return{jointMatrix:p}},uniformTypes:{jointMatrix:["mat4x4<f32>",ae]}};var yn=ct(Ue(),1);var rt=`precision highp int;
1225
1488
 
1226
1489
  // #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1227
1490
  struct AmbientLight {
@@ -1234,59 +1497,51 @@ struct PointLight {
1234
1497
  vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential
1235
1498
  };
1236
1499
 
1500
+ struct SpotLight {
1501
+ vec3 color;
1502
+ vec3 position;
1503
+ vec3 direction;
1504
+ vec3 attenuation;
1505
+ vec2 coneCos;
1506
+ };
1507
+
1237
1508
  struct DirectionalLight {
1238
1509
  vec3 color;
1239
1510
  vec3 direction;
1240
1511
  };
1241
1512
 
1242
- uniform lightingUniforms {
1243
- int enabled;
1244
- int lightType;
1513
+ struct UniformLight {
1514
+ vec3 color;
1515
+ vec3 position;
1516
+ vec3 direction;
1517
+ vec3 attenuation;
1518
+ vec2 coneCos;
1519
+ };
1245
1520
 
1521
+ layout(std140) uniform lightingUniforms {
1522
+ int enabled;
1246
1523
  int directionalLightCount;
1247
1524
  int pointLightCount;
1248
-
1525
+ int spotLightCount;
1249
1526
  vec3 ambientColor;
1250
-
1251
- vec3 lightColor0;
1252
- vec3 lightPosition0;
1253
- vec3 lightDirection0;
1254
- vec3 lightAttenuation0;
1255
-
1256
- vec3 lightColor1;
1257
- vec3 lightPosition1;
1258
- vec3 lightDirection1;
1259
- vec3 lightAttenuation1;
1260
-
1261
- vec3 lightColor2;
1262
- vec3 lightPosition2;
1263
- vec3 lightDirection2;
1264
- vec3 lightAttenuation2;
1527
+ UniformLight lights[5];
1265
1528
  } lighting;
1266
1529
 
1267
1530
  PointLight lighting_getPointLight(int index) {
1268
- switch (index) {
1269
- case 0:
1270
- return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
1271
- case 1:
1272
- return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
1273
- case 2:
1274
- default:
1275
- return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
1276
- }
1531
+ UniformLight light = lighting.lights[index];
1532
+ return PointLight(light.color, light.position, light.attenuation);
1533
+ }
1534
+
1535
+ SpotLight lighting_getSpotLight(int index) {
1536
+ UniformLight light = lighting.lights[lighting.pointLightCount + index];
1537
+ return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);
1277
1538
  }
1278
1539
 
1279
1540
  DirectionalLight lighting_getDirectionalLight(int index) {
1280
- switch (index) {
1281
- case 0:
1282
- return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
1283
- case 1:
1284
- return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
1285
- case 2:
1286
- default:
1287
- return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
1288
- }
1289
- }
1541
+ UniformLight light =
1542
+ lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
1543
+ return DirectionalLight(light.color, light.direction);
1544
+ }
1290
1545
 
1291
1546
  float getPointLightAttenuation(PointLight pointLight, float distance) {
1292
1547
  return pointLight.attenuation.x
@@ -1294,8 +1549,24 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
1294
1549
  + pointLight.attenuation.z * distance * distance;
1295
1550
  }
1296
1551
 
1552
+ float getSpotLightAttenuation(SpotLight spotLight, vec3 positionWorldspace) {
1553
+ vec3 light_direction = normalize(positionWorldspace - spotLight.position);
1554
+ float coneFactor = smoothstep(
1555
+ spotLight.coneCos.y,
1556
+ spotLight.coneCos.x,
1557
+ dot(normalize(spotLight.direction), light_direction)
1558
+ );
1559
+ float distanceAttenuation = getPointLightAttenuation(
1560
+ PointLight(spotLight.color, spotLight.position, spotLight.attenuation),
1561
+ distance(spotLight.position, positionWorldspace)
1562
+ );
1563
+ return distanceAttenuation / max(coneFactor, 0.0001);
1564
+ }
1565
+
1297
1566
  // #endif
1298
- `;var pr=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1567
+ `;var Cn=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
1568
+ const MAX_LIGHTS: i32 = 5;
1569
+
1299
1570
  struct AmbientLight {
1300
1571
  color: vec3<f32>,
1301
1572
  };
@@ -1306,48 +1577,86 @@ struct PointLight {
1306
1577
  attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
1307
1578
  };
1308
1579
 
1580
+ struct SpotLight {
1581
+ color: vec3<f32>,
1582
+ position: vec3<f32>,
1583
+ direction: vec3<f32>,
1584
+ attenuation: vec3<f32>,
1585
+ coneCos: vec2<f32>,
1586
+ };
1587
+
1309
1588
  struct DirectionalLight {
1310
1589
  color: vec3<f32>,
1311
1590
  direction: vec3<f32>,
1312
1591
  };
1313
1592
 
1593
+ struct UniformLight {
1594
+ color: vec3<f32>,
1595
+ position: vec3<f32>,
1596
+ direction: vec3<f32>,
1597
+ attenuation: vec3<f32>,
1598
+ coneCos: vec2<f32>,
1599
+ };
1600
+
1314
1601
  struct lightingUniforms {
1315
1602
  enabled: i32,
1316
- pointLightCount: i32,
1317
1603
  directionalLightCount: i32,
1318
-
1604
+ pointLightCount: i32,
1605
+ spotLightCount: i32,
1319
1606
  ambientColor: vec3<f32>,
1320
-
1321
- // TODO - support multiple lights by uncommenting arrays below
1322
- lightType: i32,
1323
- lightColor: vec3<f32>,
1324
- lightDirection: vec3<f32>,
1325
- lightPosition: vec3<f32>,
1326
- lightAttenuation: vec3<f32>,
1327
-
1328
- // AmbientLight ambientLight;
1329
- // PointLight pointLight[MAX_LIGHTS];
1330
- // DirectionalLight directionalLight[MAX_LIGHTS];
1607
+ lights: array<UniformLight, 5>,
1331
1608
  };
1332
1609
 
1333
- // Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)
1334
- @binding(1) @group(0) var<uniform> lighting : lightingUniforms;
1610
+ @group(2) @binding(auto) var<uniform> lighting : lightingUniforms;
1335
1611
 
1336
1612
  fn lighting_getPointLight(index: i32) -> PointLight {
1337
- return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
1613
+ let light = lighting.lights[index];
1614
+ return PointLight(light.color, light.position, light.attenuation);
1615
+ }
1616
+
1617
+ fn lighting_getSpotLight(index: i32) -> SpotLight {
1618
+ let light = lighting.lights[lighting.pointLightCount + index];
1619
+ return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);
1338
1620
  }
1339
1621
 
1340
1622
  fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
1341
- return DirectionalLight(lighting.lightColor, lighting.lightDirection);
1342
- }
1623
+ let light = lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
1624
+ return DirectionalLight(light.color, light.direction);
1625
+ }
1343
1626
 
1344
1627
  fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
1345
1628
  return pointLight.attenuation.x
1346
1629
  + pointLight.attenuation.y * distance
1347
1630
  + pointLight.attenuation.z * distance * distance;
1348
1631
  }
1349
- `;var bs=5,xs=255,Ke;(function(a){a[a.POINT=0]="POINT",a[a.DIRECTIONAL=1]="DIRECTIONAL"})(Ke||(Ke={}));var te={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:Ke.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:pr,vs:pn,fs:pn,getUniforms:ys};function ys(a,e={}){if(a=a&&{...a},!a)return{...te.defaultUniforms};a.lights&&(a={...a,...ks(a.lights),lights:void 0});let{ambientLight:t,pointLights:n,directionalLights:r}=a||{};if(!(t||n&&n.length>0||r&&r.length>0))return{...te.defaultUniforms,enabled:0};let i={...te.defaultUniforms,...e,...ws({ambientLight:t,pointLights:n,directionalLights:r})};return a.enabled!==void 0&&(i.enabled=a.enabled?1:0),i}function ws({ambientLight:a,pointLights:e=[],directionalLights:t=[]}){let n={};n.ambientColor=dn(a);let r=0;for(let s of e){n.lightType=Ke.POINT;let i=r;n[`lightColor${i}`]=dn(s),n[`lightPosition${i}`]=s.position,n[`lightAttenuation${i}`]=s.attenuation||[1,0,0],r++}for(let s of t){n.lightType=Ke.DIRECTIONAL;let i=r;n[`lightColor${i}`]=dn(s),n[`lightDirection${i}`]=s.direction,r++}return r>bs&&dr.log.warn("MAX_LIGHTS exceeded")(),n.directionalLightCount=t.length,n.pointLightCount=e.length,n}function ks(a){let e={pointLights:[],directionalLights:[]};for(let t of a||[])switch(t.type){case"ambient":e.ambientLight=t;break;case"directional":e.directionalLights?.push(t);break;case"point":e.pointLights?.push(t);break;default:}return e}function dn(a={}){let{color:e=[0,0,0],intensity:t=1}=a;return e.map(n=>n*t/xs)}var Is=`
1350
- struct dirlightUniforms {
1632
+
1633
+ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>) -> f32 {
1634
+ let lightDirection = normalize(positionWorldspace - spotLight.position);
1635
+ let coneFactor = smoothstep(
1636
+ spotLight.coneCos.y,
1637
+ spotLight.coneCos.x,
1638
+ dot(normalize(spotLight.direction), lightDirection)
1639
+ );
1640
+ let distanceAttenuation = getPointLightAttenuation(
1641
+ PointLight(spotLight.color, spotLight.position, spotLight.attenuation),
1642
+ distance(spotLight.position, positionWorldspace)
1643
+ );
1644
+ return distanceAttenuation / max(coneFactor, 0.0001);
1645
+ }
1646
+ `;var G=5,Ao=255,Io={color:"vec3<f32>",position:"vec3<f32>",direction:"vec3<f32>",attenuation:"vec3<f32>",coneCos:"vec2<f32>"},V={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",directionalLightCount:"i32",pointLightCount:"i32",spotLightCount:"i32",ambientColor:"vec3<f32>",lights:[Io,G]},defaultUniforms:ye(),bindingLayout:[{name:"lighting",group:2}],firstBindingSlot:0,source:Cn,vs:rt,fs:rt,getUniforms:Co};function Co(e,t={}){if(e=e&&{...e},!e)return ye();e.lights&&(e={...e,...No(e.lights),lights:void 0});let{ambientLight:n,pointLights:r,spotLights:o,directionalLights:i}=e||{};if(!(n||r&&r.length>0||o&&o.length>0||i&&i.length>0))return{...ye(),enabled:0};let s={...ye(),...yo({ambientLight:n,pointLights:r,spotLights:o,directionalLights:i})};return e.enabled!==void 0&&(s.enabled=e.enabled?1:0),s}function yo({ambientLight:e,pointLights:t=[],spotLights:n=[],directionalLights:r=[]}){let o=Nn(),i=0,a=0,s=0,c=0;for(let l of t){if(i>=G)break;o[i]={...o[i],color:Ce(l),position:l.position,attenuation:l.attenuation||[1,0,0]},i++,a++}for(let l of n){if(i>=G)break;o[i]={...o[i],color:Ce(l),position:l.position,direction:l.direction,attenuation:l.attenuation||[1,0,0],coneCos:To(l)},i++,s++}for(let l of r){if(i>=G)break;o[i]={...o[i],color:Ce(l),direction:l.direction},i++,c++}return t.length+n.length+r.length>G&&yn.log.warn(`MAX_LIGHTS exceeded, truncating to ${G}`)(),{ambientColor:Ce(e),directionalLightCount:c,pointLightCount:a,spotLightCount:s,lights:o}}function No(e){let t={pointLights:[],spotLights:[],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;case"spot":t.spotLights?.push(n);break;default:}return t}function Ce(e={}){let{color:t=[0,0,0],intensity:n=1}=e;return t.map(r=>r*n/Ao)}function ye(){return{enabled:1,directionalLightCount:0,pointLightCount:0,spotLightCount:0,ambientColor:[.1,.1,.1],lights:Nn()}}function Nn(){return Array.from({length:G},()=>Po())}function Po(){return{color:[1,1,1],position:[1,1,2],direction:[1,1,1],attenuation:[1,0,0],coneCos:[1,0]}}function To(e){let t=e.innerConeAngle??0,n=e.outerConeAngle??Math.PI/4;return[Math.cos(t),Math.cos(n)]}var Oo=`#ifdef USE_IBL
1647
+ @group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;
1648
+ @group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;
1649
+ @group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;
1650
+ @group(2) @binding(auto) var pbr_specularEnvSamplerSampler: sampler;
1651
+ @group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;
1652
+ @group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;
1653
+ #endif
1654
+ `,Pn=`#ifdef USE_IBL
1655
+ uniform samplerCube pbr_diffuseEnvSampler;
1656
+ uniform samplerCube pbr_specularEnvSampler;
1657
+ uniform sampler2D pbr_brdfLUT;
1658
+ #endif
1659
+ `,Ne={name:"ibl",firstBindingSlot:32,bindingLayout:[{name:"pbr_diffuseEnvSampler",group:2},{name:"pbr_specularEnvSampler",group:2},{name:"pbr_brdfLUT",group:2}],source:Oo,vs:Pn,fs:Pn};var Uo=`struct dirlightUniforms {
1351
1660
  lightDirection: vec3<f32>,
1352
1661
  };
1353
1662
 
@@ -1357,7 +1666,7 @@ struct DirlightInputs {
1357
1666
  normal: DirlightNormal,
1358
1667
  };
1359
1668
 
1360
- @binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;
1669
+ @group(2) @binding(auto) var<uniform> dirlight : dirlightUniforms;
1361
1670
 
1362
1671
  // For vertex
1363
1672
  fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {
@@ -1372,12 +1681,12 @@ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
1372
1681
  let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
1373
1682
  return vec4<f32>(color.rgb * d, color.a);
1374
1683
  }
1375
- `,Ss=`out vec3 dirlight_vNormal;
1684
+ `,Fo=`out vec3 dirlight_vNormal;
1376
1685
 
1377
1686
  void dirlight_setNormal(vec3 normal) {
1378
1687
  dirlight_vNormal = normalize(normal);
1379
1688
  }
1380
- `,As=`uniform dirlightUniforms {
1689
+ `,Vo=`layout(std140) uniform dirlightUniforms {
1381
1690
  vec3 lightDirection;
1382
1691
  } dirlight;
1383
1692
 
@@ -1388,15 +1697,134 @@ vec4 dirlight_filterColor(vec4 color) {
1388
1697
  float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
1389
1698
  return vec4(color.rgb * d, color.a);
1390
1699
  }
1391
- `,mn={props:{},uniforms:{},name:"dirlight",dependencies:[],source:Is,vs:Ss,fs:As,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Ts};function Ts(a=mn.defaultUniforms){let e={};return a.lightDirection&&(e.lightDirection=a.lightDirection),e}var Pt=`uniform phongMaterialUniforms {
1700
+ `,ot={props:{},uniforms:{},name:"dirlight",bindingLayout:[{name:"dirlight",group:2}],firstBindingSlot:16,dependencies:[],source:Uo,vs:Fo,fs:Vo,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:wo};function wo(e=ot.defaultUniforms){let t={};return e.lightDirection&&(t.lightDirection=e.lightDirection),t}var Tn=`struct lambertMaterialUniforms {
1701
+ unlit: u32,
1702
+ ambient: f32,
1703
+ diffuse: f32,
1704
+ };
1705
+
1706
+ @group(3) @binding(auto) var<uniform> lambertMaterial : lambertMaterialUniforms;
1707
+
1708
+ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
1709
+ let lambertian: f32 = max(dot(light_direction, normal_worldspace), 0.0);
1710
+ return lambertian * lambertMaterial.diffuse * surfaceColor * color;
1711
+ }
1712
+
1713
+ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
1714
+ var lightColor: vec3<f32> = surfaceColor;
1715
+
1716
+ if (lambertMaterial.unlit != 0u) {
1717
+ return surfaceColor;
1718
+ }
1719
+
1720
+ if (lighting.enabled == 0) {
1721
+ return lightColor;
1722
+ }
1723
+
1724
+ lightColor = lambertMaterial.ambient * surfaceColor * lighting.ambientColor;
1725
+
1726
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
1727
+ let pointLight: PointLight = lighting_getPointLight(i);
1728
+ let light_position_worldspace: vec3<f32> = pointLight.position;
1729
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1730
+ let light_attenuation = getPointLightAttenuation(
1731
+ pointLight,
1732
+ distance(light_position_worldspace, position_worldspace)
1733
+ );
1734
+ lightColor += lighting_getLightColor(
1735
+ surfaceColor,
1736
+ light_direction,
1737
+ normal_worldspace,
1738
+ pointLight.color / light_attenuation
1739
+ );
1740
+ }
1741
+
1742
+ for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
1743
+ let spotLight: SpotLight = lighting_getSpotLight(i);
1744
+ let light_position_worldspace: vec3<f32> = spotLight.position;
1745
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1746
+ let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1747
+ lightColor += lighting_getLightColor(
1748
+ surfaceColor,
1749
+ light_direction,
1750
+ normal_worldspace,
1751
+ spotLight.color / light_attenuation
1752
+ );
1753
+ }
1754
+
1755
+ for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
1756
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
1757
+ lightColor += lighting_getLightColor(
1758
+ surfaceColor,
1759
+ -directionalLight.direction,
1760
+ normal_worldspace,
1761
+ directionalLight.color
1762
+ );
1763
+ }
1764
+
1765
+ return lightColor;
1766
+ }
1767
+ `;var On=`layout(std140) uniform lambertMaterialUniforms {
1768
+ uniform bool unlit;
1769
+ uniform float ambient;
1770
+ uniform float diffuse;
1771
+ } material;
1772
+ `,Un=`layout(std140) uniform lambertMaterialUniforms {
1773
+ uniform bool unlit;
1774
+ uniform float ambient;
1775
+ uniform float diffuse;
1776
+ } material;
1777
+
1778
+ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 normal_worldspace, vec3 color) {
1779
+ float lambertian = max(dot(light_direction, normal_worldspace), 0.0);
1780
+ return lambertian * material.diffuse * surfaceColor * color;
1781
+ }
1782
+
1783
+ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
1784
+ vec3 lightColor = surfaceColor;
1785
+
1786
+ if (material.unlit) {
1787
+ return surfaceColor;
1788
+ }
1789
+
1790
+ if (lighting.enabled == 0) {
1791
+ return lightColor;
1792
+ }
1793
+
1794
+ lightColor = material.ambient * surfaceColor * lighting.ambientColor;
1795
+
1796
+ for (int i = 0; i < lighting.pointLightCount; i++) {
1797
+ PointLight pointLight = lighting_getPointLight(i);
1798
+ vec3 light_position_worldspace = pointLight.position;
1799
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
1800
+ float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
1801
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, pointLight.color / light_attenuation);
1802
+ }
1803
+
1804
+ for (int i = 0; i < lighting.spotLightCount; i++) {
1805
+ SpotLight spotLight = lighting_getSpotLight(i);
1806
+ vec3 light_position_worldspace = spotLight.position;
1807
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
1808
+ float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1809
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, spotLight.color / light_attenuation);
1810
+ }
1811
+
1812
+ for (int i = 0; i < lighting.directionalLightCount; i++) {
1813
+ DirectionalLight directionalLight = lighting_getDirectionalLight(i);
1814
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, normal_worldspace, directionalLight.color);
1815
+ }
1816
+
1817
+ return lightColor;
1818
+ }
1819
+ `;var it={name:"lambertMaterial",firstBindingSlot:0,bindingLayout:[{name:"lambertMaterial",group:3}],dependencies:[V],source:Tn,vs:On,fs:Un,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6},getUniforms(e){return{...it.defaultUniforms,...e}}};var Pe=`layout(std140) uniform phongMaterialUniforms {
1820
+ uniform bool unlit;
1392
1821
  uniform float ambient;
1393
1822
  uniform float diffuse;
1394
1823
  uniform float shininess;
1395
1824
  uniform vec3 specularColor;
1396
1825
  } material;
1397
- `,Ft=`#define MAX_LIGHTS 3
1398
-
1399
- uniform phongMaterialUniforms {
1826
+ `,Te=`layout(std140) uniform phongMaterialUniforms {
1827
+ uniform bool unlit;
1400
1828
  uniform float ambient;
1401
1829
  uniform float diffuse;
1402
1830
  uniform float shininess;
@@ -1418,6 +1846,10 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
1418
1846
  vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
1419
1847
  vec3 lightColor = surfaceColor;
1420
1848
 
1849
+ if (material.unlit) {
1850
+ return surfaceColor;
1851
+ }
1852
+
1421
1853
  if (lighting.enabled == 0) {
1422
1854
  return lightColor;
1423
1855
  }
@@ -1433,22 +1865,30 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
1433
1865
  lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
1434
1866
  }
1435
1867
 
1436
- int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
1437
- for (int i = lighting.pointLightCount; i < totalLights; i++) {
1868
+ for (int i = 0; i < lighting.spotLightCount; i++) {
1869
+ SpotLight spotLight = lighting_getSpotLight(i);
1870
+ vec3 light_position_worldspace = spotLight.position;
1871
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
1872
+ float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1873
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, spotLight.color / light_attenuation);
1874
+ }
1875
+
1876
+ for (int i = 0; i < lighting.directionalLightCount; i++) {
1438
1877
  DirectionalLight directionalLight = lighting_getDirectionalLight(i);
1439
1878
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1440
1879
  }
1441
1880
 
1442
1881
  return lightColor;
1443
1882
  }
1444
- `;var Dt=`struct phongMaterialUniforms {
1883
+ `;var Oe=`struct phongMaterialUniforms {
1884
+ unlit: u32,
1445
1885
  ambient: f32,
1446
1886
  diffuse: f32,
1447
1887
  shininess: f32,
1448
1888
  specularColor: vec3<f32>,
1449
1889
  };
1450
1890
 
1451
- @binding(2) @group(0) var<uniform> phongMaterial : phongMaterialUniforms;
1891
+ @group(3) @binding(auto) var<uniform> phongMaterial : phongMaterialUniforms;
1452
1892
 
1453
1893
  fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
1454
1894
  let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
@@ -1465,6 +1905,10 @@ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, v
1465
1905
  fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
1466
1906
  var lightColor: vec3<f32> = surfaceColor;
1467
1907
 
1908
+ if (phongMaterial.unlit != 0u) {
1909
+ return surfaceColor;
1910
+ }
1911
+
1468
1912
  if (lighting.enabled == 0) {
1469
1913
  return lightColor;
1470
1914
  }
@@ -1472,62 +1916,93 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
1472
1916
  let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
1473
1917
  lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;
1474
1918
 
1475
- if (lighting.lightType == 0) {
1476
- let pointLight: PointLight = lighting_getPointLight(0);
1919
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
1920
+ let pointLight: PointLight = lighting_getPointLight(i);
1477
1921
  let light_position_worldspace: vec3<f32> = pointLight.position;
1478
1922
  let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1479
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
1480
- } else if (lighting.lightType == 1) {
1481
- var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
1482
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1923
+ let light_attenuation = getPointLightAttenuation(
1924
+ pointLight,
1925
+ distance(light_position_worldspace, position_worldspace)
1926
+ );
1927
+ lightColor += lighting_getLightColor(
1928
+ surfaceColor,
1929
+ light_direction,
1930
+ view_direction,
1931
+ normal_worldspace,
1932
+ pointLight.color / light_attenuation
1933
+ );
1483
1934
  }
1484
-
1485
- return lightColor;
1486
- /*
1487
- for (int i = 0; i < MAX_LIGHTS; i++) {
1488
- if (i >= lighting.pointLightCount) {
1489
- break;
1490
- }
1491
- PointLight pointLight = lighting.pointLight[i];
1492
- vec3 light_position_worldspace = pointLight.position;
1493
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
1494
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
1935
+
1936
+ for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
1937
+ let spotLight: SpotLight = lighting_getSpotLight(i);
1938
+ let light_position_worldspace: vec3<f32> = spotLight.position;
1939
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1940
+ let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1941
+ lightColor += lighting_getLightColor(
1942
+ surfaceColor,
1943
+ light_direction,
1944
+ view_direction,
1945
+ normal_worldspace,
1946
+ spotLight.color / light_attenuation
1947
+ );
1495
1948
  }
1496
1949
 
1497
- for (int i = 0; i < MAX_LIGHTS; i++) {
1498
- if (i >= lighting.directionalLightCount) {
1499
- break;
1500
- }
1501
- DirectionalLight directionalLight = lighting.directionalLight[i];
1950
+ for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
1951
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
1502
1952
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1503
- }
1504
- */
1953
+ }
1954
+
1955
+ return lightColor;
1505
1956
  }
1506
1957
 
1507
1958
  fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{
1508
1959
  var lightColor = vec3<f32>(0, 0, 0);
1509
1960
  let surfaceColor = vec3<f32>(0, 0, 0);
1510
1961
 
1511
- if (lighting.enabled == 0) {
1962
+ if (lighting.enabled != 0) {
1512
1963
  let view_direction = normalize(cameraPosition - position_worldspace);
1513
1964
 
1514
- switch (lighting.lightType) {
1515
- case 0, default: {
1516
- let pointLight: PointLight = lighting_getPointLight(0);
1517
- let light_position_worldspace: vec3<f32> = pointLight.position;
1518
- let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1519
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
1520
- }
1521
- case 1: {
1522
- let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
1965
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
1966
+ let pointLight: PointLight = lighting_getPointLight(i);
1967
+ let light_position_worldspace: vec3<f32> = pointLight.position;
1968
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1969
+ let light_attenuation = getPointLightAttenuation(
1970
+ pointLight,
1971
+ distance(light_position_worldspace, position_worldspace)
1972
+ );
1973
+ lightColor += lighting_getLightColor(
1974
+ surfaceColor,
1975
+ light_direction,
1976
+ view_direction,
1977
+ normal_worldspace,
1978
+ pointLight.color / light_attenuation
1979
+ );
1980
+ }
1981
+
1982
+ for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
1983
+ let spotLight: SpotLight = lighting_getSpotLight(i);
1984
+ let light_position_worldspace: vec3<f32> = spotLight.position;
1985
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1986
+ let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1987
+ lightColor += lighting_getLightColor(
1988
+ surfaceColor,
1989
+ light_direction,
1990
+ view_direction,
1991
+ normal_worldspace,
1992
+ spotLight.color / light_attenuation
1993
+ );
1994
+ }
1995
+
1996
+ for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
1997
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
1523
1998
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1524
- }
1525
1999
  }
1526
2000
  }
1527
2001
  return lightColor;
1528
2002
  }
1529
- `;var _n={props:{},name:"gouraudMaterial",vs:Ft.replace("phongMaterial","gouraudMaterial"),fs:Pt.replace("phongMaterial","gouraudMaterial"),source:Dt.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[te],uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(a){let e={...a};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{..._n.defaultUniforms,...e}}};var gn={name:"phongMaterial",dependencies:[te],source:Dt,vs:Pt,fs:Ft,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(a){let e={...a};return e.specularColor&&(e.specularColor=e.specularColor.map(t=>t/255)),{...gn.defaultUniforms,...e}}};var mr=`out vec3 pbr_vPosition;
1530
- out vec2 pbr_vUV;
2003
+ `;var at={props:{},name:"gouraudMaterial",bindingLayout:[{name:"gouraudMaterial",group:3}],vs:Te.replace("phongMaterial","gouraudMaterial"),fs:Pe.replace("phongMaterial","gouraudMaterial"),source:Oe.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[V],uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{unlit:!1,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)),{...at.defaultUniforms,...t}}};var st={name:"phongMaterial",firstBindingSlot:0,bindingLayout:[{name:"phongMaterial",group:3}],dependencies:[V],source:Oe,vs:Pe,fs:Te,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(e){let t={...e};return t.specularColor&&(t.specularColor=t.specularColor.map(n=>n/255)),{...st.defaultUniforms,...t}}};var Fn=`out vec3 pbr_vPosition;
2004
+ out vec2 pbr_vUV0;
2005
+ out vec2 pbr_vUV1;
1531
2006
 
1532
2007
  #ifdef HAS_NORMALS
1533
2008
  # ifdef HAS_TANGENTS
@@ -1537,7 +2012,13 @@ out vec3 pbr_vNormal;
1537
2012
  # endif
1538
2013
  #endif
1539
2014
 
1540
- void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
2015
+ void pbr_setPositionNormalTangentUV(
2016
+ vec4 position,
2017
+ vec4 normal,
2018
+ vec4 tangent,
2019
+ vec2 uv0,
2020
+ vec2 uv1
2021
+ )
1541
2022
  {
1542
2023
  vec4 pos = pbrProjection.modelMatrix * position;
1543
2024
  pbr_vPosition = vec3(pos.xyz) / pos.w;
@@ -1554,14 +2035,16 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
1554
2035
  #endif
1555
2036
 
1556
2037
  #ifdef HAS_UV
1557
- pbr_vUV = uv;
2038
+ pbr_vUV0 = uv0;
1558
2039
  #else
1559
- pbr_vUV = vec2(0.,0.);
2040
+ pbr_vUV0 = vec2(0.,0.);
1560
2041
  #endif
2042
+
2043
+ pbr_vUV1 = uv1;
1561
2044
  }
1562
- `,_r=`precision highp float;
2045
+ `,Vn=`precision highp float;
1563
2046
 
1564
- uniform pbrMaterialUniforms {
2047
+ layout(std140) uniform pbrMaterialUniforms {
1565
2048
  // Material is unlit
1566
2049
  bool unlit;
1567
2050
 
@@ -1583,6 +2066,42 @@ uniform pbrMaterialUniforms {
1583
2066
 
1584
2067
  bool alphaCutoffEnabled;
1585
2068
  float alphaCutoff; // #ifdef ALPHA_CUTOFF
2069
+
2070
+ vec3 specularColorFactor;
2071
+ float specularIntensityFactor;
2072
+ bool specularColorMapEnabled;
2073
+ bool specularIntensityMapEnabled;
2074
+
2075
+ float ior;
2076
+
2077
+ float transmissionFactor;
2078
+ bool transmissionMapEnabled;
2079
+
2080
+ float thicknessFactor;
2081
+ float attenuationDistance;
2082
+ vec3 attenuationColor;
2083
+
2084
+ float clearcoatFactor;
2085
+ float clearcoatRoughnessFactor;
2086
+ bool clearcoatMapEnabled;
2087
+ bool clearcoatRoughnessMapEnabled;
2088
+
2089
+ vec3 sheenColorFactor;
2090
+ float sheenRoughnessFactor;
2091
+ bool sheenColorMapEnabled;
2092
+ bool sheenRoughnessMapEnabled;
2093
+
2094
+ float iridescenceFactor;
2095
+ float iridescenceIor;
2096
+ vec2 iridescenceThicknessRange;
2097
+ bool iridescenceMapEnabled;
2098
+
2099
+ float anisotropyStrength;
2100
+ float anisotropyRotation;
2101
+ vec2 anisotropyDirection;
2102
+ bool anisotropyMapEnabled;
2103
+
2104
+ float emissiveStrength;
1586
2105
 
1587
2106
  // IBL
1588
2107
  bool IBLenabled;
@@ -1593,6 +2112,41 @@ uniform pbrMaterialUniforms {
1593
2112
  vec4 scaleDiffBaseMR;
1594
2113
  vec4 scaleFGDSpec;
1595
2114
  // #endif
2115
+
2116
+ int baseColorUVSet;
2117
+ mat3 baseColorUVTransform;
2118
+ int metallicRoughnessUVSet;
2119
+ mat3 metallicRoughnessUVTransform;
2120
+ int normalUVSet;
2121
+ mat3 normalUVTransform;
2122
+ int occlusionUVSet;
2123
+ mat3 occlusionUVTransform;
2124
+ int emissiveUVSet;
2125
+ mat3 emissiveUVTransform;
2126
+ int specularColorUVSet;
2127
+ mat3 specularColorUVTransform;
2128
+ int specularIntensityUVSet;
2129
+ mat3 specularIntensityUVTransform;
2130
+ int transmissionUVSet;
2131
+ mat3 transmissionUVTransform;
2132
+ int thicknessUVSet;
2133
+ mat3 thicknessUVTransform;
2134
+ int clearcoatUVSet;
2135
+ mat3 clearcoatUVTransform;
2136
+ int clearcoatRoughnessUVSet;
2137
+ mat3 clearcoatRoughnessUVTransform;
2138
+ int clearcoatNormalUVSet;
2139
+ mat3 clearcoatNormalUVTransform;
2140
+ int sheenColorUVSet;
2141
+ mat3 sheenColorUVTransform;
2142
+ int sheenRoughnessUVSet;
2143
+ mat3 sheenRoughnessUVTransform;
2144
+ int iridescenceUVSet;
2145
+ mat3 iridescenceUVTransform;
2146
+ int iridescenceThicknessUVSet;
2147
+ mat3 iridescenceThicknessUVTransform;
2148
+ int anisotropyUVSet;
2149
+ mat3 anisotropyUVTransform;
1596
2150
  } pbrMaterial;
1597
2151
 
1598
2152
  // Samplers
@@ -1611,19 +2165,50 @@ uniform sampler2D pbr_metallicRoughnessSampler;
1611
2165
  #ifdef HAS_OCCLUSIONMAP
1612
2166
  uniform sampler2D pbr_occlusionSampler;
1613
2167
  #endif
1614
- #ifdef USE_IBL
1615
- uniform samplerCube pbr_diffuseEnvSampler;
1616
- uniform samplerCube pbr_specularEnvSampler;
1617
- uniform sampler2D pbr_brdfLUT;
2168
+ #ifdef HAS_SPECULARCOLORMAP
2169
+ uniform sampler2D pbr_specularColorSampler;
1618
2170
  #endif
1619
-
1620
- // Inputs from vertex shader
1621
-
1622
- in vec3 pbr_vPosition;
1623
- in vec2 pbr_vUV;
1624
-
1625
- #ifdef HAS_NORMALS
1626
- #ifdef HAS_TANGENTS
2171
+ #ifdef HAS_SPECULARINTENSITYMAP
2172
+ uniform sampler2D pbr_specularIntensitySampler;
2173
+ #endif
2174
+ #ifdef HAS_TRANSMISSIONMAP
2175
+ uniform sampler2D pbr_transmissionSampler;
2176
+ #endif
2177
+ #ifdef HAS_THICKNESSMAP
2178
+ uniform sampler2D pbr_thicknessSampler;
2179
+ #endif
2180
+ #ifdef HAS_CLEARCOATMAP
2181
+ uniform sampler2D pbr_clearcoatSampler;
2182
+ #endif
2183
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
2184
+ uniform sampler2D pbr_clearcoatRoughnessSampler;
2185
+ #endif
2186
+ #ifdef HAS_CLEARCOATNORMALMAP
2187
+ uniform sampler2D pbr_clearcoatNormalSampler;
2188
+ #endif
2189
+ #ifdef HAS_SHEENCOLORMAP
2190
+ uniform sampler2D pbr_sheenColorSampler;
2191
+ #endif
2192
+ #ifdef HAS_SHEENROUGHNESSMAP
2193
+ uniform sampler2D pbr_sheenRoughnessSampler;
2194
+ #endif
2195
+ #ifdef HAS_IRIDESCENCEMAP
2196
+ uniform sampler2D pbr_iridescenceSampler;
2197
+ #endif
2198
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
2199
+ uniform sampler2D pbr_iridescenceThicknessSampler;
2200
+ #endif
2201
+ #ifdef HAS_ANISOTROPYMAP
2202
+ uniform sampler2D pbr_anisotropySampler;
2203
+ #endif
2204
+ // Inputs from vertex shader
2205
+
2206
+ in vec3 pbr_vPosition;
2207
+ in vec2 pbr_vUV0;
2208
+ in vec2 pbr_vUV1;
2209
+
2210
+ #ifdef HAS_NORMALS
2211
+ #ifdef HAS_TANGENTS
1627
2212
  in mat3 pbr_vTBN;
1628
2213
  #else
1629
2214
  in vec3 pbr_vNormal;
@@ -1653,6 +2238,8 @@ struct PBRInfo {
1653
2238
  const float M_PI = 3.141592653589793;
1654
2239
  const float c_MinRoughness = 0.04;
1655
2240
 
2241
+ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor);
2242
+
1656
2243
  vec4 SRGBtoLINEAR(vec4 srgbIn)
1657
2244
  {
1658
2245
  #ifdef MANUAL_SRGB
@@ -1668,16 +2255,20 @@ vec4 SRGBtoLINEAR(vec4 srgbIn)
1668
2255
  #endif //MANUAL_SRGB
1669
2256
  }
1670
2257
 
1671
- // Find the normal for this fragment, pulling either from a predefined normal map
1672
- // or from the interpolated mesh normal and tangent attributes.
1673
- vec3 getNormal()
2258
+ vec2 getMaterialUV(int uvSet, mat3 uvTransform)
2259
+ {
2260
+ vec2 baseUV = uvSet == 1 ? pbr_vUV1 : pbr_vUV0;
2261
+ return (uvTransform * vec3(baseUV, 1.0)).xy;
2262
+ }
2263
+
2264
+ // Build the tangent basis from interpolated attributes or screen-space derivatives.
2265
+ mat3 getTBN(vec2 uv)
1674
2266
  {
1675
- // Retrieve the tangent space matrix
1676
2267
  #ifndef HAS_TANGENTS
1677
2268
  vec3 pos_dx = dFdx(pbr_vPosition);
1678
2269
  vec3 pos_dy = dFdy(pbr_vPosition);
1679
- vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
1680
- vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
2270
+ vec3 tex_dx = dFdx(vec3(uv, 0.0));
2271
+ vec3 tex_dy = dFdy(vec3(uv, 0.0));
1681
2272
  vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
1682
2273
 
1683
2274
  #ifdef HAS_NORMALS
@@ -1693,9 +2284,21 @@ vec3 getNormal()
1693
2284
  mat3 tbn = pbr_vTBN;
1694
2285
  #endif
1695
2286
 
2287
+ return tbn;
2288
+ }
2289
+
2290
+ // Find the normal for this fragment, pulling either from a predefined normal map
2291
+ // or from the interpolated mesh normal and tangent attributes.
2292
+ vec3 getMappedNormal(sampler2D normalSampler, mat3 tbn, float normalScale, vec2 uv)
2293
+ {
2294
+ vec3 n = texture(normalSampler, uv).rgb;
2295
+ return normalize(tbn * ((2.0 * n - 1.0) * vec3(normalScale, normalScale, 1.0)));
2296
+ }
2297
+
2298
+ vec3 getNormal(mat3 tbn, vec2 uv)
2299
+ {
1696
2300
  #ifdef HAS_NORMALMAP
1697
- vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
1698
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
2301
+ vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale, uv);
1699
2302
  #else
1700
2303
  // The tbn matrix is linearly interpolated, so we need to re-normalize
1701
2304
  vec3 n = normalize(tbn[2].xyz);
@@ -1704,6 +2307,15 @@ vec3 getNormal()
1704
2307
  return n;
1705
2308
  }
1706
2309
 
2310
+ vec3 getClearcoatNormal(mat3 tbn, vec3 baseNormal, vec2 uv)
2311
+ {
2312
+ #ifdef HAS_CLEARCOATNORMALMAP
2313
+ return getMappedNormal(pbr_clearcoatNormalSampler, tbn, 1.0, uv);
2314
+ #else
2315
+ return baseNormal;
2316
+ #endif
2317
+ }
2318
+
1707
2319
  // Calculation of the lighting contribution from an optional Image Based Light source.
1708
2320
  // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
1709
2321
  // See our README.md on Environment Maps [3] for additional discussion.
@@ -1779,6 +2391,169 @@ float microfacetDistribution(PBRInfo pbrInfo)
1779
2391
  return roughnessSq / (M_PI * f * f);
1780
2392
  }
1781
2393
 
2394
+ float maxComponent(vec3 value)
2395
+ {
2396
+ return max(max(value.r, value.g), value.b);
2397
+ }
2398
+
2399
+ float getDielectricF0(float ior)
2400
+ {
2401
+ float clampedIor = max(ior, 1.0);
2402
+ float ratio = (clampedIor - 1.0) / (clampedIor + 1.0);
2403
+ return ratio * ratio;
2404
+ }
2405
+
2406
+ vec2 normalizeDirection(vec2 direction)
2407
+ {
2408
+ float directionLength = length(direction);
2409
+ return directionLength > 0.0001 ? direction / directionLength : vec2(1.0, 0.0);
2410
+ }
2411
+
2412
+ vec2 rotateDirection(vec2 direction, float rotation)
2413
+ {
2414
+ float s = sin(rotation);
2415
+ float c = cos(rotation);
2416
+ return vec2(direction.x * c - direction.y * s, direction.x * s + direction.y * c);
2417
+ }
2418
+
2419
+ vec3 getIridescenceTint(float iridescence, float thickness, float NdotV)
2420
+ {
2421
+ if (iridescence <= 0.0) {
2422
+ return vec3(1.0);
2423
+ }
2424
+
2425
+ float phase = 0.015 * thickness * pbrMaterial.iridescenceIor + (1.0 - NdotV) * 6.0;
2426
+ vec3 thinFilmTint =
2427
+ 0.5 + 0.5 * cos(vec3(phase, phase + 2.0943951, phase + 4.1887902));
2428
+ return mix(vec3(1.0), thinFilmTint, iridescence);
2429
+ }
2430
+
2431
+ vec3 getVolumeAttenuation(float thickness)
2432
+ {
2433
+ if (thickness <= 0.0) {
2434
+ return vec3(1.0);
2435
+ }
2436
+
2437
+ vec3 attenuationCoefficient =
2438
+ -log(max(pbrMaterial.attenuationColor, vec3(0.0001))) /
2439
+ max(pbrMaterial.attenuationDistance, 0.0001);
2440
+ return exp(-attenuationCoefficient * thickness);
2441
+ }
2442
+
2443
+ PBRInfo createClearcoatPBRInfo(PBRInfo basePBRInfo, vec3 clearcoatNormal, float clearcoatRoughness)
2444
+ {
2445
+ float perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
2446
+ float alphaRoughness = perceptualRoughness * perceptualRoughness;
2447
+ float NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);
2448
+
2449
+ return PBRInfo(
2450
+ basePBRInfo.NdotL,
2451
+ NdotV,
2452
+ basePBRInfo.NdotH,
2453
+ basePBRInfo.LdotH,
2454
+ basePBRInfo.VdotH,
2455
+ perceptualRoughness,
2456
+ 0.0,
2457
+ vec3(0.04),
2458
+ vec3(1.0),
2459
+ alphaRoughness,
2460
+ vec3(0.0),
2461
+ vec3(0.04),
2462
+ clearcoatNormal,
2463
+ basePBRInfo.v
2464
+ );
2465
+ }
2466
+
2467
+ vec3 calculateClearcoatContribution(
2468
+ PBRInfo pbrInfo,
2469
+ vec3 lightColor,
2470
+ vec3 clearcoatNormal,
2471
+ float clearcoatFactor,
2472
+ float clearcoatRoughness
2473
+ ) {
2474
+ if (clearcoatFactor <= 0.0) {
2475
+ return vec3(0.0);
2476
+ }
2477
+
2478
+ PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
2479
+ return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;
2480
+ }
2481
+
2482
+ #ifdef USE_IBL
2483
+ vec3 calculateClearcoatIBLContribution(
2484
+ PBRInfo pbrInfo,
2485
+ vec3 clearcoatNormal,
2486
+ vec3 reflection,
2487
+ float clearcoatFactor,
2488
+ float clearcoatRoughness
2489
+ ) {
2490
+ if (clearcoatFactor <= 0.0) {
2491
+ return vec3(0.0);
2492
+ }
2493
+
2494
+ PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
2495
+ return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;
2496
+ }
2497
+ #endif
2498
+
2499
+ vec3 calculateSheenContribution(
2500
+ PBRInfo pbrInfo,
2501
+ vec3 lightColor,
2502
+ vec3 sheenColor,
2503
+ float sheenRoughness
2504
+ ) {
2505
+ if (maxComponent(sheenColor) <= 0.0) {
2506
+ return vec3(0.0);
2507
+ }
2508
+
2509
+ float sheenFresnel = pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
2510
+ float sheenVisibility = mix(1.0, pbrInfo.NdotL * pbrInfo.NdotV, sheenRoughness);
2511
+ return pbrInfo.NdotL *
2512
+ lightColor *
2513
+ sheenColor *
2514
+ (0.25 + 0.75 * sheenFresnel) *
2515
+ sheenVisibility *
2516
+ (1.0 - pbrInfo.metalness);
2517
+ }
2518
+
2519
+ float calculateAnisotropyBoost(
2520
+ PBRInfo pbrInfo,
2521
+ vec3 anisotropyTangent,
2522
+ float anisotropyStrength
2523
+ ) {
2524
+ if (anisotropyStrength <= 0.0) {
2525
+ return 1.0;
2526
+ }
2527
+
2528
+ vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));
2529
+ float bitangentViewAlignment = abs(dot(pbrInfo.v, anisotropyBitangent));
2530
+ return mix(1.0, 0.65 + 0.7 * bitangentViewAlignment, anisotropyStrength);
2531
+ }
2532
+
2533
+ vec3 calculateMaterialLightColor(
2534
+ PBRInfo pbrInfo,
2535
+ vec3 lightColor,
2536
+ vec3 clearcoatNormal,
2537
+ float clearcoatFactor,
2538
+ float clearcoatRoughness,
2539
+ vec3 sheenColor,
2540
+ float sheenRoughness,
2541
+ vec3 anisotropyTangent,
2542
+ float anisotropyStrength
2543
+ ) {
2544
+ float anisotropyBoost = calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
2545
+ vec3 color = calculateFinalColor(pbrInfo, lightColor) * anisotropyBoost;
2546
+ color += calculateClearcoatContribution(
2547
+ pbrInfo,
2548
+ lightColor,
2549
+ clearcoatNormal,
2550
+ clearcoatFactor,
2551
+ clearcoatRoughness
2552
+ );
2553
+ color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);
2554
+ return color;
2555
+ }
2556
+
1782
2557
  void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
1783
2558
  pbrInfo.NdotL = 1.0;
1784
2559
  pbrInfo.NdotH = 0.0;
@@ -1803,6 +2578,11 @@ void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
1803
2578
  PBRInfo_setDirectionalLight(pbrInfo, light_direction);
1804
2579
  }
1805
2580
 
2581
+ void PBRInfo_setSpotLight(inout PBRInfo pbrInfo, SpotLight spotLight) {
2582
+ vec3 light_direction = normalize(spotLight.position - pbr_vPosition);
2583
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
2584
+ }
2585
+
1806
2586
  vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
1807
2587
  // Calculate the shading terms for the microfacet specular shading model
1808
2588
  vec3 F = specularReflection(pbrInfo);
@@ -1818,9 +2598,61 @@ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
1818
2598
 
1819
2599
  vec4 pbr_filterColor(vec4 colorUnused)
1820
2600
  {
2601
+ vec2 baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
2602
+ vec2 metallicRoughnessUV = getMaterialUV(
2603
+ pbrMaterial.metallicRoughnessUVSet,
2604
+ pbrMaterial.metallicRoughnessUVTransform
2605
+ );
2606
+ vec2 normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
2607
+ vec2 occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);
2608
+ vec2 emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);
2609
+ vec2 specularColorUV = getMaterialUV(
2610
+ pbrMaterial.specularColorUVSet,
2611
+ pbrMaterial.specularColorUVTransform
2612
+ );
2613
+ vec2 specularIntensityUV = getMaterialUV(
2614
+ pbrMaterial.specularIntensityUVSet,
2615
+ pbrMaterial.specularIntensityUVTransform
2616
+ );
2617
+ vec2 transmissionUV = getMaterialUV(
2618
+ pbrMaterial.transmissionUVSet,
2619
+ pbrMaterial.transmissionUVTransform
2620
+ );
2621
+ vec2 thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);
2622
+ vec2 clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);
2623
+ vec2 clearcoatRoughnessUV = getMaterialUV(
2624
+ pbrMaterial.clearcoatRoughnessUVSet,
2625
+ pbrMaterial.clearcoatRoughnessUVTransform
2626
+ );
2627
+ vec2 clearcoatNormalUV = getMaterialUV(
2628
+ pbrMaterial.clearcoatNormalUVSet,
2629
+ pbrMaterial.clearcoatNormalUVTransform
2630
+ );
2631
+ vec2 sheenColorUV = getMaterialUV(
2632
+ pbrMaterial.sheenColorUVSet,
2633
+ pbrMaterial.sheenColorUVTransform
2634
+ );
2635
+ vec2 sheenRoughnessUV = getMaterialUV(
2636
+ pbrMaterial.sheenRoughnessUVSet,
2637
+ pbrMaterial.sheenRoughnessUVTransform
2638
+ );
2639
+ vec2 iridescenceUV = getMaterialUV(
2640
+ pbrMaterial.iridescenceUVSet,
2641
+ pbrMaterial.iridescenceUVTransform
2642
+ );
2643
+ vec2 iridescenceThicknessUV = getMaterialUV(
2644
+ pbrMaterial.iridescenceThicknessUVSet,
2645
+ pbrMaterial.iridescenceThicknessUVTransform
2646
+ );
2647
+ vec2 anisotropyUV = getMaterialUV(
2648
+ pbrMaterial.anisotropyUVSet,
2649
+ pbrMaterial.anisotropyUVTransform
2650
+ );
2651
+
1821
2652
  // The albedo may be defined from a base texture or a flat color
1822
2653
  #ifdef HAS_BASECOLORMAP
1823
- vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
2654
+ vec4 baseColor =
2655
+ SRGBtoLINEAR(texture(pbr_baseColorSampler, baseColorUV)) * pbrMaterial.baseColorFactor;
1824
2656
  #else
1825
2657
  vec4 baseColor = pbrMaterial.baseColorFactor;
1826
2658
  #endif
@@ -1833,6 +2665,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
1833
2665
 
1834
2666
  vec3 color = vec3(0, 0, 0);
1835
2667
 
2668
+ float transmission = 0.0;
2669
+
1836
2670
  if(pbrMaterial.unlit){
1837
2671
  color.rgb = baseColor.rgb;
1838
2672
  }
@@ -1845,20 +2679,258 @@ vec4 pbr_filterColor(vec4 colorUnused)
1845
2679
  #ifdef HAS_METALROUGHNESSMAP
1846
2680
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
1847
2681
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
1848
- vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
2682
+ vec4 mrSample = texture(pbr_metallicRoughnessSampler, metallicRoughnessUV);
1849
2683
  perceptualRoughness = mrSample.g * perceptualRoughness;
1850
2684
  metallic = mrSample.b * metallic;
1851
2685
  #endif
1852
2686
  perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
1853
2687
  metallic = clamp(metallic, 0.0, 1.0);
2688
+ mat3 tbn = getTBN(normalUV);
2689
+ vec3 n = getNormal(tbn, normalUV); // normal at surface point
2690
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
2691
+ float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
2692
+ #ifdef USE_MATERIAL_EXTENSIONS
2693
+ bool useExtendedPBR =
2694
+ pbrMaterial.specularColorMapEnabled ||
2695
+ pbrMaterial.specularIntensityMapEnabled ||
2696
+ abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||
2697
+ maxComponent(abs(pbrMaterial.specularColorFactor - vec3(1.0))) > 0.0001 ||
2698
+ abs(pbrMaterial.ior - 1.5) > 0.0001 ||
2699
+ pbrMaterial.transmissionMapEnabled ||
2700
+ pbrMaterial.transmissionFactor > 0.0001 ||
2701
+ pbrMaterial.clearcoatMapEnabled ||
2702
+ pbrMaterial.clearcoatRoughnessMapEnabled ||
2703
+ pbrMaterial.clearcoatFactor > 0.0001 ||
2704
+ pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||
2705
+ pbrMaterial.sheenColorMapEnabled ||
2706
+ pbrMaterial.sheenRoughnessMapEnabled ||
2707
+ maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||
2708
+ pbrMaterial.sheenRoughnessFactor > 0.0001 ||
2709
+ pbrMaterial.iridescenceMapEnabled ||
2710
+ pbrMaterial.iridescenceFactor > 0.0001 ||
2711
+ abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||
2712
+ abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||
2713
+ abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||
2714
+ pbrMaterial.anisotropyMapEnabled ||
2715
+ pbrMaterial.anisotropyStrength > 0.0001 ||
2716
+ abs(pbrMaterial.anisotropyRotation) > 0.0001 ||
2717
+ length(pbrMaterial.anisotropyDirection - vec2(1.0, 0.0)) > 0.0001;
2718
+ #else
2719
+ bool useExtendedPBR = false;
2720
+ #endif
2721
+
2722
+ if (!useExtendedPBR) {
2723
+ // Keep the baseline metallic-roughness implementation byte-for-byte equivalent in behavior.
2724
+ float alphaRoughness = perceptualRoughness * perceptualRoughness;
2725
+
2726
+ vec3 f0 = vec3(0.04);
2727
+ vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
2728
+ diffuseColor *= 1.0 - metallic;
2729
+ vec3 specularColor = mix(f0, baseColor.rgb, metallic);
2730
+
2731
+ float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
2732
+ float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
2733
+ vec3 specularEnvironmentR0 = specularColor.rgb;
2734
+ vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
2735
+ vec3 reflection = -normalize(reflect(v, n));
2736
+
2737
+ PBRInfo pbrInfo = PBRInfo(
2738
+ 0.0, // NdotL
2739
+ NdotV,
2740
+ 0.0, // NdotH
2741
+ 0.0, // LdotH
2742
+ 0.0, // VdotH
2743
+ perceptualRoughness,
2744
+ metallic,
2745
+ specularEnvironmentR0,
2746
+ specularEnvironmentR90,
2747
+ alphaRoughness,
2748
+ diffuseColor,
2749
+ specularColor,
2750
+ n,
2751
+ v
2752
+ );
2753
+
2754
+ #ifdef USE_LIGHTS
2755
+ PBRInfo_setAmbientLight(pbrInfo);
2756
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
2757
+
2758
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
2759
+ if (i < lighting.directionalLightCount) {
2760
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
2761
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
2762
+ }
2763
+ }
2764
+
2765
+ for(int i = 0; i < lighting.pointLightCount; i++) {
2766
+ if (i < lighting.pointLightCount) {
2767
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
2768
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
2769
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
2770
+ }
2771
+ }
2772
+
2773
+ for(int i = 0; i < lighting.spotLightCount; i++) {
2774
+ if (i < lighting.spotLightCount) {
2775
+ PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));
2776
+ float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);
2777
+ color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);
2778
+ }
2779
+ }
2780
+ #endif
2781
+
2782
+ #ifdef USE_IBL
2783
+ if (pbrMaterial.IBLenabled) {
2784
+ color += getIBLContribution(pbrInfo, n, reflection);
2785
+ }
2786
+ #endif
2787
+
2788
+ #ifdef HAS_OCCLUSIONMAP
2789
+ if (pbrMaterial.occlusionMapEnabled) {
2790
+ float ao = texture(pbr_occlusionSampler, occlusionUV).r;
2791
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
2792
+ }
2793
+ #endif
2794
+
2795
+ vec3 emissive = pbrMaterial.emissiveFactor;
2796
+ #ifdef HAS_EMISSIVEMAP
2797
+ if (pbrMaterial.emissiveMapEnabled) {
2798
+ emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;
2799
+ }
2800
+ #endif
2801
+ color += emissive * pbrMaterial.emissiveStrength;
2802
+
2803
+ #ifdef PBR_DEBUG
2804
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
2805
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
2806
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
2807
+ #endif
2808
+
2809
+ return vec4(pow(color, vec3(1.0 / 2.2)), baseColor.a);
2810
+ }
2811
+
2812
+ float specularIntensity = pbrMaterial.specularIntensityFactor;
2813
+ #ifdef HAS_SPECULARINTENSITYMAP
2814
+ if (pbrMaterial.specularIntensityMapEnabled) {
2815
+ specularIntensity *= texture(pbr_specularIntensitySampler, specularIntensityUV).a;
2816
+ }
2817
+ #endif
2818
+
2819
+ vec3 specularFactor = pbrMaterial.specularColorFactor;
2820
+ #ifdef HAS_SPECULARCOLORMAP
2821
+ if (pbrMaterial.specularColorMapEnabled) {
2822
+ specularFactor *= SRGBtoLINEAR(texture(pbr_specularColorSampler, specularColorUV)).rgb;
2823
+ }
2824
+ #endif
2825
+
2826
+ transmission = pbrMaterial.transmissionFactor;
2827
+ #ifdef HAS_TRANSMISSIONMAP
2828
+ if (pbrMaterial.transmissionMapEnabled) {
2829
+ transmission *= texture(pbr_transmissionSampler, transmissionUV).r;
2830
+ }
2831
+ #endif
2832
+ transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);
2833
+ float thickness = max(pbrMaterial.thicknessFactor, 0.0);
2834
+ #ifdef HAS_THICKNESSMAP
2835
+ thickness *= texture(pbr_thicknessSampler, thicknessUV).g;
2836
+ #endif
2837
+
2838
+ float clearcoatFactor = pbrMaterial.clearcoatFactor;
2839
+ float clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;
2840
+ #ifdef HAS_CLEARCOATMAP
2841
+ if (pbrMaterial.clearcoatMapEnabled) {
2842
+ clearcoatFactor *= texture(pbr_clearcoatSampler, clearcoatUV).r;
2843
+ }
2844
+ #endif
2845
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
2846
+ if (pbrMaterial.clearcoatRoughnessMapEnabled) {
2847
+ clearcoatRoughness *= texture(pbr_clearcoatRoughnessSampler, clearcoatRoughnessUV).g;
2848
+ }
2849
+ #endif
2850
+ clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);
2851
+ clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
2852
+ vec3 clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);
2853
+
2854
+ vec3 sheenColor = pbrMaterial.sheenColorFactor;
2855
+ float sheenRoughness = pbrMaterial.sheenRoughnessFactor;
2856
+ #ifdef HAS_SHEENCOLORMAP
2857
+ if (pbrMaterial.sheenColorMapEnabled) {
2858
+ sheenColor *= SRGBtoLINEAR(texture(pbr_sheenColorSampler, sheenColorUV)).rgb;
2859
+ }
2860
+ #endif
2861
+ #ifdef HAS_SHEENROUGHNESSMAP
2862
+ if (pbrMaterial.sheenRoughnessMapEnabled) {
2863
+ sheenRoughness *= texture(pbr_sheenRoughnessSampler, sheenRoughnessUV).a;
2864
+ }
2865
+ #endif
2866
+ sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);
2867
+
2868
+ float iridescence = pbrMaterial.iridescenceFactor;
2869
+ #ifdef HAS_IRIDESCENCEMAP
2870
+ if (pbrMaterial.iridescenceMapEnabled) {
2871
+ iridescence *= texture(pbr_iridescenceSampler, iridescenceUV).r;
2872
+ }
2873
+ #endif
2874
+ iridescence = clamp(iridescence, 0.0, 1.0);
2875
+ float iridescenceThickness = mix(
2876
+ pbrMaterial.iridescenceThicknessRange.x,
2877
+ pbrMaterial.iridescenceThicknessRange.y,
2878
+ 0.5
2879
+ );
2880
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
2881
+ iridescenceThickness = mix(
2882
+ pbrMaterial.iridescenceThicknessRange.x,
2883
+ pbrMaterial.iridescenceThicknessRange.y,
2884
+ texture(pbr_iridescenceThicknessSampler, iridescenceThicknessUV).g
2885
+ );
2886
+ #endif
2887
+
2888
+ float anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);
2889
+ vec2 anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);
2890
+ #ifdef HAS_ANISOTROPYMAP
2891
+ if (pbrMaterial.anisotropyMapEnabled) {
2892
+ vec3 anisotropySample = texture(pbr_anisotropySampler, anisotropyUV).rgb;
2893
+ anisotropyStrength *= anisotropySample.b;
2894
+ vec2 mappedDirection = anisotropySample.rg * 2.0 - 1.0;
2895
+ if (length(mappedDirection) > 0.0001) {
2896
+ anisotropyDirection = normalize(mappedDirection);
2897
+ }
2898
+ }
2899
+ #endif
2900
+ anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);
2901
+ vec3 anisotropyTangent = normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);
2902
+ if (length(anisotropyTangent) < 0.0001) {
2903
+ anisotropyTangent = normalize(tbn[0]);
2904
+ }
2905
+ float anisotropyViewAlignment = abs(dot(v, anisotropyTangent));
2906
+ perceptualRoughness = mix(
2907
+ perceptualRoughness,
2908
+ clamp(perceptualRoughness * (1.0 - 0.6 * anisotropyViewAlignment), c_MinRoughness, 1.0),
2909
+ anisotropyStrength
2910
+ );
2911
+
1854
2912
  // Roughness is authored as perceptual roughness; as is convention,
1855
2913
  // convert to material roughness by squaring the perceptual roughness [2].
1856
2914
  float alphaRoughness = perceptualRoughness * perceptualRoughness;
1857
2915
 
1858
- vec3 f0 = vec3(0.04);
1859
- vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
1860
- diffuseColor *= 1.0 - metallic;
1861
- vec3 specularColor = mix(f0, baseColor.rgb, metallic);
2916
+ float dielectricF0 = getDielectricF0(pbrMaterial.ior);
2917
+ vec3 dielectricSpecularF0 = min(
2918
+ vec3(dielectricF0) * specularFactor * specularIntensity,
2919
+ vec3(1.0)
2920
+ );
2921
+ vec3 iridescenceTint = getIridescenceTint(iridescence, iridescenceThickness, NdotV);
2922
+ dielectricSpecularF0 = mix(
2923
+ dielectricSpecularF0,
2924
+ dielectricSpecularF0 * iridescenceTint,
2925
+ iridescence
2926
+ );
2927
+ vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - dielectricSpecularF0);
2928
+ diffuseColor *= (1.0 - metallic) * (1.0 - transmission);
2929
+ vec3 specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);
2930
+
2931
+ float baseLayerEnergy = 1.0 - clearcoatFactor * 0.25;
2932
+ diffuseColor *= baseLayerEnergy;
2933
+ specularColor *= baseLayerEnergy;
1862
2934
 
1863
2935
  // Compute reflectance.
1864
2936
  float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
@@ -1870,11 +2942,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
1870
2942
  float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
1871
2943
  vec3 specularEnvironmentR0 = specularColor.rgb;
1872
2944
  vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
1873
-
1874
- vec3 n = getNormal(); // normal at surface point
1875
- vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
1876
-
1877
- float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
1878
2945
  vec3 reflection = -normalize(reflect(v, n));
1879
2946
 
1880
2947
  PBRInfo pbrInfo = PBRInfo(
@@ -1898,13 +2965,33 @@ vec4 pbr_filterColor(vec4 colorUnused)
1898
2965
  #ifdef USE_LIGHTS
1899
2966
  // Apply ambient light
1900
2967
  PBRInfo_setAmbientLight(pbrInfo);
1901
- color += calculateFinalColor(pbrInfo, lighting.ambientColor);
2968
+ color += calculateMaterialLightColor(
2969
+ pbrInfo,
2970
+ lighting.ambientColor,
2971
+ clearcoatNormal,
2972
+ clearcoatFactor,
2973
+ clearcoatRoughness,
2974
+ sheenColor,
2975
+ sheenRoughness,
2976
+ anisotropyTangent,
2977
+ anisotropyStrength
2978
+ );
1902
2979
 
1903
2980
  // Apply directional light
1904
2981
  for(int i = 0; i < lighting.directionalLightCount; i++) {
1905
2982
  if (i < lighting.directionalLightCount) {
1906
2983
  PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
1907
- color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
2984
+ color += calculateMaterialLightColor(
2985
+ pbrInfo,
2986
+ lighting_getDirectionalLight(i).color,
2987
+ clearcoatNormal,
2988
+ clearcoatFactor,
2989
+ clearcoatRoughness,
2990
+ sheenColor,
2991
+ sheenRoughness,
2992
+ anisotropyTangent,
2993
+ anisotropyStrength
2994
+ );
1908
2995
  }
1909
2996
  }
1910
2997
 
@@ -1913,7 +3000,35 @@ vec4 pbr_filterColor(vec4 colorUnused)
1913
3000
  if (i < lighting.pointLightCount) {
1914
3001
  PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
1915
3002
  float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
1916
- color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
3003
+ color += calculateMaterialLightColor(
3004
+ pbrInfo,
3005
+ lighting_getPointLight(i).color / attenuation,
3006
+ clearcoatNormal,
3007
+ clearcoatFactor,
3008
+ clearcoatRoughness,
3009
+ sheenColor,
3010
+ sheenRoughness,
3011
+ anisotropyTangent,
3012
+ anisotropyStrength
3013
+ );
3014
+ }
3015
+ }
3016
+
3017
+ for(int i = 0; i < lighting.spotLightCount; i++) {
3018
+ if (i < lighting.spotLightCount) {
3019
+ PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));
3020
+ float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);
3021
+ color += calculateMaterialLightColor(
3022
+ pbrInfo,
3023
+ lighting_getSpotLight(i).color / attenuation,
3024
+ clearcoatNormal,
3025
+ clearcoatFactor,
3026
+ clearcoatRoughness,
3027
+ sheenColor,
3028
+ sheenRoughness,
3029
+ anisotropyTangent,
3030
+ anisotropyStrength
3031
+ );
1917
3032
  }
1918
3033
  }
1919
3034
  #endif
@@ -1921,24 +3036,38 @@ vec4 pbr_filterColor(vec4 colorUnused)
1921
3036
  // Calculate lighting contribution from image based lighting source (IBL)
1922
3037
  #ifdef USE_IBL
1923
3038
  if (pbrMaterial.IBLenabled) {
1924
- color += getIBLContribution(pbrInfo, n, reflection);
3039
+ color += getIBLContribution(pbrInfo, n, reflection) *
3040
+ calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
3041
+ color += calculateClearcoatIBLContribution(
3042
+ pbrInfo,
3043
+ clearcoatNormal,
3044
+ -normalize(reflect(v, clearcoatNormal)),
3045
+ clearcoatFactor,
3046
+ clearcoatRoughness
3047
+ );
3048
+ color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;
1925
3049
  }
1926
3050
  #endif
1927
3051
 
1928
3052
  // Apply optional PBR terms for additional (optional) shading
1929
3053
  #ifdef HAS_OCCLUSIONMAP
1930
3054
  if (pbrMaterial.occlusionMapEnabled) {
1931
- float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
3055
+ float ao = texture(pbr_occlusionSampler, occlusionUV).r;
1932
3056
  color = mix(color, color * ao, pbrMaterial.occlusionStrength);
1933
3057
  }
1934
3058
  #endif
1935
3059
 
3060
+ vec3 emissive = pbrMaterial.emissiveFactor;
1936
3061
  #ifdef HAS_EMISSIVEMAP
1937
3062
  if (pbrMaterial.emissiveMapEnabled) {
1938
- vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
1939
- color += emissive;
3063
+ emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;
1940
3064
  }
1941
3065
  #endif
3066
+ color += emissive * pbrMaterial.emissiveStrength;
3067
+
3068
+ if (transmission > 0.0) {
3069
+ color = mix(color, color * getVolumeAttenuation(thickness), transmission);
3070
+ }
1942
3071
 
1943
3072
  // This section uses mix to override final color for reference app visualization
1944
3073
  // of various parameters in the lighting equation.
@@ -1958,62 +3087,111 @@ vec4 pbr_filterColor(vec4 colorUnused)
1958
3087
 
1959
3088
  }
1960
3089
 
1961
- return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
3090
+ float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
3091
+ return vec4(pow(color,vec3(1.0/2.2)), alpha);
1962
3092
  }
1963
- `;var gr=`struct PBRFragmentInputs {
3093
+ `;var wn=`struct PBRFragmentInputs {
1964
3094
  pbr_vPosition: vec3f,
1965
- pbr_vUV: vec2f,
1966
- pbr_vTBN: mat3f,
3095
+ pbr_vUV0: vec2f,
3096
+ pbr_vUV1: vec2f,
3097
+ pbr_vTBN: mat3x3f,
1967
3098
  pbr_vNormal: vec3f
1968
3099
  };
1969
3100
 
1970
- var fragmentInputs: PBRFragmentInputs;
3101
+ var<private> fragmentInputs: PBRFragmentInputs;
1971
3102
 
1972
- fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)
3103
+ fn pbr_setPositionNormalTangentUV(
3104
+ position: vec4f,
3105
+ normal: vec4f,
3106
+ tangent: vec4f,
3107
+ uv0: vec2f,
3108
+ uv1: vec2f
3109
+ )
1973
3110
  {
1974
3111
  var pos: vec4f = pbrProjection.modelMatrix * position;
1975
- pbr_vPosition = vec3(pos.xyz) / pos.w;
3112
+ fragmentInputs.pbr_vPosition = pos.xyz / pos.w;
3113
+ fragmentInputs.pbr_vNormal = vec3f(0.0, 0.0, 1.0);
3114
+ fragmentInputs.pbr_vTBN = mat3x3f(
3115
+ vec3f(1.0, 0.0, 0.0),
3116
+ vec3f(0.0, 1.0, 0.0),
3117
+ vec3f(0.0, 0.0, 1.0)
3118
+ );
3119
+ fragmentInputs.pbr_vUV0 = vec2f(0.0, 0.0);
3120
+ fragmentInputs.pbr_vUV1 = uv1;
1976
3121
 
1977
3122
  #ifdef HAS_NORMALS
3123
+ let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);
3124
+ fragmentInputs.pbr_vNormal = normalW;
1978
3125
  #ifdef HAS_TANGENTS
1979
- let normalW: vec3f = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
1980
- let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
3126
+ let tangentW: vec3f = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);
1981
3127
  let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;
1982
- fragmentInputs,pbr_vTBN = mat3(tangentW, bitangentW, normalW);
1983
- #else // HAS_TANGENTS != 1
1984
- fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
3128
+ fragmentInputs.pbr_vTBN = mat3x3f(tangentW, bitangentW, normalW);
1985
3129
  #endif
1986
3130
  #endif
1987
3131
 
1988
3132
  #ifdef HAS_UV
1989
- pbr_vUV = uv;
1990
- #else
1991
- pbr_vUV = vec2(0.,0.);
3133
+ fragmentInputs.pbr_vUV0 = uv0;
1992
3134
  #endif
1993
3135
  }
1994
3136
 
1995
3137
  struct pbrMaterialUniforms {
1996
3138
  // Material is unlit
1997
- unlit: uint32,
3139
+ unlit: u32,
1998
3140
 
1999
3141
  // Base color map
2000
- baseColorMapEnabled: uint32,
3142
+ baseColorMapEnabled: u32,
2001
3143
  baseColorFactor: vec4f,
2002
3144
 
2003
- normalMapEnabled : uint32,
3145
+ normalMapEnabled : u32,
2004
3146
  normalScale: f32, // #ifdef HAS_NORMALMAP
2005
3147
 
2006
- emissiveMapEnabled: uint32,
3148
+ emissiveMapEnabled: u32,
2007
3149
  emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP
2008
3150
 
2009
3151
  metallicRoughnessValues: vec2f,
2010
- metallicRoughnessMapEnabled: uint32,
3152
+ metallicRoughnessMapEnabled: u32,
2011
3153
 
2012
3154
  occlusionMapEnabled: i32,
2013
3155
  occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP
2014
3156
 
2015
3157
  alphaCutoffEnabled: i32,
2016
3158
  alphaCutoff: f32, // #ifdef ALPHA_CUTOFF
3159
+
3160
+ specularColorFactor: vec3f,
3161
+ specularIntensityFactor: f32,
3162
+ specularColorMapEnabled: i32,
3163
+ specularIntensityMapEnabled: i32,
3164
+
3165
+ ior: f32,
3166
+
3167
+ transmissionFactor: f32,
3168
+ transmissionMapEnabled: i32,
3169
+
3170
+ thicknessFactor: f32,
3171
+ attenuationDistance: f32,
3172
+ attenuationColor: vec3f,
3173
+
3174
+ clearcoatFactor: f32,
3175
+ clearcoatRoughnessFactor: f32,
3176
+ clearcoatMapEnabled: i32,
3177
+ clearcoatRoughnessMapEnabled: i32,
3178
+
3179
+ sheenColorFactor: vec3f,
3180
+ sheenRoughnessFactor: f32,
3181
+ sheenColorMapEnabled: i32,
3182
+ sheenRoughnessMapEnabled: i32,
3183
+
3184
+ iridescenceFactor: f32,
3185
+ iridescenceIor: f32,
3186
+ iridescenceThicknessRange: vec2f,
3187
+ iridescenceMapEnabled: i32,
3188
+
3189
+ anisotropyStrength: f32,
3190
+ anisotropyRotation: f32,
3191
+ anisotropyDirection: vec2f,
3192
+ anisotropyMapEnabled: i32,
3193
+
3194
+ emissiveStrength: f32,
2017
3195
 
2018
3196
  // IBL
2019
3197
  IBLenabled: i32,
@@ -2022,34 +3200,116 @@ struct pbrMaterialUniforms {
2022
3200
  // debugging flags used for shader output of intermediate PBR variables
2023
3201
  // #ifdef PBR_DEBUG
2024
3202
  scaleDiffBaseMR: vec4f,
2025
- scaleFGDSpec: vec4f
3203
+ scaleFGDSpec: vec4f,
2026
3204
  // #endif
2027
- }
2028
-
2029
- @binding(2) @group(0) var<uniform> material : pbrMaterialUniforms;
3205
+
3206
+ baseColorUVSet: i32,
3207
+ baseColorUVTransform: mat3x3f,
3208
+ metallicRoughnessUVSet: i32,
3209
+ metallicRoughnessUVTransform: mat3x3f,
3210
+ normalUVSet: i32,
3211
+ normalUVTransform: mat3x3f,
3212
+ occlusionUVSet: i32,
3213
+ occlusionUVTransform: mat3x3f,
3214
+ emissiveUVSet: i32,
3215
+ emissiveUVTransform: mat3x3f,
3216
+ specularColorUVSet: i32,
3217
+ specularColorUVTransform: mat3x3f,
3218
+ specularIntensityUVSet: i32,
3219
+ specularIntensityUVTransform: mat3x3f,
3220
+ transmissionUVSet: i32,
3221
+ transmissionUVTransform: mat3x3f,
3222
+ thicknessUVSet: i32,
3223
+ thicknessUVTransform: mat3x3f,
3224
+ clearcoatUVSet: i32,
3225
+ clearcoatUVTransform: mat3x3f,
3226
+ clearcoatRoughnessUVSet: i32,
3227
+ clearcoatRoughnessUVTransform: mat3x3f,
3228
+ clearcoatNormalUVSet: i32,
3229
+ clearcoatNormalUVTransform: mat3x3f,
3230
+ sheenColorUVSet: i32,
3231
+ sheenColorUVTransform: mat3x3f,
3232
+ sheenRoughnessUVSet: i32,
3233
+ sheenRoughnessUVTransform: mat3x3f,
3234
+ iridescenceUVSet: i32,
3235
+ iridescenceUVTransform: mat3x3f,
3236
+ iridescenceThicknessUVSet: i32,
3237
+ iridescenceThicknessUVTransform: mat3x3f,
3238
+ anisotropyUVSet: i32,
3239
+ anisotropyUVTransform: mat3x3f,
3240
+ }
3241
+
3242
+ @group(3) @binding(auto) var<uniform> pbrMaterial : pbrMaterialUniforms;
2030
3243
 
2031
3244
  // Samplers
2032
3245
  #ifdef HAS_BASECOLORMAP
2033
- uniform sampler2D pbr_baseColorSampler;
3246
+ @group(3) @binding(auto) var pbr_baseColorSampler: texture_2d<f32>;
3247
+ @group(3) @binding(auto) var pbr_baseColorSamplerSampler: sampler;
2034
3248
  #endif
2035
3249
  #ifdef HAS_NORMALMAP
2036
- uniform sampler2D pbr_normalSampler;
3250
+ @group(3) @binding(auto) var pbr_normalSampler: texture_2d<f32>;
3251
+ @group(3) @binding(auto) var pbr_normalSamplerSampler: sampler;
2037
3252
  #endif
2038
3253
  #ifdef HAS_EMISSIVEMAP
2039
- uniform sampler2D pbr_emissiveSampler;
3254
+ @group(3) @binding(auto) var pbr_emissiveSampler: texture_2d<f32>;
3255
+ @group(3) @binding(auto) var pbr_emissiveSamplerSampler: sampler;
2040
3256
  #endif
2041
3257
  #ifdef HAS_METALROUGHNESSMAP
2042
- uniform sampler2D pbr_metallicRoughnessSampler;
3258
+ @group(3) @binding(auto) var pbr_metallicRoughnessSampler: texture_2d<f32>;
3259
+ @group(3) @binding(auto) var pbr_metallicRoughnessSamplerSampler: sampler;
2043
3260
  #endif
2044
3261
  #ifdef HAS_OCCLUSIONMAP
2045
- uniform sampler2D pbr_occlusionSampler;
3262
+ @group(3) @binding(auto) var pbr_occlusionSampler: texture_2d<f32>;
3263
+ @group(3) @binding(auto) var pbr_occlusionSamplerSampler: sampler;
2046
3264
  #endif
2047
- #ifdef USE_IBL
2048
- uniform samplerCube pbr_diffuseEnvSampler;
2049
- uniform samplerCube pbr_specularEnvSampler;
2050
- uniform sampler2D pbr_brdfLUT;
3265
+ #ifdef HAS_SPECULARCOLORMAP
3266
+ @group(3) @binding(auto) var pbr_specularColorSampler: texture_2d<f32>;
3267
+ @group(3) @binding(auto) var pbr_specularColorSamplerSampler: sampler;
3268
+ #endif
3269
+ #ifdef HAS_SPECULARINTENSITYMAP
3270
+ @group(3) @binding(auto) var pbr_specularIntensitySampler: texture_2d<f32>;
3271
+ @group(3) @binding(auto) var pbr_specularIntensitySamplerSampler: sampler;
3272
+ #endif
3273
+ #ifdef HAS_TRANSMISSIONMAP
3274
+ @group(3) @binding(auto) var pbr_transmissionSampler: texture_2d<f32>;
3275
+ @group(3) @binding(auto) var pbr_transmissionSamplerSampler: sampler;
3276
+ #endif
3277
+ #ifdef HAS_THICKNESSMAP
3278
+ @group(3) @binding(auto) var pbr_thicknessSampler: texture_2d<f32>;
3279
+ @group(3) @binding(auto) var pbr_thicknessSamplerSampler: sampler;
3280
+ #endif
3281
+ #ifdef HAS_CLEARCOATMAP
3282
+ @group(3) @binding(auto) var pbr_clearcoatSampler: texture_2d<f32>;
3283
+ @group(3) @binding(auto) var pbr_clearcoatSamplerSampler: sampler;
3284
+ #endif
3285
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
3286
+ @group(3) @binding(auto) var pbr_clearcoatRoughnessSampler: texture_2d<f32>;
3287
+ @group(3) @binding(auto) var pbr_clearcoatRoughnessSamplerSampler: sampler;
3288
+ #endif
3289
+ #ifdef HAS_CLEARCOATNORMALMAP
3290
+ @group(3) @binding(auto) var pbr_clearcoatNormalSampler: texture_2d<f32>;
3291
+ @group(3) @binding(auto) var pbr_clearcoatNormalSamplerSampler: sampler;
3292
+ #endif
3293
+ #ifdef HAS_SHEENCOLORMAP
3294
+ @group(3) @binding(auto) var pbr_sheenColorSampler: texture_2d<f32>;
3295
+ @group(3) @binding(auto) var pbr_sheenColorSamplerSampler: sampler;
3296
+ #endif
3297
+ #ifdef HAS_SHEENROUGHNESSMAP
3298
+ @group(3) @binding(auto) var pbr_sheenRoughnessSampler: texture_2d<f32>;
3299
+ @group(3) @binding(auto) var pbr_sheenRoughnessSamplerSampler: sampler;
3300
+ #endif
3301
+ #ifdef HAS_IRIDESCENCEMAP
3302
+ @group(3) @binding(auto) var pbr_iridescenceSampler: texture_2d<f32>;
3303
+ @group(3) @binding(auto) var pbr_iridescenceSamplerSampler: sampler;
3304
+ #endif
3305
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
3306
+ @group(3) @binding(auto) var pbr_iridescenceThicknessSampler: texture_2d<f32>;
3307
+ @group(3) @binding(auto) var pbr_iridescenceThicknessSamplerSampler: sampler;
3308
+ #endif
3309
+ #ifdef HAS_ANISOTROPYMAP
3310
+ @group(3) @binding(auto) var pbr_anisotropySampler: texture_2d<f32>;
3311
+ @group(3) @binding(auto) var pbr_anisotropySamplerSampler: sampler;
2051
3312
  #endif
2052
-
2053
3313
  // Encapsulate the various inputs used by the various functions in the shading equation
2054
3314
  // We store values in this struct to simplify the integration of alternative implementations
2055
3315
  // of the shading terms, outlined in the Readme.MD Appendix.
@@ -2075,80 +3335,142 @@ const c_MinRoughness = 0.04;
2075
3335
 
2076
3336
  fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
2077
3337
  {
3338
+ var linOut: vec3f = srgbIn.xyz;
2078
3339
  #ifdef MANUAL_SRGB
3340
+ let bLess: vec3f = step(vec3f(0.04045), srgbIn.xyz);
3341
+ linOut = mix(
3342
+ srgbIn.xyz / vec3f(12.92),
3343
+ pow((srgbIn.xyz + vec3f(0.055)) / vec3f(1.055), vec3f(2.4)),
3344
+ bLess
3345
+ );
2079
3346
  #ifdef SRGB_FAST_APPROXIMATION
2080
- var linOut: vec3f = pow(srgbIn.xyz,vec3(2.2));
2081
- #else // SRGB_FAST_APPROXIMATION
2082
- var bLess: vec3f = step(vec3(0.04045),srgbIn.xyz);
2083
- var linOut: vec3f = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
2084
- #endif //SRGB_FAST_APPROXIMATION
2085
- return vec4f(linOut,srgbIn.w);;
2086
- #else //MANUAL_SRGB
2087
- return srgbIn;
2088
- #endif //MANUAL_SRGB
3347
+ linOut = pow(srgbIn.xyz, vec3f(2.2));
3348
+ #endif
3349
+ #endif
3350
+ return vec4f(linOut, srgbIn.w);
2089
3351
  }
2090
3352
 
2091
- // Find the normal for this fragment, pulling either from a predefined normal map
2092
- // or from the interpolated mesh normal and tangent attributes.
2093
- fn getNormal() -> vec3f
3353
+ fn getMaterialUV(uvSet: i32, uvTransform: mat3x3f) -> vec2f
2094
3354
  {
2095
- // Retrieve the tangent space matrix
2096
- #ifndef HAS_TANGENTS
2097
- var pos_dx: vec3f = dFdx(pbr_vPosition);
2098
- var pos_dy: vec3f = dFdy(pbr_vPosition);
2099
- var tex_dx: vec3f = dFdx(vec3(pbr_vUV, 0.0));
2100
- var tex_dy: vec3f = dFdy(vec3(pbr_vUV, 0.0));
2101
- 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);
3355
+ var baseUV = fragmentInputs.pbr_vUV0;
3356
+ if (uvSet == 1) {
3357
+ baseUV = fragmentInputs.pbr_vUV1;
3358
+ }
3359
+ return (uvTransform * vec3f(baseUV, 1.0)).xy;
3360
+ }
3361
+
3362
+ // Build the tangent basis from interpolated attributes or screen-space derivatives.
3363
+ fn getTBN(uv: vec2f) -> mat3x3f
3364
+ {
3365
+ let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);
3366
+ let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);
3367
+ let tex_dx: vec3f = dpdx(vec3f(uv, 0.0));
3368
+ let tex_dy: vec3f = dpdy(vec3f(uv, 0.0));
3369
+ 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);
2102
3370
 
2103
- #ifdef HAS_NORMALS
2104
- var ng: vec3f = normalize(pbr_vNormal);
2105
- #else
2106
3371
  var ng: vec3f = cross(pos_dx, pos_dy);
3372
+ #ifdef HAS_NORMALS
3373
+ ng = normalize(fragmentInputs.pbr_vNormal);
2107
3374
  #endif
2108
-
2109
3375
  t = normalize(t - ng * dot(ng, t));
2110
3376
  var b: vec3f = normalize(cross(ng, t));
2111
- var tbn: mat3f = mat3f(t, b, ng);
2112
- #else // HAS_TANGENTS
2113
- var tbn: mat3f = pbr_vTBN;
3377
+ var tbn: mat3x3f = mat3x3f(t, b, ng);
3378
+ #ifdef HAS_TANGENTS
3379
+ tbn = fragmentInputs.pbr_vTBN;
2114
3380
  #endif
2115
3381
 
2116
- #ifdef HAS_NORMALMAP
2117
- vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
2118
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
2119
- #else
3382
+ return tbn;
3383
+ }
3384
+
3385
+ // Find the normal for this fragment, pulling either from a predefined normal map
3386
+ // or from the interpolated mesh normal and tangent attributes.
3387
+ fn getMappedNormal(
3388
+ normalSampler: texture_2d<f32>,
3389
+ normalSamplerBinding: sampler,
3390
+ tbn: mat3x3f,
3391
+ normalScale: f32,
3392
+ uv: vec2f
3393
+ ) -> vec3f
3394
+ {
3395
+ let n = textureSample(normalSampler, normalSamplerBinding, uv).rgb;
3396
+ return normalize(tbn * ((2.0 * n - 1.0) * vec3f(normalScale, normalScale, 1.0)));
3397
+ }
3398
+
3399
+ fn getNormal(tbn: mat3x3f, uv: vec2f) -> vec3f
3400
+ {
2120
3401
  // The tbn matrix is linearly interpolated, so we need to re-normalize
2121
- vec3 n = normalize(tbn[2].xyz);
3402
+ var n: vec3f = normalize(tbn[2].xyz);
3403
+ #ifdef HAS_NORMALMAP
3404
+ n = getMappedNormal(
3405
+ pbr_normalSampler,
3406
+ pbr_normalSamplerSampler,
3407
+ tbn,
3408
+ pbrMaterial.normalScale,
3409
+ uv
3410
+ );
2122
3411
  #endif
2123
3412
 
2124
3413
  return n;
2125
3414
  }
2126
3415
 
3416
+ fn getClearcoatNormal(tbn: mat3x3f, baseNormal: vec3f, uv: vec2f) -> vec3f
3417
+ {
3418
+ #ifdef HAS_CLEARCOATNORMALMAP
3419
+ return getMappedNormal(
3420
+ pbr_clearcoatNormalSampler,
3421
+ pbr_clearcoatNormalSamplerSampler,
3422
+ tbn,
3423
+ 1.0,
3424
+ uv
3425
+ );
3426
+ #else
3427
+ return baseNormal;
3428
+ #endif
3429
+ }
3430
+
2127
3431
  // Calculation of the lighting contribution from an optional Image Based Light source.
2128
3432
  // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
2129
3433
  // See our README.md on Environment Maps [3] for additional discussion.
2130
3434
  #ifdef USE_IBL
2131
- fn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f
3435
+ fn getIBLContribution(pbrInfo: PBRInfo, n: vec3f, reflection: vec3f) -> vec3f
2132
3436
  {
2133
- float mipCount = 9.0; // resolution of 512x512
2134
- float lod = (pbrInfo.perceptualRoughness * mipCount);
3437
+ let mipCount: f32 = 9.0; // resolution of 512x512
3438
+ let lod: f32 = pbrInfo.perceptualRoughness * mipCount;
2135
3439
  // retrieve a scale and bias to F0. See [1], Figure 3
2136
- vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
2137
- vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
2138
- vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
2139
-
3440
+ let brdf = SRGBtoLINEAR(
3441
+ textureSampleLevel(
3442
+ pbr_brdfLUT,
3443
+ pbr_brdfLUTSampler,
3444
+ vec2f(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness),
3445
+ 0.0
3446
+ )
3447
+ ).rgb;
3448
+ let diffuseLight =
3449
+ SRGBtoLINEAR(
3450
+ textureSampleLevel(pbr_diffuseEnvSampler, pbr_diffuseEnvSamplerSampler, n, 0.0)
3451
+ ).rgb;
3452
+ var specularLight = SRGBtoLINEAR(
3453
+ textureSampleLevel(
3454
+ pbr_specularEnvSampler,
3455
+ pbr_specularEnvSamplerSampler,
3456
+ reflection,
3457
+ 0.0
3458
+ )
3459
+ ).rgb;
2140
3460
  #ifdef USE_TEX_LOD
2141
- vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
2142
- #else
2143
- vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
3461
+ specularLight = SRGBtoLINEAR(
3462
+ textureSampleLevel(
3463
+ pbr_specularEnvSampler,
3464
+ pbr_specularEnvSamplerSampler,
3465
+ reflection,
3466
+ lod
3467
+ )
3468
+ ).rgb;
2144
3469
  #endif
2145
3470
 
2146
- vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
2147
- vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
2148
-
2149
- // For presentation, this allows us to disable IBL terms
2150
- diffuse *= pbrMaterial.scaleIBLAmbient.x;
2151
- specular *= pbrMaterial.scaleIBLAmbient.y;
3471
+ let diffuse = diffuseLight * pbrInfo.diffuseColor * pbrMaterial.scaleIBLAmbient.x;
3472
+ let specular =
3473
+ specularLight * (pbrInfo.specularColor * brdf.x + brdf.y) * pbrMaterial.scaleIBLAmbient.y;
2152
3474
 
2153
3475
  return diffuse + specular;
2154
3476
  }
@@ -2158,7 +3480,7 @@ fn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f
2158
3480
  // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
2159
3481
  // See also [1], Equation 1
2160
3482
  fn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {
2161
- return pbrInfo.diffuseColor / PI;
3483
+ return pbrInfo.diffuseColor / M_PI;
2162
3484
  }
2163
3485
 
2164
3486
  // The following equation models the Fresnel reflectance term of the spec equation (aka F())
@@ -2192,7 +3514,173 @@ fn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {
2192
3514
  fn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {
2193
3515
  let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
2194
3516
  let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
2195
- return roughnessSq / (PI * f * f);
3517
+ return roughnessSq / (M_PI * f * f);
3518
+ }
3519
+
3520
+ fn maxComponent(value: vec3f) -> f32 {
3521
+ return max(max(value.r, value.g), value.b);
3522
+ }
3523
+
3524
+ fn getDielectricF0(ior: f32) -> f32 {
3525
+ let clampedIor = max(ior, 1.0);
3526
+ let ratio = (clampedIor - 1.0) / (clampedIor + 1.0);
3527
+ return ratio * ratio;
3528
+ }
3529
+
3530
+ fn normalizeDirection(direction: vec2f) -> vec2f {
3531
+ let directionLength = length(direction);
3532
+ if (directionLength > 0.0001) {
3533
+ return direction / directionLength;
3534
+ }
3535
+
3536
+ return vec2f(1.0, 0.0);
3537
+ }
3538
+
3539
+ fn rotateDirection(direction: vec2f, rotation: f32) -> vec2f {
3540
+ let s = sin(rotation);
3541
+ let c = cos(rotation);
3542
+ return vec2f(direction.x * c - direction.y * s, direction.x * s + direction.y * c);
3543
+ }
3544
+
3545
+ fn getIridescenceTint(iridescence: f32, thickness: f32, NdotV: f32) -> vec3f {
3546
+ if (iridescence <= 0.0) {
3547
+ return vec3f(1.0);
3548
+ }
3549
+
3550
+ let phase = 0.015 * thickness * pbrMaterial.iridescenceIor + (1.0 - NdotV) * 6.0;
3551
+ let thinFilmTint =
3552
+ 0.5 +
3553
+ 0.5 *
3554
+ cos(vec3f(phase, phase + 2.0943951, phase + 4.1887902));
3555
+ return mix(vec3f(1.0), thinFilmTint, iridescence);
3556
+ }
3557
+
3558
+ fn getVolumeAttenuation(thickness: f32) -> vec3f {
3559
+ if (thickness <= 0.0) {
3560
+ return vec3f(1.0);
3561
+ }
3562
+
3563
+ let attenuationCoefficient =
3564
+ -log(max(pbrMaterial.attenuationColor, vec3f(0.0001))) /
3565
+ max(pbrMaterial.attenuationDistance, 0.0001);
3566
+ return exp(-attenuationCoefficient * thickness);
3567
+ }
3568
+
3569
+ fn createClearcoatPBRInfo(
3570
+ basePBRInfo: PBRInfo,
3571
+ clearcoatNormal: vec3f,
3572
+ clearcoatRoughness: f32
3573
+ ) -> PBRInfo {
3574
+ let perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
3575
+ let alphaRoughness = perceptualRoughness * perceptualRoughness;
3576
+ let NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);
3577
+
3578
+ return PBRInfo(
3579
+ basePBRInfo.NdotL,
3580
+ NdotV,
3581
+ basePBRInfo.NdotH,
3582
+ basePBRInfo.LdotH,
3583
+ basePBRInfo.VdotH,
3584
+ perceptualRoughness,
3585
+ 0.0,
3586
+ vec3f(0.04),
3587
+ vec3f(1.0),
3588
+ alphaRoughness,
3589
+ vec3f(0.0),
3590
+ vec3f(0.04),
3591
+ clearcoatNormal,
3592
+ basePBRInfo.v
3593
+ );
3594
+ }
3595
+
3596
+ fn calculateClearcoatContribution(
3597
+ pbrInfo: PBRInfo,
3598
+ lightColor: vec3f,
3599
+ clearcoatNormal: vec3f,
3600
+ clearcoatFactor: f32,
3601
+ clearcoatRoughness: f32
3602
+ ) -> vec3f {
3603
+ if (clearcoatFactor <= 0.0) {
3604
+ return vec3f(0.0);
3605
+ }
3606
+
3607
+ let clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
3608
+ return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;
3609
+ }
3610
+
3611
+ #ifdef USE_IBL
3612
+ fn calculateClearcoatIBLContribution(
3613
+ pbrInfo: PBRInfo,
3614
+ clearcoatNormal: vec3f,
3615
+ reflection: vec3f,
3616
+ clearcoatFactor: f32,
3617
+ clearcoatRoughness: f32
3618
+ ) -> vec3f {
3619
+ if (clearcoatFactor <= 0.0) {
3620
+ return vec3f(0.0);
3621
+ }
3622
+
3623
+ let clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
3624
+ return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;
3625
+ }
3626
+ #endif
3627
+
3628
+ fn calculateSheenContribution(
3629
+ pbrInfo: PBRInfo,
3630
+ lightColor: vec3f,
3631
+ sheenColor: vec3f,
3632
+ sheenRoughness: f32
3633
+ ) -> vec3f {
3634
+ if (maxComponent(sheenColor) <= 0.0) {
3635
+ return vec3f(0.0);
3636
+ }
3637
+
3638
+ let sheenFresnel = pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
3639
+ let sheenVisibility = mix(1.0, pbrInfo.NdotL * pbrInfo.NdotV, sheenRoughness);
3640
+ return pbrInfo.NdotL *
3641
+ lightColor *
3642
+ sheenColor *
3643
+ (0.25 + 0.75 * sheenFresnel) *
3644
+ sheenVisibility *
3645
+ (1.0 - pbrInfo.metalness);
3646
+ }
3647
+
3648
+ fn calculateAnisotropyBoost(
3649
+ pbrInfo: PBRInfo,
3650
+ anisotropyTangent: vec3f,
3651
+ anisotropyStrength: f32
3652
+ ) -> f32 {
3653
+ if (anisotropyStrength <= 0.0) {
3654
+ return 1.0;
3655
+ }
3656
+
3657
+ let anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));
3658
+ let bitangentViewAlignment = abs(dot(pbrInfo.v, anisotropyBitangent));
3659
+ return mix(1.0, 0.65 + 0.7 * bitangentViewAlignment, anisotropyStrength);
3660
+ }
3661
+
3662
+ fn calculateMaterialLightColor(
3663
+ pbrInfo: PBRInfo,
3664
+ lightColor: vec3f,
3665
+ clearcoatNormal: vec3f,
3666
+ clearcoatFactor: f32,
3667
+ clearcoatRoughness: f32,
3668
+ sheenColor: vec3f,
3669
+ sheenRoughness: f32,
3670
+ anisotropyTangent: vec3f,
3671
+ anisotropyStrength: f32
3672
+ ) -> vec3f {
3673
+ let anisotropyBoost = calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
3674
+ var color = calculateFinalColor(pbrInfo, lightColor) * anisotropyBoost;
3675
+ color += calculateClearcoatContribution(
3676
+ pbrInfo,
3677
+ lightColor,
3678
+ clearcoatNormal,
3679
+ clearcoatFactor,
3680
+ clearcoatRoughness
3681
+ );
3682
+ color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);
3683
+ return color;
2196
3684
  }
2197
3685
 
2198
3686
  fn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {
@@ -2215,7 +3703,12 @@ fn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection:
2215
3703
  }
2216
3704
 
2217
3705
  fn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {
2218
- let light_direction = normalize(pointLight.position - pbr_vPosition);
3706
+ let light_direction = normalize(pointLight.position - fragmentInputs.pbr_vPosition);
3707
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
3708
+ }
3709
+
3710
+ fn PBRInfo_setSpotLight(pbrInfo: ptr<function, PBRInfo>, spotLight: SpotLight) {
3711
+ let light_direction = normalize(spotLight.position - fragmentInputs.pbr_vPosition);
2219
3712
  PBRInfo_setDirectionalLight(pbrInfo, light_direction);
2220
3713
  }
2221
3714
 
@@ -2233,12 +3726,63 @@ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
2233
3726
  }
2234
3727
 
2235
3728
  fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
3729
+ let baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
3730
+ let metallicRoughnessUV = getMaterialUV(
3731
+ pbrMaterial.metallicRoughnessUVSet,
3732
+ pbrMaterial.metallicRoughnessUVTransform
3733
+ );
3734
+ let normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
3735
+ let occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);
3736
+ let emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);
3737
+ let specularColorUV = getMaterialUV(
3738
+ pbrMaterial.specularColorUVSet,
3739
+ pbrMaterial.specularColorUVTransform
3740
+ );
3741
+ let specularIntensityUV = getMaterialUV(
3742
+ pbrMaterial.specularIntensityUVSet,
3743
+ pbrMaterial.specularIntensityUVTransform
3744
+ );
3745
+ let transmissionUV = getMaterialUV(
3746
+ pbrMaterial.transmissionUVSet,
3747
+ pbrMaterial.transmissionUVTransform
3748
+ );
3749
+ let thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);
3750
+ let clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);
3751
+ let clearcoatRoughnessUV = getMaterialUV(
3752
+ pbrMaterial.clearcoatRoughnessUVSet,
3753
+ pbrMaterial.clearcoatRoughnessUVTransform
3754
+ );
3755
+ let clearcoatNormalUV = getMaterialUV(
3756
+ pbrMaterial.clearcoatNormalUVSet,
3757
+ pbrMaterial.clearcoatNormalUVTransform
3758
+ );
3759
+ let sheenColorUV = getMaterialUV(
3760
+ pbrMaterial.sheenColorUVSet,
3761
+ pbrMaterial.sheenColorUVTransform
3762
+ );
3763
+ let sheenRoughnessUV = getMaterialUV(
3764
+ pbrMaterial.sheenRoughnessUVSet,
3765
+ pbrMaterial.sheenRoughnessUVTransform
3766
+ );
3767
+ let iridescenceUV = getMaterialUV(
3768
+ pbrMaterial.iridescenceUVSet,
3769
+ pbrMaterial.iridescenceUVTransform
3770
+ );
3771
+ let iridescenceThicknessUV = getMaterialUV(
3772
+ pbrMaterial.iridescenceThicknessUVSet,
3773
+ pbrMaterial.iridescenceThicknessUVTransform
3774
+ );
3775
+ let anisotropyUV = getMaterialUV(
3776
+ pbrMaterial.anisotropyUVSet,
3777
+ pbrMaterial.anisotropyUVTransform
3778
+ );
3779
+
2236
3780
  // The albedo may be defined from a base texture or a flat color
2237
- var baseColor: vec4<f32>;
3781
+ var baseColor: vec4<f32> = pbrMaterial.baseColorFactor;
2238
3782
  #ifdef HAS_BASECOLORMAP
2239
- baseColor = SRGBtoLINEAR(textureSample(pbr_baseColorSampler, pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
2240
- #else
2241
- baseColor = pbrMaterial.baseColorFactor;
3783
+ baseColor = SRGBtoLINEAR(
3784
+ textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, baseColorUV)
3785
+ ) * pbrMaterial.baseColorFactor;
2242
3786
  #endif
2243
3787
 
2244
3788
  #ifdef ALPHA_CUTOFF
@@ -2248,8 +3792,9 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2248
3792
  #endif
2249
3793
 
2250
3794
  var color = vec3<f32>(0.0, 0.0, 0.0);
3795
+ var transmission = 0.0;
2251
3796
 
2252
- if (pbrMaterial.unlit) {
3797
+ if (pbrMaterial.unlit != 0u) {
2253
3798
  color = baseColor.rgb;
2254
3799
  } else {
2255
3800
  // Metallic and Roughness material properties are packed together
@@ -2260,20 +3805,317 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2260
3805
  #ifdef HAS_METALROUGHNESSMAP
2261
3806
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
2262
3807
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
2263
- let mrSample = textureSample(pbr_metallicRoughnessSampler, pbr_metallicRoughnessSampler, pbr_vUV);
3808
+ let mrSample = textureSample(
3809
+ pbr_metallicRoughnessSampler,
3810
+ pbr_metallicRoughnessSamplerSampler,
3811
+ metallicRoughnessUV
3812
+ );
2264
3813
  perceptualRoughness = mrSample.g * perceptualRoughness;
2265
3814
  metallic = mrSample.b * metallic;
2266
3815
  #endif
2267
3816
  perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
2268
3817
  metallic = clamp(metallic, 0.0, 1.0);
3818
+ let tbn = getTBN(normalUV);
3819
+ let n = getNormal(tbn, normalUV); // normal at surface point
3820
+ let v = normalize(pbrProjection.camera - fragmentInputs.pbr_vPosition); // Vector from surface point to camera
3821
+ let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
3822
+ var useExtendedPBR = false;
3823
+ #ifdef USE_MATERIAL_EXTENSIONS
3824
+ useExtendedPBR =
3825
+ pbrMaterial.specularColorMapEnabled != 0 ||
3826
+ pbrMaterial.specularIntensityMapEnabled != 0 ||
3827
+ abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||
3828
+ maxComponent(abs(pbrMaterial.specularColorFactor - vec3f(1.0))) > 0.0001 ||
3829
+ abs(pbrMaterial.ior - 1.5) > 0.0001 ||
3830
+ pbrMaterial.transmissionMapEnabled != 0 ||
3831
+ pbrMaterial.transmissionFactor > 0.0001 ||
3832
+ pbrMaterial.clearcoatMapEnabled != 0 ||
3833
+ pbrMaterial.clearcoatRoughnessMapEnabled != 0 ||
3834
+ pbrMaterial.clearcoatFactor > 0.0001 ||
3835
+ pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||
3836
+ pbrMaterial.sheenColorMapEnabled != 0 ||
3837
+ pbrMaterial.sheenRoughnessMapEnabled != 0 ||
3838
+ maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||
3839
+ pbrMaterial.sheenRoughnessFactor > 0.0001 ||
3840
+ pbrMaterial.iridescenceMapEnabled != 0 ||
3841
+ pbrMaterial.iridescenceFactor > 0.0001 ||
3842
+ abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||
3843
+ abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||
3844
+ abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||
3845
+ pbrMaterial.anisotropyMapEnabled != 0 ||
3846
+ pbrMaterial.anisotropyStrength > 0.0001 ||
3847
+ abs(pbrMaterial.anisotropyRotation) > 0.0001 ||
3848
+ length(pbrMaterial.anisotropyDirection - vec2f(1.0, 0.0)) > 0.0001;
3849
+ #endif
3850
+
3851
+ if (!useExtendedPBR) {
3852
+ let alphaRoughness = perceptualRoughness * perceptualRoughness;
3853
+
3854
+ let f0 = vec3<f32>(0.04);
3855
+ var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);
3856
+ diffuseColor *= 1.0 - metallic;
3857
+ let specularColor = mix(f0, baseColor.rgb, metallic);
3858
+
3859
+ let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
3860
+ let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
3861
+ let specularEnvironmentR0 = specularColor;
3862
+ let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;
3863
+ let reflection = -normalize(reflect(v, n));
3864
+
3865
+ var pbrInfo = PBRInfo(
3866
+ 0.0, // NdotL
3867
+ NdotV,
3868
+ 0.0, // NdotH
3869
+ 0.0, // LdotH
3870
+ 0.0, // VdotH
3871
+ perceptualRoughness,
3872
+ metallic,
3873
+ specularEnvironmentR0,
3874
+ specularEnvironmentR90,
3875
+ alphaRoughness,
3876
+ diffuseColor,
3877
+ specularColor,
3878
+ n,
3879
+ v
3880
+ );
3881
+
3882
+ #ifdef USE_LIGHTS
3883
+ PBRInfo_setAmbientLight(&pbrInfo);
3884
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
3885
+
3886
+ for (var i = 0; i < lighting.directionalLightCount; i++) {
3887
+ if (i < lighting.directionalLightCount) {
3888
+ PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
3889
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
3890
+ }
3891
+ }
3892
+
3893
+ for (var i = 0; i < lighting.pointLightCount; i++) {
3894
+ if (i < lighting.pointLightCount) {
3895
+ PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));
3896
+ let attenuation = getPointLightAttenuation(
3897
+ lighting_getPointLight(i),
3898
+ distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)
3899
+ );
3900
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
3901
+ }
3902
+ }
3903
+
3904
+ for (var i = 0; i < lighting.spotLightCount; i++) {
3905
+ if (i < lighting.spotLightCount) {
3906
+ PBRInfo_setSpotLight(&pbrInfo, lighting_getSpotLight(i));
3907
+ let attenuation = getSpotLightAttenuation(
3908
+ lighting_getSpotLight(i),
3909
+ fragmentInputs.pbr_vPosition
3910
+ );
3911
+ color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);
3912
+ }
3913
+ }
3914
+ #endif
3915
+
3916
+ #ifdef USE_IBL
3917
+ if (pbrMaterial.IBLenabled != 0) {
3918
+ color += getIBLContribution(pbrInfo, n, reflection);
3919
+ }
3920
+ #endif
3921
+
3922
+ #ifdef HAS_OCCLUSIONMAP
3923
+ if (pbrMaterial.occlusionMapEnabled != 0) {
3924
+ let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;
3925
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
3926
+ }
3927
+ #endif
3928
+
3929
+ var emissive = pbrMaterial.emissiveFactor;
3930
+ #ifdef HAS_EMISSIVEMAP
3931
+ if (pbrMaterial.emissiveMapEnabled != 0u) {
3932
+ emissive *= SRGBtoLINEAR(
3933
+ textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, emissiveUV)
3934
+ ).rgb;
3935
+ }
3936
+ #endif
3937
+ color += emissive * pbrMaterial.emissiveStrength;
3938
+
3939
+ #ifdef PBR_DEBUG
3940
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
3941
+ color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);
3942
+ color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
3943
+ #endif
3944
+
3945
+ return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);
3946
+ }
3947
+
3948
+ var specularIntensity = pbrMaterial.specularIntensityFactor;
3949
+ #ifdef HAS_SPECULARINTENSITYMAP
3950
+ if (pbrMaterial.specularIntensityMapEnabled != 0) {
3951
+ specularIntensity *= textureSample(
3952
+ pbr_specularIntensitySampler,
3953
+ pbr_specularIntensitySamplerSampler,
3954
+ specularIntensityUV
3955
+ ).a;
3956
+ }
3957
+ #endif
3958
+
3959
+ var specularFactor = pbrMaterial.specularColorFactor;
3960
+ #ifdef HAS_SPECULARCOLORMAP
3961
+ if (pbrMaterial.specularColorMapEnabled != 0) {
3962
+ specularFactor *= SRGBtoLINEAR(
3963
+ textureSample(
3964
+ pbr_specularColorSampler,
3965
+ pbr_specularColorSamplerSampler,
3966
+ specularColorUV
3967
+ )
3968
+ ).rgb;
3969
+ }
3970
+ #endif
3971
+
3972
+ transmission = pbrMaterial.transmissionFactor;
3973
+ #ifdef HAS_TRANSMISSIONMAP
3974
+ if (pbrMaterial.transmissionMapEnabled != 0) {
3975
+ transmission *= textureSample(
3976
+ pbr_transmissionSampler,
3977
+ pbr_transmissionSamplerSampler,
3978
+ transmissionUV
3979
+ ).r;
3980
+ }
3981
+ #endif
3982
+ transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);
3983
+ var thickness = max(pbrMaterial.thicknessFactor, 0.0);
3984
+ #ifdef HAS_THICKNESSMAP
3985
+ thickness *= textureSample(
3986
+ pbr_thicknessSampler,
3987
+ pbr_thicknessSamplerSampler,
3988
+ thicknessUV
3989
+ ).g;
3990
+ #endif
3991
+
3992
+ var clearcoatFactor = pbrMaterial.clearcoatFactor;
3993
+ var clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;
3994
+ #ifdef HAS_CLEARCOATMAP
3995
+ if (pbrMaterial.clearcoatMapEnabled != 0) {
3996
+ clearcoatFactor *= textureSample(
3997
+ pbr_clearcoatSampler,
3998
+ pbr_clearcoatSamplerSampler,
3999
+ clearcoatUV
4000
+ ).r;
4001
+ }
4002
+ #endif
4003
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
4004
+ if (pbrMaterial.clearcoatRoughnessMapEnabled != 0) {
4005
+ clearcoatRoughness *= textureSample(
4006
+ pbr_clearcoatRoughnessSampler,
4007
+ pbr_clearcoatRoughnessSamplerSampler,
4008
+ clearcoatRoughnessUV
4009
+ ).g;
4010
+ }
4011
+ #endif
4012
+ clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);
4013
+ clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
4014
+ let clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);
4015
+
4016
+ var sheenColor = pbrMaterial.sheenColorFactor;
4017
+ var sheenRoughness = pbrMaterial.sheenRoughnessFactor;
4018
+ #ifdef HAS_SHEENCOLORMAP
4019
+ if (pbrMaterial.sheenColorMapEnabled != 0) {
4020
+ sheenColor *= SRGBtoLINEAR(
4021
+ textureSample(
4022
+ pbr_sheenColorSampler,
4023
+ pbr_sheenColorSamplerSampler,
4024
+ sheenColorUV
4025
+ )
4026
+ ).rgb;
4027
+ }
4028
+ #endif
4029
+ #ifdef HAS_SHEENROUGHNESSMAP
4030
+ if (pbrMaterial.sheenRoughnessMapEnabled != 0) {
4031
+ sheenRoughness *= textureSample(
4032
+ pbr_sheenRoughnessSampler,
4033
+ pbr_sheenRoughnessSamplerSampler,
4034
+ sheenRoughnessUV
4035
+ ).a;
4036
+ }
4037
+ #endif
4038
+ sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);
4039
+
4040
+ var iridescence = pbrMaterial.iridescenceFactor;
4041
+ #ifdef HAS_IRIDESCENCEMAP
4042
+ if (pbrMaterial.iridescenceMapEnabled != 0) {
4043
+ iridescence *= textureSample(
4044
+ pbr_iridescenceSampler,
4045
+ pbr_iridescenceSamplerSampler,
4046
+ iridescenceUV
4047
+ ).r;
4048
+ }
4049
+ #endif
4050
+ iridescence = clamp(iridescence, 0.0, 1.0);
4051
+ var iridescenceThickness = mix(
4052
+ pbrMaterial.iridescenceThicknessRange.x,
4053
+ pbrMaterial.iridescenceThicknessRange.y,
4054
+ 0.5
4055
+ );
4056
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
4057
+ iridescenceThickness = mix(
4058
+ pbrMaterial.iridescenceThicknessRange.x,
4059
+ pbrMaterial.iridescenceThicknessRange.y,
4060
+ textureSample(
4061
+ pbr_iridescenceThicknessSampler,
4062
+ pbr_iridescenceThicknessSamplerSampler,
4063
+ iridescenceThicknessUV
4064
+ ).g
4065
+ );
4066
+ #endif
4067
+
4068
+ var anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);
4069
+ var anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);
4070
+ #ifdef HAS_ANISOTROPYMAP
4071
+ if (pbrMaterial.anisotropyMapEnabled != 0) {
4072
+ let anisotropySample = textureSample(
4073
+ pbr_anisotropySampler,
4074
+ pbr_anisotropySamplerSampler,
4075
+ anisotropyUV
4076
+ ).rgb;
4077
+ anisotropyStrength *= anisotropySample.b;
4078
+ let mappedDirection = anisotropySample.rg * 2.0 - 1.0;
4079
+ if (length(mappedDirection) > 0.0001) {
4080
+ anisotropyDirection = normalize(mappedDirection);
4081
+ }
4082
+ }
4083
+ #endif
4084
+ anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);
4085
+ var anisotropyTangent =
4086
+ normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);
4087
+ if (length(anisotropyTangent) < 0.0001) {
4088
+ anisotropyTangent = normalize(tbn[0]);
4089
+ }
4090
+ let anisotropyViewAlignment = abs(dot(v, anisotropyTangent));
4091
+ perceptualRoughness = mix(
4092
+ perceptualRoughness,
4093
+ clamp(perceptualRoughness * (1.0 - 0.6 * anisotropyViewAlignment), c_MinRoughness, 1.0),
4094
+ anisotropyStrength
4095
+ );
4096
+
2269
4097
  // Roughness is authored as perceptual roughness; as is convention,
2270
4098
  // convert to material roughness by squaring the perceptual roughness [2].
2271
4099
  let alphaRoughness = perceptualRoughness * perceptualRoughness;
2272
4100
 
2273
- let f0 = vec3<f32>(0.04);
2274
- var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);
2275
- diffuseColor *= 1.0 - metallic;
2276
- let specularColor = mix(f0, baseColor.rgb, metallic);
4101
+ let dielectricF0 = getDielectricF0(pbrMaterial.ior);
4102
+ var dielectricSpecularF0 = min(
4103
+ vec3f(dielectricF0) * specularFactor * specularIntensity,
4104
+ vec3f(1.0)
4105
+ );
4106
+ let iridescenceTint = getIridescenceTint(iridescence, iridescenceThickness, NdotV);
4107
+ dielectricSpecularF0 = mix(
4108
+ dielectricSpecularF0,
4109
+ dielectricSpecularF0 * iridescenceTint,
4110
+ iridescence
4111
+ );
4112
+ var diffuseColor = baseColor.rgb * (vec3f(1.0) - dielectricSpecularF0);
4113
+ diffuseColor *= (1.0 - metallic) * (1.0 - transmission);
4114
+ var specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);
4115
+
4116
+ let baseLayerEnergy = 1.0 - clearcoatFactor * 0.25;
4117
+ diffuseColor *= baseLayerEnergy;
4118
+ specularColor *= baseLayerEnergy;
2277
4119
 
2278
4120
  // Compute reflectance.
2279
4121
  let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
@@ -2285,11 +4127,6 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2285
4127
  let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
2286
4128
  let specularEnvironmentR0 = specularColor;
2287
4129
  let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;
2288
-
2289
- let n = getNormal(); // normal at surface point
2290
- let v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
2291
-
2292
- let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
2293
4130
  let reflection = -normalize(reflect(v, n));
2294
4131
 
2295
4132
  var pbrInfo = PBRInfo(
@@ -2312,13 +4149,33 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2312
4149
  #ifdef USE_LIGHTS
2313
4150
  // Apply ambient light
2314
4151
  PBRInfo_setAmbientLight(&pbrInfo);
2315
- color += calculateFinalColor(pbrInfo, lighting.ambientColor);
4152
+ color += calculateMaterialLightColor(
4153
+ pbrInfo,
4154
+ lighting.ambientColor,
4155
+ clearcoatNormal,
4156
+ clearcoatFactor,
4157
+ clearcoatRoughness,
4158
+ sheenColor,
4159
+ sheenRoughness,
4160
+ anisotropyTangent,
4161
+ anisotropyStrength
4162
+ );
2316
4163
 
2317
4164
  // Apply directional light
2318
4165
  for (var i = 0; i < lighting.directionalLightCount; i++) {
2319
4166
  if (i < lighting.directionalLightCount) {
2320
4167
  PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
2321
- color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
4168
+ color += calculateMaterialLightColor(
4169
+ pbrInfo,
4170
+ lighting_getDirectionalLight(i).color,
4171
+ clearcoatNormal,
4172
+ clearcoatFactor,
4173
+ clearcoatRoughness,
4174
+ sheenColor,
4175
+ sheenRoughness,
4176
+ anisotropyTangent,
4177
+ anisotropyStrength
4178
+ );
2322
4179
  }
2323
4180
  }
2324
4181
 
@@ -2326,33 +4183,80 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2326
4183
  for (var i = 0; i < lighting.pointLightCount; i++) {
2327
4184
  if (i < lighting.pointLightCount) {
2328
4185
  PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));
2329
- let attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
2330
- color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
4186
+ let attenuation = getPointLightAttenuation(
4187
+ lighting_getPointLight(i),
4188
+ distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)
4189
+ );
4190
+ color += calculateMaterialLightColor(
4191
+ pbrInfo,
4192
+ lighting_getPointLight(i).color / attenuation,
4193
+ clearcoatNormal,
4194
+ clearcoatFactor,
4195
+ clearcoatRoughness,
4196
+ sheenColor,
4197
+ sheenRoughness,
4198
+ anisotropyTangent,
4199
+ anisotropyStrength
4200
+ );
4201
+ }
4202
+ }
4203
+
4204
+ for (var i = 0; i < lighting.spotLightCount; i++) {
4205
+ if (i < lighting.spotLightCount) {
4206
+ PBRInfo_setSpotLight(&pbrInfo, lighting_getSpotLight(i));
4207
+ let attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), fragmentInputs.pbr_vPosition);
4208
+ color += calculateMaterialLightColor(
4209
+ pbrInfo,
4210
+ lighting_getSpotLight(i).color / attenuation,
4211
+ clearcoatNormal,
4212
+ clearcoatFactor,
4213
+ clearcoatRoughness,
4214
+ sheenColor,
4215
+ sheenRoughness,
4216
+ anisotropyTangent,
4217
+ anisotropyStrength
4218
+ );
2331
4219
  }
2332
4220
  }
2333
4221
  #endif
2334
4222
 
2335
4223
  // Calculate lighting contribution from image based lighting source (IBL)
2336
4224
  #ifdef USE_IBL
2337
- if (pbrMaterial.IBLenabled) {
2338
- color += getIBLContribution(pbrInfo, n, reflection);
4225
+ if (pbrMaterial.IBLenabled != 0) {
4226
+ color += getIBLContribution(pbrInfo, n, reflection) *
4227
+ calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
4228
+ color += calculateClearcoatIBLContribution(
4229
+ pbrInfo,
4230
+ clearcoatNormal,
4231
+ -normalize(reflect(v, clearcoatNormal)),
4232
+ clearcoatFactor,
4233
+ clearcoatRoughness
4234
+ );
4235
+ color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;
2339
4236
  }
2340
4237
  #endif
2341
4238
 
2342
4239
  // Apply optional PBR terms for additional (optional) shading
2343
4240
  #ifdef HAS_OCCLUSIONMAP
2344
- if (pbrMaterial.occlusionMapEnabled) {
2345
- let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSampler, pbr_vUV).r;
4241
+ if (pbrMaterial.occlusionMapEnabled != 0) {
4242
+ let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;
2346
4243
  color = mix(color, color * ao, pbrMaterial.occlusionStrength);
2347
4244
  }
2348
4245
  #endif
2349
4246
 
4247
+ var emissive = pbrMaterial.emissiveFactor;
2350
4248
  #ifdef HAS_EMISSIVEMAP
2351
- if (pbrMaterial.emissiveMapEnabled) {
2352
- let emissive = SRGBtoLINEAR(textureSample(pbr_emissiveSampler, pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
2353
- color += emissive;
4249
+ if (pbrMaterial.emissiveMapEnabled != 0u) {
4250
+ emissive *= SRGBtoLINEAR(
4251
+ textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, emissiveUV)
4252
+ ).rgb;
2354
4253
  }
2355
4254
  #endif
4255
+ color += emissive * pbrMaterial.emissiveStrength;
4256
+
4257
+ if (transmission > 0.0) {
4258
+ color = mix(color, color * getVolumeAttenuation(thickness), transmission);
4259
+ }
2356
4260
 
2357
4261
  // This section uses mix to override final color for reference app visualization
2358
4262
  // of various parameters in the lighting equation.
@@ -2371,14 +4275,52 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2371
4275
  #endif
2372
4276
  }
2373
4277
 
2374
- return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);
4278
+ let alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
4279
+ return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), alpha);
2375
4280
  }
2376
- `;var vr=`uniform pbrProjectionUniforms {
4281
+ `;var Bn=`layout(std140) uniform pbrProjectionUniforms {
2377
4282
  mat4 modelViewProjectionMatrix;
2378
4283
  mat4 modelMatrix;
2379
4284
  mat4 normalMatrix;
2380
4285
  vec3 camera;
2381
4286
  } pbrProjection;
2382
- `,br={name:"pbrProjection",vs:vr,fs:vr,getUniforms:a=>a,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<i32>"}};var xr={props:{},uniforms:{},name:"pbrMaterial",dependencies:[te,br],source:gr,vs:mr,fs:_r,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:a=>a,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>"}};return Er(Ze);})();
4287
+ `,Bo=`struct pbrProjectionUniforms {
4288
+ modelViewProjectionMatrix: mat4x4<f32>,
4289
+ modelMatrix: mat4x4<f32>,
4290
+ normalMatrix: mat4x4<f32>,
4291
+ camera: vec3<f32>
4292
+ };
4293
+
4294
+ @group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;
4295
+ `,kn={name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:Bo,vs:Bn,fs:Bn,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}};var Dn={props:{},uniforms:{},defaultUniforms:{unlit:!1,baseColorMapEnabled:!1,baseColorFactor:[1,1,1,1],normalMapEnabled:!1,normalScale:1,emissiveMapEnabled:!1,emissiveFactor:[0,0,0],metallicRoughnessValues:[1,1],metallicRoughnessMapEnabled:!1,occlusionMapEnabled:!1,occlusionStrength:1,alphaCutoffEnabled:!1,alphaCutoff:.5,IBLenabled:!1,scaleIBLAmbient:[1,1],scaleDiffBaseMR:[0,0,0,0],scaleFGDSpec:[0,0,0,0],specularColorFactor:[1,1,1],specularIntensityFactor:1,specularColorMapEnabled:!1,specularIntensityMapEnabled:!1,ior:1.5,transmissionFactor:0,transmissionMapEnabled:!1,thicknessFactor:0,attenuationDistance:1e9,attenuationColor:[1,1,1],clearcoatFactor:0,clearcoatRoughnessFactor:0,clearcoatMapEnabled:!1,clearcoatRoughnessMapEnabled:!1,sheenColorFactor:[0,0,0],sheenRoughnessFactor:0,sheenColorMapEnabled:!1,sheenRoughnessMapEnabled:!1,iridescenceFactor:0,iridescenceIor:1.3,iridescenceThicknessRange:[100,400],iridescenceMapEnabled:!1,anisotropyStrength:0,anisotropyRotation:0,anisotropyDirection:[1,0],anisotropyMapEnabled:!1,emissiveStrength:1,baseColorUVSet:0,baseColorUVTransform:[1,0,0,0,1,0,0,0,1],metallicRoughnessUVSet:0,metallicRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],normalUVSet:0,normalUVTransform:[1,0,0,0,1,0,0,0,1],occlusionUVSet:0,occlusionUVTransform:[1,0,0,0,1,0,0,0,1],emissiveUVSet:0,emissiveUVTransform:[1,0,0,0,1,0,0,0,1],specularColorUVSet:0,specularColorUVTransform:[1,0,0,0,1,0,0,0,1],specularIntensityUVSet:0,specularIntensityUVTransform:[1,0,0,0,1,0,0,0,1],transmissionUVSet:0,transmissionUVTransform:[1,0,0,0,1,0,0,0,1],thicknessUVSet:0,thicknessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatUVSet:0,clearcoatUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatRoughnessUVSet:0,clearcoatRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatNormalUVSet:0,clearcoatNormalUVTransform:[1,0,0,0,1,0,0,0,1],sheenColorUVSet:0,sheenColorUVTransform:[1,0,0,0,1,0,0,0,1],sheenRoughnessUVSet:0,sheenRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceUVSet:0,iridescenceUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceThicknessUVSet:0,iridescenceThicknessUVTransform:[1,0,0,0,1,0,0,0,1],anisotropyUVSet:0,anisotropyUVTransform:[1,0,0,0,1,0,0,0,1]},name:"pbrMaterial",firstBindingSlot:0,bindingLayout:[{name:"pbrMaterial",group:3},{name:"pbr_baseColorSampler",group:3},{name:"pbr_normalSampler",group:3},{name:"pbr_emissiveSampler",group:3},{name:"pbr_metallicRoughnessSampler",group:3},{name:"pbr_occlusionSampler",group:3},{name:"pbr_specularColorSampler",group:3},{name:"pbr_specularIntensitySampler",group:3},{name:"pbr_transmissionSampler",group:3},{name:"pbr_thicknessSampler",group:3},{name:"pbr_clearcoatSampler",group:3},{name:"pbr_clearcoatRoughnessSampler",group:3},{name:"pbr_clearcoatNormalSampler",group:3},{name:"pbr_sheenColorSampler",group:3},{name:"pbr_sheenRoughnessSampler",group:3},{name:"pbr_iridescenceSampler",group:3},{name:"pbr_iridescenceThicknessSampler",group:3},{name:"pbr_anisotropySampler",group:3}],dependencies:[V,Ne,kn],source:wn,vs:Fn,fs:Vn,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,HAS_SPECULARCOLORMAP:!1,HAS_SPECULARINTENSITYMAP:!1,HAS_TRANSMISSIONMAP:!1,HAS_THICKNESSMAP:!1,HAS_CLEARCOATMAP:!1,HAS_CLEARCOATROUGHNESSMAP:!1,HAS_CLEARCOATNORMALMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_SHEENROUGHNESSMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_IRIDESCENCETHICKNESSMAP:!1,HAS_ANISOTROPYMAP:!1,USE_MATERIAL_EXTENSIONS:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:e=>e,uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",specularColorFactor:"vec3<f32>",specularIntensityFactor:"f32",specularColorMapEnabled:"i32",specularIntensityMapEnabled:"i32",ior:"f32",transmissionFactor:"f32",transmissionMapEnabled:"i32",thicknessFactor:"f32",attenuationDistance:"f32",attenuationColor:"vec3<f32>",clearcoatFactor:"f32",clearcoatRoughnessFactor:"f32",clearcoatMapEnabled:"i32",clearcoatRoughnessMapEnabled:"i32",sheenColorFactor:"vec3<f32>",sheenRoughnessFactor:"f32",sheenColorMapEnabled:"i32",sheenRoughnessMapEnabled:"i32",iridescenceFactor:"f32",iridescenceIor:"f32",iridescenceThicknessRange:"vec2<f32>",iridescenceMapEnabled:"i32",anisotropyStrength:"f32",anisotropyRotation:"f32",anisotropyDirection:"vec2<f32>",anisotropyMapEnabled:"i32",emissiveStrength:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>",baseColorUVSet:"i32",baseColorUVTransform:"mat3x3<f32>",metallicRoughnessUVSet:"i32",metallicRoughnessUVTransform:"mat3x3<f32>",normalUVSet:"i32",normalUVTransform:"mat3x3<f32>",occlusionUVSet:"i32",occlusionUVTransform:"mat3x3<f32>",emissiveUVSet:"i32",emissiveUVTransform:"mat3x3<f32>",specularColorUVSet:"i32",specularColorUVTransform:"mat3x3<f32>",specularIntensityUVSet:"i32",specularIntensityUVTransform:"mat3x3<f32>",transmissionUVSet:"i32",transmissionUVTransform:"mat3x3<f32>",thicknessUVSet:"i32",thicknessUVTransform:"mat3x3<f32>",clearcoatUVSet:"i32",clearcoatUVTransform:"mat3x3<f32>",clearcoatRoughnessUVSet:"i32",clearcoatRoughnessUVTransform:"mat3x3<f32>",clearcoatNormalUVSet:"i32",clearcoatNormalUVTransform:"mat3x3<f32>",sheenColorUVSet:"i32",sheenColorUVTransform:"mat3x3<f32>",sheenRoughnessUVSet:"i32",sheenRoughnessUVTransform:"mat3x3<f32>",iridescenceUVSet:"i32",iridescenceUVTransform:"mat3x3<f32>",iridescenceThicknessUVSet:"i32",iridescenceThicknessUVTransform:"mat3x3<f32>",anisotropyUVSet:"i32",anisotropyUVTransform:"mat3x3<f32>"}};var zn=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Gn=`layout(std140) uniform pbrSceneUniforms {
4296
+ float exposure;
4297
+ int toneMapMode;
4298
+ float environmentIntensity;
4299
+ float environmentRotation;
4300
+ vec2 framebufferSize;
4301
+ mat4 viewMatrix;
4302
+ mat4 projectionMatrix;
4303
+ } pbrScene;
4304
+
4305
+ #ifdef USE_TRANSMISSION_FRAMEBUFFER
4306
+ uniform sampler2D pbr_transmissionFramebufferSampler;
4307
+ #endif
4308
+ `,ko=`struct pbrSceneUniforms {
4309
+ exposure: f32,
4310
+ toneMapMode: i32,
4311
+ environmentIntensity: f32,
4312
+ environmentRotation: f32,
4313
+ framebufferSize: vec2<f32>,
4314
+ viewMatrix: mat4x4<f32>,
4315
+ projectionMatrix: mat4x4<f32>
4316
+ };
4317
+
4318
+ @group(1) @binding(auto) var<uniform> pbrScene: pbrSceneUniforms;
4319
+
4320
+ #ifdef USE_TRANSMISSION_FRAMEBUFFER
4321
+ @group(1) @binding(auto) var pbr_transmissionFramebufferSampler: texture_2d<f32>;
4322
+ @group(1) @binding(auto) var pbr_transmissionFramebufferSamplerSampler: sampler;
4323
+ #endif
4324
+ `,Hn={name:"pbrScene",bindingLayout:[{name:"pbrScene",group:1},{name:"pbr_transmissionFramebufferSampler",group:1}],source:ko,vs:Gn,fs:Gn,getUniforms:e=>e,uniformTypes:{exposure:"f32",toneMapMode:"i32",environmentIntensity:"f32",environmentRotation:"f32",framebufferSize:"vec2<f32>",viewMatrix:"mat4x4<f32>",projectionMatrix:"mat4x4<f32>"},defaultUniforms:{exposure:1,toneMapMode:2,environmentIntensity:1,environmentRotation:Math.PI*.5,framebufferSize:[1,1],viewMatrix:zn,projectionMatrix:zn}};return Qn(se);})();
2383
4325
  return __exports__;
2384
4326
  });