Builtin Library
README.md
shader.compute (procNode)
An author's .computeShader run over a geometry's elements, one invocation per element. Each buffer binding the
shader declares is a column of the geometry under the binding's own name (or the name bind gives it): a read
binding reads the column, a read_write binding writes it, making it when the geometry has none. Each value the
shader's params: block declares is a knob of the node, set in uniforms, where it can be animated or wired like any
input. A copy of the geometry comes out carrying every column the shader wrote. For a shader that steps a state frame
after frame, sim.shader is the solver form.
The shader's WGSL reads element global_invocation_id.x of every bound column. A column's lanes are packed f32s: a
Vec3 column binds as array<f32> read three to an element, and a Vec2 or Vec4 one as array<vec2<f32>> /
array<vec4<f32>>.
Inputs
geometry(Geometry): the elements the shader runs over and the columns its bindings read.shader(AssetRef<computeShader>): the shader that runs, writtenasset.resolve("<identity>", "computeShader").class(String, default"point"): which elements the shader runs over and whose columns its bindings are:"point","vertex","primitive","edge"or"detail".bind(Record, optional): which column each buffer binding is, by binding name. A binding left out is the column of its own name, so a shader whose bindings are named after the columns it works on needs none of this; the same shader placed twice reads different columns by giving each node its ownbind. A column a mapped binding writes lands under the mapped name.uniforms(Record, optional): values of the shader'sparams:block, by name, for this node alone. A value left out keeps its declared default.countis the number of elements,timethe graph's time in seconds andframeits frame, each filled in when the shader declares it anduniformsleaves it out.
Outputs
geometry(Geometry): a copy of the input carrying every column the shader wrote.
Example
The built-in test fixture shader_compute_rise declares one read_write binding P (element: f32, three to a
point) and the params rate, time and count, and raises each point by rate times the graph's time:
local cloud = g.points.grid({ countX = 4, countZ = 4 })
local raised = g.shader.compute({
geometry = cloud,
shader = asset.resolve("@builtin::tests.fixtures.shader_compute_rise", "computeShader"),
uniforms = { rate = 2 },
})