Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

sim.shader (procNode)

A solver whose step is an author's .computeShader: the elements of a geometry are its state, and at every fixed step (1/60 s, over the graph's timeline) the shader runs once per element over their columns, writing its read_write bindings in place. What a step wrote is what the next step reads. Cellular automata, an author's own particle behaviour, anything a shader advances frame to frame. Like sim.particles, the result at a frame depends on the frames cooked before it in the same node cache.

Inputs

  • geometry (Geometry): the elements the solver starts from: every column of class (and P for points) is the state the shader's bindings read and write.
  • shader (AssetRef<computeShader>): the compute shader one step runs, written asset.resolve("<identity>", "computeShader").
  • uniforms (Record, default empty): values for the shader's params: block, by name.
  • bind (Record, default empty): which state column each of the shader's bindings reads or writes, by binding name; a binding left out reads the column of its own name.
  • class (String, default "point"): the class whose elements the shader runs over: "point", "vertex" or "primitive".
  • neighborRadius (Float, optional, min 0): the cell side of the spatial hash built over the points at each step, which is how far a shader can look for neighbours in one walk. Left out, no hash is built.

At each step the shader's params: block also receives count (the element count), dt, time, frame and graphTime, filled in when the shader declares them. A shader that looks at the elements near each one declares the bindings pts, order and range and the params buckets and inv_cell of the hash_walk module, and neighborRadius fills them.

Outputs

  • geometry (Geometry): a copy of the input whose class columns hold the state after the last step.

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 * time at every step:

local cloud = g.points.grid({ countX = 4, countZ = 4 })
local risen = g.sim.shader({
    geometry = cloud,
    shader = asset.resolve("@builtin::tests.fixtures.shader_compute_rise", "computeShader"),
    uniforms = { rate = 1 },
})