# Ballast — WebGL Background for React

> A physics ballpit background in sea-glass celadon: frosted spheres pour in from a corner and drift under low gravity like objects underwater, jostling softly while the pointer stirs gentle currents. Instanced rigid bodies, DPR-clamped, offscreen-paused, reduced-motion-safe; idles on its own when untouched — a ghost paddle stirs the currents.

- Page: https://crucibleui.com/components/backgrounds/ballast
- Category: [backgrounds](https://crucibleui.com/backgrounds)
- Tier: pro (one-time purchase, see https://crucibleui.com/pricing)
- Engine: r3f
- npm dependencies: three, @react-three/fiber, @react-three/rapier, @react-three/postprocessing

## Install

```bash
npx shadcn@latest add @crucible/ballast
```

Pro install requires adding the token-bearing `@crucible` registry to components.json (issued at https://crucibleui.com/account after purchase).

Import from `@/components/crucible/ballast`.

Backgrounds render `absolute inset-0 -z-10`. Their parent must be a stacking context — wrap in `relative isolate` and put your content in a `relative z-10` child, or the background disappears behind an opaque ancestor.

## Props (`Props`)

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `count?` | `number` | `30` | How many sea-glass spheres drift in the tank (plus one oversized "keystone" sphere that anchors the composition). Rendered as a single instanced draw call. |
| `colors?` | `string[]` | `a tight celadon-to-glaucous sea-glass ramp so the pit reads as one material in many sizes, not a rainbow ballpit` | Palette of hex colors, assigned per sphere. |
| `gravity?` | `number` | `1` | Gravity multiplier. 1 = the default dreamy underwater sink; push toward 3 for a snappier pit, toward 0.3 for near-weightless drift. |
| `drift?` | `number` | `1` | Strength of the ambient current that keeps the spheres slowly circulating (0 lets them settle completely). |
| `intensity?` | `number` | `1` | Master brightness for lights and highlight bloom. |
| `interactive?` | `boolean` | `true` | Enable pointer stirring — the cursor is an invisible paddle with gentle force. Automatically disabled on touch / coarse-pointer devices. |
| `idle?` | `boolean` | `true` | Idle autoplay: after ~1.5s with no real pointer (and always on touch devices), a seeded ghost paddle drifts through the tank stirring slow currents and now and then presses into the pile, so thumbnails and heroes never sit still; the real pointer takes over instantly. Requires `interactive`. Never runs under reduced motion. |
| `paused?` | `boolean` | `false` | Freeze the simulation with the spheres in a settled, aesthetic pile. Also forced on when the user prefers reduced motion. |
| `className?` | `string` | — | Extra classes for the wrapper. Positioned `absolute inset-0 -z-10`. |
| `ref?` | `React.Ref<BallastHandle>` | — | React 19 ref prop → {@link BallastHandle}. |

## Usage example

`DemoScene` is a site-only preview harness, not part of the component — replace it with your own layout.

```tsx
import { Ballast } from "@/components/crucible/ballast";
import { DemoScene } from "@/components/registry/demo-scene";

export default function BallastDemo() {
  return (
    <DemoScene
      background={<Ballast />}
      headline="Calm has a current"
      subhead="Sea-glass spheres drift under low gravity — move your cursor to stir them."
    />
  );
}
```

## Accessibility & performance

Honors `prefers-reduced-motion` with a designed static frame or fade (never a blank box) and passes `className` through. Pauses offscreen and on hidden tabs, clamps device pixel ratio, and tears down its GL/canvas context on unmount.
