Skip to content

Interactions — pointer, pulse, scroll

Interaction state is fed to every shader as built-in uniforms — one vec4 slot each, same layout in WGSL (uni.*) and GLSL (u_*).

Slot Contents
mouse xy smoothed pointer uv, zw raw target
pointer xy pointer velocity (~uv/s), z hover 0→1, w pressed 0/1
pulse xy last press position, z strength decaying 1→0, w press age (s)
scroll x element progress through viewport 0→1, y scroll velocity (viewport-heights/s, damped)

Pointer tracking is opt-in per instance — pass pointer: true to attach window-level listeners:

new ShaderInstance(aurora, { pointer: true });
<Shader shader={aurora} pointer />
<!-- element: enable it at define time -->
<script type="module">
defineShaderElement({ aurora }, { styles, pointer: true });
</script>

mouse/pointer/pulse update only when tracking is on; otherwise they hold their initial values. Damping uses 1 - exp(-10·dt) — the same smoothing speed at any refresh rate.

scroll.x is the element’s own progress through the viewport (0 at the bottom edge, 1 at the top), and scroll.y is damped page scroll velocity. Scroll tracking starts when a mounted canvas registers a scroll consumer — engines that read uni.scroll opt in automatically.

If a shader never reads time, poin