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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/dist/dist.dev.js +1005 -487
  2. package/dist/dist.min.js +2489 -1625
  3. package/dist/index.cjs +2864 -1817
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +29 -28
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +8 -12
  8. package/dist/lib/glsl-utils/shader-utils.d.ts.map +1 -1
  9. package/dist/lib/glsl-utils/shader-utils.js +2 -3
  10. package/dist/lib/shader-assembler.d.ts +3 -4
  11. package/dist/lib/shader-assembler.d.ts.map +1 -1
  12. package/dist/lib/shader-assembler.js +3 -2
  13. package/dist/lib/shader-assembly/assemble-shaders.d.ts +4 -3
  14. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  15. package/dist/lib/shader-assembly/assemble-shaders.js +46 -18
  16. package/dist/lib/shader-assembly/platform-defines.d.ts.map +1 -1
  17. package/dist/lib/shader-assembly/platform-defines.js +14 -6
  18. package/dist/lib/shader-module/shader-module-dependencies.d.ts +53 -0
  19. package/dist/lib/shader-module/shader-module-dependencies.d.ts.map +1 -0
  20. package/dist/lib/{shader-assembly/resolve-modules.js → shader-module/shader-module-dependencies.js} +38 -14
  21. package/dist/lib/shader-module/shader-module.d.ts +30 -12
  22. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  23. package/dist/lib/shader-module/shader-module.js +76 -6
  24. package/dist/lib/shader-module/shader-pass.d.ts +3 -2
  25. package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
  26. package/dist/module-injectors.d.ts +2 -2
  27. package/dist/module-injectors.d.ts.map +1 -1
  28. package/dist/module-injectors.js +13 -10
  29. package/dist/modules/engine/geometry/geometry.d.ts.map +1 -1
  30. package/dist/modules/engine/geometry/geometry.js +12 -8
  31. package/dist/modules/engine/picking/picking.d.ts +9 -9
  32. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  33. package/dist/modules/engine/picking/picking.js +103 -66
  34. package/dist/modules/engine/project/project.d.ts +2 -2
  35. package/dist/modules/engine/project/project.d.ts.map +1 -1
  36. package/dist/modules/engine/project/project.js +36 -22
  37. package/dist/modules/engine/transform/transform.d.ts.map +1 -1
  38. package/dist/modules/engine/transform/transform.js +28 -16
  39. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +10 -7
  40. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  41. package/dist/modules/lighting/gouraud-material/gouraud-material.js +2 -0
  42. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +2 -2
  43. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +1 -1
  44. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +79 -53
  45. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
  46. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
  47. package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +38 -23
  48. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts +2 -0
  49. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +1 -0
  50. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js +56 -0
  51. package/dist/modules/lighting/lights/lighting.d.ts +5 -4
  52. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  53. package/dist/modules/lighting/lights/lighting.js +7 -5
  54. package/dist/modules/lighting/no-material/dirlight.d.ts +8 -8
  55. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  56. package/dist/modules/lighting/no-material/dirlight.js +34 -20
  57. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
  58. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
  59. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +304 -181
  60. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +72 -69
  61. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  62. package/dist/modules/lighting/pbr-material/pbr-material.js +4 -2
  63. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +1 -1
  64. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +1 -1
  65. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +38 -20
  66. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
  67. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
  68. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +21 -16
  69. package/dist/modules/lighting/phong-material/phong-material.d.ts +14 -12
  70. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  71. package/dist/modules/lighting/phong-material/phong-material.js +5 -3
  72. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  73. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  74. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +82 -54
  75. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +41 -0
  76. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -0
  77. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +130 -0
  78. package/dist/modules/math/fp32/fp32.d.ts.map +1 -1
  79. package/dist/modules/math/fp32/fp32.js +127 -100
  80. package/dist/modules/math/fp64/fp64-utils.d.ts +3 -3
  81. package/dist/modules/math/fp64/fp64-utils.d.ts.map +1 -1
  82. package/dist/modules/math/random/random.d.ts +1 -1
  83. package/dist/modules/math/random/random.d.ts.map +1 -1
  84. package/dist/modules/math/random/random.js +3 -3
  85. package/dist/modules/module-injectors.d.ts +2 -2
  86. package/dist/modules/module-injectors.d.ts.map +1 -1
  87. package/dist/modules/module-injectors.js +13 -10
  88. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +4 -1
  89. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
  90. package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.js +16 -12
  91. package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts +4 -1
  92. package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
  93. package/dist/modules/postprocessing/image-adjust-filters/denoise.js +21 -17
  94. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts +5 -2
  95. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  96. package/dist/modules/postprocessing/image-adjust-filters/huesaturation.js +29 -22
  97. package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts +4 -1
  98. package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
  99. package/dist/modules/postprocessing/image-adjust-filters/noise.js +14 -10
  100. package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts +4 -1
  101. package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
  102. package/dist/modules/postprocessing/image-adjust-filters/sepia.js +17 -12
  103. package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts +4 -1
  104. package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
  105. package/dist/modules/postprocessing/image-adjust-filters/vibrance.js +12 -9
  106. package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts +4 -1
  107. package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
  108. package/dist/modules/postprocessing/image-adjust-filters/vignette.js +13 -10
  109. package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts +5 -2
  110. package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
  111. package/dist/modules/postprocessing/image-blur-filters/tiltshift.js +40 -26
  112. package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts +5 -2
  113. package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
  114. package/dist/modules/postprocessing/image-blur-filters/triangleblur.js +32 -19
  115. package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts +4 -1
  116. package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
  117. package/dist/modules/postprocessing/image-blur-filters/zoomblur.js +2 -0
  118. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts +4 -1
  119. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
  120. package/dist/modules/postprocessing/image-fun-filters/colorhalftone.js +31 -27
  121. package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts +4 -1
  122. package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
  123. package/dist/modules/postprocessing/image-fun-filters/dotscreen.js +19 -15
  124. package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts +8 -5
  125. package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
  126. package/dist/modules/postprocessing/image-fun-filters/edgework.js +53 -42
  127. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +4 -1
  128. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
  129. package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.js +41 -33
  130. package/dist/modules/postprocessing/image-fun-filters/ink.d.ts +4 -1
  131. package/dist/modules/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
  132. package/dist/modules/postprocessing/image-fun-filters/ink.js +27 -25
  133. package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts +2 -1
  134. package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
  135. package/dist/modules/postprocessing/image-fun-filters/magnify.js +17 -16
  136. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts +5 -2
  137. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
  138. package/dist/modules/postprocessing/image-warp-filters/bulgepinch.js +24 -20
  139. package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts +5 -2
  140. package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
  141. package/dist/modules/postprocessing/image-warp-filters/swirl.js +26 -22
  142. package/dist/modules/postprocessing/image-warp-filters/warp.d.ts +2 -1
  143. package/dist/modules/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
  144. package/dist/modules/postprocessing/image-warp-filters/warp.js +9 -8
  145. package/dist/modules-webgl1/geometry/geometry.d.ts.map +1 -1
  146. package/dist/modules-webgl1/geometry/geometry.js +12 -8
  147. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +2 -2
  148. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +1 -1
  149. package/dist/modules-webgl1/lighting/dirlight/dirlight.js +8 -5
  150. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +1 -1
  151. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +1 -1
  152. package/dist/modules-webgl1/lighting/lights/lights-glsl.js +19 -11
  153. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +1 -1
  154. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +1 -1
  155. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +268 -157
  156. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +1 -1
  157. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +1 -1
  158. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +16 -12
  159. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +1 -1
  160. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +1 -1
  161. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +64 -55
  162. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  163. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  164. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +113 -81
  165. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +1 -1
  166. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +1 -1
  167. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +588 -433
  168. package/dist/modules-webgl1/project/project.d.ts +2 -2
  169. package/dist/modules-webgl1/project/project.d.ts.map +1 -1
  170. package/dist/modules-webgl1/project/project.js +5 -4
  171. package/package.json +5 -5
  172. package/src/index.ts +78 -32
  173. package/src/lib/glsl-utils/shader-utils.ts +1 -3
  174. package/src/lib/shader-assembler.ts +7 -8
  175. package/src/lib/shader-assembly/assemble-shaders.ts +55 -22
  176. package/src/lib/shader-assembly/platform-defines.ts +5 -6
  177. package/src/lib/shader-module/shader-module-dependencies.ts +111 -0
  178. package/src/lib/shader-module/shader-module.ts +134 -19
  179. package/src/lib/shader-module/shader-pass.ts +3 -2
  180. package/src/module-injectors.ts +2 -4
  181. package/src/modules/engine/geometry/geometry.ts +2 -3
  182. package/src/modules/engine/picking/picking.ts +12 -10
  183. package/src/modules/engine/project/project.ts +2 -3
  184. package/src/modules/engine/transform/transform.ts +1 -3
  185. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  186. package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +2 -4
  187. package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +1 -3
  188. package/src/modules/lighting/lights/lighting-uniforms-wgsl.ts +57 -0
  189. package/src/modules/lighting/lights/lighting.ts +9 -5
  190. package/src/modules/lighting/no-material/dirlight.ts +30 -19
  191. package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +1 -2
  192. package/src/modules/lighting/pbr-material/pbr-material.ts +44 -38
  193. package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +1 -3
  194. package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +1 -3
  195. package/src/modules/lighting/phong-material/phong-material.ts +6 -3
  196. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -4
  197. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +132 -0
  198. package/src/modules/math/fp32/fp32.ts +1 -2
  199. package/src/modules/math/fp64/fp64-utils.ts +3 -3
  200. package/src/modules/math/random/random.ts +1 -2
  201. package/src/modules/module-injectors.ts +2 -4
  202. package/src/modules/postprocessing/image-adjust-filters/brightnesscontrast.ts +6 -2
  203. package/src/modules/postprocessing/image-adjust-filters/denoise.ts +7 -3
  204. package/src/modules/postprocessing/image-adjust-filters/huesaturation.ts +9 -4
  205. package/src/modules/postprocessing/image-adjust-filters/noise.ts +6 -2
  206. package/src/modules/postprocessing/image-adjust-filters/sepia.ts +6 -2
  207. package/src/modules/postprocessing/image-adjust-filters/vibrance.ts +5 -2
  208. package/src/modules/postprocessing/image-adjust-filters/vignette.ts +11 -4
  209. package/src/modules/postprocessing/image-blur-filters/tiltshift.ts +6 -2
  210. package/src/modules/postprocessing/image-blur-filters/triangleblur.ts +6 -2
  211. package/src/modules/postprocessing/image-blur-filters/zoomblur.ts +5 -0
  212. package/src/modules/postprocessing/image-fun-filters/colorhalftone.ts +6 -2
  213. package/src/modules/postprocessing/image-fun-filters/dotscreen.ts +6 -2
  214. package/src/modules/postprocessing/image-fun-filters/edgework.ts +10 -4
  215. package/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts +6 -2
  216. package/src/modules/postprocessing/image-fun-filters/ink.ts +8 -3
  217. package/src/modules/postprocessing/image-fun-filters/magnify.ts +3 -2
  218. package/src/modules/postprocessing/image-warp-filters/bulgepinch.ts +6 -2
  219. package/src/modules/postprocessing/image-warp-filters/swirl.ts +8 -2
  220. package/src/modules/postprocessing/image-warp-filters/warp.ts +3 -2
  221. package/src/modules-webgl1/geometry/geometry.ts +2 -3
  222. package/src/modules-webgl1/lighting/dirlight/dirlight.ts +3 -4
  223. package/src/modules-webgl1/lighting/lights/lights-glsl.ts +1 -3
  224. package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +1 -2
  225. package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +1 -3
  226. package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +1 -3
  227. package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +1 -3
  228. package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +1 -3
  229. package/src/modules-webgl1/project/project.ts +1 -2
  230. package/dist/lib/glsl-utils/highlight.d.ts +0 -6
  231. package/dist/lib/glsl-utils/highlight.d.ts.map +0 -1
  232. package/dist/lib/glsl-utils/highlight.js +0 -9
  233. package/dist/lib/shader-assembly/resolve-modules.d.ts +0 -40
  234. package/dist/lib/shader-assembly/resolve-modules.d.ts.map +0 -1
  235. package/dist/lib/shader-module/normalize-shader-module.d.ts +0 -3
  236. package/dist/lib/shader-module/normalize-shader-module.d.ts.map +0 -1
  237. package/dist/lib/shader-module/normalize-shader-module.js +0 -14
  238. package/dist/lib/shader-module/shader-module-instance.d.ts +0 -28
  239. package/dist/lib/shader-module/shader-module-instance.d.ts.map +0 -1
  240. package/dist/lib/shader-module/shader-module-instance.js +0 -126
  241. package/src/lib/glsl-utils/highlight.ts +0 -11
  242. package/src/lib/shader-assembly/resolve-modules.ts +0 -81
  243. package/src/lib/shader-module/normalize-shader-module.ts +0 -17
  244. package/src/lib/shader-module/shader-module-instance.ts +0 -167
