Skip to main content

WebGLAggregator

The WebGLAggregator implements the Aggregator interface by performing aggregation on the GPU.

Example

This example implements an aggregator that makes a histogram that calculates "weight" distribution by "position".

import {WebGLAggregator} from '@deck.gl/aggregation-layers';

const aggregator = new WebGLAggregator(device, {
dimensions: 1,
channelCount: 1,
bufferLayout: [
{name: 'position', format: 'float32'},
{name: 'weight', format: 'float32'}
],
vs: `
uniform float binSize;
in float position;
in float weight;
void getBin(out int binId) {
binId = int(floor(position / binSize));
}
void getValue(out float value) {
value = weight;
}`
});

const position = new Attribute(device, {id: 'position', size: 1});
position.setData({value: new Float32Array(...)});
const weight = new Attribute(device, {id: 'weight', size: 1});
position.setData({value: new Float32Array(...)});

aggregator.setProps({
pointCount: data.length,
binIdRange: [0, 100],
operations: ['SUM'],
binOptions: {
binSize: 1
},
attributes: {position, weight}
});

aggregator.update();

Constructor

new WebGLAggregator(props);

Arguments:

  • dimensions (number) - size of bin IDs, either 1 or 2
  • channelCount (number) - number of channels, up to 3
  • vs (string) - vertex shader for the aggregator. Should define the following functions:
    • void getBin(out int binId), if dimensions=1 or void getBin(out ivec2 binId), if dimensions=2
    • void getValue(out float value), if channelCount=1 or void getValue(out vec2 value), if channelCount=2 or void getValue(out vec3 value), if channelCount=3
  • bufferLayout (object[]) - see ModelProps
  • modules (object[]) - luma.gl shader modules, see ModelProps
  • defines (object) - luma.gl shader defines, see ModelProps

Props

Requires all Aggregator props, and the following:

binIdRange (number[][])

Limits of binId defined as [start, end] for each dimension. Ids less than start or larger than or equal to end are ignored.

moduleSettings (object)

Mapped uniforms for shadertool modules, see ModelProps

Source

modules/aggregation-layers/src/common/aggregator/gpu-aggregator/webgl-aggregator.ts