Skip to main content

@luma.gl/graph/gpu-pointcloud

@luma.gl/graph/gpu-pointcloud provides experimental WebGPU voxel sampling, radius filtering and additive octree construction as operations in a caller-owned GPUCommandGraph.

OperationResultCost
gpuPointCloudVoxelDownsampleRepresentative source IDs, voxel populations, representative positionsO(points + voxels) time; O(voxels) output storage
gpuPointCloudRadiusFilterExact other-point neighbor counts and an outlier selection maskO(points²) time; O(points) output storage
GPUPointCloudOctreeSource-ID ranges and sparse additive octree nodesStable sort + O(points × depth) work; O(points) scratch

Select original point IDs in GPUGraph​

Use named values to pass the radius filter's selection mask to stable compaction. Supply one packed point cloud and the corresponding original IDs at execution. The graph allocates the row-aligned counts and mask, and only publishes the outputs selected at compilation.

import {GPUGraph, gpuCompact} from '@luma.gl/graph/gpu-graph';
import {gpuPointCloudRadiusFilter} from '@luma.gl/graph/gpu-pointcloud';

const graph = new GPUGraph();
graph.addInput('positions', {type: 'vector', format: 'float32x3'});
graph.addInput('sourceIds', {type: 'vector', format: 'uint32'});
graph.add(gpuPointCloudRadiusFilter, {
positions: 'positions',
radius: 0.22,
minimumNeighbors: 3,
counts: 'neighborCounts',
mask: 'validPoints'
}).add(gpuCompact, {
input: 'sourceIds',
flags: 'validPoints',
output: 'selectedIds',
count: 'selectedCount'
});

The compacted IDs retain input order. Use the GPU scalar selectedCount in a subsequent operation that consumes the compacted prefix.

Sample a filtered cloud without changing its row indices​

Pass the radius filter's named mask directly to voxel downsampling. Use the original positions for both operations so each representative still indexes the source rows.

import {gpuPointCloudVoxelDownsample} from '@luma.gl/graph/gpu-pointcloud';

// The radius filter above produces 'validPoints' from 'positions'.
graph.add(gpuPointCloudVoxelDownsample, {
positions: 'positions',
mask: 'validPoints',
origin: [-1, -1, -1],
gridSize: [20, 20, 20],
voxelSize: 0.1,
representatives: 'representativeRows',
counts: 'voxelPopulations',
output: 'sampledPositions'
});

Each occupied voxel returns the lowest selected source row index in that voxel. Its population counts only selected points. Pick the results you need at compilation or pass them to later GPU operations. The graph sizes the three outputs from the grid and allocates them for execution.

A command graph can use an interactive Crossfilter selection for both voxel sampling and vector search. Each flag addresses an original source row. Voxel sampling walks the ordered point and mask chunks without combining them, even when their boundaries differ.

import {gpuCrossfilterSelection, type GPUCrossfilterSelectionResult} from '@luma.gl/graph/gpu-crossfilter';
import {gpuPointCloudVoxelDownsample} from '@luma.gl/graph/gpu-pointcloud';
import {gpuSimilaritySearch} from '@luma.gl/graph/gpu-vector-search';

graph.add(gpuCrossfilterSelection, {id: 'category', kind: 'range', input: categories});
const selection = graph.getContribution<GPUCrossfilterSelectionResult>('category');

graph.add(gpuPointCloudVoxelDownsample, {
id: 'samples',
positions,
mask: selection.mask,
origin: [-1, -1, -1],
gridSize: [16, 16, 16],
voxelSize: 0.125
});
graph.add(gpuSimilaritySearch, {
id: 'neighbors',
dataset: embeddings,
queries,
k: 8,
filterMask: selection.mask
});

Keep positions, category values, and embeddings in the same source row order. Match the selection chunks to the embedding chunks for search. One range update changes both results on the next encoding of the same compiled graph. Voxel representatives are zero-based row indices across the entire cloud. Search returns the dataset's stable IDs.

Compose downsampling and filtering​

