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

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 (174) hide show
  1. package/dist/dist.dev.js +4798 -6439
  2. package/dist/dist.min.js +2047 -311
  3. package/dist/index.cjs +3033 -507
  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/preprocessor/preprocessor.d.ts.map +1 -1
  10. package/dist/lib/preprocessor/preprocessor.js +35 -8
  11. package/dist/lib/preprocessor/preprocessor.js.map +1 -1
  12. package/dist/lib/shader-assembler.d.ts +10 -0
  13. package/dist/lib/shader-assembler.d.ts.map +1 -1
  14. package/dist/lib/shader-assembler.js +20 -3
  15. package/dist/lib/shader-assembler.js.map +1 -1
  16. package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
  17. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  18. package/dist/lib/shader-assembly/assemble-shaders.js +214 -11
  19. package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
  20. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
  21. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
  22. package/dist/lib/shader-assembly/wgsl-binding-debug.js +140 -0
  23. package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
  24. package/dist/lib/shader-generator/glsl/generate-glsl.js +7 -4
  25. package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
  26. package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
  27. package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
  28. package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
  29. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +91 -0
  30. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
  31. package/dist/lib/shader-module/shader-module-uniform-layout.js +209 -0
  32. package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
  33. package/dist/lib/shader-module/shader-module.d.ts +12 -6
  34. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  35. package/dist/lib/shader-module/shader-module.js.map +1 -1
  36. package/dist/lib/utils/assert.d.ts.map +1 -1
  37. package/dist/lib/utils/assert.js +3 -1
  38. package/dist/lib/utils/assert.js.map +1 -1
  39. package/dist/lib/utils/uniform-types.d.ts +11 -7
  40. package/dist/lib/utils/uniform-types.d.ts.map +1 -1
  41. package/dist/modules/engine/picking/picking.d.ts +5 -2
  42. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  43. package/dist/modules/engine/picking/picking.js +5 -2
  44. package/dist/modules/engine/picking/picking.js.map +1 -1
  45. package/dist/modules/engine/project/project.d.ts +1 -1
  46. package/dist/modules/engine/project/project.js +1 -1
  47. package/dist/modules/engine/skin/skin.d.ts +30 -0
  48. package/dist/modules/engine/skin/skin.d.ts.map +1 -0
  49. package/dist/modules/engine/skin/skin.js +86 -0
  50. package/dist/modules/engine/skin/skin.js.map +1 -0
  51. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
  52. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  53. package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
  54. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
  55. package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
  56. package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
  57. package/dist/modules/lighting/ibl/ibl.js +33 -0
  58. package/dist/modules/lighting/ibl/ibl.js.map +1 -0
  59. package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
  60. package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
  61. package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
  62. package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
  63. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
  64. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
  65. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
  66. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
  67. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
  68. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
  69. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
  70. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
  71. package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
  72. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
  73. package/dist/modules/lighting/lights/lighting-glsl.js +44 -38
  74. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
  75. package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
  76. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
  77. package/dist/modules/lighting/lights/lighting-wgsl.js +46 -18
  78. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
  79. package/dist/modules/lighting/lights/lighting.d.ts +104 -62
  80. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  81. package/dist/modules/lighting/lights/lighting.js +107 -68
  82. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  83. package/dist/modules/lighting/no-material/dirlight.d.ts +8 -3
  84. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  85. package/dist/modules/lighting/no-material/dirlight.js +4 -2
  86. package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
  87. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
  88. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
  89. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +581 -28
  90. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
  91. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
  92. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  93. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +850 -107
  94. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  95. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +172 -41
  96. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  97. package/dist/modules/lighting/pbr-material/pbr-material.js +109 -1
  98. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
  99. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
  100. package/dist/modules/lighting/pbr-material/pbr-projection.js +14 -2
  101. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
  102. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +40 -0
  103. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
  104. package/dist/modules/lighting/pbr-material/pbr-scene.js +67 -0
  105. package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
  106. package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
  107. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  108. package/dist/modules/lighting/phong-material/phong-material.js +4 -0
  109. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
  110. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  111. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  112. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +17 -6
  113. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
  114. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
  115. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
  116. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
  117. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
  118. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  119. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  120. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +42 -11
  121. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
  122. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
  123. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
  124. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
  125. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
  126. package/dist/modules/math/fp64/fp64.d.ts +1 -0
  127. package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
  128. package/dist/modules/math/fp64/fp64.js +8 -2
  129. package/dist/modules/math/fp64/fp64.js.map +1 -1
  130. package/dist/modules/math/random/random.d.ts +1 -1
  131. package/dist/modules/math/random/random.d.ts.map +1 -1
  132. package/dist/modules/math/random/random.js +2 -3
  133. package/dist/modules/math/random/random.js.map +1 -1
  134. package/package.json +4 -5
  135. package/src/index.ts +37 -6
  136. package/src/lib/preprocessor/preprocessor.ts +44 -8
  137. package/src/lib/shader-assembler.ts +25 -3
  138. package/src/lib/shader-assembly/assemble-shaders.ts +384 -12
  139. package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
  140. package/src/lib/shader-generator/glsl/generate-glsl.ts +11 -5
  141. package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
  142. package/src/lib/shader-module/shader-module-uniform-layout.ts +346 -0
  143. package/src/lib/shader-module/shader-module.ts +17 -7
  144. package/src/lib/utils/assert.ts +3 -1
  145. package/src/lib/utils/uniform-types.ts +24 -9
  146. package/src/modules/engine/picking/picking.ts +5 -2
  147. package/src/modules/engine/project/project.ts +1 -1
  148. package/src/modules/engine/skin/skin.ts +114 -0
  149. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  150. package/src/modules/lighting/ibl/ibl.ts +44 -0
  151. package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
  152. package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
  153. package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
  154. package/src/modules/lighting/lights/lighting-glsl.ts +44 -38
  155. package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
  156. package/src/modules/lighting/lights/lighting.ts +198 -99
  157. package/src/modules/lighting/no-material/dirlight.ts +4 -2
  158. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +581 -28
  159. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +850 -107
  160. package/src/modules/lighting/pbr-material/pbr-material.ts +185 -5
  161. package/src/modules/lighting/pbr-material/pbr-projection.ts +15 -2
  162. package/src/modules/lighting/pbr-material/pbr-scene.ts +91 -0
  163. package/src/modules/lighting/phong-material/phong-material.ts +5 -0
  164. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +17 -6
  165. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
  166. package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +42 -11
  167. package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
  168. package/src/modules/math/fp64/fp64.ts +9 -3
  169. package/src/modules/math/random/random.ts +2 -3
  170. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts +0 -8
  171. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +0 -1
  172. package/dist/lib/wgsl/get-shader-layout-wgsl.js +0 -95
  173. package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +0 -1
  174. 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 wn=Object.create;var W=Object.defineProperty;var Bn=Object.getOwnPropertyDescriptor;var kn=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var zn=(e,t,n)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Hn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Gn=(e,t)=>{for(var n in t)W(e,n,{get:t[n],enumerable:!0})},re=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kn(t))!Un.call(e,o)&&o!==n&&W(e,o,{get:()=>t[o],enumerable:!(r=Bn(t,o))||r.enumerable});return e},oe=(e,t,n)=>(re(e,t,"default"),n&&re(n,t,"default")),Je=(e,t,n)=>(n=e!=null?wn(Dn(e)):{},re(t||!e||!e.__esModule?W(n,"default",{value:e,enumerable:!0}):n,e)),Vn=e=>re(W({},"__esModule",{value:!0}),e);var et=(e,t,n)=>(zn(e,typeof t!="symbol"?t+"":t,n),n);var ye=Hn((Eo,tt)=>{tt.exports=globalThis.luma});var ne={};Gn(ne,{ShaderAssembler:()=>Q,_getDependencyGraph:()=>X,_resolveModules:()=>ut,assembleGLSLShaderPair:()=>ge,capitalize:()=>k,checkShaderModuleDeprecations:()=>K,combineInjects:()=>ft,convertToVec4:()=>De,dirlight:()=>Ye,fp32:()=>hn,fp64:()=>dn,fp64LowPart:()=>J,fp64arithmetic:()=>qe,fp64ify:()=>V,fp64ifyMatrix4:()=>ee,fromHalfFloat:()=>fn,generateShaderForModule:()=>wt,getGLSLUniformBlocks:()=>ce,getPassthroughFS:()=>Pt,getQualifierDetails:()=>yt,getShaderInfo:()=>fe,getShaderModuleDependencies:()=>Y,getShaderModuleSource:()=>me,getShaderModuleUniformBlockFields:()=>Oe,getShaderModuleUniformBlockName:()=>ae,getShaderModuleUniformLayoutValidationResult:()=>Te,getShaderModuleUniforms:()=>pt,gouraudMaterial:()=>Ze,ibl:()=>Ee,initializeShaderModule:()=>ie,initializeShaderModules:()=>T,lambertMaterial:()=>Xe,lighting:()=>F,pbrMaterial:()=>Nn,pbrScene:()=>Fn,phongMaterial:()=>Qe,picking:()=>_n,preprocess:()=>de,random:()=>un,skin:()=>bn,toHalfFloat:()=>ln,typeToChannelCount:()=>Ot,typeToChannelSuffix:()=>Nt,validateShaderModuleUniformLayout:()=>se,warnIfGLSLUniformBlocksAreNotStd140:()=>le});oe(ne,Je(ye(),1));function O(e,t){if(!e){let n=new Error(t||"shadertools: assertion failed.");throw Error.captureStackTrace?.(n,O),n}}var Pe={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 rt(e){let t={};for(let[n,r]of Object.entries(e))t[n]=jn(r);return t}function ot(e,t,n){let r={};for(let[o,i]of Object.entries(t))e&&o in e&&!i.private?(i.validate&&O(i.validate(e[o],i),`${n}: invalid ${o}`),r[o]=e[o]):r[o]=i.value;return r}function jn(e){let t=nt(e);if(t!=="object")return{value:e,...Pe[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...Pe[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=nt(e.value),{...e,...Pe[t],type:t}):{type:"object",value:null};throw new Error("props")}function nt(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}var it=`#ifdef MODULE_LOGDEPTH
8
8
  logdepth_adjustPosition(gl_Position);
9
9
  #endif
10
- `,In=`#ifdef MODULE_MATERIAL
10
+ `,at=`#ifdef MODULE_MATERIAL
11
11
  fragColor = material_filterColor(fragColor);
12
12
  #endif
13
13
 
@@ -27,10 +27,13 @@
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 Wn={vertex:it,fragment:at},st=/void\s+main\s*\([^)]*\)\s*\{\n?/,ct=/}\n?[^{}]*$/,Ne=[],$="__LUMA_INJECT_DECLARATIONS__";function lt(e){let t={vertex:{},fragment:{}};for(let n in e){let r=e[n],o=$n(n);typeof r=="string"&&(r={order:0,injection:r}),t[o][n]=r}return t}function $n(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),Ne.length=a.length;for(let c=0,l=a.length;c<l;++c)Ne[c]=a[c].injection;let s=`${Ne.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($,s));break;case"vs:#main-start":o&&(e=e.replace(st,c=>c+s));break;case"vs:#main-end":o&&(e=e.replace(ct,c=>s+c));break;case"fs:#decl":o||(e=e.replace($,s));break;case"fs:#main-start":o||(e=e.replace(st,c=>c+s));break;case"fs:#main-end":o||(e=e.replace(ct,c=>s+c));break;default:e=e.replace(i,c=>c+s)}}return e=e.replace($,""),r&&(e=e.replace(/\}\s*$/,i=>i+Wn[t])),e}function ft(e){let t={};return O(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 T(e){e.map(t=>ie(t))}function ie(e){if(e.instance)return;T(e.dependencies||[]);let{propTypes:t={},deprecations:n=[],inject:r={}}=e,o={normalizedInjections:lt(r),parsedDeprecations:qn(n)};t&&(o.propValidators=rt(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 pt(e,t,n){ie(e);let r=n||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,r):ot(t,e.instance?.propValidators,e.name)}function K(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 qn(e){return e.forEach(t=>{switch(t.type){case"function":t.regex=new RegExp(`\\b${t.old}\\(`);break;default:t.regex=new RegExp(`${t.type} ${t.old};`)}}),e}function Y(e){T(e);let t={},n={};X({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 T(r),r}function X(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&&X({modules:i.dependencies,level:n+1,moduleMap:r,moduleDepth:o})}function Kn(e){T(e);let t={},n={};return X({modules:e,level:0,moduleMap:t,moduleDepth:n}),e=Object.keys(n).sort((r,o)=>n[o]-n[r]).map(r=>t[r]),T(e),e}function ut(e){return Kn(e)}var Yn=/^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/,Xn=/((?: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 ae(e){return`${e.name}Uniforms`}function Oe(e,t){let n=t==="wgsl"?e.source:t==="vertex"?e.vs:e.fs;if(!n)return null;let r=ae(e);return Zn(n,t==="wgsl"?"wgsl":"glsl",r)}function Te(e,t){let n=Object.keys(e.uniformTypes||{});if(!n.length)return null;let r=Oe(e,t);return r?{moduleName:e.name,uniformBlockName:ae(e),stage:t,expectedUniformNames:n,actualUniformNames:r,matches:er(n,r)}:null}function se(e,t,n={}){let r=Te(e,t);if(!r||r.matches)return r;let o=tr(r);return n.log?.error?.(o,r)(),n.throwOnError!==!1&&O(!1,o),r}function ce(e){let t=[],n=nr(e);for(let r of n.matchAll(Xn)){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 le(e,t,n,r){let o=ce(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 ${rr(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 Zn(e,t,n){let r=t==="wgsl"?Qn(e,n):Jn(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(Yn);s&&o.push(s[1])}return o}function Qn(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 Jn(e,t){return ce(e).find(r=>r.blockName===t)?.body||null}function er(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 tr(e){return`${e.moduleName}: ${e.stage} shader uniform block ${e.uniformBlockName} does not match module.uniformTypes.
35
+ Expected: ${e.expectedUniformNames.join(", ")}
36
+ Actual: ${e.actualUniformNames.join(", ")}`}function nr(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function rr(e){return e.replace(/\s+/g," ").trim()}function ht(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
34
37
  // Apple optimizes away the calculation necessary for emulated fp64
35
38
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
36
39
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
@@ -54,60 +57,58 @@ ${t[n]}`:t[n]}),e}function ne(a){a.map(e=>et(e))}function et(a){if(a.instance)re
54
57
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
55
58
  // If the GPU doesn't have full 32 bits precision, will causes overflow
56
59
  #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(`
60
+ `}}function mt(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=gt(e,or),e;case"fragment":return e=gt(e,ir),e;default:throw new Error(t)}}var dt=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
61
+ `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],or=[...dt,[Fe("attribute"),"in $1"],[Fe("varying"),"out $1"]],ir=[...dt,[Fe("varying"),"in $1"]];function gt(e,t){for(let[n,r]of t)e=e.replace(n,r);return e}function Fe(e){return new RegExp(`\\b${e}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function we(e,t){let n="";for(let r in e){let o=e[r];if(n+=`void ${o.signature} {
62
+ `,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}
63
+ `}o.footer&&(n+=` ${o.footer}`),n+=`}
64
+ `}return n}function Be(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 fe(e,t){return{name:ar(e,t),language:"glsl",version:sr(e)}}function ar(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 sr(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 _t=[/@binding\(\s*(\d+)\s*\)\s*@group\(\s*(\d+)\s*\)\s*var(?:<([^>]+)>)?\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([^;]+);/g,/@group\(\s*(\d+)\s*\)\s*@binding\(\s*(\d+)\s*\)\s*var(?:<([^>]+)>)?\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([^;]+);/g];function pe(e,t=[]){let n=new Map;for(let o of t)n.set(bt(o.name,o.group,o.location),o.moduleName);let r=[];for(let o of _t){o.lastIndex=0;let i;for(;i=o.exec(e);){let a=o===_t[0],s=Number(i[a?1:2]),c=Number(i[a?2:1]),l=i[3]?.trim(),p=i[4],f=i[5].trim(),u=n.get(bt(p,c,s));r.push(cr({name:p,group:c,binding:s,owner:u?"module":"application",moduleName:u,accessDeclaration:l,resourceType:f}))}}return r.sort((o,i)=>o.group!==i.group?o.group-i.group:o.binding!==i.binding?o.binding-i.binding:o.name.localeCompare(i.name))}function cr(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:fr(e.resourceType),viewDimension:vt(e.resourceType)}:e.resourceType.startsWith("texture_")?{...t,kind:"texture",viewDimension:vt(e.resourceType),sampleType:lr(e.resourceType),multisampled:e.resourceType.startsWith("texture_multisampled_")}:t}function bt(e,t,n){return`${t}:${n}:${e}`}function vt(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 lr(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 fr(e){return/,\s*([A-Za-z_][A-Za-z0-9_]*)\s*>$/.exec(e)?.[1]}var Et=`
65
+
66
+ ${$}
67
+ `,ue=[/@binding\(\s*(auto|\d+)\s*\)\s*@group\(\s*(\d+)\s*\)\s*(var(?:<[^>]+>)?\s+([A-Za-z_][A-Za-z0-9_]*))/g,/@group\(\s*(\d+)\s*\)\s*@binding\(\s*(auto|\d+)\s*\)\s*(var(?:<[^>]+>)?\s+([A-Za-z_][A-Za-z0-9_]*))/g],St=[/@binding\(\s*(\d+)\s*\)\s*@group\(\s*(\d+)\s*\)\s*(var(?:<[^>]+>)?\s+([A-Za-z_][A-Za-z0-9_]*))/g,/@group\(\s*(\d+)\s*\)\s*@binding\(\s*(\d+)\s*\)\s*(var(?:<[^>]+>)?\s+([A-Za-z_][A-Za-z0-9_]*))/g],Z=100,pr=`precision highp float;
68
+ `;function Rt(e){let t=Y(e.modules||[]),{source:n,bindingAssignments:r}=ur(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t});return{source:n,getUniforms:It(t),bindingAssignments:r,bindingTable:pe(n,r)}}function ge(e){let{vs:t,fs:n}=e,r=Y(e.modules||[]);return{vs:xt(e.platformInfo,{...e,source:t,stage:"vertex",modules:r}),fs:xt(e.platformInfo,{...e,source:n,stage:"fragment",modules:r}),getUniforms:It(r)}}function ur(e,t){let{source:n,stage:r,modules:o,hookFunctions:i=[],inject:a={},log:s}=t;O(typeof n=="string","shader source must be a string");let c=n,l="",p=Be(i),f={},u={},g={};for(let M in a){let b=typeof a[M]=="string"?{injection:a[M],order:0}:a[M],S=/^(v|f)s:(#)?([\w-]+)$/.exec(M);if(S){let v=S[2],h=S[3];v?h==="decl"?u[M]=[b]:g[M]=[b]:f[M]=[b]}else g[M]=[b]}let _=o,m=gr(c),x=_r(_,t._bindingRegistry,m),d=[];for(let M of _){s&&K(M,c,s);let b=mr(me(M,"wgsl",s),M,{usedBindingsByGroup:m,bindingRegistry:t._bindingRegistry,reservedBindingKeysByGroup:x});d.push(...b.bindingAssignments);let S=b.source;l+=S;let v=M.injections?.[r]||{};for(let h in v){let E=/^(v|f)s:#([\w-]+)$/.exec(h);if(E){let L=E[2]==="decl"?u:g;L[h]=L[h]||[],L[h].push(v[h])}else f[h]=f[h]||[],f[h].push(v[h])}}return l+=Et,l=q(l,r,u),l+=we(p[r],f),l+=Mr(d),l+=c,l=q(l,r,g),xr(l),{source:l,bindingAssignments:d}}function xt(e,t){let{source:n,stage:r,language:o="glsl",modules:i,defines:a={},hookFunctions:s=[],inject:c={},prologue:l=!0,log:p}=t;O(typeof n=="string","shader source must be a string");let f=o==="glsl"?fe(n).version:-1,u=e.shaderLanguageVersion,g=f===100?"#version 100":"#version 300 es",m=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(h=>{Object.assign(x,h.defines)}),Object.assign(x,a);let d="";switch(o){case"wgsl":break;case"glsl":d=l?`${g}
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
+ ${ht(e)}
76
+ ${r==="fragment"?pr:""}
74
77
 
75
78
  // ----- APPLICATION DEFINES -------------------------
76
79
 
77
- ${$r(T)}
80
+ ${hr(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
+ `:`${g}
83
+ `;break}let M=Be(s),b={},S={},v={};for(let h in c){let E=typeof c[h]=="string"?{injection:c[h],order:0}:c[h],R=/^(v|f)s:(#)?([\w-]+)$/.exec(h);if(R){let L=R[2],I=R[3];L?I==="decl"?S[h]=[E]:v[h]=[E]:b[h]=[E]}else v[h]=[E]}for(let h of i){p&&K(h,m,p);let E=me(h,r,p);d+=E;let R=h.instance?.normalizedInjections[r]||{};for(let L in R){let I=/^(v|f)s:#([\w-]+)$/.exec(L);if(I){let C=I[2]==="decl"?S:v;C[L]=C[L]||[],C[L].push(R[L])}else b[L]=b[L]||[],b[L].push(R[L])}}return d+="// ----- MAIN SHADER SOURCE -------------------------",d+=Et,d=q(d,r,S),d+=we(M[r],b),d+=m,d=q(d,r,v),o==="glsl"&&f!==u&&(d=mt(d,r)),o==="glsl"&&le(d,r,p),d.trim()}function It(e){return function(n){let r={};for(let o of e){let i=o.getUniforms?.(n,r);Object.assign(r,i)}return r}}function hr(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 me(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:O(!1)}if(!e.name)throw new Error("Shader module must have a name");se(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 gr(e){let t=new Map;for(let n of St){n.lastIndex=0;let r;for(;r=n.exec(e);){let o=n===St[0],i=Number(r[o?1:2]),a=Number(r[o?2:1]),s=r[4];Sr(a,i,s),he(t,a,i,`application binding "${s}"`)}}return t}function mr(e,t,n){let r=[],o={sawSupportedBindingDeclaration:!1,nextHintedBindingLocation:typeof t.firstBindingSlot=="number"?t.firstBindingSlot:null},i=Mt(e,ue[0],{isBindingFirst:!0,module:t,context:n,bindingAssignments:r,relocationState:o});if(i=Mt(i,ue[1],{isBindingFirst:!1,module:t,context:n,bindingAssignments:r,relocationState:o}),e.includes("@binding(auto)")&&!o.sawSupportedBindingDeclaration)throw new Error(`Unsupported @binding(auto) declaration form in module "${t.name}". Use "@group(N) @binding(auto) var ..." or "@binding(auto) @group(N) var ..." on a single line.`);return{source:i,bindingAssignments:r}}function Mt(e,t,n){return e.replace(t,(...r)=>dr(r,n))}function dr(e,t){let{isBindingFirst:n,module:r,context:o,bindingAssignments:i,relocationState:a}=t;a.sawSupportedBindingDeclaration=!0;let s=e[0],c=e[n?1:2],l=e[n?2:1],p=e[4],f=Number(l);if(c==="auto"){let g=Ct(f,r.name,p),_=o.bindingRegistry?.get(g),m=_!==void 0?_:a.nextHintedBindingLocation===null?At(f,o.usedBindingsByGroup):At(f,o.usedBindingsByGroup,a.nextHintedBindingLocation);return Lt(r.name,f,m,p),_!==void 0&&br(o.reservedBindingKeysByGroup,f,m,g)?(i.push({moduleName:r.name,name:p,group:f,location:m}),s.replace(/@binding\(\s*auto\s*\)/,`@binding(${m})`)):(he(o.usedBindingsByGroup,f,m,`module "${r.name}" binding "${p}"`),o.bindingRegistry?.set(g,m),i.push({moduleName:r.name,name:p,group:f,location:m}),a.nextHintedBindingLocation!==null&&_===void 0&&(a.nextHintedBindingLocation=m+1),s.replace(/@binding\(\s*auto\s*\)/,`@binding(${m})`))}let u=Number(c);return Lt(r.name,f,u,p),he(o.usedBindingsByGroup,f,u,`module "${r.name}" binding "${p}"`),i.push({moduleName:r.name,name:p,group:f,location:u}),s}function _r(e,t,n){let r=new Map;if(!t)return r;for(let o of e)for(let i of vr(o)){let a=Ct(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}.`);he(n,i.group,s,`registered module binding "${a}"`),c.set(s,a),r.set(i.group,c)}}return r}function br(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 vr(e){let t=[],n=e.source||"";for(let r of ue){r.lastIndex=0;let o;for(;o=r.exec(n);){let i=r===ue[0];t.push({name:o[4],group:Number(o[i?2:1])})}}return t}function Sr(e,t,n){if(e===0&&t>=Z)throw new Error(`Application binding "${n}" in group 0 uses reserved binding ${t}. Application-owned explicit group-0 bindings must stay below ${Z}.`)}function Lt(e,t,n,r){if(t===0&&n<Z)throw new Error(`Module "${e}" binding "${r}" in group 0 uses reserved application binding ${n}. Module-owned explicit group-0 bindings must be ${Z} or higher.`)}function he(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 At(e,t,n){let r=t.get(e)||new Set,o=n??(e===0?Z:r.size>0?Math.max(...r)+1:0);for(;r.has(o);)o++;return o}function xr(e){if(/@binding\(\s*auto\s*\)/.test(e))throw new Error("Unresolved @binding(auto) remained in assembled WGSL source.")}function Mr(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 Ct(e,t,n){return`${e}:${t}:${n}`}var ke="([a-zA-Z_][a-zA-Z0-9_]*)",Lr=new RegExp(`^\\s*\\#\\s*ifdef\\s*${ke}\\s*$`),Ar=new RegExp(`^\\s*\\#\\s*ifndef\\s*${ke}\\s*(?:\\/\\/.*)?$`),Er=/^\s*\#\s*else\s*(?:\/\/.*)?$/,Rr=/^\s*\#\s*endif\s*$/,Ir=new RegExp(`^\\s*\\#\\s*ifdef\\s*${ke}\\s*(?:\\/\\/.*)?$`),Cr=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function de(e,t){let n=e.split(`
92
+ `),r=[],o=[],i=!0;for(let a of n){let s=a.match(Ir)||a.match(Lr),c=a.match(Ar),l=a.match(Er),p=a.match(Cr)||a.match(Rr);if(s||c){let f=(s||c)?.[1],u=Boolean(t?.defines?.[f]),g=s?u:!u,_=i&&g;o.push({parentActive:i,branchTaken:g,active:_}),i=_}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 z=class{_hookFunctions=[];_defaultModules=[];_wgslBindingRegistry=new Map;static getDefaultShaderAssembler(){return z.defaultShaderAssembler=z.defaultShaderAssembler||new z,z.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}=Rt({...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"?de(o,{defines:s}):o;return{source:c,getUniforms:i,modules:n,bindingAssignments:a,bindingTable:pe(c,a)}}assembleGLSLShaderPair(t){let n=this._getModuleList(t.modules),r=this._hookFunctions;return{...ge({...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,T(n),n}},Q=z;et(Q,"defaultShaderAssembler");var yr=`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
+ }`,Pr=`#version 300 es
97
+ ${yr}`;function yt(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 Pt(e){let{input:t,inputChannels:n,output:r}=e||{};if(!t)return Pr;if(!n)throw new Error("inputChannels");let o=Nr(n),i=De(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 Nt(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 Ot(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 Nr(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 De(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 k(e){return typeof e=="string"?e.charAt(0).toUpperCase()+e.slice(1):e}function Tt(e,t){return Or(e,t)}function Or(e,t){let n=[];switch(t.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":n.push(`layout(std140) uniform ${k(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=Tr(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 Tr(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 Ft(e,t){return Fr(e,t)}function Fr(e,t){let n=[];n.push(`struct ${k(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} : ${k(e.name)};`),n.join(`
104
+ `)}function wt(e,t){switch(t.shaderLanguage){case"glsl":return Tt(e,t);case"wgsl":return Ft(e,t)}}var bi=1/Math.PI*180,vi=1/180*Math.PI,wr={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...wr}};var y=globalThis.mathgl.config;function Ue(e,{precision:t=y.precision}={}){return e=Br(e),`${parseFloat(e.toPrecision(t))}`}function H(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function ze(e,t,n){return Dr(e,r=>Math.max(t,Math.min(n,r)))}function _e(e,t,n){let r=y.EPSILON;n&&(y.EPSILON=n);try{if(e===t)return!0;if(H(e)&&H(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(!_e(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 Br(e){return Math.round(e/y.EPSILON)*y.EPSILON}function kr(e){return e.clone?e.clone():new Array(e.length)}function Dr(e,t,n){if(H(e)){let r=e;n=n||kr(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 be=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:H(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?", ":"")+Ue(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(!_e(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 Ur(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 Bt(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function ve(e,t,n=""){if(y.debug&&!Ur(e,t))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return e}var w=typeof Float32Array<"u"?Float32Array:Array;var Ei=Math.PI/180;function zr(){let e=new w(2);return w!=Float32Array&&(e[0]=0,e[1]=0),e}function Ut(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 Ri=function(){let e=zr();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 zt(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 Ht(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 Hr(){let e=new w(3);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Gt(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 yi=function(){let e=Hr();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 Se=class extends be{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]=Bt(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 Gr(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 Vt(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],g=t[11],_=t[12],m=t[13],x=t[14],d=t[15],M=n*s-r*a,b=n*c-o*a,S=n*l-i*a,v=r*c-o*s,h=r*l-i*s,E=o*l-i*c,R=p*m-f*_,L=p*x-u*_,I=p*d-g*_,P=f*x-u*m,C=f*d-g*m,N=u*d-g*x,A=M*N-b*C+S*P+v*I-h*L+E*R;return A?(A=1/A,e[0]=(s*N-c*C+l*P)*A,e[1]=(o*C-r*N-i*P)*A,e[2]=(m*E-x*h+d*v)*A,e[3]=(u*h-f*E-g*v)*A,e[4]=(c*I-a*N-l*L)*A,e[5]=(n*N-o*I+i*L)*A,e[6]=(x*S-_*E-d*b)*A,e[7]=(p*E-u*S+g*b)*A,e[8]=(a*C-s*I+l*R)*A,e[9]=(r*I-n*C-i*R)*A,e[10]=(_*h-m*S+d*M)*A,e[11]=(f*S-p*h-g*M)*A,e[12]=(s*L-a*P-c*R)*A,e[13]=(n*P-r*L+o*R)*A,e[14]=(m*b-_*v-x*M)*A,e[15]=(p*v-f*b+u*M)*A,e):null}function Wt(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],g=e[12],_=e[13],m=e[14],x=e[15],d=t*a-n*i,M=t*s-r*i,b=n*s-r*a,S=l*_-p*g,v=l*m-f*g,h=p*m-f*_,E=t*h-n*v+r*S,R=i*h-a*v+s*S,L=l*b-p*M+f*d,I=g*b-_*M+m*d;return c*E-o*R+x*L-u*I}function Ge(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],g=t[10],_=t[11],m=t[12],x=t[13],d=t[14],M=t[15],b=n[0],S=n[1],v=n[2],h=n[3];return e[0]=b*r+S*s+v*f+h*m,e[1]=b*o+S*c+v*u+h*x,e[2]=b*i+S*l+v*g+h*d,e[3]=b*a+S*p+v*_+h*M,b=n[4],S=n[5],v=n[6],h=n[7],e[4]=b*r+S*s+v*f+h*m,e[5]=b*o+S*c+v*u+h*x,e[6]=b*i+S*l+v*g+h*d,e[7]=b*a+S*p+v*_+h*M,b=n[8],S=n[9],v=n[10],h=n[11],e[8]=b*r+S*s+v*f+h*m,e[9]=b*o+S*c+v*u+h*x,e[10]=b*i+S*l+v*g+h*d,e[11]=b*a+S*p+v*_+h*M,b=n[12],S=n[13],v=n[14],h=n[15],e[12]=b*r+S*s+v*f+h*m,e[13]=b*o+S*c+v*u+h*x,e[14]=b*i+S*l+v*g+h*d,e[15]=b*a+S*p+v*_+h*M,e}function $t(e,t,n){let r=n[0],o=n[1],i=n[2],a,s,c,l,p,f,u,g,_,m,x,d;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],g=t[7],_=t[8],m=t[9],x=t[10],d=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]=g,e[8]=_,e[9]=m,e[10]=x,e[11]=d,e[12]=a*r+p*o+_*i+t[12],e[13]=s*r+f*o+m*i+t[13],e[14]=c*r+u*o+x*i+t[14],e[15]=l*r+g*o+d*i+t[15]),e}function qt(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 Kt(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,g,_,m,x,d,M,b,S,v,h,E,R,L,I,P,C,N,A,j;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],g=t[2],_=t[3],m=t[4],x=t[5],d=t[6],M=t[7],b=t[8],S=t[9],v=t[10],h=t[11],E=o*o*p+c,R=i*o*p+a*l,L=a*o*p-i*l,I=o*i*p-a*l,P=i*i*p+c,C=a*i*p+o*l,N=o*a*p+i*l,A=i*a*p-o*l,j=a*a*p+c,e[0]=f*E+m*R+b*L,e[1]=u*E+x*R+S*L,e[2]=g*E+d*R+v*L,e[3]=_*E+M*R+h*L,e[4]=f*I+m*P+b*C,e[5]=u*I+x*P+S*C,e[6]=g*I+d*P+v*C,e[7]=_*I+M*P+h*C,e[8]=f*N+m*A+b*j,e[9]=u*N+x*A+S*j,e[10]=g*N+d*A+v*j,e[11]=_*N+M*A+h*j,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function Yt(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 Xt(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 Zt(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 Qt(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,g=o*s,_=o*c,m=i*a,x=i*s,d=i*c;return e[0]=1-f-_,e[1]=p+d,e[2]=u-x,e[3]=0,e[4]=p-d,e[5]=1-l-_,e[6]=g+m,e[7]=0,e[8]=u+x,e[9]=g-m,e[10]=1-l-f,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Jt(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 Vr(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 en=Vr;function jr(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 tn=jr;function nn(e,t,n,r){let o,i,a,s,c,l,p,f,u,g,_=t[0],m=t[1],x=t[2],d=r[0],M=r[1],b=r[2],S=n[0],v=n[1],h=n[2];return Math.abs(_-S)<1e-6&&Math.abs(m-v)<1e-6&&Math.abs(x-h)<1e-6?Gr(e):(f=_-S,u=m-v,g=x-h,o=1/Math.sqrt(f*f+u*u+g*g),f*=o,u*=o,g*=o,i=M*g-b*u,a=b*f-d*g,s=d*u-M*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-g*a,l=g*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]=g,e[11]=0,e[12]=-(i*_+a*m+s*x),e[13]=-(c*_+l*m+p*x),e[14]=-(f*_+u*m+g*x),e[15]=1,e)}function Wr(){let e=new w(4);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function rn(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 Bi=function(){let e=Wr();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 We;(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"})(We||(We={}));var $r=45*Math.PI/180,qr=1,Ve=.1,je=500,Kr=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),B=class extends Se{static get IDENTITY(){return Xr()}static get ZERO(){return Yr()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return We}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,g,_,m,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]=g,this[13]=_,this[14]=m,this[15]=x,this.check()}setRowMajor(t,n,r,o,i,a,s,c,l,p,f,u,g,_,m,x){return this[0]=t,this[1]=i,this[2]=l,this[3]=g,this[4]=n,this[5]=a,this[6]=p,this[7]=_,this[8]=r,this[9]=s,this[10]=f,this[11]=m,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(Kr)}fromObject(t){return this.check()}fromQuaternion(t){return Qt(this,t),this.check()}frustum(t){let{left:n,right:r,bottom:o,top:i,near:a=Ve,far:s=je}=t;return s===1/0?Zr(this,n,r,o,i,a):Jt(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 nn(this,n,r,o),this.check()}ortho(t){let{left:n,right:r,bottom:o,top:i,near:a=Ve,far:s=je}=t;return tn(this,n,r,o,i,a,s),this.check()}orthographic(t){let{fovy:n=$r,aspect:r=qr,focalDistance:o=1,near:i=Ve,far:a=je}=t;on(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 on(n),en(this,n,r,o,i),this.check()}determinant(){return Wt(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 Vt(this,this),this.check()}invert(){return jt(this,this),this.check()}multiplyLeft(t){return Ge(this,t,this),this.check()}multiplyRight(t){return Ge(this,this,t),this.check()}rotateX(t){return Yt(this,this,t),this.check()}rotateY(t){return Xt(this,this,t),this.check()}rotateZ(t){return Zt(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,n){return Kt(this,this,t,n),this.check()}scale(t){return qt(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return $t(this,this,t),this.check()}transform(t,n){return t.length===4?(n=rn(n||[-0,-0,-0,-0],t,this),ve(n,4),n):this.transformAsPoint(t,n)}transformAsPoint(t,n){let{length:r}=t,o;switch(r){case 2:o=Ut(n||[-0,-0],t,this);break;case 3:o=Gt(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return ve(o,t.length),o}transformAsVector(t,n){let r;switch(t.length){case 2:r=zt(n||[-0,-0],t,this);break;case 3:r=Ht(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return ve(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])}},xe,Me;function Yr(){return xe||(xe=new B([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(xe)),xe}function Xr(){return Me||(Me=new B,Object.freeze(Me)),Me}function on(e){if(e>Math.PI*2)throw Error("expected radians")}function Zr(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 D=null,an=new ArrayBuffer(4),sn=new Float32Array(an),cn=new Uint32Array(an);function ln(e){D||=pn(),e=ze(e,-65504,65504),sn[0]=e;let t=cn[0],n=t>>23&511;return D.baseTable[n]+((t&8388607)>>D.shiftTable[n])}function fn(e){D||=pn();let t=e>>10;return cn[0]=D.mantissaTable[D.offsetTable[t]+(e&1023)]+D.exponentTable[t],sn[0]}function pn(){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 V(e,t=[],n=0){let r=Math.fround(e),o=e-r;return t[n]=r,t[n+1]=o,t}function J(e){return e-Math.fround(e)}function ee(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;V(e[r*4+n],t,o*2)}return t}var Qr=`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
+ `,Jr=`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
+ `,un={name:"random",source:Qr,fs:Jr};var eo=`#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
+ `,hn={name:"fp32",vs:eo};var $e=`
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 gn=`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 mn=`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 to={ONE:1,SPLIT:4097},qe={name:"fp64arithmetic",source:gn,fs:$e,vs:$e,defaultUniforms:to,uniformTypes:{ONE:"f32",SPLIT:"f32"},fp64ify:V,fp64LowPart:J,fp64ifyMatrix4:ee},dn={name:"fp64",vs:mn,dependencies:[qe],fp64ify:V,fp64LowPart:J,fp64ifyMatrix4:ee};var no=[0,1,1,1],ro=`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
+ `,oo=`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
+ `,_n={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:no},vs:ro,fs:oo,getUniforms:io};function io(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 te=20,ao=`
1463
+ struct skinUniforms {
1464
+ jointMatrix: array<mat4x4<f32>, ${te}>,
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
+ `,so=`
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
+ `,co="",bn={props:{},uniforms:{},name:"skin",bindingLayout:[{name:"skin",group:0}],dependencies:[],source:ao,vs:so,fs:co,defines:{SKIN_MAX_JOINTS:te},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(te*16);for(let f=0;f<te;++f){let u=o[f];if(u===void 0)break;let g=l[n.gltfNodeIndexToNodeMap.get(u).id],_=a[f],m=new B().copy(g).multiplyRight(_),x=f*16;for(let d=0;d<16;d++)p[x+d]=m[d]}return{jointMatrix:p}},uniformTypes:{jointMatrix:["mat4x4<f32>",te]}};var Sn=Je(ye(),1);var Ke=`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 vn=`// #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,47 +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=`
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 U=5,lo=255,fo={color:"vec3<f32>",position:"vec3<f32>",direction:"vec3<f32>",attenuation:"vec3<f32>",coneCos:"vec2<f32>"},F={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",directionalLightCount:"i32",pointLightCount:"i32",spotLightCount:"i32",ambientColor:"vec3<f32>",lights:[fo,U]},defaultUniforms:Ae(),bindingLayout:[{name:"lighting",group:2}],firstBindingSlot:0,source:vn,vs:Ke,fs:Ke,getUniforms:po};function po(e,t={}){if(e=e&&{...e},!e)return Ae();e.lights&&(e={...e,...ho(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{...Ae(),enabled:0};let s={...Ae(),...uo({ambientLight:n,pointLights:r,spotLights:o,directionalLights:i})};return e.enabled!==void 0&&(s.enabled=e.enabled?1:0),s}function uo({ambientLight:e,pointLights:t=[],spotLights:n=[],directionalLights:r=[]}){let o=xn(),i=0,a=0,s=0,c=0;for(let l of t){if(i>=U)break;o[i]={...o[i],color:Le(l),position:l.position,attenuation:l.attenuation||[1,0,0]},i++,a++}for(let l of n){if(i>=U)break;o[i]={...o[i],color:Le(l),position:l.position,direction:l.direction,attenuation:l.attenuation||[1,0,0],coneCos:mo(l)},i++,s++}for(let l of r){if(i>=U)break;o[i]={...o[i],color:Le(l),direction:l.direction},i++,c++}return t.length+n.length+r.length>U&&Sn.log.warn(`MAX_LIGHTS exceeded, truncating to ${U}`)(),{ambientColor:Le(e),directionalLightCount:c,pointLightCount:a,spotLightCount:s,lights:o}}function ho(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 Le(e={}){let{color:t=[0,0,0],intensity:n=1}=e;return t.map(r=>r*n/lo)}function Ae(){return{enabled:1,directionalLightCount:0,pointLightCount:0,spotLightCount:0,ambientColor:[.1,.1,.1],lights:xn()}}function xn(){return Array.from({length:U},()=>go())}function go(){return{color:[1,1,1],position:[1,1,2],direction:[1,1,1],attenuation:[1,0,0],coneCos:[1,0]}}function mo(e){let t=e.innerConeAngle??0,n=e.outerConeAngle??Math.PI/4;return[Math.cos(t),Math.cos(n)]}var _o=`#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
+ `,Mn=`#ifdef USE_IBL
1655
+ uniform samplerCube pbr_diffuseEnvSampler;
1656
+ uniform samplerCube pbr_specularEnvSampler;
1657
+ uniform sampler2D pbr_brdfLUT;
1658
+ #endif
1659
+ `,Ee={name:"ibl",firstBindingSlot:32,bindingLayout:[{name:"pbr_diffuseEnvSampler",group:2},{name:"pbr_specularEnvSampler",group:2},{name:"pbr_brdfLUT",group:2}],source:_o,vs:Mn,fs:Mn};var bo=`
1350
1660
  struct dirlightUniforms {
1351
1661
  lightDirection: vec3<f32>,
1352
1662
  };
@@ -1357,7 +1667,7 @@ struct DirlightInputs {
1357
1667
  normal: DirlightNormal,
1358
1668
  };
1359
1669
 
1360
- @binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;
1670
+ @group(2) @binding(auto) var<uniform> dirlight : dirlightUniforms;
1361
1671
 
1362
1672
  // For vertex
1363
1673
  fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {
@@ -1372,12 +1682,12 @@ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
1372
1682
  let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
1373
1683
  return vec4<f32>(color.rgb * d, color.a);
1374
1684
  }
1375
- `,Ss=`out vec3 dirlight_vNormal;
1685
+ `,vo=`out vec3 dirlight_vNormal;
1376
1686
 
1377
1687
  void dirlight_setNormal(vec3 normal) {
1378
1688
  dirlight_vNormal = normalize(normal);
1379
1689
  }
1380
- `,As=`uniform dirlightUniforms {
1690
+ `,So=`layout(std140) uniform dirlightUniforms {
1381
1691
  vec3 lightDirection;
1382
1692
  } dirlight;
1383
1693
 
@@ -1388,15 +1698,134 @@ vec4 dirlight_filterColor(vec4 color) {
1388
1698
  float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
1389
1699
  return vec4(color.rgb * d, color.a);
1390
1700
  }
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 {
1701
+ `,Ye={props:{},uniforms:{},name:"dirlight",bindingLayout:[{name:"dirlight",group:2}],firstBindingSlot:16,dependencies:[],source:bo,vs:vo,fs:So,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:xo};function xo(e=Ye.defaultUniforms){let t={};return e.lightDirection&&(t.lightDirection=e.lightDirection),t}var Ln=`struct lambertMaterialUniforms {
1702
+ unlit: u32,
1703
+ ambient: f32,
1704
+ diffuse: f32,
1705
+ };
1706
+
1707
+ @group(3) @binding(auto) var<uniform> lambertMaterial : lambertMaterialUniforms;
1708
+
1709
+ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
1710
+ let lambertian: f32 = max(dot(light_direction, normal_worldspace), 0.0);
1711
+ return lambertian * lambertMaterial.diffuse * surfaceColor * color;
1712
+ }
1713
+
1714
+ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
1715
+ var lightColor: vec3<f32> = surfaceColor;
1716
+
1717
+ if (lambertMaterial.unlit != 0u) {
1718
+ return surfaceColor;
1719
+ }
1720
+
1721
+ if (lighting.enabled == 0) {
1722
+ return lightColor;
1723
+ }
1724
+
1725
+ lightColor = lambertMaterial.ambient * surfaceColor * lighting.ambientColor;
1726
+
1727
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
1728
+ let pointLight: PointLight = lighting_getPointLight(i);
1729
+ let light_position_worldspace: vec3<f32> = pointLight.position;
1730
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1731
+ let light_attenuation = getPointLightAttenuation(
1732
+ pointLight,
1733
+ distance(light_position_worldspace, position_worldspace)
1734
+ );
1735
+ lightColor += lighting_getLightColor(
1736
+ surfaceColor,
1737
+ light_direction,
1738
+ normal_worldspace,
1739
+ pointLight.color / light_attenuation
1740
+ );
1741
+ }
1742
+
1743
+ for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
1744
+ let spotLight: SpotLight = lighting_getSpotLight(i);
1745
+ let light_position_worldspace: vec3<f32> = spotLight.position;
1746
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1747
+ let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1748
+ lightColor += lighting_getLightColor(
1749
+ surfaceColor,
1750
+ light_direction,
1751
+ normal_worldspace,
1752
+ spotLight.color / light_attenuation
1753
+ );
1754
+ }
1755
+
1756
+ for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
1757
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
1758
+ lightColor += lighting_getLightColor(
1759
+ surfaceColor,
1760
+ -directionalLight.direction,
1761
+ normal_worldspace,
1762
+ directionalLight.color
1763
+ );
1764
+ }
1765
+
1766
+ return lightColor;
1767
+ }
1768
+ `;var An=`layout(std140) uniform lambertMaterialUniforms {
1769
+ uniform bool unlit;
1770
+ uniform float ambient;
1771
+ uniform float diffuse;
1772
+ } material;
1773
+ `,En=`layout(std140) uniform lambertMaterialUniforms {
1774
+ uniform bool unlit;
1775
+ uniform float ambient;
1776
+ uniform float diffuse;
1777
+ } material;
1778
+
1779
+ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 normal_worldspace, vec3 color) {
1780
+ float lambertian = max(dot(light_direction, normal_worldspace), 0.0);
1781
+ return lambertian * material.diffuse * surfaceColor * color;
1782
+ }
1783
+
1784
+ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
1785
+ vec3 lightColor = surfaceColor;
1786
+
1787
+ if (material.unlit) {
1788
+ return surfaceColor;
1789
+ }
1790
+
1791
+ if (lighting.enabled == 0) {
1792
+ return lightColor;
1793
+ }
1794
+
1795
+ lightColor = material.ambient * surfaceColor * lighting.ambientColor;
1796
+
1797
+ for (int i = 0; i < lighting.pointLightCount; i++) {
1798
+ PointLight pointLight = lighting_getPointLight(i);
1799
+ vec3 light_position_worldspace = pointLight.position;
1800
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
1801
+ float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
1802
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, pointLight.color / light_attenuation);
1803
+ }
1804
+
1805
+ for (int i = 0; i < lighting.spotLightCount; i++) {
1806
+ SpotLight spotLight = lighting_getSpotLight(i);
1807
+ vec3 light_position_worldspace = spotLight.position;
1808
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
1809
+ float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1810
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, spotLight.color / light_attenuation);
1811
+ }
1812
+
1813
+ for (int i = 0; i < lighting.directionalLightCount; i++) {
1814
+ DirectionalLight directionalLight = lighting_getDirectionalLight(i);
1815
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, normal_worldspace, directionalLight.color);
1816
+ }
1817
+
1818
+ return lightColor;
1819
+ }
1820
+ `;var Xe={name:"lambertMaterial",firstBindingSlot:0,bindingLayout:[{name:"lambertMaterial",group:3}],dependencies:[F],source:Ln,vs:An,fs:En,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6},getUniforms(e){return{...Xe.defaultUniforms,...e}}};var Re=`layout(std140) uniform phongMaterialUniforms {
1821
+ uniform bool unlit;
1392
1822
  uniform float ambient;
1393
1823
  uniform float diffuse;
1394
1824
  uniform float shininess;
1395
1825
  uniform vec3 specularColor;
1396
1826
  } material;
1397
- `,Ft=`#define MAX_LIGHTS 3
1398
-
1399
- uniform phongMaterialUniforms {
1827
+ `,Ie=`layout(std140) uniform phongMaterialUniforms {
1828
+ uniform bool unlit;
1400
1829
  uniform float ambient;
1401
1830
  uniform float diffuse;
1402
1831
  uniform float shininess;
@@ -1418,6 +1847,10 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
1418
1847
  vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
1419
1848
  vec3 lightColor = surfaceColor;
1420
1849
 
1850
+ if (material.unlit) {
1851
+ return surfaceColor;
1852
+ }
1853
+
1421
1854
  if (lighting.enabled == 0) {
1422
1855
  return lightColor;
1423
1856
  }
@@ -1433,22 +1866,30 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
1433
1866
  lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
1434
1867
  }
1435
1868
 
1436
- int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
1437
- for (int i = lighting.pointLightCount; i < totalLights; i++) {
1869
+ for (int i = 0; i < lighting.spotLightCount; i++) {
1870
+ SpotLight spotLight = lighting_getSpotLight(i);
1871
+ vec3 light_position_worldspace = spotLight.position;
1872
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
1873
+ float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1874
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, spotLight.color / light_attenuation);
1875
+ }
1876
+
1877
+ for (int i = 0; i < lighting.directionalLightCount; i++) {
1438
1878
  DirectionalLight directionalLight = lighting_getDirectionalLight(i);
1439
1879
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1440
1880
  }
1441
1881
 
1442
1882
  return lightColor;
1443
1883
  }
1444
- `;var Dt=`struct phongMaterialUniforms {
1884
+ `;var Ce=`struct phongMaterialUniforms {
1885
+ unlit: u32,
1445
1886
  ambient: f32,
1446
1887
  diffuse: f32,
1447
1888
  shininess: f32,
1448
1889
  specularColor: vec3<f32>,
1449
1890
  };
1450
1891
 
1451
- @binding(2) @group(0) var<uniform> phongMaterial : phongMaterialUniforms;
1892
+ @group(3) @binding(auto) var<uniform> phongMaterial : phongMaterialUniforms;
1452
1893
 
1453
1894
  fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
1454
1895
  let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
@@ -1465,6 +1906,10 @@ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, v
1465
1906
  fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
1466
1907
  var lightColor: vec3<f32> = surfaceColor;
1467
1908
 
1909
+ if (phongMaterial.unlit != 0u) {
1910
+ return surfaceColor;
1911
+ }
1912
+
1468
1913
  if (lighting.enabled == 0) {
1469
1914
  return lightColor;
1470
1915
  }
@@ -1472,61 +1917,91 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
1472
1917
  let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
1473
1918
  lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;
1474
1919
 
1475
- if (lighting.lightType == 0) {
1476
- let pointLight: PointLight = lighting_getPointLight(0);
1920
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
1921
+ let pointLight: PointLight = lighting_getPointLight(i);
1477
1922
  let light_position_worldspace: vec3<f32> = pointLight.position;
1478
1923
  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);
1924
+ let light_attenuation = getPointLightAttenuation(
1925
+ pointLight,
1926
+ distance(light_position_worldspace, position_worldspace)
1927
+ );
1928
+ lightColor += lighting_getLightColor(
1929
+ surfaceColor,
1930
+ light_direction,
1931
+ view_direction,
1932
+ normal_worldspace,
1933
+ pointLight.color / light_attenuation
1934
+ );
1483
1935
  }
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);
1936
+
1937
+ for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
1938
+ let spotLight: SpotLight = lighting_getSpotLight(i);
1939
+ let light_position_worldspace: vec3<f32> = spotLight.position;
1940
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1941
+ let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1942
+ lightColor += lighting_getLightColor(
1943
+ surfaceColor,
1944
+ light_direction,
1945
+ view_direction,
1946
+ normal_worldspace,
1947
+ spotLight.color / light_attenuation
1948
+ );
1495
1949
  }
1496
1950
 
1497
- for (int i = 0; i < MAX_LIGHTS; i++) {
1498
- if (i >= lighting.directionalLightCount) {
1499
- break;
1500
- }
1501
- DirectionalLight directionalLight = lighting.directionalLight[i];
1951
+ for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
1952
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
1502
1953
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1503
- }
1504
- */
1954
+ }
1955
+
1956
+ return lightColor;
1505
1957
  }
1506
1958
 
1507
1959
  fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{
1508
1960
  var lightColor = vec3<f32>(0, 0, 0);
1509
1961
  let surfaceColor = vec3<f32>(0, 0, 0);
1510
1962
 
1511
- if (lighting.enabled == 0) {
1963
+ if (lighting.enabled != 0) {
1512
1964
  let view_direction = normalize(cameraPosition - position_worldspace);
1513
1965
 
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);
1966
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
1967
+ let pointLight: PointLight = lighting_getPointLight(i);
1968
+ let light_position_worldspace: vec3<f32> = pointLight.position;
1969
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1970
+ let light_attenuation = getPointLightAttenuation(
1971
+ pointLight,
1972
+ distance(light_position_worldspace, position_worldspace)
1973
+ );
1974
+ lightColor += lighting_getLightColor(
1975
+ surfaceColor,
1976
+ light_direction,
1977
+ view_direction,
1978
+ normal_worldspace,
1979
+ pointLight.color / light_attenuation
1980
+ );
1981
+ }
1982
+
1983
+ for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
1984
+ let spotLight: SpotLight = lighting_getSpotLight(i);
1985
+ let light_position_worldspace: vec3<f32> = spotLight.position;
1986
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
1987
+ let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
1988
+ lightColor += lighting_getLightColor(
1989
+ surfaceColor,
1990
+ light_direction,
1991
+ view_direction,
1992
+ normal_worldspace,
1993
+ spotLight.color / light_attenuation
1994
+ );
1995
+ }
1996
+
1997
+ for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
1998
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
1523
1999
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
1524
- }
1525
2000
  }
1526
2001
  }
1527
2002
  return lightColor;
1528
2003
  }
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;
2004
+ `;var Ze={props:{},name:"gouraudMaterial",bindingLayout:[{name:"gouraudMaterial",group:3}],vs:Ie.replace("phongMaterial","gouraudMaterial"),fs:Re.replace("phongMaterial","gouraudMaterial"),source:Ce.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[F],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)),{...Ze.defaultUniforms,...t}}};var Qe={name:"phongMaterial",firstBindingSlot:0,bindingLayout:[{name:"phongMaterial",group:3}],dependencies:[F],source:Ce,vs:Re,fs:Ie,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)),{...Qe.defaultUniforms,...t}}};var Rn=`out vec3 pbr_vPosition;
1530
2005
  out vec2 pbr_vUV;
1531
2006
 
1532
2007
  #ifdef HAS_NORMALS
@@ -1559,9 +2034,9 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
1559
2034
  pbr_vUV = vec2(0.,0.);
1560
2035
  #endif
1561
2036
  }
1562
- `,_r=`precision highp float;
2037
+ `,In=`precision highp float;
1563
2038
 
1564
- uniform pbrMaterialUniforms {
2039
+ layout(std140) uniform pbrMaterialUniforms {
1565
2040
  // Material is unlit
1566
2041
  bool unlit;
1567
2042
 
@@ -1583,6 +2058,42 @@ uniform pbrMaterialUniforms {
1583
2058
 
1584
2059
  bool alphaCutoffEnabled;
1585
2060
  float alphaCutoff; // #ifdef ALPHA_CUTOFF
2061
+
2062
+ vec3 specularColorFactor;
2063
+ float specularIntensityFactor;
2064
+ bool specularColorMapEnabled;
2065
+ bool specularIntensityMapEnabled;
2066
+
2067
+ float ior;
2068
+
2069
+ float transmissionFactor;
2070
+ bool transmissionMapEnabled;
2071
+
2072
+ float thicknessFactor;
2073
+ float attenuationDistance;
2074
+ vec3 attenuationColor;
2075
+
2076
+ float clearcoatFactor;
2077
+ float clearcoatRoughnessFactor;
2078
+ bool clearcoatMapEnabled;
2079
+ bool clearcoatRoughnessMapEnabled;
2080
+
2081
+ vec3 sheenColorFactor;
2082
+ float sheenRoughnessFactor;
2083
+ bool sheenColorMapEnabled;
2084
+ bool sheenRoughnessMapEnabled;
2085
+
2086
+ float iridescenceFactor;
2087
+ float iridescenceIor;
2088
+ vec2 iridescenceThicknessRange;
2089
+ bool iridescenceMapEnabled;
2090
+
2091
+ float anisotropyStrength;
2092
+ float anisotropyRotation;
2093
+ vec2 anisotropyDirection;
2094
+ bool anisotropyMapEnabled;
2095
+
2096
+ float emissiveStrength;
1586
2097
 
1587
2098
  // IBL
1588
2099
  bool IBLenabled;
@@ -1611,20 +2122,50 @@ uniform sampler2D pbr_metallicRoughnessSampler;
1611
2122
  #ifdef HAS_OCCLUSIONMAP
1612
2123
  uniform sampler2D pbr_occlusionSampler;
1613
2124
  #endif
1614
- #ifdef USE_IBL
1615
- uniform samplerCube pbr_diffuseEnvSampler;
1616
- uniform samplerCube pbr_specularEnvSampler;
1617
- uniform sampler2D pbr_brdfLUT;
2125
+ #ifdef HAS_SPECULARCOLORMAP
2126
+ uniform sampler2D pbr_specularColorSampler;
1618
2127
  #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
1627
- in mat3 pbr_vTBN;
2128
+ #ifdef HAS_SPECULARINTENSITYMAP
2129
+ uniform sampler2D pbr_specularIntensitySampler;
2130
+ #endif
2131
+ #ifdef HAS_TRANSMISSIONMAP
2132
+ uniform sampler2D pbr_transmissionSampler;
2133
+ #endif
2134
+ #ifdef HAS_THICKNESSMAP
2135
+ uniform sampler2D pbr_thicknessSampler;
2136
+ #endif
2137
+ #ifdef HAS_CLEARCOATMAP
2138
+ uniform sampler2D pbr_clearcoatSampler;
2139
+ #endif
2140
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
2141
+ uniform sampler2D pbr_clearcoatRoughnessSampler;
2142
+ #endif
2143
+ #ifdef HAS_CLEARCOATNORMALMAP
2144
+ uniform sampler2D pbr_clearcoatNormalSampler;
2145
+ #endif
2146
+ #ifdef HAS_SHEENCOLORMAP
2147
+ uniform sampler2D pbr_sheenColorSampler;
2148
+ #endif
2149
+ #ifdef HAS_SHEENROUGHNESSMAP
2150
+ uniform sampler2D pbr_sheenRoughnessSampler;
2151
+ #endif
2152
+ #ifdef HAS_IRIDESCENCEMAP
2153
+ uniform sampler2D pbr_iridescenceSampler;
2154
+ #endif
2155
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
2156
+ uniform sampler2D pbr_iridescenceThicknessSampler;
2157
+ #endif
2158
+ #ifdef HAS_ANISOTROPYMAP
2159
+ uniform sampler2D pbr_anisotropySampler;
2160
+ #endif
2161
+ // Inputs from vertex shader
2162
+
2163
+ in vec3 pbr_vPosition;
2164
+ in vec2 pbr_vUV;
2165
+
2166
+ #ifdef HAS_NORMALS
2167
+ #ifdef HAS_TANGENTS
2168
+ in mat3 pbr_vTBN;
1628
2169
  #else
1629
2170
  in vec3 pbr_vNormal;
1630
2171
  #endif
@@ -1653,6 +2194,8 @@ struct PBRInfo {
1653
2194
  const float M_PI = 3.141592653589793;
1654
2195
  const float c_MinRoughness = 0.04;
1655
2196
 
2197
+ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor);
2198
+
1656
2199
  vec4 SRGBtoLINEAR(vec4 srgbIn)
1657
2200
  {
1658
2201
  #ifdef MANUAL_SRGB
@@ -1668,11 +2211,9 @@ vec4 SRGBtoLINEAR(vec4 srgbIn)
1668
2211
  #endif //MANUAL_SRGB
1669
2212
  }
1670
2213
 
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()
2214
+ // Build the tangent basis from interpolated attributes or screen-space derivatives.
2215
+ mat3 getTBN()
1674
2216
  {
1675
- // Retrieve the tangent space matrix
1676
2217
  #ifndef HAS_TANGENTS
1677
2218
  vec3 pos_dx = dFdx(pbr_vPosition);
1678
2219
  vec3 pos_dy = dFdy(pbr_vPosition);
@@ -1693,9 +2234,21 @@ vec3 getNormal()
1693
2234
  mat3 tbn = pbr_vTBN;
1694
2235
  #endif
1695
2236
 
2237
+ return tbn;
2238
+ }
2239
+
2240
+ // Find the normal for this fragment, pulling either from a predefined normal map
2241
+ // or from the interpolated mesh normal and tangent attributes.
2242
+ vec3 getMappedNormal(sampler2D normalSampler, mat3 tbn, float normalScale)
2243
+ {
2244
+ vec3 n = texture(normalSampler, pbr_vUV).rgb;
2245
+ return normalize(tbn * ((2.0 * n - 1.0) * vec3(normalScale, normalScale, 1.0)));
2246
+ }
2247
+
2248
+ vec3 getNormal(mat3 tbn)
2249
+ {
1696
2250
  #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)));
2251
+ vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale);
1699
2252
  #else
1700
2253
  // The tbn matrix is linearly interpolated, so we need to re-normalize
1701
2254
  vec3 n = normalize(tbn[2].xyz);
@@ -1704,6 +2257,15 @@ vec3 getNormal()
1704
2257
  return n;
1705
2258
  }
1706
2259
 
2260
+ vec3 getClearcoatNormal(mat3 tbn, vec3 baseNormal)
2261
+ {
2262
+ #ifdef HAS_CLEARCOATNORMALMAP
2263
+ return getMappedNormal(pbr_clearcoatNormalSampler, tbn, 1.0);
2264
+ #else
2265
+ return baseNormal;
2266
+ #endif
2267
+ }
2268
+
1707
2269
  // Calculation of the lighting contribution from an optional Image Based Light source.
1708
2270
  // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
1709
2271
  // See our README.md on Environment Maps [3] for additional discussion.
@@ -1779,6 +2341,169 @@ float microfacetDistribution(PBRInfo pbrInfo)
1779
2341
  return roughnessSq / (M_PI * f * f);
1780
2342
  }
1781
2343
 
2344
+ float maxComponent(vec3 value)
2345
+ {
2346
+ return max(max(value.r, value.g), value.b);
2347
+ }
2348
+
2349
+ float getDielectricF0(float ior)
2350
+ {
2351
+ float clampedIor = max(ior, 1.0);
2352
+ float ratio = (clampedIor - 1.0) / (clampedIor + 1.0);
2353
+ return ratio * ratio;
2354
+ }
2355
+
2356
+ vec2 normalizeDirection(vec2 direction)
2357
+ {
2358
+ float directionLength = length(direction);
2359
+ return directionLength > 0.0001 ? direction / directionLength : vec2(1.0, 0.0);
2360
+ }
2361
+
2362
+ vec2 rotateDirection(vec2 direction, float rotation)
2363
+ {
2364
+ float s = sin(rotation);
2365
+ float c = cos(rotation);
2366
+ return vec2(direction.x * c - direction.y * s, direction.x * s + direction.y * c);
2367
+ }
2368
+
2369
+ vec3 getIridescenceTint(float iridescence, float thickness, float NdotV)
2370
+ {
2371
+ if (iridescence <= 0.0) {
2372
+ return vec3(1.0);
2373
+ }
2374
+
2375
+ float phase = 0.015 * thickness * pbrMaterial.iridescenceIor + (1.0 - NdotV) * 6.0;
2376
+ vec3 thinFilmTint =
2377
+ 0.5 + 0.5 * cos(vec3(phase, phase + 2.0943951, phase + 4.1887902));
2378
+ return mix(vec3(1.0), thinFilmTint, iridescence);
2379
+ }
2380
+
2381
+ vec3 getVolumeAttenuation(float thickness)
2382
+ {
2383
+ if (thickness <= 0.0) {
2384
+ return vec3(1.0);
2385
+ }
2386
+
2387
+ vec3 attenuationCoefficient =
2388
+ -log(max(pbrMaterial.attenuationColor, vec3(0.0001))) /
2389
+ max(pbrMaterial.attenuationDistance, 0.0001);
2390
+ return exp(-attenuationCoefficient * thickness);
2391
+ }
2392
+
2393
+ PBRInfo createClearcoatPBRInfo(PBRInfo basePBRInfo, vec3 clearcoatNormal, float clearcoatRoughness)
2394
+ {
2395
+ float perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
2396
+ float alphaRoughness = perceptualRoughness * perceptualRoughness;
2397
+ float NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);
2398
+
2399
+ return PBRInfo(
2400
+ basePBRInfo.NdotL,
2401
+ NdotV,
2402
+ basePBRInfo.NdotH,
2403
+ basePBRInfo.LdotH,
2404
+ basePBRInfo.VdotH,
2405
+ perceptualRoughness,
2406
+ 0.0,
2407
+ vec3(0.04),
2408
+ vec3(1.0),
2409
+ alphaRoughness,
2410
+ vec3(0.0),
2411
+ vec3(0.04),
2412
+ clearcoatNormal,
2413
+ basePBRInfo.v
2414
+ );
2415
+ }
2416
+
2417
+ vec3 calculateClearcoatContribution(
2418
+ PBRInfo pbrInfo,
2419
+ vec3 lightColor,
2420
+ vec3 clearcoatNormal,
2421
+ float clearcoatFactor,
2422
+ float clearcoatRoughness
2423
+ ) {
2424
+ if (clearcoatFactor <= 0.0) {
2425
+ return vec3(0.0);
2426
+ }
2427
+
2428
+ PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
2429
+ return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;
2430
+ }
2431
+
2432
+ #ifdef USE_IBL
2433
+ vec3 calculateClearcoatIBLContribution(
2434
+ PBRInfo pbrInfo,
2435
+ vec3 clearcoatNormal,
2436
+ vec3 reflection,
2437
+ float clearcoatFactor,
2438
+ float clearcoatRoughness
2439
+ ) {
2440
+ if (clearcoatFactor <= 0.0) {
2441
+ return vec3(0.0);
2442
+ }
2443
+
2444
+ PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
2445
+ return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;
2446
+ }
2447
+ #endif
2448
+
2449
+ vec3 calculateSheenContribution(
2450
+ PBRInfo pbrInfo,
2451
+ vec3 lightColor,
2452
+ vec3 sheenColor,
2453
+ float sheenRoughness
2454
+ ) {
2455
+ if (maxComponent(sheenColor) <= 0.0) {
2456
+ return vec3(0.0);
2457
+ }
2458
+
2459
+ float sheenFresnel = pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
2460
+ float sheenVisibility = mix(1.0, pbrInfo.NdotL * pbrInfo.NdotV, sheenRoughness);
2461
+ return pbrInfo.NdotL *
2462
+ lightColor *
2463
+ sheenColor *
2464
+ (0.25 + 0.75 * sheenFresnel) *
2465
+ sheenVisibility *
2466
+ (1.0 - pbrInfo.metalness);
2467
+ }
2468
+
2469
+ float calculateAnisotropyBoost(
2470
+ PBRInfo pbrInfo,
2471
+ vec3 anisotropyTangent,
2472
+ float anisotropyStrength
2473
+ ) {
2474
+ if (anisotropyStrength <= 0.0) {
2475
+ return 1.0;
2476
+ }
2477
+
2478
+ vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));
2479
+ float bitangentViewAlignment = abs(dot(pbrInfo.v, anisotropyBitangent));
2480
+ return mix(1.0, 0.65 + 0.7 * bitangentViewAlignment, anisotropyStrength);
2481
+ }
2482
+
2483
+ vec3 calculateMaterialLightColor(
2484
+ PBRInfo pbrInfo,
2485
+ vec3 lightColor,
2486
+ vec3 clearcoatNormal,
2487
+ float clearcoatFactor,
2488
+ float clearcoatRoughness,
2489
+ vec3 sheenColor,
2490
+ float sheenRoughness,
2491
+ vec3 anisotropyTangent,
2492
+ float anisotropyStrength
2493
+ ) {
2494
+ float anisotropyBoost = calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
2495
+ vec3 color = calculateFinalColor(pbrInfo, lightColor) * anisotropyBoost;
2496
+ color += calculateClearcoatContribution(
2497
+ pbrInfo,
2498
+ lightColor,
2499
+ clearcoatNormal,
2500
+ clearcoatFactor,
2501
+ clearcoatRoughness
2502
+ );
2503
+ color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);
2504
+ return color;
2505
+ }
2506
+
1782
2507
  void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
1783
2508
  pbrInfo.NdotL = 1.0;
1784
2509
  pbrInfo.NdotH = 0.0;
@@ -1803,6 +2528,11 @@ void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
1803
2528
  PBRInfo_setDirectionalLight(pbrInfo, light_direction);
1804
2529
  }
1805
2530
 
2531
+ void PBRInfo_setSpotLight(inout PBRInfo pbrInfo, SpotLight spotLight) {
2532
+ vec3 light_direction = normalize(spotLight.position - pbr_vPosition);
2533
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
2534
+ }
2535
+
1806
2536
  vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
1807
2537
  // Calculate the shading terms for the microfacet specular shading model
1808
2538
  vec3 F = specularReflection(pbrInfo);
@@ -1833,6 +2563,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
1833
2563
 
1834
2564
  vec3 color = vec3(0, 0, 0);
1835
2565
 
2566
+ float transmission = 0.0;
2567
+
1836
2568
  if(pbrMaterial.unlit){
1837
2569
  color.rgb = baseColor.rgb;
1838
2570
  }
@@ -1851,14 +2583,252 @@ vec4 pbr_filterColor(vec4 colorUnused)
1851
2583
  #endif
1852
2584
  perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
1853
2585
  metallic = clamp(metallic, 0.0, 1.0);
2586
+ mat3 tbn = getTBN();
2587
+ vec3 n = getNormal(tbn); // normal at surface point
2588
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
2589
+ float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
2590
+ #ifdef USE_MATERIAL_EXTENSIONS
2591
+ bool useExtendedPBR =
2592
+ pbrMaterial.specularColorMapEnabled ||
2593
+ pbrMaterial.specularIntensityMapEnabled ||
2594
+ abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||
2595
+ maxComponent(abs(pbrMaterial.specularColorFactor - vec3(1.0))) > 0.0001 ||
2596
+ abs(pbrMaterial.ior - 1.5) > 0.0001 ||
2597
+ pbrMaterial.transmissionMapEnabled ||
2598
+ pbrMaterial.transmissionFactor > 0.0001 ||
2599
+ pbrMaterial.clearcoatMapEnabled ||
2600
+ pbrMaterial.clearcoatRoughnessMapEnabled ||
2601
+ pbrMaterial.clearcoatFactor > 0.0001 ||
2602
+ pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||
2603
+ pbrMaterial.sheenColorMapEnabled ||
2604
+ pbrMaterial.sheenRoughnessMapEnabled ||
2605
+ maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||
2606
+ pbrMaterial.sheenRoughnessFactor > 0.0001 ||
2607
+ pbrMaterial.iridescenceMapEnabled ||
2608
+ pbrMaterial.iridescenceFactor > 0.0001 ||
2609
+ abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||
2610
+ abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||
2611
+ abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||
2612
+ pbrMaterial.anisotropyMapEnabled ||
2613
+ pbrMaterial.anisotropyStrength > 0.0001 ||
2614
+ abs(pbrMaterial.anisotropyRotation) > 0.0001 ||
2615
+ length(pbrMaterial.anisotropyDirection - vec2(1.0, 0.0)) > 0.0001;
2616
+ #else
2617
+ bool useExtendedPBR = false;
2618
+ #endif
2619
+
2620
+ if (!useExtendedPBR) {
2621
+ // Keep the baseline metallic-roughness implementation byte-for-byte equivalent in behavior.
2622
+ float alphaRoughness = perceptualRoughness * perceptualRoughness;
2623
+
2624
+ vec3 f0 = vec3(0.04);
2625
+ vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
2626
+ diffuseColor *= 1.0 - metallic;
2627
+ vec3 specularColor = mix(f0, baseColor.rgb, metallic);
2628
+
2629
+ float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
2630
+ float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
2631
+ vec3 specularEnvironmentR0 = specularColor.rgb;
2632
+ vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
2633
+ vec3 reflection = -normalize(reflect(v, n));
2634
+
2635
+ PBRInfo pbrInfo = PBRInfo(
2636
+ 0.0, // NdotL
2637
+ NdotV,
2638
+ 0.0, // NdotH
2639
+ 0.0, // LdotH
2640
+ 0.0, // VdotH
2641
+ perceptualRoughness,
2642
+ metallic,
2643
+ specularEnvironmentR0,
2644
+ specularEnvironmentR90,
2645
+ alphaRoughness,
2646
+ diffuseColor,
2647
+ specularColor,
2648
+ n,
2649
+ v
2650
+ );
2651
+
2652
+ #ifdef USE_LIGHTS
2653
+ PBRInfo_setAmbientLight(pbrInfo);
2654
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
2655
+
2656
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
2657
+ if (i < lighting.directionalLightCount) {
2658
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
2659
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
2660
+ }
2661
+ }
2662
+
2663
+ for(int i = 0; i < lighting.pointLightCount; i++) {
2664
+ if (i < lighting.pointLightCount) {
2665
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
2666
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
2667
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
2668
+ }
2669
+ }
2670
+
2671
+ for(int i = 0; i < lighting.spotLightCount; i++) {
2672
+ if (i < lighting.spotLightCount) {
2673
+ PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));
2674
+ float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);
2675
+ color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);
2676
+ }
2677
+ }
2678
+ #endif
2679
+
2680
+ #ifdef USE_IBL
2681
+ if (pbrMaterial.IBLenabled) {
2682
+ color += getIBLContribution(pbrInfo, n, reflection);
2683
+ }
2684
+ #endif
2685
+
2686
+ #ifdef HAS_OCCLUSIONMAP
2687
+ if (pbrMaterial.occlusionMapEnabled) {
2688
+ float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
2689
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
2690
+ }
2691
+ #endif
2692
+
2693
+ vec3 emissive = pbrMaterial.emissiveFactor;
2694
+ #ifdef HAS_EMISSIVEMAP
2695
+ if (pbrMaterial.emissiveMapEnabled) {
2696
+ emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb;
2697
+ }
2698
+ #endif
2699
+ color += emissive * pbrMaterial.emissiveStrength;
2700
+
2701
+ #ifdef PBR_DEBUG
2702
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
2703
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
2704
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
2705
+ #endif
2706
+
2707
+ return vec4(pow(color, vec3(1.0 / 2.2)), baseColor.a);
2708
+ }
2709
+
2710
+ float specularIntensity = pbrMaterial.specularIntensityFactor;
2711
+ #ifdef HAS_SPECULARINTENSITYMAP
2712
+ if (pbrMaterial.specularIntensityMapEnabled) {
2713
+ specularIntensity *= texture(pbr_specularIntensitySampler, pbr_vUV).a;
2714
+ }
2715
+ #endif
2716
+
2717
+ vec3 specularFactor = pbrMaterial.specularColorFactor;
2718
+ #ifdef HAS_SPECULARCOLORMAP
2719
+ if (pbrMaterial.specularColorMapEnabled) {
2720
+ specularFactor *= SRGBtoLINEAR(texture(pbr_specularColorSampler, pbr_vUV)).rgb;
2721
+ }
2722
+ #endif
2723
+
2724
+ transmission = pbrMaterial.transmissionFactor;
2725
+ #ifdef HAS_TRANSMISSIONMAP
2726
+ if (pbrMaterial.transmissionMapEnabled) {
2727
+ transmission *= texture(pbr_transmissionSampler, pbr_vUV).r;
2728
+ }
2729
+ #endif
2730
+ transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);
2731
+ float thickness = max(pbrMaterial.thicknessFactor, 0.0);
2732
+ #ifdef HAS_THICKNESSMAP
2733
+ thickness *= texture(pbr_thicknessSampler, pbr_vUV).g;
2734
+ #endif
2735
+
2736
+ float clearcoatFactor = pbrMaterial.clearcoatFactor;
2737
+ float clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;
2738
+ #ifdef HAS_CLEARCOATMAP
2739
+ if (pbrMaterial.clearcoatMapEnabled) {
2740
+ clearcoatFactor *= texture(pbr_clearcoatSampler, pbr_vUV).r;
2741
+ }
2742
+ #endif
2743
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
2744
+ if (pbrMaterial.clearcoatRoughnessMapEnabled) {
2745
+ clearcoatRoughness *= texture(pbr_clearcoatRoughnessSampler, pbr_vUV).g;
2746
+ }
2747
+ #endif
2748
+ clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);
2749
+ clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
2750
+ vec3 clearcoatNormal = getClearcoatNormal(tbn, n);
2751
+
2752
+ vec3 sheenColor = pbrMaterial.sheenColorFactor;
2753
+ float sheenRoughness = pbrMaterial.sheenRoughnessFactor;
2754
+ #ifdef HAS_SHEENCOLORMAP
2755
+ if (pbrMaterial.sheenColorMapEnabled) {
2756
+ sheenColor *= SRGBtoLINEAR(texture(pbr_sheenColorSampler, pbr_vUV)).rgb;
2757
+ }
2758
+ #endif
2759
+ #ifdef HAS_SHEENROUGHNESSMAP
2760
+ if (pbrMaterial.sheenRoughnessMapEnabled) {
2761
+ sheenRoughness *= texture(pbr_sheenRoughnessSampler, pbr_vUV).a;
2762
+ }
2763
+ #endif
2764
+ sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);
2765
+
2766
+ float iridescence = pbrMaterial.iridescenceFactor;
2767
+ #ifdef HAS_IRIDESCENCEMAP
2768
+ if (pbrMaterial.iridescenceMapEnabled) {
2769
+ iridescence *= texture(pbr_iridescenceSampler, pbr_vUV).r;
2770
+ }
2771
+ #endif
2772
+ iridescence = clamp(iridescence, 0.0, 1.0);
2773
+ float iridescenceThickness = mix(
2774
+ pbrMaterial.iridescenceThicknessRange.x,
2775
+ pbrMaterial.iridescenceThicknessRange.y,
2776
+ 0.5
2777
+ );
2778
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
2779
+ iridescenceThickness = mix(
2780
+ pbrMaterial.iridescenceThicknessRange.x,
2781
+ pbrMaterial.iridescenceThicknessRange.y,
2782
+ texture(pbr_iridescenceThicknessSampler, pbr_vUV).g
2783
+ );
2784
+ #endif
2785
+
2786
+ float anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);
2787
+ vec2 anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);
2788
+ #ifdef HAS_ANISOTROPYMAP
2789
+ if (pbrMaterial.anisotropyMapEnabled) {
2790
+ vec3 anisotropySample = texture(pbr_anisotropySampler, pbr_vUV).rgb;
2791
+ anisotropyStrength *= anisotropySample.b;
2792
+ vec2 mappedDirection = anisotropySample.rg * 2.0 - 1.0;
2793
+ if (length(mappedDirection) > 0.0001) {
2794
+ anisotropyDirection = normalize(mappedDirection);
2795
+ }
2796
+ }
2797
+ #endif
2798
+ anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);
2799
+ vec3 anisotropyTangent = normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);
2800
+ if (length(anisotropyTangent) < 0.0001) {
2801
+ anisotropyTangent = normalize(tbn[0]);
2802
+ }
2803
+ float anisotropyViewAlignment = abs(dot(v, anisotropyTangent));
2804
+ perceptualRoughness = mix(
2805
+ perceptualRoughness,
2806
+ clamp(perceptualRoughness * (1.0 - 0.6 * anisotropyViewAlignment), c_MinRoughness, 1.0),
2807
+ anisotropyStrength
2808
+ );
2809
+
1854
2810
  // Roughness is authored as perceptual roughness; as is convention,
1855
2811
  // convert to material roughness by squaring the perceptual roughness [2].
1856
2812
  float alphaRoughness = perceptualRoughness * perceptualRoughness;
1857
2813
 
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);
2814
+ float dielectricF0 = getDielectricF0(pbrMaterial.ior);
2815
+ vec3 dielectricSpecularF0 = min(
2816
+ vec3(dielectricF0) * specularFactor * specularIntensity,
2817
+ vec3(1.0)
2818
+ );
2819
+ vec3 iridescenceTint = getIridescenceTint(iridescence, iridescenceThickness, NdotV);
2820
+ dielectricSpecularF0 = mix(
2821
+ dielectricSpecularF0,
2822
+ dielectricSpecularF0 * iridescenceTint,
2823
+ iridescence
2824
+ );
2825
+ vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - dielectricSpecularF0);
2826
+ diffuseColor *= (1.0 - metallic) * (1.0 - transmission);
2827
+ vec3 specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);
2828
+
2829
+ float baseLayerEnergy = 1.0 - clearcoatFactor * 0.25;
2830
+ diffuseColor *= baseLayerEnergy;
2831
+ specularColor *= baseLayerEnergy;
1862
2832
 
1863
2833
  // Compute reflectance.
1864
2834
  float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
@@ -1870,11 +2840,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
1870
2840
  float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
1871
2841
  vec3 specularEnvironmentR0 = specularColor.rgb;
1872
2842
  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
2843
  vec3 reflection = -normalize(reflect(v, n));
1879
2844
 
1880
2845
  PBRInfo pbrInfo = PBRInfo(
@@ -1898,13 +2863,33 @@ vec4 pbr_filterColor(vec4 colorUnused)
1898
2863
  #ifdef USE_LIGHTS
1899
2864
  // Apply ambient light
1900
2865
  PBRInfo_setAmbientLight(pbrInfo);
1901
- color += calculateFinalColor(pbrInfo, lighting.ambientColor);
2866
+ color += calculateMaterialLightColor(
2867
+ pbrInfo,
2868
+ lighting.ambientColor,
2869
+ clearcoatNormal,
2870
+ clearcoatFactor,
2871
+ clearcoatRoughness,
2872
+ sheenColor,
2873
+ sheenRoughness,
2874
+ anisotropyTangent,
2875
+ anisotropyStrength
2876
+ );
1902
2877
 
1903
2878
  // Apply directional light
1904
2879
  for(int i = 0; i < lighting.directionalLightCount; i++) {
1905
2880
  if (i < lighting.directionalLightCount) {
1906
2881
  PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
1907
- color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
2882
+ color += calculateMaterialLightColor(
2883
+ pbrInfo,
2884
+ lighting_getDirectionalLight(i).color,
2885
+ clearcoatNormal,
2886
+ clearcoatFactor,
2887
+ clearcoatRoughness,
2888
+ sheenColor,
2889
+ sheenRoughness,
2890
+ anisotropyTangent,
2891
+ anisotropyStrength
2892
+ );
1908
2893
  }
1909
2894
  }
1910
2895
 
@@ -1913,7 +2898,35 @@ vec4 pbr_filterColor(vec4 colorUnused)
1913
2898
  if (i < lighting.pointLightCount) {
1914
2899
  PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
1915
2900
  float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
1916
- color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
2901
+ color += calculateMaterialLightColor(
2902
+ pbrInfo,
2903
+ lighting_getPointLight(i).color / attenuation,
2904
+ clearcoatNormal,
2905
+ clearcoatFactor,
2906
+ clearcoatRoughness,
2907
+ sheenColor,
2908
+ sheenRoughness,
2909
+ anisotropyTangent,
2910
+ anisotropyStrength
2911
+ );
2912
+ }
2913
+ }
2914
+
2915
+ for(int i = 0; i < lighting.spotLightCount; i++) {
2916
+ if (i < lighting.spotLightCount) {
2917
+ PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));
2918
+ float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);
2919
+ color += calculateMaterialLightColor(
2920
+ pbrInfo,
2921
+ lighting_getSpotLight(i).color / attenuation,
2922
+ clearcoatNormal,
2923
+ clearcoatFactor,
2924
+ clearcoatRoughness,
2925
+ sheenColor,
2926
+ sheenRoughness,
2927
+ anisotropyTangent,
2928
+ anisotropyStrength
2929
+ );
1917
2930
  }
1918
2931
  }
1919
2932
  #endif
@@ -1921,7 +2934,16 @@ vec4 pbr_filterColor(vec4 colorUnused)
1921
2934
  // Calculate lighting contribution from image based lighting source (IBL)
1922
2935
  #ifdef USE_IBL
1923
2936
  if (pbrMaterial.IBLenabled) {
1924
- color += getIBLContribution(pbrInfo, n, reflection);
2937
+ color += getIBLContribution(pbrInfo, n, reflection) *
2938
+ calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
2939
+ color += calculateClearcoatIBLContribution(
2940
+ pbrInfo,
2941
+ clearcoatNormal,
2942
+ -normalize(reflect(v, clearcoatNormal)),
2943
+ clearcoatFactor,
2944
+ clearcoatRoughness
2945
+ );
2946
+ color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;
1925
2947
  }
1926
2948
  #endif
1927
2949
 
@@ -1933,12 +2955,17 @@ vec4 pbr_filterColor(vec4 colorUnused)
1933
2955
  }
1934
2956
  #endif
1935
2957
 
2958
+ vec3 emissive = pbrMaterial.emissiveFactor;
1936
2959
  #ifdef HAS_EMISSIVEMAP
1937
2960
  if (pbrMaterial.emissiveMapEnabled) {
1938
- vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
1939
- color += emissive;
2961
+ emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb;
1940
2962
  }
1941
2963
  #endif
2964
+ color += emissive * pbrMaterial.emissiveStrength;
2965
+
2966
+ if (transmission > 0.0) {
2967
+ color = mix(color, color * getVolumeAttenuation(thickness), transmission);
2968
+ }
1942
2969
 
1943
2970
  // This section uses mix to override final color for reference app visualization
1944
2971
  // of various parameters in the lighting equation.
@@ -1958,62 +2985,103 @@ vec4 pbr_filterColor(vec4 colorUnused)
1958
2985
 
1959
2986
  }
1960
2987
 
1961
- return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
2988
+ float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
2989
+ return vec4(pow(color,vec3(1.0/2.2)), alpha);
1962
2990
  }
1963
- `;var gr=`struct PBRFragmentInputs {
2991
+ `;var Cn=`struct PBRFragmentInputs {
1964
2992
  pbr_vPosition: vec3f,
1965
2993
  pbr_vUV: vec2f,
1966
- pbr_vTBN: mat3f,
2994
+ pbr_vTBN: mat3x3f,
1967
2995
  pbr_vNormal: vec3f
1968
2996
  };
1969
2997
 
1970
- var fragmentInputs: PBRFragmentInputs;
2998
+ var<private> fragmentInputs: PBRFragmentInputs;
1971
2999
 
1972
3000
  fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)
1973
3001
  {
1974
3002
  var pos: vec4f = pbrProjection.modelMatrix * position;
1975
- pbr_vPosition = vec3(pos.xyz) / pos.w;
3003
+ fragmentInputs.pbr_vPosition = pos.xyz / pos.w;
3004
+ fragmentInputs.pbr_vNormal = vec3f(0.0, 0.0, 1.0);
3005
+ fragmentInputs.pbr_vTBN = mat3x3f(
3006
+ vec3f(1.0, 0.0, 0.0),
3007
+ vec3f(0.0, 1.0, 0.0),
3008
+ vec3f(0.0, 0.0, 1.0)
3009
+ );
3010
+ fragmentInputs.pbr_vUV = vec2f(0.0, 0.0);
1976
3011
 
1977
3012
  #ifdef HAS_NORMALS
3013
+ let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);
3014
+ fragmentInputs.pbr_vNormal = normalW;
1978
3015
  #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)));
3016
+ let tangentW: vec3f = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);
1981
3017
  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)));
3018
+ fragmentInputs.pbr_vTBN = mat3x3f(tangentW, bitangentW, normalW);
1985
3019
  #endif
1986
3020
  #endif
1987
3021
 
1988
3022
  #ifdef HAS_UV
1989
- pbr_vUV = uv;
1990
- #else
1991
- pbr_vUV = vec2(0.,0.);
3023
+ fragmentInputs.pbr_vUV = uv;
1992
3024
  #endif
1993
3025
  }
1994
3026
 
1995
3027
  struct pbrMaterialUniforms {
1996
3028
  // Material is unlit
1997
- unlit: uint32,
3029
+ unlit: u32,
1998
3030
 
1999
3031
  // Base color map
2000
- baseColorMapEnabled: uint32,
3032
+ baseColorMapEnabled: u32,
2001
3033
  baseColorFactor: vec4f,
2002
3034
 
2003
- normalMapEnabled : uint32,
3035
+ normalMapEnabled : u32,
2004
3036
  normalScale: f32, // #ifdef HAS_NORMALMAP
2005
3037
 
2006
- emissiveMapEnabled: uint32,
3038
+ emissiveMapEnabled: u32,
2007
3039
  emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP
2008
3040
 
2009
3041
  metallicRoughnessValues: vec2f,
2010
- metallicRoughnessMapEnabled: uint32,
3042
+ metallicRoughnessMapEnabled: u32,
2011
3043
 
2012
3044
  occlusionMapEnabled: i32,
2013
3045
  occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP
2014
3046
 
2015
3047
  alphaCutoffEnabled: i32,
2016
3048
  alphaCutoff: f32, // #ifdef ALPHA_CUTOFF
3049
+
3050
+ specularColorFactor: vec3f,
3051
+ specularIntensityFactor: f32,
3052
+ specularColorMapEnabled: i32,
3053
+ specularIntensityMapEnabled: i32,
3054
+
3055
+ ior: f32,
3056
+
3057
+ transmissionFactor: f32,
3058
+ transmissionMapEnabled: i32,
3059
+
3060
+ thicknessFactor: f32,
3061
+ attenuationDistance: f32,
3062
+ attenuationColor: vec3f,
3063
+
3064
+ clearcoatFactor: f32,
3065
+ clearcoatRoughnessFactor: f32,
3066
+ clearcoatMapEnabled: i32,
3067
+ clearcoatRoughnessMapEnabled: i32,
3068
+
3069
+ sheenColorFactor: vec3f,
3070
+ sheenRoughnessFactor: f32,
3071
+ sheenColorMapEnabled: i32,
3072
+ sheenRoughnessMapEnabled: i32,
3073
+
3074
+ iridescenceFactor: f32,
3075
+ iridescenceIor: f32,
3076
+ iridescenceThicknessRange: vec2f,
3077
+ iridescenceMapEnabled: i32,
3078
+
3079
+ anisotropyStrength: f32,
3080
+ anisotropyRotation: f32,
3081
+ anisotropyDirection: vec2f,
3082
+ anisotropyMapEnabled: i32,
3083
+
3084
+ emissiveStrength: f32,
2017
3085
 
2018
3086
  // IBL
2019
3087
  IBLenabled: i32,
@@ -2022,34 +3090,81 @@ struct pbrMaterialUniforms {
2022
3090
  // debugging flags used for shader output of intermediate PBR variables
2023
3091
  // #ifdef PBR_DEBUG
2024
3092
  scaleDiffBaseMR: vec4f,
2025
- scaleFGDSpec: vec4f
3093
+ scaleFGDSpec: vec4f,
2026
3094
  // #endif
2027
- }
2028
-
2029
- @binding(2) @group(0) var<uniform> material : pbrMaterialUniforms;
3095
+ }
3096
+
3097
+ @group(3) @binding(auto) var<uniform> pbrMaterial : pbrMaterialUniforms;
2030
3098
 
2031
3099
  // Samplers
2032
3100
  #ifdef HAS_BASECOLORMAP
2033
- uniform sampler2D pbr_baseColorSampler;
3101
+ @group(3) @binding(auto) var pbr_baseColorSampler: texture_2d<f32>;
3102
+ @group(3) @binding(auto) var pbr_baseColorSamplerSampler: sampler;
2034
3103
  #endif
2035
3104
  #ifdef HAS_NORMALMAP
2036
- uniform sampler2D pbr_normalSampler;
3105
+ @group(3) @binding(auto) var pbr_normalSampler: texture_2d<f32>;
3106
+ @group(3) @binding(auto) var pbr_normalSamplerSampler: sampler;
2037
3107
  #endif
2038
3108
  #ifdef HAS_EMISSIVEMAP
2039
- uniform sampler2D pbr_emissiveSampler;
3109
+ @group(3) @binding(auto) var pbr_emissiveSampler: texture_2d<f32>;
3110
+ @group(3) @binding(auto) var pbr_emissiveSamplerSampler: sampler;
2040
3111
  #endif
2041
3112
  #ifdef HAS_METALROUGHNESSMAP
2042
- uniform sampler2D pbr_metallicRoughnessSampler;
3113
+ @group(3) @binding(auto) var pbr_metallicRoughnessSampler: texture_2d<f32>;
3114
+ @group(3) @binding(auto) var pbr_metallicRoughnessSamplerSampler: sampler;
2043
3115
  #endif
2044
3116
  #ifdef HAS_OCCLUSIONMAP
2045
- uniform sampler2D pbr_occlusionSampler;
3117
+ @group(3) @binding(auto) var pbr_occlusionSampler: texture_2d<f32>;
3118
+ @group(3) @binding(auto) var pbr_occlusionSamplerSampler: sampler;
2046
3119
  #endif
2047
- #ifdef USE_IBL
2048
- uniform samplerCube pbr_diffuseEnvSampler;
2049
- uniform samplerCube pbr_specularEnvSampler;
2050
- uniform sampler2D pbr_brdfLUT;
3120
+ #ifdef HAS_SPECULARCOLORMAP
3121
+ @group(3) @binding(auto) var pbr_specularColorSampler: texture_2d<f32>;
3122
+ @group(3) @binding(auto) var pbr_specularColorSamplerSampler: sampler;
3123
+ #endif
3124
+ #ifdef HAS_SPECULARINTENSITYMAP
3125
+ @group(3) @binding(auto) var pbr_specularIntensitySampler: texture_2d<f32>;
3126
+ @group(3) @binding(auto) var pbr_specularIntensitySamplerSampler: sampler;
3127
+ #endif
3128
+ #ifdef HAS_TRANSMISSIONMAP
3129
+ @group(3) @binding(auto) var pbr_transmissionSampler: texture_2d<f32>;
3130
+ @group(3) @binding(auto) var pbr_transmissionSamplerSampler: sampler;
3131
+ #endif
3132
+ #ifdef HAS_THICKNESSMAP
3133
+ @group(3) @binding(auto) var pbr_thicknessSampler: texture_2d<f32>;
3134
+ @group(3) @binding(auto) var pbr_thicknessSamplerSampler: sampler;
3135
+ #endif
3136
+ #ifdef HAS_CLEARCOATMAP
3137
+ @group(3) @binding(auto) var pbr_clearcoatSampler: texture_2d<f32>;
3138
+ @group(3) @binding(auto) var pbr_clearcoatSamplerSampler: sampler;
3139
+ #endif
3140
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
3141
+ @group(3) @binding(auto) var pbr_clearcoatRoughnessSampler: texture_2d<f32>;
3142
+ @group(3) @binding(auto) var pbr_clearcoatRoughnessSamplerSampler: sampler;
3143
+ #endif
3144
+ #ifdef HAS_CLEARCOATNORMALMAP
3145
+ @group(3) @binding(auto) var pbr_clearcoatNormalSampler: texture_2d<f32>;
3146
+ @group(3) @binding(auto) var pbr_clearcoatNormalSamplerSampler: sampler;
3147
+ #endif
3148
+ #ifdef HAS_SHEENCOLORMAP
3149
+ @group(3) @binding(auto) var pbr_sheenColorSampler: texture_2d<f32>;
3150
+ @group(3) @binding(auto) var pbr_sheenColorSamplerSampler: sampler;
3151
+ #endif
3152
+ #ifdef HAS_SHEENROUGHNESSMAP
3153
+ @group(3) @binding(auto) var pbr_sheenRoughnessSampler: texture_2d<f32>;
3154
+ @group(3) @binding(auto) var pbr_sheenRoughnessSamplerSampler: sampler;
3155
+ #endif
3156
+ #ifdef HAS_IRIDESCENCEMAP
3157
+ @group(3) @binding(auto) var pbr_iridescenceSampler: texture_2d<f32>;
3158
+ @group(3) @binding(auto) var pbr_iridescenceSamplerSampler: sampler;
3159
+ #endif
3160
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
3161
+ @group(3) @binding(auto) var pbr_iridescenceThicknessSampler: texture_2d<f32>;
3162
+ @group(3) @binding(auto) var pbr_iridescenceThicknessSamplerSampler: sampler;
3163
+ #endif
3164
+ #ifdef HAS_ANISOTROPYMAP
3165
+ @group(3) @binding(auto) var pbr_anisotropySampler: texture_2d<f32>;
3166
+ @group(3) @binding(auto) var pbr_anisotropySamplerSampler: sampler;
2051
3167
  #endif
2052
-
2053
3168
  // Encapsulate the various inputs used by the various functions in the shading equation
2054
3169
  // We store values in this struct to simplify the integration of alternative implementations
2055
3170
  // of the shading terms, outlined in the Readme.MD Appendix.
@@ -2075,80 +3190,130 @@ const c_MinRoughness = 0.04;
2075
3190
 
2076
3191
  fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
2077
3192
  {
3193
+ var linOut: vec3f = srgbIn.xyz;
2078
3194
  #ifdef MANUAL_SRGB
3195
+ let bLess: vec3f = step(vec3f(0.04045), srgbIn.xyz);
3196
+ linOut = mix(
3197
+ srgbIn.xyz / vec3f(12.92),
3198
+ pow((srgbIn.xyz + vec3f(0.055)) / vec3f(1.055), vec3f(2.4)),
3199
+ bLess
3200
+ );
2079
3201
  #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
3202
+ linOut = pow(srgbIn.xyz, vec3f(2.2));
3203
+ #endif
3204
+ #endif
3205
+ return vec4f(linOut, srgbIn.w);
2089
3206
  }
2090
3207
 
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
3208
+ // Build the tangent basis from interpolated attributes or screen-space derivatives.
3209
+ fn getTBN() -> mat3x3f
2094
3210
  {
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);
3211
+ let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);
3212
+ let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);
3213
+ let tex_dx: vec3f = dpdx(vec3f(fragmentInputs.pbr_vUV, 0.0));
3214
+ let tex_dy: vec3f = dpdy(vec3f(fragmentInputs.pbr_vUV, 0.0));
3215
+ 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
3216
 
2103
- #ifdef HAS_NORMALS
2104
- var ng: vec3f = normalize(pbr_vNormal);
2105
- #else
2106
3217
  var ng: vec3f = cross(pos_dx, pos_dy);
3218
+ #ifdef HAS_NORMALS
3219
+ ng = normalize(fragmentInputs.pbr_vNormal);
2107
3220
  #endif
2108
-
2109
3221
  t = normalize(t - ng * dot(ng, t));
2110
3222
  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;
3223
+ var tbn: mat3x3f = mat3x3f(t, b, ng);
3224
+ #ifdef HAS_TANGENTS
3225
+ tbn = fragmentInputs.pbr_vTBN;
2114
3226
  #endif
2115
3227
 
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
3228
+ return tbn;
3229
+ }
3230
+
3231
+ // Find the normal for this fragment, pulling either from a predefined normal map
3232
+ // or from the interpolated mesh normal and tangent attributes.
3233
+ fn getMappedNormal(
3234
+ normalSampler: texture_2d<f32>,
3235
+ normalSamplerBinding: sampler,
3236
+ tbn: mat3x3f,
3237
+ normalScale: f32
3238
+ ) -> vec3f
3239
+ {
3240
+ let n = textureSample(normalSampler, normalSamplerBinding, fragmentInputs.pbr_vUV).rgb;
3241
+ return normalize(tbn * ((2.0 * n - 1.0) * vec3f(normalScale, normalScale, 1.0)));
3242
+ }
3243
+
3244
+ fn getNormal(tbn: mat3x3f) -> vec3f
3245
+ {
2120
3246
  // The tbn matrix is linearly interpolated, so we need to re-normalize
2121
- vec3 n = normalize(tbn[2].xyz);
3247
+ var n: vec3f = normalize(tbn[2].xyz);
3248
+ #ifdef HAS_NORMALMAP
3249
+ n = getMappedNormal(
3250
+ pbr_normalSampler,
3251
+ pbr_normalSamplerSampler,
3252
+ tbn,
3253
+ pbrMaterial.normalScale
3254
+ );
2122
3255
  #endif
2123
3256
 
2124
3257
  return n;
2125
3258
  }
2126
3259
 
3260
+ fn getClearcoatNormal(tbn: mat3x3f, baseNormal: vec3f) -> vec3f
3261
+ {
3262
+ #ifdef HAS_CLEARCOATNORMALMAP
3263
+ return getMappedNormal(
3264
+ pbr_clearcoatNormalSampler,
3265
+ pbr_clearcoatNormalSamplerSampler,
3266
+ tbn,
3267
+ 1.0
3268
+ );
3269
+ #else
3270
+ return baseNormal;
3271
+ #endif
3272
+ }
3273
+
2127
3274
  // Calculation of the lighting contribution from an optional Image Based Light source.
2128
3275
  // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
2129
3276
  // See our README.md on Environment Maps [3] for additional discussion.
2130
3277
  #ifdef USE_IBL
2131
- fn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f
3278
+ fn getIBLContribution(pbrInfo: PBRInfo, n: vec3f, reflection: vec3f) -> vec3f
2132
3279
  {
2133
- float mipCount = 9.0; // resolution of 512x512
2134
- float lod = (pbrInfo.perceptualRoughness * mipCount);
3280
+ let mipCount: f32 = 9.0; // resolution of 512x512
3281
+ let lod: f32 = pbrInfo.perceptualRoughness * mipCount;
2135
3282
  // 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
-
3283
+ let brdf = SRGBtoLINEAR(
3284
+ textureSampleLevel(
3285
+ pbr_brdfLUT,
3286
+ pbr_brdfLUTSampler,
3287
+ vec2f(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness),
3288
+ 0.0
3289
+ )
3290
+ ).rgb;
3291
+ let diffuseLight =
3292
+ SRGBtoLINEAR(
3293
+ textureSampleLevel(pbr_diffuseEnvSampler, pbr_diffuseEnvSamplerSampler, n, 0.0)
3294
+ ).rgb;
3295
+ var specularLight = SRGBtoLINEAR(
3296
+ textureSampleLevel(
3297
+ pbr_specularEnvSampler,
3298
+ pbr_specularEnvSamplerSampler,
3299
+ reflection,
3300
+ 0.0
3301
+ )
3302
+ ).rgb;
2140
3303
  #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;
3304
+ specularLight = SRGBtoLINEAR(
3305
+ textureSampleLevel(
3306
+ pbr_specularEnvSampler,
3307
+ pbr_specularEnvSamplerSampler,
3308
+ reflection,
3309
+ lod
3310
+ )
3311
+ ).rgb;
2144
3312
  #endif
2145
3313
 
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;
3314
+ let diffuse = diffuseLight * pbrInfo.diffuseColor * pbrMaterial.scaleIBLAmbient.x;
3315
+ let specular =
3316
+ specularLight * (pbrInfo.specularColor * brdf.x + brdf.y) * pbrMaterial.scaleIBLAmbient.y;
2152
3317
 
2153
3318
  return diffuse + specular;
2154
3319
  }
@@ -2158,7 +3323,7 @@ fn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f
2158
3323
  // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
2159
3324
  // See also [1], Equation 1
2160
3325
  fn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {
2161
- return pbrInfo.diffuseColor / PI;
3326
+ return pbrInfo.diffuseColor / M_PI;
2162
3327
  }
2163
3328
 
2164
3329
  // The following equation models the Fresnel reflectance term of the spec equation (aka F())
@@ -2192,7 +3357,173 @@ fn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {
2192
3357
  fn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {
2193
3358
  let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
2194
3359
  let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
2195
- return roughnessSq / (PI * f * f);
3360
+ return roughnessSq / (M_PI * f * f);
3361
+ }
3362
+
3363
+ fn maxComponent(value: vec3f) -> f32 {
3364
+ return max(max(value.r, value.g), value.b);
3365
+ }
3366
+
3367
+ fn getDielectricF0(ior: f32) -> f32 {
3368
+ let clampedIor = max(ior, 1.0);
3369
+ let ratio = (clampedIor - 1.0) / (clampedIor + 1.0);
3370
+ return ratio * ratio;
3371
+ }
3372
+
3373
+ fn normalizeDirection(direction: vec2f) -> vec2f {
3374
+ let directionLength = length(direction);
3375
+ if (directionLength > 0.0001) {
3376
+ return direction / directionLength;
3377
+ }
3378
+
3379
+ return vec2f(1.0, 0.0);
3380
+ }
3381
+
3382
+ fn rotateDirection(direction: vec2f, rotation: f32) -> vec2f {
3383
+ let s = sin(rotation);
3384
+ let c = cos(rotation);
3385
+ return vec2f(direction.x * c - direction.y * s, direction.x * s + direction.y * c);
3386
+ }
3387
+
3388
+ fn getIridescenceTint(iridescence: f32, thickness: f32, NdotV: f32) -> vec3f {
3389
+ if (iridescence <= 0.0) {
3390
+ return vec3f(1.0);
3391
+ }
3392
+
3393
+ let phase = 0.015 * thickness * pbrMaterial.iridescenceIor + (1.0 - NdotV) * 6.0;
3394
+ let thinFilmTint =
3395
+ 0.5 +
3396
+ 0.5 *
3397
+ cos(vec3f(phase, phase + 2.0943951, phase + 4.1887902));
3398
+ return mix(vec3f(1.0), thinFilmTint, iridescence);
3399
+ }
3400
+
3401
+ fn getVolumeAttenuation(thickness: f32) -> vec3f {
3402
+ if (thickness <= 0.0) {
3403
+ return vec3f(1.0);
3404
+ }
3405
+
3406
+ let attenuationCoefficient =
3407
+ -log(max(pbrMaterial.attenuationColor, vec3f(0.0001))) /
3408
+ max(pbrMaterial.attenuationDistance, 0.0001);
3409
+ return exp(-attenuationCoefficient * thickness);
3410
+ }
3411
+
3412
+ fn createClearcoatPBRInfo(
3413
+ basePBRInfo: PBRInfo,
3414
+ clearcoatNormal: vec3f,
3415
+ clearcoatRoughness: f32
3416
+ ) -> PBRInfo {
3417
+ let perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
3418
+ let alphaRoughness = perceptualRoughness * perceptualRoughness;
3419
+ let NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);
3420
+
3421
+ return PBRInfo(
3422
+ basePBRInfo.NdotL,
3423
+ NdotV,
3424
+ basePBRInfo.NdotH,
3425
+ basePBRInfo.LdotH,
3426
+ basePBRInfo.VdotH,
3427
+ perceptualRoughness,
3428
+ 0.0,
3429
+ vec3f(0.04),
3430
+ vec3f(1.0),
3431
+ alphaRoughness,
3432
+ vec3f(0.0),
3433
+ vec3f(0.04),
3434
+ clearcoatNormal,
3435
+ basePBRInfo.v
3436
+ );
3437
+ }
3438
+
3439
+ fn calculateClearcoatContribution(
3440
+ pbrInfo: PBRInfo,
3441
+ lightColor: vec3f,
3442
+ clearcoatNormal: vec3f,
3443
+ clearcoatFactor: f32,
3444
+ clearcoatRoughness: f32
3445
+ ) -> vec3f {
3446
+ if (clearcoatFactor <= 0.0) {
3447
+ return vec3f(0.0);
3448
+ }
3449
+
3450
+ let clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
3451
+ return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;
3452
+ }
3453
+
3454
+ #ifdef USE_IBL
3455
+ fn calculateClearcoatIBLContribution(
3456
+ pbrInfo: PBRInfo,
3457
+ clearcoatNormal: vec3f,
3458
+ reflection: vec3f,
3459
+ clearcoatFactor: f32,
3460
+ clearcoatRoughness: f32
3461
+ ) -> vec3f {
3462
+ if (clearcoatFactor <= 0.0) {
3463
+ return vec3f(0.0);
3464
+ }
3465
+
3466
+ let clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
3467
+ return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;
3468
+ }
3469
+ #endif
3470
+
3471
+ fn calculateSheenContribution(
3472
+ pbrInfo: PBRInfo,
3473
+ lightColor: vec3f,
3474
+ sheenColor: vec3f,
3475
+ sheenRoughness: f32
3476
+ ) -> vec3f {
3477
+ if (maxComponent(sheenColor) <= 0.0) {
3478
+ return vec3f(0.0);
3479
+ }
3480
+
3481
+ let sheenFresnel = pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
3482
+ let sheenVisibility = mix(1.0, pbrInfo.NdotL * pbrInfo.NdotV, sheenRoughness);
3483
+ return pbrInfo.NdotL *
3484
+ lightColor *
3485
+ sheenColor *
3486
+ (0.25 + 0.75 * sheenFresnel) *
3487
+ sheenVisibility *
3488
+ (1.0 - pbrInfo.metalness);
3489
+ }
3490
+
3491
+ fn calculateAnisotropyBoost(
3492
+ pbrInfo: PBRInfo,
3493
+ anisotropyTangent: vec3f,
3494
+ anisotropyStrength: f32
3495
+ ) -> f32 {
3496
+ if (anisotropyStrength <= 0.0) {
3497
+ return 1.0;
3498
+ }
3499
+
3500
+ let anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));
3501
+ let bitangentViewAlignment = abs(dot(pbrInfo.v, anisotropyBitangent));
3502
+ return mix(1.0, 0.65 + 0.7 * bitangentViewAlignment, anisotropyStrength);
3503
+ }
3504
+
3505
+ fn calculateMaterialLightColor(
3506
+ pbrInfo: PBRInfo,
3507
+ lightColor: vec3f,
3508
+ clearcoatNormal: vec3f,
3509
+ clearcoatFactor: f32,
3510
+ clearcoatRoughness: f32,
3511
+ sheenColor: vec3f,
3512
+ sheenRoughness: f32,
3513
+ anisotropyTangent: vec3f,
3514
+ anisotropyStrength: f32
3515
+ ) -> vec3f {
3516
+ let anisotropyBoost = calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
3517
+ var color = calculateFinalColor(pbrInfo, lightColor) * anisotropyBoost;
3518
+ color += calculateClearcoatContribution(
3519
+ pbrInfo,
3520
+ lightColor,
3521
+ clearcoatNormal,
3522
+ clearcoatFactor,
3523
+ clearcoatRoughness
3524
+ );
3525
+ color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);
3526
+ return color;
2196
3527
  }
2197
3528
 
2198
3529
  fn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {
@@ -2215,7 +3546,12 @@ fn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection:
2215
3546
  }
2216
3547
 
2217
3548
  fn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {
2218
- let light_direction = normalize(pointLight.position - pbr_vPosition);
3549
+ let light_direction = normalize(pointLight.position - fragmentInputs.pbr_vPosition);
3550
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
3551
+ }
3552
+
3553
+ fn PBRInfo_setSpotLight(pbrInfo: ptr<function, PBRInfo>, spotLight: SpotLight) {
3554
+ let light_direction = normalize(spotLight.position - fragmentInputs.pbr_vPosition);
2219
3555
  PBRInfo_setDirectionalLight(pbrInfo, light_direction);
2220
3556
  }
2221
3557
 
@@ -2234,11 +3570,11 @@ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
2234
3570
 
2235
3571
  fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2236
3572
  // The albedo may be defined from a base texture or a flat color
2237
- var baseColor: vec4<f32>;
3573
+ var baseColor: vec4<f32> = pbrMaterial.baseColorFactor;
2238
3574
  #ifdef HAS_BASECOLORMAP
2239
- baseColor = SRGBtoLINEAR(textureSample(pbr_baseColorSampler, pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
2240
- #else
2241
- baseColor = pbrMaterial.baseColorFactor;
3575
+ baseColor = SRGBtoLINEAR(
3576
+ textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, fragmentInputs.pbr_vUV)
3577
+ ) * pbrMaterial.baseColorFactor;
2242
3578
  #endif
2243
3579
 
2244
3580
  #ifdef ALPHA_CUTOFF
@@ -2248,8 +3584,9 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2248
3584
  #endif
2249
3585
 
2250
3586
  var color = vec3<f32>(0.0, 0.0, 0.0);
3587
+ var transmission = 0.0;
2251
3588
 
2252
- if (pbrMaterial.unlit) {
3589
+ if (pbrMaterial.unlit != 0u) {
2253
3590
  color = baseColor.rgb;
2254
3591
  } else {
2255
3592
  // Metallic and Roughness material properties are packed together
@@ -2260,20 +3597,318 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2260
3597
  #ifdef HAS_METALROUGHNESSMAP
2261
3598
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
2262
3599
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
2263
- let mrSample = textureSample(pbr_metallicRoughnessSampler, pbr_metallicRoughnessSampler, pbr_vUV);
3600
+ let mrSample = textureSample(
3601
+ pbr_metallicRoughnessSampler,
3602
+ pbr_metallicRoughnessSamplerSampler,
3603
+ fragmentInputs.pbr_vUV
3604
+ );
2264
3605
  perceptualRoughness = mrSample.g * perceptualRoughness;
2265
3606
  metallic = mrSample.b * metallic;
2266
3607
  #endif
2267
3608
  perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
2268
3609
  metallic = clamp(metallic, 0.0, 1.0);
3610
+ let tbn = getTBN();
3611
+ let n = getNormal(tbn); // normal at surface point
3612
+ let v = normalize(pbrProjection.camera - fragmentInputs.pbr_vPosition); // Vector from surface point to camera
3613
+ let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
3614
+ var useExtendedPBR = false;
3615
+ #ifdef USE_MATERIAL_EXTENSIONS
3616
+ useExtendedPBR =
3617
+ pbrMaterial.specularColorMapEnabled != 0 ||
3618
+ pbrMaterial.specularIntensityMapEnabled != 0 ||
3619
+ abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||
3620
+ maxComponent(abs(pbrMaterial.specularColorFactor - vec3f(1.0))) > 0.0001 ||
3621
+ abs(pbrMaterial.ior - 1.5) > 0.0001 ||
3622
+ pbrMaterial.transmissionMapEnabled != 0 ||
3623
+ pbrMaterial.transmissionFactor > 0.0001 ||
3624
+ pbrMaterial.clearcoatMapEnabled != 0 ||
3625
+ pbrMaterial.clearcoatRoughnessMapEnabled != 0 ||
3626
+ pbrMaterial.clearcoatFactor > 0.0001 ||
3627
+ pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||
3628
+ pbrMaterial.sheenColorMapEnabled != 0 ||
3629
+ pbrMaterial.sheenRoughnessMapEnabled != 0 ||
3630
+ maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||
3631
+ pbrMaterial.sheenRoughnessFactor > 0.0001 ||
3632
+ pbrMaterial.iridescenceMapEnabled != 0 ||
3633
+ pbrMaterial.iridescenceFactor > 0.0001 ||
3634
+ abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||
3635
+ abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||
3636
+ abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||
3637
+ pbrMaterial.anisotropyMapEnabled != 0 ||
3638
+ pbrMaterial.anisotropyStrength > 0.0001 ||
3639
+ abs(pbrMaterial.anisotropyRotation) > 0.0001 ||
3640
+ length(pbrMaterial.anisotropyDirection - vec2f(1.0, 0.0)) > 0.0001;
3641
+ #endif
3642
+
3643
+ if (!useExtendedPBR) {
3644
+ let alphaRoughness = perceptualRoughness * perceptualRoughness;
3645
+
3646
+ let f0 = vec3<f32>(0.04);
3647
+ var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);
3648
+ diffuseColor *= 1.0 - metallic;
3649
+ let specularColor = mix(f0, baseColor.rgb, metallic);
3650
+
3651
+ let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
3652
+ let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
3653
+ let specularEnvironmentR0 = specularColor;
3654
+ let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;
3655
+ let reflection = -normalize(reflect(v, n));
3656
+
3657
+ var pbrInfo = PBRInfo(
3658
+ 0.0, // NdotL
3659
+ NdotV,
3660
+ 0.0, // NdotH
3661
+ 0.0, // LdotH
3662
+ 0.0, // VdotH
3663
+ perceptualRoughness,
3664
+ metallic,
3665
+ specularEnvironmentR0,
3666
+ specularEnvironmentR90,
3667
+ alphaRoughness,
3668
+ diffuseColor,
3669
+ specularColor,
3670
+ n,
3671
+ v
3672
+ );
3673
+
3674
+ #ifdef USE_LIGHTS
3675
+ PBRInfo_setAmbientLight(&pbrInfo);
3676
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
3677
+
3678
+ for (var i = 0; i < lighting.directionalLightCount; i++) {
3679
+ if (i < lighting.directionalLightCount) {
3680
+ PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
3681
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
3682
+ }
3683
+ }
3684
+
3685
+ for (var i = 0; i < lighting.pointLightCount; i++) {
3686
+ if (i < lighting.pointLightCount) {
3687
+ PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));
3688
+ let attenuation = getPointLightAttenuation(
3689
+ lighting_getPointLight(i),
3690
+ distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)
3691
+ );
3692
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
3693
+ }
3694
+ }
3695
+
3696
+ for (var i = 0; i < lighting.spotLightCount; i++) {
3697
+ if (i < lighting.spotLightCount) {
3698
+ PBRInfo_setSpotLight(&pbrInfo, lighting_getSpotLight(i));
3699
+ let attenuation = getSpotLightAttenuation(
3700
+ lighting_getSpotLight(i),
3701
+ fragmentInputs.pbr_vPosition
3702
+ );
3703
+ color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);
3704
+ }
3705
+ }
3706
+ #endif
3707
+
3708
+ #ifdef USE_IBL
3709
+ if (pbrMaterial.IBLenabled != 0) {
3710
+ color += getIBLContribution(pbrInfo, n, reflection);
3711
+ }
3712
+ #endif
3713
+
3714
+ #ifdef HAS_OCCLUSIONMAP
3715
+ if (pbrMaterial.occlusionMapEnabled != 0) {
3716
+ let ao =
3717
+ textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, fragmentInputs.pbr_vUV).r;
3718
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
3719
+ }
3720
+ #endif
3721
+
3722
+ var emissive = pbrMaterial.emissiveFactor;
3723
+ #ifdef HAS_EMISSIVEMAP
3724
+ if (pbrMaterial.emissiveMapEnabled != 0u) {
3725
+ emissive *= SRGBtoLINEAR(
3726
+ textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, fragmentInputs.pbr_vUV)
3727
+ ).rgb;
3728
+ }
3729
+ #endif
3730
+ color += emissive * pbrMaterial.emissiveStrength;
3731
+
3732
+ #ifdef PBR_DEBUG
3733
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
3734
+ color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);
3735
+ color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
3736
+ #endif
3737
+
3738
+ return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);
3739
+ }
3740
+
3741
+ var specularIntensity = pbrMaterial.specularIntensityFactor;
3742
+ #ifdef HAS_SPECULARINTENSITYMAP
3743
+ if (pbrMaterial.specularIntensityMapEnabled != 0) {
3744
+ specularIntensity *= textureSample(
3745
+ pbr_specularIntensitySampler,
3746
+ pbr_specularIntensitySamplerSampler,
3747
+ fragmentInputs.pbr_vUV
3748
+ ).a;
3749
+ }
3750
+ #endif
3751
+
3752
+ var specularFactor = pbrMaterial.specularColorFactor;
3753
+ #ifdef HAS_SPECULARCOLORMAP
3754
+ if (pbrMaterial.specularColorMapEnabled != 0) {
3755
+ specularFactor *= SRGBtoLINEAR(
3756
+ textureSample(
3757
+ pbr_specularColorSampler,
3758
+ pbr_specularColorSamplerSampler,
3759
+ fragmentInputs.pbr_vUV
3760
+ )
3761
+ ).rgb;
3762
+ }
3763
+ #endif
3764
+
3765
+ transmission = pbrMaterial.transmissionFactor;
3766
+ #ifdef HAS_TRANSMISSIONMAP
3767
+ if (pbrMaterial.transmissionMapEnabled != 0) {
3768
+ transmission *= textureSample(
3769
+ pbr_transmissionSampler,
3770
+ pbr_transmissionSamplerSampler,
3771
+ fragmentInputs.pbr_vUV
3772
+ ).r;
3773
+ }
3774
+ #endif
3775
+ transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);
3776
+ var thickness = max(pbrMaterial.thicknessFactor, 0.0);
3777
+ #ifdef HAS_THICKNESSMAP
3778
+ thickness *= textureSample(
3779
+ pbr_thicknessSampler,
3780
+ pbr_thicknessSamplerSampler,
3781
+ fragmentInputs.pbr_vUV
3782
+ ).g;
3783
+ #endif
3784
+
3785
+ var clearcoatFactor = pbrMaterial.clearcoatFactor;
3786
+ var clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;
3787
+ #ifdef HAS_CLEARCOATMAP
3788
+ if (pbrMaterial.clearcoatMapEnabled != 0) {
3789
+ clearcoatFactor *= textureSample(
3790
+ pbr_clearcoatSampler,
3791
+ pbr_clearcoatSamplerSampler,
3792
+ fragmentInputs.pbr_vUV
3793
+ ).r;
3794
+ }
3795
+ #endif
3796
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
3797
+ if (pbrMaterial.clearcoatRoughnessMapEnabled != 0) {
3798
+ clearcoatRoughness *= textureSample(
3799
+ pbr_clearcoatRoughnessSampler,
3800
+ pbr_clearcoatRoughnessSamplerSampler,
3801
+ fragmentInputs.pbr_vUV
3802
+ ).g;
3803
+ }
3804
+ #endif
3805
+ clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);
3806
+ clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
3807
+ let clearcoatNormal = getClearcoatNormal(tbn, n);
3808
+
3809
+ var sheenColor = pbrMaterial.sheenColorFactor;
3810
+ var sheenRoughness = pbrMaterial.sheenRoughnessFactor;
3811
+ #ifdef HAS_SHEENCOLORMAP
3812
+ if (pbrMaterial.sheenColorMapEnabled != 0) {
3813
+ sheenColor *= SRGBtoLINEAR(
3814
+ textureSample(
3815
+ pbr_sheenColorSampler,
3816
+ pbr_sheenColorSamplerSampler,
3817
+ fragmentInputs.pbr_vUV
3818
+ )
3819
+ ).rgb;
3820
+ }
3821
+ #endif
3822
+ #ifdef HAS_SHEENROUGHNESSMAP
3823
+ if (pbrMaterial.sheenRoughnessMapEnabled != 0) {
3824
+ sheenRoughness *= textureSample(
3825
+ pbr_sheenRoughnessSampler,
3826
+ pbr_sheenRoughnessSamplerSampler,
3827
+ fragmentInputs.pbr_vUV
3828
+ ).a;
3829
+ }
3830
+ #endif
3831
+ sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);
3832
+
3833
+ var iridescence = pbrMaterial.iridescenceFactor;
3834
+ #ifdef HAS_IRIDESCENCEMAP
3835
+ if (pbrMaterial.iridescenceMapEnabled != 0) {
3836
+ iridescence *= textureSample(
3837
+ pbr_iridescenceSampler,
3838
+ pbr_iridescenceSamplerSampler,
3839
+ fragmentInputs.pbr_vUV
3840
+ ).r;
3841
+ }
3842
+ #endif
3843
+ iridescence = clamp(iridescence, 0.0, 1.0);
3844
+ var iridescenceThickness = mix(
3845
+ pbrMaterial.iridescenceThicknessRange.x,
3846
+ pbrMaterial.iridescenceThicknessRange.y,
3847
+ 0.5
3848
+ );
3849
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
3850
+ iridescenceThickness = mix(
3851
+ pbrMaterial.iridescenceThicknessRange.x,
3852
+ pbrMaterial.iridescenceThicknessRange.y,
3853
+ textureSample(
3854
+ pbr_iridescenceThicknessSampler,
3855
+ pbr_iridescenceThicknessSamplerSampler,
3856
+ fragmentInputs.pbr_vUV
3857
+ ).g
3858
+ );
3859
+ #endif
3860
+
3861
+ var anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);
3862
+ var anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);
3863
+ #ifdef HAS_ANISOTROPYMAP
3864
+ if (pbrMaterial.anisotropyMapEnabled != 0) {
3865
+ let anisotropySample = textureSample(
3866
+ pbr_anisotropySampler,
3867
+ pbr_anisotropySamplerSampler,
3868
+ fragmentInputs.pbr_vUV
3869
+ ).rgb;
3870
+ anisotropyStrength *= anisotropySample.b;
3871
+ let mappedDirection = anisotropySample.rg * 2.0 - 1.0;
3872
+ if (length(mappedDirection) > 0.0001) {
3873
+ anisotropyDirection = normalize(mappedDirection);
3874
+ }
3875
+ }
3876
+ #endif
3877
+ anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);
3878
+ var anisotropyTangent =
3879
+ normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);
3880
+ if (length(anisotropyTangent) < 0.0001) {
3881
+ anisotropyTangent = normalize(tbn[0]);
3882
+ }
3883
+ let anisotropyViewAlignment = abs(dot(v, anisotropyTangent));
3884
+ perceptualRoughness = mix(
3885
+ perceptualRoughness,
3886
+ clamp(perceptualRoughness * (1.0 - 0.6 * anisotropyViewAlignment), c_MinRoughness, 1.0),
3887
+ anisotropyStrength
3888
+ );
3889
+
2269
3890
  // Roughness is authored as perceptual roughness; as is convention,
