<sk-custom-wgsl-spline-source>

← prev index next →

Generates a spline's polyline from inline WGSL you write — the way to describe a curve as a per-vertex formula (a parametric knot, a rose curve, a live time-varying shape) and have the GPU evaluate it every frame.

Remarks

This is the WGSL-authored member of the spline-source family: a spline-source supplies the curve geometry for a AbstractSpline, so it lives as the single geometry child of a sk-spline. You write only fn getSplineVertex(index: u32) -> SplineVertex; the source runs its own generation dispatch (one GPU thread per vertex, engine-owned fn main) into a polyline the renderer consumes through the shared zero-copy + readback path. A kernel that reads params.time (scene time in milliseconds) re-generates every frame; a static kernel dispatches once per change. CPU-side queries (pointAt, bounds, cloner matrices) come from the readback path and are null until the first readback — as with sk-compute-buffer-spline-source.

Key attributes. vertex-count is how many polyline vertices to generate — getSplineVertex is called once per index 0 … vertex-count-1. wgsl is the inline kernel body; src loads the WGSL from an external file instead (and, like <script src>, wins over inline wgsl), with on-load / on-error handlers for the fetch. is-closed declares the generated polyline a closed loop. Author parameters are `sk-wgsl-uniform children (and the vec/array variants), read inside the kernel via the generated skUniform_<name>() accessors; changing a uniform value re-uploads and re-dispatches without a pipeline rebuild. Like every spline-source it also carries the family's distribution / distribution-count` controls: a spline-source is itself a points-source, so a sk-cloner given one places clones along the curve, and these controls choose how it is sampled into those positions.

Related. It is one input modality of the spline-source family alongside sk-svg-spline-source, sk-points-spline-source, sk-trail-spline-source, sk-morph-spline-source, and its GPU sibling sk-compute-buffer-spline-source (which reads a separate sk-compute-node producer rather than owning the kernel). It parameterizes the kernel with sk-wgsl-uniform children; its host is a sk-spline, whose curve then draws with a stroke paint or carries an sk-align-to-spline-constraint.

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
vertex-countrequired <number> 1 Number of polyline vertices to generate. Must be a positive integer.
wgsl <string> "" Author WGSL defining fn getSplineVertex(index: u32) -> SplineVertex.
src <string> URL of an external .wgsl file (mirrors <script src>).
is-closedanimatable <boolean> false Whether the generated polyline forms a closed loop.
distributionanimatable <spline-distribution> ("control-points" | "tessellated" | "arc-length-spaced") How clone points are placed along the spline — at the control points, at
distribution-count <number> The number of evenly spaced points to place when the distribution is

Event handler attributes

Standard DOM event-handler content attributes — the value is JavaScript run when the event fires. They behave exactly as on any HTML element.

onload, onerror