@luma.gl/shadertools 9.1.0-alpha.1 → 9.1.0-alpha.12

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 (244) hide show
  1. package/dist/dist.dev.js +1005 -487
  2. package/dist/dist.min.js +2489 -1625
  3. package/dist/index.cjs +2864 -1817
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +29 -28
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +8 -12
  8. package/dist/lib/glsl-utils/shader-utils.d.ts.map +1 -1
  9. package/dist/lib/glsl-utils/shader-utils.js +2 -3
  10. package/dist/lib/shader-assembler.d.ts +3 -4
  11. package/dist/lib/shader-assembler.d.ts.map +1 -1
  12. package/dist/lib/shader-assembler.js +3 -2
  13. package/dist/lib/shader-assembly/assemble-shaders.d.ts +4 -3
  14. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  15. package/dist/lib/shader-assembly/assemble-shaders.js +46 -18
  16. package/dist/lib/shader-assembly/platform-defines.d.ts.map +1 -1
  17. package/dist/lib/shader-assembly/platform-defines.js +14 -6
  18. package/dist/lib/shader-module/shader-module-dependencies.d.ts +53 -0
  19. package/dist/lib/shader-module/shader-module-dependencies.d.ts.map +1 -0
  20. package/dist/lib/{shader-assembly/resolve-modules.js → shader-module/shader-module-dependencies.js} +38 -14
  21. package/dist/lib/shader-module/shader-module.d.ts +30 -12
  22. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  23. package/dist/lib/shader-module/shader-module.js +76 -6
  24. package/dist/lib/shader-module/shader-pass.d.ts +3 -2
  25. package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
  26. package/dist/module-injectors.d.ts +2 -2
  27. package/dist/module-injectors.d.ts.map +1 -1
  28. package/dist/module-injectors.js +13 -10
  29. package/dist/modules/engine/geometry/geometry.d.ts.map +1 -1
  30. package/dist/modules/engine/geometry/geometry.js +12 -8
  31. package/dist/modules/engine/picking/picking.d.ts +9 -9
  32. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  33. package/dist/modules/engine/picking/picking.js +103 -66
  34. package/dist/modules/engine/project/project.d.ts +2 -2
  35. package/dist/modules/engine/project/project.d.ts.map +1 -1
  36. package/dist/modules/engine/project/project.js +36 -22
  37. package/dist/modules/engine/transform/transform.d.ts.map +1 -1
  38. package/dist/modules/engine/transform/transform.js +28 -16
  39. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +10 -7
  40. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  41. package/dist/modules/lighting/gouraud-material/gouraud-material.js +2 -0
  42. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +2 -2
  43. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +1 -1
  44. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +79 -53
  45. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
  46. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
  47. package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +38 -23
  48. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts +2 -0
  49. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +1 -0
  50. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js +56 -0
  51. package/dist/modules/lighting/lights/lighting.d.ts +5 -4
  52. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  53. package/dist/modules/lighting/lights/lighting.js +7 -5
  54. package/dist/modules/lighting/no-material/dirlight.d.ts +8 -8
  55. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  56. package/dist/modules/lighting/no-material/dirlight.js +34 -20
  57. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
  58. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
  59. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +304 -181
  60. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +72 -69
  61. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  62. package/dist/modules/lighting/pbr-material/pbr-material.js +4 -2
  63. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +1 -1
  64. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +1 -1
  65. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +38 -20
  66. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
  67. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
  68. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +21 -16
  69. package/dist/modules/lighting/phong-material/phong-material.d.ts +14 -12
  70. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  71. package/dist/modules/lighting/phong-material/phong-material.js +5 -3
  72. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  73. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  74. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +82 -54
  75. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +41 -0
  76. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -0
  77. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +130 -0
  78. package/dist/modules/math/fp32/fp32.d.ts.map +1 -1
  79. package/dist/modules/math/fp32/fp32.js +127 -100
  80. package/dist/modules/math/fp64/fp64-utils.d.ts +3 -3
  81. package/dist/modules/math/fp64/fp64-utils.d.ts.map +1 -1
  82. package/dist/modules/math/random/random.d.ts +1 -1
  83. package/dist/modules/math/random/random.d.ts.map +1 -1
  84. package/dist/modules/math/random/random.js +3 -3
  85. package/dist/modules/module-injectors.d.ts +2 -2
  86. package/dist/modules/module-injectors.d.ts.map +1 -1
  87. package/dist/modules/module-injectors.js +13 -10
  88. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +4 -1
  89. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
  90. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.js +16 -12
  91. package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts +4 -1
  92. package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
  93. package/dist/modules/postprocessing/image-adjust-filters/denoise.js +21 -17
  94. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts +5 -2
  95. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  96. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.js +29 -22
  97. package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts +4 -1
  98. package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
  99. package/dist/modules/postprocessing/image-adjust-filters/noise.js +14 -10
  100. package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts +4 -1
  101. package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
  102. package/dist/modules/postprocessing/image-adjust-filters/sepia.js +17 -12
  103. package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts +4 -1
  104. package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
  105. package/dist/modules/postprocessing/image-adjust-filters/vibrance.js +12 -9
  106. package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts +4 -1
  107. package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
  108. package/dist/modules/postprocessing/image-adjust-filters/vignette.js +13 -10
  109. package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts +5 -2
  110. package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
  111. package/dist/modules/postprocessing/image-blur-filters/tiltshift.js +40 -26
  112. package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts +5 -2
  113. package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
  114. package/dist/modules/postprocessing/image-blur-filters/triangleblur.js +32 -19
  115. package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts +4 -1
  116. package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
  117. package/dist/modules/postprocessing/image-blur-filters/zoomblur.js +2 -0
  118. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts +4 -1
  119. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
  120. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.js +31 -27
  121. package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts +4 -1
  122. package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
  123. package/dist/modules/postprocessing/image-fun-filters/dotscreen.js +19 -15
  124. package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts +8 -5
  125. package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
  126. package/dist/modules/postprocessing/image-fun-filters/edgework.js +53 -42
  127. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +4 -1
  128. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
  129. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.js +41 -33
  130. package/dist/modules/postprocessing/image-fun-filters/ink.d.ts +4 -1
  131. package/dist/modules/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
  132. package/dist/modules/postprocessing/image-fun-filters/ink.js +27 -25
  133. package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts +2 -1
  134. package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
  135. package/dist/modules/postprocessing/image-fun-filters/magnify.js +17 -16
  136. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts +5 -2
  137. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
  138. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.js +24 -20
  139. package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts +5 -2
  140. package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
  141. package/dist/modules/postprocessing/image-warp-filters/swirl.js +26 -22
  142. package/dist/modules/postprocessing/image-warp-filters/warp.d.ts +2 -1
  143. package/dist/modules/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
  144. package/dist/modules/postprocessing/image-warp-filters/warp.js +9 -8
  145. package/dist/modules-webgl1/geometry/geometry.d.ts.map +1 -1
  146. package/dist/modules-webgl1/geometry/geometry.js +12 -8
  147. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +2 -2
  148. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +1 -1
  149. package/dist/modules-webgl1/lighting/dirlight/dirlight.js +8 -5
  150. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +1 -1
  151. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +1 -1
  152. package/dist/modules-webgl1/lighting/lights/lights-glsl.js +19 -11
  153. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +1 -1
  154. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +1 -1
  155. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +268 -157
  156. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +1 -1
  157. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +1 -1
  158. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +16 -12
  159. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +1 -1
  160. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +1 -1
  161. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +64 -55
  162. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  163. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  164. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +113 -81
  165. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +1 -1
  166. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +1 -1
  167. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +588 -433
  168. package/dist/modules-webgl1/project/project.d.ts +2 -2
  169. package/dist/modules-webgl1/project/project.d.ts.map +1 -1
  170. package/dist/modules-webgl1/project/project.js +5 -4
  171. package/package.json +5 -5
  172. package/src/index.ts +78 -32
  173. package/src/lib/glsl-utils/shader-utils.ts +1 -3
  174. package/src/lib/shader-assembler.ts +7 -8
  175. package/src/lib/shader-assembly/assemble-shaders.ts +55 -22
  176. package/src/lib/shader-assembly/platform-defines.ts +5 -6
  177. package/src/lib/shader-module/shader-module-dependencies.ts +111 -0
  178. package/src/lib/shader-module/shader-module.ts +134 -19
  179. package/src/lib/shader-module/shader-pass.ts +3 -2
  180. package/src/module-injectors.ts +2 -4
  181. package/src/modules/engine/geometry/geometry.ts +2 -3
  182. package/src/modules/engine/picking/picking.ts +12 -10
  183. package/src/modules/engine/project/project.ts +2 -3
  184. package/src/modules/engine/transform/transform.ts +1 -3
  185. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  186. package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +2 -4
  187. package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +1 -3
  188. package/src/modules/lighting/lights/lighting-uniforms-wgsl.ts +57 -0
  189. package/src/modules/lighting/lights/lighting.ts +9 -5
  190. package/src/modules/lighting/no-material/dirlight.ts +30 -19
  191. package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +1 -2
  192. package/src/modules/lighting/pbr-material/pbr-material.ts +44 -38
  193. package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +1 -3
  194. package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +1 -3
  195. package/src/modules/lighting/phong-material/phong-material.ts +6 -3
  196. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -4
  197. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +132 -0
  198. package/src/modules/math/fp32/fp32.ts +1 -2
  199. package/src/modules/math/fp64/fp64-utils.ts +3 -3
  200. package/src/modules/math/random/random.ts +1 -2
  201. package/src/modules/module-injectors.ts +2 -4
  202. package/src/modules/postprocessing/image-adjust-filters/brightnesscontrast.ts +6 -2
  203. package/src/modules/postprocessing/image-adjust-filters/denoise.ts +7 -3
  204. package/src/modules/postprocessing/image-adjust-filters/huesaturation.ts +9 -4
  205. package/src/modules/postprocessing/image-adjust-filters/noise.ts +6 -2
  206. package/src/modules/postprocessing/image-adjust-filters/sepia.ts +6 -2
  207. package/src/modules/postprocessing/image-adjust-filters/vibrance.ts +5 -2
  208. package/src/modules/postprocessing/image-adjust-filters/vignette.ts +11 -4
  209. package/src/modules/postprocessing/image-blur-filters/tiltshift.ts +6 -2
  210. package/src/modules/postprocessing/image-blur-filters/triangleblur.ts +6 -2
  211. package/src/modules/postprocessing/image-blur-filters/zoomblur.ts +5 -0
  212. package/src/modules/postprocessing/image-fun-filters/colorhalftone.ts +6 -2
  213. package/src/modules/postprocessing/image-fun-filters/dotscreen.ts +6 -2
  214. package/src/modules/postprocessing/image-fun-filters/edgework.ts +10 -4
  215. package/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts +6 -2
  216. package/src/modules/postprocessing/image-fun-filters/ink.ts +8 -3
  217. package/src/modules/postprocessing/image-fun-filters/magnify.ts +3 -2
  218. package/src/modules/postprocessing/image-warp-filters/bulgepinch.ts +6 -2
  219. package/src/modules/postprocessing/image-warp-filters/swirl.ts +8 -2
  220. package/src/modules/postprocessing/image-warp-filters/warp.ts +3 -2
  221. package/src/modules-webgl1/geometry/geometry.ts +2 -3
  222. package/src/modules-webgl1/lighting/dirlight/dirlight.ts +3 -4
  223. package/src/modules-webgl1/lighting/lights/lights-glsl.ts +1 -3
  224. package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +1 -2
  225. package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +1 -3
  226. package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +1 -3
  227. package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +1 -3
  228. package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +1 -3
  229. package/src/modules-webgl1/project/project.ts +1 -2
  230. package/dist/lib/glsl-utils/highlight.d.ts +0 -6
  231. package/dist/lib/glsl-utils/highlight.d.ts.map +0 -1
  232. package/dist/lib/glsl-utils/highlight.js +0 -9
  233. package/dist/lib/shader-assembly/resolve-modules.d.ts +0 -40
  234. package/dist/lib/shader-assembly/resolve-modules.d.ts.map +0 -1
  235. package/dist/lib/shader-module/normalize-shader-module.d.ts +0 -3
  236. package/dist/lib/shader-module/normalize-shader-module.d.ts.map +0 -1
  237. package/dist/lib/shader-module/normalize-shader-module.js +0 -14
  238. package/dist/lib/shader-module/shader-module-instance.d.ts +0 -28
  239. package/dist/lib/shader-module/shader-module-instance.d.ts.map +0 -1
  240. package/dist/lib/shader-module/shader-module-instance.js +0 -126
  241. package/src/lib/glsl-utils/highlight.ts +0 -11
  242. package/src/lib/shader-assembly/resolve-modules.ts +0 -81
  243. package/src/lib/shader-module/normalize-shader-module.ts +0 -17
  244. package/src/lib/shader-module/shader-module-instance.ts +0 -167
