Skip to main content

filterPlugin

import {filterPlugin} from '@luma.gl/shaders/plugins';

filterPlugin tests one value per row against an inclusive range.

  • FILTER_POSITION is the vertex shader target the host registers and calls.
  • filterValues is the scalar column. Supply one float32 value per row through the filterValues vertex input.

The plugin attaches a filter shader module with enabled, min, and max props. Defaults are {enabled: true, min: 0, max: 1}.

Compatible base shaders register and call the position target:

shaderAssembler.addShaderInjectionTarget({name: 'FILTER_POSITION', stage: 'vertex', glsl: {parameters: 'inout vec4 position'}}); // GLSL
shaderAssembler.addShaderInjectionTarget({name: 'FILTER_POSITION', stage: 'vertex', wgsl: {parameters: 'position: ptr<function, vec4<f32>>'}}); // WGSL
FILTER_POSITION(gl_Position);

The caller supplies the data and updates only shader inputs when the range changes:

const model = new Model(device, {
plugins: [filterPlugin],
shaderAssembler,
bufferLayout: [{name: 'filterValues', format: 'float32', stepMode: 'instance'}],
attributes: {filterValues: filterValueBuffer}
});

model.shaderInputs.setProps({filter: {enabled: true, min: 0.2, max: 0.8}});

Rejected vertices are moved outside clip space. This first version does not support category filters, filtered-row counts, fp64 values, or storage-buffer inputs.