2270
3891
  // convert to material roughness by squaring the perceptual roughness [2].
2271
3892
  let alphaRoughness = perceptualRoughness * perceptualRoughness;
2272
3893
 
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);
3894
+ let dielectricF0 = getDielectricF0(pbrMaterial.ior);
3895
+ var dielectricSpecularF0 = min(
3896
+ vec3f(dielectricF0) * specularFactor * specularIntensity,
3897
+ vec3f(1.0)
3898
+ );
3899
+ let iridescenceTint = getIridescenceTint(iridescence, iridescenceThickness, NdotV);
3900
+ dielectricSpecularF0 = mix(
3901
+ dielectricSpecularF0,
3902
+ dielectricSpecularF0 * iridescenceTint,
3903
+ iridescence
3904
+ );
3905
+ var diffuseColor = baseColor.rgb * (vec3f(1.0) - dielectricSpecularF0);
3906
+ diffuseColor *= (1.0 - metallic) * (1.0 - transmission);
3907
+ var specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);
3908
+
3909
+ let baseLayerEnergy = 1.0 - clearcoatFactor * 0.25;
3910
+ diffuseColor *= baseLayerEnergy;
3911
+ specularColor *= baseLayerEnergy;
2277
3912
 
2278
3913
  // Compute reflectance.
