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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/dist/dist.dev.js +816 -483
  2. package/dist/dist.min.js +2325 -1622
  3. package/dist/index.cjs +2669 -1808
  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 +43 -16
  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 +29 -11
  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 +4 -4
  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 +9 -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.d.ts +4 -4
  49. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  50. package/dist/modules/lighting/lights/lighting.js +2 -2
  51. package/dist/modules/lighting/no-material/dirlight.d.ts +4 -4
  52. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  53. package/dist/modules/lighting/no-material/dirlight.js +12 -9
  54. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
  55. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
  56. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +304 -181
  57. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +71 -69
  58. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  59. package/dist/modules/lighting/pbr-material/pbr-material.js +4 -2
  60. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +1 -1
  61. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +1 -1
  62. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +38 -20
  63. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
  64. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
  65. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +21 -16
  66. package/dist/modules/lighting/phong-material/phong-material.d.ts +12 -12
  67. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  68. package/dist/modules/lighting/phong-material/phong-material.js +3 -3
  69. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  70. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  71. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +82 -54
  72. package/dist/modules/math/fp32/fp32.d.ts.map +1 -1
  73. package/dist/modules/math/fp32/fp32.js +127 -100
  74. package/dist/modules/math/random/random.d.ts +1 -1
  75. package/dist/modules/math/random/random.d.ts.map +1 -1
  76. package/dist/modules/math/random/random.js +3 -3
  77. package/dist/modules/module-injectors.d.ts +2 -2
  78. package/dist/modules/module-injectors.d.ts.map +1 -1
  79. package/dist/modules/module-injectors.js +13 -10
  80. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +4 -1
  81. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
  82. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.js +16 -12
  83. package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts +4 -1
  84. package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
  85. package/dist/modules/postprocessing/image-adjust-filters/denoise.js +21 -17
  86. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts +5 -2
  87. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  88. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.js +29 -22
  89. package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts +4 -1
  90. package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
  91. package/dist/modules/postprocessing/image-adjust-filters/noise.js +14 -10
  92. package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts +4 -1
  93. package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
  94. package/dist/modules/postprocessing/image-adjust-filters/sepia.js +17 -12
  95. package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts +4 -1
  96. package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
  97. package/dist/modules/postprocessing/image-adjust-filters/vibrance.js +12 -9
  98. package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts +4 -1
  99. package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
  100. package/dist/modules/postprocessing/image-adjust-filters/vignette.js +13 -10
  101. package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts +5 -2
  102. package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
  103. package/dist/modules/postprocessing/image-blur-filters/tiltshift.js +40 -26
  104. package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts +5 -2
  105. package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
  106. package/dist/modules/postprocessing/image-blur-filters/triangleblur.js +32 -19
  107. package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts +4 -1
  108. package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
  109. package/dist/modules/postprocessing/image-blur-filters/zoomblur.js +2 -0
  110. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts +4 -1
  111. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
  112. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.js +31 -27
  113. package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts +4 -1
  114. package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
  115. package/dist/modules/postprocessing/image-fun-filters/dotscreen.js +19 -15
  116. package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts +8 -5
  117. package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
  118. package/dist/modules/postprocessing/image-fun-filters/edgework.js +53 -42
  119. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +4 -1
  120. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
  121. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.js +41 -33
  122. package/dist/modules/postprocessing/image-fun-filters/ink.d.ts +4 -1
  123. package/dist/modules/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
  124. package/dist/modules/postprocessing/image-fun-filters/ink.js +27 -25
  125. package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts +2 -1
  126. package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
  127. package/dist/modules/postprocessing/image-fun-filters/magnify.js +17 -16
  128. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts +5 -2
  129. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
  130. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.js +24 -20
  131. package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts +5 -2
  132. package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
  133. package/dist/modules/postprocessing/image-warp-filters/swirl.js +26 -22
  134. package/dist/modules/postprocessing/image-warp-filters/warp.d.ts +2 -1
  135. package/dist/modules/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
  136. package/dist/modules/postprocessing/image-warp-filters/warp.js +9 -8
  137. package/dist/modules-webgl1/geometry/geometry.d.ts.map +1 -1
  138. package/dist/modules-webgl1/geometry/geometry.js +12 -8
  139. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +1 -1
  140. package/dist/modules-webgl1/lighting/dirlight/dirlight.js +8 -5
  141. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +1 -1
  142. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +1 -1
  143. package/dist/modules-webgl1/lighting/lights/lights-glsl.js +19 -11
  144. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +1 -1
  145. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +1 -1
  146. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +268 -157
  147. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +1 -1
  148. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +1 -1
  149. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +16 -12
  150. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +1 -1
  151. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +1 -1
  152. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +64 -55
  153. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  154. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  155. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +113 -81
  156. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +1 -1
  157. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +1 -1
  158. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +588 -433
  159. package/dist/modules-webgl1/project/project.d.ts +2 -2
  160. package/dist/modules-webgl1/project/project.d.ts.map +1 -1
  161. package/dist/modules-webgl1/project/project.js +5 -4
  162. package/package.json +2 -2
  163. package/src/index.ts +78 -32
  164. package/src/lib/glsl-utils/shader-utils.ts +1 -3
  165. package/src/lib/shader-assembler.ts +7 -8
  166. package/src/lib/shader-assembly/assemble-shaders.ts +52 -20
  167. package/src/lib/shader-assembly/platform-defines.ts +5 -6
  168. package/src/lib/shader-module/shader-module-dependencies.ts +112 -0
  169. package/src/lib/shader-module/shader-module.ts +129 -18
  170. package/src/lib/shader-module/shader-pass.ts +3 -2
  171. package/src/module-injectors.ts +2 -4
  172. package/src/modules/engine/geometry/geometry.ts +2 -3
  173. package/src/modules/engine/picking/picking.ts +7 -5
  174. package/src/modules/engine/project/project.ts +2 -3
  175. package/src/modules/engine/transform/transform.ts +1 -3
  176. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  177. package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +2 -4
  178. package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +1 -3
  179. package/src/modules/lighting/lights/lighting.ts +4 -2
  180. package/src/modules/lighting/no-material/dirlight.ts +6 -5
  181. package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +1 -2
  182. package/src/modules/lighting/pbr-material/pbr-material.ts +44 -38
  183. package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +1 -3
  184. package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +1 -3
  185. package/src/modules/lighting/phong-material/phong-material.ts +4 -3
  186. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -4
  187. package/src/modules/math/fp32/fp32.ts +1 -2
  188. package/src/modules/math/random/random.ts +1 -2
  189. package/src/modules/module-injectors.ts +2 -4
  190. package/src/modules/postprocessing/image-adjust-filters/brightnesscontrast.ts +6 -2
  191. package/src/modules/postprocessing/image-adjust-filters/denoise.ts +7 -3
  192. package/src/modules/postprocessing/image-adjust-filters/huesaturation.ts +9 -4
  193. package/src/modules/postprocessing/image-adjust-filters/noise.ts +6 -2
  194. package/src/modules/postprocessing/image-adjust-filters/sepia.ts +6 -2
  195. package/src/modules/postprocessing/image-adjust-filters/vibrance.ts +5 -2
  196. package/src/modules/postprocessing/image-adjust-filters/vignette.ts +11 -4
  197. package/src/modules/postprocessing/image-blur-filters/tiltshift.ts +6 -2
  198. package/src/modules/postprocessing/image-blur-filters/triangleblur.ts +6 -2
  199. package/src/modules/postprocessing/image-blur-filters/zoomblur.ts +5 -0
  200. package/src/modules/postprocessing/image-fun-filters/colorhalftone.ts +6 -2
  201. package/src/modules/postprocessing/image-fun-filters/dotscreen.ts +6 -2
  202. package/src/modules/postprocessing/image-fun-filters/edgework.ts +10 -4
  203. package/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts +6 -2
  204. package/src/modules/postprocessing/image-fun-filters/ink.ts +8 -3
  205. package/src/modules/postprocessing/image-fun-filters/magnify.ts +3 -2
  206. package/src/modules/postprocessing/image-warp-filters/bulgepinch.ts +6 -2
  207. package/src/modules/postprocessing/image-warp-filters/swirl.ts +8 -2
  208. package/src/modules/postprocessing/image-warp-filters/warp.ts +3 -2
  209. package/src/modules-webgl1/geometry/geometry.ts +2 -3
  210. package/src/modules-webgl1/lighting/dirlight/dirlight.ts +1 -2
  211. package/src/modules-webgl1/lighting/lights/lights-glsl.ts +1 -3
  212. package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +1 -2
  213. package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +1 -3
  214. package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +1 -3
  215. package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +1 -3
  216. package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +1 -3
  217. package/src/modules-webgl1/project/project.ts +1 -2
  218. package/dist/lib/glsl-utils/highlight.d.ts +0 -6
  219. package/dist/lib/glsl-utils/highlight.d.ts.map +0 -1
  220. package/dist/lib/glsl-utils/highlight.js +0 -9
  221. package/dist/lib/shader-assembly/resolve-modules.d.ts +0 -40
  222. package/dist/lib/shader-assembly/resolve-modules.d.ts.map +0 -1
  223. package/dist/lib/shader-module/normalize-shader-module.d.ts +0 -3
  224. package/dist/lib/shader-module/normalize-shader-module.d.ts.map +0 -1
  225. package/dist/lib/shader-module/normalize-shader-module.js +0 -14
  226. package/dist/lib/shader-module/shader-module-instance.d.ts +0 -28
  227. package/dist/lib/shader-module/shader-module-instance.d.ts.map +0 -1
  228. package/dist/lib/shader-module/shader-module-instance.js +0 -126
  229. package/src/lib/glsl-utils/highlight.ts +0 -11
  230. package/src/lib/shader-assembly/resolve-modules.ts +0 -81
  231. package/src/lib/shader-module/normalize-shader-module.ts +0 -17
  232. package/src/lib/shader-module/shader-module-instance.ts +0 -167
