@luma.gl/shadertools 9.2.5 → 9.3.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/dist/dist.dev.js +4798 -6439
  2. package/dist/dist.min.js +2047 -311
  3. package/dist/index.cjs +3033 -507
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +12 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
  10. package/dist/lib/preprocessor/preprocessor.js +35 -8
  11. package/dist/lib/preprocessor/preprocessor.js.map +1 -1
  12. package/dist/lib/shader-assembler.d.ts +10 -0
  13. package/dist/lib/shader-assembler.d.ts.map +1 -1
  14. package/dist/lib/shader-assembler.js +20 -3
  15. package/dist/lib/shader-assembler.js.map +1 -1
  16. package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
  17. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  18. package/dist/lib/shader-assembly/assemble-shaders.js +214 -11
  19. package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
  20. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
  21. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
  22. package/dist/lib/shader-assembly/wgsl-binding-debug.js +140 -0
  23. package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
  24. package/dist/lib/shader-generator/glsl/generate-glsl.js +7 -4
  25. package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
  26. package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
  27. package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
  28. package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
  29. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +91 -0
  30. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
  31. package/dist/lib/shader-module/shader-module-uniform-layout.js +209 -0
  32. package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
  33. package/dist/lib/shader-module/shader-module.d.ts +12 -6
  34. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  35. package/dist/lib/shader-module/shader-module.js.map +1 -1
  36. package/dist/lib/utils/assert.d.ts.map +1 -1
  37. package/dist/lib/utils/assert.js +3 -1
  38. package/dist/lib/utils/assert.js.map +1 -1
  39. package/dist/lib/utils/uniform-types.d.ts +11 -7
  40. package/dist/lib/utils/uniform-types.d.ts.map +1 -1
  41. package/dist/modules/engine/picking/picking.d.ts +5 -2
  42. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  43. package/dist/modules/engine/picking/picking.js +5 -2
  44. package/dist/modules/engine/picking/picking.js.map +1 -1
  45. package/dist/modules/engine/project/project.d.ts +1 -1
  46. package/dist/modules/engine/project/project.js +1 -1
  47. package/dist/modules/engine/skin/skin.d.ts +30 -0
  48. package/dist/modules/engine/skin/skin.d.ts.map +1 -0
  49. package/dist/modules/engine/skin/skin.js +86 -0
  50. package/dist/modules/engine/skin/skin.js.map +1 -0
  51. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
  52. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  53. package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
  54. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
  55. package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
  56. package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
  57. package/dist/modules/lighting/ibl/ibl.js +33 -0
  58. package/dist/modules/lighting/ibl/ibl.js.map +1 -0
  59. package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
  60. package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
  61. package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
  62. package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
  63. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
  64. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
  65. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
  66. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
  67. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
  68. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
  69. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
  70. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
  71. package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
  72. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
  73. package/dist/modules/lighting/lights/lighting-glsl.js +44 -38
  74. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
  75. package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
  76. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
  77. package/dist/modules/lighting/lights/lighting-wgsl.js +46 -18
  78. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
  79. package/dist/modules/lighting/lights/lighting.d.ts +104 -62
  80. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  81. package/dist/modules/lighting/lights/lighting.js +107 -68
  82. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  83. package/dist/modules/lighting/no-material/dirlight.d.ts +8 -3
  84. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  85. package/dist/modules/lighting/no-material/dirlight.js +4 -2
  86. package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
  87. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
  88. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
  89. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +581 -28
  90. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
  91. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
  92. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  93. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +850 -107
  94. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  95. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +172 -41
  96. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  97. package/dist/modules/lighting/pbr-material/pbr-material.js +109 -1
  98. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
  99. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
  100. package/dist/modules/lighting/pbr-material/pbr-projection.js +14 -2
  101. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
  102. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +40 -0
  103. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
  104. package/dist/modules/lighting/pbr-material/pbr-scene.js +67 -0
  105. package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
  106. package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
  107. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  108. package/dist/modules/lighting/phong-material/phong-material.js +4 -0
  109. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
  110. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  111. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  112. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +17 -6
  113. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
  114. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
  115. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
  116. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
  117. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
  118. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  119. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  120. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +42 -11
  121. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
  122. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
  123. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
  124. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
  125. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
  126. package/dist/modules/math/fp64/fp64.d.ts +1 -0
  127. package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
  128. package/dist/modules/math/fp64/fp64.js +8 -2
  129. package/dist/modules/math/fp64/fp64.js.map +1 -1
  130. package/dist/modules/math/random/random.d.ts +1 -1
  131. package/dist/modules/math/random/random.d.ts.map +1 -1
  132. package/dist/modules/math/random/random.js +2 -3
  133. package/dist/modules/math/random/random.js.map +1 -1
  134. package/package.json +4 -5
  135. package/src/index.ts +37 -6
  136. package/src/lib/preprocessor/preprocessor.ts +44 -8
  137. package/src/lib/shader-assembler.ts +25 -3
  138. package/src/lib/shader-assembly/assemble-shaders.ts +384 -12
  139. package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
  140. package/src/lib/shader-generator/glsl/generate-glsl.ts +11 -5
  141. package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
  142. package/src/lib/shader-module/shader-module-uniform-layout.ts +346 -0
  143. package/src/lib/shader-module/shader-module.ts +17 -7
  144. package/src/lib/utils/assert.ts +3 -1
  145. package/src/lib/utils/uniform-types.ts +24 -9
  146. package/src/modules/engine/picking/picking.ts +5 -2
  147. package/src/modules/engine/project/project.ts +1 -1
  148. package/src/modules/engine/skin/skin.ts +114 -0
  149. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  150. package/src/modules/lighting/ibl/ibl.ts +44 -0
  151. package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
  152. package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
  153. package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
  154. package/src/modules/lighting/lights/lighting-glsl.ts +44 -38
  155. package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
  156. package/src/modules/lighting/lights/lighting.ts +198 -99
  157. package/src/modules/lighting/no-material/dirlight.ts +4 -2
  158. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +581 -28
  159. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +850 -107
  160. package/src/modules/lighting/pbr-material/pbr-material.ts +185 -5
  161. package/src/modules/lighting/pbr-material/pbr-projection.ts +15 -2
  162. package/src/modules/lighting/pbr-material/pbr-scene.ts +91 -0
  163. package/src/modules/lighting/phong-material/phong-material.ts +5 -0
  164. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +17 -6
  165. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
  166. package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +42 -11
  167. package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
  168. package/src/modules/math/fp64/fp64.ts +9 -3
  169. package/src/modules/math/random/random.ts +2 -3
  170. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts +0 -8
  171. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +0 -1
  172. package/dist/lib/wgsl/get-shader-layout-wgsl.js +0 -95
  173. package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +0 -1
  174. package/src/lib/wgsl/get-shader-layout-wgsl.ts +0 -105