2279
3914
  let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
@@ -2285,11 +3920,6 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2285
3920
  let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
2286
3921
  let specularEnvironmentR0 = specularColor;
2287
3922
  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
3923
  let reflection = -normalize(reflect(v, n));
2294
3924
 
2295
3925
  var pbrInfo = PBRInfo(
@@ -2312,13 +3942,33 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2312
3942
  #ifdef USE_LIGHTS
2313
3943
  // Apply ambient light
2314
3944
  PBRInfo_setAmbientLight(&pbrInfo);
2315
- color += calculateFinalColor(pbrInfo, lighting.ambientColor);
3945
+ color += calculateMaterialLightColor(
3946
+ pbrInfo,
3947
+ lighting.ambientColor,
3948
+ clearcoatNormal,
3949
+ clearcoatFactor,
3950
+ clearcoatRoughness,
3951
+ sheenColor,
3952
+ sheenRoughness,
3953
+ anisotropyTangent,
3954
+ anisotropyStrength
3955
+ );
2316
3956
 
2317
3957
  // Apply directional light
2318
3958
  for (var i = 0; i < lighting.directionalLightCount; i++) {
2319
3959
  if (i < lighting.directionalLightCount) {
2320
3960
  PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
2321
- color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
3961
+ color += calculateMaterialLightColor(
3962
+ pbrInfo,
3963
+ lighting_getDirectionalLight(i).color,
3964
+ clearcoatNormal,
3965
+ clearcoatFactor,
3966
+ clearcoatRoughness,
3967
+ sheenColor,
3968
+ sheenRoughness,
3969
+ anisotropyTangent,
3970
+ anisotropyStrength
3971
+ );
2322
3972
  }
2323
3973
  }
2324
3974
 
@@ -2326,33 +3976,81 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2326
3976
  for (var i = 0; i < lighting.pointLightCount; i++) {
2327
3977
  if (i < lighting.pointLightCount) {
2328
3978
  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);
3979
+ let attenuation = getPointLightAttenuation(
3980
+ lighting_getPointLight(i),
3981
+ distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)
3982
+ );
3983
+ color += calculateMaterialLightColor(
3984
+ pbrInfo,
3985
+ lighting_getPointLight(i).color / attenuation,
3986
+ clearcoatNormal,
3987
+ clearcoatFactor,
3988
+ clearcoatRoughness,
3989
+ sheenColor,
3990
+ sheenRoughness,
3991
+ anisotropyTangent,
3992
+ anisotropyStrength
3993
+ );
3994
+ }
3995
+ }
3996
+
3997
+ for (var i = 0; i < lighting.spotLightCount; i++) {
3998
+ if (i < lighting.spotLightCount) {
3999
+ PBRInfo_setSpotLight(&pbrInfo, lighting_getSpotLight(i));
4000
+ let attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), fragmentInputs.pbr_vPosition);
4001
+ color += calculateMaterialLightColor(
4002
+ pbrInfo,
4003
+ lighting_getSpotLight(i).color / attenuation,
4004
+ clearcoatNormal,
4005
+ clearcoatFactor,
4006
+ clearcoatRoughness,
4007
+ sheenColor,
4008
+ sheenRoughness,
4009
+ anisotropyTangent,
4010
+ anisotropyStrength
4011
+ );
2331
4012
  }
