Custom Attributes

Attributes are a way to pass data from one part of the pipeline to another. Currently shadeup supports passing data from the vertex shader to the fragment shader.

Passing interpolated attributes (perspective)

  • out.attr<T>(index, value) - Passes the value to the fragment shader.
  • in.attr<T>(index) - Reads the value from the vertex shader.

Passing flat attributes

  • out.attr<T>(index, value, interpolate: "flat" | "perspective" | "linear") - Passes the value to the fragment shader.
  • in.attr<T>(index, interpolate: "flat" | "perspective" | "linear") - Reads the value from the vertex shader.

Interpolation modes

Taken from the webgpu spec:

“flat”

Flat interpolation is unaffected, and is based on provoking vertex, which is the first vertex in the primitive. The output value is the same for the whole primitive, and matches the vertex output of the provoking vertex: c.v = provoking vertex.v

“linear”

The interpolation ratio gets adjusted against the perspective coordinates of the clip positions, so that the result of interpolation is linear in screen space.

“perspective”

The value is linearly interpolated in clip space, producing perspective-correct values:

c.v = t × a.v + (1 − t) × b.v