import {gpuPointCloudVoxelDownsample, gpuPointCloudRadiusFilter} from '@luma.gl/graph/gpu-pointcloud';

// Import the caller-owned views into the same graph before adding the operations.
graph.add(gpuPointCloudVoxelDownsample, {
id: 'sampled-voxels',
positions, origin: [-1, -1, -1], voxelSize: 0.125, gridSize: [16, 16, 16],
representatives, counts: voxelCounts, output: sampledPositions
});
graph.add(gpuPointCloudRadiusFilter, {
id: 'radius-filter',
positions: sampledPositions, validity: voxelCounts,
radius: 0.22, minimumNeighbors: 3, mask
});
const {counts: neighborCounts} = graph.getContribution('radius-filter', gpuPointCloudRadiusFilter);
const compiledGraph = graph.compile();

Omit a destination to let the graph allocate it. Use operation.commands(props) with explicit destinations inside a nested command producer.

The resulting mask and sampled position buffer can drive instanced rendering directly. If compact output is needed, explicitly compose GPUCompaction over representative IDs using the mask and a caller-owned output count. Sampling preserves source provenance: every accepted representative ID indexes the original input position view.

Voxel contract​

  • Position chunks and output positions are packed float32x3. Counts, IDs, and optional selection flags are packed uint32. Selection length must match the total number of source rows.
  • gridSize contains three positive integer dimensions; all three voxel output views have exactly their product in rows. The grid is dense and bounded, not an unbounded spatial hash.
  • Coordinates use floor((position - origin) / voxelSize) and x-fastest ordering: (z * height + y) * width + x.
  • Bounds are half-open: the minimum is included and the maximum excluded. Non-finite positions and points outside the grid do not contribute.
  • Each occupied voxel selects the minimum input row ID deterministically. This is representative sampling, not centroid averaging. Counts report the included source population per cell (including the representative itself). Bind this count as a per-instance attribute to size reduced points: radius proportional to sqrt(count) makes their displayed area proportional to the represented population.
  • Empty voxels have count zero, representative 0xffffffff, and position [0, 0, 0]. Always use counts as validity; a real point may be at the origin.
  • Outputs are reset on every encoding, so reusing a compiled graph does not accumulate stale counts.

Radius contract​

The radius is inclusive. The query point itself is excluded; distinct rows at identical coordinates are neighbors. Optional validity flags exclude rows from both queries and candidate searches. Non-finite query positions produce zero counts and a zero mask. The mask is one when a valid query has at least minimumNeighbors other valid points within the radius; the default threshold is one. Squared radius must be positive and finite in float32. Choose a coordinate scale that avoids squared-distance overflow and expect float32 rounding near boundaries.

This initial radius implementation scans every candidate for every valid query. Use it for bounded clouds or after voxel sampling. It is not a spatially accelerated million-point neighborhood query, and there is no silent candidate truncation.

Ownership and batching​

Imported views support nonzero byte offsets. The command graph borrows those buffers and owns destinations allocated for a contribution. Output buffers must be separate from input buffers. Writable storage bindings must remain disjoint after rounding start offsets down to 256-byte alignment. Compile after adding consumers, then encode and submit from the application.

Voxel sampling accepts ordered chunks that each fit the device storage-binding limit. Call the operation once with those chunks to share one voxel grid and select representatives across the whole cloud. Radius filtering and octree construction accept one packed view per attribute.

Run the cleanup lab to compare original samples with voxel representatives filtered by local density. Normal estimation and registration are future extensions.

Additive octree​

GPUPointCloudOctree partitions source row IDs into sparse octree tile ranges while preserving original positions. Draw a node's range together with its ancestors' ranges for additive refinement. Across the complete tree every accepted source row occurs exactly once, including distinct rows with identical coordinates. No position or other attribute buffers are reordered.

import {gpuPointCloudOctree, type GPUPointCloudOctreeResult} from '@luma.gl/graph/gpu-pointcloud';

