docs/api-reference/aggregation-layers/webgl-aggregator.md
The WebGLAggregator implements the Aggregator interface by performing aggregation on the GPU.
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();
new WebGLAggregator(props);
Arguments:
dimensions (number) - size of bin IDs, either 1 or 2channelCount (number) - number of channels, up to 3vs (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=2void getValue(out float value), if channelCount=1 or
void getValue(out vec2 value), if channelCount=2 or
void getValue(out vec3 value), if channelCount=3bufferLayout (object[]) - see ModelPropsmodules (object[]) - luma.gl shader modules, see ModelPropsdefines (object) - luma.gl shader defines, see ModelPropsRequires all Aggregator props, and the following:
binIdRange (number[][]) {#binidrange}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) {#modulesettings}Mapped uniforms for shadertool modules, see ModelProps
modules/aggregation-layers/src/common/aggregator/gpu-aggregator/webgl-aggregator.ts