Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

grid

How a compute shader finds the points near a point: the walk over a spatial hash grid proc.device.gridInto builds on the device. zero_grid_cell, zero_grid_bucket (from grid_cell) and zero_grid_range.

The includer binds the grid's runs as three read bindings: gcfg (f32, the settings grid_cell reads), grange (u32, each bucket's start and end in the order) and gorder (u32, point indices ordered by bucket). A shader run by the shader.compute or sim.shader op of the shader pack gets a grid over its domain's P by declaring those three bindings and giving the op a neighborRadius, the cell side (g:node("counted", "shader.compute", { domain = "pts" }, { shader = ref, neighborRadius = 0.7 })). The g.sim.shader node walks the hash_walk module's hash instead.

A point j = gorder[s] in the span of cell cc belongs to cc exactly when zero_grid_cell of its own position is cc; two cells can share a bucket, so the walk checks it:

#include "@builtin::systems.procgen.grid"

let c = zero_grid_cell(p);
for (var dz = -1; dz <= 1; dz = dz + 1) {
    for (var dy = -1; dy <= 1; dy = dy + 1) {
        for (var dx = -1; dx <= 1; dx = dx + 1) {
            let cc = c + vec3<i32>(dx, dy, dz);
            let span = zero_grid_range(cc);
            for (var s = span.x; s < span.y; s = s + 1u) {
                let j = gorder[s];
                // skip j == i, and any j whose own cell is not cc
            }
        }
    }
}

@builtin::tests.fixtures.shader_neighbor_count is a complete shader that counts each point's neighbours this way.