@@ -3,13 +3,14 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
  export const PHONG_WGSL = /* wgsl */ `\
5
5
  struct phongMaterialUniforms {
6
+ unlit: u32,
6
7
  ambient: f32,
7
8
  diffuse: f32,
8
9
  shininess: f32,
9
10
  specularColor: vec3<f32>,
10
11
  };
11
12
 
12
- @binding(2) @group(0) var<uniform> phongMaterial : phongMaterialUniforms;
13
+ @group(3) @binding(auto) var<uniform> phongMaterial : phongMaterialUniforms;
13
14
 
14
15
  fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
15
16
  let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
@@ -26,6 +27,10 @@ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, v
26
27
  fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
27
28
  var lightColor: vec3<f32> = surfaceColor;
28
29
 
30
+ if (phongMaterial.unlit != 0u) {
31
+ return surfaceColor;
32
+ }
33
+
29
34
  if (lighting.enabled == 0) {
30
35
  return lightColor;
31
36
  }
@@ -33,99 +38,89 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
33
38
  let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
34
39
  lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;
35
40
 
36
- if (lighting.lightType == 0) {
37
- let pointLight: PointLight = lighting_getPointLight(0);
41
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
42
+ let pointLight: PointLight = lighting_getPointLight(i);
38
43
  let light_position_worldspace: vec3<f32> = pointLight.position;
39
44
  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);
45
+ let light_attenuation = getPointLightAttenuation(
46
+ pointLight,
47
+ distance(light_position_worldspace, position_worldspace)
48
+ );
49
+ lightColor += lighting_getLightColor(
50
+ surfaceColor,
51
+ light_direction,
52
+ view_direction,
53
+ normal_worldspace,
54
+ pointLight.color / light_attenuation
55
+ );
44
56
  }
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);
57
+
58
+ for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
59
+ let spotLight: SpotLight = lighting_getSpotLight(i);
60
+ let light_position_worldspace: vec3<f32> = spotLight.position;
61
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
62
+ let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
63
+ lightColor += lighting_getLightColor(
64
+ surfaceColor,
65
+ light_direction,
66
+ view_direction,
67
+ normal_worldspace,
68
+ spotLight.color / light_attenuation
69
+ );
56
70
  }
57
71
 
58
- for (int i = 0; i < MAX_LIGHTS; i++) {
59
- if (i >= lighting.directionalLightCount) {
60
- break;
61
- }
62
- DirectionalLight directionalLight = lighting.directionalLight[i];
72
+ for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
73
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
63
74
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
64
- }
65
- */
75
+ }
76
+
77
+ return lightColor;
66
78
  }
67
79
 
68
80
  fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{
69
81
  var lightColor = vec3<f32>(0, 0, 0);
70
82
  let surfaceColor = vec3<f32>(0, 0, 0);
71
83
 
72
- if (lighting.enabled == 0) {
84
+ if (lighting.enabled != 0) {
73
85
  let view_direction = normalize(cameraPosition - position_worldspace);
74
86
 
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);
87
+ for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
88
+ let pointLight: PointLight = lighting_getPointLight(i);
89
+ let light_position_worldspace: vec3<f32> = pointLight.position;
90
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
91
+ let light_attenuation = getPointLightAttenuation(
92
+ pointLight,
93
+ distance(light_position_worldspace, position_worldspace)
94
+ );
95
+ lightColor += lighting_getLightColor(
96
+ surfaceColor,
97
+ light_direction,
98
+ view_direction,
99
+ normal_worldspace,
100
+ pointLight.color / light_attenuation
101
+ );
101
102
  }
102
103
 
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);
104
+ for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
105
+ let spotLight: SpotLight = lighting_getSpotLight(i);
106
+ let light_position_worldspace: vec3<f32> = spotLight.position;
107
+ let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
108
+ let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
109
+ lightColor += lighting_getLightColor(
110
+ surfaceColor,
111
+ light_direction,
112
+ view_direction,
113
+ normal_worldspace,
114
+ spotLight.color / light_attenuation
115
+ );
120
116
  }
121
117
 
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);
118
+ for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
119
+ let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
120
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
128
121
  }
129
122
  }
130
- */
123
+ return lightColor;
124
+ }
125
+ `;
131
126
  //# sourceMappingURL=phong-shaders-wgsl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"phong-shaders-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFpC,CAAC;AAEF,gCAAgC;AAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