@@ -1,70 +1,98 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- import { glsl } from "../../../lib/glsl-utils/highlight.js";
5
- export const PHONG_VS = `\
4
+ export const PHONG_VS = /* glsl */ `\
6
5
  uniform phongMaterialUniforms {
7
- uniform float ambient;
8
- uniform float diffuse;
9
- uniform float shininess;
10
- uniform vec3 specularColor;
6
+ uniform float ambient;
7
+ uniform float diffuse;
8
+ uniform float shininess;
9
+ uniform vec3 specularColor;
11
10
  } material;
12
11
  `;
13
- export const PHONG_FS = `\
12
+ export const PHONG_FS = /* glsl */ `\
14
13
  uniform phongMaterialUniforms {
15
- uniform float ambient;
16
- uniform float diffuse;
17
- uniform float shininess;
18
- uniform vec3 specularColor;
14
+ uniform float ambient;
15
+ uniform float diffuse;
16
+ uniform float shininess;
17
+ uniform vec3 specularColor;
19
18
  } material;
19
+
20
20
  vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
21
- vec3 halfway_direction = normalize(light_direction + view_direction);
22
- float lambertian = dot(light_direction, normal_worldspace);
23
- float specular = 0.0;
24
- if (lambertian > 0.0) {
25
- float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
26
- specular = pow(specular_angle, material.shininess);
27
- }
28
- lambertian = max(lambertian, 0.0);
29
- return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
21
+ vec3 halfway_direction = normalize(light_direction + view_direction);
22
+ float lambertian = dot(light_direction, normal_worldspace);
23
+ float specular = 0.0;
24
+ if (lambertian > 0.0) {
25
+ float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
26
+ specular = pow(specular_angle, material.shininess);
27
+ }
28
+ lambertian = max(lambertian, 0.0);
29
+ return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
30
30
  }
31
+
31
32
  vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
32
- vec3 lightColor = surfaceColor;
33
- if (lighting.enabled == 0) {
34
- return lightColor;
35
- }
36
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
37
- lightColor = material.ambient * surfaceColor * lighting.ambientColor;
38
- if (lighting.lightType == 0) {
39
- PointLight pointLight = lighting_getPointLight(0);
40
- vec3 light_position_worldspace = pointLight.position;
41
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
42
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
43
- } else if (lighting.lightType == 1) {
44
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
45
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
46
- }
47
- return lightColor;
33
+ vec3 lightColor = surfaceColor;
34
+
35
+ if (lighting.enabled == 0) {
36
+ return lightColor;
37
+ }
38
+
39
+ vec3 view_direction = normalize(cameraPosition - position_worldspace);
40
+ lightColor = material.ambient * surfaceColor * lighting.ambientColor;
41
+
42
+ if (lighting.lightType == 0) {
43
+ PointLight pointLight = lighting_getPointLight(0);
44
+ vec3 light_position_worldspace = pointLight.position;
45
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
46
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
47
+ } else if (lighting.lightType == 1) {
48
+ DirectionalLight directionalLight = lighting_getDirectionalLight(0);
49
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
50
+ }
51
+
52
+ /*
53
+ for (int i = 0; i < MAX_LIGHTS; i++) {
54
+ if (i >= lighting.pointLightCount) {
55
+ break;
56
+ }
57
+ PointLight pointLight = lighting.pointLight[i];
58
+ vec3 light_position_worldspace = pointLight.position;
59
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
60
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
61
+ }
62
+
63
+ for (int i = 0; i < MAX_LIGHTS; i++) {
64
+ if (i >= lighting.directionalLightCount) {
65
+ break;
66
+ }
67
+ DirectionalLight directionalLight = lighting.directionalLight[i];
68
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
69
+ }
70
+ */
71
+ return lightColor;
48
72
  }
73
+
49
74
  vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
50
- vec3 lightColor = vec3(0, 0, 0);
51
- vec3 surfaceColor = vec3(0, 0, 0);
52
- if (lighting.enabled == 0) {
53
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
54
- switch (lighting.lightType) {
55
- case 0:
56
- PointLight pointLight = lighting_getPointLight(0);
57
- vec3 light_position_worldspace = pointLight.position;
58
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
59
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
60
- break;
61
- case 1:
62
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
63
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
64
- break;
65
- }
66
- }
67
- return lightColor;
75
+ vec3 lightColor = vec3(0, 0, 0);
76
+ vec3 surfaceColor = vec3(0, 0, 0);
77
+
78
+ if (lighting.enabled == 0) {
79
+ vec3 view_direction = normalize(cameraPosition - position_worldspace);
80
+
81
+ switch (lighting.lightType) {
82
+ case 0:
83
+ PointLight pointLight = lighting_getPointLight(0);
84
+ vec3 light_position_worldspace = pointLight.position;
85
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
86
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
87
+ break;
88
+
89
+ case 1:
90
+ DirectionalLight directionalLight = lighting_getDirectionalLight(0);
91
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
92
+ break;
93
+ }
94
+ }
95
+ return lightColor;
68
96
  }
69
97
  `;
