@deck.gl/aggregation-layers 9.4.0-alpha.1 → 9.4.0-alpha.2

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 (78) hide show
  1. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.d.ts.map +1 -1
  2. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js +1 -3
  3. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js.map +1 -1
  4. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js +0 -1
  5. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js.map +1 -1
  6. package/dist/dist.dev.js +499 -25
  7. package/dist/grid-layer/grid-cell-layer.d.ts.map +1 -1
  8. package/dist/grid-layer/grid-cell-layer.js +2 -1
  9. package/dist/grid-layer/grid-cell-layer.js.map +1 -1
  10. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts +2 -0
  11. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts.map +1 -1
  12. package/dist/heatmap-layer/heatmap-layer-uniforms.js +19 -0
  13. package/dist/heatmap-layer/heatmap-layer-uniforms.js.map +1 -1
  14. package/dist/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  15. package/dist/heatmap-layer/heatmap-layer.js +59 -12
  16. package/dist/heatmap-layer/heatmap-layer.js.map +1 -1
  17. package/dist/heatmap-layer/max.wgsl.d.ts +3 -0
  18. package/dist/heatmap-layer/max.wgsl.d.ts.map +1 -0
  19. package/dist/heatmap-layer/max.wgsl.js +48 -0
  20. package/dist/heatmap-layer/max.wgsl.js.map +1 -0
  21. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts +1 -0
  22. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts.map +1 -1
  23. package/dist/heatmap-layer/triangle-layer-uniforms.js +16 -0
  24. package/dist/heatmap-layer/triangle-layer-uniforms.js.map +1 -1
  25. package/dist/heatmap-layer/triangle-layer.d.ts.map +1 -1
  26. package/dist/heatmap-layer/triangle-layer.js +3 -2
  27. package/dist/heatmap-layer/triangle-layer.js.map +1 -1
  28. package/dist/heatmap-layer/triangle-layer.wgsl.d.ts +3 -0
  29. package/dist/heatmap-layer/triangle-layer.wgsl.d.ts.map +1 -0
  30. package/dist/heatmap-layer/triangle-layer.wgsl.js +65 -0
  31. package/dist/heatmap-layer/triangle-layer.wgsl.js.map +1 -0
  32. package/dist/heatmap-layer/weights.wgsl.d.ts +3 -0
  33. package/dist/heatmap-layer/weights.wgsl.d.ts.map +1 -0
  34. package/dist/heatmap-layer/weights.wgsl.js +64 -0
  35. package/dist/heatmap-layer/weights.wgsl.js.map +1 -0
  36. package/dist/hexagon-layer/hexagon-cell-layer.d.ts.map +1 -1
  37. package/dist/hexagon-layer/hexagon-cell-layer.js +2 -1
  38. package/dist/hexagon-layer/hexagon-cell-layer.js.map +1 -1
  39. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.d.ts +3 -0
  40. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.d.ts.map +1 -0
  41. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.js +120 -0
  42. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.js.map +1 -0
  43. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts +1 -0
  44. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts.map +1 -1
  45. package/dist/hexagon-layer/hexagon-layer-uniforms.js +13 -0
  46. package/dist/hexagon-layer/hexagon-layer-uniforms.js.map +1 -1
  47. package/dist/index.cjs +499 -25
  48. package/dist/index.cjs.map +4 -4
  49. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts +1 -6
  50. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
  51. package/dist/screen-grid-layer/screen-grid-cell-layer.js +3 -2
  52. package/dist/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  53. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.d.ts +3 -0
  54. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.d.ts.map +1 -0
  55. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.js +76 -0
  56. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.js.map +1 -0
  57. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts +1 -0
  58. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts.map +1 -1
  59. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js +12 -0
  60. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js.map +1 -1
  61. package/dist.min.js +426 -35
  62. package/package.json +9 -5
  63. package/src/common/aggregator/gpu-aggregator/webgl-aggregation-transform.ts +1 -3
  64. package/src/common/aggregator/gpu-aggregator/webgl-bin-sorter.ts +0 -1
  65. package/src/grid-layer/grid-cell-layer.ts +2 -1
  66. package/src/heatmap-layer/heatmap-layer-uniforms.ts +20 -0
  67. package/src/heatmap-layer/heatmap-layer.ts +67 -13
  68. package/src/heatmap-layer/max.wgsl.ts +48 -0
  69. package/src/heatmap-layer/triangle-layer-uniforms.ts +17 -0
  70. package/src/heatmap-layer/triangle-layer.ts +3 -2
  71. package/src/heatmap-layer/triangle-layer.wgsl.ts +65 -0
  72. package/src/heatmap-layer/weights.wgsl.ts +64 -0
  73. package/src/hexagon-layer/hexagon-cell-layer.ts +2 -1
  74. package/src/hexagon-layer/hexagon-cell-layer.wgsl.ts +120 -0
  75. package/src/hexagon-layer/hexagon-layer-uniforms.ts +14 -0
  76. package/src/screen-grid-layer/screen-grid-cell-layer.ts +4 -4
  77. package/src/screen-grid-layer/screen-grid-cell-layer.wgsl.ts +76 -0
  78. package/src/screen-grid-layer/screen-grid-layer-uniforms.ts +13 -0