2332
4013
  }
2333
4014
  #endif
2334
4015
 
2335
4016
  // Calculate lighting contribution from image based lighting source (IBL)
2336
4017
  #ifdef USE_IBL
2337
- if (pbrMaterial.IBLenabled) {
2338
- color += getIBLContribution(pbrInfo, n, reflection);
4018
+ if (pbrMaterial.IBLenabled != 0) {
4019
+ color += getIBLContribution(pbrInfo, n, reflection) *
4020
+ calculateAnisotropyBoost(pbrInfo, anisotropyTangent, anisotropyStrength);
4021
+ color += calculateClearcoatIBLContribution(
4022
+ pbrInfo,
4023
+ clearcoatNormal,
4024
+ -normalize(reflect(v, clearcoatNormal)),
4025
+ clearcoatFactor,
4026
+ clearcoatRoughness
4027
+ );
4028
+ color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;
2339
4029
  }
2340
4030
  #endif
2341
4031
 
2342
4032
  // Apply optional PBR terms for additional (optional) shading
2343
4033
  #ifdef HAS_OCCLUSIONMAP
2344
- if (pbrMaterial.occlusionMapEnabled) {
2345
- let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSampler, pbr_vUV).r;
4034
+ if (pbrMaterial.occlusionMapEnabled != 0) {
4035
+ let ao =
4036
+ textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, fragmentInputs.pbr_vUV).r;
2346
4037
  color = mix(color, color * ao, pbrMaterial.occlusionStrength);
2347
4038
  }
