@deck.gl/aggregation-layers 9.3.7 → 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 (96) hide show
  1. package/dist/common/aggregation-layer.d.ts.map +1 -1
  2. package/dist/common/aggregation-layer.js +1 -3
  3. package/dist/common/aggregation-layer.js.map +1 -1
  4. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.d.ts.map +1 -1
  5. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js +1 -3
  6. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js.map +1 -1
  7. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js +0 -1
  8. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js.map +1 -1
  9. package/dist/dist.dev.js +502 -32
  10. package/dist/grid-layer/grid-cell-layer-vertex.glsl.d.ts +1 -1
  11. package/dist/grid-layer/grid-cell-layer-vertex.glsl.d.ts.map +1 -1
  12. package/dist/grid-layer/grid-cell-layer-vertex.glsl.js +1 -2
  13. package/dist/grid-layer/grid-cell-layer-vertex.glsl.js.map +1 -1
  14. package/dist/grid-layer/grid-cell-layer.d.ts.map +1 -1
  15. package/dist/grid-layer/grid-cell-layer.js +2 -1
  16. package/dist/grid-layer/grid-cell-layer.js.map +1 -1
  17. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts +2 -0
  18. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts.map +1 -1
  19. package/dist/heatmap-layer/heatmap-layer-uniforms.js +19 -0
  20. package/dist/heatmap-layer/heatmap-layer-uniforms.js.map +1 -1
  21. package/dist/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  22. package/dist/heatmap-layer/heatmap-layer.js +59 -12
  23. package/dist/heatmap-layer/heatmap-layer.js.map +1 -1
  24. package/dist/heatmap-layer/max.wgsl.d.ts +3 -0
  25. package/dist/heatmap-layer/max.wgsl.d.ts.map +1 -0
  26. package/dist/heatmap-layer/max.wgsl.js +48 -0
  27. package/dist/heatmap-layer/max.wgsl.js.map +1 -0
  28. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts +1 -0
  29. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts.map +1 -1
  30. package/dist/heatmap-layer/triangle-layer-uniforms.js +16 -0
  31. package/dist/heatmap-layer/triangle-layer-uniforms.js.map +1 -1
  32. package/dist/heatmap-layer/triangle-layer.d.ts.map +1 -1
  33. package/dist/heatmap-layer/triangle-layer.js +3 -2
  34. package/dist/heatmap-layer/triangle-layer.js.map +1 -1
  35. package/dist/heatmap-layer/triangle-layer.wgsl.d.ts +3 -0
  36. package/dist/heatmap-layer/triangle-layer.wgsl.d.ts.map +1 -0
  37. package/dist/heatmap-layer/triangle-layer.wgsl.js +65 -0
  38. package/dist/heatmap-layer/triangle-layer.wgsl.js.map +1 -0
  39. package/dist/heatmap-layer/weights.wgsl.d.ts +3 -0
  40. package/dist/heatmap-layer/weights.wgsl.d.ts.map +1 -0
  41. package/dist/heatmap-layer/weights.wgsl.js +64 -0
  42. package/dist/heatmap-layer/weights.wgsl.js.map +1 -0
  43. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.d.ts.map +1 -1
  44. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.js +1 -2
  45. package/dist/hexagon-layer/hexagon-cell-layer-vertex.glsl.js.map +1 -1
  46. package/dist/hexagon-layer/hexagon-cell-layer.d.ts.map +1 -1
  47. package/dist/hexagon-layer/hexagon-cell-layer.js +2 -1
  48. package/dist/hexagon-layer/hexagon-cell-layer.js.map +1 -1
  49. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.d.ts +3 -0
  50. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.d.ts.map +1 -0
  51. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.js +120 -0
  52. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.js.map +1 -0
  53. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts +1 -0
  54. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts.map +1 -1
  55. package/dist/hexagon-layer/hexagon-layer-uniforms.js +13 -0
  56. package/dist/hexagon-layer/hexagon-layer-uniforms.js.map +1 -1
  57. package/dist/index.cjs +502 -32
  58. package/dist/index.cjs.map +4 -4
  59. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts +1 -6
  60. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
  61. package/dist/screen-grid-layer/screen-grid-cell-layer.js +3 -2
  62. package/dist/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  63. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.d.ts +3 -0
  64. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.d.ts.map +1 -0
  65. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.js +76 -0
  66. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.js.map +1 -0
  67. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts +1 -0
  68. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts.map +1 -1
  69. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js +12 -0
  70. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js.map +1 -1
  71. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts +1 -1
  72. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts.map +1 -1
  73. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -2
  74. package/dist/screen-grid-layer/screen-grid-layer-vertex.glsl.js.map +1 -1
  75. package/dist.min.js +428 -40
  76. package/package.json +11 -7
  77. package/src/common/aggregation-layer.ts +1 -3
  78. package/src/common/aggregator/gpu-aggregator/webgl-aggregation-transform.ts +1 -3
  79. package/src/common/aggregator/gpu-aggregator/webgl-bin-sorter.ts +0 -1
  80. package/src/grid-layer/grid-cell-layer-vertex.glsl.ts +1 -2
  81. package/src/grid-layer/grid-cell-layer.ts +2 -1
  82. package/src/heatmap-layer/heatmap-layer-uniforms.ts +20 -0
  83. package/src/heatmap-layer/heatmap-layer.ts +67 -13
  84. package/src/heatmap-layer/max.wgsl.ts +48 -0
  85. package/src/heatmap-layer/triangle-layer-uniforms.ts +17 -0
  86. package/src/heatmap-layer/triangle-layer.ts +3 -2
  87. package/src/heatmap-layer/triangle-layer.wgsl.ts +65 -0
  88. package/src/heatmap-layer/weights.wgsl.ts +64 -0
  89. package/src/hexagon-layer/hexagon-cell-layer-vertex.glsl.ts +1 -2
  90. package/src/hexagon-layer/hexagon-cell-layer.ts +2 -1
  91. package/src/hexagon-layer/hexagon-cell-layer.wgsl.ts +120 -0
  92. package/src/hexagon-layer/hexagon-layer-uniforms.ts +14 -0
  93. package/src/screen-grid-layer/screen-grid-cell-layer.ts +4 -4
  94. package/src/screen-grid-layer/screen-grid-cell-layer.wgsl.ts +76 -0
  95. package/src/screen-grid-layer/screen-grid-layer-uniforms.ts +13 -0
  96. package/src/screen-grid-layer/screen-grid-layer-vertex.glsl.ts +1 -2
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "deck.gl layers that aggregate the input data into alternative representations",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "9.3.7",
6
+ "version": "9.4.0-alpha.2",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -17,6 +17,10 @@
17
17
  "type": "git",
