@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
@@ -1,126 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { assert } from "../utils/assert.js";
5
- import { makePropValidators, getValidatedProperties } from "../filters/prop-types.js";
6
- import { normalizeInjections } from "../shader-assembly/shader-injections.js";
7
- let index = 1;
8
- /** An initialized ShaderModule, ready to use with `assembleShaders()` */
9
- export class ShaderModuleInstance {
10
- name;
11
- vs;
12
- fs;
13
- getModuleUniforms;
14
- dependencies;
15
- deprecations;
16
- defines;
17
- injections;
18
- uniforms = {};
19
- uniformTypes = {};
20
- static instantiateModules(modules) {
21
- return modules.map((module) => {
22
- if (module instanceof ShaderModuleInstance) {
23
- return module;
24
- }
25
- assert(typeof module !== 'string', `Shader module use by name is deprecated. Import shader module '${JSON.stringify(module)}' and use it directly.`);
26
- if (!module.name) {
27
- // eslint-disable-next-line no-console
28
- console.warn('shader module has no name');
29
- module.name = `shader-module-${index++}`;
30
- }
31
- const moduleObject = new ShaderModuleInstance(module);
32
- moduleObject.dependencies = ShaderModuleInstance.instantiateModules(module.dependencies || []);
33
- return moduleObject;
34
- });
35
- }
36
- constructor(props) {
37
- const { name, vs, fs, dependencies = [], uniformPropTypes = {}, getUniforms, deprecations = [], defines = {}, inject = {} } = props;
38
- assert(typeof name === 'string');
39
- this.name = name;
40
- this.vs = vs;
41
- this.fs = fs;
42
- this.getModuleUniforms = getUniforms;
43
- this.dependencies = ShaderModuleInstance.instantiateModules(dependencies);
44
- this.deprecations = this._parseDeprecationDefinitions(deprecations);
45
- this.defines = defines;
46
- this.injections = normalizeInjections(inject);
47
- if (uniformPropTypes) {
48
- this.uniforms = makePropValidators(uniformPropTypes);
49
- }
50
- }
51
- // Extracts the source code chunk for the specified shader type from the named shader module
52
- getModuleSource(stage) {
53
- let moduleSource;
54
- switch (stage) {
55
- case 'vertex':
56
- moduleSource = this.vs || '';
57
- break;
58
- case 'fragment':
59
- moduleSource = this.fs || '';
60
- break;
61
- default:
62
- assert(false);
63
- }
64
- const moduleName = this.name.toUpperCase().replace(/[^0-9a-z]/gi, '_');
65
- return `\
66
- // ----- MODULE ${this.name} ---------------
67
-
68
- #define MODULE_${moduleName}
69
- ${moduleSource}\
70
-
71
-
72
- `;
73
- }
74
- getUniforms(userProps, uniforms) {
75
- if (this.getModuleUniforms) {
76
- return this.getModuleUniforms(userProps, uniforms);
77
- }
78
- // Build uniforms from the uniforms array
79
- return getValidatedProperties(userProps, this.uniforms, this.name);
80
- }
81
- getDefines() {
82
- return this.defines;
83
- }
84
- // Warn about deprecated uniforms or functions
85
- checkDeprecations(shaderSource, log) {
86
- this.deprecations.forEach(def => {
87
- if (def.regex?.test(shaderSource)) {
88
- if (def.deprecated) {
89
- log.deprecated(def.old, def.new)();
90
- }
91
- else {
92
- log.removed(def.old, def.new)();
93
- }
94
- }
95
- });
96
- }
97
- _parseDeprecationDefinitions(deprecations) {
98
- deprecations.forEach(def => {
99
- switch (def.type) {
100
- case 'function':
101
- def.regex = new RegExp(`\\b${def.old}\\(`);
102
- break;
103
- default:
104
- def.regex = new RegExp(`${def.type} ${def.old};`);
105
- }
106
- });
107
- return deprecations;
108
- }
109
- _defaultGetUniforms(opts = {}) {
110
- const uniforms = {};
111
- const propTypes = this.uniforms;
112
- for (const key in propTypes) {
113
- const propDef = propTypes[key];
114
- if (key in opts && !propDef.private) {
115
- if (propDef.validate) {
116
- assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);
117
- }
118
- uniforms[key] = opts[key];
119
- }
120
- else {
121
- uniforms[key] = propDef.value;
122
- }
123
- }
124
- return uniforms;
125
- }
126
- }
@@ -1,11 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- // SHADER HELPERS
6
-
7
- /**
8
- * Marks GLSL shaders for syntax highlighting: glsl`...`
9
- * Install https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
10
- */
11
- export const glsl = (x: TemplateStringsArray) => `${x}`;
@@ -1,81 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import type {ShaderModule} from '../shader-module/shader-module';
6
- import {ShaderModuleInstance} from '../shader-module/shader-module-instance';
7
-
8
- /**
9
- * Instantiate shader modules and esolve any dependencies
10
- */
11
- export function resolveModules(
12
- modules: (ShaderModule | ShaderModuleInstance)[]
13
- ): ShaderModuleInstance[] {
14
- const instances = ShaderModuleInstance.instantiateModules(modules);
15
- return getShaderDependencies(instances);
16
- }
17
-
18
- /**
19
- * Takes a list of shader module names and returns a new list of
20
- * shader module names that includes all dependencies, sorted so
21
- * that modules that are dependencies of other modules come first.
22
- *
23
- * If the shader glsl code from the returned modules is concatenated
24
- * in the reverse order, it is guaranteed that all functions be resolved and
25
- * that all function and variable definitions come before use.
26
- *
27
- * @param modules - Array of modules (inline modules or module names)
28
- * @return - Array of modules
29
- */
30
- function getShaderDependencies(modules: ShaderModuleInstance[]): ShaderModuleInstance[] {
31
- const moduleMap: Record<string, ShaderModuleInstance> = {};
32
- const moduleDepth: Record<string, number> = {};
33
- getDependencyGraph({modules, level: 0, moduleMap, moduleDepth});
34
-
35
- // Return a reverse sort so that dependencies come before the modules that use them
36
- return Object.keys(moduleDepth)
37
- .sort((a, b) => moduleDepth[b] - moduleDepth[a])
38
- .map(name => moduleMap[name]);
39
- }
40
-
41
- /**
42
- * Recursively checks module dependencies to calculate dependency level of each module.
43
- *
44
- * @param options.modules - Array of modules
45
- * @param options.level - Current level
46
- * @param options.moduleMap -
47
- * @param options.moduleDepth - Current level
48
- * @return - Map of module name to its level
49
- */
50
- // Adds another level of dependencies to the result map
51
- export function getDependencyGraph(options: {
52
- modules: ShaderModuleInstance[];
53
- level: number;
54
- moduleMap: Record<string, ShaderModuleInstance>;
55
- moduleDepth: Record<string, number>;
56
- }) {
57
- const {modules, level, moduleMap, moduleDepth} = options;
58
- if (level >= 5) {
59
- throw new Error('Possible loop in shader dependency graph');
60
- }
61
-
62
- // Update level on all current modules
63
- for (const module of modules) {
64
- moduleMap[module.name] = module;
65
- if (moduleDepth[module.name] === undefined || moduleDepth[module.name] < level) {
66
- moduleDepth[module.name] = level;
67
- }
68
- }
69
-
70
- // Recurse
71
- for (const module of modules) {
72
- if (module.dependencies) {
73
- getDependencyGraph({modules: module.dependencies, level: level + 1, moduleMap, moduleDepth});
74
- }
75
- }
76
- }
77
-
78
- export const TEST_EXPORTS = {
79
- getShaderDependencies,
80
- getDependencyGraph
81
- };
@@ -1,17 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {ShaderModule} from './shader-module';
6
- import {ShaderModuleInstance} from './shader-module-instance';
7
-
8
- export function normalizeShaderModule(module: ShaderModule): ShaderModule {
9
- if (!module.normalized) {
10
- module.normalized = true;
11
- if (module.uniformPropTypes && !module.getUniforms) {
12
- const shaderModule = new ShaderModuleInstance(module);
13
- module.getUniforms = shaderModule.getUniforms.bind(shaderModule);
14
- }
15
- }
16
- return module;
17
- }
@@ -1,167 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {assert} from '../utils/assert';
6
- import {makePropValidators, getValidatedProperties, PropValidator} from '../filters/prop-types';
7
- import {ShaderModule, ShaderModuleDeprecation} from './shader-module';
8
- import {ShaderInjection, normalizeInjections} from '../shader-assembly/shader-injections';
9
-
10
- let index = 1;
11
-
12
- /** An initialized ShaderModule, ready to use with `assembleShaders()` */
13
- export class ShaderModuleInstance {
14
- name: string;
15
- vs?: string;
16
- fs?: string;
17
- getModuleUniforms: Function;
18
- dependencies: ShaderModuleInstance[];
19
- deprecations: ShaderModuleDeprecation[];
20
- defines: Record<string, string | number>;
21
- injections: {
22
- vertex: Record<string, ShaderInjection>;
23
- fragment: Record<string, ShaderInjection>;
24
- };
25
- uniforms: Record<string, PropValidator> = {};
26
- uniformTypes: Record<string, PropValidator> = {};
27
-
28
- static instantiateModules(
29
- modules: (ShaderModule | ShaderModuleInstance)[]
30
- ): ShaderModuleInstance[] {
31
- return modules.map((module: ShaderModule | ShaderModuleInstance) => {
32
- if (module instanceof ShaderModuleInstance) {
33
- return module;
34
- }
35
-
36
- assert(
37
- typeof module !== 'string',
38
- `Shader module use by name is deprecated. Import shader module '${JSON.stringify(
39
- module
40
- )}' and use it directly.`
41
- );
42
- if (!module.name) {
43
- // eslint-disable-next-line no-console
44
- console.warn('shader module has no name');
45
- module.name = `shader-module-${index++}`;
46
- }
47
-
48
- const moduleObject = new ShaderModuleInstance(module);
49
- moduleObject.dependencies = ShaderModuleInstance.instantiateModules(
50
- module.dependencies || []
51
- );
52
-
53
- return moduleObject;
54
- });
55
- }
56
-
57
- constructor(props: ShaderModule) {
58
- const {
59
- name,
60
- vs,
61
- fs,
62
- dependencies = [],
63
- uniformPropTypes = {},
64
- getUniforms,
65
- deprecations = [],
66
- defines = {},
67
- inject = {}
68
- } = props;
69
-
70
- assert(typeof name === 'string');
71
- this.name = name;
72
- this.vs = vs;
73
- this.fs = fs;
74
- this.getModuleUniforms = getUniforms!;
75
- this.dependencies = ShaderModuleInstance.instantiateModules(dependencies);
76
- this.deprecations = this._parseDeprecationDefinitions(deprecations);
77
- this.defines = defines;
78
- this.injections = normalizeInjections(inject);
79
-
80
- if (uniformPropTypes) {
81
- this.uniforms = makePropValidators(uniformPropTypes);
82
- }
83
- }
84
-
85
- // Extracts the source code chunk for the specified shader type from the named shader module
86
- getModuleSource(stage: 'vertex' | 'fragment'): string {
87
- let moduleSource;
88
- switch (stage) {
89
- case 'vertex':
90
- moduleSource = this.vs || '';
91
- break;
92
- case 'fragment':
93
- moduleSource = this.fs || '';
94
- break;
95
- default:
96
- assert(false);
97
- }
98
-
99
- const moduleName = this.name.toUpperCase().replace(/[^0-9a-z]/gi, '_');
100
- return `\
101
- // ----- MODULE ${this.name} ---------------
102
-
103
- #define MODULE_${moduleName}
104
- ${moduleSource}\
105
-
106
-
107
- `;
108
- }
109
-
110
- getUniforms(userProps: Record<string, any>, uniforms: Record<string, any>): Record<string, any> {
111
- if (this.getModuleUniforms) {
112
- return this.getModuleUniforms(userProps, uniforms);
113
- }
114
- // Build uniforms from the uniforms array
115
- return getValidatedProperties(userProps, this.uniforms, this.name);
116
- }
117
-
118
- getDefines(): Record<string, string | number> {
119
- return this.defines;
120
- }
121
-
122
- // Warn about deprecated uniforms or functions
123
- checkDeprecations(shaderSource: string, log: any): void {
124
- this.deprecations.forEach(def => {
125
- if (def.regex?.test(shaderSource)) {
126
- if (def.deprecated) {
127
- log.deprecated(def.old, def.new)();
128
- } else {
129
- log.removed(def.old, def.new)();
130
- }
131
- }
132
- });
133
- }
134
-
135
- _parseDeprecationDefinitions(deprecations: ShaderModuleDeprecation[]) {
136
- deprecations.forEach(def => {
137
- switch (def.type) {
138
- case 'function':
139
- def.regex = new RegExp(`\\b${def.old}\\(`);
140
- break;
141
- default:
142
- def.regex = new RegExp(`${def.type} ${def.old};`);
143
- }
144
- });
145
-
146
- return deprecations;
147
- }
148
-
149
- _defaultGetUniforms(opts: Record<string, any> = {}): Record<string, any> {
150
- const uniforms: Record<string, any> = {};
151
- const propTypes = this.uniforms;
152
-
153
- for (const key in propTypes) {
154
- const propDef = propTypes[key];
155
- if (key in opts && !propDef.private) {
156
- if (propDef.validate) {
157
- assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);
158
- }
159
- uniforms[key] = opts[key];
160
- } else {
161
- uniforms[key] = propDef.value;
162
- }
163
- }
164
-
165
- return uniforms;
166
- }
167
- }