<sk-custom-wgsl-point-constraint>

← prev index next →

Displaces every point of a host with a GPU kernel you write inline in WGSL — the escape hatch for any per-point deformation the built-in point-constraints don't cover.

Remarks

This is the fully-programmable member of the PointConstraint family: like every point-constraint it runs a GPU kernel over all of a host's points at once (a mesh, a spline, or a sk-cloner). What is unique here is that you supply the kernel body: the engine owns the scaffold (world-space sampling, the field-weight range, per-target buffer I/O) and calls your computeDisplacement() for each point, plus an optional computeGradient() when the result should also recompute normals.

Key attributes. wgsl holds the kernel source — at minimum a computeDisplacement(worldXZ) function returning a world-space offset. Its tunable parameters come from sk-wgsl-uniform elements attached to it, read inside the kernel through generated skUniform_<name>() accessors, so each is independently animatable. affects-normals turns on the computeGradient() path so shading and cloner orientation follow the deformed surface. max-displacement reports the kernel's worst-case travel so bounds stay correct. It is the per-point cousin of sk-compute-node, which produces whole output buffers that compute-buffer sources consume by reference.

Related. For a ready-made wave there is sk-ocean-displacement-point-constraint; for field-weighted translate/scale/rotate there is sk-simple-point-constraint. Its single-node CPU analogue is sk-field-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
id <id> The element's unique identifier — the standard HTML global id attribute.
wgsl <string> "" Inline WGSL implementing the displacement-kernel contract.
src <string> URL of an external .wgsl file providing the displacement kernel,
affects-normals <boolean> false The AUTHORED affects-normals value, independent of show. alias for affectsNormalsConfig
max-displacement <number> 0 Analytic upper-bound displacement magnitude (world units), used to
time-dependent <boolean> false Whether the kernel must be re-dispatched every frame.
show <boolean> true Whether the constraint is active.
field-weight-rangeanimatable <field-weight-range> ([<number>, <number>]) The [lo, hi] range the field weight maps onto.

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