@@ -2,10 +2,15 @@
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 {NumberArray} from '@math.gl/types';
6
+ import {Sampler, Texture} from '@luma.gl/core';
7
+ import type {UniformFormat} from '../../types';
8
+ import {PropType, PropValidator} from '../filters/prop-types';
9
+ import {ShaderInjection} from '../shader-assembly/shader-injections';
10
+ import {makePropValidators, getValidatedProperties} from '../filters/prop-types';
11
+ import {normalizeInjections} from '../shader-assembly/shader-injections';
8
12
 
13
+ export type BindingValue = Buffer | Texture | Sampler;
9
14
  export type UniformValue = number | boolean | Readonly<NumberArray>; // Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>;
10
15
 
11
16
  export type UniformInfo = {
@@ -14,20 +19,26 @@ export type UniformInfo = {
14
19
 
15
20
  /**
16
21
  * A shader module definition object
17
- * @note Can be viewed as the ShaderModuleProps for a ShaderModuleInstance
22
+ *
23
+ * @note Needs to be initialized with `initializeShaderModules`
18
24
  */
19
25
  export type ShaderModule<
20
26
  PropsT extends Record<string, unknown> = Record<string, unknown>,
21
27
  UniformsT extends Record<string, UniformValue> = Record<string, UniformValue>,
22
- BindingsT extends Record<string, unknown> = {}
28
+ BindingsT extends Record<string, BindingValue> = Record<string, BindingValue>
23
29
  > = {
24
30
  /** Used for type inference not for values */
25
- props?: Required<PropsT>;
31
+ props?: PropsT;
26
32
  /** Used for type inference, not currently used for values */
27
33
  uniforms?: UniformsT;
28
34
 
29
35
  name: string;
36
+
37
+ /** WGSL code */
38
+ source?: string;
39
+ /** GLSL fragment shader code */
30
40
  fs?: string;
41
+ /** GLSL vertex shader code */
31
42
  vs?: string;
32
43
 
33
44
  /** Uniform shader types @note: Both order and types MUST match uniform block declarations in shader */
@@ -37,9 +48,8 @@ export type ShaderModule<
37
48
  /** Default uniform values */
38
49
  defaultUniforms?: Required<UniformsT>; // Record<keyof UniformsT, UniformValue>;
39
50
 
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>;
51
+ /** Function that maps props to uniforms & bindings */
52
+ getUniforms?: (props?: any, oldProps?: any) => Record<string, BindingValue | UniformValue>;
43
53
 
44
54
  /** uniform buffers, textures, samplers, storage, ... */
45
55
  bindings?: Record<keyof BindingsT, {location: number; type: 'texture' | 'sampler' | 'uniforms'}>;
@@ -51,8 +61,16 @@ export type ShaderModule<
51
61
  /** Information on deprecated properties */
52
62
  deprecations?: ShaderModuleDeprecation[];
53
63
 
54
- /** Internal */
55
- normalized?: boolean;
64
+ /** The instance field contains information that is generated at run-time */
65
+ instance?: {
66
+ propValidators?: Record<string, PropValidator>;
67
+ parsedDeprecations: ShaderModuleDeprecation[];
68
+
69
+ normalizedInjections: {
70
+ vertex: Record<string, ShaderInjection>;
71
+ fragment: Record<string, ShaderInjection>;
72
+ };
73
+ };
56
74
  };
57
75
 
58
76
  /** Use to generate deprecations when shader module is used */
@@ -64,16 +82,109 @@ export type ShaderModuleDeprecation = {
64
82
  deprecated?: boolean;
65
83
  };
66
84
 
85
+ // SHNDER MODULE API
86
+
87
+ export function initializeShaderModules(modules: ShaderModule[]): void {
88
+ modules.map((module: ShaderModule) => initializeShaderModule(module));
89
+ }
90
+
91
+ export function initializeShaderModule(module: ShaderModule): void {
92
+ if (module.instance) {
93
+ return;
94
+ }
95
+
96
+ initializeShaderModules(module.dependencies || []);
97
+
98
+ const {
99
+ uniformPropTypes = {},
100
+ deprecations = [],
101
+ // defines = {},
102
+ inject = {}
103
+ } = module;
104
+
105
+ const instance: Required<ShaderModule>['instance'] = {
106
+ normalizedInjections: normalizeInjections(inject),
107
+ parsedDeprecations: parseDeprecationDefinitions(deprecations)
108
+ };
109
+
110
+ if (uniformPropTypes) {
111
+ instance.propValidators = makePropValidators(uniformPropTypes);
112
+ }
113
+
114
+ module.instance = instance;
115
+ }
116
+
67
117
  /** Convert module props to uniforms */
68
118
  export function getShaderModuleUniforms<
69
119
  ShaderModuleT extends ShaderModule<Record<string, unknown>, Record<string, UniformValue>>
70
- >(module: ShaderModuleT, props: ShaderModuleT['props']): ShaderModuleT['uniforms'] {
71
- const uniforms = {...module.defaultUniforms};
120
+ >(
121
+ module: ShaderModuleT,
122
+ props: ShaderModuleT['props'],
123
+ oldUniforms?: ShaderModuleT['uniforms']
124
+ ): Record<string, BindingValue | UniformValue> {
125
+ initializeShaderModule(module);
126
+
127
+ const uniforms = oldUniforms || {...module.defaultUniforms};
128
+ // If module has a getUniforms function, use it
72
129
  if (module.getUniforms) {
73
- // @ts-expect-error
74
- Object.assign(props, module.getUniforms(props));
75
- } else {
76
- Object.assign(uniforms, props);
130
+ return module.getUniforms(props, uniforms);
77
131
  }
78
- return uniforms;
132
+
133
+ // Build uniforms from the uniforms array
134
+ // @ts-expect-error
135
+ return getValidatedProperties(props, module.instance?.propValidators, module.name);
136
+ }
137
+
138
+ /* TODO this looks like it was unused code
139
+ _defaultGetUniforms(opts: Record<string, any> = {}): Record<string, any> {
140
+ const uniforms: Record<string, any> = {};
141
+ const propTypes = this.uniforms;
142
+
143
+ for (const key in propTypes) {
144
+ const propDef = propTypes[key];
145
+ if (key in opts && !propDef.private) {
146
+ if (propDef.validate) {
147
+ assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);
148
+ }
149
+ uniforms[key] = opts[key];
150
+ } else {
151
+ uniforms[key] = propDef.value;
152
+ }
153
+ }
154
+
155
+ return uniforms;
156
+ }
157
+ }
158
+ */
159
+ // Warn about deprecated uniforms or functions
160
+ export function checkShaderModuleDeprecations(
161
+ shaderModule: ShaderModule,
162
+ shaderSource: string,
163
+ log: any
164
+ ): void {
165
+ shaderModule.deprecations?.forEach(def => {
166
+ if (def.regex?.test(shaderSource)) {
167
+ if (def.deprecated) {
168
+ log.deprecated(def.old, def.new)();
169
+ } else {
170
+ log.removed(def.old, def.new)();
171
+ }
172
+ }
173
+ });
174
+ }
175
+
176
+ // HELPERS
177
+
178
+ function parseDeprecationDefinitions(deprecations: ShaderModuleDeprecation[]) {
179
+ deprecations.forEach(def => {
180
+ switch (def.type) {
181
+ case 'function':
182
+ def.regex = new RegExp(`\\b${def.old}\\(`);
183
+ break;
184
+ default:
185
+ def.regex = new RegExp(`${def.type} ${def.old};`);
186
+ }
187
+ });
188
+
189
+ return deprecations;
79
190
  }
@@ -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
 
@@ -3,7 +3,6 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {NumberArray} from '../../../types';
6
- import {glsl} from '../../../lib/glsl-utils/highlight';
7
6
  import {ShaderModule} from '../../../lib/shader-module/shader-module';
8
7
 
9
8
  // cyan color
@@ -50,7 +49,7 @@ export type PickingUniforms = {
50
49
  highlightColor?: NumberArray;
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 lightingUniforms = /* 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))
@@ -68,7 +68,11 @@ export type LightingUniforms = {
68
68
 
69
69
  /** UBO ready lighting module */
70
70
  export const lighting = {
71
+ props: {} as LightingProps,
72
+ uniforms: {} as LightingUniforms,
73
+
71
74
  name: 'lighting',
75
+
72
76
  defines: {
73
77
  MAX_LIGHTS
74
78
  },
@@ -99,8 +103,6 @@ export const lighting = {
99
103
  vs: lightingUniforms,
100
104
  fs: lightingUniforms,
101
105
 
102
- props: {} as Required<LightingProps>,
103
- uniforms: {} as LightingUniforms,
104
106
  getUniforms
105
107
  } as const satisfies ShaderModule<LightingProps, LightingUniforms>;
106
108
 
@@ -3,7 +3,6 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {NumberArray} from '@math.gl/types';
6
- import {glsl} from '../../../lib/glsl-utils/highlight';
7
6
  import {ShaderModule} from '../../../lib/shader-module/shader-module';
8
7
 
9
8
  export type DirlightProps = {
@@ -32,7 +31,7 @@ fn dirlight_filterColor(color: vec4<f32>, dirlightInputs): vec4<f32> {
32
31
  }
33
32
  `;
34
33
 
35
- const VS_GLSL = glsl`\
34
+ const VS_GLSL = /* glsl */ `\
36
35
  out vec3 dirlight_vNormal;
37
36
 
38
37
  void dirlight_setNormal(vec3 normal) {
@@ -40,7 +39,7 @@ void dirlight_setNormal(vec3 normal) {
40
39
  }
41
40
  `;
42
41
 
43
- const FS_GLSL = glsl`\
42
+ const FS_GLSL = /* glsl */ `\
44
43
  uniform dirlightUniforms {
45
44
  vec3 lightDirection;
46
45
  } dirlight;
@@ -58,10 +57,14 @@ vec4 dirlight_filterColor(vec4 color) {
58
57
  * Cheap lighting - single directional light, single dot product, one uniform
59
58
  */
60
59
  export const dirlight = {
60
+ props: {} as DirlightProps,
61
+ uniforms: {} as DirlightUniforms,
62
+
61
63
  name: 'dirlight',
62
64
  dependencies: [],
63
65
  vs: VS_GLSL,
64
66
  fs: FS_GLSL,
67
+
65
68
  // fragmentInputs: [
66
69
  // {
67
70
  // name: 'dirlight_vNormal',
@@ -74,8 +77,6 @@ export const dirlight = {
74
77
  defaultUniforms: {
75
78
  lightDirection: new Float32Array([1, 1, 2])
76
79
  },
77
- props: {} as Required<DirlightProps>,
78
- uniforms: {} as DirlightUniforms,
79
80
  getUniforms
80
81
  } as const satisfies ShaderModule<DirlightProps, DirlightUniforms>;
81
82
 
@@ -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 {
@@ -15,35 +15,35 @@ import {vs} from './pbr-vertex-glsl';
15
15
  import {fs} from './pbr-fragment-glsl';
16
16
 
17
17
  export type PBRMaterialProps = PBRMaterialBindings & {
18
- unlit: boolean;
18
+ unlit?: boolean;
19
19
 
20
20
  // Base color map
21
- baseColorMapEnabled: boolean;
22
- baseColorFactor: Readonly<Vector4 | NumberArray>;
21
+ baseColorMapEnabled?: boolean;
22
+ baseColorFactor?: Readonly<Vector4 | NumberArray>;
23
23
 
24
- normalMapEnabled: boolean;
25
- normalScale: number; // #ifdef HAS_NORMALMAP
24
+ normalMapEnabled?: boolean;
25
+ normalScale?: number; // #ifdef HAS_NORMALMAP
26
26
 
27
- emissiveMapEnabled: boolean;
28
- emissiveFactor: Readonly<Vector3 | NumberArray>; // #ifdef HAS_EMISSIVEMAP
27
+ emissiveMapEnabled?: boolean;
28
+ emissiveFactor?: Readonly<Vector3 | NumberArray>; // #ifdef HAS_EMISSIVEMAP
29
29
 
30
- metallicRoughnessValues: Readonly<Vector2 | NumberArray>;
31
- metallicRoughnessMapEnabled: boolean;
30
+ metallicRoughnessValues?: Readonly<Vector2 | NumberArray>;
31
+ metallicRoughnessMapEnabled?: boolean;
32
32
 
33
- occlusionMapEnabled: boolean;
34
- occlusionStrength: number; // #ifdef HAS_OCCLUSIONMAP
33
+ occlusionMapEnabled?: boolean;
34
+ occlusionStrength?: number; // #ifdef HAS_OCCLUSIONMAP
35
35
 
36
- alphaCutoffEnabled: boolean;
37
- alphaCutoff: number; // #ifdef ALPHA_CUTOFF
36
+ alphaCutoffEnabled?: boolean;
37
+ alphaCutoff?: number; // #ifdef ALPHA_CUTOFF
38
38
 
39
39
  // IBL
40
- IBLenabled: boolean;
41
- scaleIBLAmbient: Readonly<Vector2 | NumberArray>; // #ifdef USE_IBL
40
+ IBLenabled?: boolean;
41
+ scaleIBLAmbient?: Readonly<Vector2 | NumberArray>; // #ifdef USE_IBL
42
42
 
43
43
  // debugging flags used for shader output of intermediate PBR variables
44
44
  // #ifdef PBR_DEBUG
45
- scaleDiffBaseMR: Readonly<Vector4 | NumberArray>;
46
- scaleFGDSpec: Readonly<Vector4 | NumberArray>;
45
+ scaleDiffBaseMR?: Readonly<Vector4 | NumberArray>;
46
+ scaleFGDSpec?: Readonly<Vector4 | NumberArray>;
47
47
  };
48
48
 
49
49
  /** Non-uniform block bindings for pbr module */
@@ -56,41 +56,41 @@ type PBRMaterialBindings = {
56
56
  occlusionSampler?: Texture | null; // #ifdef HAS_OCCLUSIONMAP
57
57
 
58
58
  // IBL Samplers
59
- diffuseEnvSampler: Texture | null; // #ifdef USE_IBL (samplerCube)
60
- specularEnvSampler: Texture | null; // #ifdef USE_IBL (samplerCube)
59
+ diffuseEnvSampler?: Texture | null; // #ifdef USE_IBL (samplerCube)
60
+ specularEnvSampler?: Texture | null; // #ifdef USE_IBL (samplerCube)
61
61
  brdfLUT?: Texture | null; // #ifdef USE_IBL
62
62
  };
63
63
 
64
64
  export type PBRMaterialUniforms = {
65
- unlit: boolean;
65
+ unlit?: boolean;
66
66
 
67
67
  // Base color map
68
- baseColorMapEnabled: boolean;
69
- baseColorFactor: Readonly<Vector4 | NumberArray>;
68
+ baseColorMapEnabled?: boolean;
69
+ baseColorFactor?: Readonly<Vector4 | NumberArray>;
70
70
 
71
- normalMapEnabled: boolean;
72
- normalScale: number; // #ifdef HAS_NORMALMAP
71
+ normalMapEnabled?: boolean;
72
+ normalScale?: number; // #ifdef HAS_NORMALMAP
73
73
 
74
- emissiveMapEnabled: boolean;
75
- emissiveFactor: Readonly<Vector3 | NumberArray>; // #ifdef HAS_EMISSIVEMAP
74
+ emissiveMapEnabled?: boolean;
75
+ emissiveFactor?: Readonly<Vector3 | NumberArray>; // #ifdef HAS_EMISSIVEMAP
76
76
 
77
- metallicRoughnessValues: Readonly<Vector2 | NumberArray>;
78
- metallicRoughnessMapEnabled: boolean;
77
+ metallicRoughnessValues?: Readonly<Vector2 | NumberArray>;
78
+ metallicRoughnessMapEnabled?: boolean;
79
79
 
80
- occlusionMapEnabled: boolean;
81
- occlusionStrength: number; // #ifdef HAS_OCCLUSIONMAP
80
+ occlusionMapEnabled?: boolean;
81
+ occlusionStrength?: number; // #ifdef HAS_OCCLUSIONMAP
82
82
 
83
- alphaCutoffEnabled: boolean;
84
- alphaCutoff: number; // #ifdef ALPHA_CUTOFF
83
+ alphaCutoffEnabled?: boolean;
84
+ alphaCutoff?: number; // #ifdef ALPHA_CUTOFF
85
85
 
86
86
  // IBL
87
- IBLenabled: boolean;
88
- scaleIBLAmbient: Readonly<Vector2 | NumberArray>; // #ifdef USE_IBL
87
+ IBLenabled?: boolean;
88
+ scaleIBLAmbient?: Readonly<Vector2 | NumberArray>; // #ifdef USE_IBL
89
89
 
90
90
  // debugging flags used for shader output of intermediate PBR variables
91
91
  // #ifdef PBR_DEBUG
92
- scaleDiffBaseMR: Readonly<Vector4 | NumberArray>;
93
- scaleFGDSpec: Readonly<Vector4 | NumberArray>;
92
+ scaleDiffBaseMR?: Readonly<Vector4 | NumberArray>;
93
+ scaleFGDSpec?: Readonly<Vector4 | NumberArray>;
94
94
  };
95
95
 
96
96
  /**
@@ -98,9 +98,14 @@ export type PBRMaterialUniforms = {
98
98
  * Physically Based Shading of a microfacet surface defined by a glTF material.
99
99
  */
100
100
  export const pbrMaterial = {
101
+ props: {} as PBRMaterialProps,
102
+ uniforms: {} as PBRMaterialUniforms,
103
+
101
104
  name: 'pbr',
105
+ dependencies: [lighting],
102
106
  vs,
103
107
  fs,
108
+
104
109
  defines: {
105
110
  LIGHTING_FRAGMENT: 1,
106
111
  HAS_NORMALMAP: 0,
@@ -112,6 +117,7 @@ export const pbrMaterial = {
112
117
  USE_IBL: 0,
113
118
  PBR_DEBUG: 0
114
119
  },
120
+
115
121
  uniformTypes: {
116
122
  // Material is unlit
117
123
  unlit: 'i32',
@@ -144,6 +150,7 @@ export const pbrMaterial = {
144
150
  scaleDiffBaseMR: 'vec4<f32>',
145
151
  scaleFGDSpec: 'vec4<f32>'
146
152
  },
153
+
147
154
  bindings: {
148
155
  baseColorSampler: {type: 'texture', location: 8}, // #ifdef HAS_BASECOLORMAP
149
156
  normalSampler: {type: 'texture', location: 9}, // #ifdef HAS_NORMALMAP
@@ -154,6 +161,5 @@ export const pbrMaterial = {
154
161
  diffuseEnvSampler: {type: 'texture', location: 13}, // #ifdef USE_IBL (samplerCube)
155
162
  specularEnvSampler: {type: 'texture', location: 14}, // #ifdef USE_IBL (samplerCube)
156
163
  brdfLUT: {type: 'texture', location: 15} // #ifdef USE_IBL
157
- },
158
- dependencies: [lighting]
164
+ }
159
165
  } as const satisfies ShaderModule<PBRMaterialProps, PBRMaterialUniforms>;
@@ -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 pbrMaterialUniforms = glsl`\
5
+ export const pbrMaterialUniforms = /* glsl */ `\
8
6
  uniform Projection {
9
7
  // Projection
10
8
  vec3 u_Camera;
@@ -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 vs = glsl`\
5
+ export const vs = /* glsl */ `\
8
6
  uniform projection {
9
7
  mat4 u_MVPMatrix;
10
8
  mat4 u_ModelMatrix;