package/dist/dist.dev.js CHANGED
@@ -54,8 +54,6 @@ var __exports__ = (() => {
54
54
  var bundle_exports = {};
55
55
  __export(bundle_exports, {
56
56
  ShaderAssembler: () => ShaderAssembler,
57
- ShaderModuleInstance: () => ShaderModuleInstance,
58
- _ShaderModuleInstance: () => ShaderModuleInstance,
59
57
  _getDependencyGraph: () => getDependencyGraph,
60
58
  _resolveModules: () => resolveModules,
61
59
  _warp: () => warp,
@@ -63,6 +61,7 @@ var __exports__ = (() => {
63
61
  brightnessContrast: () => brightnessContrast,
64
62
  bulgePinch: () => bulgePinch,
65
63
  capitalize: () => capitalize,
64
+ checkShaderModuleDeprecations: () => checkShaderModuleDeprecations,
66
65
  colorHalftone: () => colorHalftone,
67
66
  combineInjects: () => combineInjects,
68
67
  convertToVec4: () => convertToVec4,
@@ -85,17 +84,20 @@ var __exports__ = (() => {
85
84
  getQualifierDetails: () => getQualifierDetails,
86
85
  getShaderInfo: () => getShaderInfo,
87
86
  getShaderLayoutFromWGSL: () => getShaderLayoutFromWGSL,
88
- glsl: () => glsl,
87
+ getShaderModuleDependencies: () => getShaderModuleDependencies,
88
+ getShaderModuleSource: () => getShaderModuleSource,
89
+ getShaderModuleUniforms: () => getShaderModuleUniforms,
89
90
  gouraudLighting: () => gouraudLighting,
90
91
  gouraudMaterial: () => gouraudMaterial,
91
92
  hexagonalPixelate: () => hexagonalPixelate,
92
93
  hueSaturation: () => hueSaturation,
94
+ initializeShaderModule: () => initializeShaderModule,
95
+ initializeShaderModules: () => initializeShaderModules,
93
96
  ink: () => ink,
94
97
  lighting: () => lighting,
95
98
  lights1: () => lights,
96
99
  magnify: () => magnify,
97
100
  noise: () => noise,
98
- normalizeShaderModule: () => normalizeShaderModule,
99
101
  pbr: () => pbr,
100
102
  pbrMaterial: () => pbrMaterial,
101
103
  phongLighting: () => phongLighting,
@@ -117,9 +119,6 @@ var __exports__ = (() => {
117
119
  });
118
120
  __reExport(bundle_exports, __toESM(require_core(), 1));
119
121
 
120
- // src/lib/glsl-utils/highlight.ts
121
- var glsl = (x) => `${x}`;
122
-
123
122
  // src/lib/utils/assert.ts
124
123
  function assert(condition, message) {
125
124
  if (!condition) {
@@ -194,13 +193,16 @@ var __exports__ = (() => {
194
193
  }
195
194
 
196
195
  // src/module-injectors.ts
197
- var MODULE_INJECTORS_VS = glsl`\
198
- #ifdef MODULE_LOGDEPTH
196
+ var MODULE_INJECTORS_VS = (
197
+ /* glsl */
198
+ `#ifdef MODULE_LOGDEPTH
199
199
  logdepth_adjustPosition(gl_Position);
200
200
  #endif
201
- `;
202
- var MODULE_INJECTORS_FS = glsl`\
203
- #ifdef MODULE_MATERIAL
201
+ `
202
+ );
203
+ var MODULE_INJECTORS_FS = (
204
+ /* glsl */
205
+ `#ifdef MODULE_MATERIAL
204
206
  gl_FragColor = material_filterColor(gl_FragColor);
205
207
  #endif
206
208
 
@@ -220,7 +222,8 @@ var __exports__ = (() => {
220
222
  #ifdef MODULE_LOGDEPTH
221
223
  logdepth_setFragDepth();
222
224
  #endif
223
- `;
225
+ `
226
+ );
224
227
 
225
228
  // src/lib/shader-assembly/shader-injections.ts
226
229
  var MODULE_INJECTORS = {
@@ -321,148 +324,71 @@ ${inject[key]}` : inject[key];
321
324
  return result;
322
325
  }
323
326
 
324
- // src/lib/shader-module/shader-module-instance.ts
325
- var index = 1;
326
- var ShaderModuleInstance = class {
327
- name;
328
- vs;
329
- fs;
330
- getModuleUniforms;
331
- dependencies;
332
- deprecations;
333
- defines;
334
- injections;
335
- uniforms = {};
336
- uniformTypes = {};
337
- static instantiateModules(modules) {
338
- return modules.map((module) => {
339
- if (module instanceof ShaderModuleInstance) {
340
- return module;
341
- }
342
- assert(
343
- typeof module !== "string",
344
- `Shader module use by name is deprecated. Import shader module '${JSON.stringify(
345
- module
346
- )}' and use it directly.`
347
- );
348
- if (!module.name) {
349
- console.warn("shader module has no name");
350
- module.name = `shader-module-${index++}`;
351
- }
352
- const moduleObject = new ShaderModuleInstance(module);
353
- moduleObject.dependencies = ShaderModuleInstance.instantiateModules(
354
- module.dependencies || []
355
- );
356
- return moduleObject;
357
- });
358
- }
359
- constructor(props) {
360
- const {
361
- name,
362
- vs: vs6,
363
- fs: fs28,
364
- dependencies = [],
365
- uniformPropTypes = {},
366
- getUniforms: getUniforms9,
367
- deprecations = [],
368
- defines = {},
369
- inject = {}
370
- } = props;
371
- assert(typeof name === "string");
372
- this.name = name;
373
- this.vs = vs6;
374
- this.fs = fs28;
375
- this.getModuleUniforms = getUniforms9;
376
- this.dependencies = ShaderModuleInstance.instantiateModules(dependencies);
377
- this.deprecations = this._parseDeprecationDefinitions(deprecations);
378
- this.defines = defines;
379
- this.injections = normalizeInjections(inject);
380
- if (uniformPropTypes) {
381
- this.uniforms = makePropValidators(uniformPropTypes);
382
- }
383
- }
384
- // Extracts the source code chunk for the specified shader type from the named shader module
385
- getModuleSource(stage) {
386
- let moduleSource;
387
- switch (stage) {
388
- case "vertex":
389
- moduleSource = this.vs || "";
390
- break;
391
- case "fragment":
392
- moduleSource = this.fs || "";
393
- break;
394
- default:
395
- assert(false);
396
- }
397
- const moduleName = this.name.toUpperCase().replace(/[^0-9a-z]/gi, "_");
398
- return `// ----- MODULE ${this.name} ---------------
399
-
400
- #define MODULE_${moduleName}
401
- ${moduleSource}
402
-
403
- `;
404
- }
405
- getUniforms(userProps, uniforms) {
406
- if (this.getModuleUniforms) {
407
- return this.getModuleUniforms(userProps, uniforms);
408
- }
409
- return getValidatedProperties(userProps, this.uniforms, this.name);
410
- }
411
- getDefines() {
412
- return this.defines;
327
+ // src/lib/shader-module/shader-module.ts
328
+ function initializeShaderModules(modules) {
329
+ modules.map((module) => initializeShaderModule(module));
330
+ }
331
+ function initializeShaderModule(module) {
332
+ if (module.instance) {
333
+ return;
413
334
  }
414
- // Warn about deprecated uniforms or functions
415
- checkDeprecations(shaderSource, log2) {
416
- this.deprecations.forEach((def) => {
417
- if (def.regex?.test(shaderSource)) {
418
- if (def.deprecated) {
419
- log2.deprecated(def.old, def.new)();
420
- } else {
421
- log2.removed(def.old, def.new)();
422
- }
423
- }
424
- });
335
+ initializeShaderModules(module.dependencies || []);
336
+ const {
337
+ uniformPropTypes = {},
338
+ deprecations = [],
339
+ // defines = {},
340
+ inject = {}
341
+ } = module;
342
+ const instance = {
343
+ normalizedInjections: normalizeInjections(inject),
344
+ parsedDeprecations: parseDeprecationDefinitions(deprecations)
345
+ };
346
+ if (uniformPropTypes) {
347
+ instance.propValidators = makePropValidators(uniformPropTypes);
425
348
  }
426
- _parseDeprecationDefinitions(deprecations) {
427
- deprecations.forEach((def) => {
428
- switch (def.type) {
429
- case "function":
430
- def.regex = new RegExp(`\\b${def.old}\\(`);
431
- break;
432
- default:
433
- def.regex = new RegExp(`${def.type} ${def.old};`);
434
- }
435
- });
436
- return deprecations;
349
+ module.instance = instance;
350
+ }
351
+ function getShaderModuleUniforms(module, props, oldUniforms) {
352
+ initializeShaderModule(module);
353
+ const uniforms = oldUniforms || { ...module.defaultUniforms };
354
+ if (module.getUniforms) {
355
+ return module.getUniforms(props, uniforms);
437
356
  }
438
- _defaultGetUniforms(opts = {}) {
439
- const uniforms = {};
440
- const propTypes = this.uniforms;
441
- for (const key in propTypes) {
442
- const propDef = propTypes[key];
443
- if (key in opts && !propDef.private) {
444
- if (propDef.validate) {
445
- assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);
446
- }
447
- uniforms[key] = opts[key];
357
+ return getValidatedProperties(props, module.instance?.propValidators, module.name);
358
+ }
359
+ function checkShaderModuleDeprecations(shaderModule, shaderSource, log2) {
360
+ shaderModule.deprecations?.forEach((def) => {
361
+ if (def.regex?.test(shaderSource)) {
362
+ if (def.deprecated) {
363
+ log2.deprecated(def.old, def.new)();
448
364
  } else {
449
- uniforms[key] = propDef.value;
365
+ log2.removed(def.old, def.new)();
450
366
  }
451
367
  }
452
- return uniforms;
453
- }
454
- };
455
-
456
- // src/lib/shader-assembly/resolve-modules.ts
457
- function resolveModules(modules) {
458
- const instances = ShaderModuleInstance.instantiateModules(modules);
459
- return getShaderDependencies(instances);
368
+ });
460
369
  }
461
- function getShaderDependencies(modules) {
370
+ function parseDeprecationDefinitions(deprecations) {
371
+ deprecations.forEach((def) => {
372
+ switch (def.type) {
373
+ case "function":
374
+ def.regex = new RegExp(`\\b${def.old}\\(`);
375
+ break;
376
+ default:
377
+ def.regex = new RegExp(`${def.type} ${def.old};`);
378
+ }
379
+ });
380
+ return deprecations;
381
+ }
382
+
383
+ // src/lib/shader-module/shader-module-dependencies.ts
384
+ function getShaderModuleDependencies(modules) {
385
+ initializeShaderModules(modules);
462
386
  const moduleMap = {};
463
387
  const moduleDepth = {};
464
388
  getDependencyGraph({ modules, level: 0, moduleMap, moduleDepth });
465
- return Object.keys(moduleDepth).sort((a, b) => moduleDepth[b] - moduleDepth[a]).map((name) => moduleMap[name]);
389
+ const dependencies = Object.keys(moduleDepth).sort((a, b) => moduleDepth[b] - moduleDepth[a]).map((name) => moduleMap[name]);
390
+ initializeShaderModules(dependencies);
391
+ return dependencies;
466
392
  }
467
393
  function getDependencyGraph(options) {
468
394
  const { modules, level, moduleMap, moduleDepth } = options;
@@ -481,49 +407,71 @@ ${moduleSource}
481
407
  }
482
408
  }
483
409
  }
410
+ function getShaderDependencies(modules) {
411
+ initializeShaderModules(modules);
412
+ const moduleMap = {};
413
+ const moduleDepth = {};
414
+ getDependencyGraph({ modules, level: 0, moduleMap, moduleDepth });
415
+ modules = Object.keys(moduleDepth).sort((a, b) => moduleDepth[b] - moduleDepth[a]).map((name) => moduleMap[name]);
416
+ initializeShaderModules(modules);
417
+ return modules;
418
+ }
419
+ function resolveModules(modules) {
420
+ return getShaderDependencies(modules);
421
+ }
484
422
 
485
423
  // src/lib/shader-assembly/platform-defines.ts
486
424
  function getPlatformShaderDefines(platformInfo) {
487
425
  switch (platformInfo?.gpu.toLowerCase()) {
488
426
  case "apple":
489
- return glsl`\
490
- #define APPLE_GPU
427
+ return (
428
+ /* glsl */
429
+ `#define APPLE_GPU
491
430
  // Apple optimizes away the calculation necessary for emulated fp64
492
431
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
493
432
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
494
433
  // Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
495
434
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
496
- `;
435
+ `
436
+ );
497
437
  case "nvidia":
498
- return glsl`\
499
- #define NVIDIA_GPU
438
+ return (
439
+ /* glsl */
440
+ `#define NVIDIA_GPU
500
441
  // Nvidia optimizes away the calculation necessary for emulated fp64
501
442
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
502
- `;
443
+ `
444
+ );
503
445
  case "intel":
504
- return glsl`\
505
- #define INTEL_GPU
446
+ return (
447
+ /* glsl */
448
+ `#define INTEL_GPU
506
449
  // Intel optimizes away the calculation necessary for emulated fp64
507
450
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
508
451
  // Intel's built-in 'tan' function doesn't have acceptable precision
509
452
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
510
453
  // Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
511
454
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
512
- `;
455
+ `
456
+ );
513
457
  case "amd":
514
- return glsl`\
515
- #define AMD_GPU
516
- `;
458
+ return (
459
+ /* glsl */
460
+ `#define AMD_GPU
461
+ `
462
+ );
517
463
  default:
518
- return glsl`\
519
- #define DEFAULT_GPU
464
+ return (
465
+ /* glsl */
466
+ `#define DEFAULT_GPU
520
467
  // Prevent driver from optimizing away the calculation necessary for emulated fp64
521
468
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
522
469
  // Headless Chrome's software shader 'tan' function doesn't have acceptable precision
523
470
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
524
471
  // If the GPU doesn't have full 32 bits precision, will causes overflow
525
472
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
526
- `;
473
+ `
474
+ );
527
475
  }
528
476
  }
529
477
 
@@ -661,11 +609,13 @@ ${moduleSource}
661
609
 
662
610
  ${DECLARATION_INJECT_MARKER}
663
611
  `;
664
- var FRAGMENT_SHADER_PROLOGUE = glsl`\
665
- precision highp float;
666
- `;
612
+ var FRAGMENT_SHADER_PROLOGUE = (
613
+ /* glsl */
614
+ `precision highp float;
615
+ `
616
+ );
667
617
  function assembleWGSLShader(options) {
668
- const modules = resolveModules(options.modules || []);
618
+ const modules = getShaderModuleDependencies(options.modules || []);
669
619
  return {
670
620
  source: assembleShaderWGSL(options.platformInfo, {
671
621
  ...options,
@@ -678,7 +628,7 @@ precision highp float;
678
628
  }
679
629
  function assembleGLSLShaderPair(options) {
680
630
  const { vs: vs6, fs: fs28 } = options;
681
- const modules = resolveModules(options.modules || []);
631
+ const modules = getShaderModuleDependencies(options.modules || []);
682
632
  return {
683
633
  vs: assembleShaderGLSL(options.platformInfo, {
684
634
  ...options,
@@ -733,14 +683,14 @@ precision highp float;
733
683
  mainInjections[key] = [injection];
734
684
  }
735
685
  }
736
- const modulesToInject = platformInfo.type !== "webgpu" ? modules : [];
686
+ const modulesToInject = modules;
737
687
  for (const module of modulesToInject) {
738
688
  if (log2) {
739
- module.checkDeprecations(coreSource, log2);
689
+ checkShaderModuleDeprecations(module, coreSource, log2);
740
690
  }
741
- const moduleSource = module.getModuleSource(stage, "wgsl");
691
+ const moduleSource = getShaderModuleSource(module, "wgsl");
742
692
  assembledSource += moduleSource;
743
- const injections = module.injections[stage];
693
+ const injections = module.injections?.[stage] || {};
744
694
  for (const key in injections) {
745
695
  const match = /^(v|f)s:#([\w-]+)$/.exec(key);
746
696
  if (match) {
@@ -782,7 +732,7 @@ precision highp float;
782
732
  const coreSource = sourceLines.slice(1).join("\n");
783
733
  const allDefines = {};
784
734
  modules.forEach((module) => {
785
- Object.assign(allDefines, module.getDefines());
735
+ Object.assign(allDefines, module.defines);
786
736
  });
787
737
  Object.assign(allDefines, defines);
788
738
  let assembledSource = "";
@@ -795,6 +745,7 @@ precision highp float;
795
745
  // ----- PROLOGUE -------------------------
796
746
  ${getShaderNameDefine({ id, source, stage })}
797
747
  ${`#define SHADER_TYPE_${stage.toUpperCase()}`}
748
+
798
749
  ${getPlatformShaderDefines(platformInfo)}
799
750
  ${stage === "fragment" ? FRAGMENT_SHADER_PROLOGUE : ""}
800
751
 
@@ -831,11 +782,11 @@ ${getApplicationDefines(allDefines)}
831
782
  }
832
783
  for (const module of modules) {
833
784
  if (log2) {
834
- module.checkDeprecations(coreSource, log2);
785
+ checkShaderModuleDeprecations(module, coreSource, log2);
835
786
  }
836
- const moduleSource = module.getModuleSource(stage);
787
+ const moduleSource = getShaderModuleSource(module, stage);
837
788
  assembledSource += moduleSource;
838
- const injections = module.injections[stage];
789
+ const injections = module.instance?.normalizedInjections[stage] || {};
839
790
  for (const key in injections) {
840
791
  const match = /^(v|f)s:#([\w-]+)$/.exec(key);
841
792
  if (match) {
@@ -864,7 +815,7 @@ ${getApplicationDefines(allDefines)}
864
815
  return function getUniforms9(opts) {
865
816
  const uniforms = {};
866
817
  for (const module of modules) {
867
- const moduleUniforms = module.getUniforms(opts, uniforms);
818
+ const moduleUniforms = module.getUniforms?.(opts, uniforms);
868
819
  Object.assign(uniforms, moduleUniforms);
869
820
  }
870
821
  return uniforms;
@@ -874,9 +825,7 @@ ${getApplicationDefines(allDefines)}
874
825
  const { id, source, stage } = options;
875
826
  const injectShaderName = id && source.indexOf("SHADER_NAME") === -1;
876
827
  return injectShaderName ? `
877
- #define SHADER_NAME ${id}_${stage}
878
-
879
- ` : "";
828
+ #define SHADER_NAME ${id}_${stage}` : "";
880
829
  }
881
830
  function getApplicationDefines(defines = {}) {
882
831
  let sourceText = "";
@@ -889,6 +838,36 @@ ${getApplicationDefines(allDefines)}
889
838
  }
890
839
  return sourceText;
891
840
  }
841
+ function getShaderModuleSource(module, stage) {
842
+ let moduleSource;
843
+ switch (stage) {
844
+ case "vertex":
845
+ moduleSource = module.vs || "";
846
+ break;
847
+ case "fragment":
848
+ moduleSource = module.fs || "";
849
+ break;
850
+ case "wgsl":
851
+ moduleSource = module.source || "";
852
+ break;
853
+ default:
854
+ assert(false);
855
+ }
856
+ if (!module.name) {
857
+ throw new Error("Shader module must have a name");
858
+ }
859
+ const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, "_");
860
+ let source = `// ----- MODULE ${module.name} ---------------
861
+
862
+ `;
863
+ if (stage !== "wgsl") {
864
+ source += `#define MODULE_${moduleName}
865
+ `;
866
+ }
867
+ source += `${moduleSource}
868
+ `;
869
+ return source;
870
+ }
892
871
 
893
872
  // src/lib/preprocessor/preprocessor.ts
894
873
  var IFDEF_REGEXP = /^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/;
@@ -998,9 +977,7 @@ ${getApplicationDefines(allDefines)}
998
977
  * Dedupe and combine with default modules
999
978
  */
1000
979
  _getModuleList(appModules = []) {
1001
- const modules = new Array(
1002
- this._defaultModules.length + appModules.length
1003
- );
980
+ const modules = new Array(this._defaultModules.length + appModules.length);
1004
981
  const seen = {};
1005
982
  let count = 0;
1006
983
  for (let i = 0, len = this._defaultModules.length; i < len; ++i) {
@@ -1018,31 +995,22 @@ ${getApplicationDefines(allDefines)}
1018
995
  }
1019
996
  }
1020
997
  modules.length = count;
1021
- return ShaderModuleInstance.instantiateModules(modules);
998
+ initializeShaderModules(modules);
999
+ return modules;
1022
1000
  }
1023
1001
  };
1024
1002
  var ShaderAssembler = _ShaderAssembler;
1025
1003
  /** Default ShaderAssembler instance */
1026
1004
  __publicField(ShaderAssembler, "defaultShaderAssembler");
1027
1005
 
1028
- // src/lib/shader-module/normalize-shader-module.ts
1029
- function normalizeShaderModule(module) {
1030
- if (!module.normalized) {
1031
- module.normalized = true;
1032
- if (module.uniformPropTypes && !module.getUniforms) {
1033
- const shaderModule = new ShaderModuleInstance(module);
1034
- module.getUniforms = shaderModule.getUniforms.bind(shaderModule);
1035
- }
1036
- }
1037
- return module;
1038
- }
1039
-
1040
1006
  // src/lib/glsl-utils/shader-utils.ts
1041
- var FS_GLES = glsl`\
1042
- out vec4 transform_output;
1007
+ var FS_GLES = (
1008
+ /* glsl */
1009
+ `out vec4 transform_output;
1043
1010
  void main() {
1044
1011
  transform_output = vec4(0);
1045
- }`;
1012
+ }`
1013
+ );
1046
1014
  var FS300 = `#version 300 es
1047
1015
  ${FS_GLES}`;
1048
1016
  function getQualifierDetails(line, qualifiers) {
@@ -1139,11 +1107,11 @@ void main() {
1139
1107
  return generateGLSLUniformDeclarations(module, options);
1140
1108
  }
1141
1109
  function generateGLSLUniformDeclarations(module, options) {
1142
- const glsl2 = [];
1110
+ const glsl = [];
1143
1111
  switch (options.uniforms) {
1144
1112
  case "scoped-interface-blocks":
1145
1113
  case "unscoped-interface-blocks":
1146
- glsl2.push(`uniform ${capitalize(module.name)} {`);
1114
+ glsl.push(`uniform ${capitalize(module.name)} {`);
1147
1115
  break;
1148
1116
  case "uniforms":
1149
1117
  }
@@ -1151,26 +1119,26 @@ void main() {
1151
1119
  const glslUniformType = getGLSLUniformType(uniformFormat);
1152
1120
  switch (options.uniforms) {
1153
1121
  case "scoped-interface-blocks":
1154
- glsl2.push(` ${glslUniformType} ${uniformName};`);
1122
+ glsl.push(` ${glslUniformType} ${uniformName};`);
1155
1123
  break;
1156
1124
  case "unscoped-interface-blocks":
1157
- glsl2.push(` ${glslUniformType} ${module.name}_${uniformName};`);
1125
+ glsl.push(` ${glslUniformType} ${module.name}_${uniformName};`);
1158
1126
  break;
1159
1127
  case "uniforms":
1160
- glsl2.push(`uniform ${glslUniformType} ${module.name}_${uniformName};`);
1128
+ glsl.push(`uniform ${glslUniformType} ${module.name}_${uniformName};`);
1161
1129
  }
1162
1130
  }
1163
1131
  switch (options.uniforms) {
1164
1132
  case "scoped-interface-blocks":
1165
- glsl2.push(`} ${module.name};`);
1133
+ glsl.push(`} ${module.name};`);
1166
1134
  break;
1167
1135
  case "unscoped-interface-blocks":
1168
- glsl2.push("};");
1136
+ glsl.push("};");
1169
1137
  break;
1170
1138
  case "uniforms":
1171
1139
  }
1172
- glsl2.push("");
1173
- return glsl2.join("\n");
1140
+ glsl.push("");
1141
+ return glsl.join("\n");
1174
1142
  }
1175
1143
  function getGLSLUniformType(uniformFormat) {
1176
1144
  const UNIFORM_TYPE_TO_GLSL = {
@@ -1196,8 +1164,8 @@ void main() {
1196
1164
  "mat4x3<f32>": "mat4x3",
1197
1165
  "mat4x4<f32>": "mat4"
1198
1166
  };
1199
- const glsl2 = UNIFORM_TYPE_TO_GLSL[uniformFormat];
1200
- return glsl2;
1167
+ const glsl = UNIFORM_TYPE_TO_GLSL[uniformFormat];
1168
+ return glsl;
1201
1169
  }
1202
1170
 
1203
1171
  // src/lib/shader-generator/wgsl/generate-wgsl.ts
@@ -1488,6 +1456,7 @@ void main() {
1488
1456
  return "assign";
1489
1457
  }
1490
1458
  search(callback) {
1459
+ this.variable.search(callback);
1491
1460
  this.value.search(callback);
1492
1461
  }
1493
1462
  };
@@ -1567,6 +1536,15 @@ void main() {
1567
1536
  return "enable";
1568
1537
  }
1569
1538
  };
1539
+ var Requires = class extends Statement {
1540
+ constructor(extensions) {
1541
+ super();
1542
+ this.extensions = extensions;
1543
+ }
1544
+ get astNodeType() {
1545
+ return "requires";
1546
+ }
1547
+ };
1570
1548
  var Diagnostic = class extends Statement {
1571
1549
  constructor(severity, rule) {
1572
1550
  super();
@@ -1838,6 +1816,9 @@ void main() {
1838
1816
  }
1839
1817
  search(callback) {
1840
1818
  callback(this);
1819
+ if (this.postfix) {
1820
+ this.postfix.search(callback);
1821
+ }
1841
1822
  }
1842
1823
  evaluate(context) {
1843
1824
  const constant = context.constants.get(this.name);
@@ -1931,6 +1912,15 @@ void main() {
1931
1912
  this.searchBlock(this.contents, callback);
1932
1913
  }
1933
1914
  };
1915
+ var ArrayIndex = class extends Expression {
1916
+ constructor(index) {
1917
+ super();
1918
+ this.index = index;
1919
+ }
1920
+ search(callback) {
1921
+ this.index.search(callback);
1922
+ }
1923
+ };
1934
1924
  var Operator = class extends Expression {
1935
1925
  constructor() {
1936
1926
  super();
@@ -2178,10 +2168,10 @@ void main() {
2178
2168
  continue: new TokenType("continue", TokenClass.keyword, "continue"),
2179
2169
  continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
2180
2170
  default: new TokenType("default", TokenClass.keyword, "default"),
2171
+ diagnostic: new TokenType("diagnostic", TokenClass.keyword, "diagnostic"),
2181
2172
  discard: new TokenType("discard", TokenClass.keyword, "discard"),
2182
2173
  else: new TokenType("else", TokenClass.keyword, "else"),
2183
2174
  enable: new TokenType("enable", TokenClass.keyword, "enable"),
2184
- diagnostic: new TokenType("diagnostic", TokenClass.keyword, "diagnostic"),
2185
2175
  fallthrough: new TokenType("fallthrough", TokenClass.keyword, "fallthrough"),
2186
2176
  false: new TokenType("false", TokenClass.keyword, "false"),
2187
2177
  fn: new TokenType("fn", TokenClass.keyword, "fn"),
@@ -2196,6 +2186,7 @@ void main() {
2196
2186
  read: new TokenType("read", TokenClass.keyword, "read"),
2197
2187
  read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
2198
2188
  return: new TokenType("return", TokenClass.keyword, "return"),
2189
+ requires: new TokenType("requires", TokenClass.keyword, "requires"),
2199
2190
  storage: new TokenType("storage", TokenClass.keyword, "storage"),
2200
2191
  switch: new TokenType("switch", TokenClass.keyword, "switch"),
2201
2192
  true: new TokenType("true", TokenClass.keyword, "true"),
@@ -2259,8 +2250,6 @@ void main() {
2259
2250
  and_and: new TokenType("and_and", TokenClass.token, "&&"),
2260
2251
  arrow: new TokenType("arrow ", TokenClass.token, "->"),
2261
2252
  attr: new TokenType("attr", TokenClass.token, "@"),
2262
- attr_left: new TokenType("attr_left", TokenClass.token, "[["),
2263
- attr_right: new TokenType("attr_right", TokenClass.token, "]]"),
2264
2253
  forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
2265
2254
  bang: new TokenType("bang", TokenClass.token, "!"),
2266
2255
  bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
@@ -2304,6 +2293,63 @@ void main() {
2304
2293
  shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
2305
2294
  shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<=")
2306
2295
  };
2296
+ TokenTypes.simpleTokens = {
2297
+ "@": _a.tokens.attr,
2298
+ "{": _a.tokens.brace_left,
2299
+ "}": _a.tokens.brace_right,
2300
+ ":": _a.tokens.colon,
2301
+ ",": _a.tokens.comma,
2302
+ "(": _a.tokens.paren_left,
2303
+ ")": _a.tokens.paren_right,
2304
+ ";": _a.tokens.semicolon
2305
+ };
2306
+ TokenTypes.literalTokens = {
2307
+ "&": _a.tokens.and,
2308
+ "&&": _a.tokens.and_and,
2309
+ "->": _a.tokens.arrow,
2310
+ "/": _a.tokens.forward_slash,
2311
+ "!": _a.tokens.bang,
2312
+ "[": _a.tokens.bracket_left,
2313
+ "]": _a.tokens.bracket_right,
2314
+ "=": _a.tokens.equal,
2315
+ "==": _a.tokens.equal_equal,
2316
+ "!=": _a.tokens.not_equal,
2317
+ ">": _a.tokens.greater_than,
2318
+ ">=": _a.tokens.greater_than_equal,
2319
+ ">>": _a.tokens.shift_right,
2320
+ "<": _a.tokens.less_than,
2321
+ "<=": _a.tokens.less_than_equal,
2322
+ "<<": _a.tokens.shift_left,
2323
+ "%": _a.tokens.modulo,
2324
+ "-": _a.tokens.minus,
2325
+ "--": _a.tokens.minus_minus,
2326
+ ".": _a.tokens.period,
2327
+ "+": _a.tokens.plus,
2328
+ "++": _a.tokens.plus_plus,
2329
+ "|": _a.tokens.or,
2330
+ "||": _a.tokens.or_or,
2331
+ "*": _a.tokens.star,
2332
+ "~": _a.tokens.tilde,
2333
+ "_": _a.tokens.underscore,
2334
+ "^": _a.tokens.xor,
2335
+ "+=": _a.tokens.plus_equal,
2336
+ "-=": _a.tokens.minus_equal,
2337
+ "*=": _a.tokens.times_equal,
2338
+ "/=": _a.tokens.division_equal,
2339
+ "%=": _a.tokens.modulo_equal,
2340
+ "&=": _a.tokens.and_equal,
2341
+ "|=": _a.tokens.or_equal,
2342
+ "^=": _a.tokens.xor_equal,
2343
+ ">>=": _a.tokens.shift_right_equal,
2344
+ "<<=": _a.tokens.shift_left_equal
2345
+ };
2346
+ TokenTypes.regexTokens = {
2347
+ decimal_float_literal: _a.tokens.decimal_float_literal,
2348
+ hex_float_literal: _a.tokens.hex_float_literal,
2349
+ int_literal: _a.tokens.int_literal,
2350
+ uint_literal: _a.tokens.uint_literal,
2351
+ ident: _a.tokens.ident
2352
+ };
2307
2353
  TokenTypes.storage_class = [
2308
2354
  _a.keywords.function,
2309
2355
  _a.keywords.private,
@@ -2426,7 +2472,7 @@ void main() {
2426
2472
  _a.keywords.bitcast,
2427
2473
  ..._a.any_texture_type
2428
2474
  ];
2429
- TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block];
2475
+ TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block, _a.keywords.diagnostic];
2430
2476
  TokenTypes.assignment_operators = [
2431
2477
  _a.tokens.equal,
2432
2478
  _a.tokens.plus_equal,
@@ -2530,7 +2576,32 @@ void main() {
2530
2576
  return true;
2531
2577
  }
2532
2578
  }
2579
+ const simpleToken = TokenTypes.simpleTokens[lexeme];
2580
+ if (simpleToken) {
2581
+ this._addToken(simpleToken);
2582
+ return true;
2583
+ }
2533
2584
  let matchType = TokenTypes.none;
2585
+ const isAlpha = this._isAlpha(lexeme);
2586
+ const isUnderscore = lexeme === "_";
2587
+ if (this._isAlphaNumeric(lexeme)) {
2588
+ let nextChar = this._peekAhead();
2589
+ while (this._isAlphaNumeric(nextChar)) {
2590
+ lexeme += this._advance();
2591
+ nextChar = this._peekAhead();
2592
+ }
2593
+ }
2594
+ if (isAlpha) {
2595
+ const matchedType = TokenTypes.keywords[lexeme];
2596
+ if (matchedType) {
2597
+ this._addToken(matchedType);
2598
+ return true;
2599
+ }
2600
+ }
2601
+ if (isAlpha || isUnderscore) {
2602
+ this._addToken(TokenTypes.tokens.ident);
2603
+ return true;
2604
+ }
2534
2605
  for (; ; ) {
2535
2606
  let matchedType = this._findType(lexeme);
2536
2607
  const nextLexeme = this._peekAhead();
@@ -2586,36 +2657,31 @@ void main() {
2586
2657
  return true;
2587
2658
  }
2588
2659
  _findType(lexeme) {
2589
- for (const name in TokenTypes.keywords) {
2590
- const type = TokenTypes.keywords[name];
2591
- if (this._match(lexeme, type.rule)) {
2592
- return type;
2660
+ for (const name in TokenTypes.regexTokens) {
2661
+ const type2 = TokenTypes.regexTokens[name];
2662
+ if (this._match(lexeme, type2.rule)) {
2663
+ return type2;
2593
2664
  }
2594
2665
  }
2595
- for (const name in TokenTypes.tokens) {
2596
- const type = TokenTypes.tokens[name];
2597
- if (this._match(lexeme, type.rule)) {
2598
- return type;
2599
- }
2666
+ const type = TokenTypes.literalTokens[lexeme];
2667
+ if (type) {
2668
+ return type;
2600
2669
  }
2601
2670
  return TokenTypes.none;
2602
2671
  }
2603
2672
  _match(lexeme, rule) {
2604
- if (typeof rule === "string") {
2605
- if (rule == lexeme) {
2606
- return true;
2607
- }
2608
- } else {
2609
- const match = rule.exec(lexeme);
2610
- if (match && match.index == 0 && match[0] == lexeme) {
2611
- return true;
2612
- }
2613
- }
2614
- return false;
2673
+ const match = rule.exec(lexeme);
2674
+ return match && match.index == 0 && match[0] == lexeme;
2615
2675
  }
2616
2676
  _isAtEnd() {
2617
2677
  return this._current >= this._source.length;
2618
2678
  }
2679
+ _isAlpha(c) {
2680
+ return c >= "a" && c <= "z" || c >= "A" && c <= "Z";
2681
+ }
2682
+ _isAlphaNumeric(c) {
2683
+ return c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c == "_" || c >= "0" && c <= "9";
2684
+ }
2619
2685
  _isWhitespace(c) {
2620
2686
  return c == " " || c == " " || c == "\r";
2621
2687
  }
@@ -2733,8 +2799,8 @@ void main() {
2733
2799
  const tk = this._peek();
2734
2800
  if (types instanceof Array) {
2735
2801
  const t = tk.type;
2736
- const index2 = types.indexOf(t);
2737
- return index2 != -1;
2802
+ const index = types.indexOf(t);
2803
+ return index != -1;
2738
2804
  }
2739
2805
  return tk.type == types;
2740
2806
  }
@@ -2765,6 +2831,11 @@ void main() {
2765
2831
  this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
2766
2832
  return directive;
2767
2833
  }
2834
+ if (this._match(TokenTypes.keywords.requires)) {
2835
+ const requires = this._requires_directive();
2836
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
2837
+ return requires;
2838
+ }
2768
2839
  if (this._match(TokenTypes.keywords.enable)) {
2769
2840
  const enable = this._enable_directive();
2770
2841
  this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
@@ -2871,6 +2942,9 @@ void main() {
2871
2942
  _statement() {
2872
2943
  while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
2873
2944
  ;
2945
+ if (this._check(TokenTypes.tokens.attr)) {
2946
+ this._attribute();
2947
+ }
2874
2948
  if (this._check(TokenTypes.keywords.if)) {
2875
2949
  return this._if_statement();
2876
2950
  }
@@ -2930,6 +3004,9 @@ void main() {
2930
3004
  return null;
2931
3005
  }
2932
3006
  const condition = this._optional_paren_expression();
3007
+ if (this._check(TokenTypes.tokens.attr)) {
3008
+ this._attribute();
3009
+ }
2933
3010
  const block = this._compound_statement();
2934
3011
  return new While(condition, block);
2935
3012
  }
@@ -2951,6 +3028,9 @@ void main() {
2951
3028
  this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
2952
3029
  const increment = !this._check(TokenTypes.tokens.paren_right) ? this._for_increment() : null;
2953
3030
  this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
3031
+ if (this._check(TokenTypes.tokens.attr)) {
3032
+ this._attribute();
3033
+ }
2954
3034
  const body = this._compound_statement();
2955
3035
  return new For(init, condition, increment, body);
2956
3036
  }
@@ -3048,6 +3128,9 @@ void main() {
3048
3128
  if (!this._match(TokenTypes.keywords.loop)) {
3049
3129
  return null;
3050
3130
  }
3131
+ if (this._check(TokenTypes.tokens.attr)) {
3132
+ this._attribute();
3133
+ }
3051
3134
  this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
3052
3135
  const statements = [];
3053
3136
  let statement = this._statement();
@@ -3073,6 +3156,9 @@ void main() {
3073
3156
  return null;
3074
3157
  }
3075
3158
  const condition = this._optional_paren_expression();
3159
+ if (this._check(TokenTypes.tokens.attr)) {
3160
+ this._attribute();
3161
+ }
3076
3162
  this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
3077
3163
  const body = this._switch_body();
3078
3164
  if (body == null || body.length == 0) {
@@ -3086,6 +3172,9 @@ void main() {
3086
3172
  if (this._match(TokenTypes.keywords.case)) {
3087
3173
  const selector = this._case_selectors();
3088
3174
  this._match(TokenTypes.tokens.colon);
3175
+ if (this._check(TokenTypes.tokens.attr)) {
3176
+ this._attribute();
3177
+ }
3089
3178
  this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
3090
3179
  const body = this._case_body();
3091
3180
  this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
@@ -3093,6 +3182,9 @@ void main() {
3093
3182
  }
3094
3183
  if (this._match(TokenTypes.keywords.default)) {
3095
3184
  this._match(TokenTypes.tokens.colon);
3185
+ if (this._check(TokenTypes.tokens.attr)) {
3186
+ this._attribute();
3187
+ }
3096
3188
  this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
3097
3189
  const body = this._case_body();
3098
3190
  this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
@@ -3137,13 +3229,22 @@ void main() {
3137
3229
  return null;
3138
3230
  }
3139
3231
  const condition = this._optional_paren_expression();
3232
+ if (this._check(TokenTypes.tokens.attr)) {
3233
+ this._attribute();
3234
+ }
3140
3235
  const block = this._compound_statement();
3141
3236
  let elseif = [];
3142
3237
  if (this._match_elseif()) {
3238
+ if (this._check(TokenTypes.tokens.attr)) {
3239
+ this._attribute();
3240
+ }
3143
3241
  elseif = this._elseif_statement(elseif);
3144
3242
  }
3145
3243
  let _else = null;
3146
3244
  if (this._match(TokenTypes.keywords.else)) {
3245
+ if (this._check(TokenTypes.tokens.attr)) {
3246
+ this._attribute();
3247
+ }
3147
3248
  _else = this._compound_statement();
3148
3249
  }
3149
3250
  return new If(condition, block, elseif, _else);
@@ -3161,6 +3262,9 @@ void main() {
3161
3262
  const block = this._compound_statement();
3162
3263
  elseif.push(new ElseIf(condition, block));
3163
3264
  if (this._match_elseif()) {
3265
+ if (this._check(TokenTypes.tokens.attr)) {
3266
+ this._attribute();
3267
+ }
3164
3268
  this._elseif_statement(elseif);
3165
3269
  }
3166
3270
  return elseif;
@@ -3266,25 +3370,29 @@ void main() {
3266
3370
  _singular_expression() {
3267
3371
  const expr = this._primary_expression();
3268
3372
  const p = this._postfix_expression();
3269
- if (p)
3373
+ if (p) {
3270
3374
  expr.postfix = p;
3375
+ }
3271
3376
  return expr;
3272
3377
  }
3273
3378
  _postfix_expression() {
3274
3379
  if (this._match(TokenTypes.tokens.bracket_left)) {
3275
3380
  const expr = this._short_circuit_or_expression();
3276
3381
  this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
3382
+ const arrayIndex = new ArrayIndex(expr);
3277
3383
  const p = this._postfix_expression();
3278
- if (p)
3279
- expr.postfix = p;
3280
- return expr;
3384
+ if (p) {
3385
+ arrayIndex.postfix = p;
3386
+ }
3387
+ return arrayIndex;
3281
3388
  }
3282
3389
  if (this._match(TokenTypes.tokens.period)) {
3283
3390
  const name = this._consume(TokenTypes.tokens.ident, "Expected member name.");
3284
3391
  const p = this._postfix_expression();
3285
3392
  const expr = new StringExpr(name.lexeme);
3286
- if (p)
3393
+ if (p) {
3287
3394
  expr.postfix = p;
3395
+ }
3288
3396
  return expr;
3289
3397
  }
3290
3398
  return null;
@@ -3523,6 +3631,14 @@ void main() {
3523
3631
  const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
3524
3632
  return new Enable(name.toString());
3525
3633
  }
3634
+ _requires_directive() {
3635
+ const extensions = [this._consume(TokenTypes.tokens.ident, "identity expected.").toString()];
3636
+ while (this._match(TokenTypes.tokens.comma)) {
3637
+ const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
3638
+ extensions.push(name.toString());
3639
+ }
3640
+ return new Requires(extensions);
3641
+ }
3526
3642
  _type_alias() {
3527
3643
  const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
3528
3644
  this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
@@ -3665,29 +3781,6 @@ void main() {
3665
3781
  }
3666
3782
  attributes.push(attr);
3667
3783
  }
3668
- while (this._match(TokenTypes.tokens.attr_left)) {
3669
- if (!this._check(TokenTypes.tokens.attr_right)) {
3670
- do {
3671
- const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
3672
- const attr = new Attribute(name.toString(), null);
3673
- if (this._match(TokenTypes.tokens.paren_left)) {
3674
- attr.value = [
3675
- this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString()
3676
- ];
3677
- if (this._check(TokenTypes.tokens.comma)) {
3678
- this._advance();
3679
- do {
3680
- const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
3681
- attr.value.push(v);
3682
- } while (this._match(TokenTypes.tokens.comma));
3683
- }
3684
- this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
3685
- }
3686
- attributes.push(attr);
3687
- } while (this._match(TokenTypes.tokens.comma));
3688
- }
3689
- this._consume(TokenTypes.tokens.attr_right, "Expected ']]' after attribute declarations");
3690
- }
3691
3784
  if (attributes.length == 0) {
3692
3785
  return null;
3693
3786
  }
@@ -4607,17 +4700,11 @@ void main() {
4607
4700
  printRowMajor: true,
4608
4701
  _cartographicRadians: false
4609
4702
  };
4610
- globalThis.mathgl = globalThis.mathgl || {
4611
- config: {
4612
- ...DEFAULT_CONFIG
4613
- }
4614
- };
4703
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
4615
4704
  var config = globalThis.mathgl.config;
4616
- function formatValue(value, {
4617
- precision = config.precision
4618
- } = {}) {
4705
+ function formatValue(value, { precision = config.precision } = {}) {
4619
4706
  value = round(value);
4620
- return "".concat(parseFloat(value.toPrecision(precision)));
4707
+ return `${parseFloat(value.toPrecision(precision))}`;
4621
4708
  }
4622
4709
  function isArray(value) {
4623
4710
  return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
@@ -4679,28 +4766,12 @@ void main() {
4679
4766
  }
4680
4767
 
4681
4768
  // ../../node_modules/@math.gl/core/dist/classes/base/math-array.js
4682
- function _extendableBuiltin(cls) {
4683
- function ExtendableBuiltin() {
4684
- var instance = Reflect.construct(cls, Array.from(arguments));
4685
- Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
4686
- return instance;
4687
- }
4688
- ExtendableBuiltin.prototype = Object.create(cls.prototype, {
4689
- constructor: {
4690
- value: cls,
4691
- enumerable: false,
4692
- writable: true,
4693
- configurable: true
4694
- }
4695
- });
4696
- if (Object.setPrototypeOf) {
4697
- Object.setPrototypeOf(ExtendableBuiltin, cls);
4698
- } else {
4699
- ExtendableBuiltin.__proto__ = cls;
4700
- }
4701
- return ExtendableBuiltin;
4702
- }
4703
- var MathArray = class extends _extendableBuiltin(Array) {
4769
+ var MathArray = class extends Array {
4770
+ // Common methods
4771
+ /**
4772
+ * Clone the current object
4773
+ * @returns a new copy of this object
4774
+ */
4704
4775
  clone() {
4705
4776
  return new this.constructor().copy(this);
4706
4777
  }
@@ -4720,7 +4791,10 @@ void main() {
4720
4791
  return targetObject;
4721
4792
  }
4722
4793
  from(arrayOrObject) {
4723
- return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : this.fromObject(arrayOrObject);
4794
+ return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : (
4795
+ // @ts-ignore
4796
+ this.fromObject(arrayOrObject)
4797
+ );
4724
4798
  }
4725
4799
  to(arrayOrObject) {
4726
4800
  if (arrayOrObject === this) {
@@ -4731,18 +4805,20 @@ void main() {
4731
4805
  toTarget(target) {
4732
4806
  return target ? this.to(target) : this;
4733
4807
  }
4808
+ /** @deprecated */
4734
4809
  toFloat32Array() {
4735
4810
  return new Float32Array(this);
4736
4811
  }
4737
4812
  toString() {
4738
4813
  return this.formatString(config);
4739
4814
  }
4815
+ /** Formats string according to options */
4740
4816
  formatString(opts) {
4741
4817
  let string = "";
4742
4818
  for (let i = 0; i < this.ELEMENTS; ++i) {
4743
4819
  string += (i > 0 ? ", " : "") + formatValue(this[i], opts);
4744
4820
  }
4745
- return "".concat(opts.printTypes ? this.constructor.name : "", "[").concat(string, "]");
4821
+ return `${opts.printTypes ? this.constructor.name : ""}[${string}]`;
4746
4822
  }
4747
4823
  equals(array) {
4748
4824
  if (!array || this.length !== array.length) {
@@ -4766,6 +4842,8 @@ void main() {
4766
4842
  }
4767
4843
  return true;
4768
4844
  }
4845
+ // Modifiers
4846
+ /** Negates all values in this object */
4769
4847
  negate() {
4770
4848
  for (let i = 0; i < this.ELEMENTS; ++i) {
4771
4849
  this[i] = -this[i];
@@ -4783,12 +4861,14 @@ void main() {
4783
4861
  }
4784
4862
  return this.check();
4785
4863
  }
4864
+ /** Minimal */
4786
4865
  min(vector) {
4787
4866
  for (let i = 0; i < this.ELEMENTS; ++i) {
4788
4867
  this[i] = Math.min(vector[i], this[i]);
4789
4868
  }
4790
4869
  return this.check();
4791
4870
  }
4871
+ /** Maximal */
4792
4872
  max(vector) {
4793
4873
  for (let i = 0; i < this.ELEMENTS; ++i) {
4794
4874
  this[i] = Math.max(vector[i], this[i]);
@@ -4829,18 +4909,25 @@ void main() {
4829
4909
  }
4830
4910
  return this.check();
4831
4911
  }
4912
+ /**
4913
+ * Multiplies all elements by `scale`
4914
+ * Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
4915
+ */
4832
4916
  multiplyByScalar(scalar) {
4833
4917
  for (let i = 0; i < this.ELEMENTS; ++i) {
4834
4918
  this[i] *= scalar;
4835
4919
  }
4836
4920
  return this.check();
4837
4921
  }
4922
+ // Debug checks
4923
+ /** Throws an error if array length is incorrect or contains illegal values */
4838
4924
  check() {
4839
4925
  if (config.debug && !this.validate()) {
4840
- throw new Error("math.gl: ".concat(this.constructor.name, " some fields set to invalid numbers'"));
4926
+ throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
4841
4927
  }
4842
4928
  return this;
4843
4929
  }
4930
+ /** Returns false if the array length is incorrect or contains illegal values */
4844
4931
  validate() {
4845
4932
  let valid = this.length === this.ELEMENTS;
4846
4933
  for (let i = 0; i < this.ELEMENTS; ++i) {
@@ -4848,39 +4935,48 @@ void main() {
4848
4935
  }
4849
4936
  return valid;
4850
4937
  }
4938
+ // three.js compatibility
4939
+ /** @deprecated */
4851
4940
  sub(a) {
4852
4941
  return this.subtract(a);
4853
4942
  }
4943
+ /** @deprecated */
4854
4944
  setScalar(a) {
4855
4945
  for (let i = 0; i < this.ELEMENTS; ++i) {
4856
4946
  this[i] = a;
4857
4947
  }
4858
4948
  return this.check();
4859
4949
  }
4950
+ /** @deprecated */
4860
4951
  addScalar(a) {
4861
4952
  for (let i = 0; i < this.ELEMENTS; ++i) {
4862
4953
  this[i] += a;
4863
4954
  }
4864
4955
  return this.check();
4865
4956
  }
4957
+ /** @deprecated */
4866
4958
  subScalar(a) {
4867
4959
  return this.addScalar(-a);
4868
4960
  }
4961
+ /** @deprecated */
4869
4962
  multiplyScalar(scalar) {
4870
4963
  for (let i = 0; i < this.ELEMENTS; ++i) {
4871
4964
  this[i] *= scalar;
4872
4965
  }
4873
4966
  return this.check();
4874
4967
  }
4968
+ /** @deprecated */
4875
4969
  divideScalar(a) {
4876
4970
  return this.multiplyByScalar(1 / a);
4877
4971
  }
4972
+ /** @deprecated */
4878
4973
  clampScalar(min, max) {
4879
4974
  for (let i = 0; i < this.ELEMENTS; ++i) {
4880
4975
  this[i] = Math.min(Math.max(this[i], min), max);
4881
4976
  }
4882
4977
  return this.check();
4883
4978
  }
4979
+ /** @deprecated */
4884
4980
  get elements() {
4885
4981
  return this;
4886
4982
  }
@@ -4900,13 +4996,13 @@ void main() {
4900
4996
  }
4901
4997
  function checkNumber(value) {
4902
4998
  if (!Number.isFinite(value)) {
4903
- throw new Error("Invalid number ".concat(JSON.stringify(value)));
4999
+ throw new Error(`Invalid number ${JSON.stringify(value)}`);
4904
5000
  }
4905
5001
  return value;
4906
5002
  }
4907
5003
  function checkVector(v, length, callerName = "") {
4908
5004
  if (config.debug && !validateVector(v, length)) {
4909
- throw new Error("math.gl: ".concat(callerName, " some fields set to invalid numbers'"));
5005
+ throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
4910
5006
  }
4911
5007
  return v;
4912
5008
  }
@@ -5031,19 +5127,29 @@ void main() {
5031
5127
 
5032
5128
  // ../../node_modules/@math.gl/core/dist/classes/base/matrix.js
5033
5129
  var Matrix = class extends MathArray {
5130
+ // fromObject(object) {
5131
+ // const array = object.elements;
5132
+ // return this.fromRowMajor(array);
5133
+ // }
5134
+ // toObject(object) {
5135
+ // const array = object.elements;
5136
+ // this.toRowMajor(array);
5137
+ // return object;
5138
+ // }
5139
+ // TODO better override formatString?
5034
5140
  toString() {
5035
5141
  let string = "[";
5036
5142
  if (config.printRowMajor) {
5037
5143
  string += "row-major:";
5038
5144
  for (let row = 0; row < this.RANK; ++row) {
5039
5145
  for (let col = 0; col < this.RANK; ++col) {
5040
- string += " ".concat(this[col * this.RANK + row]);
5146
+ string += ` ${this[col * this.RANK + row]}`;
5041
5147
  }
5042
5148
  }
5043
5149
  } else {
5044
5150
  string += "column-major:";
5045
5151
  for (let i = 0; i < this.ELEMENTS; ++i) {
5046
- string += " ".concat(this[i]);
5152
+ string += ` ${this[i]}`;
5047
5153
  }
5048
5154
  }
5049
5155
  string += "]";
@@ -5052,9 +5158,11 @@ void main() {
5052
5158
  getElementIndex(row, col) {
5053
5159
  return col * this.RANK + row;
5054
5160
  }
5161
+ // By default assumes row major indices
5055
5162
  getElement(row, col) {
5056
5163
  return this[col * this.RANK + row];
5057
5164
  }
5165
+ // By default assumes row major indices
5058
5166
  setElement(row, col, value) {
5059
5167
  this[col * this.RANK + row] = checkNumber(value);
5060
5168
  return this;
@@ -5820,6 +5928,7 @@ void main() {
5820
5928
  this[15] = array[15];
5821
5929
  return this.check();
5822
5930
  }
5931
+ // eslint-disable-next-line max-params
5823
5932
  set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
5824
5933
  this[0] = m00;
5825
5934
  this[1] = m10;
@@ -5839,6 +5948,8 @@ void main() {
5839
5948
  this[15] = m33;
5840
5949
  return this.check();
5841
5950
  }
5951
+ // accepts row major order, stores as column major
5952
+ // eslint-disable-next-line max-params
5842
5953
  setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
5843
5954
  this[0] = m00;
5844
5955
  this[1] = m10;
@@ -5877,25 +5988,41 @@ void main() {
5877
5988
  result[15] = this[15];
5878
5989
  return result;
5879
5990
  }
5991
+ // Constructors
5992
+ /** Set to identity matrix */
5880
5993
  identity() {
5881
5994
  return this.copy(IDENTITY_MATRIX);
5882
5995
  }
5996
+ /**
5997
+ *
5998
+ * @param object
5999
+ * @returns self
6000
+ */
6001
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5883
6002
  fromObject(object) {
5884
6003
  return this.check();
5885
6004
  }
6005
+ /**
6006
+ * Calculates a 4x4 matrix from the given quaternion
6007
+ * @param quaternion Quaternion to create matrix from
6008
+ * @returns self
6009
+ */
5886
6010
  fromQuaternion(quaternion) {
5887
6011
  fromQuat(this, quaternion);
5888
6012
  return this.check();
5889
6013
  }
6014
+ /**
6015
+ * Generates a frustum matrix with the given bounds
6016
+ * @param view.left - Left bound of the frustum
6017
+ * @param view.right - Right bound of the frustum
6018
+ * @param view.bottom - Bottom bound of the frustum
6019
+ * @param view.top - Top bound of the frustum
6020
+ * @param view.near - Near bound of the frustum
6021
+ * @param view.far - Far bound of the frustum. Can be set to Infinity.
6022
+ * @returns self
6023
+ */
5890
6024
  frustum(view) {
5891
- const {
5892
- left,
5893
- right,
5894
- bottom,
5895
- top,
5896
- near = DEFAULT_NEAR,
5897
- far = DEFAULT_FAR
5898
- } = view;
6025
+ const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
5899
6026
  if (far === Infinity) {
5900
6027
  computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
5901
6028
  } else {
@@ -5903,35 +6030,47 @@ void main() {
5903
6030
  }
5904
6031
  return this.check();
5905
6032
  }
6033
+ /**
6034
+ * Generates a look-at matrix with the given eye position, focal point,
6035
+ * and up axis
6036
+ * @param view.eye - (vector) Position of the viewer
6037
+ * @param view.center - (vector) Point the viewer is looking at
6038
+ * @param view.up - (vector) Up axis
6039
+ * @returns self
6040
+ */
5906
6041
  lookAt(view) {
5907
- const {
5908
- eye,
5909
- center = [0, 0, 0],
5910
- up = [0, 1, 0]
5911
- } = view;
6042
+ const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
5912
6043
  lookAt(this, eye, center, up);
5913
6044
  return this.check();
5914
6045
  }
6046
+ /**
6047
+ * Generates a orthogonal projection matrix with the given bounds
6048
+ * from "traditional" view space parameters
6049
+ * @param view.left - Left bound of the frustum
6050
+ * @param view.right number Right bound of the frustum
6051
+ * @param view.bottom - Bottom bound of the frustum
6052
+ * @param view.top number Top bound of the frustum
6053
+ * @param view.near - Near bound of the frustum
6054
+ * @param view.far number Far bound of the frustum
6055
+ * @returns self
6056
+ */
5915
6057
  ortho(view) {
5916
- const {
5917
- left,
5918
- right,
5919
- bottom,
5920
- top,
5921
- near = DEFAULT_NEAR,
5922
- far = DEFAULT_FAR
5923
- } = view;
6058
+ const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
5924
6059
  ortho(this, left, right, bottom, top, near, far);
5925
6060
  return this.check();
5926
6061
  }
6062
+ /**
6063
+ * Generates an orthogonal projection matrix with the same parameters
6064
+ * as a perspective matrix (plus focalDistance)
6065
+ * @param view.fovy Vertical field of view in radians
6066
+ * @param view.aspect Aspect ratio. Typically viewport width / viewport height
6067
+ * @param view.focalDistance Distance in the view frustum used for extent calculations
6068
+ * @param view.near Near bound of the frustum
6069
+ * @param view.far Far bound of the frustum
6070
+ * @returns self
6071
+ */
5927
6072
  orthographic(view) {
5928
- const {
5929
- fovy = DEFAULT_FOVY,
5930
- aspect = DEFAULT_ASPECT,
5931
- focalDistance = 1,
5932
- near = DEFAULT_NEAR,
5933
- far = DEFAULT_FAR
5934
- } = view;
6073
+ const { fovy = DEFAULT_FOVY, aspect = DEFAULT_ASPECT, focalDistance = 1, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
5935
6074
  checkRadians(fovy);
5936
6075
  const halfY = fovy / 2;
5937
6076
  const top = focalDistance * Math.tan(halfY);
@@ -5945,32 +6084,53 @@ void main() {
5945
6084
  far
5946
6085
  });
5947
6086
  }
6087
+ /**
6088
+ * Generates a perspective projection matrix with the given bounds
6089
+ * @param view.fovy Vertical field of view in radians
6090
+ * @param view.aspect Aspect ratio. typically viewport width/height
6091
+ * @param view.near Near bound of the frustum
6092
+ * @param view.far Far bound of the frustum
6093
+ * @returns self
6094
+ */
5948
6095
  perspective(view) {
5949
- const {
5950
- fovy = 45 * Math.PI / 180,
5951
- aspect = 1,
5952
- near = 0.1,
5953
- far = 500
5954
- } = view;
6096
+ const { fovy = 45 * Math.PI / 180, aspect = 1, near = 0.1, far = 500 } = view;
5955
6097
  checkRadians(fovy);
5956
6098
  perspective(this, fovy, aspect, near, far);
5957
6099
  return this.check();
5958
6100
  }
6101
+ // Accessors
5959
6102
  determinant() {
5960
6103
  return determinant(this);
5961
6104
  }
6105
+ /**
6106
+ * Extracts the non-uniform scale assuming the matrix is an affine transformation.
6107
+ * The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
6108
+ * @param result
6109
+ * @returns self
6110
+ */
5962
6111
  getScale(result = [-0, -0, -0]) {
5963
6112
  result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
5964
6113
  result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
5965
6114
  result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
5966
6115
  return result;
5967
6116
  }
6117
+ /**
6118
+ * Gets the translation portion, assuming the matrix is a affine transformation matrix.
6119
+ * @param result
6120
+ * @returns self
6121
+ */
5968
6122
  getTranslation(result = [-0, -0, -0]) {
5969
6123
  result[0] = this[12];
5970
6124
  result[1] = this[13];
5971
6125
  result[2] = this[14];
5972
6126
  return result;
5973
6127
  }
6128
+ /**
6129
+ * Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
6130
+ * @param result
6131
+ * @param scaleResult
6132
+ * @returns self
6133
+ */
5974
6134
  getRotation(result, scaleResult) {
5975
6135
  result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
5976
6136
  scaleResult = scaleResult || [-0, -0, -0];
@@ -5996,6 +6156,12 @@ void main() {
5996
6156
  result[15] = 1;
5997
6157
  return result;
5998
6158
  }
6159
+ /**
6160
+ *
6161
+ * @param result
6162
+ * @param scaleResult
6163
+ * @returns self
6164
+ */
5999
6165
  getRotationMatrix3(result, scaleResult) {
6000
6166
  result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
6001
6167
  scaleResult = scaleResult || [-0, -0, -0];
@@ -6014,6 +6180,7 @@ void main() {
6014
6180
  result[8] = this[10] * inverseScale2;
6015
6181
  return result;
6016
6182
  }
6183
+ // Modifiers
6017
6184
  transpose() {
6018
6185
  transpose(this, this);
6019
6186
  return this.check();
@@ -6022,6 +6189,7 @@ void main() {
6022
6189
  invert(this, this);
6023
6190
  return this.check();
6024
6191
  }
6192
+ // Operations
6025
6193
  multiplyLeft(a) {
6026
6194
  multiply(this, a, this);
6027
6195
  return this.check();
@@ -6030,33 +6198,68 @@ void main() {
6030
6198
  multiply(this, this, a);
6031
6199
  return this.check();
6032
6200
  }
6201
+ // Rotates a matrix by the given angle around the X axis
6033
6202
  rotateX(radians2) {
6034
6203
  rotateX(this, this, radians2);
6035
6204
  return this.check();
6036
6205
  }
6206
+ // Rotates a matrix by the given angle around the Y axis.
6037
6207
  rotateY(radians2) {
6038
6208
  rotateY(this, this, radians2);
6039
6209
  return this.check();
6040
6210
  }
6211
+ /**
6212
+ * Rotates a matrix by the given angle around the Z axis.
6213
+ * @param radians
6214
+ * @returns self
6215
+ */
6041
6216
  rotateZ(radians2) {
6042
6217
  rotateZ(this, this, radians2);
6043
6218
  return this.check();
6044
6219
  }
6220
+ /**
6221
+ *
6222
+ * @param param0
6223
+ * @returns self
6224
+ */
6045
6225
  rotateXYZ(angleXYZ) {
6046
6226
  return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
6047
6227
  }
6228
+ /**
6229
+ *
6230
+ * @param radians
6231
+ * @param axis
6232
+ * @returns self
6233
+ */
6048
6234
  rotateAxis(radians2, axis) {
6049
6235
  rotate(this, this, radians2, axis);
6050
6236
  return this.check();
6051
6237
  }
6238
+ /**
6239
+ *
6240
+ * @param factor
6241
+ * @returns self
6242
+ */
6052
6243
  scale(factor) {
6053
6244
  scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
6054
6245
  return this.check();
6055
6246
  }
6247
+ /**
6248
+ *
6249
+ * @param vec
6250
+ * @returns self
6251
+ */
6056
6252
  translate(vector) {
6057
6253
  translate(this, this, vector);
6058
6254
  return this.check();
6059
6255
  }
6256
+ // Transforms
6257
+ /**
6258
+ * Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
6259
+ * @param vector
6260
+ * @param result
6261
+ * @returns self
6262
+ */
6060
6263
  transform(vector, result) {
6061
6264
  if (vector.length === 4) {
6062
6265
  result = transformMat43(result || [-0, -0, -0, -0], vector, this);
@@ -6065,10 +6268,14 @@ void main() {
6065
6268
  }
6066
6269
  return this.transformAsPoint(vector, result);
6067
6270
  }
6271
+ /**
6272
+ * Transforms any 2 or 3 element array as point (w implicitly 1)
6273
+ * @param vector
6274
+ * @param result
6275
+ * @returns self
6276
+ */
6068
6277
  transformAsPoint(vector, result) {
6069
- const {
6070
- length
6071
- } = vector;
6278
+ const { length } = vector;
6072
6279
  let out;
6073
6280
  switch (length) {
6074
6281
  case 2:
@@ -6083,6 +6290,12 @@ void main() {
6083
6290
  checkVector(out, vector.length);
6084
6291
  return out;
6085
6292
  }
6293
+ /**
6294
+ * Transforms any 2 or 3 element array as vector (w implicitly 0)
6295
+ * @param vector
6296
+ * @param result
6297
+ * @returns self
6298
+ */
6086
6299
  transformAsVector(vector, result) {
6087
6300
  let out;
6088
6301
  switch (vector.length) {
@@ -6098,15 +6311,19 @@ void main() {
6098
6311
  checkVector(out, vector.length);
6099
6312
  return out;
6100
6313
  }
6314
+ /** @deprecated */
6101
6315
  transformPoint(vector, result) {
6102
6316
  return this.transformAsPoint(vector, result);
6103
6317
  }
6318
+ /** @deprecated */
6104
6319
  transformVector(vector, result) {
6105
6320
  return this.transformAsPoint(vector, result);
6106
6321
  }
6322
+ /** @deprecated */
6107
6323
  transformDirection(vector, result) {
6108
6324
  return this.transformAsVector(vector, result);
6109
6325
  }
6326
+ // three.js math API compatibility
6110
6327
  makeRotationX(radians2) {
6111
6328
  return this.identity().rotateX(radians2);
6112
6329
  }
@@ -6262,28 +6479,31 @@ void main() {
6262
6479
  const matrixFP64 = new Float32Array(32);
6263
6480
  for (let i = 0; i < 4; ++i) {
6264
6481
  for (let j = 0; j < 4; ++j) {
6265
- const index2 = i * 4 + j;
6266
- fp64ify(matrix[j * 4 + i], matrixFP64, index2 * 2);
6482
+ const index = i * 4 + j;
6483
+ fp64ify(matrix[j * 4 + i], matrixFP64, index * 2);
6267
6484
  }
6268
6485
  }
6269
6486
  return matrixFP64;
6270
6487
  }
6271
6488
 
6272
6489
  // src/modules/math/random/random.ts
6273
- var fs = glsl`\
6274
- float random(vec3 scale, float seed) {
6490
+ var fs = (
6491
+ /* glsl */
6492
+ `float random(vec3 scale, float seed) {
6275
6493
  /* use the fragment position for a different seed per-pixel */
6276
6494
  return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
6277
6495
  }
6278
- `;
6496
+ `
6497
+ );
6279
6498
  var random = {
6280
6499
  name: "random",
6281
6500
  fs
6282
6501
  };
6283
6502
 
6284
6503
  // src/modules/math/fp32/fp32.ts
6285
- var fp32shader = glsl`\
6286
- #ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
6504
+ var fp32shader = (
6505
+ /* glsl */
6506
+ `#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
6287
6507
 
6288
6508
  // All these functions are for substituting tan() function from Intel GPU only
6289
6509
  const float TWO_PI = 6.2831854820251465;
@@ -6433,7 +6653,8 @@ float tan_fp32(float a) {
6433
6653
  return tan(a);
6434
6654
  #endif
6435
6655
  }
6436
- `;
6656
+ `
6657
+ );
6437
6658
  var fp32 = {
6438
6659
  name: "fp32",
6439
6660
  vs: fp32shader
@@ -6441,8 +6662,9 @@ float tan_fp32(float a) {
6441
6662
 
6442
6663
  // src/modules/engine/picking/picking.ts
6443
6664
  var DEFAULT_HIGHLIGHT_COLOR = new Float32Array([0, 1, 1, 1]);
6444
- var vs = glsl`\
6445
- uniform pickingUniforms {
6665
+ var vs = (
6666
+ /* glsl */
6667
+ `uniform pickingUniforms {
6446
6668
  float isActive;
6447
6669
  float isAttribute;
6448
6670
  float isHighlightActive;
@@ -6513,9 +6735,11 @@ void picking_setPickingAttribute(vec3 value) {
6513
6735
  picking_vRGBcolor_Avalid.rgb = value;
6514
6736
  }
6515
6737
  }
6516
- `;
6517
- var fs2 = glsl`\
6518
- uniform pickingUniforms {
6738
+ `
6739
+ );
6740
+ var fs2 = (
6741
+ /* glsl */
6742
+ `uniform pickingUniforms {
6519
6743
  float isActive;
6520
6744
  float isAttribute;
6521
6745
  float isHighlightActive;
@@ -6571,8 +6795,11 @@ vec4 picking_filterColor(vec4 color) {
6571
6795
  vec4 highlightColor = picking_filterHighlightColor(color);
6572
6796
  return picking_filterPickingColor(highlightColor);
6573
6797
  }
6574
- `;
6798
+ `
6799
+ );
6575
6800
  var picking = {
6801
+ props: {},
6802
+ uniforms: {},
6576
6803
  name: "picking",
6577
6804
  uniformTypes: {
6578
6805
  isActive: "f32",
@@ -6592,8 +6819,6 @@ vec4 picking_filterColor(vec4 color) {
6592
6819
  },
6593
6820
  vs,
6594
6821
  fs: fs2,
6595
- props: {},
6596
- uniforms: {},
6597
6822
  getUniforms
6598
6823
  };
6599
6824
  function getUniforms(opts = {}, prevUniforms) {
@@ -6624,8 +6849,9 @@ vec4 picking_filterColor(vec4 color) {
6624
6849
  }
6625
6850
 
6626
6851
  // src/modules/lighting/lights/lighting-uniforms-glsl.ts
6627
- var lightingUniforms = glsl`\
6628
- precision highp int;
6852
+ var lightingUniformsGLSL = (
6853
+ /* glsl */
6854
+ `precision highp int;
6629
6855
 
6630
6856
  // #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
6631
6857
  struct AmbientLight {
@@ -6676,12 +6902,72 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
6676
6902
  }
6677
6903
 
6678
6904
  // #endif
6679
- `;
6905
+ `
6906
+ );
6907
+
6908
+ // src/modules/lighting/lights/lighting-uniforms-wgsl.ts
6909
+ var lightingUniformsWGSL = (
6910
+ /* wgsl */
6911
+ `// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
6912
+ struct AmbientLight {
6913
+ color: vec3<f32>,
6914
+ };
6915
+
6916
+ struct PointLight {
6917
+ color: vec3<f32>,
6918
+ position: vec3<f32>,
6919
+ attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
6920
+ };
6921
+
6922
+ struct DirectionalLight {
6923
+ color: vec3<f32>,
6924
+ direction: vec3<f32>,
6925
+ };
6926
+
6927
+ struct lightingUniforms {
6928
+ enabled: i32,
6929
+ poightCount: i32,
6930
+ directionalLightCount: i32,
6931
+
6932
+ ambientColor: vec3<f32>,
6933
+
6934
+ // TODO - support multiple lights by uncommenting arrays below
6935
+ lightType: i32,
6936
+ lightColor: vec3<f32>,
6937
+ lightDirection: vec3<f32>,
6938
+ lightPosition: vec3<f32>,
6939
+ lightAttenuation: vec3<f32>,
6940
+
6941
+ // AmbientLight ambientLight;
6942
+ // PointLight pointLight[MAX_LIGHTS];
6943
+ // DirectionalLight directionalLight[MAX_LIGHTS];
6944
+ };
6945
+
6946
+ // Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)
6947
+ @binding(1) @group(0) var<uniform> lighting : lightingUniforms;
6948
+
6949
+ fn lighting_getPointLight(index: i32) -> PointLight {
6950
+ return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
6951
+ }
6952
+
6953
+ fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
6954
+ return DirectionalLight(lighting.lightColor, lighting.lightDirection);
6955
+ }
6956
+
6957
+ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
6958
+ return pointLight.attenuation.x
6959
+ + pointLight.attenuation.y * distance
6960
+ + pointLight.attenuation.z * distance * distance;
6961
+ }
6962
+ `
6963
+ );
6680
6964
 
6681
6965
  // src/modules/lighting/lights/lighting.ts
6682
6966
  var MAX_LIGHTS = 5;
6683
6967
  var COLOR_FACTOR = 255;
6684
6968
  var lighting = {
6969
+ props: {},
6970
+ uniforms: {},
6685
6971
  name: "lighting",
6686
6972
  defines: {
6687
6973
  MAX_LIGHTS
@@ -6714,10 +7000,9 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
6714
7000
  lightDirection: [1, 1, 1],
6715
7001
  lightAttenuation: [1, 1, 1]
6716
7002
  },
6717
- vs: lightingUniforms,
6718
- fs: lightingUniforms,
6719
- props: {},
6720
- uniforms: {},
7003
+ source: lightingUniformsWGSL,
7004
+ vs: lightingUniformsGLSL,
7005
+ fs: lightingUniformsGLSL,
6721
7006
  getUniforms: getUniforms2
6722
7007
  };
6723
7008
  function getUniforms2(props, prevUniforms = {}) {
@@ -6798,15 +7083,48 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
6798
7083
  }
6799
7084
 
6800
7085
  // src/modules/lighting/no-material/dirlight.ts
6801
- var VS_GLSL = glsl`\
6802
- out vec3 dirlight_vNormal;
7086
+ var SOURCE_WGSL = (
7087
+ /* WGSL */
7088
+ `
7089
+ struct dirlightUniforms {
7090
+ lightDirection: vec3<f32>,
7091
+ };
7092
+
7093
+ alias DirlightNormal = vec3<f32>;
7094
+
7095
+ struct DirlightInputs {
7096
+ normal: DirlightNormal,
7097
+ };
7098
+
7099
+ @binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;
7100
+
7101
+ // For vertex
7102
+ fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {
7103
+ return normalize(normal);
7104
+ }
7105
+
7106
+ // Returns color attenuated by angle from light source
7107
+ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
7108
+ // TODO - fix default light direction
7109
+ // let lightDirection = dirlight.lightDirection;
7110
+ let lightDirection = vec3<f32>(1, 1, 1);
7111
+ let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
7112
+ return vec4<f32>(color.rgb * d, color.a);
7113
+ }
7114
+ `
7115
+ );
7116
+ var VS_GLSL = (
7117
+ /* glsl */
7118
+ `out vec3 dirlight_vNormal;
6803
7119
 
6804
7120
  void dirlight_setNormal(vec3 normal) {
6805
7121
  dirlight_vNormal = normalize(normal);
6806
7122
  }
6807
- `;
6808
- var FS_GLSL = glsl`\
6809
- uniform dirlightUniforms {
7123
+ `
7124
+ );
7125
+ var FS_GLSL = (
7126
+ /* glsl */
7127
+ `uniform dirlightUniforms {
6810
7128
  vec3 lightDirection;
6811
7129
  } dirlight;
6812
7130
 
@@ -6817,10 +7135,14 @@ vec4 dirlight_filterColor(vec4 color) {
6817
7135
  float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
6818
7136
  return vec4(color.rgb * d, color.a);
6819
7137
  }
6820
- `;
7138
+ `
7139
+ );
6821
7140
  var dirlight = {
7141
+ props: {},
7142
+ uniforms: {},
6822
7143
  name: "dirlight",
6823
7144
  dependencies: [],
7145
+ source: SOURCE_WGSL,
6824
7146
  vs: VS_GLSL,
6825
7147
  fs: FS_GLSL,
6826
7148
  // fragmentInputs: [
@@ -6835,8 +7157,6 @@ vec4 dirlight_filterColor(vec4 color) {
6835
7157
  defaultUniforms: {
6836
7158
  lightDirection: new Float32Array([1, 1, 2])
6837
7159
  },
6838
- props: {},
6839
- uniforms: {},
6840
7160
  getUniforms: getUniforms3
6841
7161
  };
6842
7162
  function getUniforms3(opts = dirlight.defaultUniforms) {
@@ -6848,16 +7168,19 @@ vec4 dirlight_filterColor(vec4 color) {
6848
7168
  }
6849
7169
 
6850
7170
  // src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts
6851
- var GOURAUD_VS = glsl`\
6852
- uniform materialUniforms {
7171
+ var GOURAUD_VS = (
7172
+ /* glsl */
7173
+ `uniform materialUniforms {
6853
7174
  uniform float ambient;
6854
7175
  uniform float diffuse;
6855
7176
  uniform float shininess;
6856
7177
  uniform vec3 specularColor;
6857
7178
  } material;
6858
- `;
6859
- var GOURAUD_FS = glsl`\
6860
- uniform materialUniforms {
7179
+ `
7180
+ );
7181
+ var GOURAUD_FS = (
7182
+ /* glsl */
7183
+ `uniform materialUniforms {
6861
7184
  uniform float ambient;
6862
7185
  uniform float diffuse;
6863
7186
  uniform float shininess;
@@ -6938,10 +7261,13 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
6938
7261
  }
6939
7262
  return lightColor;
6940
7263
  }
6941
- `;
7264
+ `
7265
+ );
6942
7266
 
6943
7267
  // src/modules/lighting/gouraud-material/gouraud-material.ts
6944
7268
  var gouraudMaterial = {
7269
+ props: {},
7270
+ uniforms: {},
6945
7271
  name: "gouraud-lighting",
6946
7272
  // Note these are switched between phong and gouraud
6947
7273
  vs: GOURAUD_VS,
@@ -6967,17 +7293,111 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
6967
7293
  }
6968
7294
  };
6969
7295
 
7296
+ // src/modules/lighting/phong-material/phong-shaders-wgsl.ts
7297
+ var PHONG_WGSL = (
7298
+ /* wgsl */
7299
+ `struct phongMaterialUniforms {
7300
+ ambient: f32,
7301
+ diffuse: f32,
7302
+ shininess: f32,
7303
+ specularColor: vec3<f32>,
7304
+ };
7305
+
7306
+ @binding(2) @group(0) var<uniform> material : phongMaterialUniforms;
7307
+
7308
+ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
7309
+ let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
7310
+ var lambertian: f32 = dot(light_direction, normal_worldspace);
7311
+ var specular: f32 = 0.0;
7312
+ if (lambertian > 0.0) {
7313
+ let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
7314
+ specular = pow(specular_angle, material.shininess);
7315
+ }
7316
+ lambertian = max(lambertian, 0.0);
7317
+ return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
7318
+ }
7319
+
7320
+ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
7321
+ var lightColor: vec3<f32> = surfaceColor;
7322
+
7323
+ if (lighting.enabled == 0) {
7324
+ return lightColor;
7325
+ }
7326
+
7327
+ let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
7328
+ lightColor = material.ambient * surfaceColor * lighting.ambientColor;
7329
+
7330
+ if (lighting.lightType == 0) {
7331
+ let pointLight: PointLight = lighting_getPointLight(0);
7332
+ let light_position_worldspace: vec3<f32> = pointLight.position;
7333
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
7334
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7335
+ } else if (lighting.lightType == 1) {
7336
+ var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
7337
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7338
+ }
7339
+
7340
+ return lightColor;
7341
+ /*
7342
+ for (int i = 0; i < MAX_LIGHTS; i++) {
7343
+ if (i >= lighting.pointLightCount) {
7344
+ break;
7345
+ }
7346
+ PointLight pointLight = lighting.pointLight[i];
7347
+ vec3 light_position_worldspace = pointLight.position;
7348
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
7349
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7350
+ }
7351
+
7352
+ for (int i = 0; i < MAX_LIGHTS; i++) {
7353
+ if (i >= lighting.directionalLightCount) {
7354
+ break;
7355
+ }
7356
+ DirectionalLight directionalLight = lighting.directionalLight[i];
7357
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7358
+ }
7359
+ */
7360
+ }
7361
+
7362
+ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{
7363
+ var lightColor = vec3<f32>(0, 0, 0);
7364
+ let surfaceColor = vec3<f32>(0, 0, 0);
7365
+
7366
+ if (lighting.enabled == 0) {
7367
+ let view_direction = normalize(cameraPosition - position_worldspace);
7368
+
7369
+ switch (lighting.lightType) {
7370
+ case 0, default: {
7371
+ let pointLight: PointLight = lighting_getPointLight(0);
7372
+ let light_position_worldspace: vec3<f32> = pointLight.position;
7373
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
7374
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7375
+ }
7376
+ case 1: {
7377
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
7378
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7379
+ }
7380
+ }
7381
+ }
7382
+ return lightColor;
7383
+ }
7384
+ `
7385
+ );
7386
+
6970
7387
  // src/modules/lighting/phong-material/phong-shaders-glsl.ts
6971
- var PHONG_VS = glsl`\
6972
- uniform phongMaterialUniforms {
7388
+ var PHONG_VS = (
7389
+ /* glsl */
7390
+ `uniform phongMaterialUniforms {
6973
7391
  uniform float ambient;
6974
7392
  uniform float diffuse;
6975
7393
  uniform float shininess;
6976
7394
  uniform vec3 specularColor;
6977
7395
  } material;
6978
- `;
6979
- var PHONG_FS = glsl`\
6980
- uniform phongMaterialUniforms {
7396
+ `
7397
+ );
7398
+ var PHONG_FS = (
7399
+ /* glsl */
7400
+ `uniform phongMaterialUniforms {
6981
7401
  uniform float ambient;
6982
7402
  uniform float diffuse;
6983
7403
  uniform float shininess;
@@ -7061,18 +7481,22 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
7061
7481
  }
7062
7482
  return lightColor;
7063
7483
  }
7064
- `;
7484
+ `
7485
+ );
7065
7486
 
7066
7487
  // src/modules/lighting/phong-material/phong-material.ts
7067
7488
  var phongMaterial = {
7489
+ props: {},
7490
+ uniforms: {},
7068
7491
  name: "phong-lighting",
7492
+ dependencies: [lighting],
7069
7493
  // Note these are switched between phong and gouraud
7494
+ source: PHONG_WGSL,
7070
7495
  vs: PHONG_VS,
7071
7496
  fs: PHONG_FS,
7072
7497
  defines: {
7073
7498
  LIGHTING_FRAGMENT: 1
7074
7499
  },
7075
- dependencies: [lighting],
7076
7500
  uniformTypes: {
7077
7501
  ambient: "f32",
7078
7502
  diffuse: "f32",
@@ -7085,16 +7509,15 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
7085
7509
  shininess: 32,
7086
7510
  specularColor: [0.15, 0.15, 0.15]
7087
7511
  },
7088
- props: {},
7089
- uniforms: {},
7090
7512
  getUniforms(props) {
7091
7513
  return { ...phongMaterial.defaultUniforms, ...props };
7092
7514
  }
7093
7515
  };
7094
7516
 
7095
7517
  // src/modules/lighting/pbr-material/pbr-vertex-glsl.ts
7096
- var vs2 = glsl`\
7097
- uniform projection {
7518
+ var vs2 = (
7519
+ /* glsl */
7520
+ `uniform projection {
7098
7521
  mat4 u_MVPMatrix;
7099
7522
  mat4 u_ModelMatrix;
7100
7523
  mat4 u_NormalMatrix;
@@ -7135,11 +7558,13 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
7135
7558
  pbr_vUV = vec2(0.,0.);
7136
7559
  #endif
7137
7560
  }
7138
- `;
7561
+ `
7562
+ );
7139
7563
 
7140
7564
  // src/modules/lighting/pbr-material/pbr-fragment-glsl.ts
7141
- var fs3 = glsl`\
7142
- precision highp float;
7565
+ var fs3 = (
7566
+ /* glsl */
7567
+ `precision highp float;
7143
7568
 
7144
7569
  uniform Projection {
7145
7570
  // Projection
@@ -7544,11 +7969,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
7544
7969
 
7545
7970
  return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
7546
7971
  }
7547
- `;
7972
+ `
7973
+ );
7548
7974
 
7549
7975
  // src/modules/lighting/pbr-material/pbr-material.ts
7550
7976
  var pbrMaterial = {
7977
+ props: {},
7978
+ uniforms: {},
7551
7979
  name: "pbr",
7980
+ dependencies: [lighting],
7552
7981
  vs: vs2,
7553
7982
  fs: fs3,
7554
7983
  defines: {
@@ -7609,13 +8038,13 @@ vec4 pbr_filterColor(vec4 colorUnused)
7609
8038
  // #ifdef USE_IBL (samplerCube)
7610
8039
  brdfLUT: { type: "texture", location: 15 }
7611
8040
  // #ifdef USE_IBL
7612
- },
7613
- dependencies: [lighting]
8041
+ }
7614
8042
  };
7615
8043
 
7616
8044
  // src/modules/postprocessing/image-adjust-filters/brightnesscontrast.ts
7617
- var fs4 = glsl`\
7618
-
8045
+ var fs4 = (
8046
+ /* glsl */
8047
+ `
7619
8048
  uniform brightnessContrastUniforms {
7620
8049
  float brightness;
7621
8050
  float contrast;
@@ -7634,8 +8063,11 @@ vec4 brightnessContrast_filterColor(vec4 color) {
7634
8063
  vec4 brightnessContrast_filterColor(vec4 color, vec2 texSize, vec2 texCoords) {
7635
8064
  return brightnessContrast_filterColor(color);
7636
8065
  }
7637
- `;
8066
+ `
8067
+ );
7638
8068
  var brightnessContrast = {
8069
+ props: {},
8070
+ uniforms: {},
7639
8071
  name: "brightnessContrast",
7640
8072
  uniformTypes: {
7641
8073
  brightness: "f32",
@@ -7650,8 +8082,9 @@ vec4 brightnessContrast_filterColor(vec4 color, vec2 texSize, vec2 texCoords) {
7650
8082
  };
7651
8083
 
7652
8084
  // src/modules/postprocessing/image-adjust-filters/denoise.ts
7653
- var fs5 = glsl`\
7654
- uniform denoiseUniforms {
8085
+ var fs5 = (
8086
+ /* glsl */
8087
+ `uniform denoiseUniforms {
7655
8088
  float strength;
7656
8089
  } noise;
7657
8090
 
@@ -7673,8 +8106,11 @@ vec4 denoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
7673
8106
 
7674
8107
  return color / total;
7675
8108
  }
7676
- `;
8109
+ `
8110
+ );
7677
8111
  var denoise = {
8112
+ props: {},
8113
+ uniforms: {},
7678
8114
  name: "denoise",
7679
8115
  uniformTypes: {
7680
8116
  strength: "f32"
@@ -7688,8 +8124,9 @@ vec4 denoise_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
7688
8124
  };
7689
8125
 
7690
8126
  // src/modules/postprocessing/image-adjust-filters/huesaturation.ts
7691
- var fs6 = glsl`\
7692
- uniform hueSaturationUniforms {
8127
+ var fs6 = (
8128
+ /* glsl */
8129
+ `uniform hueSaturationUniforms {
7693
8130
  float hue;
7694
8131
  float saturation;
7695
8132
  } hueSaturation;
@@ -7720,9 +8157,13 @@ vec4 hueSaturation_filterColor(vec4 color) {
7720
8157
  vec4 hueSaturation_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7721
8158
  return hueSaturation_filterColor(color);
7722
8159
  }
7723
- `;
8160
+ `
8161
+ );
7724
8162
  var hueSaturation = {
8163
+ props: {},
8164
+ uniforms: {},
7725
8165
  name: "hueSaturation",
8166
+ fs: fs6,
7726
8167
  uniformTypes: {
7727
8168
  hue: "f32",
7728
8169
  saturation: "f32"
@@ -7731,13 +8172,13 @@ vec4 hueSaturation_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7731
8172
  hue: { value: 0, min: -1, max: 1 },
7732
8173
  saturation: { value: 0, min: -1, max: 1 }
7733
8174
  },
7734
- fs: fs6,
7735
8175
  passes: [{ filter: true }]
7736
8176
  };
7737
8177
 
7738
8178
  // src/modules/postprocessing/image-adjust-filters/noise.ts
7739
- var fs7 = glsl`\
7740
- uniform noiseUniforms {
8179
+ var fs7 = (
8180
+ /* glsl */
8181
+ `uniform noiseUniforms {
7741
8182
  float amount;
7742
8183
  } noise;
7743
8184
 
@@ -7756,8 +8197,11 @@ vec4 noise_filterColor(vec4 color, vec2 texCoord) {
7756
8197
  vec4 noise_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7757
8198
  return noise_filterColor(color, texCoord);
7758
8199
  }
7759
- `;
8200
+ `
8201
+ );
7760
8202
  var noise = {
8203
+ props: {},
8204
+ uniforms: {},
7761
8205
  name: "noise",
7762
8206
  uniformTypes: {
7763
8207
  amount: "f32"
@@ -7770,8 +8214,9 @@ vec4 noise_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7770
8214
  };
7771
8215
 
7772
8216
  // src/modules/postprocessing/image-adjust-filters/sepia.ts
7773
- var fs8 = glsl`\
7774
- uniform sepiaUniforms {
8217
+ var fs8 = (
8218
+ /* glsl */
8219
+ `uniform sepiaUniforms {
7775
8220
  float amount;
7776
8221
  } sepia;
7777
8222
 
@@ -7791,8 +8236,11 @@ vec4 sepia_filterColor(vec4 color) {
7791
8236
  vec4 sepia_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7792
8237
  return sepia_filterColor(color);
7793
8238
  }
7794
- `;
8239
+ `
8240
+ );
7795
8241
  var sepia = {
8242
+ props: {},
8243
+ uniforms: {},
7796
8244
  name: "sepia",
7797
8245
  uniformTypes: {
7798
8246
  amount: "f32"
@@ -7805,8 +8253,9 @@ vec4 sepia_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7805
8253
  };
7806
8254
 
7807
8255
  // src/modules/postprocessing/image-adjust-filters/vibrance.ts
7808
- var fs9 = glsl`\
7809
- uniform vibranceUniforms {
8256
+ var fs9 = (
8257
+ /* glsl */
8258
+ `uniform vibranceUniforms {
7810
8259
  float amount;
7811
8260
  } vibrance;
7812
8261
 
@@ -7821,8 +8270,11 @@ vec4 vibrance_filterColor(vec4 color) {
7821
8270
  vec4 vibrance_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7822
8271
  return vibrance_filterColor(color);
7823
8272
  }
7824
- `;
8273
+ `
8274
+ );
7825
8275
  var vibrance = {
8276
+ props: {},
8277
+ uniforms: {},
7826
8278
  name: "vibrance",
7827
8279
  uniformPropTypes: {
7828
8280
  amount: { value: 0, min: -1, max: 1 }
@@ -7832,8 +8284,9 @@ vec4 vibrance_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7832
8284
  };
7833
8285
 
7834
8286
  // src/modules/postprocessing/image-adjust-filters/vignette.ts
7835
- var fs10 = glsl`\
7836
- uniform vignetteUniforms {
8287
+ var fs10 = (
8288
+ /* glsl */
8289
+ `uniform vignetteUniforms {
7837
8290
  float radius;
7838
8291
  float amount;
7839
8292
  } vignette;
@@ -7847,10 +8300,12 @@ vec4 vignette_filterColor(vec4 color, vec2 texCoord) {
7847
8300
  vec4 vignette_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7848
8301
  return vignette_filterColor(color, texCoord);
7849
8302
  }
7850
- `;
8303
+ `
8304
+ );
7851
8305
  var vignette = {
8306
+ props: {},
8307
+ uniforms: {},
7852
8308
  name: "vignette",
7853
- fs: fs10,
7854
8309
  uniformTypes: {
7855
8310
  radius: "f32",
7856
8311
  amount: "f32"
@@ -7859,12 +8314,14 @@ vec4 vignette_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
7859
8314
  radius: { value: 0.5, min: 0, max: 1 },
7860
8315
  amount: { value: 0.5, min: 0, max: 1 }
7861
8316
  },
7862
- passes: [{ filter: true }]
8317
+ passes: [{ filter: true }],
8318
+ fs: fs10
7863
8319
  };
7864
8320
 
7865
8321
  // src/modules/postprocessing/image-blur-filters/tiltshift.ts
7866
- var fs11 = glsl`\
7867
- uniform tiltShiftUniforms {
8322
+ var fs11 = (
8323
+ /* glsl */
8324
+ `uniform tiltShiftUniforms {
7868
8325
  float blurRadius;
7869
8326
  float gradientRadius;
7870
8327
  vec2 start;
@@ -7907,8 +8364,11 @@ vec4 tiltShift_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
7907
8364
 
7908
8365
  return color;
7909
8366
  }
7910
- `;
8367
+ `
8368
+ );
7911
8369
  var tiltShift = {
8370
+ props: {},
8371
+ uniforms: {},
7912
8372
  name: "tiltShift",
7913
8373
  dependencies: [random],
7914
8374
  uniformTypes: {
@@ -7933,8 +8393,9 @@ vec4 tiltShift_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
7933
8393
  };
7934
8394
 
7935
8395
  // src/modules/postprocessing/image-blur-filters/triangleblur.ts
7936
- var fs12 = glsl`\
7937
- uniform triangleBlurUniforms {
8396
+ var fs12 = (
8397
+ /* glsl */
8398
+ `uniform triangleBlurUniforms {
7938
8399
  float radius;
7939
8400
  vec2 delta;
7940
8401
  } triangleBlur;
@@ -7967,8 +8428,11 @@ vec4 triangleBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
7967
8428
 
7968
8429
  return color;
7969
8430
  }
7970
- `;
8431
+ `
8432
+ );
7971
8433
  var triangleBlur = {
8434
+ props: {},
8435
+ uniforms: {},
7972
8436
  name: "triangleBlur",
7973
8437
  uniformTypes: {
7974
8438
  radius: "f32",
@@ -8022,6 +8486,8 @@ vec4 zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8022
8486
  }
8023
8487
  `;
8024
8488
  var zoomBlur = {
8489
+ props: {},
8490
+ uniforms: {},
8025
8491
  name: "zoomBlur",
8026
8492
  uniformTypes: {
8027
8493
  center: "vec2<f32>",
@@ -8037,8 +8503,9 @@ vec4 zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8037
8503
  };
8038
8504
 
8039
8505
  // src/modules/postprocessing/image-fun-filters/colorhalftone.ts
8040
- var fs14 = glsl`\
8041
- uniform colorHalftoneUniforms {
8506
+ var fs14 = (
8507
+ /* glsl */
8508
+ `uniform colorHalftoneUniforms {
8042
8509
  vec2 center;
8043
8510
  float angle;
8044
8511
  float size;
@@ -8072,8 +8539,11 @@ vec4 colorHalftone_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
8072
8539
  k = clamp(k * 10.0 - 5.0 + pattern(colorHalftone.angle + 0.78539, scale, texSize, texCoord), 0.0, 1.0);
8073
8540
  return vec4(1.0 - cmy - k, color.a);
8074
8541
  }
8075
- `;
8542
+ `
8543
+ );
8076
8544
  var colorHalftone = {
8545
+ props: {},
8546
+ uniforms: {},
8077
8547
  name: "colorHalftone",
8078
8548
  uniformTypes: {
8079
8549
  center: "vec2<f32>",
@@ -8090,8 +8560,9 @@ vec4 colorHalftone_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
8090
8560
  };
8091
8561
 
8092
8562
  // src/modules/postprocessing/image-fun-filters/dotscreen.ts
8093
- var fs15 = glsl`\
8094
- uniform dotScreenUniforms {
8563
+ var fs15 = (
8564
+ /* glsl */
8565
+ `uniform dotScreenUniforms {
8095
8566
  vec2 center;
8096
8567
  float angle;
8097
8568
  float size;
@@ -8113,8 +8584,11 @@ vec4 dotScreen_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
8113
8584
  float average = (color.r + color.g + color.b) / 3.0;
8114
8585
  return vec4(vec3(average * 10.0 - 5.0 + pattern(texSize, texCoord)), color.a);
8115
8586
  }
8116
- `;
8587
+ `
8588
+ );
8117
8589
  var dotScreen = {
8590
+ props: {},
8591
+ uniforms: {},
8118
8592
  name: "dotScreen",
8119
8593
  uniformTypes: {
8120
8594
  center: "vec2<f32>",
@@ -8131,8 +8605,9 @@ vec4 dotScreen_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
8131
8605
  };
8132
8606
 
8133
8607
  // src/modules/postprocessing/image-fun-filters/edgework.ts
8134
- var fs16 = glsl`\
8135
- uniform edgeWorkUniforms {
8608
+ var fs16 = (
8609
+ /* glsl */
8610
+ `uniform edgeWorkUniforms {
8136
8611
  float radius;
8137
8612
  vec2 delta;
8138
8613
  } edgeWork;
@@ -8186,15 +8661,18 @@ vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
8186
8661
  float c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
8187
8662
  return vec4(c, c, c, 1.0);
8188
8663
  }
8189
- `;
8664
+ `
8665
+ );
8190
8666
  var edgeWork = {
8667
+ props: {},
8668
+ uniforms: {},
8191
8669
  name: "edgeWork",
8670
+ dependencies: [random],
8671
+ fs: fs16,
8192
8672
  uniformPropTypes: {
8193
8673
  radius: { value: 2, min: 1, softMax: 50 },
8194
8674
  delta: { value: [1, 0], private: true }
8195
8675
  },
8196
- fs: fs16,
8197
- dependencies: [random],
8198
8676
  passes: [
8199
8677
  {
8200
8678
  // @ts-expect-error
@@ -8210,8 +8688,9 @@ vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
8210
8688
  };
8211
8689
 
8212
8690
  // src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts
8213
- var fs17 = glsl`\
8214
- uniform hexagonalPixelateUniforms {
8691
+ var fs17 = (
8692
+ /* glsl */
8693
+ `uniform hexagonalPixelateUniforms {
8215
8694
  vec2 center;
8216
8695
  float scale;
8217
8696
  } hexagonalPixelate;
@@ -8253,8 +8732,11 @@ vec4 hexagonalPixelate_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord
8253
8732
 
8254
8733
  return texture(source, choice + hexagonalPixelate.center);
8255
8734
  }
8256
- `;
8735
+ `
8736
+ );
8257
8737
  var hexagonalPixelate = {
8738
+ props: {},
8739
+ uniforms: {},
8258
8740
  name: "hexagonalPixelate",
8259
8741
  uniformTypes: {
8260
8742
  center: "vec2<f32>",
@@ -8269,8 +8751,9 @@ vec4 hexagonalPixelate_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord
8269
8751
  };
8270
8752
 
8271
8753
  // src/modules/postprocessing/image-fun-filters/ink.ts
8272
- var fs18 = glsl`\
8273
- uniform inkUniforms {
8754
+ var fs18 = (
8755
+ /* glsl */
8756
+ `uniform inkUniforms {
8274
8757
  float strength;
8275
8758
  } ink;
8276
8759
 
@@ -8297,22 +8780,26 @@ vec4 ink_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8297
8780
  float power = ink.strength * ink.strength * ink.strength * ink.strength * ink.strength;
8298
8781
  return vec4(color.rgb - dot(edge, edge) * power * 100000.0, color.a);
8299
8782
  }
8300
- `;
8783
+ `
8784
+ );
8301
8785
  var ink = {
8786
+ props: {},
8787
+ uniforms: {},
8302
8788
  name: "ink",
8789
+ fs: fs18,
8303
8790
  uniformTypes: {
8304
8791
  strength: "f32"
8305
8792
  },
8306
8793
  uniformPropTypes: {
8307
8794
  strength: { value: 0.25, min: 0, softMax: 1 }
8308
8795
  },
8309
- fs: fs18,
8310
8796
  passes: [{ sampler: true }]
8311
8797
  };
8312
8798
 
8313
8799
  // src/modules/postprocessing/image-fun-filters/magnify.ts
8314
- var fs19 = glsl`\
8315
- uniform magnifyUniforms {
8800
+ var fs19 = (
8801
+ /* glsl */
8802
+ `uniform magnifyUniforms {
8316
8803
  vec2 screenXY;
8317
8804
  float radiusPixels;
8318
8805
  float zoom;
@@ -8332,7 +8819,8 @@ vec4 magnify_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8332
8819
  }
8333
8820
  return texture(source, texCoord);
8334
8821
  }
8335
- `;
8822
+ `
8823
+ );
8336
8824
  var magnify = {
8337
8825
  name: "magnify",
8338
8826
  uniformTypes: {
@@ -8355,8 +8843,9 @@ vec4 magnify_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8355
8843
  };
8356
8844
 
8357
8845
  // src/modules/postprocessing/image-warp-filters/warp.ts
8358
- var fs20 = glsl`\
8359
- vec4 warp_sampleColor(sampler2D source, vec2 texSize, vec2 coord) {
8846
+ var fs20 = (
8847
+ /* glsl */
8848
+ `vec4 warp_sampleColor(sampler2D source, vec2 texSize, vec2 coord) {
8360
8849
  vec4 color = texture(source, coord / texSize);
8361
8850
  vec2 clampedCoord = clamp(coord, vec2(0.0), texSize);
8362
8851
  if (coord != clampedCoord) {
@@ -8366,7 +8855,8 @@ vec4 warp_sampleColor(sampler2D source, vec2 texSize, vec2 coord) {
8366
8855
 
8367
8856
  return color;
8368
8857
  }
8369
- `;
8858
+ `
8859
+ );
8370
8860
  var warp = {
8371
8861
  name: "warp",
8372
8862
  passes: [],
@@ -8374,8 +8864,9 @@ vec4 warp_sampleColor(sampler2D source, vec2 texSize, vec2 coord) {
8374
8864
  };
8375
8865
 
8376
8866
  // src/modules/postprocessing/image-warp-filters/bulgepinch.ts
8377
- var fs21 = glsl`\
8378
- uniform bulgePinchUniforms {
8867
+ var fs21 = (
8868
+ /* glsl */
8869
+ `uniform bulgePinchUniforms {
8379
8870
  float radius;
8380
8871
  float strength;
8381
8872
  vec2 center;
@@ -8402,8 +8893,11 @@ vec4 bulgePinch_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8402
8893
 
8403
8894
  return warp_sampleColor(source, texSize, coord);
8404
8895
  }
8405
- `;
8896
+ `
8897
+ );
8406
8898
  var bulgePinch = {
8899
+ props: {},
8900
+ uniforms: {},
8407
8901
  name: "bulgePinch",
8408
8902
  dependencies: [warp],
8409
8903
  fs: fs21,
@@ -8421,8 +8915,9 @@ vec4 bulgePinch_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8421
8915
  };
8422
8916
 
8423
8917
  // src/modules/postprocessing/image-warp-filters/swirl.ts
8424
- var fs22 = glsl`\
8425
- uniform swirlUniforms {
8918
+ var fs22 = (
8919
+ /* glsl */
8920
+ `uniform swirlUniforms {
8426
8921
  float radius;
8427
8922
  float angle;
8428
8923
  vec2 center;
@@ -8451,8 +8946,11 @@ vec4 swirl_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8451
8946
 
8452
8947
  return warp_sampleColor(source, texSize, coord);
8453
8948
  }
8454
- `;
8949
+ `
8950
+ );
8455
8951
  var swirl = {
8952
+ props: {},
8953
+ uniforms: {},
8456
8954
  name: "swirl",
8457
8955
  dependencies: [warp],
8458
8956
  fs: fs22,
@@ -9060,8 +9558,9 @@ vec4 fxaa_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
9060
9558
  };
9061
9559
 
9062
9560
  // src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts
9063
- var fp64arithmeticShader = glsl`\
9064
- uniform float ONE;
9561
+ var fp64arithmeticShader = (
9562
+ /* glsl */
9563
+ `uniform float ONE;
9065
9564
 
9066
9565
  /*
9067
9566
  About LUMA_FP64_CODE_ELIMINATION_WORKAROUND
@@ -9226,11 +9725,13 @@ vec2 sqrt_fp64(vec2 a) {
9226
9725
  return sum_fp64(vec2(yn, 0.0), prod);
9227
9726
  #endif
9228
9727
  }
9229
- `;
9728
+ `
9729
+ );
9230
9730
 
9231
9731
  // src/modules-webgl1/math/fp64/fp64-functions-glsl.ts
9232
- var fp64functionShader = glsl`\
9233
- const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
9732
+ var fp64functionShader = (
9733
+ /* glsl */
9734
+ `const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
9234
9735
  const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
9235
9736
  const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
9236
9737
  const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
@@ -9899,7 +10400,8 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
9899
10400
  vec4_dot_fp64(a, tmp, out_val[i]);
9900
10401
  }
9901
10402
  }
9902
- `;
10403
+ `
10404
+ );
9903
10405
 
9904
10406
  // src/modules-webgl1/math/fp64/fp64.ts
9905
10407
  var CONST_UNIFORMS = {
@@ -9928,8 +10430,9 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
9928
10430
  };
9929
10431
 
9930
10432
  // src/modules-webgl1/geometry/geometry.ts
9931
- var vs3 = glsl`\
9932
- varying vec4 geometry_vPosition;
10433
+ var vs3 = (
10434
+ /* glsl */
10435
+ `varying vec4 geometry_vPosition;
9933
10436
  varying vec3 geometry_vNormal;
9934
10437
 
9935
10438
  void geometry_setNormal(vec3 normal) {
@@ -9943,9 +10446,11 @@ void geometry_setPosition(vec4 position) {
9943
10446
  void geometry_setPosition(vec3 position) {
9944
10447
  geometry_vPosition = vec4(position, 1.);
9945
10448
  }
9946
- `;
9947
- var fs24 = glsl`\
9948
- varying vec4 geometry_vPosition;
10449
+ `
10450
+ );
10451
+ var fs24 = (
10452
+ /* glsl */
10453
+ `varying vec4 geometry_vPosition;
9949
10454
  varying vec3 geometry_vNormal;
9950
10455
 
9951
10456
  vec4 geometry_getPosition() {
@@ -9955,7 +10460,8 @@ vec4 geometry_getPosition() {
9955
10460
  vec3 geometry_getNormal() {
9956
10461
  return geometry_vNormal;
9957
10462
  }
9958
- `;
10463
+ `
10464
+ );
9959
10465
  var geometry = {
9960
10466
  name: "geometry",
9961
10467
  vs: vs3,
@@ -9991,8 +10497,9 @@ vec3 geometry_getNormal() {
9991
10497
  }
9992
10498
  return uniforms;
9993
10499
  }
9994
- var common = glsl`\
9995
- varying vec4 project_vPositionWorld;
10500
+ var common = (
10501
+ /* glsl */
10502
+ `varying vec4 project_vPositionWorld;
9996
10503
  varying vec3 project_vNormalWorld;
9997
10504
 
9998
10505
  vec4 project_getPosition_World() {
@@ -10002,7 +10509,8 @@ vec4 project_getPosition_World() {
10002
10509
  vec3 project_getNormal_World() {
10003
10510
  return project_vNormalWorld;
10004
10511
  }
10005
- `;
10512
+ `
10513
+ );
10006
10514
  var vs4 = `${common}
10007
10515
 
10008
10516
  // Unprefixed uniforms
@@ -10067,8 +10575,9 @@ ${common}`;
10067
10575
  };
10068
10576
 
10069
10577
  // src/modules-webgl1/lighting/lights/lights-glsl.ts
10070
- var lightingShader = glsl`\
10071
- #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
10578
+ var lightingShader = (
10579
+ /* glsl */
10580
+ `#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
10072
10581
 
10073
10582
  struct AmbientLight {
10074
10583
  vec3 color;
@@ -10102,7 +10611,8 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
10102
10611
  }
10103
10612
 
10104
10613
  #endif
10105
- `;
10614
+ `
10615
+ );
10106
10616
 
10107
10617
  // src/modules-webgl1/lighting/lights/lights.ts
10108
10618
  var INITIAL_MODULE_OPTIONS = {
@@ -10123,19 +10633,19 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
10123
10633
  } else {
10124
10634
  lightSourceUniforms["lighting_uAmbientLight.color"] = [0, 0, 0];
10125
10635
  }
10126
- pointLights.forEach((pointLight, index2) => {
10127
- lightSourceUniforms[`lighting_uPointLight[${index2}].color`] = convertColor2(pointLight);
10128
- lightSourceUniforms[`lighting_uPointLight[${index2}].position`] = pointLight.position;
10129
- lightSourceUniforms[`lighting_uPointLight[${index2}].attenuation`] = pointLight.attenuation || [
10636
+ pointLights.forEach((pointLight, index) => {
10637
+ lightSourceUniforms[`lighting_uPointLight[${index}].color`] = convertColor2(pointLight);
10638
+ lightSourceUniforms[`lighting_uPointLight[${index}].position`] = pointLight.position;
10639
+ lightSourceUniforms[`lighting_uPointLight[${index}].attenuation`] = pointLight.attenuation || [
10130
10640
  1,
10131
10641
  0,
10132
10642
  0
10133
10643
  ];
10134
10644
  });
10135
10645
  lightSourceUniforms.lighting_uPointLightCount = pointLights.length;
10136
- directionalLights.forEach((directionalLight, index2) => {
10137
- lightSourceUniforms[`lighting_uDirectionalLight[${index2}].color`] = convertColor2(directionalLight);
10138
- lightSourceUniforms[`lighting_uDirectionalLight[${index2}].direction`] = directionalLight.direction;
10646
+ directionalLights.forEach((directionalLight, index) => {
10647
+ lightSourceUniforms[`lighting_uDirectionalLight[${index}].color`] = convertColor2(directionalLight);
10648
+ lightSourceUniforms[`lighting_uDirectionalLight[${index}].direction`] = directionalLight.direction;
10139
10649
  });
10140
10650
  lightSourceUniforms.lighting_uDirectionalLightCount = directionalLights.length;
10141
10651
  return lightSourceUniforms;
@@ -10196,8 +10706,9 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
10196
10706
  }
10197
10707
  return uniforms;
10198
10708
  }
10199
- var fs26 = glsl`\
10200
- uniform vec3 dirlight_uLightDirection;
10709
+ var fs26 = (
10710
+ /* glsl */
10711
+ `uniform vec3 dirlight_uLightDirection;
10201
10712
 
10202
10713
  /*
10203
10714
  * Returns color attenuated by angle from light source
@@ -10207,7 +10718,8 @@ vec4 dirlight_filterColor(vec4 color) {
10207
10718
  float d = abs(dot(normalize(normal), normalize(dirlight_uLightDirection)));
10208
10719
  return vec4(color.rgb * d, color.a);
10209
10720
  }
10210
- `;
10721
+ `
10722
+ );
10211
10723
  var dirlight2 = {
10212
10724
  name: "dirlight",
10213
10725
  // vs // TODO - reuse normal from geometry module
@@ -10217,8 +10729,9 @@ vec4 dirlight_filterColor(vec4 color) {
10217
10729
  };
10218
10730
 
10219
10731
  // src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts
10220
- var lightingShader2 = glsl`\
10221
-
10732
+ var lightingShader2 = (
10733
+ /* glsl */
10734
+ `
10222
10735
  uniform float lighting_uAmbient;
10223
10736
  uniform float lighting_uDiffuse;
10224
10737
  uniform float lighting_uShininess;
@@ -10291,7 +10804,8 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
10291
10804
  }
10292
10805
  return lightColor;
10293
10806
  }
10294
- `;
10807
+ `
10808
+ );
10295
10809
 
10296
10810
  // src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts
10297
10811
  var INITIAL_MODULE_OPTIONS2 = {};
@@ -10334,8 +10848,9 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
10334
10848
  };
10335
10849
 
10336
10850
  // src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts
10337
- var vs5 = glsl`\
10338
- uniform mat4 u_MVPMatrix;
10851
+ var vs5 = (
10852
+ /* glsl */
10853
+ `uniform mat4 u_MVPMatrix;
10339
10854
  uniform mat4 u_ModelMatrix;
10340
10855
  uniform mat4 u_NormalMatrix;
10341
10856
 
@@ -10372,11 +10887,13 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
10372
10887
  pbr_vUV = vec2(0.,0.);
10373
10888
  #endif
10374
10889
  }
10375
- `;
10890
+ `
10891
+ );
10376
10892
 
10377
10893
  // src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts
10378
- var fs27 = glsl`\
10379
- precision highp float;
10894
+ var fs27 = (
10895
+ /* glsl */
10896
+ `precision highp float;
10380
10897
 
10381
10898
  uniform bool pbr_uUnlit;
10382
10899
 
@@ -10757,7 +11274,8 @@ vec4 pbr_filterColor(vec4 colorUnused)
10757
11274
 
10758
11275
  return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
10759
11276
  }
10760
- `;
11277
+ `
11278
+ );
10761
11279
 
10762
11280
  // src/modules-webgl1/lighting/pbr/pbr.ts
10763
11281
  var pbr = {