@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
@@ -11,8 +11,8 @@ declare function getUniforms(opts?: ProjectionProps, prevUniforms?: {}): Record<
11
11
  export declare const project: {
12
12
  readonly name: "project";
13
13
  readonly getUniforms: typeof getUniforms;
14
- readonly vs: string;
15
- readonly fs: string;
14
+ readonly vs: "varying vec4 project_vPositionWorld;\nvarying vec3 project_vNormalWorld;\n\nvec4 project_getPosition_World() {\n return project_vPositionWorld;\n}\n\nvec3 project_getNormal_World() {\n return project_vNormalWorld;\n}\n\n\n// Unprefixed uniforms\nuniform mat4 modelMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewProjectionMatrix;\nuniform vec3 cameraPositionWorld;\n\nstruct World {\n vec3 position;\n vec3 normal;\n};\n\nWorld world;\n\nvoid project_setPosition(vec4 position) {\n project_vPositionWorld = position;\n}\n\nvoid project_setNormal(vec3 normal) {\n project_vNormalWorld = normal;\n}\n\nvoid project_setPositionAndNormal_World(vec3 position, vec3 normal) {\n world.position = position;\n world.normal = normal;\n}\n\nvoid project_setPositionAndNormal_Model(vec3 position, vec3 normal) {\n world.position = (modelMatrix * vec4(position, 1.)).xyz;\n world.normal = mat3(modelMatrix) * normal;\n}\n\nvec4 project_model_to_clipspace(vec4 position) {\n return viewProjectionMatrix * modelMatrix * position;\n}\n\nvec4 project_model_to_clipspace(vec3 position) {\n return viewProjectionMatrix * modelMatrix * vec4(position, 1.);\n}\n\nvec4 project_world_to_clipspace(vec3 position) {\n return viewProjectionMatrix * vec4(position, 1.);\n}\n\nvec4 project_view_to_clipspace(vec3 position) {\n return projectionMatrix * vec4(position, 1.);\n}\n\nvec4 project_to_clipspace(vec3 position) {\n return viewProjectionMatrix * vec4(position, 1.);\n}\n";
15
+ readonly fs: "\nvarying vec4 project_vPositionWorld;\nvarying vec3 project_vNormalWorld;\n\nvec4 project_getPosition_World() {\n return project_vPositionWorld;\n}\n\nvec3 project_getNormal_World() {\n return project_vNormalWorld;\n}\n";
16
16
  };
17
17
  export {};
18
18
  //# sourceMappingURL=project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/modules-webgl1/project/project.ts"],"names":[],"mappings":"AAQA,KAAK,eAAe,GAAG;IACrB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAAC;AAWF,iBAAS,WAAW,CAAC,IAAI,GAAE,eAAwC,EAAE,YAAY,KAAK,uBA2BrF;AA2ED;;GAEG;AACH,eAAO,MAAM,OAAO;;;;;CAK+C,CAAC"}
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/modules-webgl1/project/project.ts"],"names":[],"mappings":"AAOA,KAAK,eAAe,GAAG;IACrB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAAC;AAWF,iBAAS,WAAW,CAAC,IAAI,GAAE,eAAwC,EAAE,YAAY,KAAK,uBA2BrF;AA2ED;;GAEG;AACH,eAAO,MAAM,OAAO;;;;;CAK+C,CAAC"}
@@ -2,7 +2,6 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
  import { Matrix4 } from '@math.gl/core';
5
- import { glsl } from "../../lib/glsl-utils/highlight.js";
6
5
  const IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
7
6
  const DEFAULT_MODULE_OPTIONS = {
8
7
  modelMatrix: IDENTITY_MATRIX,
@@ -33,14 +32,16 @@ function getUniforms(opts = DEFAULT_MODULE_OPTIONS, prevUniforms = {}) {
33
32
  }
34
33
  return uniforms;
35
34
  }
36
- const common = `\
35
+ const common = /* glsl */ `\
37
36
  varying vec4 project_vPositionWorld;
38
37
  varying vec3 project_vNormalWorld;
38
+
39
39
  vec4 project_getPosition_World() {
40
- return project_vPositionWorld;
40
+ return project_vPositionWorld;
41
41
  }
42
+
42
43
  vec3 project_getNormal_World() {
43
- return project_vNormalWorld;
44
+ return project_vNormalWorld;
44
45
  }
