@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
@@ -2,11 +2,20 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {NumberArray} from '@math.gl/types';
6
- import {UniformFormat} from '../../types';
7
- import {PropType} from '../filters/prop-types';
5
+ import type {NumericArray} from '@math.gl/types';
6
+ import {Sampler, Texture} from '@luma.gl/core';
7
+ import type {UniformFormat} from '../../types';
8
+ import {
9
+ PropType,
10
+ PropValidator,
11
+ makePropValidators,
12
+ getValidatedProperties
13
+ } from '../filters/prop-types';
14
+ import {ShaderInjection, normalizeInjections} from '../shader-assembly/shader-injections';
8
15
 
9
- export type UniformValue = number | boolean | Readonly<NumberArray>; // Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>;
16
+ export type BindingValue = Buffer | Texture | Sampler;
17
+ export type UniformValue = number | boolean | Readonly<NumericArray>;
18
+ // Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>;
10
19
 
11
20
  export type UniformInfo = {
12
21
  format?: UniformFormat;
@@ -14,20 +23,26 @@ export type UniformInfo = {
14
23
 
15
24
  /**
16
25
  * A shader module definition object
17
- * @note Can be viewed as the ShaderModuleProps for a ShaderModuleInstance
26
+ *
27
+ * @note Needs to be initialized with `initializeShaderModules`
18
28
  */
19
29
  export type ShaderModule<
20
30
  PropsT extends Record<string, unknown> = Record<string, unknown>,
21
31
  UniformsT extends Record<string, UniformValue> = Record<string, UniformValue>,
22
- BindingsT extends Record<string, unknown> = {}
32
+ BindingsT extends Record<string, BindingValue> = Record<string, BindingValue>
23
33
  > = {
24
34
  /** Used for type inference not for values */
25
- props?: Required<PropsT>;
35
+ props?: PropsT;
26
36
  /** Used for type inference, not currently used for values */
27
37
  uniforms?: UniformsT;
28
38
 
29
39
  name: string;
40
+
41
+ /** WGSL code */
42
+ source?: string;
43
+ /** GLSL fragment shader code */
30
44
  fs?: string;
45
+ /** GLSL vertex shader code */
31
46
  vs?: string;
32
47
 
33
48
  /** Uniform shader types @note: Both order and types MUST match uniform block declarations in shader */
@@ -37,9 +52,8 @@ export type ShaderModule<
37
52
  /** Default uniform values */
38
53
  defaultUniforms?: Required<UniformsT>; // Record<keyof UniformsT, UniformValue>;
39
54
 
40
- /** Function that maps settings to uniforms */
41
- // getUniforms?: (settings?: Partial<SettingsT>, prevUniforms?: any /* UniformsT */) => UniformsT;
42
- getUniforms?: (settings?: any, prevUniforms?: any) => Record<string, UniformValue>;
55
+ /** Function that maps props to uniforms & bindings */
56
+ getUniforms?: (props?: any, oldProps?: any) => Record<string, BindingValue | UniformValue>;
43
57
 
44
58
  /** uniform buffers, textures, samplers, storage, ... */
45
59
  bindings?: Record<keyof BindingsT, {location: number; type: 'texture' | 'sampler' | 'uniforms'}>;
@@ -51,8 +65,16 @@ export type ShaderModule<
51
65
  /** Information on deprecated properties */
52
66
  deprecations?: ShaderModuleDeprecation[];
53
67
 
54
- /** Internal */
55
- normalized?: boolean;
68
+ /** The instance field contains information that is generated at run-time */
69
+ instance?: {
70
+ propValidators?: Record<string, PropValidator>;
71
+ parsedDeprecations: ShaderModuleDeprecation[];
72
+
73
+ normalizedInjections: {
74
+ vertex: Record<string, ShaderInjection>;
75
+ fragment: Record<string, ShaderInjection>;
76
+ };
77
+ };
56
78
  };
57
79
 
58
80
  /** Use to generate deprecations when shader module is used */
@@ -64,16 +86,109 @@ export type ShaderModuleDeprecation = {
64
86
  deprecated?: boolean;
65
87
  };
66
88
 
89
+ // SHNDER MODULE API
90
+
91
+ export function initializeShaderModules(modules: ShaderModule[]): void {
92
+ modules.map((module: ShaderModule) => initializeShaderModule(module));
93
+ }
94
+
95
+ export function initializeShaderModule(module: ShaderModule): void {
96
+ if (module.instance) {
97
+ return;
98
+ }
99
+
100
+ initializeShaderModules(module.dependencies || []);
101
+
102
+ const {
103
+ uniformPropTypes = {},
104
+ deprecations = [],
105
+ // defines = {},
106
+ inject = {}
107
+ } = module;
108
+
109
+ const instance: Required<ShaderModule>['instance'] = {
110
+ normalizedInjections: normalizeInjections(inject),
111
+ parsedDeprecations: parseDeprecationDefinitions(deprecations)
112
+ };
113
+
114
+ if (uniformPropTypes) {
115
+ instance.propValidators = makePropValidators(uniformPropTypes);
116
+ }
117
+
118
+ module.instance = instance;
119
+ }
120
+
67
121
  /** Convert module props to uniforms */
68
122
  export function getShaderModuleUniforms<
69
123
  ShaderModuleT extends ShaderModule<Record<string, unknown>, Record<string, UniformValue>>
70
- >(module: ShaderModuleT, props: ShaderModuleT['props']): ShaderModuleT['uniforms'] {
71
- const uniforms = {...module.defaultUniforms};
124
+ >(
125
+ module: ShaderModuleT,
126
+ props: ShaderModuleT['props'],
127
+ oldUniforms?: ShaderModuleT['uniforms']
128
+ ): Record<string, BindingValue | UniformValue> {
129
+ initializeShaderModule(module);
130
+
131
+ const uniforms = oldUniforms || {...module.defaultUniforms};
132
+ // If module has a getUniforms function, use it
72
133
  if (module.getUniforms) {
73
- // @ts-expect-error
74
- Object.assign(props, module.getUniforms(props));
75
- } else {
76
- Object.assign(uniforms, props);
134
+ return module.getUniforms(props, uniforms);
77
135
  }
78
- return uniforms;
136
+
137
+ // Build uniforms from the uniforms array
138
+ // @ts-expect-error
139
+ return getValidatedProperties(props, module.instance?.propValidators, module.name);
140
+ }
141
+
142
+ /* TODO this looks like it was unused code
143
+ _defaultGetUniforms(opts: Record<string, any> = {}): Record<string, any> {
144
+ const uniforms: Record<string, any> = {};
145
+ const propTypes = this.uniforms;
146
+
147
+ for (const key in propTypes) {
148
+ const propDef = propTypes[key];
149
+ if (key in opts && !propDef.private) {
150
+ if (propDef.validate) {
151
+ assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);
152
+ }
153
+ uniforms[key] = opts[key];
154
+ } else {
155
+ uniforms[key] = propDef.value;
156
+ }
157
+ }
158
+
159
+ return uniforms;
160
+ }
161
+ }
162
+ */
163
+ // Warn about deprecated uniforms or functions
164
+ export function checkShaderModuleDeprecations(
165
+ shaderModule: ShaderModule,
166
+ shaderSource: string,
167
+ log: any
168
+ ): void {
169
+ shaderModule.deprecations?.forEach(def => {
170
+ if (def.regex?.test(shaderSource)) {
171
+ if (def.deprecated) {
172
+ log.deprecated(def.old, def.new)();
173
+ } else {
174
+ log.removed(def.old, def.new)();
175
+ }
176
+ }
177
+ });
178
+ }
179
+
180
+ // HELPERS
181
+
182
+ function parseDeprecationDefinitions(deprecations: ShaderModuleDeprecation[]) {
183
+ deprecations.forEach(def => {
184
+ switch (def.type) {
185
+ case 'function':
186
+ def.regex = new RegExp(`\\b${def.old}\\(`);
187
+ break;
188
+ default:
189
+ def.regex = new RegExp(`${def.type} ${def.old};`);
190
+ }
191
+ });
192
+
193
+ return deprecations;
79
194
  }
@@ -5,8 +5,8 @@
5
5
  import type {ShaderModule, UniformValue} from './shader-module';
6
6
 
7
7
  /**
8
- * A shaderpass is a shader module with additional information
9
- * on how to run
8
+ * A ShaderPass is a ShaderModule that can be run "standalone" (e.g. post processing effects)
9
+ * It adds additional information on how to run the module in one or more passes.
10
10
  */
11
11
  export type ShaderPass<
12
12
  PropsT extends Record<string, unknown> = Record<string, unknown>,
@@ -15,6 +15,7 @@ export type ShaderPass<
15
15
  passes: ShaderPassData[];
16
16
  };
17
17
 
18
+ /** Information on how to run a specific pass */
18
19
  type ShaderPassData = {
19
20
  sampler?: boolean;
20
21
  filter?: boolean;
@@ -2,15 +2,13 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {glsl} from './lib/glsl-utils/highlight';
6
-
7
- export const MODULE_INJECTORS_VS = glsl`\
5
+ export const MODULE_INJECTORS_VS = /* glsl */ `\
8
6
  #ifdef MODULE_LOGDEPTH
9
7
  logdepth_adjustPosition(gl_Position);
10
8
  #endif
11
9
  `;
12
10
 
13
- export const MODULE_INJECTORS_FS = glsl`\
11
+ export const MODULE_INJECTORS_FS = /* glsl */ `\
14
12
  #ifdef MODULE_MATERIAL
15
13
  gl_FragColor = material_filterColor(gl_FragColor);
16
14
  #endif
@@ -3,10 +3,9 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  // import {ShaderModule} from '../../types';
6
- import {glsl} from '../../../lib/glsl-utils/highlight';
7
6
 
8
7
  // TODO - reuse normal from geometry module
9
- const vs = glsl`\
8
+ const vs = /* glsl */ `\
10
9
  varying vec4 geometry_vPosition;
11
10
  varying vec3 geometry_vNormal;
12
11
 
@@ -23,7 +22,7 @@ void geometry_setPosition(vec3 position) {
23
22
  }
24
23
  `;
25
24
 
26
- const fs = glsl`\
25
+ const fs = /* glsl */ `\
27
26
  varying vec4 geometry_vPosition;
28
27
  varying vec3 geometry_vNormal;
29
28
 
@@ -2,8 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {NumberArray} from '../../../types';
6
- import {glsl} from '../../../lib/glsl-utils/highlight';
5
+ import {NumericArray} from '../../../types';
7
6
  import {ShaderModule} from '../../../lib/shader-module/shader-module';
8
7
 
9
8
  // cyan color
@@ -20,9 +19,9 @@ export type PickingProps = {
20
19
  /** Set to true when picking an attribute value instead of object index */
21
20
  isAttribute?: boolean;
22
21
  /** Set to a picking color to visually highlight that item, or `null` to explicitly clear **/
23
- highlightedObjectColor?: NumberArray | null;
22
+ highlightedObjectColor?: NumericArray | null;
24
23
  /** Color of visual highlight of "selected" item */
25
- highlightColor?: NumberArray;
24
+ highlightColor?: NumericArray;
26
25
  /** Color range 0-1 or 0-255 */
27
26
  useFloatColors?: boolean;
28
27
  };
@@ -45,12 +44,12 @@ export type PickingUniforms = {
45
44
  /** Do we have a highlighted item? */
46
45
  isHighlightActive?: boolean;
47
46
  /** Set to a picking color to visually highlight that item */
48
- highlightedObjectColor?: NumberArray;
47
+ highlightedObjectColor?: NumericArray;
49
48
  /** Color of visual highlight of "selected" item */
50
- highlightColor?: NumberArray;
49
+ highlightColor?: NumericArray;
51
50
  };
52
51
 
53
- const vs = glsl`\
52
+ const vs = /* glsl */ `\
54
53
  uniform pickingUniforms {
55
54
  float isActive;
56
55
  float isAttribute;
@@ -124,7 +123,7 @@ void picking_setPickingAttribute(vec3 value) {
124
123
  }
125
124
  `;
126
125
 
127
- const fs = glsl`\
126
+ const fs = /* glsl */ `\
128
127
  uniform pickingUniforms {
129
128
  float isActive;
130
129
  float isAttribute;
@@ -191,7 +190,11 @@ vec4 picking_filterColor(vec4 color) {
191
190
  * primitives with the same picking color in non-instanced draw-calls
192
191
  */
193
192
  export const picking = {
193
+ props: {} as PickingProps,
194
+ uniforms: {} as PickingUniforms,
195
+
194
196
  name: 'picking',
197
+
195
198
  uniformTypes: {
196
199
  isActive: 'f32',
197
200
  isAttribute: 'f32',
@@ -208,10 +211,9 @@ export const picking = {
208
211
  highlightedObjectColor: new Float32Array([0, 0, 0]),
209
212
  highlightColor: DEFAULT_HIGHLIGHT_COLOR
210
213
  },
214
+
211
215
  vs,
212
216
  fs,
213
- props: {} as Required<PickingProps>,
214
- uniforms: {} as PickingUniforms,
215
217
  getUniforms
216
218
  } as const satisfies ShaderModule<PickingProps, PickingUniforms>;
217
219
 
@@ -4,7 +4,6 @@
4
4
 
5
5
  import {NumericArray as NumberArray, Matrix4, Vector3} from '@math.gl/core';
6
6
  import {ShaderModule} from '../../../lib/shader-module/shader-module';
7
- import {glsl} from '../../../lib/glsl-utils/highlight';
8
7
 
9
8
  const IDENTITY_MATRIX: Readonly<NumberArray> = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
10
9
 
@@ -70,7 +69,7 @@ function getUniforms(
70
69
  * @note varyings must match vertex shader
71
70
  * @note project module uses unprefixed uniforms to match conventions
72
71
  */
73
- const vs = glsl`\
72
+ const vs = /* glsl */ `\
74
73
  varying vec4 project_vPositionWorld;
75
74
  varying vec3 project_vNormalWorld;
76
75
 
@@ -132,7 +131,7 @@ vec4 project_to_clipspace(vec3 position) {
132
131
  * Functions to get the position and normal from the vertex shader
133
132
  * @note varyings must match vertex shader
134
133
  */
135
- const fs = glsl`\
134
+ const fs = /* glsl */ `\
136
135
  varying vec4 project_vPositionWorld;
137
136
  varying vec3 project_vNormalWorld;
138
137
 
@@ -2,9 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {glsl} from '../../../lib/glsl-utils/highlight';
6
-
7
- const vs = glsl`\
5
+ const vs = /* glsl */ `\
8
6
  attribute float transform_elementID;
9
7
 
10
8
  // returns half of pixel size, used to move the pixel position to center of the pixel.
@@ -18,6 +18,9 @@ export type GouraudMaterialUniforms = {
18
18
 
19
19
  /** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
20
20
  export const gouraudMaterial = {
21
+ props: {} as GouraudMaterialProps,
22
+ uniforms: {} as GouraudMaterialUniforms,
23
+
21
24
  name: 'gouraud-lighting',
22
25
  // Note these are switched between phong and gouraud
23
26
  vs: GOURAUD_VS,
@@ -38,6 +41,7 @@ export const gouraudMaterial = {
38
41
  shininess: 32,
39
42
  specularColor: [0.15, 0.15, 0.15]
40
43
  },
44
+
41
45
  getUniforms(props: GouraudMaterialProps): GouraudMaterialUniforms {
42
46
  return {...gouraudMaterial.defaultUniforms, ...props};
43
47
  }
@@ -2,9 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {glsl} from '../../../lib/glsl-utils/highlight';
6
-
7
- export const GOURAUD_VS = glsl`\
5
+ export const GOURAUD_VS = /* glsl */ `\
8
6
  uniform materialUniforms {
9
7
  uniform float ambient;
10
8
  uniform float diffuse;
@@ -13,7 +11,7 @@ uniform materialUniforms {
13
11
  } material;
14
12
  `;
15
13
 
16
- export const GOURAUD_FS = glsl`\
14
+ export const GOURAUD_FS = /* glsl */ `\
17
15
  uniform materialUniforms {
18
16
  uniform float ambient;
19
17
  uniform float diffuse;
@@ -2,9 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {glsl} from '../../../lib/glsl-utils/highlight';
6
-
7
- export const lightingUniforms = glsl`\
5
+ export const lightingUniformsGLSL = /* glsl */ `\
8
6
  precision highp int;
9
7
 
10
8
  // #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
@@ -0,0 +1,57 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export const lightingUniformsWGSL = /* wgsl */ `\
6
+ // #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
7
+ struct AmbientLight {
8
+ color: vec3<f32>,
9
+ };
10
+
11
+ struct PointLight {
12
+ color: vec3<f32>,
13
+ position: vec3<f32>,
14
+ attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
15
+ };
16
+
17
+ struct DirectionalLight {
18
+ color: vec3<f32>,
19
+ direction: vec3<f32>,
20
+ };
21
+
22
+ struct lightingUniforms {
23
+ enabled: i32,
24
+ poightCount: i32,
25
+ directionalLightCount: i32,
26
+
27
+ ambientColor: vec3<f32>,
28
+
29
+ // TODO - support multiple lights by uncommenting arrays below
30
+ lightType: i32,
31
+ lightColor: vec3<f32>,
32
+ lightDirection: vec3<f32>,
33
+ lightPosition: vec3<f32>,
34
+ lightAttenuation: vec3<f32>,
35
+
36
+ // AmbientLight ambientLight;
37
+ // PointLight pointLight[MAX_LIGHTS];
38
+ // DirectionalLight directionalLight[MAX_LIGHTS];
39
+ };
40
+
41
+ // Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)
42
+ @binding(1) @group(0) var<uniform> lighting : lightingUniforms;
43
+
44
+ fn lighting_getPointLight(index: i32) -> PointLight {
45
+ return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
46
+ }
47
+
48
+ fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
49
+ return DirectionalLight(lighting.lightColor, lighting.lightDirection);
50
+ }
51
+
52
+ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
53
+ return pointLight.attenuation.x
54
+ + pointLight.attenuation.y * distance
55
+ + pointLight.attenuation.z * distance * distance;
56
+ }
57
+ `;
@@ -4,7 +4,8 @@
4
4
 
5
5
  import type {NumberArray} from '@math.gl/types';
6
6
  import {ShaderModule} from '../../../lib/shader-module/shader-module';
7
- import {lightingUniforms} from './lighting-uniforms-glsl';
7
+ import {lightingUniformsGLSL} from './lighting-uniforms-glsl';
8
+ import {lightingUniformsWGSL} from './lighting-uniforms-wgsl';
8
9
 
9
10
  /** Max number of supported lights (in addition to ambient light */
10
11
  const MAX_LIGHTS = 5;
@@ -68,7 +69,11 @@ export type LightingUniforms = {
68
69
 
69
70
  /** UBO ready lighting module */
70
71
  export const lighting = {
72
+ props: {} as LightingProps,
73
+ uniforms: {} as LightingUniforms,
74
+
71
75
  name: 'lighting',
76
+
72
77
  defines: {
73
78
  MAX_LIGHTS
74
79
  },
@@ -96,11 +101,10 @@ export const lighting = {
96
101
  lightDirection: [1, 1, 1],
97
102
  lightAttenuation: [1, 1, 1]
98
103
  },
99
- vs: lightingUniforms,
100
- fs: lightingUniforms,
104
+ source: lightingUniformsWGSL,
105
+ vs: lightingUniformsGLSL,
106
+ fs: lightingUniformsGLSL,
101
107
 
102
- props: {} as Required<LightingProps>,
103
- uniforms: {} as LightingUniforms,
104
108
  getUniforms
105
109
  } as const satisfies ShaderModule<LightingProps, LightingUniforms>;
106
110
 
@@ -2,37 +2,45 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {NumberArray} from '@math.gl/types';
6
- import {glsl} from '../../../lib/glsl-utils/highlight';
5
+ import type {Vector3Like, TypedArray} from '@math.gl/core';
7
6
  import {ShaderModule} from '../../../lib/shader-module/shader-module';
8
7
 
9
8
  export type DirlightProps = {
10
- lightDirection?: NumberArray | [number, number, number];
9
+ lightDirection?: Vector3Like | TypedArray;
11
10
  };
12
11
 
13
12
  export type DirlightUniforms = DirlightProps;
14
13
 
15
14
  // TODO
16
- export const VS_WGSL = /* WGSL */ `\
17
- void dirlight_setNormal(normal: vec3<f32>) {
18
- dirlight_vNormal = normalize(normal);
19
- }
20
- `;
15
+ export const SOURCE_WGSL = /* WGSL */ `\
16
+ struct dirlightUniforms {
17
+ lightDirection: vec3<f32>,
18
+ };
21
19
 
22
- // TODO
23
- export const FS_WGSL = /* WGSL */ `\
24
- uniform dirlightUniforms {
25
- vec3 lightDirection;
26
- } dirlight;
20
+ alias DirlightNormal = vec3<f32>;
21
+
22
+ struct DirlightInputs {
23
+ normal: DirlightNormal,
24
+ };
25
+
26
+ @binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;
27
+
28
+ // For vertex
29
+ fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {
30
+ return normalize(normal);
31
+ }
27
32
 
28
33
  // Returns color attenuated by angle from light source
29
- fn dirlight_filterColor(color: vec4<f32>, dirlightInputs): vec4<f32> {
30
- const d: float = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
34
+ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
35
+ // TODO - fix default light direction
36
+ // let lightDirection = dirlight.lightDirection;
37
+ let lightDirection = vec3<f32>(1, 1, 1);
38
+ let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
31
39
  return vec4<f32>(color.rgb * d, color.a);
32
40
  }
33
41
  `;
34
42
 
35
- const VS_GLSL = glsl`\
43
+ const VS_GLSL = /* glsl */ `\
36
44
  out vec3 dirlight_vNormal;
37
45
 
38
46
  void dirlight_setNormal(vec3 normal) {
@@ -40,7 +48,7 @@ void dirlight_setNormal(vec3 normal) {
40
48
  }
41
49
  `;
42
50
 
43
- const FS_GLSL = glsl`\
51
+ const FS_GLSL = /* glsl */ `\
44
52
  uniform dirlightUniforms {
45
53
  vec3 lightDirection;
46
54
  } dirlight;
@@ -58,10 +66,15 @@ vec4 dirlight_filterColor(vec4 color) {
58
66
  * Cheap lighting - single directional light, single dot product, one uniform
59
67
  */
60
68
  export const dirlight = {
69
+ props: {} as DirlightProps,
70
+ uniforms: {} as DirlightUniforms,
71
+
61
72
  name: 'dirlight',
62
73
  dependencies: [],
74
+ source: SOURCE_WGSL,
63
75
  vs: VS_GLSL,
64
76
  fs: FS_GLSL,
77
+
65
78
  // fragmentInputs: [
66
79
  // {
67
80
  // name: 'dirlight_vNormal',
@@ -74,8 +87,6 @@ export const dirlight = {
74
87
  defaultUniforms: {
75
88
  lightDirection: new Float32Array([1, 1, 2])
76
89
  },
77
- props: {} as Required<DirlightProps>,
78
- uniforms: {} as DirlightUniforms,
79
90
  getUniforms
80
91
  } as const satisfies ShaderModule<DirlightProps, DirlightUniforms>;
81
92
 
@@ -9,9 +9,8 @@
9
9
  // a microfacet surface material defined by a glTF model.
10
10
 
11
11
  // TODO - better do the checks outside of shader
12
- import {glsl} from '../../../lib/glsl-utils/highlight';
13
12
 
14
- export const fs = glsl`\
13
+ export const fs = /* glsl */ `\
15
14
  precision highp float;
16
15
 
17
16
  uniform Projection {