2348
4039
  #endif
2349
4040
 
4041
+ var emissive = pbrMaterial.emissiveFactor;
2350
4042
  #ifdef HAS_EMISSIVEMAP
2351
- if (pbrMaterial.emissiveMapEnabled) {
2352
- let emissive = SRGBtoLINEAR(textureSample(pbr_emissiveSampler, pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
2353
- color += emissive;
4043
+ if (pbrMaterial.emissiveMapEnabled != 0u) {
4044
+ emissive *= SRGBtoLINEAR(
4045
+ textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, fragmentInputs.pbr_vUV)
4046
+ ).rgb;
2354
4047
  }
2355
4048
  #endif
4049
+ color += emissive * pbrMaterial.emissiveStrength;
4050
+
4051
+ if (transmission > 0.0) {
4052
+ color = mix(color, color * getVolumeAttenuation(thickness), transmission);
4053
+ }
2356
4054
 
2357
4055
  // This section uses mix to override final color for reference app visualization
2358
4056
  // of various parameters in the lighting equation.
@@ -2371,14 +4069,52 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
2371
4069
  #endif
2372
4070
  }
2373
4071
 
2374
- return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);
4072
+ let alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
4073
+ return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), alpha);
2375
4074
  }
2376
- `;var vr=`uniform pbrProjectionUniforms {
4075
+ `;var yn=`layout(std140) uniform pbrProjectionUniforms {
2377
4076
  mat4 modelViewProjectionMatrix;
2378
4077
  mat4 modelMatrix;
2379
4078
  mat4 normalMatrix;
2380
4079
  vec3 camera;
2381
4080
  } 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);})();