70
98
  // TODO - handle multiple lights
@@ -0,0 +1,41 @@
1
+ export declare const PHONG_WGSL = "struct phongMaterialUniforms {\n ambient: f32,\n diffuse: f32,\n shininess: f32,\n specularColor: vec3<f32>,\n};\n\n@binding(2) @group(0) var<uniform> material : phongMaterialUniforms;\n\nfn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {\n let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);\n var lambertian: f32 = dot(light_direction, normal_worldspace);\n var specular: f32 = 0.0;\n if (lambertian > 0.0) {\n let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, material.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;\n}\n\nfn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {\n var lightColor: vec3<f32> = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n } else if (lighting.lightType == 1) {\n var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\n /*\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.pointLightCount) {\n break;\n }\n PointLight pointLight = lighting.pointLight[i];\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.directionalLightCount) {\n break;\n }\n DirectionalLight directionalLight = lighting.directionalLight[i];\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n */\n}\n\nfn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{\n var lightColor = vec3<f32>(0, 0, 0);\n let surfaceColor = vec3<f32>(0, 0, 0);\n\n if (lighting.enabled == 0) {\n let view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0, default: {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n case 1: {\n let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n }\n }\n return lightColor;\n}\n";
2
+ /**
3
+ for (int i = 0; i < MAX_LIGHTS; i++) {
4
+ if (i >= lighting.pointLightCount) {
5
+ break;
6
+ }
7
+ PointLight pointLight = lighting_getPointLight(i);
8
+ vec3 light_position_worldspace = pointLight.position;
9
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
10
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
11
+ }
12
+
13
+ for (int i = 0; i < MAX_LIGHTS; i++) {
14
+ if (i >= lighting.directionalLightCount) {
15
+ break;
16
+ }
17
+ PointLight pointLight = lighting_getDirectionalLight(i);
18
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
19
+ }
20
+ }
21
+ /**
22
+ for (int i = 0; i < MAX_LIGHTS; i++) {
23
+ if (i >= lighting.pointLightCount) {
24
+ break;
25
+ }
26
+ PointLight pointLight = lighting_getPointLight(i);
27
+ vec3 light_position_worldspace = pointLight.position;
28
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
29
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
30
+ }
31
+
32
+ for (int i = 0; i < MAX_LIGHTS; i++) {
33
+ if (i >= lighting.directionalLightCount) {
34
+ break;
35
+ }
36
+ PointLight pointLight = lighting_getDirectionalLight(i);
37
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
38
+ }
39
+ }
40
+ */
41
+ //# sourceMappingURL=phong-shaders-wgsl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phong-shaders-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,gvHAsFtB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
@@ -0,0 +1,130 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export const PHONG_WGSL = /* wgsl */ `\
5
+ struct phongMaterialUniforms {
6
+ ambient: f32,
7
+ diffuse: f32,
8
+ shininess: f32,
9
+ specularColor: vec3<f32>,
10
+ };
11
+
12
+ @binding(2) @group(0) var<uniform> material : phongMaterialUniforms;
13
+
14
+ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
15
+ let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
16
+ var lambertian: f32 = dot(light_direction, normal_worldspace);
17
+ var specular: f32 = 0.0;
18
+ if (lambertian > 0.0) {
19
+ let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
20
+ specular = pow(specular_angle, material.shininess);
21
+ }
22
+ lambertian = max(lambertian, 0.0);
23
+ return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
24
+ }
25
+
26
+ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
27
+ var lightColor: vec3<f32> = surfaceColor;
28
+
29
+ if (lighting.enabled == 0) {
30
+ return lightColor;
31
+ }
32
+
33
+ let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
34
+ lightColor = material.ambient * surfaceColor * lighting.ambientColor;
35
+
36
+ if (lighting.lightType == 0) {
37
+ let pointLight: PointLight = lighting_getPointLight(0);
38
+ let light_position_worldspace: vec3<f32> = pointLight.position;
39
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
40
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
41
+ } else if (lighting.lightType == 1) {
42
+ var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
43
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
44
+ }
45
+
46
+ return lightColor;
47
+ /*
48
+ for (int i = 0; i < MAX_LIGHTS; i++) {
49
+ if (i >= lighting.pointLightCount) {
50
+ break;
51
+ }
52
+ PointLight pointLight = lighting.pointLight[i];
53
+ vec3 light_position_worldspace = pointLight.position;
54
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
55
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
56
+ }
57
+
58
+ for (int i = 0; i < MAX_LIGHTS; i++) {
59
+ if (i >= lighting.directionalLightCount) {
60
+ break;
61
+ }
62
+ DirectionalLight directionalLight = lighting.directionalLight[i];
63
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
64
+ }
65
+ */
66
+ }
67
+
68
+ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{
69
+ var lightColor = vec3<f32>(0, 0, 0);
70
+ let surfaceColor = vec3<f32>(0, 0, 0);
71
+
72
+ if (lighting.enabled == 0) {
73
+ let view_direction = normalize(cameraPosition - position_worldspace);
74
+
75
+ switch (lighting.lightType) {
76
+ case 0, default: {
77
+ let pointLight: PointLight = lighting_getPointLight(0);
78
+ let light_position_worldspace: vec3<f32> = pointLight.position;
79
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
80
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
81
+ }
82
+ case 1: {
83
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
84
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
85
+ }
86
+ }
87
+ }
88
+ return lightColor;
89
+ }
90
+ `;
91
+ // TODO - handle multiple lights
92
+ /**
93
+ for (int i = 0; i < MAX_LIGHTS; i++) {
94
+ if (i >= lighting.pointLightCount) {
95
+ break;
96
+ }
97
+ PointLight pointLight = lighting_getPointLight(i);
98
+ vec3 light_position_worldspace = pointLight.position;
99
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
100
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
101
+ }
102
+
103
+ for (int i = 0; i < MAX_LIGHTS; i++) {
104
+ if (i >= lighting.directionalLightCount) {
105
+ break;
106
+ }
107
+ PointLight pointLight = lighting_getDirectionalLight(i);
108
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
109
+ }
110
+ }
111
+ /**
112
+ for (int i = 0; i < MAX_LIGHTS; i++) {
113
+ if (i >= lighting.pointLightCount) {
114
+ break;
115
+ }
116
+ PointLight pointLight = lighting_getPointLight(i);
117
+ vec3 light_position_worldspace = pointLight.position;
118
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
119
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
120
+ }
121
+
122
+ for (int i = 0; i < MAX_LIGHTS; i++) {
123
+ if (i >= lighting.directionalLightCount) {
124
+ break;
125
+ }
126
+ PointLight pointLight = lighting_getDirectionalLight(i);
127
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
128
+ }
129
+ }
130
+ */
@@ -1 +1 @@
1
- {"version":3,"file":"fp32.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp32/fp32.ts"],"names":[],"mappings":"AAgKA;;GAEG;AACH,eAAO,MAAM,IAAI;;;CAGhB,CAAC"}
1
+ {"version":3,"file":"fp32.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp32/fp32.ts"],"names":[],"mappings":"AA+JA;;GAEG;AACH,eAAO,MAAM,IAAI;;;CAGhB,CAAC"}
@@ -1,129 +1,156 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- import { glsl } from "../../../lib/glsl-utils/highlight.js";
5
4
  // import {ShaderModule} from '../../types';
