Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

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, written asset.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 own bind. A column a mapped binding writes lands under the mapped name.
  • uniforms (Record, optional): values of the shader's params: block, by name, for this node alone. A value left out keeps its declared default. count is the number of elements, time the graph's time in seconds and frame its frame, each filled in when the shader declares it and uniforms leaves 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 },
})