package/dist/dist.dev.js CHANGED
@@ -631,7 +631,6 @@ void main() {
631
631
  const model = new import_engine.Model(device, {
632
632
  bufferLayout: props.bufferLayout,
633
633
  modules: [...props.modules || [], binSorterUniforms],
634
- // @ts-expect-error TODO fix luma type
635
634
  defines: { ...props.defines, NON_INSTANCED_MODEL: 1, NUM_CHANNELS: props.channelCount },
636
635
  isInstanced: false,
637
636
  vs,
@@ -745,6 +744,7 @@ void main() {
745
744
  transform.run({
746
745
  id: "gpu-aggregation-domain",
747
746
  framebuffer: target,
747
+ discard: false,
748
748
  parameters: {
749
749
  viewport: [0, 0, 2, 1]
750
750
  },
@@ -872,11 +872,8 @@ void main() {
872
872
  blendAlphaOperation: "max"
873
873
  },
874
874
  defines: {
875
- // @ts-expect-error TODO fix luma type
876
875
  NUM_DIMS: props.dimensions,
877
- // @ts-expect-error TODO fix luma type
878
876
  NUM_CHANNELS: props.channelCount,
879
- // @ts-expect-error TODO fix luma type
880
877
  SAMPLER_WIDTH: TEXTURE_WIDTH
881
878
  },
882
879
  varyings: ["binIds", "values"],
@@ -1146,11 +1143,11 @@ void main() {
1146
1143
  flatArray = new ArrayType(colorRange.length * 4);
1147
1144
  let index = 0;
1148
1145
  for (let i = 0; i < colorRange.length; i++) {
1149
- const color = colorRange[i];
1150
- flatArray[index++] = color[0];
1151
- flatArray[index++] = color[1];
1152
- flatArray[index++] = color[2];
1153
- flatArray[index++] = Number.isFinite(color[3]) ? color[3] : 255;
1146
+ const color3 = colorRange[i];
1147
+ flatArray[index++] = color3[0];
1148
+ flatArray[index++] = color3[1];
1149
+ flatArray[index++] = color3[2];
1150
+ flatArray[index++] = Number.isFinite(color3[3]) ? color3[3] : 255;
1154
1151
  }
1155
1152
  }
1156
1153
  if (normalize) {
@@ -1188,6 +1185,83 @@ void main() {
1188
1185
  });
1189
1186
  }
1190
1187
 
1188
+ // src/screen-grid-layer/screen-grid-cell-layer.wgsl.ts
1189
+ var screen_grid_cell_layer_wgsl_default = (
1190
+ /* wgsl */
1191
+ `
1192
+ struct Attributes {
1193
+ @builtin(instance_index) instanceIndex: u32,
1194
+ @location(0) positions: vec2<f32>,
1195
+ @location(1) instancePositions: vec2<f32>,
1196
+ @location(2) instanceWeights: f32,
1197
+ };
1198
+
1199
+ struct Varyings {
1200
+ @builtin(position) position: vec4<f32>,
1201
+ @location(0) color: vec4<f32>,
1202
+ @location(1) pickingColor: vec3<f32>,
1203
+ };
1204
+
1205
+ fn sampleColorRange(value: f32, domain: vec2<f32>) -> vec4<f32> {
1206
+ let ratio = (value - domain.x) / (domain.y - domain.x);
1207
+ return textureSampleLevel(colorRange, colorRangeSampler, vec2<f32>(ratio, 0.5), 0.0);
1208
+ }
1209
+
1210
+ @vertex
1211
+ fn vertexMain(attributes: Attributes) -> Varyings {
1212
+ var output: Varyings;
1213
+ output.pickingColor = picking_getPickingColorFromIndex(attributes.instanceIndex);
1214
+
1215
+ if (attributes.instanceWeights != attributes.instanceWeights) {
1216
+ output.position = vec4<f32>(0.0);
1217
+ output.color = vec4<f32>(0.0);
1218
+ return output;
1219
+ }
1220
+
1221
+ var position =
1222
+ attributes.instancePositions * screenGrid.gridSizeClipspace +
1223
+ attributes.positions * screenGrid.cellSizeClipspace;
1224
+ position.x -= 1.0;
1225
+ position.y = 1.0 - position.y;
1226
+
1227
+ output.position = vec4<f32>(position, 0.0, 1.0);
1228
+ let colorValue = sampleColorRange(attributes.instanceWeights, screenGrid.colorDomain);
1229
+ output.color = vec4<f32>(colorValue.rgb, colorValue.a * layer.opacity);
1230
+ return output;
1231
+ }
1232
+
1233
+ @fragment
1234
+ fn fragmentMain(varyings: Varyings) -> @location(0) vec4<f32> {
1235
+ if (picking.isActive > 0.5) {
1236
+ if (!picking_isColorValid(varyings.pickingColor)) {
1237
+ discard;
1238
+ }
1239
+ return vec4<f32>(varyings.pickingColor, 1.0);
1240
+ }
1241
+
1242
+ var color = varyings.color;
1243
+ if (picking.isHighlightActive > 0.5) {
1244
+ let highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
1245
+ if (picking_isColorZero(abs(varyings.pickingColor - highlightedObjectColor))) {
1246
+ let highLightAlpha = picking.highlightColor.a;
1247
+ let blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
1248
+ if (blendedAlpha > 0.0) {
1249
+ let highLightRatio = highLightAlpha / blendedAlpha;
1250
+ color = vec4<f32>(
1251
+ mix(color.rgb, picking.highlightColor.rgb, highLightRatio),
1252
+ blendedAlpha
1253
+ );
1254
+ } else {
1255
+ color = vec4<f32>(color.rgb, 0.0);
1256
+ }
1257
+ }
1258
+ }
1259
+
1260
+ return deckgl_premultiplied_alpha(color);
1261
+ }
1262
+ `
1263
+ );
1264
+
1191
1265
  // src/screen-grid-layer/screen-grid-layer-vertex.glsl.ts
1192
1266
  var screen_grid_layer_vertex_glsl_default = (
1193
1267
  /* glsl */
@@ -1250,6 +1324,20 @@ void main(void) {
1250
1324
  );
1251
1325
 
1252
1326
  // src/screen-grid-layer/screen-grid-layer-uniforms.ts
1327
+ var uniformBlockWGSL = (
1328
+ /* wgsl */
1329
+ `
1330
+ struct ScreenGridUniforms {
1331
+ cellSizeClipspace: vec2<f32>,
1332
+ gridSizeClipspace: vec2<f32>,
1333
+ colorDomain: vec2<f32>,
1334
+ };
1335
+
1336
+ @group(0) @binding(auto) var<uniform> screenGrid: ScreenGridUniforms;
1337
+ @group(0) @binding(auto) var colorRange: texture_2d<f32>;
1338
+ @group(0) @binding(auto) var colorRangeSampler: sampler;
1339
+ `
1340
+ );
1253
1341
  var uniformBlock3 = (
1254
1342
  /* glsl */
1255
1343
  `layout(std140) uniform screenGridUniforms {
@@ -1261,6 +1349,7 @@ void main(void) {
1261
1349
  );
1262
1350
  var screenGridUniforms = {
1263
1351
  name: "screenGrid",
1352
+ source: uniformBlockWGSL,
1264
1353
  vs: uniformBlock3,
1265
1354
  uniformTypes: {
1266
1355
  cellSizeClipspace: "vec2<f32>",
@@ -1272,7 +1361,7 @@ void main(void) {
1272
1361
  // src/screen-grid-layer/screen-grid-cell-layer.ts
1273
1362
  var ScreenGridCellLayer = class extends import_core4.Layer {
1274
1363
  getShaders() {
1275
- return super.getShaders({ vs: screen_grid_layer_vertex_glsl_default, fs: screen_grid_layer_fragment_glsl_default, modules: [import_core4.picking, screenGridUniforms] });
1364
+ return super.getShaders({ source: screen_grid_cell_layer_wgsl_default, vs: screen_grid_layer_vertex_glsl_default, fs: screen_grid_layer_fragment_glsl_default, modules: [import_core4.color, import_core4.picking, screenGridUniforms] });
1276
1365
  }
1277
1366
  initializeState() {
1278
1367
  this.getAttributeManager().addInstanced({
@@ -1740,6 +1829,126 @@ void main(void) {
1740
1829
  // src/hexagon-layer/hexagon-cell-layer.ts
1741
1830
  var import_layers2 = __toESM(require_layers(), 1);
1742
1831
 
1832
+ // src/hexagon-layer/hexagon-cell-layer.wgsl.ts
1833
+ var hexagon_cell_layer_wgsl_default = (
1834
+ /* wgsl */
1835
+ `const HEXBIN_DISTANCE: vec2<f32> = vec2<f32>(1.7320508, 1.5);
1836
+
1837
+ struct Attributes {
1838
+ @builtin(instance_index) instanceIndex: u32,
1839
+ @location(0) positions: vec3<f32>,
1840
+ @location(1) normals: vec3<f32>,
1841
+ @location(2) instancePositions: vec2<f32>,
1842
+ @location(3) instanceColorValues: f32,
1843
+ @location(4) instanceElevationValues: f32,
1844
+ };
1845
+
1846
+ struct Varyings {
1847
+ @builtin(position) position: vec4<f32>,
1848
+ @location(0) color: vec4<f32>,
1849
+ @location(1) pickingColor: vec3<f32>,
1850
+ };
1851
+
1852
+ fn hexbinCentroid(binId: vec2<f32>, radius: f32) -> vec2<f32> {
1853
+ var adjustedBinId = binId;
1854
+ adjustedBinId.x += fract(adjustedBinId.y * 0.5);
1855
+ return adjustedBinId * HEXBIN_DISTANCE * radius;
1856
+ }
1857
+
1858
+ fn interpolate(value: f32, domain: vec2<f32>, range: vec2<f32>) -> f32 {
1859
+ let ratio = clamp((value - domain.x) / (domain.y - domain.x), 0.0, 1.0);
1860
+ return mix(range.x, range.y, ratio);
1861
+ }
1862
+
1863
+ fn sampleColorRange(value: f32, domain: vec2<f32>) -> vec4<f32> {
1864
+ let ratio = (value - domain.x) / (domain.y - domain.x);
1865
+ return textureSampleLevel(colorRange, colorRangeSampler, vec2<f32>(ratio, 0.5), 0.0);
1866
+ }
1867
+
1868
+ @vertex
1869
+ fn vertexMain(attributes: Attributes) -> Varyings {
1870
+ var output: Varyings;
1871
+ geometry.pickingColor = picking_getPickingColorFromIndex(attributes.instanceIndex);
1872
+ output.pickingColor = geometry.pickingColor;
1873
+
1874
+ if (
1875
+ attributes.instanceColorValues != attributes.instanceColorValues ||
1876
+ attributes.instanceColorValues < hexagon.colorDomain.z ||
1877
+ attributes.instanceColorValues > hexagon.colorDomain.w ||
1878
+ attributes.instanceElevationValues < hexagon.elevationDomain.z ||
1879
+ attributes.instanceElevationValues > hexagon.elevationDomain.w
1880
+ ) {
1881
+ output.position = vec4<f32>(0.0);
1882
+ output.color = vec4<f32>(0.0);
1883
+ return output;
1884
+ }
1885
+
1886
+ var commonPosition =
1887
+ hexbinCentroid(attributes.instancePositions, column.radius) +
1888
+ (hexagon.originCommon - project.commonOrigin.xy);
1889
+ commonPosition += attributes.positions.xy * column.radius * column.coverage;
1890
+ geometry.position = vec4<f32>(commonPosition, 0.0, 1.0);
1891
+ geometry.normal = project_normal(attributes.normals);
1892
+
1893
+ if (column.extruded > 0.5) {
1894
+ var elevation = interpolate(
1895
+ attributes.instanceElevationValues,
1896
+ hexagon.elevationDomain.xy,
1897
+ hexagon.elevationRange
1898
+ );
1899
+ elevation = project_size_float(elevation);
1900
+ geometry.position.z = (attributes.positions.z + 1.0) / 2.0 * elevation;
1901
+ }
1902
+
1903
+ output.position = project_common_position_to_clipspace(geometry.position);
1904
+ var colorValue = sampleColorRange(attributes.instanceColorValues, hexagon.colorDomain.xy);
1905
+ if (column.extruded > 0.5) {
1906
+ colorValue = vec4<f32>(
1907
+ lighting_getLightColor2(
1908
+ colorValue.rgb,
1909
+ project.cameraPosition,
1910
+ geometry.position.xyz,
1911
+ geometry.normal
1912
+ ),
1913
+ colorValue.a
1914
+ );
1915
+ }
1916
+ output.color = vec4<f32>(colorValue.rgb, colorValue.a * layer.opacity);
1917
+ return output;
1918
+ }
1919
+
1920
+ @fragment
1921
+ fn fragmentMain(varyings: Varyings) -> @location(0) vec4<f32> {
1922
+ if (picking.isActive > 0.5) {
1923
+ if (!picking_isColorValid(varyings.pickingColor)) {
1924
+ discard;
1925
+ }
1926
+ return vec4<f32>(varyings.pickingColor, 1.0);
1927
+ }
1928
+
1929
+ var color = varyings.color;
1930
+ if (picking.isHighlightActive > 0.5) {
1931
+ let highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
1932
+ if (picking_isColorZero(abs(varyings.pickingColor - highlightedObjectColor))) {
1933
+ let highLightAlpha = picking.highlightColor.a;
1934
+ let blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
1935
+ if (blendedAlpha > 0.0) {
1936
+ let highLightRatio = highLightAlpha / blendedAlpha;
1937
+ color = vec4<f32>(
1938
+ mix(color.rgb, picking.highlightColor.rgb, highLightRatio),
1939
+ blendedAlpha
1940
+ );
1941
+ } else {
1942
+ color = vec4<f32>(color.rgb, 0.0);
1943
+ }
1944
+ }
1945
+ }
1946
+
1947
+ return deckgl_premultiplied_alpha(color);
1948
+ }
1949
+ `
1950
+ );
1951
+
1743
1952
  // src/hexagon-layer/hexbin.ts
1744
1953
  var THIRD_PI = Math.PI / 3;
1745
1954
  var DIST_X = 2 * Math.sin(THIRD_PI);
@@ -1874,6 +2083,20 @@ void main(void) {
1874
2083
  );
1875
2084
 
1876
2085
  // src/hexagon-layer/hexagon-layer-uniforms.ts
2086
+ var uniformBlockWGSL2 = (
2087
+ /* wgsl */
2088
+ `struct HexagonUniforms {
2089
+ colorDomain: vec4<f32>,
2090
+ elevationDomain: vec4<f32>,
2091
+ elevationRange: vec2<f32>,
2092
+ originCommon: vec2<f32>,
2093
+ };
2094
+
2095
+ @group(0) @binding(auto) var<uniform> hexagon: HexagonUniforms;
2096
+ @group(0) @binding(auto) var colorRange: texture_2d<f32>;
2097
+ @group(0) @binding(auto) var colorRangeSampler: sampler;
2098
+ `
2099
+ );
1877
2100
  var uniformBlock5 = (
1878
2101
  /* glsl */
1879
2102
  `layout(std140) uniform hexagonUniforms {
@@ -1886,6 +2109,7 @@ void main(void) {
1886
2109
  );
1887
2110
  var hexagonUniforms = {
1888
2111
  name: "hexagon",
2112
+ source: uniformBlockWGSL2,
1889
2113
  vs: uniformBlock5,
1890
2114
  uniformTypes: {
1891
2115
  colorDomain: "vec4<f32>",
@@ -1900,7 +2124,7 @@ void main(void) {
1900
2124
  getShaders() {
1901
2125
  const shaders = super.getShaders();
1902
2126
  shaders.modules.push(hexagonUniforms);
1903
- return { ...shaders, vs: hexagon_cell_layer_vertex_glsl_default };
2127
+ return { ...shaders, source: hexagon_cell_layer_wgsl_default, vs: hexagon_cell_layer_vertex_glsl_default };
1904
2128
  }
1905
2129
  initializeState() {
1906
2130
  super.initializeState();
@@ -5008,7 +5232,8 @@ void main(void) {
5008
5232
  }
5009
5233
  _updateGeometry() {
5010
5234
  const geometry = new import_engine4.CubeGeometry();
5011
- this.state.fillModel.setGeometry(geometry);
5235
+ this._setFillGeometry(geometry);
5236
+ this._setWireframeGeometry(geometry);
5012
5237
  }
5013
5238
  draw({ uniforms }) {
5014
5239
  const {
@@ -5494,6 +5719,71 @@ void main(void) {
5494
5719
  var import_engine5 = __toESM(require_engine(), 1);
5495
5720
  var import_core10 = __toESM(require_core(), 1);
5496
5721
 
5722
+ // src/heatmap-layer/triangle-layer.wgsl.ts
5723
+ var triangle_layer_wgsl_default = (
5724
+ /* wgsl */
5725
+ `struct TriangleAttributes {
5726
+ @location(0) positions: vec3<f32>,
5727
+ @location(1) texCoords: vec2<f32>,
5728
+ };
5729
+
5730
+ struct TriangleVaryings {
5731
+ @builtin(position) position: vec4<f32>,
5732
+ @location(0) textureCoordinates: vec2<f32>,
5733
+ @location(1) intensityMinimum: f32,
5734
+ @location(2) intensityMaximum: f32,
5735
+ };
5736
+
5737
+ @vertex
5738
+ fn vertexMain(attributes: TriangleAttributes) -> TriangleVaryings {
5739
+ var output: TriangleVaryings;
5740
+ output.position = project_position_to_clipspace(
5741
+ attributes.positions,
5742
+ vec3<f32>(0.0),
5743
+ vec3<f32>(0.0)
5744
+ );
5745
+ // WebGPU render-target textures use a top-left origin.
5746
+ output.textureCoordinates = vec2<f32>(attributes.texCoords.x, 1.0 - attributes.texCoords.y);
5747
+
5748
+ let maxWeights = textureLoad(maxTexture, vec2<i32>(0), 0);
5749
+ var maximumValue = select(maxWeights.r, maxWeights.g, triangle.aggregationMode > 0.5);
5750
+ var minimumValue = maximumValue * triangle.threshold;
5751
+
5752
+ if (triangle.colorDomain.y > 0.0) {
5753
+ maximumValue = triangle.colorDomain.y;
5754
+ minimumValue = triangle.colorDomain.x;
5755
+ }
5756
+
5757
+ output.intensityMaximum = triangle.intensity / maximumValue;
5758
+ output.intensityMinimum = triangle.intensity / minimumValue;
5759
+ return output;
5760
+ }
5761
+
5762
+ @fragment
5763
+ fn fragmentMain(varyings: TriangleVaryings) -> @location(0) vec4<f32> {
5764
+ let weights = textureSample(weightsTexture, weightsTextureSampler, varyings.textureCoordinates);
5765
+ var weight = weights.r;
5766
+
5767
+ if (triangle.aggregationMode > 0.5) {
5768
+ weight /= max(1.0, weights.a);
5769
+ }
5770
+
5771
+ let colorCoordinates = vec2<f32>(
5772
+ clamp(weight * varyings.intensityMaximum, 0.0, 1.0),
5773
+ 0.5
5774
+ );
5775
+ var color = textureSample(colorTexture, colorTextureSampler, colorCoordinates);
5776
+
5777
+ if (weight <= 0.0) {
5778
+ discard;
5779
+ }
5780
+
5781
+ color.a *= min(weight * varyings.intensityMinimum, 1.0) * layer.opacity;
5782
+ return deckgl_premultiplied_alpha(color);
5783
+ }
5784
+ `
5785
+ );
5786
+
5497
5787
  // src/heatmap-layer/triangle-layer-vertex.glsl.ts
5498
5788
  var triangle_layer_vertex_glsl_default = `#version 300 es
5499
5789
  #define SHADER_NAME heatp-map-layer-vertex-shader
@@ -5565,6 +5855,23 @@ void main(void) {
5565
5855
  `;
5566
5856
 
5567
5857
  // src/heatmap-layer/triangle-layer-uniforms.ts
5858
+ var uniformBlockWGSL3 = (
5859
+ /* wgsl */
5860
+ `struct triangleUniforms {
5861
+ aggregationMode: f32,
5862
+ colorDomain: vec2<f32>,
5863
+ intensity: f32,
5864
+ threshold: f32,
5865
+ };
5866
+
5867
+ @group(0) @binding(auto) var<uniform> triangle: triangleUniforms;
5868
+ @group(0) @binding(auto) var colorTexture: texture_2d<f32>;
5869
+ @group(0) @binding(auto) var colorTextureSampler: sampler;
5870
+ @group(0) @binding(auto) var maxTexture: texture_2d<f32>;
5871
+ @group(0) @binding(auto) var weightsTexture: texture_2d<f32>;
5872
+ @group(0) @binding(auto) var weightsTextureSampler: sampler;
5873
+ `
5874
+ );
5568
5875
  var uniformBlock10 = `layout(std140) uniform triangleUniforms {
5569
5876
  float aggregationMode;
5570
5877
  vec2 colorDomain;
@@ -5574,6 +5881,7 @@ void main(void) {
5574
5881
  `;
5575
5882
  var triangleUniforms = {
5576
5883
  name: "triangle",
5884
+ source: uniformBlockWGSL3,
5577
5885
  vs: uniformBlock10,
5578
5886
  fs: uniformBlock10,
5579
5887
  uniformTypes: {
@@ -5587,7 +5895,7 @@ void main(void) {
5587
5895
  // src/heatmap-layer/triangle-layer.ts
5588
5896
  var TriangleLayer = class extends import_core10.Layer {
5589
5897
  getShaders() {
5590
- return super.getShaders({ vs: triangle_layer_vertex_glsl_default, fs: triangle_layer_fragment_glsl_default, modules: [import_core10.project32, triangleUniforms] });
5898
+ return super.getShaders({ source: triangle_layer_wgsl_default, vs: triangle_layer_vertex_glsl_default, fs: triangle_layer_fragment_glsl_default, modules: [import_core10.project32, import_core10.color, triangleUniforms] });
5591
5899
  }
5592
5900
  initializeState({ device }) {
5593
5901
  this.setState({ model: this._getModel(device) });
@@ -5840,7 +6148,131 @@ void main() {
5840
6148
  }
5841
6149
  `;
5842
6150
 
6151
+ // src/heatmap-layer/max.wgsl.ts
6152
+ var max_wgsl_default = (
6153
+ /* wgsl */
6154
+ `struct MaxWeightVaryings {
6155
+ @builtin(position) position: vec4<f32>,
6156
+ @location(0) weights: vec4<f32>,
6157
+ };
6158
+
6159
+ const MAX_WEIGHT_REDUCTION_SIZE: u32 = 16u;
6160
+
6161
+ @vertex
6162
+ fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> MaxWeightVaryings {
6163
+ var output: MaxWeightVaryings;
6164
+ let textureSize = u32(maxWeight.textureSize);
6165
+ let reducedTextureSize =
6166
+ (textureSize + MAX_WEIGHT_REDUCTION_SIZE - 1u) / MAX_WEIGHT_REDUCTION_SIZE;
6167
+ let blockCoordinates = vec2<u32>(
6168
+ vertexIndex % reducedTextureSize,
6169
+ vertexIndex / reducedTextureSize
6170
+ );
6171
+ var maximumWeights = vec4<f32>(0.0);
6172
+
6173
+ for (var y = 0u; y < MAX_WEIGHT_REDUCTION_SIZE; y++) {
6174
+ for (var x = 0u; x < MAX_WEIGHT_REDUCTION_SIZE; x++) {
6175
+ let textureCoordinates = blockCoordinates * MAX_WEIGHT_REDUCTION_SIZE + vec2<u32>(x, y);
6176
+
6177
+ if (textureCoordinates.x < textureSize && textureCoordinates.y < textureSize) {
6178
+ let weights = textureLoad(inTexture, vec2<i32>(textureCoordinates), 0);
6179
+ maximumWeights.r = max(maximumWeights.r, weights.r);
6180
+ maximumWeights.g = max(maximumWeights.g, weights.r / max(1.0, weights.a));
6181
+ maximumWeights.b = max(maximumWeights.b, weights.b);
6182
+ maximumWeights.a = max(maximumWeights.a, weights.a);
6183
+ }
6184
+ }
6185
+ }
6186
+
6187
+ output.position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
6188
+ output.weights = maximumWeights;
6189
+ return output;
6190
+ }
6191
+
6192
+ @fragment
6193
+ fn fragmentMain(varyings: MaxWeightVaryings) -> @location(0) vec4<f32> {
6194
+ return varyings.weights;
6195
+ }
6196
+ `
6197
+ );
6198
+
6199
+ // src/heatmap-layer/weights.wgsl.ts
6200
+ var weights_wgsl_default = (
6201
+ /* wgsl */
6202
+ `struct WeightAttributes {
6203
+ @builtin(vertex_index) vertexIndex: u32,
6204
+ @location(0) instancePositions: vec3<f32>,
6205
+ @location(1) instancePositions64Low: vec3<f32>,
6206
+ @location(2) instanceWeights: f32,
6207
+ };
6208
+
6209
+ struct WeightVaryings {
6210
+ @builtin(position) position: vec4<f32>,
6211
+ @location(0) pointCoordinates: vec2<f32>,
6212
+ @location(1) weights: vec4<f32>,
6213
+ };
6214
+
6215
+ const WEIGHT_QUAD_POSITIONS = array<vec2<f32>, 6>(
6216
+ vec2<f32>(-1.0, -1.0),
6217
+ vec2<f32>(1.0, -1.0),
6218
+ vec2<f32>(-1.0, 1.0),
6219
+ vec2<f32>(-1.0, 1.0),
6220
+ vec2<f32>(1.0, -1.0),
6221
+ vec2<f32>(1.0, 1.0)
6222
+ );
6223
+
6224
+ @vertex
6225
+ fn vertexMain(attributes: WeightAttributes) -> WeightVaryings {
6226
+ var output: WeightVaryings;
6227
+ let commonPosition = project_position_vec3_f64(
6228
+ attributes.instancePositions,
6229
+ attributes.instancePositions64Low
6230
+ );
6231
+ let clipPosition =
6232
+ (commonPosition.xy - weight.commonBounds.xy) /
6233
+ (weight.commonBounds.zw - weight.commonBounds.xy) * 2.0 - vec2<f32>(1.0);
6234
+ let radiusTexels =
6235
+ project_pixel_size_float(weight.radiusPixels) * weight.textureWidth /
6236
+ (weight.commonBounds.z - weight.commonBounds.x);
6237
+ let offset = WEIGHT_QUAD_POSITIONS[attributes.vertexIndex];
6238
+
6239
+ output.position = vec4<f32>(
6240
+ clipPosition + offset * radiusTexels * 2.0 / weight.textureWidth,
6241
+ 0.0,
6242
+ 1.0
6243
+ );
6244
+ output.pointCoordinates = (offset + vec2<f32>(1.0)) * 0.5;
6245
+ output.weights = vec4<f32>(attributes.instanceWeights * weight.weightsScale, 0.0, 0.0, 1.0);
6246
+ return output;
6247
+ }
6248
+
6249
+ @fragment
6250
+ fn fragmentMain(varyings: WeightVaryings) -> @location(0) vec4<f32> {
6251
+ let distanceFromCenter = length(varyings.pointCoordinates - vec2<f32>(0.5));
6252
+ if (distanceFromCenter > 0.5) {
6253
+ discard;
6254
+ }
6255
+
6256
+ let gaussian = exp(-pow(2.0 * distanceFromCenter, 2.0) / 0.05555) /
6257
+ (1.77245385 * 0.166666);
6258
+ return varyings.weights * gaussian;
6259
+ }
6260
+ `
6261
+ );
6262
+
5843
6263
  // src/heatmap-layer/heatmap-layer-uniforms.ts
6264
+ var uniformBlockWGSL4 = (
6265
+ /* wgsl */
6266
+ `struct weightUniforms {
6267
+ commonBounds: vec4<f32>,
6268
+ radiusPixels: f32,
6269
+ textureWidth: f32,
6270
+ weightsScale: f32,
6271
+ };
6272
+
6273
+ @group(0) @binding(auto) var<uniform> weight: weightUniforms;
6274
+ `
6275
+ );
5844
6276
  var uniformBlock11 = `layout(std140) uniform weightUniforms {
5845
6277
  vec4 commonBounds;
5846
6278
  float radiusPixels;
@@ -5850,6 +6282,7 @@ void main() {
5850
6282
  `;
5851
6283
  var weightUniforms = {
5852
6284
  name: "weight",
6285
+ source: uniformBlockWGSL4,
5853
6286
  vs: uniformBlock11,
5854
6287
  uniformTypes: {
5855
6288
  commonBounds: "vec4<f32>",
@@ -5860,6 +6293,16 @@ void main() {
5860
6293
  };
5861
6294
  var maxWeightUniforms = {
5862
6295
  name: "maxWeight",
6296
+ source: (
6297
+ /* wgsl */
6298
+ `struct maxWeightUniforms {
6299
+ textureSize: f32,
6300
+ };
6301
+
6302
+ @group(0) @binding(auto) var<uniform> maxWeight: maxWeightUniforms;
6303
+ @group(0) @binding(auto) var inTexture: texture_2d<f32>;
6304
+ `
6305
+ ),
5863
6306
  vs: `layout(std140) uniform maxWeightUniforms {
5864
6307
  float textureSize;
5865
6308
  } maxWeight;
@@ -5871,6 +6314,7 @@ void main() {
5871
6314
 
5872
6315
  // src/heatmap-layer/heatmap-layer.ts
5873
6316
  var RESOLUTION = 2;
6317
+ var MAX_WEIGHT_REDUCTION_SIZE = 16;
5874
6318
  var TEXTURE_PROPS = {
5875
6319
  format: "rgba8unorm",
5876
6320
  dimension: "2d",
@@ -6062,18 +6506,33 @@ void main() {
6062
6506
  }
6063
6507
  _setupAttributes() {
6064
6508
  const attributeManager = this.getAttributeManager();
6065
- attributeManager.add({
6066
- positions: { size: 3, type: "float64", accessor: "getPosition" },
6067
- weights: { size: 1, accessor: "getWeight" }
6068
- });
6069
- this.setState({ positionAttributeName: "positions" });
6509
+ if (this.context.device.type === "webgpu") {
6510
+ attributeManager.addInstanced({
6511
+ instancePositions: {
6512
+ size: 3,
6513
+ type: "float64",
6514
+ accessor: "getPosition",
6515
+ // Normalize binary XY positions into the packed XYZ high/low layout WebGPU requires.
6516
+ transform: (position) => [position[0], position[1], position[2] ?? 0]
6517
+ },
6518
+ instanceWeights: { size: 1, accessor: "getWeight" }
6519
+ });
6520
+ this.setState({ positionAttributeName: "instancePositions" });
6521
+ } else {
6522
+ attributeManager.add({
6523
+ positions: { size: 3, type: "float64", accessor: "getPosition" },
6524
+ weights: { size: 1, accessor: "getWeight" }
6525
+ });
6526
+ this.setState({ positionAttributeName: "positions" });
6527
+ }
6070
6528
  }
6071
6529
  _setupTextureParams() {
6072
6530
  const { device } = this.context;
6073
6531
  const { weightsTextureSize } = this.props;
6074
6532
  const textureSize = Math.min(weightsTextureSize, device.limits.maxTextureDimension2D);
6075
- const floatTargetSupport = FLOAT_TARGET_FEATURES.every((feature) => device.features.has(feature));
6076
- const format = floatTargetSupport ? "rgba32float" : "rgba8unorm";
6533
+ const isWebGPU = device.type === "webgpu";
6534
+ const floatTargetSupport = isWebGPU ? device.getTextureFormatCapabilities("rgba16float").blend : FLOAT_TARGET_FEATURES.every((feature) => device.features.has(feature));
6535
+ const format = floatTargetSupport ? isWebGPU ? "rgba16float" : "rgba32float" : "rgba8unorm";
6077
6536
  const weightsScale = floatTargetSupport ? 1 : 1 / 255;
6078
6537
  this.setState({ textureSize, format, weightsScale });
6079
6538
  if (!floatTargetSupport) {
@@ -6085,13 +6544,20 @@ void main() {
6085
6544
  _createWeightsTransform(shaders) {
6086
6545
  let { weightsTransform } = this.state;
6087
6546
  const { weightsTexture } = this.state;
6547
+ const isWebGPU = this.context.device.type === "webgpu";
6088
6548
  const attributeManager = this.getAttributeManager();
6089
6549
  weightsTransform?.destroy();
6090
6550
  weightsTransform = new import_engine6.TextureTransform(this.context.device, {
6091
6551
  id: `${this.id}-weights-transform`,
6092
6552
  ...shaders,
6093
- bufferLayout: attributeManager.getBufferLayouts(),
6094
- vertexCount: 1,
6553
+ source: weights_wgsl_default,
6554
+ bufferLayout: attributeManager.getBufferLayouts({ isInstanced: isWebGPU }),
6555
+ vertexCount: isWebGPU ? 6 : 1,
6556
+ ...isWebGPU ? {
6557
+ colorAttachmentFormats: [weightsTexture.format],
6558
+ isInstanced: true,
6559
+ instanceCount: this.getNumInstances()
6560
+ } : {},
6095
6561
  targetTexture: weightsTexture,
6096
6562
  parameters: {
6097
6563
  depthWriteEnabled: false,
@@ -6102,7 +6568,7 @@ void main() {
6102
6568
  blendAlphaSrcFactor: "one",
6103
6569
  blendAlphaDstFactor: "one"
6104
6570
  },
6105
- topology: "point-list",
6571
+ topology: isWebGPU ? "triangle-list" : "point-list",
6106
6572
  modules: [...shaders.modules, weightUniforms]
6107
6573
  });
6108
6574
  this.setState({ weightsTransform });
@@ -6117,6 +6583,7 @@ void main() {
6117
6583
  });
6118
6584
  this._createWeightsTransform(weightsTransformShaders);
6119
6585
  const maxWeightsTransformShaders = this.getShaders({
6586
+ source: max_wgsl_default,
6120
6587
  vs: max_vs_glsl_default,
6121
6588
  fs: max_fs_glsl_default,
6122
6589
  modules: [maxWeightUniforms]
@@ -6125,7 +6592,8 @@ void main() {
6125
6592
  id: `${this.id}-max-weights-transform`,
6126
6593
  targetTexture: maxWeightsTexture,
6127
6594
  ...maxWeightsTransformShaders,
6128
- vertexCount: textureSize * textureSize,
6595
+ ...device.type === "webgpu" ? { colorAttachmentFormats: [maxWeightsTexture.format] } : {},
6596
+ vertexCount: device.type === "webgpu" ? Math.ceil(textureSize / MAX_WEIGHT_REDUCTION_SIZE) ** 2 : textureSize * textureSize,
6129
6597
  topology: "point-list",
6130
6598
  parameters: {
6131
6599
  depthWriteEnabled: false,
@@ -6239,7 +6707,13 @@ void main() {
6239
6707
  const attributes = attributeManager.getAttributes();
6240
6708
  const moduleSettings = this.getModuleSettings();
6241
6709
  this._setModelAttributes(weightsTransform.model, attributes);
6242
- weightsTransform.model.setVertexCount(this.getNumInstances());
6710
+ if (this.context.device.type === "webgpu") {
6711
+ const instanceCount = this.getNumInstances();
6712
+ weightsTransform.model.setVertexCount(instanceCount > 0 ? 6 : 0);
6713
+ weightsTransform.model.setInstanceCount(instanceCount);
6714
+ } else {
6715
+ weightsTransform.model.setVertexCount(this.getNumInstances());
6716
+ }
6243
6717
  const weightProps = {
6244
6718
  radiusPixels,
6245
6719
  commonBounds,