18
18
  "url": "https://github.com/visgl/deck.gl.git"
19
19
  },
20
+ "bugs": {
21
+ "url": "https://github.com/visgl/deck.gl/issues"
22
+ },
23
+ "homepage": "https://deck.gl",
20
24
  "types": "dist/index.d.ts",
21
25
  "main": "dist/index.cjs",
22
26
  "module": "dist/index.js",
@@ -38,16 +42,16 @@
38
42
  "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
39
43
  },
40
44
  "dependencies": {
41
- "@luma.gl/shadertools": "^9.3.3",
45
+ "@luma.gl/shadertools": "^9.4.0-alpha.1",
42
46
  "@math.gl/core": "^4.1.0",
43
47
  "@math.gl/web-mercator": "^4.1.0",
44
48
  "d3-hexbin": "^0.2.1"
45
49
  },
46
50
  "peerDependencies": {
47
- "@deck.gl/core": "~9.3.0",
48
- "@deck.gl/layers": "~9.3.0",
49
- "@luma.gl/core": "~9.3.3",
50
- "@luma.gl/engine": "~9.3.3"
51
+ "@deck.gl/core": "~9.3.0-beta.2",
52
+ "@deck.gl/layers": "~9.3.0-beta.2",
53
+ "@luma.gl/core": "~9.4.0-alpha.1",
54
+ "@luma.gl/engine": "~9.4.0-alpha.1"
51
55
  },
52
- "gitHead": "ac8cd3dd7a70b1f1471729425d63fcff38dc0a13"
56
+ "gitHead": "546e2e8284b00949ab26e744ffd05b9aa017c802"
53
57
  }
