@shader-core/solid
v1.0.0
Published
Solid components for Shader Core: <Shader> with layers as children.
Maintainers
Readme
@shader-core/solid
Solid components for Shader Core: an animated WebGL2 background composed from layers that stack.
npm install @shader-core/solidSolid 1.6+ is a peer dependency. The package is written without JSX, so it needs no compiler of its own; your JSX is compiled by your build as usual.
Use
import { createSignal } from 'solid-js';
import { Shader, Gradient, Curtains, Grain } from '@shader-core/solid';
export function Background() {
const [intensity, setIntensity] = createSignal(0.05);
return (
<Shader style={{ position: 'fixed', inset: '0', 'z-index': '-1' }}>
<Gradient colorA="#04060f" colorB="#0a1230" />
<Curtains scale={3.8} colorSheet="#3ddc97" colorFilament="#4361ee" />
<Grain intensity={intensity()} />
</Shader>
);
}Children are layers, bottom to top, composed into one program and drawn in one pass. Each is typed from its schema, so a mistyped prop is a compile error rather than a uniform nobody sets.
It is as fine-grained as the rest of Solid. A signal behind a prop —
intensity() above — moves one uniform and re-runs nothing else. Adding,
removing or reordering a layer recompiles once, then it is cached.
Children
<Show>, <For> and {cond && <Grain />} all work. A component that wraps
layers does not: <Shader> reads what its children return rather than
rendering them, so inline the layers, or have the component return its own
<Shader>.
Props
| Prop | What it does |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------- |
| paused | Stops the animation and keeps everything else. Unset it to resume. |
| quality | auto (default), high or low. Caps the pixel budget on modest hardware. |
| reducedMotion | static (default) or animate, under prefers-reduced-motion. |
| staticTime | Renders one frame at this time, in seconds, and never animates. |
| onError | Called for anything that goes wrong. Without it, errors go to the console. |
| class, style | On the canvas, alongside its own display: block and full size. Style keys are CSS names — 'z-index', not zIndex. |
Changing quality, reducedMotion or staticTime swaps in a new canvas: they
belong to the GL context, and a canvas cannot get a context back once it has
been released.
A background is not worth taking a page down for: a device with no WebGL2, or a layer that will not compile, is reported and leaves the canvas blank rather than throwing.
Server rendering
A canvas and a GL context are the browser's, so on the server <Shader>
renders nothing. In SolidStart, render it on the client only — with
clientOnly(() => import('./Background')) — so hydration has nothing to
disagree about.
Per-layer entry points
Every layer also has its own module — @shader-core/solid/gradient — if you
would rather not rely on tree-shaking.
Licence
Free to use, including commercially, on one condition: the credit comment stays in shader source you copy. Full terms in LICENSE.md.