6
- const fp32shader = `\
5
+ const fp32shader = /* glsl */ `\
7
6
  #ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
7
+
8
+ // All these functions are for substituting tan() function from Intel GPU only
8
9
  const float TWO_PI = 6.2831854820251465;
9
10
  const float PI_2 = 1.5707963705062866;
10
11
  const float PI_16 = 0.1963495463132858;
12
+
11
13
  const float SIN_TABLE_0 = 0.19509032368659973;
12
14
  const float SIN_TABLE_1 = 0.3826834261417389;
13
15
  const float SIN_TABLE_2 = 0.5555702447891235;
14
16
  const float SIN_TABLE_3 = 0.7071067690849304;
17
+
15
18
  const float COS_TABLE_0 = 0.9807852506637573;
16
19
  const float COS_TABLE_1 = 0.9238795042037964;
17
20
  const float COS_TABLE_2 = 0.8314695954322815;
18
21
  const float COS_TABLE_3 = 0.7071067690849304;
19
- const float INVERSE_FACTORIAL_3 = 1.666666716337204e-01;
20
- const float INVERSE_FACTORIAL_5 = 8.333333767950535e-03;
21
- const float INVERSE_FACTORIAL_7 = 1.9841270113829523e-04;
22
- const float INVERSE_FACTORIAL_9 = 2.75573188446287533e-06;
22
+
23
+ const float INVERSE_FACTORIAL_3 = 1.666666716337204e-01; // 1/3!
24
+ const float INVERSE_FACTORIAL_5 = 8.333333767950535e-03; // 1/5!
25
+ const float INVERSE_FACTORIAL_7 = 1.9841270113829523e-04; // 1/7!
26
+ const float INVERSE_FACTORIAL_9 = 2.75573188446287533e-06; // 1/9!
27
+
23
28
  float sin_taylor_fp32(float a) {
24
- float r, s, t, x;
25
- if (a == 0.0) {
26
- return 0.0;
27
- }
28
- x = -a * a;
29
- s = a;
30
- r = a;
31
- r = r * x;
32
- t = r * INVERSE_FACTORIAL_3;
33
- s = s + t;
34
- r = r * x;
35
- t = r * INVERSE_FACTORIAL_5;
36
- s = s + t;
37
- r = r * x;
38
- t = r * INVERSE_FACTORIAL_7;
39
- s = s + t;
40
- r = r * x;
41
- t = r * INVERSE_FACTORIAL_9;
42
- s = s + t;
43
- return s;
29
+ float r, s, t, x;
30
+
31
+ if (a == 0.0) {
32
+ return 0.0;
33
+ }
34
+
35
+ x = -a * a;
36
+ s = a;
37
+ r = a;
38
+
39
+ r = r * x;
40
+ t = r * INVERSE_FACTORIAL_3;
41
+ s = s + t;
42
+
43
+ r = r * x;
44
+ t = r * INVERSE_FACTORIAL_5;
45
+ s = s + t;
46
+
47
+ r = r * x;
48
+ t = r * INVERSE_FACTORIAL_7;
49
+ s = s + t;
50
+
51
+ r = r * x;
52
+ t = r * INVERSE_FACTORIAL_9;
53
+ s = s + t;
54
+
55
+ return s;
44
56
  }
