<sk-custom-wgsl-points-source>

← prev index next →

Generates clone placements from your own WGSL — a procedural point distribution written as a GPU function, for shapes no built-in source covers (a helix, a gyroid, a formula-defined swarm).

Remarks

This is the fully custom member of the points-source family (see ShaderFunctionPointsSource): a points-source defines the set of positions at which a sk-cloner places copies of its content, so it lives as a child of a <sk-cloner> and the cloner's other child is the template cloned at each point. Where the built-in procedural sources encode a fixed shape (sk-grid-points-source, sk-sphere-points-source, …), this one runs an author-supplied getPointAtIndex(index) on the GPU, so every point's local transform is whatever the WGSL computes — and, like the other procedural sources, the placements never touch the CPU, so even large counts stay cheap.

Key attributes. point-count is how many points to generate — the WGSL is evaluated once per index from 0 to point-count − 1. wgsl is the inline shader body; it must define fn getPointAtIndex(index: u32) -> PointData and set point.localMatrix (column 3 is the position, the +Y axis is the surface normal). src loads that WGSL from an external .wgsl file instead, taking precedence over inline wgsl (mirroring <script src>); on-load / on-error fire when a src fetch resolves or fails. Author parameters are supplied as <sk-wgsl-uniform> children and read in WGSL via the generated skUniform_<name>() accessors.

Related. For placements a GPU compute pass produces into a buffer rather than a per-index function, see sk-compute-buffer-points-source (which pairs with a sk-compute-node). For built-in procedural shapes see sk-grid-points-source, sk-sphere-points-source, and sk-platonic-sphere-points-source; for object/data-driven placements see sk-mesh-vertex-points-source, sk-mesh-surface-points-source, sk-buffer-points-source, and sk-cloner-points-source. Its host is always a sk-cloner.

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.
point-countrequired <number> 1 Total number of points to generate.
wgsl <string> "" WGSL shader code for procedural point generation.
src <string> URL of an external .wgsl file providing the shader code, mirroring

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