45
46
  `;
46
47
  const vs = `\
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/shadertools",
3
- "version": "9.1.0-alpha.1",
3
+ "version": "9.1.0-alpha.12",
4
4
  "description": "Shader module system for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,12 +46,12 @@
46
46
  "prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
47
47
  },
48
48
  "peerDependencies": {
49
- "@luma.gl/core": "^9.0.0-beta"
49
+ "@luma.gl/core": "9.1.0-alpha.10"
50
50
  },
51
51
  "dependencies": {
52
- "@math.gl/core": "^4.0.0",
53
- "@math.gl/types": "^4.0.0",
52
+ "@math.gl/core": "4.1.0-alpha.3",
53
+ "@math.gl/types": "4.1.0-alpha.3",
54
54
  "wgsl_reflect": "^1.0.1"
55
55
  },
56
- "gitHead": "bc5c11c87f1e4db857e701688ca1410d7f51fd0f"
56
+ "gitHead": "61b0080d5beb5284b8bdcec5cf59e13cda65295a"
57
57
  }
package/src/index.ts CHANGED
@@ -8,20 +8,27 @@
8
8
  * Marks GLSL shaders for syntax highlighting: glsl`...`
9
9
  * Install https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
10
10
  */
11
- export {glsl} from './lib/glsl-utils/highlight';
12
-
13
11
  export type {PlatformInfo} from './lib/shader-assembly/platform-info';
14
12
 
13
+ // ShaderModules
14
+
15
15
  export type {ShaderModule} from './lib/shader-module/shader-module';
16
16
  export type {ShaderPass} from './lib/shader-module/shader-pass';
17
- export type {ShaderHook} from './lib/shader-assembly/shader-hooks';
18
- export type {ShaderInjection} from './lib/shader-assembly/shader-injections';
19
- export {ShaderModuleInstance} from './lib/shader-module/shader-module-instance';
17
+
18
+ export {initializeShaderModule, initializeShaderModules} from './lib/shader-module/shader-module';
19
+ export {getShaderModuleUniforms} from './lib/shader-module/shader-module';
20
+ export {getShaderModuleDependencies} from './lib/shader-module/shader-module-dependencies';
21
+ export {checkShaderModuleDeprecations} from './lib/shader-module/shader-module';
22
+
23
+ export {getShaderModuleSource} from './lib/shader-assembly/assemble-shaders';
24
+
25
+ export {resolveModules as _resolveModules} from './lib/shader-module/shader-module-dependencies';
26
+ export {getDependencyGraph as _getDependencyGraph} from './lib/shader-module/shader-module-dependencies';
20
27
 
21
28
  // ShaderAssembler
22
29
  export {ShaderAssembler} from './lib/shader-assembler';
23
-
24
- export {normalizeShaderModule} from './lib/shader-module/normalize-shader-module';
30
+ export type {ShaderHook} from './lib/shader-assembly/shader-hooks';
31
+ export type {ShaderInjection} from './lib/shader-assembly/shader-injections';
25
32
 
26
33
  // SHADER HELPERS
27
34
 
@@ -43,10 +50,7 @@ export {capitalize} from './lib/shader-generator/utils/capitalize';
43
50
  // TEST EXPORTS - Do not use in production applications
44
51
  export {preprocess} from './lib/preprocessor/preprocessor';
45
52
  export {assembleGLSLShaderPair} from './lib/shader-assembly/assemble-shaders';
46
- export {ShaderModuleInstance as _ShaderModuleInstance} from './lib/shader-module/shader-module-instance';
47
53
  export {combineInjects} from './lib/shader-assembly/shader-injections';
48
- export {resolveModules as _resolveModules} from './lib/shader-assembly/resolve-modules';
49
- export {getDependencyGraph as _getDependencyGraph} from './lib/shader-assembly/resolve-modules';
50
54
 
51
55
  // EXPERIMENTAL WGSL
52
56
  export {getShaderLayoutFromWGSL} from './lib/wgsl/get-shader-layout-wgsl';
@@ -66,11 +70,11 @@ export {fp32} from './modules/math/fp32/fp32';
66
70
  // // projection
67
71
  // export type {ProjectionUniforms} from './modules/engine/project/project';
68
72
  // export {projection} from './modules/engine/project/project';
69
- export type {PickingProps} from './modules/engine/picking/picking';
73
+ export type {PickingProps, PickingUniforms} from './modules/engine/picking/picking';
70
74
  export {picking} from './modules/engine/picking/picking';
