<sk-compute-buffer-color-source>

← prev index next →

Paints a material's base color from a GPU-computed table of positioned color stops, looked up by a field's spatial weight — the escape hatch for a spatial color no built-in source computes, driven straight from a compute buffer with zero copy, with each color placed at its OWN parametric position.

Remarks

This is the GPU-computed member of the ColorSource family: like every color-source it gives a material a base color that varies across the surface, but the colors come from a table a compute node produces on the GPU rather than from a color-map, an image, or a procedural formula. It is the GPU-computed analogue of sk-ramp-color-map: each record is a (offset, color) stop, and an intensity-field DRIVER supplies a [0,1] weight from where a point is that is resolved against those stops the same way a ramp resolves its authored <sk-color-stop> offsets — find the bracketing pair by position and interpolate. Because each stop carries its own offset, the table can be non-uniformly spaced: dense stops in one region, sparse in another, or a sharp feature at an arbitrary position — an addressing a fixed i/(count-1) grid cannot express. A spherical, linear, or composite field addresses the table radially, directionally, or carved, exactly as it would drive a color-map.

Key attributes. compute-node (required) references the producing sk-compute-node by id; the node must declare output-kind="color-stops". compute-property-key selects which of its outputs to read (default output.0); alpha-mode declares how the sampled records' alpha is classified. intensity-field is the DRIVER whose [0,1] weight is looked up against the stops; field (from the ColorSource base) is the APPLICABILITY mask — where the source shows versus the flat base-color. Both fields follow the same absence convention: an omitted intensity-field drives the weight to 1 (the LAST stop's color), and an omitted field applies the source at full weight everywhere.

Stop contract. Each record is 32 bytes — an offset vec4<f32> (the [0,1] position in .x) and a color vec4<f32> (straight-alpha RGBA in linear space), bound zero-copy from the producer's buffer. Offsets must be a finite, monotonically non-decreasing sequence in [0,1]; the producing kernel emits them sorted (the lookup does NOT sort on the GPU, so out-of-order data yields undefined placement). A weight below the first offset or above the last clamps to that endpoint stop's color; coincident offsets produce a hard step. The lookup honors up to 100 stops. When the producer re-dispatches continuously, the source keeps the scene re-rendering.

Related. Its producer is a sk-compute-node (see AbstractComputeNode); its driver is any Field (sk-linear-gradient-field, sk-spherical-gradient-field, sk-composite-field, …). A material selects the source with base-color-source="#id" (see sk-plain-material). Its CPU-authored counterpart with arbitrary offsets is sk-ramp-color-map + sk-color-stop; its field-driven color-map sibling is sk-color-map-source; for hand-written per-fragment color instead of a precomputed table, use sk-custom-wgsl-color-source.

Serve these docs to run the live example. WebGPU needs a secure context — open this page via grunt serve rather than double-clicking the file. The Markup tab works from disk.

Attributes

AttributeTypeDefaultDescription
id <id> The element's unique identifier — the standard HTML global id attribute.
compute-nodeanimatable <id-ref> The producing compute node (instance, wired at connect via its id). reference by id
compute-property-key <property-name> "output.0" The output key to read (output.N).
alpha-mode <custom-wgsl-alpha-mode> ("auto" | "opaque" | "translucent" | "cutout") "auto" Author-declared alpha classification of the sampled records.
intensity-fieldanimatable <id-ref> Gets the driver field feeding the [0,1] scalar the concrete source turns reference by id
fieldanimatable <id-ref> Gets the optional applicability field that masks where this source reference by id
xanimatable <number> 0 Gets the X position component.
yanimatable <number> 0 Gets the Y position component.
zanimatable <number> 0 Gets the Z position component.
hanimatable <angle> 0 Gets the heading (Y-axis) rotation in radians.
panimatable <angle> 0 Gets the pitch (X-axis) rotation in radians.
banimatable <angle> 0 Gets the bank (Z-axis) rotation in radians.
visualize <boolean> false Whether the visualization is visible (wireframe splines + center marker).
interactive-controls <boolean> false Whether interactive controls are shown (draggable markers for adjusting parameters).