57
+
45
58
  void sincos_taylor_fp32(float a, out float sin_t, out float cos_t) {
46
- if (a == 0.0) {
47
- sin_t = 0.0;
48
- cos_t = 1.0;
49
- }
50
- sin_t = sin_taylor_fp32(a);
51
- cos_t = sqrt(1.0 - sin_t * sin_t);
59
+ if (a == 0.0) {
60
+ sin_t = 0.0;
61
+ cos_t = 1.0;
62
+ }
63
+ sin_t = sin_taylor_fp32(a);
64
+ cos_t = sqrt(1.0 - sin_t * sin_t);
52
65
  }
66
+
53
67
  float tan_taylor_fp32(float a) {
54
- float sin_a;
55
- float cos_a;
56
- if (a == 0.0) {
57
- return 0.0;
58
- }
59
- float z = floor(a / TWO_PI);
60
- float r = a - TWO_PI * z;
61
- float t;
62
- float q = floor(r / PI_2 + 0.5);
63
- int j = int(q);
64
- if (j < -2 || j > 2) {
65
- return 1.0 / 0.0;
66
- }
67
- t = r - PI_2 * q;
68
- q = floor(t / PI_16 + 0.5);
69
- int k = int(q);
70
- int abs_k = int(abs(float(k)));
71
- if (abs_k > 4) {
72
- return 1.0 / 0.0;
73
- } else {
74
- t = t - PI_16 * q;
75
- }
76
- float u = 0.0;
77
- float v = 0.0;
78
- float sin_t, cos_t;
79
- float s, c;
80
- sincos_taylor_fp32(t, sin_t, cos_t);
81
- if (k == 0) {
82
- s = sin_t;
83
- c = cos_t;
84
- } else {
85
- if (abs(float(abs_k) - 1.0) < 0.5) {
86
- u = COS_TABLE_0;
87
- v = SIN_TABLE_0;
88
- } else if (abs(float(abs_k) - 2.0) < 0.5) {
89
- u = COS_TABLE_1;
90
- v = SIN_TABLE_1;
91
- } else if (abs(float(abs_k) - 3.0) < 0.5) {
92
- u = COS_TABLE_2;
93
- v = SIN_TABLE_2;
94
- } else if (abs(float(abs_k) - 4.0) < 0.5) {
95
- u = COS_TABLE_3;
96
- v = SIN_TABLE_3;
97
- }
98
- if (k > 0) {
99
- s = u * sin_t + v * cos_t;
100
- c = u * cos_t - v * sin_t;
101
- } else {
102
- s = u * sin_t - v * cos_t;
103
- c = u * cos_t + v * sin_t;
104
- }
105
- }
106
- if (j == 0) {
107
- sin_a = s;
108
- cos_a = c;
109
- } else if (j == 1) {
110
- sin_a = c;
111
- cos_a = -s;
112
- } else if (j == -1) {
113
- sin_a = -c;
114
- cos_a = s;
115
- } else {
116
- sin_a = -s;
117
- cos_a = -c;
118
- }
119
- return sin_a / cos_a;
68
+ float sin_a;
69
+ float cos_a;
70
+
71
+ if (a == 0.0) {
72
+ return 0.0;
73
+ }
74
+
75
+ // 2pi range reduction
76
+ float z = floor(a / TWO_PI);
77
+ float r = a - TWO_PI * z;
78
+
79
+ float t;
80
+ float q = floor(r / PI_2 + 0.5);
81
+ int j = int(q);
82
+
83
+ if (j < -2 || j > 2) {
84
+ return 1.0 / 0.0;
85
+ }
86
+
87
+ t = r - PI_2 * q;
88
+
89
+ q = floor(t / PI_16 + 0.5);
90
+ int k = int(q);
91
+ int abs_k = int(abs(float(k)));
92
+
93
+ if (abs_k > 4) {
94
+ return 1.0 / 0.0;
95
+ } else {
96
+ t = t - PI_16 * q;
97
+ }
98
+
99
+ float u = 0.0;
100
+ float v = 0.0;
101
+
102
+ float sin_t, cos_t;
103
+ float s, c;
104
+ sincos_taylor_fp32(t, sin_t, cos_t);
105
+
106
+ if (k == 0) {
107
+ s = sin_t;
108
+ c = cos_t;
109
+ } else {
110
+ if (abs(float(abs_k) - 1.0) < 0.5) {
111
+ u = COS_TABLE_0;
112
+ v = SIN_TABLE_0;
113
+ } else if (abs(float(abs_k) - 2.0) < 0.5) {
114
+ u = COS_TABLE_1;
115
+ v = SIN_TABLE_1;
116
+ } else if (abs(float(abs_k) - 3.0) < 0.5) {
117
+ u = COS_TABLE_2;
118
+ v = SIN_TABLE_2;
119
+ } else if (abs(float(abs_k) - 4.0) < 0.5) {
120
+ u = COS_TABLE_3;
121
+ v = SIN_TABLE_3;
122
+ }
123
+ if (k > 0) {
124
+ s = u * sin_t + v * cos_t;
125
+ c = u * cos_t - v * sin_t;
126
+ } else {
127
+ s = u * sin_t - v * cos_t;
128
+ c = u * cos_t + v * sin_t;
129
+ }
130
+ }
131
+
132
+ if (j == 0) {
133
+ sin_a = s;
134
+ cos_a = c;
135
+ } else if (j == 1) {
136
+ sin_a = c;
137
+ cos_a = -s;
138
+ } else if (j == -1) {
139
+ sin_a = -c;
140
+ cos_a = s;
141
+ } else {
142
+ sin_a = -s;
143
+ cos_a = -c;
144
+ }
145
+ return sin_a / cos_a;
120
146
  }