71
75
 
72
76
  // // lighting
73
- export type {LightingProps} from './modules/lighting/lights/lighting';
77
+ export type {LightingProps, LightingUniforms} from './modules/lighting/lights/lighting';
74
78
  export {lighting} from './modules/lighting/lights/lighting';
75
79
  export {dirlight} from './modules/lighting/no-material/dirlight';
76
80
  export type {PhongMaterialUniforms as GouraudMaterialUniforms} from './modules/lighting/phong-material/phong-material';
@@ -83,55 +87,97 @@ export {pbrMaterial} from './modules/lighting/pbr-material/pbr-material';
83
87
  // POST PROCESSING / SHADER PASS MODULES
84
88
 
85
89
  // glfx image adjustment shader modules
86
- export type {BrightnessContrastProps} from './modules/postprocessing/image-adjust-filters/brightnesscontrast';
90
+ export type {
91
+ BrightnessContrastProps,
92
+ BrightnessContrastUniforms
93
+ } from './modules/postprocessing/image-adjust-filters/brightnesscontrast';
87
94
  export {brightnessContrast} from './modules/postprocessing/image-adjust-filters/brightnesscontrast';
88
- export type {DenoiseProps} from './modules/postprocessing/image-adjust-filters/denoise';
95
+ export type {
96
+ DenoiseProps,
97
+ DenoiseUniforms
98
+ } from './modules/postprocessing/image-adjust-filters/denoise';
89
99
  export {denoise} from './modules/postprocessing/image-adjust-filters/denoise';
90
- export type {HueSaturationProps} from './modules/postprocessing/image-adjust-filters/huesaturation';
100
+ export type {
101
+ HueSaturationProps,
102
+ HueSaturationUniforms
103
+ } from './modules/postprocessing/image-adjust-filters/huesaturation';
91
104
  export {hueSaturation} from './modules/postprocessing/image-adjust-filters/huesaturation';
92
- export type {NoiseProps} from './modules/postprocessing/image-adjust-filters/noise';
105
+ export type {NoiseProps, NoiseUniforms} from './modules/postprocessing/image-adjust-filters/noise';
93
106
  export {noise} from './modules/postprocessing/image-adjust-filters/noise';
94
- export type {SepiaProps} from './modules/postprocessing/image-adjust-filters/sepia';
107
+ export type {SepiaProps, SepiaUniforms} from './modules/postprocessing/image-adjust-filters/sepia';
95
108
  export {sepia} from './modules/postprocessing/image-adjust-filters/sepia';
96
- export type {VibranceProps} from './modules/postprocessing/image-adjust-filters/vibrance';
109
+ export type {
110
+ VibranceProps,
111
+ VibranceUniforms
112
+ } from './modules/postprocessing/image-adjust-filters/vibrance';
97
113
  export {vibrance} from './modules/postprocessing/image-adjust-filters/vibrance';
98
- export type {VignetteProps} from './modules/postprocessing/image-adjust-filters/vignette';
114
+ export type {
115
+ VignetteProps,
116
+ VignetteUniforms
117
+ } from './modules/postprocessing/image-adjust-filters/vignette';
99
118
  export {vignette} from './modules/postprocessing/image-adjust-filters/vignette';
100
119
 
101
120
  // glfx BLUR shader modules
102
- export type {TiltShiftProps} from './modules/postprocessing/image-blur-filters/tiltshift';
121
+ export type {
122
+ TiltShiftProps,
123
+ TiltShiftUniforms
124
+ } from './modules/postprocessing/image-blur-filters/tiltshift';
103
125
  export {tiltShift} from './modules/postprocessing/image-blur-filters/tiltshift';
104
- export type {TriangleBlurProps} from './modules/postprocessing/image-blur-filters/triangleblur';
126
+ export type {
127
+ TriangleBlurProps,
128
+ TriangleBlurUniforms
129
+ } from './modules/postprocessing/image-blur-filters/triangleblur';
105
130
  export {triangleBlur} from './modules/postprocessing/image-blur-filters/triangleblur';
106
- export type {ZoomBlurProps} from './modules/postprocessing/image-blur-filters/zoomblur';
131
+ export type {
132
+ ZoomBlurProps,
133
+ ZoomBlurUniforms
134
+ } from './modules/postprocessing/image-blur-filters/zoomblur';
107
135
  export {zoomBlur} from './modules/postprocessing/image-blur-filters/zoomblur';