1
+ {"version":3,"file":"phong-shaders-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyHpC,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const fp64arithmeticShader = "\nuniform fp64arithmeticUniforms {\n uniform float ONE;\n} fp64;\n\n/*\nAbout LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n\nThe purpose of this workaround is to prevent shader compilers from\noptimizing away necessary arithmetic operations by swapping their sequences\nor transform the equation to some 'equivalent' form.\n\nThe method is to multiply an artifical variable, ONE, which will be known to\nthe compiler to be 1 only at runtime. The whole expression is then represented\nas a polynomial with respective to ONE. In the coefficients of all terms, only one a\nand one b should appear\n\nerr = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE\n*/\n\n// Divide float number to high and low floats to extend fraction bits\nvec2 split(float a) {\n const float SPLIT = 4097.0;\n float t = a * SPLIT;\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float a_hi = t * fp64.ONE - (t - a);\n float a_lo = a * fp64.ONE - a_hi;\n#else\n float a_hi = t - (t - a);\n float a_lo = a - a_hi;\n#endif\n return vec2(a_hi, a_lo);\n}\n\n// Divide float number again when high float uses too many fraction bits\nvec2 split2(vec2 a) {\n vec2 b = split(a.x);\n b.y += a.y;\n return b;\n}\n\n// Special sum operation when a > b\nvec2 quickTwoSum(float a, float b) {\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float sum = (a + b) * fp64.ONE;\n float err = b - (sum - a) * fp64.ONE;\n#else\n float sum = a + b;\n float err = b - (sum - a);\n#endif\n return vec2(sum, err);\n}\n\n// General sum operation\nvec2 twoSum(float a, float b) {\n float s = (a + b);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float v = (s * fp64.ONE - a) * fp64.ONE;\n float err = (a - (s - v) * fp64.ONE) * fp64.ONE * fp64.ONE * fp64.ONE + (b - v);\n#else\n float v = s - a;\n float err = (a - (s - v)) + (b - v);\n#endif\n return vec2(s, err);\n}\n\nvec2 twoSub(float a, float b) {\n float s = (a - b);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float v = (s * fp64.ONE - a) * fp64.ONE;\n float err = (a - (s - v) * fp64.ONE) * fp64.ONE * fp64.ONE * fp64.ONE - (b + v);\n#else\n float v = s - a;\n float err = (a - (s - v)) - (b + v);\n#endif\n return vec2(s, err);\n}\n\nvec2 twoSqr(float a) {\n float prod = a * a;\n vec2 a_fp64 = split(a);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float err = ((a_fp64.x * a_fp64.x - prod) * fp64.ONE + 2.0 * a_fp64.x *\n a_fp64.y * fp64.ONE * fp64.ONE) + a_fp64.y * a_fp64.y * fp64.ONE * fp64.ONE * fp64.ONE;\n#else\n float err = ((a_fp64.x * a_fp64.x - prod) + 2.0 * a_fp64.x * a_fp64.y) + a_fp64.y * a_fp64.y;\n#endif\n return vec2(prod, err);\n}\n\nvec2 twoProd(float a, float b) {\n float prod = a * b;\n vec2 a_fp64 = split(a);\n vec2 b_fp64 = split(b);\n float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +\n a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;\n return vec2(prod, err);\n}\n\nvec2 sum_fp64(vec2 a, vec2 b) {\n vec2 s, t;\n s = twoSum(a.x, b.x);\n t = twoSum(a.y, b.y);\n s.y += t.x;\n s = quickTwoSum(s.x, s.y);\n s.y += t.y;\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nvec2 sub_fp64(vec2 a, vec2 b) {\n vec2 s, t;\n s = twoSub(a.x, b.x);\n t = twoSub(a.y, b.y);\n s.y += t.x;\n s = quickTwoSum(s.x, s.y);\n s.y += t.y;\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nvec2 mul_fp64(vec2 a, vec2 b) {\n vec2 prod = twoProd(a.x, b.x);\n // y component is for the error\n prod.y += a.x * b.y;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n prod.y += a.y * b.x;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n return prod;\n}\n\nvec2 div_fp64(vec2 a, vec2 b) {\n float xn = 1.0 / b.x;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n vec2 yn = mul_fp64(a, vec2(xn, 0));\n#else\n vec2 yn = a * xn;\n#endif\n float diff = (sub_fp64(a, mul_fp64(b, yn))).x;\n vec2 prod = twoProd(xn, diff);\n return sum_fp64(yn, prod);\n}\n\nvec2 sqrt_fp64(vec2 a) {\n if (a.x == 0.0 && a.y == 0.0) return vec2(0.0, 0.0);\n if (a.x < 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);\n\n float x = 1.0 / sqrt(a.x);\n float yn = a.x * x;\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n vec2 yn_sqr = twoSqr(yn) * fp64.ONE;\n#else\n vec2 yn_sqr = twoSqr(yn);\n#endif\n float diff = sub_fp64(a, yn_sqr).x;\n vec2 prod = twoProd(x * 0.5, diff);\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n return sum_fp64(split(yn), prod);\n#else\n return sum_fp64(vec2(yn, 0.0), prod);\n#endif\n}\n";
1
+ export declare const fp64arithmeticShader = "\nlayout(std140) uniform fp64arithmeticUniforms {\n uniform float ONE;\n uniform float SPLIT;\n} fp64;\n\n/*\nAbout LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n\nThe purpose of this workaround is to prevent shader compilers from\noptimizing away necessary arithmetic operations by swapping their sequences\nor transform the equation to some 'equivalent' form.\n\nThese helpers implement Dekker/Veltkamp-style error tracking. If the compiler\nfolds constants or reassociates the arithmetic, the high/low split can stop\ntracking the rounding error correctly. That failure mode tends to look fine in\nsimple coordinate setup, but then breaks down inside iterative arithmetic such\nas fp64 Mandelbrot loops.\n\nThe method is to multiply an artifical variable, ONE, which will be known to\nthe compiler to be 1 only at runtime. The whole expression is then represented\nas a polynomial with respective to ONE. In the coefficients of all terms, only one a\nand one b should appear\n\nerr = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE\n*/\n\nfloat prevent_fp64_optimization(float value) {\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n return value + fp64.ONE * 0.0;\n#else\n return value;\n#endif\n}\n\n// Divide float number to high and low floats to extend fraction bits\nvec2 split(float a) {\n // Keep SPLIT as a runtime uniform so the compiler cannot fold the Dekker\n // split into a constant expression and reassociate the recovery steps.\n float split = prevent_fp64_optimization(fp64.SPLIT);\n float t = prevent_fp64_optimization(a * split);\n float temp = t - a;\n float a_hi = t - temp;\n float a_lo = a - a_hi;\n return vec2(a_hi, a_lo);\n}\n\n// Divide float number again when high float uses too many fraction bits\nvec2 split2(vec2 a) {\n vec2 b = split(a.x);\n b.y += a.y;\n return b;\n}\n\n// Special sum operation when a > b\nvec2 quickTwoSum(float a, float b) {\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float sum = (a + b) * fp64.ONE;\n float err = b - (sum - a) * fp64.ONE;\n#else\n float sum = a + b;\n float err = b - (sum - a);\n#endif\n return vec2(sum, err);\n}\n\n// General sum operation\nvec2 twoSum(float a, float b) {\n float s = (a + b);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float v = (s * fp64.ONE - a) * fp64.ONE;\n float err = (a - (s - v) * fp64.ONE) * fp64.ONE * fp64.ONE * fp64.ONE + (b - v);\n#else\n float v = s - a;\n float err = (a - (s - v)) + (b - v);\n#endif\n return vec2(s, err);\n}\n\nvec2 twoSub(float a, float b) {\n float s = (a - b);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float v = (s * fp64.ONE - a) * fp64.ONE;\n float err = (a - (s - v) * fp64.ONE) * fp64.ONE * fp64.ONE * fp64.ONE - (b + v);\n#else\n float v = s - a;\n float err = (a - (s - v)) - (b + v);\n#endif\n return vec2(s, err);\n}\n\nvec2 twoSqr(float a) {\n float prod = a * a;\n vec2 a_fp64 = split(a);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float err = ((a_fp64.x * a_fp64.x - prod) * fp64.ONE + 2.0 * a_fp64.x *\n a_fp64.y * fp64.ONE * fp64.ONE) + a_fp64.y * a_fp64.y * fp64.ONE * fp64.ONE * fp64.ONE;\n#else\n float err = ((a_fp64.x * a_fp64.x - prod) + 2.0 * a_fp64.x * a_fp64.y) + a_fp64.y * a_fp64.y;\n#endif\n return vec2(prod, err);\n}\n\nvec2 twoProd(float a, float b) {\n float prod = a * b;\n vec2 a_fp64 = split(a);\n vec2 b_fp64 = split(b);\n // twoProd is especially sensitive because mul_fp64 and div_fp64 both depend\n // on the split terms and cross terms staying in the original evaluation\n // order. If the compiler folds or reassociates them, the low part tends to\n // collapse to zero or NaN on some drivers.\n float highProduct = prevent_fp64_optimization(a_fp64.x * b_fp64.x);\n float crossProduct1 = prevent_fp64_optimization(a_fp64.x * b_fp64.y);\n float crossProduct2 = prevent_fp64_optimization(a_fp64.y * b_fp64.x);\n float lowProduct = prevent_fp64_optimization(a_fp64.y * b_fp64.y);\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n float err1 = (highProduct - prod) * fp64.ONE;\n float err2 = crossProduct1 * fp64.ONE * fp64.ONE;\n float err3 = crossProduct2 * fp64.ONE * fp64.ONE * fp64.ONE;\n float err4 = lowProduct * fp64.ONE * fp64.ONE * fp64.ONE * fp64.ONE;\n#else\n float err1 = highProduct - prod;\n float err2 = crossProduct1;\n float err3 = crossProduct2;\n float err4 = lowProduct;\n#endif\n float err = ((err1 + err2) + err3) + err4;\n return vec2(prod, err);\n}\n\nvec2 sum_fp64(vec2 a, vec2 b) {\n vec2 s, t;\n s = twoSum(a.x, b.x);\n t = twoSum(a.y, b.y);\n s.y += t.x;\n s = quickTwoSum(s.x, s.y);\n s.y += t.y;\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nvec2 sub_fp64(vec2 a, vec2 b) {\n vec2 s, t;\n s = twoSub(a.x, b.x);\n t = twoSub(a.y, b.y);\n s.y += t.x;\n s = quickTwoSum(s.x, s.y);\n s.y += t.y;\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nvec2 mul_fp64(vec2 a, vec2 b) {\n vec2 prod = twoProd(a.x, b.x);\n // y component is for the error\n prod.y += a.x * b.y;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n prod.y += a.y * b.x;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n return prod;\n}\n\nvec2 div_fp64(vec2 a, vec2 b) {\n float xn = 1.0 / b.x;\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n vec2 yn = mul_fp64(a, vec2(xn, 0));\n#else\n vec2 yn = a * xn;\n#endif\n float diff = (sub_fp64(a, mul_fp64(b, yn))).x;\n vec2 prod = twoProd(xn, diff);\n return sum_fp64(yn, prod);\n}\n\nvec2 sqrt_fp64(vec2 a) {\n if (a.x == 0.0 && a.y == 0.0) return vec2(0.0, 0.0);\n if (a.x < 0.0) return vec2(0.0 / 0.0, 0.0 / 0.0);\n\n float x = 1.0 / sqrt(a.x);\n float yn = a.x * x;\n#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)\n vec2 yn_sqr = twoSqr(yn) * fp64.ONE;\n#else\n vec2 yn_sqr = twoSqr(yn);\n#endif\n float diff = sub_fp64(a, yn_sqr).x;\n vec2 prod = twoProd(x * 0.5, diff);\n#if defined(LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND)\n return sum_fp64(split(yn), prod);\n#else\n return sum_fp64(vec2(yn, 0.0), prod);\n#endif\n}\n";
2
2
  //# sourceMappingURL=fp64-arithmetic-glsl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fp64-arithmetic-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,shJAyKhC,CAAC"}
1
+ {"version":3,"file":"fp64-arithmetic-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,ijMAwMhC,CAAC"}
@@ -3,8 +3,9 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
  export const fp64arithmeticShader = /* glsl */ `\
5
5
 
6
- uniform fp64arithmeticUniforms {
6
+ layout(std140) uniform fp64arithmeticUniforms {
7
7
  uniform float ONE;
8
+ uniform float SPLIT;
8
9
  } fp64;
9
10
 
10
11
  /*
@@ -14,6 +15,12 @@ The purpose of this workaround is to prevent shader compilers from
14
15
  optimizing away necessary arithmetic operations by swapping their sequences
15
16
  or transform the equation to some 'equivalent' form.
16
17
 
18
+ These helpers implement Dekker/Veltkamp-style error tracking. If the compiler
19
+ folds constants or reassociates the arithmetic, the high/low split can stop
20
+ tracking the rounding error correctly. That failure mode tends to look fine in
21
+ simple coordinate setup, but then breaks down inside iterative arithmetic such
22
+ as fp64 Mandelbrot loops.
23
+
17
24
  The method is to multiply an artifical variable, ONE, which will be known to
18
25
  the compiler to be 1 only at runtime. The whole expression is then represented
19
26
  as a polynomial with respective to ONE. In the coefficients of all terms, only one a
@@ -22,17 +29,23 @@ and one b should appear
22
29
  err = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE
23
30
  */
24
31
 
25
- // Divide float number to high and low floats to extend fraction bits
26
- vec2 split(float a) {
27
- const float SPLIT = 4097.0;
28
- float t = a * SPLIT;
32
+ float prevent_fp64_optimization(float value) {
29
33
  #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
30
- float a_hi = t * fp64.ONE - (t - a);
31
- float a_lo = a * fp64.ONE - a_hi;
34
+ return value + fp64.ONE * 0.0;
32
35
  #else
33
- float a_hi = t - (t - a);
34
- float a_lo = a - a_hi;
36
+ return value;
35
37
  #endif
38
+ }
39
+
40
+ // Divide float number to high and low floats to extend fraction bits
41
+ vec2 split(float a) {
42
+ // Keep SPLIT as a runtime uniform so the compiler cannot fold the Dekker
43
+ // split into a constant expression and reassociate the recovery steps.
44
+ float split = prevent_fp64_optimization(fp64.SPLIT);
45
+ float t = prevent_fp64_optimization(a * split);
46
+ float temp = t - a;
47
+ float a_hi = t - temp;
48
+ float a_lo = a - a_hi;
36
49
  return vec2(a_hi, a_lo);
37
50
  }
38
51
 
@@ -96,8 +109,26 @@ vec2 twoProd(float a, float b) {
96
109
  float prod = a * b;
97
110
  vec2 a_fp64 = split(a);
98
111
  vec2 b_fp64 = split(b);
99
- float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +
100
- a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;
112
+ // twoProd is especially sensitive because mul_fp64 and div_fp64 both depend
113
+ // on the split terms and cross terms staying in the original evaluation
114
+ // order. If the compiler folds or reassociates them, the low part tends to
115
+ // collapse to zero or NaN on some drivers.
116
+ float highProduct = prevent_fp64_optimization(a_fp64.x * b_fp64.x);
117
+ float crossProduct1 = prevent_fp64_optimization(a_fp64.x * b_fp64.y);
118
+ float crossProduct2 = prevent_fp64_optimization(a_fp64.y * b_fp64.x);
119
+ float lowProduct = prevent_fp64_optimization(a_fp64.y * b_fp64.y);
120
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
121
+ float err1 = (highProduct - prod) * fp64.ONE;
122
+ float err2 = crossProduct1 * fp64.ONE * fp64.ONE;
123
+ float err3 = crossProduct2 * fp64.ONE * fp64.ONE * fp64.ONE;
124
+ float err4 = lowProduct * fp64.ONE * fp64.ONE * fp64.ONE * fp64.ONE;
125
+ #else
126
+ float err1 = highProduct - prod;
127
+ float err2 = crossProduct1;
128
+ float err3 = crossProduct2;
129
+ float err4 = lowProduct;
130
+ #endif
131
+ float err = ((err1 + err2) + err3) + err4;
101
132
  return vec2(prod, err);
102
133
  }
103
134
 
@@ -1 +1 @@
1
- {"version":3,"file":"fp64-arithmetic-glsl.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyK9C,CAAC"}
1
+ {"version":3,"file":"fp64-arithmetic-glsl.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwM9C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const fp64arithmeticWGSL = "struct Fp64ArithmeticUniforms {\n ONE: f32,\n SPLIT: f32,\n};\n\n@group(0) @binding(auto) var<uniform> fp64arithmetic : Fp64ArithmeticUniforms;\n\nfn fp64_nan(seed: f32) -> f32 {\n let nanBits = 0x7fc00000u | select(0u, 1u, seed < 0.0);\n return bitcast<f32>(nanBits);\n}\n\nfn fp64_runtime_zero() -> f32 {\n return fp64arithmetic.ONE * 0.0;\n}\n\nfn prevent_fp64_optimization(value: f32) -> f32 {\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n return value + fp64_runtime_zero();\n#else\n return value;\n#endif\n}\n\nfn split(a: f32) -> vec2f {\n let splitValue = prevent_fp64_optimization(fp64arithmetic.SPLIT + fp64_runtime_zero());\n let t = prevent_fp64_optimization(a * splitValue);\n let temp = prevent_fp64_optimization(t - a);\n let aHi = prevent_fp64_optimization(t - temp);\n let aLo = prevent_fp64_optimization(a - aHi);\n return vec2f(aHi, aLo);\n}\n\nfn split2(a: vec2f) -> vec2f {\n var b = split(a.x);\n b.y = b.y + a.y;\n return b;\n}\n\nfn quickTwoSum(a: f32, b: f32) -> vec2f {\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let sum = prevent_fp64_optimization((a + b) * fp64arithmetic.ONE);\n let err = prevent_fp64_optimization(b - (sum - a) * fp64arithmetic.ONE);\n#else\n let sum = prevent_fp64_optimization(a + b);\n let err = prevent_fp64_optimization(b - (sum - a));\n#endif\n return vec2f(sum, err);\n}\n\nfn twoSum(a: f32, b: f32) -> vec2f {\n let s = prevent_fp64_optimization(a + b);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);\n let err =\n prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE) +\n prevent_fp64_optimization(b - v);\n#else\n let v = prevent_fp64_optimization(s - a);\n let err = prevent_fp64_optimization(a - (s - v)) + prevent_fp64_optimization(b - v);\n#endif\n return vec2f(s, err);\n}\n\nfn twoSub(a: f32, b: f32) -> vec2f {\n let s = prevent_fp64_optimization(a - b);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);\n let err =\n prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE) -\n prevent_fp64_optimization(b + v);\n#else\n let v = prevent_fp64_optimization(s - a);\n let err = prevent_fp64_optimization(a - (s - v)) - prevent_fp64_optimization(b + v);\n#endif\n return vec2f(s, err);\n}\n\nfn twoSqr(a: f32) -> vec2f {\n let prod = prevent_fp64_optimization(a * a);\n let aFp64 = split(a);\n let highProduct = prevent_fp64_optimization(aFp64.x * aFp64.x);\n let crossProduct = prevent_fp64_optimization(2.0 * aFp64.x * aFp64.y);\n let lowProduct = prevent_fp64_optimization(aFp64.y * aFp64.y);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let err =\n (prevent_fp64_optimization(highProduct - prod) * fp64arithmetic.ONE +\n crossProduct * fp64arithmetic.ONE * fp64arithmetic.ONE) +\n lowProduct * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;\n#else\n let err = ((prevent_fp64_optimization(highProduct - prod) + crossProduct) + lowProduct);\n#endif\n return vec2f(prod, err);\n}\n\nfn twoProd(a: f32, b: f32) -> vec2f {\n let prod = prevent_fp64_optimization(a * b);\n let aFp64 = split(a);\n let bFp64 = split(b);\n let highProduct = prevent_fp64_optimization(aFp64.x * bFp64.x);\n let crossProduct1 = prevent_fp64_optimization(aFp64.x * bFp64.y);\n let crossProduct2 = prevent_fp64_optimization(aFp64.y * bFp64.x);\n let lowProduct = prevent_fp64_optimization(aFp64.y * bFp64.y);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let err1 = (highProduct - prod) * fp64arithmetic.ONE;\n let err2 = crossProduct1 * fp64arithmetic.ONE * fp64arithmetic.ONE;\n let err3 = crossProduct2 * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;\n let err4 =\n lowProduct *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE;\n#else\n let err1 = highProduct - prod;\n let err2 = crossProduct1;\n let err3 = crossProduct2;\n let err4 = lowProduct;\n#endif\n let err12InputA = prevent_fp64_optimization(err1);\n let err12InputB = prevent_fp64_optimization(err2);\n let err12 = prevent_fp64_optimization(err12InputA + err12InputB);\n let err123InputA = prevent_fp64_optimization(err12);\n let err123InputB = prevent_fp64_optimization(err3);\n let err123 = prevent_fp64_optimization(err123InputA + err123InputB);\n let err1234InputA = prevent_fp64_optimization(err123);\n let err1234InputB = prevent_fp64_optimization(err4);\n let err = prevent_fp64_optimization(err1234InputA + err1234InputB);\n return vec2f(prod, err);\n}\n\nfn sum_fp64(a: vec2f, b: vec2f) -> vec2f {\n var s = twoSum(a.x, b.x);\n let t = twoSum(a.y, b.y);\n s.y = prevent_fp64_optimization(s.y + t.x);\n s = quickTwoSum(s.x, s.y);\n s.y = prevent_fp64_optimization(s.y + t.y);\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nfn sub_fp64(a: vec2f, b: vec2f) -> vec2f {\n var s = twoSub(a.x, b.x);\n let t = twoSub(a.y, b.y);\n s.y = prevent_fp64_optimization(s.y + t.x);\n s = quickTwoSum(s.x, s.y);\n s.y = prevent_fp64_optimization(s.y + t.y);\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nfn mul_fp64(a: vec2f, b: vec2f) -> vec2f {\n var prod = twoProd(a.x, b.x);\n let crossProduct1 = prevent_fp64_optimization(a.x * b.y);\n prod.y = prevent_fp64_optimization(prod.y + crossProduct1);\n#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n let crossProduct2 = prevent_fp64_optimization(a.y * b.x);\n prod.y = prevent_fp64_optimization(prod.y + crossProduct2);\n#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n return prod;\n}\n\nfn div_fp64(a: vec2f, b: vec2f) -> vec2f {\n let xn = prevent_fp64_optimization(1.0 / b.x);\n let yn = mul_fp64(a, vec2f(xn, fp64_runtime_zero()));\n let diff = prevent_fp64_optimization(sub_fp64(a, mul_fp64(b, yn)).x);\n let prod = twoProd(xn, diff);\n return sum_fp64(yn, prod);\n}\n\nfn sqrt_fp64(a: vec2f) -> vec2f {\n if (a.x == 0.0 && a.y == 0.0) {\n return vec2f(0.0, 0.0);\n }\n if (a.x < 0.0) {\n let nanValue = fp64_nan(a.x);\n return vec2f(nanValue, nanValue);\n }\n\n let x = prevent_fp64_optimization(1.0 / sqrt(a.x));\n let yn = prevent_fp64_optimization(a.x * x);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let ynSqr = twoSqr(yn) * fp64arithmetic.ONE;\n#else\n let ynSqr = twoSqr(yn);\n#endif\n let diff = prevent_fp64_optimization(sub_fp64(a, ynSqr).x);\n let prod = twoProd(prevent_fp64_optimization(x * 0.5), diff);\n#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND\n return sum_fp64(split(yn), prod);\n#else\n return sum_fp64(vec2f(yn, 0.0), prod);\n#endif\n}\n";
2
+ //# sourceMappingURL=fp64-arithmetic-wgsl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fp64-arithmetic-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,yyNA+M9B,CAAC"}
@@ -0,0 +1,212 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export const fp64arithmeticWGSL = /* wgsl */ `\
5
+ struct Fp64ArithmeticUniforms {
6
+ ONE: f32,
7
+ SPLIT: f32,
8
+ };
9
+
10
+ @group(0) @binding(auto) var<uniform> fp64arithmetic : Fp64ArithmeticUniforms;
11
+
12
+ fn fp64_nan(seed: f32) -> f32 {
13
+ let nanBits = 0x7fc00000u | select(0u, 1u, seed < 0.0);
14
+ return bitcast<f32>(nanBits);
15
+ }
16
+
17
+ fn fp64_runtime_zero() -> f32 {
18
+ return fp64arithmetic.ONE * 0.0;
19
+ }
20
+
21
+ fn prevent_fp64_optimization(value: f32) -> f32 {
22
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
23
+ return value + fp64_runtime_zero();
24
+ #else
25
+ return value;
26
+ #endif
27
+ }
28
+
29
+ fn split(a: f32) -> vec2f {
30
+ let splitValue = prevent_fp64_optimization(fp64arithmetic.SPLIT + fp64_runtime_zero());
31
+ let t = prevent_fp64_optimization(a * splitValue);
32
+ let temp = prevent_fp64_optimization(t - a);
33
+ let aHi = prevent_fp64_optimization(t - temp);
34
+ let aLo = prevent_fp64_optimization(a - aHi);
35
+ return vec2f(aHi, aLo);
36
+ }
37
+
38
+ fn split2(a: vec2f) -> vec2f {
39
+ var b = split(a.x);
40
+ b.y = b.y + a.y;
41
+ return b;
42
+ }
43
+
44
+ fn quickTwoSum(a: f32, b: f32) -> vec2f {
45
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
46
+ let sum = prevent_fp64_optimization((a + b) * fp64arithmetic.ONE);
47
+ let err = prevent_fp64_optimization(b - (sum - a) * fp64arithmetic.ONE);
48
+ #else
49
+ let sum = prevent_fp64_optimization(a + b);
50
+ let err = prevent_fp64_optimization(b - (sum - a));
51
+ #endif
52
+ return vec2f(sum, err);
53
+ }
54
+
55
+ fn twoSum(a: f32, b: f32) -> vec2f {
56
+ let s = prevent_fp64_optimization(a + b);
57
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
58
+ let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
59
+ let err =
60
+ prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
61
+ fp64arithmetic.ONE *
62
+ fp64arithmetic.ONE *
63
+ fp64arithmetic.ONE) +
64
+ prevent_fp64_optimization(b - v);
65
+ #else
66
+ let v = prevent_fp64_optimization(s - a);
67
+ let err = prevent_fp64_optimization(a - (s - v)) + prevent_fp64_optimization(b - v);
68
+ #endif
69
+ return vec2f(s, err);
70
+ }
71
+
72
+ fn twoSub(a: f32, b: f32) -> vec2f {
73
+ let s = prevent_fp64_optimization(a - b);
74
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
75
+ let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
76
+ let err =
77
+ prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
78
+ fp64arithmetic.ONE *
79
+ fp64arithmetic.ONE *
80
+ fp64arithmetic.ONE) -
81
+ prevent_fp64_optimization(b + v);
82
+ #else
83
+ let v = prevent_fp64_optimization(s - a);
84
+ let err = prevent_fp64_optimization(a - (s - v)) - prevent_fp64_optimization(b + v);
85
+ #endif
86
+ return vec2f(s, err);
87
+ }
88
+
89
+ fn twoSqr(a: f32) -> vec2f {
90
+ let prod = prevent_fp64_optimization(a * a);
91
+ let aFp64 = split(a);
92
+ let highProduct = prevent_fp64_optimization(aFp64.x * aFp64.x);
93
+ let crossProduct = prevent_fp64_optimization(2.0 * aFp64.x * aFp64.y);
94
+ let lowProduct = prevent_fp64_optimization(aFp64.y * aFp64.y);
95
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
96
+ let err =
97
+ (prevent_fp64_optimization(highProduct - prod) * fp64arithmetic.ONE +
98
+ crossProduct * fp64arithmetic.ONE * fp64arithmetic.ONE) +
99
+ lowProduct * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
100
+ #else
101
+ let err = ((prevent_fp64_optimization(highProduct - prod) + crossProduct) + lowProduct);
102
+ #endif
103
+ return vec2f(prod, err);
104
+ }
105
+
106
+ fn twoProd(a: f32, b: f32) -> vec2f {
107
+ let prod = prevent_fp64_optimization(a * b);
108
+ let aFp64 = split(a);
109
+ let bFp64 = split(b);
110
+ let highProduct = prevent_fp64_optimization(aFp64.x * bFp64.x);
111
+ let crossProduct1 = prevent_fp64_optimization(aFp64.x * bFp64.y);
112
+ let crossProduct2 = prevent_fp64_optimization(aFp64.y * bFp64.x);
113
+ let lowProduct = prevent_fp64_optimization(aFp64.y * bFp64.y);
114
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
115
+ let err1 = (highProduct - prod) * fp64arithmetic.ONE;
116
+ let err2 = crossProduct1 * fp64arithmetic.ONE * fp64arithmetic.ONE;
117
+ let err3 = crossProduct2 * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
118
+ let err4 =
119
+ lowProduct *
120
+ fp64arithmetic.ONE *
121
+ fp64arithmetic.ONE *
122
+ fp64arithmetic.ONE *
123
+ fp64arithmetic.ONE;
124
+ #else
125
+ let err1 = highProduct - prod;
126
+ let err2 = crossProduct1;
127
+ let err3 = crossProduct2;
128
+ let err4 = lowProduct;
129
+ #endif
130
+ let err12InputA = prevent_fp64_optimization(err1);
131
+ let err12InputB = prevent_fp64_optimization(err2);
132
+ let err12 = prevent_fp64_optimization(err12InputA + err12InputB);
133
+ let err123InputA = prevent_fp64_optimization(err12);
134
+ let err123InputB = prevent_fp64_optimization(err3);
135
+ let err123 = prevent_fp64_optimization(err123InputA + err123InputB);
136
+ let err1234InputA = prevent_fp64_optimization(err123);
137
+ let err1234InputB = prevent_fp64_optimization(err4);
138
+ let err = prevent_fp64_optimization(err1234InputA + err1234InputB);
139
+ return vec2f(prod, err);
140
+ }
141
+
142
+ fn sum_fp64(a: vec2f, b: vec2f) -> vec2f {
143
+ var s = twoSum(a.x, b.x);
144
+ let t = twoSum(a.y, b.y);
145
+ s.y = prevent_fp64_optimization(s.y + t.x);
146
+ s = quickTwoSum(s.x, s.y);
147
+ s.y = prevent_fp64_optimization(s.y + t.y);
148
+ s = quickTwoSum(s.x, s.y);
149
+ return s;
150
+ }
151
+
152
+ fn sub_fp64(a: vec2f, b: vec2f) -> vec2f {
153
+ var s = twoSub(a.x, b.x);
154
+ let t = twoSub(a.y, b.y);
155
+ s.y = prevent_fp64_optimization(s.y + t.x);
156
+ s = quickTwoSum(s.x, s.y);
157
+ s.y = prevent_fp64_optimization(s.y + t.y);
158
+ s = quickTwoSum(s.x, s.y);
159
+ return s;
160
+ }
161
+
162
+ fn mul_fp64(a: vec2f, b: vec2f) -> vec2f {
163
+ var prod = twoProd(a.x, b.x);
164
+ let crossProduct1 = prevent_fp64_optimization(a.x * b.y);
165
+ prod.y = prevent_fp64_optimization(prod.y + crossProduct1);
166
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
167
+ prod = split2(prod);
168
+ #endif
169
+ prod = quickTwoSum(prod.x, prod.y);
170
+ let crossProduct2 = prevent_fp64_optimization(a.y * b.x);
171
+ prod.y = prevent_fp64_optimization(prod.y + crossProduct2);
172
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
173
+ prod = split2(prod);
174
+ #endif
175
+ prod = quickTwoSum(prod.x, prod.y);
176
+ return prod;
177
+ }
178
+
179
+ fn div_fp64(a: vec2f, b: vec2f) -> vec2f {
180
+ let xn = prevent_fp64_optimization(1.0 / b.x);
181
+ let yn = mul_fp64(a, vec2f(xn, fp64_runtime_zero()));
182
+ let diff = prevent_fp64_optimization(sub_fp64(a, mul_fp64(b, yn)).x);
183
+ let prod = twoProd(xn, diff);
184
+ return sum_fp64(yn, prod);
185
+ }
186
+
187
+ fn sqrt_fp64(a: vec2f) -> vec2f {
188
+ if (a.x == 0.0 && a.y == 0.0) {
189
+ return vec2f(0.0, 0.0);
190
+ }
191
+ if (a.x < 0.0) {
192
+ let nanValue = fp64_nan(a.x);
193
+ return vec2f(nanValue, nanValue);
194
+ }
195
+
196
+ let x = prevent_fp64_optimization(1.0 / sqrt(a.x));
197
+ let yn = prevent_fp64_optimization(a.x * x);
198
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
199
+ let ynSqr = twoSqr(yn) * fp64arithmetic.ONE;
200
+ #else
201
+ let ynSqr = twoSqr(yn);
202
+ #endif
203
+ let diff = prevent_fp64_optimization(sub_fp64(a, ynSqr).x);
204
+ let prod = twoProd(prevent_fp64_optimization(x * 0.5), diff);
205
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
206
+ return sum_fp64(split(yn), prod);
207
+ #else
208
+ return sum_fp64(vec2f(yn, 0.0), prod);
209
+ #endif
210
+ }
211
+ `;
212
+ //# sourceMappingURL=fp64-arithmetic-wgsl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fp64-arithmetic-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+M5C,CAAC"}
@@ -3,6 +3,7 @@ import { fp64ify, fp64LowPart, fp64ifyMatrix4 } from "../../../modules/math/fp64
3
3
  type FP64Props = {};
4
4
  type FP64Uniforms = {
5
5
  ONE: number;
6
+ SPLIT: number;
6
7
  };
7
8
  type FP64Bindings = {};
8
9
  type FP64Utilities = {
@@ -1 +1 @@
1
- {"version":3,"file":"fp64.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAI3F,KAAK,SAAS,GAAG,EAAE,CAAC;AACpB,KAAK,YAAY,GAAG;IAAC,GAAG,EAAE,MAAM,CAAA;CAAC,CAAC;AAClC,KAAK,YAAY,GAAG,EAAE,CAAC;AAEvB,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,WAAW,CAAC;IAChC,cAAc,EAAE,OAAO,cAAc,CAAC;CACvC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,SAAS,EAAE,YAAY,EAAE,YAAY,CAAC,GAAG,aAUlF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,aASrC,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,CAAC"}
1
+ {"version":3,"file":"fp64.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAK3F,KAAK,SAAS,GAAG,EAAE,CAAC;AACpB,KAAK,YAAY,GAAG;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC;AACjD,KAAK,YAAY,GAAG,EAAE,CAAC;AAEvB,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,WAAW,CAAC;IAChC,cAAc,EAAE,OAAO,cAAc,CAAC;CACvC,CAAC;AAUF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,SAAS,EAAE,YAAY,EAAE,YAAY,CAAC,GAAG,aAYlF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,aASrC,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,CAAC"}
@@ -3,19 +3,25 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
  import { fp64ify, fp64LowPart, fp64ifyMatrix4 } from "../../../modules/math/fp64/fp64-utils.js";
5
5
  import { fp64arithmeticShader } from "./fp64-arithmetic-glsl.js";
6
+ import { fp64arithmeticWGSL } from "./fp64-arithmetic-wgsl.js";
6
7
  import { fp64functionShader } from "./fp64-functions-glsl.js";
7
8
  const defaultUniforms = {
8
9
  // Used in LUMA_FP64_CODE_ELIMINATION_WORKAROUND
9
- ONE: 1.0
10
+ ONE: 1.0,
11
+ // Runtime split factor for Dekker splitting. Keeping this as a uniform helps
12
+ // prevent aggressive constant folding in shader compilers.
13
+ SPLIT: 4097.0
10
14
  };
11
15
  /**
12
16
  * 64bit arithmetic: add, sub, mul, div (small subset of fp64 module)
13
17
  */
14
18
  export const fp64arithmetic = {
15
19
  name: 'fp64arithmetic',
20
+ source: fp64arithmeticWGSL,
21
+ fs: fp64arithmeticShader,
16
22
  vs: fp64arithmeticShader,
17
23
  defaultUniforms,
18
- uniformTypes: { ONE: 'f32' },
24
+ uniformTypes: { ONE: 'f32', SPLIT: 'f32' },
19
25
  // Additional Functions
20
26
  fp64ify,
21
27
  fp64LowPart,
@@ -1 +1 @@
1
- {"version":3,"file":"fp64.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAC3F,OAAO,EAAC,oBAAoB,EAAC,kCAA+B;AAC5D,OAAO,EAAC,kBAAkB,EAAC,iCAA8B;AAYzD,MAAM,eAAe,GAAiB;IACpC,gDAAgD;IAChD,GAAG,EAAE,GAAG;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAwE;IACjG,IAAI,EAAE,gBAAgB;IACtB,EAAE,EAAE,oBAAoB;IACxB,eAAe;IACf,YAAY,EAAE,EAAC,GAAG,EAAE,KAAK,EAAC;IAE1B,uBAAuB;IACvB,OAAO;IACP,WAAW;IACX,cAAc;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAqC;IACpD,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,kBAAkB;IACtB,YAAY,EAAE,CAAC,cAAc,CAAC;IAE9B,uBAAuB;IACvB,OAAO;IACP,WAAW;IACX,cAAc;CACf,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,CAAC"}
1
+ {"version":3,"file":"fp64.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAC3F,OAAO,EAAC,oBAAoB,EAAC,kCAA+B;AAC5D,OAAO,EAAC,kBAAkB,EAAC,kCAA+B;AAC1D,OAAO,EAAC,kBAAkB,EAAC,iCAA8B;AAYzD,MAAM,eAAe,GAAiB;IACpC,gDAAgD;IAChD,GAAG,EAAE,GAAG;IACR,6EAA6E;IAC7E,2DAA2D;IAC3D,KAAK,EAAE,MAAM;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAwE;IACjG,IAAI,EAAE,gBAAgB;IACtB,MAAM,EAAE,kBAAkB;IAC1B,EAAE,EAAE,oBAAoB;IACxB,EAAE,EAAE,oBAAoB;IACxB,eAAe;IACf,YAAY,EAAE,EAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC;IAExC,uBAAuB;IACvB,OAAO;IACP,WAAW;IACX,cAAc;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAqC;IACpD,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,kBAAkB;IACtB,YAAY,EAAE,CAAC,cAAc,CAAC;IAE9B,uBAAuB;IACvB,OAAO;IACP,WAAW;IACX,cAAc;CACf,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /** Quick random generator for fragment shaders */
2
2
  export declare const random: {
3
3
  readonly name: "random";
4
- readonly source: "fn random(scale: vec3f, seed: float) -> f32 {\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";
4
+ readonly source: "fn random(scale: vec3f, seed: f32) -> f32 {\n return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);\n}\n";
5
5
  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";
6
6
  };
7
7
  //# sourceMappingURL=random.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAoBA,kDAAkD;AAClD,eAAO,MAAM,MAAM;;;;CAIsB,CAAC"}
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAmBA,kDAAkD;AAClD,eAAO,MAAM,MAAM;;;;CAIsB,CAAC"}
@@ -2,9 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
  const source = /* wgsl */ `\
5
- fn random(scale: vec3f, seed: float) -> f32 {
6
- /* use the fragment position for a different seed per-pixel */
7
- return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
5
+ fn random(scale: vec3f, seed: f32) -> f32 {
6
+ return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
8
7
  }
9
8
  `;
10
9
  const fs = /* glsl */ `\
@@ -1 +1 @@
1
- {"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,MAAM,MAAM,GAAG,UAAU,CAAC;;;;;CAKzB,CAAC;AAEF,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;CAKrB,CAAC;AAEF,kDAAkD;AAClD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,MAAM;IACN,EAAE;CACqC,CAAC"}
1
+ {"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,MAAM,MAAM,GAAG,UAAU,CAAC;;;;CAIzB,CAAC;AAEF,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;CAKrB,CAAC;AAEF,kDAAkD;AAClD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,MAAM;IACN,EAAE;CACqC,CAAC"}