121
147
  #endif
148
+
122
149
  float tan_fp32(float a) {
123
150
  #ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
124
- return tan_taylor_fp32(a);
151
+ return tan_taylor_fp32(a);
125
152
  #else
126
- return tan(a);
153
+ return tan(a);
127
154
  #endif
128
155
  }
129
156
  `;
@@ -1,4 +1,4 @@
1
- import type { NumberArray } from '@math.gl/types';
1
+ import type { NumericArray } from '@math.gl/types';
2
2
  /**
3
3
  * Calculate WebGL 64 bit float
4
4
  * @param a - the input float number
@@ -6,7 +6,7 @@ import type { NumberArray } from '@math.gl/types';
6
6
  * @param startIndex - the index in the output array to fill from. Default 0.
7
7
  * @returns - the fp64 representation of the input number
8
8
  */
9
- export declare function fp64ify(a: number, out?: NumberArray, startIndex?: number): NumberArray;
9
+ export declare function fp64ify(a: number, out?: NumericArray, startIndex?: number): NumericArray;
10
10
  /**
11
11
  * Calculate the low part of a WebGL 64 bit float
12
12
  * @param a the input float number
@@ -18,5 +18,5 @@ export declare function fp64LowPart(a: number): number;
18
18
  * @param matrix the input matrix
19
19
  * @returns the fp64 representation of the input matrix
20
20
  */
21
- export declare function fp64ifyMatrix4(matrix: NumberArray): Float32Array;
21
+ export declare function fp64ifyMatrix4(matrix: NumericArray): Float32Array;
22
22
  //# sourceMappingURL=fp64-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fp64-utils.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,WAAgB,EAAE,UAAU,GAAE,MAAU,GAAG,WAAW,CAM7F;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CAUhE"}
1
+ {"version":3,"file":"fp64-utils.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,YAAiB,EAAE,UAAU,GAAE,MAAU,GAAG,YAAY,CAM/F;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAUjE"}
@@ -1,6 +1,6 @@
1
1
  /** Quick random generator for fragment shaders */
2
2
  export declare const random: {
3
3
  readonly name: "random";
4
- readonly fs: string;
4
+ readonly fs: "float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n}\n";
5
5
  };
6
6
  //# sourceMappingURL=random.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAcA,kDAAkD;AAClD,eAAO,MAAM,MAAM;;;CAGsB,CAAC"}
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAaA,kDAAkD;AAClD,eAAO,MAAM,MAAM;;;CAGsB,CAAC"}
@@ -1,10 +1,10 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- import { glsl } from "../../../lib/glsl-utils/highlight.js";
5
- const fs = `\
4
+ const fs = /* glsl */ `\
6
5
  float random(vec3 scale, float seed) {
7
- return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
6
+ /* use the fragment position for a different seed per-pixel */
7
+ return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
8
8
  }
9
9
  `;
10
10
  /** Quick random generator for fragment shaders */