108
136
 
109
137
  // glfx FUN shader modules
110
- export type {ColorHalftoneProps} from './modules/postprocessing/image-fun-filters/colorhalftone';
138
+ export type {
139
+ ColorHalftoneProps,
140
+ ColorHalftoneUniforms
141
+ } from './modules/postprocessing/image-fun-filters/colorhalftone';
111
142
  export {colorHalftone} from './modules/postprocessing/image-fun-filters/colorhalftone';
112
- export type {DotScreenProps} from './modules/postprocessing/image-fun-filters/dotscreen';
143
+ export type {
144
+ DotScreenProps,
145
+ DotScreenUniforms
146
+ } from './modules/postprocessing/image-fun-filters/dotscreen';
113
147
  export {dotScreen} from './modules/postprocessing/image-fun-filters/dotscreen';
114
- export type {EdgeWorkProps} from './modules/postprocessing/image-fun-filters/edgework';
148
+ export type {
149
+ EdgeWorkProps,
150
+ EdgeWorkUniforms
151
+ } from './modules/postprocessing/image-fun-filters/edgework';
115
152
  export {edgeWork} from './modules/postprocessing/image-fun-filters/edgework';
116
- export type {HexagonalPixelateProps} from './modules/postprocessing/image-fun-filters/hexagonalpixelate';
153
+ export type {
154
+ HexagonalPixelateProps,
155
+ HexagonalPixelateUniforms
156
+ } from './modules/postprocessing/image-fun-filters/hexagonalpixelate';
117
157
  export {hexagonalPixelate} from './modules/postprocessing/image-fun-filters/hexagonalpixelate';
118
- export type {InkProps} from './modules/postprocessing/image-fun-filters/ink';
158
+ export type {InkProps, InkUniforms} from './modules/postprocessing/image-fun-filters/ink';
119
159
  export {ink} from './modules/postprocessing/image-fun-filters/ink';
120
- export type {MagnifyProps} from './modules/postprocessing/image-fun-filters/magnify';
160
+ export type {
161
+ MagnifyProps,
162
+ MagnifyUniforms
163
+ } from './modules/postprocessing/image-fun-filters/magnify';
121
164
  export {magnify} from './modules/postprocessing/image-fun-filters/magnify';
122
165
 
123
166
  // glfx WARP shader modules
124
- export type {BulgePinchProps} from './modules/postprocessing/image-warp-filters/bulgepinch';
167
+ export type {
168
+ BulgePinchProps,
169
+ BulgePinchUniforms
170
+ } from './modules/postprocessing/image-warp-filters/bulgepinch';
125
171
  export {bulgePinch} from './modules/postprocessing/image-warp-filters/bulgepinch';
126
- export type {SwirlProps} from './modules/postprocessing/image-warp-filters/swirl';
172
+ export type {SwirlProps, SwirlUniforms} from './modules/postprocessing/image-warp-filters/swirl';
127
173
  export {swirl} from './modules/postprocessing/image-warp-filters/swirl';
128
174
 
129
175
  // Postprocessing modules
130
- // export type {FXAAProps} from './modules/postprocessing/fxaa/fxaa';
176
+ // export type {FXAAProps, FXAAUniforms} from './modules/postprocessing/fxaa/fxaa';
131
177
  export {fxaa} from './modules/postprocessing/fxaa/fxaa';
132
178
 
133
179
  // experimental modules
134
- export type {WarpProps} from './modules/postprocessing/image-warp-filters/warp';
180
+ export type {WarpProps, WarpUniforms} from './modules/postprocessing/image-warp-filters/warp';
135
181
  export {warp as _warp} from './modules/postprocessing/image-warp-filters/warp';
136
182
 
137
183
  // DEPRECATED - v8 legacy shader modules (non-uniform buffer)
@@ -2,9 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {glsl} from './highlight';
6
-
7
- const FS_GLES = glsl`\
5
+ const FS_GLES = /* glsl */ `\
8
6
  out vec4 transform_output;