@@ -39,9 +39,7 @@ export default abstract class AggregationLayer<
39
39
  /** Called when some attributes change, a chance to mark Aggregator as dirty */
40
40
  abstract onAttributeChange(id: string): void;
41
41
 
42
- initializeState(): void {
43
- this.getAttributeManager()!.remove(['instancePickingColors']);
44
- }
42
+ initializeState(): void {}
45
43
 
46
44
  // Extend Layer.updateState to update the Aggregator instance
47
45
  // returns true if aggregator is changed
@@ -112,6 +112,7 @@ export class WebGLAggregationTransform {
112
112
  transform.run({
113
113
  id: 'gpu-aggregation-domain',
114
114
  framebuffer: target,
115
+ discard: false,
115
116
  parameters: {
116
117
  viewport: [0, 0, 2, 1]
117
118
  },
@@ -243,11 +244,8 @@ void main() {
243
244
  blendAlphaOperation: 'max'
244
245
  },
245
246
  defines: {
246
- // @ts-expect-error TODO fix luma type
247
247
  NUM_DIMS: props.dimensions,
248
- // @ts-expect-error TODO fix luma type
249
248
  NUM_CHANNELS: props.channelCount,
250
- // @ts-expect-error TODO fix luma type
251
249
  SAMPLER_WIDTH: TEXTURE_WIDTH
252
250
  },
253
251
  varyings: ['binIds', 'values'],
@@ -248,7 +248,6 @@ void main() {
248
248
  const model = new Model(device, {
249
249
  bufferLayout: props.bufferLayout,
250
250
  modules: [...(props.modules || []), binSorterUniforms],
251
- // @ts-expect-error TODO fix luma type
252
251
  defines: {...props.defines, NON_INSTANCED_MODEL: 1, NUM_CHANNELS: props.channelCount},
253
252
  isInstanced: false,
254
253
  vs,
@@ -12,7 +12,6 @@ in vec3 normals;
12
12
  in vec2 instancePositions;
13
13
  in float instanceElevationValues;
14
14
  in float instanceColorValues;
15
- in vec3 instancePickingColors;
16
15
 
17
16
  uniform sampler2D colorRange;
18
17
 
@@ -30,7 +29,7 @@ vec4 interp(float value, vec2 domain, sampler2D range) {
30
29
  }
31
30
 
32
31
  void main(void) {
33
- geometry.pickingColor = instancePickingColors;
32
+ geometry.pickingColor = picking_getPickingColorFromInstanceID();
34
33
 
35
34
  if (isnan(instanceColorValues) ||
36
35
  instanceColorValues < grid.colorDomain.z ||
@@ -97,7 +97,8 @@ export class GridCellLayer<ExtraPropsT extends {} = {}> extends ColumnLayer<
97
97
 
98
98
  protected _updateGeometry() {
99
99
  const geometry = new CubeGeometry();
100
- this.state.fillModel!.setGeometry(geometry);
100
+ this._setFillGeometry(geometry);
101
+ this._setWireframeGeometry(geometry);
101
102
  }
102
103
 
103
104
  draw({uniforms}) {
@@ -5,6 +5,17 @@
5
5
  import {Texture} from '@luma.gl/core';
6
6
  import type {ShaderModule} from '@luma.gl/shadertools';
7
7
 
8
+ const uniformBlockWGSL = /* wgsl */ `\
9
+ struct weightUniforms {
10
+ commonBounds: vec4<f32>,
11
+ radiusPixels: f32,
12
+ textureWidth: f32,
13
+ weightsScale: f32,
14
+ };
15
+
16
+ @group(0) @binding(auto) var<uniform> weight: weightUniforms;
17
+ `;
18
+
8
19
  const uniformBlock = `\
9
20
  layout(std140) uniform weightUniforms {
10
21
  vec4 commonBounds;
@@ -23,6 +34,7 @@ export type WeightProps = {
23
34
 
24
35
  export const weightUniforms = {
25
36
  name: 'weight',
37
+ source: uniformBlockWGSL,
26
38
  vs: uniformBlock,
27
39
  uniformTypes: {
28
40
  commonBounds: 'vec4<f32>',
@@ -39,6 +51,14 @@ export type MaxWeightProps = {
39
51
 
40
52
  export const maxWeightUniforms = {
41
53
  name: 'maxWeight',
54
+ source: /* wgsl */ `\
55
+ struct maxWeightUniforms {
56
+ textureSize: f32,
57
+ };
58
+
59
+ @group(0) @binding(auto) var<uniform> maxWeight: maxWeightUniforms;
60
+ @group(0) @binding(auto) var inTexture: texture_2d<f32>;
61
+ `,
42
62
  vs: `\
43
63
  layout(std140) uniform maxWeightUniforms {
44
64
  float textureSize;
@@ -10,7 +10,14 @@ import {
10
10
  scaleToAspectRatio,
11
11
  getTextureCoordinates
12
12
  } from './heatmap-layer-utils';
13
- import {Buffer, DeviceFeature, Texture, TextureProps, TextureFormat} from '@luma.gl/core';
13
+ import {
14
+ Buffer,
15
+ DeviceFeature,
16
+ Texture,
17
+ TextureProps,
18
+ TextureFormat,
19
+ TextureFormatColor
20
+ } from '@luma.gl/core';
14
21
  import {TextureTransform, TextureTransformProps} from '@luma.gl/engine';
15
22
  import {
16
23
  Accessor,
@@ -34,6 +41,8 @@ import weightsVs from './weights-vs.glsl';
34
41
  import weightsFs from './weights-fs.glsl';
35
42
  import maxVs from './max-vs.glsl';
36
43
  import maxFs from './max-fs.glsl';
44
+ import maxSource from './max.wgsl';
45
+ import weightsSource from './weights.wgsl';
37
46
  import {
38
47
  MaxWeightProps,
39
48
  maxWeightUniforms,
@@ -42,6 +51,7 @@ import {
42
51
  } from './heatmap-layer-uniforms';
43
52
 
44
53
  const RESOLUTION = 2; // (number of common space pixels) / (number texels)
54
+ const MAX_WEIGHT_REDUCTION_SIZE = 16;
45
55
  const TEXTURE_PROPS: TextureProps = {
46
56
  format: 'rgba8unorm',
47
57
  dimension: '2d',
@@ -376,11 +386,26 @@ export default class HeatmapLayer<
376
386
 
377
387
  _setupAttributes() {
378
388
  const attributeManager = this.getAttributeManager()!;
379
- attributeManager.add({
380
- positions: {size: 3, type: 'float64', accessor: 'getPosition'},
381
- weights: {size: 1, accessor: 'getWeight'}
382
- });
383
- this.setState({positionAttributeName: 'positions'});
389
+
390
+ if (this.context.device.type === 'webgpu') {
391
+ attributeManager.addInstanced({
392
+ instancePositions: {
393
+ size: 3,
394
+ type: 'float64',
395
+ accessor: 'getPosition',
396
+ // Normalize binary XY positions into the packed XYZ high/low layout WebGPU requires.
397
+ transform: (position: Position) => [position[0], position[1], position[2] ?? 0]
398
+ },
399
+ instanceWeights: {size: 1, accessor: 'getWeight'}
400
+ });
401
+ this.setState({positionAttributeName: 'instancePositions'});
402
+ } else {
403
+ attributeManager.add({
404
+ positions: {size: 3, type: 'float64', accessor: 'getPosition'},
405
+ weights: {size: 1, accessor: 'getWeight'}
406
+ });
407
+ this.setState({positionAttributeName: 'positions'});
408
+ }
384
409
  }
385
410
 
386
411
  _setupTextureParams() {
@@ -388,8 +413,15 @@ export default class HeatmapLayer<
388
413
  const {weightsTextureSize} = this.props;
389
414
 
390
415
  const textureSize = Math.min(weightsTextureSize, device.limits.maxTextureDimension2D);
391
- const floatTargetSupport = FLOAT_TARGET_FEATURES.every(feature => device.features.has(feature));
392
- const format: TextureFormat = floatTargetSupport ? 'rgba32float' : 'rgba8unorm';
416
+ const isWebGPU = device.type === 'webgpu';
417
+ const floatTargetSupport = isWebGPU
418
+ ? device.getTextureFormatCapabilities('rgba16float').blend
419
+ : FLOAT_TARGET_FEATURES.every(feature => device.features.has(feature));
420
+ const format: TextureFormat = floatTargetSupport
421
+ ? isWebGPU
422
+ ? 'rgba16float'
423
+ : 'rgba32float'
424
+ : 'rgba8unorm';
393
425
  const weightsScale = floatTargetSupport ? 1 : 1 / 255;
394
426
  this.setState({textureSize, format, weightsScale});
395
427
  if (!floatTargetSupport) {
@@ -402,14 +434,23 @@ export default class HeatmapLayer<
402
434
  _createWeightsTransform(shaders: {vs: string; fs?: string; modules: any[]}) {
403
435
  let {weightsTransform} = this.state;
404
436
  const {weightsTexture} = this.state;
437
+ const isWebGPU = this.context.device.type === 'webgpu';
405
438
  const attributeManager = this.getAttributeManager()!;
406
439
 
407
440
  weightsTransform?.destroy();
408
441
  weightsTransform = new TextureTransform(this.context.device, {
409
442
  id: `${this.id}-weights-transform`,
410
443
  ...shaders,
411
- bufferLayout: attributeManager.getBufferLayouts(),
412
- vertexCount: 1,
444
+ source: weightsSource,
445
+ bufferLayout: attributeManager.getBufferLayouts({isInstanced: isWebGPU}),
446
+ vertexCount: isWebGPU ? 6 : 1,
447
+ ...(isWebGPU
448
+ ? {
449
+ colorAttachmentFormats: [weightsTexture!.format as TextureFormatColor],
450
+ isInstanced: true,
451
+ instanceCount: this.getNumInstances()
452
+ }
453
+ : {}),
413
454
  targetTexture: weightsTexture!,
414
455
  parameters: {
415
456
  depthWriteEnabled: false,
@@ -420,7 +461,7 @@ export default class HeatmapLayer<
420
461
  blendAlphaSrcFactor: 'one',
421
462
  blendAlphaDstFactor: 'one'
422
463
  },
423
- topology: 'point-list',
464
+ topology: isWebGPU ? 'triangle-list' : 'point-list',
424
465
  modules: [...shaders.modules, weightUniforms]
425
466
  } as TextureTransformProps);
426
467
 
@@ -439,6 +480,7 @@ export default class HeatmapLayer<
439
480
  this._createWeightsTransform(weightsTransformShaders);
440
481
 
441
482
  const maxWeightsTransformShaders = this.getShaders({
483
+ source: maxSource,
442
484
  vs: maxVs,
443
485
  fs: maxFs,
444
486
  modules: [maxWeightUniforms]
@@ -447,7 +489,13 @@ export default class HeatmapLayer<
447
489
  id: `${this.id}-max-weights-transform`,
448
490
  targetTexture: maxWeightsTexture!,
449
491
  ...maxWeightsTransformShaders,
450
- vertexCount: textureSize * textureSize,
492
+ ...(device.type === 'webgpu'
493
+ ? {colorAttachmentFormats: [maxWeightsTexture!.format as TextureFormatColor]}
494
+ : {}),
495
+ vertexCount:
496
+ device.type === 'webgpu'
497
+ ? Math.ceil(textureSize / MAX_WEIGHT_REDUCTION_SIZE) ** 2
498
+ : textureSize * textureSize,
451
499
  topology: 'point-list',
452
500
  parameters: {
453
501
  depthWriteEnabled: false,
@@ -605,7 +653,13 @@ export default class HeatmapLayer<
605
653
  const attributes = attributeManager.getAttributes();
606
654
  const moduleSettings = this.getModuleSettings();
607
655
  this._setModelAttributes(weightsTransform.model, attributes);
608
- weightsTransform.model.setVertexCount(this.getNumInstances());
656
+ if (this.context.device.type === 'webgpu') {
657
+ const instanceCount = this.getNumInstances();
658
+ weightsTransform.model.setVertexCount(instanceCount > 0 ? 6 : 0);
659
+ weightsTransform.model.setInstanceCount(instanceCount);
660
+ } else {
661
+ weightsTransform.model.setVertexCount(this.getNumInstances());
662
+ }
609
663
 
610
664
  const weightProps: WeightProps = {
611
665
  radiusPixels,
@@ -0,0 +1,48 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export default /* wgsl */ `\
6
+ struct MaxWeightVaryings {
7
+ @builtin(position) position: vec4<f32>,
8
+ @location(0) weights: vec4<f32>,
9
+ };
10
+
11
+ const MAX_WEIGHT_REDUCTION_SIZE: u32 = 16u;
12
+
13
+ @vertex
14
+ fn vertexMain(@builtin(vertex_index) vertexIndex: u32) -> MaxWeightVaryings {
15
+ var output: MaxWeightVaryings;
16
+ let textureSize = u32(maxWeight.textureSize);
17
+ let reducedTextureSize =
18
+ (textureSize + MAX_WEIGHT_REDUCTION_SIZE - 1u) / MAX_WEIGHT_REDUCTION_SIZE;
19
+ let blockCoordinates = vec2<u32>(
20
+ vertexIndex % reducedTextureSize,
21
+ vertexIndex / reducedTextureSize
22
+ );
23
+ var maximumWeights = vec4<f32>(0.0);
24
+
25
+ for (var y = 0u; y < MAX_WEIGHT_REDUCTION_SIZE; y++) {
26
+ for (var x = 0u; x < MAX_WEIGHT_REDUCTION_SIZE; x++) {
27
+ let textureCoordinates = blockCoordinates * MAX_WEIGHT_REDUCTION_SIZE + vec2<u32>(x, y);
28
+
29
+ if (textureCoordinates.x < textureSize && textureCoordinates.y < textureSize) {
30
+ let weights = textureLoad(inTexture, vec2<i32>(textureCoordinates), 0);
31
+ maximumWeights.r = max(maximumWeights.r, weights.r);
32
+ maximumWeights.g = max(maximumWeights.g, weights.r / max(1.0, weights.a));
33
+ maximumWeights.b = max(maximumWeights.b, weights.b);
34
+ maximumWeights.a = max(maximumWeights.a, weights.a);
35
+ }
36
+ }
37
+ }
38
+
39
+ output.position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
40
+ output.weights = maximumWeights;
41
+ return output;
42
+ }
43
+
44
+ @fragment
45
+ fn fragmentMain(varyings: MaxWeightVaryings) -> @location(0) vec4<f32> {
46
+ return varyings.weights;
47
+ }
48
+ `;
@@ -5,6 +5,22 @@
5
5
  import {Texture} from '@luma.gl/core';
6
6
  import type {ShaderModule} from '@luma.gl/shadertools';
7
7
 
8
+ const uniformBlockWGSL = /* wgsl */ `\
9
+ struct triangleUniforms {
10
+ aggregationMode: f32,
11
+ colorDomain: vec2<f32>,
12
+ intensity: f32,
13
+ threshold: f32,
14
+ };
15
+
16
+ @group(0) @binding(auto) var<uniform> triangle: triangleUniforms;
17
+ @group(0) @binding(auto) var colorTexture: texture_2d<f32>;
18
+ @group(0) @binding(auto) var colorTextureSampler: sampler;
19
+ @group(0) @binding(auto) var maxTexture: texture_2d<f32>;
20
+ @group(0) @binding(auto) var weightsTexture: texture_2d<f32>;
21
+ @group(0) @binding(auto) var weightsTextureSampler: sampler;
22
+ `;
23
+
8
24
  const uniformBlock = `\
9
25
  layout(std140) uniform triangleUniforms {
10
26
  float aggregationMode;
@@ -26,6 +42,7 @@ export type TriangleProps = {
26
42
 
27
43
  export const triangleUniforms = {
28
44
  name: 'triangle',
45
+ source: uniformBlockWGSL,
29
46
  vs: uniformBlock,
30
47
  fs: uniformBlock,
31
48
  uniformTypes: {
@@ -4,7 +4,8 @@
4
4
 
5
5
  import type {Buffer, Device, Texture} from '@luma.gl/core';
6
6
  import {Model} from '@luma.gl/engine';
7
- import {Layer, LayerContext, project32} from '@deck.gl/core';
7
+ import {Layer, LayerContext, color, project32} from '@deck.gl/core';
8
+ import source from './triangle-layer.wgsl';
8
9
  import vs from './triangle-layer-vertex.glsl';
9
10
  import fs from './triangle-layer-fragment.glsl';
10
11
  import {TriangleProps, triangleUniforms} from './triangle-layer-uniforms';
@@ -31,7 +32,7 @@ export default class TriangleLayer extends Layer<_TriangleLayerProps> {
31
32
  };
32
33
 
33
34
  getShaders() {
34
- return super.getShaders({vs, fs, modules: [project32, triangleUniforms]});
35
+ return super.getShaders({source, vs, fs, modules: [project32, color, triangleUniforms]});
35
36
  }
36
37
 
37
38
  initializeState({device}: LayerContext): void {
@@ -0,0 +1,65 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export default /* wgsl */ `\
6
+ struct TriangleAttributes {
7
+ @location(0) positions: vec3<f32>,
8
+ @location(1) texCoords: vec2<f32>,
9
+ };
10
+
11
+ struct TriangleVaryings {
12
+ @builtin(position) position: vec4<f32>,
13
+ @location(0) textureCoordinates: vec2<f32>,
14
+ @location(1) intensityMinimum: f32,
15
+ @location(2) intensityMaximum: f32,
16
+ };
17
+
18
+ @vertex
19
+ fn vertexMain(attributes: TriangleAttributes) -> TriangleVaryings {
20
+ var output: TriangleVaryings;
21
+ output.position = project_position_to_clipspace(
22
+ attributes.positions,
23
+ vec3<f32>(0.0),
24
+ vec3<f32>(0.0)
25
+ );
26
+ // WebGPU render-target textures use a top-left origin.
27
+ output.textureCoordinates = vec2<f32>(attributes.texCoords.x, 1.0 - attributes.texCoords.y);
28
+
29
+ let maxWeights = textureLoad(maxTexture, vec2<i32>(0), 0);
30
+ var maximumValue = select(maxWeights.r, maxWeights.g, triangle.aggregationMode > 0.5);
31
+ var minimumValue = maximumValue * triangle.threshold;
32
+
33
+ if (triangle.colorDomain.y > 0.0) {
34
+ maximumValue = triangle.colorDomain.y;
35
+ minimumValue = triangle.colorDomain.x;
36
+ }
37
+
38
+ output.intensityMaximum = triangle.intensity / maximumValue;
39
+ output.intensityMinimum = triangle.intensity / minimumValue;
40
+ return output;
41
+ }
42
+
43
+ @fragment
44
+ fn fragmentMain(varyings: TriangleVaryings) -> @location(0) vec4<f32> {
45
+ let weights = textureSample(weightsTexture, weightsTextureSampler, varyings.textureCoordinates);
46
+ var weight = weights.r;
47
+
48
+ if (triangle.aggregationMode > 0.5) {
49
+ weight /= max(1.0, weights.a);
50
+ }
51
+
52
+ let colorCoordinates = vec2<f32>(
53
+ clamp(weight * varyings.intensityMaximum, 0.0, 1.0),
54
+ 0.5
55
+ );
56
+ var color = textureSample(colorTexture, colorTextureSampler, colorCoordinates);
57
+
58
+ if (weight <= 0.0) {
59
+ discard;
60
+ }
61
+
62
+ color.a *= min(weight * varyings.intensityMinimum, 1.0) * layer.opacity;
63
+ return deckgl_premultiplied_alpha(color);
64
+ }
65
+ `;
@@ -0,0 +1,64 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export default /* wgsl */ `\
6
+ struct WeightAttributes {
7
+ @builtin(vertex_index) vertexIndex: u32,
8
+ @location(0) instancePositions: vec3<f32>,
9
+ @location(1) instancePositions64Low: vec3<f32>,
10
+ @location(2) instanceWeights: f32,
11
+ };
12
+
13
+ struct WeightVaryings {
14
+ @builtin(position) position: vec4<f32>,
15
+ @location(0) pointCoordinates: vec2<f32>,
16
+ @location(1) weights: vec4<f32>,
17
+ };
18
+
19
+ const WEIGHT_QUAD_POSITIONS = array<vec2<f32>, 6>(
20
+ vec2<f32>(-1.0, -1.0),
21
+ vec2<f32>(1.0, -1.0),
22
+ vec2<f32>(-1.0, 1.0),
23
+ vec2<f32>(-1.0, 1.0),
24
+ vec2<f32>(1.0, -1.0),
25
+ vec2<f32>(1.0, 1.0)
26
+ );
27
+
28
+ @vertex
29
+ fn vertexMain(attributes: WeightAttributes) -> WeightVaryings {
30
+ var output: WeightVaryings;
31
+ let commonPosition = project_position_vec3_f64(
32
+ attributes.instancePositions,
33
+ attributes.instancePositions64Low
34
+ );
35
+ let clipPosition =
36
+ (commonPosition.xy - weight.commonBounds.xy) /
37
+ (weight.commonBounds.zw - weight.commonBounds.xy) * 2.0 - vec2<f32>(1.0);
38
+ let radiusTexels =
39
+ project_pixel_size_float(weight.radiusPixels) * weight.textureWidth /
40
+ (weight.commonBounds.z - weight.commonBounds.x);
41
+ let offset = WEIGHT_QUAD_POSITIONS[attributes.vertexIndex];
42
+
43
+ output.position = vec4<f32>(
44
+ clipPosition + offset * radiusTexels * 2.0 / weight.textureWidth,
45
+ 0.0,
46
+ 1.0
47
+ );
48
+ output.pointCoordinates = (offset + vec2<f32>(1.0)) * 0.5;
49
+ output.weights = vec4<f32>(attributes.instanceWeights * weight.weightsScale, 0.0, 0.0, 1.0);
50
+ return output;
51
+ }
52
+
53
+ @fragment
54
+ fn fragmentMain(varyings: WeightVaryings) -> @location(0) vec4<f32> {
55
+ let distanceFromCenter = length(varyings.pointCoordinates - vec2<f32>(0.5));
56
+ if (distanceFromCenter > 0.5) {
57
+ discard;
58
+ }
59
+
60
+ let gaussian = exp(-pow(2.0 * distanceFromCenter, 2.0) / 0.05555) /
61
+ (1.77245385 * 0.166666);
62
+ return varyings.weights * gaussian;
63
+ }
64
+ `;
@@ -14,7 +14,6 @@ in vec3 normals;
14
14
  in vec2 instancePositions;
15
15
  in float instanceElevationValues;
16
16
  in float instanceColorValues;
17
- in vec3 instancePickingColors;
18
17
 
19
18
  uniform sampler2D colorRange;
20
19
 
@@ -34,7 +33,7 @@ vec4 interp(float value, vec2 domain, sampler2D range) {
34
33
  }
35
34
 
36
35
  void main(void) {
37
- geometry.pickingColor = instancePickingColors;
36
+ geometry.pickingColor = picking_getPickingColorFromInstanceID();
38
37
 
39
38
  if (isnan(instanceColorValues) ||
40
39
  instanceColorValues < hexagon.colorDomain.z ||
@@ -6,6 +6,7 @@ import {Texture} from '@luma.gl/core';
6
6
  import {UpdateParameters, Color} from '@deck.gl/core';
7
7
  import {ColumnLayer} from '@deck.gl/layers';
8
8
  import {createColorRangeTexture, updateColorRangeTexture} from '../common/utils/color-utils';
9
+ import source from './hexagon-cell-layer.wgsl';
9
10
  import vs from './hexagon-cell-layer-vertex.glsl';
10
11
  import {HexagonProps, hexagonUniforms} from './hexagon-layer-uniforms';
11
12
  import type {ScaleType} from '../common/types';
@@ -35,7 +36,7 @@ export default class HexagonCellLayer<ExtraPropsT extends {} = {}> extends Colum
35
36
  getShaders() {
36
37
  const shaders = super.getShaders();
37
38
  shaders.modules.push(hexagonUniforms);
38
- return {...shaders, vs};
39
+ return {...shaders, source, vs};
39
40
  }
40
41
 
41
42
  initializeState() {