4081
+ `,Mo=`struct pbrProjectionUniforms {
4082
+ modelViewProjectionMatrix: mat4x4<f32>,
4083
+ modelMatrix: mat4x4<f32>,
4084
+ normalMatrix: mat4x4<f32>,
4085
+ camera: vec3<f32>
4086
+ };
4087
+
4088
+ @group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;
4089
+ `,Pn={name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:Mo,vs:yn,fs:yn,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}};var Nn={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},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:[F,Ee,Pn],source:Cn,vs:Rn,fs:In,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>"}};var On=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Tn=`layout(std140) uniform pbrSceneUniforms {
4090
+ float exposure;
4091
+ int toneMapMode;
4092
+ float environmentIntensity;
4093
+ float environmentRotation;
4094
+ vec2 framebufferSize;
4095
+ mat4 viewMatrix;
4096
+ mat4 projectionMatrix;
4097
+ } pbrScene;
4098
+
4099
+ #ifdef USE_TRANSMISSION_FRAMEBUFFER
4100
+ uniform sampler2D pbr_transmissionFramebufferSampler;
4101
+ #endif
4102
+ `,Lo=`struct pbrSceneUniforms {
4103
+ exposure: f32,
4104
+ toneMapMode: i32,
4105
+ environmentIntensity: f32,
4106
+ environmentRotation: f32,
4107
+ framebufferSize: vec2<f32>,
4108
+ viewMatrix: mat4x4<f32>,
4109
+ projectionMatrix: mat4x4<f32>
4110
+ };
4111
+
4112
+ @group(1) @binding(auto) var<uniform> pbrScene: pbrSceneUniforms;
4113
+
4114
+ #ifdef USE_TRANSMISSION_FRAMEBUFFER
4115
+ @group(1) @binding(auto) var pbr_transmissionFramebufferSampler: texture_2d<f32>;
4116
+ @group(1) @binding(auto) var pbr_transmissionFramebufferSamplerSampler: sampler;
4117
+ #endif
4118
+ `,Fn={name:"pbrScene",bindingLayout:[{name:"pbrScene",group:1},{name:"pbr_transmissionFramebufferSampler",group:1}],source:Lo,vs:Tn,fs:Tn,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:On,projectionMatrix:On}};return Vn(ne);})();
2383
4119
  return __exports__;
2384
4120
  });