graph.add(gpuPointCloudOctree, {
id: 'octree',
positions,
origin: [-1, -1, -1], size: 2,
maximumDepth: 6, nodePointLimit: 64, samplingLevels: 2
});
const {pointIndices, nodes, status} =
graph.getContribution<GPUPointCloudOctreeResult>('octree');

Supply pointIndices, nodes, or status views to keep the corresponding output in caller-owned storage. Omitted outputs are graph transients. The Additive Octree example reads the node ranges and status directly in a downstream pass that writes point and tile draw counts for each depth. Rendering can begin in the same submission. The controls read back only the compact draw counts, frontier counts, and status.

status must use a separate buffer from nodes and pointIndices: intermediate passes read status while writing those outputs. nodes and pointIndices may share disjoint output storage. This requirement is checked when constructing the operation.

The root is a cube from origin to origin + size, including both faces. Coordinates and extent must be representable in float32; nonfinite or out-of-bounds points are rejected and counted. maximumDepth is 0–10 (default 6), using at most 30 Morton bits. The root is depth zero.

Each nonterminal node samples the first Morton-ordered point in each occupied finer cell, up to nodePointLimit (default 64). samplingLevels (1–10, default 2) controls the finer grid: up to 2^samplingLevels cells per axis, limited by the remaining depth. Stable sorting resolves equal Morton keys by source row ID. If the cap is smaller than the occupied sample-cell count, earlier Morton cells win; this is deterministic spatial sampling, not unbiased sampling. Nodes with at most the point limit terminate early. At maximum depth leaves retain all remaining points, even when that exceeds the limit. Unselected IDs pass to children without duplicating parent data.

Outputs​

pointIndices contains source row IDs in breadth-first node order. Each node owns one nonempty, contiguous [pointOffset, pointOffset + pointCount) range. This is an indirection buffer that can be bound as storage for attribute gathering, or as an index buffer when the rendering path supports it and the caller allocated the corresponding usage. It does not contain gathered attributes.

nodes contains eight packed uint32 words per node (GPU_POINT_CLOUD_OCTREE_NODE_STRIDE = 8):

WordFieldMeaning
0Morton prefixOctant path, three bits per level; XYZ use bits 4/2/1
1LevelRoot is zero
2ParentNode index; root uses 0xffffffff
3First childFirst contiguous child node; leaf uses 0xffffffff
4Child maskOne bit per occupied child octant; children are in octant order
5Point offsetElement offset into pointIndices, not bytes
6Point countPoints owned by this tile only
7Subtree countThis tile plus all descendants; excludes ancestor-owned points

Recover bounds by starting with the root cube and halving it for each octant in the prefix, from most significant to least significant. A child octant's node index is firstChild plus the number of set mask bits below that octant. For a coarse conservative refinement error, use the node cube's diagonal; a smaller sample-cell error is not guaranteed when the sample budget is capped.

status is exactly four words: required node count, retained point count, rejected point count, overflow flag. Only consume the tree when overflow is zero. Node capacity may be smaller than needed; writes are guarded and status reports the required capacity for an explicit retry. Allocating N node records always suffices because every created node owns at least one source row. pointIndices must have capacity at least N. An empty or wholly rejected input creates no nodes. Every encoding resets metadata, counts and unused IDs (to 0xffffffff).

Cost and integration​

Construction uses a stable Morton sort followed by fixed GPU scan/partition passes per depth: O(N × depth) work after sorting, O(N) scratch, with no intermediate CPU readback or dense 8^depth allocation. Each level scans the original capacity, even after the active set shrinks. Storage binding limits and graph scratch allocations bound the resident cloud size; this is not an out-of-core or incremental streaming tiler. Changing bounds or construction options requires a new graph; changed source values of the same size can reuse the compiled graph.

The additive ownership contract matches additive point-cloud tiling, but sample selection and metadata are not a byte-compatible loaders.gl tile-source adapter. Serialization, network loading, view-dependent traversal and integration with PointCloudTileSource remain separate work.

Run the additive octree example to inspect tile bounds and progressively reveal detail without rebuilding the tree.