# Tempered — WebGL Background for React

> A scroll-scrubbed tempering shader: white-hot amber turbulence at the top of the page cools through ember red into blued violet-steel with oxidation bands — and scrolling back genuinely reheats. GSAP ScrollTrigger drives an original OGL fragment shader, with idle micro-motion, custom phase keyframes, and a static mid-temper frame under reduced motion. A ghost heat welt drifts across the metal when untouched.

- Page: https://crucibleui.com/components/backgrounds/tempered
- Category: [backgrounds](https://crucibleui.com/backgrounds)
- Tier: pro (one-time purchase, see https://crucibleui.com/pricing)
- Engine: ogl
- npm dependencies: ogl, gsap

## Install

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

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

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

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 (`TemperedProps`)

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `phases?` | `TemperPhase[]` | `the tempering sequence: white-hot amber at the top, ember red mid-page, blued violet-steel with oxidation bands at the bottom. Scrolling back up genuinely reheats` | Phase keyframes mapping scroll position to color. Interpolated linearly between entries (sorted by `at`). |
| `scrub?` | `number` | `0.8` | Scrub smoothing in seconds — how long the shader takes to catch up to the scrollbar (GSAP ScrollTrigger scrub). 0 locks it hard to the wheel. |
| `idleMotion?` | `number` | `0.5` | Idle micro-motion (0–1): how much the surface keeps shimmering once scrolling stops. 0 freezes dead between scrolls. |
| `scroller?` | `string \| Element \| React.RefObject<HTMLElement \| null>` | `the window, mapped over the full document scroll range` | The scroll container whose progress drives the temper. Accepts a selector, element, or ref to an `overflow-y-auto` container. |
| `speed?` | `number` | `1` | Idle shimmer speed multiplier (scroll scrubbing is unaffected). |
| `intensity?` | `number` | `1` | Overall brightness multiplier. |
| `heat?` | `number` | `1` | Forge heat (0–1): scales glow, bloom, and turbulence energy together. |
| `idle?` | `boolean` | `true` | Idle autoplay: after ~1.5s with no real pointer, a seeded ghost pointer drags a faint heat welt slowly across the metal so it never looks dead in thumbnails and heroes; the real pointer takes over instantly. Never runs under reduced motion. |
| `paused?` | `boolean` | — | Freeze the render loop, holding the current frame. |
| `className?` | `string` | — | Extra classes for the wrapper. Positioned `absolute inset-0 -z-10`. |

## Usage example

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

```tsx
"use client";

import * as React from "react";

import { DemoSceneContext } from "@/components/registry/demo-scene";
import { Tempered } from "@/components/crucible/tempered";
import { useReducedMotion } from "@/hooks/use-reduced-motion";

// Skips the shared DemoScene wrapper: the inner scroller IS the demo — the
// background's color journey is driven by scroll position.
const STAGES = [
  {
    mark: "1 260 °C",
    title: "White heat",
    copy: "The top of the scroll — the field is at its brightest.",
  },
  {
    mark: "870 °C",
    title: "Ember",
    copy: "The glow settles as you scroll; color tracks your position.",
  },
  {
    mark: "300 °C",
    title: "Oxide bloom",
    copy: "Straw, bronze, violet — the palette shifts through the midpoint.",
  },
  {
    mark: "Quenched",
    title: "Blued steel",
    copy: "Cooled to violet-blue. Scroll back up to reheat.",
  },
];

export default function TemperedDemo() {
  const scrollRef = React.useRef<HTMLDivElement>(null);
  const reducedMotion = useReducedMotion();
  // Site embeds (thumbnails, mosaics) ask for the bare effect — mirror what
  // DemoScene's raw mode does for demos that use it. A tall invisible spacer
  // keeps the scroll-scrubbed color journey drivable even without the copy.
  const embed = React.useContext(DemoSceneContext);

  if (embed?.raw && !reducedMotion) {
    return (
      <div className="relative isolate h-full min-h-0 w-full overflow-hidden rounded-xl bg-neutral-950">
        <Tempered scroller={scrollRef} />
        <div ref={scrollRef} className="absolute inset-0 z-10 overflow-y-auto">
          <div aria-hidden className="h-[400%]" />
        </div>
      </div>
    );
  }

  // Reduced motion disables the scroll scrub and holds the shader at its
  // mid-temper frame (progress 0.5 — ember cooling toward oxide bloom). The
  // scroll-journey copy would contradict the frozen field, so show a single
  // static overlay that describes exactly what's on screen.
  if (reducedMotion) {
    return (
      <div className="relative isolate flex h-full min-h-[360px] w-full items-center justify-center overflow-hidden rounded-xl bg-neutral-950">
        <Tempered scroller={scrollRef} />
        <div className="relative z-10 flex flex-col items-center px-6 text-center">
          <p className="font-mono text-xs uppercase tracking-[0.3em] text-white/50">
            Mid-temper
          </p>
          <p className="mt-2 text-3xl font-semibold tracking-tight text-white drop-shadow-[0_2px_12px_rgba(0,0,0,0.7)]">
            Ember &amp; oxide
          </p>
          <p className="mt-2 max-w-sm text-sm text-white/70">
            Reduced motion holds the field at its mid-temper frame — ember red
            shading into oxide bloom.
          </p>
        </div>
      </div>
    );
  }

  return (
    <div className="relative isolate flex h-full min-h-[360px] w-full items-center justify-center overflow-hidden rounded-xl bg-neutral-950">
      <Tempered scroller={scrollRef} />
      <div ref={scrollRef} className="absolute inset-0 z-10 overflow-y-auto">
        {STAGES.map((stage, i) => {
          // Stage 1 sits on the white-hot field: dark ink, not white-on-white.
          const onHotField = i === 0;
          return (
            <section
              key={stage.title}
              className="flex h-full flex-col items-center justify-center px-6 text-center"
            >
              <p
                className={
                  onHotField
                    ? "font-mono text-xs uppercase tracking-[0.3em] text-neutral-900/70"
                    : "font-mono text-xs uppercase tracking-[0.3em] text-white/50"
                }
              >
                {stage.mark}
              </p>
              <p
                className={
                  onHotField
                    ? "mt-2 text-3xl font-semibold tracking-tight text-neutral-950 drop-shadow-[0_1px_8px_rgba(255,244,214,0.55)]"
                    : "mt-2 text-3xl font-semibold tracking-tight text-white drop-shadow-[0_2px_12px_rgba(0,0,0,0.7)]"
                }
              >
                {stage.title}
              </p>
              <p
                className={
                  onHotField
                    ? "mt-2 max-w-sm text-sm text-neutral-900/80"
                    : "mt-2 max-w-sm text-sm text-white/70"
                }
              >
                {stage.copy}
              </p>
              {i === 0 && (
                <p className="mt-8 animate-bounce text-xs text-neutral-900/60">
                  Scroll down &darr;
                </p>
              )}
            </section>
          );
        })}
      </div>
    </div>
  );
}
```

## 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.