9
7
  void main() {
10
8
  transform_output = vec4(0);
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {ShaderModule} from './shader-module/shader-module';
6
- import {ShaderModuleInstance} from './shader-module/shader-module-instance';
6
+ import {initializeShaderModules} from './shader-module/shader-module';
7
7
  import {
8
8
  AssembleShaderProps,
9
9
  GetUniformsFunc,
@@ -76,7 +76,7 @@ export class ShaderAssembler {
76
76
  assembleWGSLShader(props: AssembleShaderProps): {
77
77
  source: string;
78
78
  getUniforms: GetUniformsFunc;
79
- modules: ShaderModuleInstance[];
79
+ modules: ShaderModule[];
80
80
  } {
81
81
  const modules = this._getModuleList(props.modules); // Combine with default modules
82
82
  const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions
@@ -103,7 +103,7 @@ export class ShaderAssembler {
103
103
  vs: string;
104
104
  fs: string;
105
105
  getUniforms: GetUniformsFunc;
106
- modules: ShaderModuleInstance[];
106
+ modules: ShaderModule[];
107
107
  } {
108
108
  const modules = this._getModuleList(props.modules); // Combine with default modules
109
109
  const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions
@@ -123,10 +123,8 @@ export class ShaderAssembler {
123
123
  /**
124
124
  * Dedupe and combine with default modules
125
125
  */
126
- _getModuleList(appModules: (ShaderModule | ShaderModuleInstance)[] = []): ShaderModuleInstance[] {
127
- const modules = new Array<ShaderModule | ShaderModuleInstance>(
128
- this._defaultModules.length + appModules.length
129
- );
126
+ _getModuleList(appModules: ShaderModule[] = []): ShaderModule[] {
127
+ const modules = new Array<ShaderModule>(this._defaultModules.length + appModules.length);
130
128
  const seen: Record<string, boolean> = {};
131
129
  let count = 0;
132
130
 
@@ -148,6 +146,7 @@ export class ShaderAssembler {
148
146
 
149
147
  modules.length = count;
150
148
 
151
- return ShaderModuleInstance.instantiateModules(modules);
149
+ initializeShaderModules(modules);
150
+ return modules;
152
151
  }
153
152
  }
@@ -2,13 +2,12 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {glsl} from '../glsl-utils/highlight';
6
- import {resolveModules} from './resolve-modules';
5
+ import {getShaderModuleDependencies} from '../shader-module/shader-module-dependencies';
7
6
  import {PlatformInfo} from './platform-info';
8
7
  import {getPlatformShaderDefines} from './platform-defines';
9
8
  import {injectShader, DECLARATION_INJECT_MARKER} from './shader-injections';
10
9
  import {transpileGLSLShader} from '../shader-transpiler/transpile-glsl-shader';
11
- import {ShaderModuleInstance} from '../shader-module/shader-module-instance';
10
+ import {checkShaderModuleDeprecations} from '../shader-module/shader-module';
12
11
  import type {ShaderInjection} from './shader-injections';
13
12
  import type {ShaderModule} from '../shader-module/shader-module';
14
13
  import {ShaderHook, normalizeShaderHooks, getShaderHooks} from './shader-hooks';
@@ -24,7 +23,7 @@ const INJECT_SHADER_DECLARATIONS = `\n\n${DECLARATION_INJECT_MARKER}\n`;
24
23
  * Precision prologue to inject before functions are injected in shader
25
24
  * TODO - extract any existing prologue in the fragment source and move it up...
26
25
  */
27
- const FRAGMENT_SHADER_PROLOGUE = glsl`\
26
+ const FRAGMENT_SHADER_PROLOGUE = /* glsl */ `\
28
27
  precision highp float;
29
28
  `;
30
29
 
@@ -47,7 +46,7 @@ export type AssembleShaderOptions = {
47
46
  /** Inject shader id #defines */
48
47
  id?: string;
49
48
  /** Modules to be injected */
50
- modules?: (ShaderModule | ShaderModuleInstance)[];
49
+ modules?: ShaderModule[];
51
50
  /** Defines to be injected */
52
51
  defines?: Record<string, ShaderDefine>;
53
52
  /** Hook functions */
@@ -99,7 +98,8 @@ export function assembleWGSLShader(
99
98
  source: string;
100
99
  getUniforms: GetUniformsFunc;
101
100
  } {
102
- const modules = resolveModules(options.modules || []);
101
+ const modules = getShaderModuleDependencies(options.modules || []);
102
+
103
103
  return {
104
104
  source: assembleShaderWGSL(options.platformInfo, {
105
105
  ...options,
@@ -127,7 +127,7 @@ export function assembleGLSLShaderPair(
127
127
  getUniforms: GetUniformsFunc;
128
128
  } {
129
129
  const {vs, fs} = options;
130
- const modules = resolveModules(options.modules || []);
130
+ const modules = getShaderModuleDependencies(options.modules || []);
131
131
 
132
132
  return {
133
133
  vs: assembleShaderGLSL(options.platformInfo, {
@@ -224,17 +224,17 @@ export function assembleShaderWGSL(platformInfo: PlatformInfo, options: Assemble
224
224
  }
225
225
 
226
226
  // TODO - hack until shadertool modules support WebGPU
227
- const modulesToInject = platformInfo.type !== 'webgpu' ? modules : [];
227
+ const modulesToInject = modules;
228
228
 
229
229
  for (const module of modulesToInject) {
230
230
  if (log) {
231
- module.checkDeprecations(coreSource, log);
231
+ checkShaderModuleDeprecations(module, coreSource, log);
232
232
  }
233
- const moduleSource = module.getModuleSource(stage, 'wgsl');
233
+ const moduleSource = getShaderModuleSource(module, 'wgsl');
234
234
  // Add the module source, and a #define that declares it presence
235
235
  assembledSource += moduleSource;
236
236
 
237
- const injections = module.injections[stage];
237
+ const injections = module.injections?.[stage] || {};
238
238
  for (const key in injections) {
239
239
  const match = /^(v|f)s:#([\w-]+)$/.exec(key);
240
240
  if (match) {
@@ -279,7 +279,7 @@ function assembleShaderGLSL(
279
279
  source: string;
280
280
  language?: 'glsl' | 'wgsl';
281
281
  stage: 'vertex' | 'fragment';
282
- modules: ShaderModuleInstance[];
282
+ modules: ShaderModule[];
283
283
  defines?: Record<string, ShaderDefine>;
284
284
  hookFunctions?: any[];
285
285
  inject?: Record<string, string | ShaderInjection>;
@@ -314,7 +314,7 @@ function assembleShaderGLSL(
314
314
  // Combine Module and Application Defines
315
315
  const allDefines = {};
316
316
  modules.forEach(module => {
317
- Object.assign(allDefines, module.getDefines());
317
+ Object.assign(allDefines, module.defines);
318
318
  });
319
319
  Object.assign(allDefines, defines);
320
320
 
@@ -333,6 +333,7 @@ ${sourceVersionDirective}
333
333
  // ----- PROLOGUE -------------------------
334
334
  ${getShaderNameDefine({id, source, stage})}
335
335
  ${`#define SHADER_TYPE_${stage.toUpperCase()}`}
336
+
336
337
  ${getPlatformShaderDefines(platformInfo)}
337
338
  ${stage === 'fragment' ? FRAGMENT_SHADER_PROLOGUE : ''}
338
339
 
@@ -354,7 +355,6 @@ ${getApplicationDefines(allDefines)}
354
355
  const mainInjections: Record<string, ShaderInjection[]> = {};
355
356
 
356
357
  for (const key in inject) {
357
- // @ts-expect-error
358
358
  const injection: ShaderInjection =
359
359
  typeof inject[key] === 'string' ? {injection: inject[key], order: 0} : inject[key];
360
360
  const match = /^(v|f)s:(#)?([\w-]+)$/.exec(key);
@@ -378,13 +378,13 @@ ${getApplicationDefines(allDefines)}
378
378
 
379
379
  for (const module of modules) {
380
380
  if (log) {
381
- module.checkDeprecations(coreSource, log);
381
+ checkShaderModuleDeprecations(module, coreSource, log);
382
382
  }
383
- const moduleSource = module.getModuleSource(stage);
383
+ const moduleSource = getShaderModuleSource(module, stage);
384
384
  // Add the module source, and a #define that declares it presence
385
385
  assembledSource += moduleSource;
386
386
 
387
- const injections = module.injections[stage];
387
+ const injections = module.instance?.normalizedInjections[stage] || {};
388
388
  for (const key in injections) {
389
389
  const match = /^(v|f)s:#([\w-]+)$/.exec(key);
390
390
  if (match) {
@@ -429,13 +429,13 @@ ${getApplicationDefines(allDefines)}
429
429
  * @param modules
430
430
  * @returns
431
431
  */
432
- export function assembleGetUniforms(modules: ShaderModuleInstance[]) {
432
+ export function assembleGetUniforms(modules: ShaderModule[]) {
433
433
  return function getUniforms(opts: Record<string, any>): Record<string, any> {
434
434
  const uniforms = {};
435
435
  for (const module of modules) {
436
436
  // `modules` is already sorted by dependency level. This guarantees that
437
437
  // modules have access to the uniforms that are generated by their dependencies.
438
- const moduleUniforms = module.getUniforms(opts, uniforms);
438
+ const moduleUniforms = module.getUniforms?.(opts, uniforms);
439
439
  Object.assign(uniforms, moduleUniforms);
440
440
  }
441
441
  return uniforms;
@@ -456,9 +456,7 @@ function getShaderNameDefine(options: {
456
456
  const injectShaderName = id && source.indexOf('SHADER_NAME') === -1;
457
457
  return injectShaderName
458
458
  ? `
459
- #define SHADER_NAME ${id}_${stage}
460
-
461
- `
459
+ #define SHADER_NAME ${id}_${stage}`
462
460
  : '';
463
461
  }
464
462
 
@@ -474,6 +472,41 @@ function getApplicationDefines(defines: Record<string, ShaderDefine> = {}): stri
474
472
  return sourceText;
475
473
  }
476
474
 
475
+ /** Extracts the source code chunk for the specified shader type from the named shader module */
476
+ export function getShaderModuleSource(
477
+ module: ShaderModule,
478
+ stage: 'vertex' | 'fragment' | 'wgsl'
479
+ ): string {
480
+ let moduleSource;
481
+ switch (stage) {
482
+ case 'vertex':
483
+ moduleSource = module.vs || '';
484
+ break;
485
+ case 'fragment':
486
+ moduleSource = module.fs || '';
487
+ break;
488
+ case 'wgsl':
489
+ moduleSource = module.source || '';
490
+ break;
491
+ default:
492
+ assert(false);
493
+ }
494
+
495
+ if (!module.name) {
496
+ throw new Error('Shader module must have a name');
497
+ }
498
+ const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, '_');
499
+ let source = `\
500
+ // ----- MODULE ${module.name} ---------------
501
+
502
+ `;
503
+ if (stage !== 'wgsl') {
504
+ source += `#define MODULE_${moduleName}\n`;
505
+ }
506
+ source += `${moduleSource}\n`;
507
+ return source;
508
+ }
509
+
477
510
  /*
478
511
  function getHookFunctions(
479
512
  hookFunctions: Record<string, HookFunction>,
@@ -2,14 +2,13 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {glsl} from '../glsl-utils/highlight';
6
5
  import {PlatformInfo} from './platform-info';
7
6
 
8
7
  /** Adds defines to help identify GPU architecture / platform */
9
8
  export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
10
9
  switch (platformInfo?.gpu.toLowerCase()) {
11
10
  case 'apple':
12
- return glsl`\
11
+ return /* glsl */ `\
13
12
  #define APPLE_GPU
14
13
  // Apple optimizes away the calculation necessary for emulated fp64
15
14
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
@@ -19,14 +18,14 @@ export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
19
18
  `;
20
19
 
21
20
  case 'nvidia':
22
- return glsl`\
21
+ return /* glsl */ `\
23
22
  #define NVIDIA_GPU
24
23
  // Nvidia optimizes away the calculation necessary for emulated fp64
25
24
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
26
25
  `;
27
26
 
28
27
  case 'intel':
29
- return glsl`\
28
+ return /* glsl */ `\
30
29
  #define INTEL_GPU
31
30
  // Intel optimizes away the calculation necessary for emulated fp64
32
31
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
@@ -38,7 +37,7 @@ export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
38
37
 
39
38
  case 'amd':
40
39
  // AMD Does not eliminate fp64 code
41
- return glsl`\
40
+ return /* glsl */ `\
42
41
  #define AMD_GPU
43
42
  `;
44
43
 
@@ -46,7 +45,7 @@ export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
46
45
  // We don't know what GPU it is, could be that the GPU driver or
47
46
  // browser is not implementing UNMASKED_RENDERER constant and not
48
47
  // reporting a correct name
49
- return glsl`\
48
+ return /* glsl */ `\
50
49
  #define DEFAULT_GPU
51
50
  // Prevent driver from optimizing away the calculation necessary for emulated fp64
52
51
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
@@ -0,0 +1,111 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {ShaderModule, initializeShaderModules} from './shader-module';
6
+
7
+ // import type {ShaderModule} from '../shader-module/shader-module';
8
+
9
+ type AbstractModule = {
10
+ name: string;
11
+ dependencies?: AbstractModule[];
12
+ };
13
+
14
+ /**
15
+ * Takes a list of shader module names and returns a new list of
16
+ * shader module names that includes all dependencies, sorted so
17
+ * that modules that are dependencies of other modules come first.
18
+ *
19
+ * If the shader glsl code from the returned modules is concatenated
20
+ * in the reverse order, it is guaranteed that all functions be resolved and
21
+ * that all function and variable definitions come before use.
22
+ *
23
+ * @param modules - Array of modules (inline modules or module names)
24
+ * @return - Array of modules
25
+ */
26
+ export function getShaderModuleDependencies<T extends AbstractModule>(modules: T[]): T[] {
27
+ initializeShaderModules(modules);
28
+ const moduleMap: Record<string, T> = {};
29
+ const moduleDepth: Record<string, number> = {};
30
+ getDependencyGraph({modules, level: 0, moduleMap, moduleDepth});
31
+
32
+ // Return a reverse sort so that dependencies come before the modules that use them
33
+ const dependencies = Object.keys(moduleDepth)
34
+ .sort((a, b) => moduleDepth[b] - moduleDepth[a])
35
+ .map(name => moduleMap[name]);
36
+ initializeShaderModules(dependencies);
37
+ return dependencies;
38
+ }
39
+
40
+ /**
41
+ * Recursively checks module dependencies to calculate dependency level of each module.
42
+ *
43
+ * @param options.modules - Array of modules
44
+ * @param options.level - Current level
45
+ * @param options.moduleMap -
46
+ * @param options.moduleDepth - Current level
47
+ * @return - Map of module name to its level
48
+ */
49
+ // Adds another level of dependencies to the result map
50
+ export function getDependencyGraph<T extends AbstractModule>(options: {
51
+ modules: T[];
52
+ level: number;
53
+ moduleMap: Record<string, T>;
54
+ moduleDepth: Record<string, number>;
55
+ }) {
56
+ const {modules, level, moduleMap, moduleDepth} = options;
57
+ if (level >= 5) {
58
+ throw new Error('Possible loop in shader dependency graph');
59
+ }
60
+
61
+ // Update level on all current modules
62
+ for (const module of modules) {
63
+ moduleMap[module.name] = module;
64
+ if (moduleDepth[module.name] === undefined || moduleDepth[module.name] < level) {
65
+ moduleDepth[module.name] = level;
66
+ }
67
+ }
68
+
69
+ // Recurse
70
+ for (const module of modules) {
71
+ if (module.dependencies) {
72
+ getDependencyGraph({modules: module.dependencies, level: level + 1, moduleMap, moduleDepth});
73
+ }
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Takes a list of shader module names and returns a new list of
79
+ * shader module names that includes all dependencies, sorted so
80
+ * that modules that are dependencies of other modules come first.
81
+ *
82
+ * If the shader glsl code from the returned modules is concatenated
83
+ * in the reverse order, it is guaranteed that all functions be resolved and
84
+ * that all function and variable definitions come before use.
85
+ *
86
+ * @param modules - Array of modules (inline modules or module names)
87
+ * @return - Array of modules
88
+ */
89
+ export function getShaderDependencies(modules: ShaderModule[]): ShaderModule[] {
90
+ initializeShaderModules(modules);
91
+ const moduleMap: Record<string, ShaderModule> = {};
92
+ const moduleDepth: Record<string, number> = {};
93
+ getDependencyGraph({modules, level: 0, moduleMap, moduleDepth});
94
+
95
+ // Return a reverse sort so that dependencies come before the modules that use them
96
+ modules = Object.keys(moduleDepth)
97
+ .sort((a, b) => moduleDepth[b] - moduleDepth[a])
98
+ .map(name => moduleMap[name]);
99
+ initializeShaderModules(modules);
100
+ return modules;
101
+ }
102
+
103
+ // DEPRECATED
104
+
105
+ /**
106
+ * Instantiate shader modules and resolve any dependencies
107
+ * @deprecated Use getShaderDpendencies
108
+ */
109
+ export function resolveModules(modules: ShaderModule[]): ShaderModule[] {
110
+ return getShaderDependencies(modules);
111
+ }