{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "plasma",
  "type": "registry:ui",
  "title": "Plasma",
  "description": "A classic 90s demoscene plasma background: layered sine/cosine fields over space and time sum into a scalar that indexes a smooth looping palette, so flowing color bands both deform and palette-cycle — organic, hypnotic, seamless. The pointer subtly warps the field. Tasteful cool duotone-to-tritone by default, full psychedelia via the colors knob. Original OGL fragment shader, tone-mapped, dithered, DPR-clamped, offscreen-paused, reduced-motion-safe; a ghost pointer keeps it moving when untouched.",
  "dependencies": [
    "ogl"
  ],
  "registryDependencies": [
    "https://crucibleui.com/r/ogl-canvas.json",
    "https://crucibleui.com/r/use-visibility-pause.json",
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/backgrounds/plasma/plasma.tsx",
      "type": "registry:ui",
      "target": "components/crucible/plasma.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { OglCanvas } from \"@/lib/ogl-canvas\";\n\nexport interface PlasmaProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  /**\n   * Three palette stops the plasma cycles through as a seamless loop\n   * (`A → B → C → A`). Keep one stop dark for elegant flowing bands, or push\n   * all three to saturated hues for full 90s psychedelia. Defaults to a cool\n   * indigo → sky → periwinkle gradient. Warm alt: `[\"#2a0f3d\", \"#f97316\", \"#fbbf24\"]`.\n   */\n  colors?: [string, string, string];\n  /** Flow speed multiplier. 1 = default, 2 = twice as fast, 0 = frozen field. Default 1. */\n  speed?: number;\n  /**\n   * Band richness, 0–2. Scales spatial frequency (how many color bands fill the\n   * frame) and vividness. 1 = calm and tasteful; higher packs denser, more\n   * saturated psychedelic bands. Default 1.\n   */\n  intensity?: number;\n  /**\n   * Idle autoplay: after ~1.5s with no real pointer, a seeded ghost pointer\n   * warps the field on a slow drift so it never looks dead in thumbnails and\n   * heroes; the real pointer takes over instantly. Never runs under reduced\n   * motion. @default true\n   */\n  idle?: boolean;\n  /** Freeze the animation at its current frame. */\n  paused?: boolean;\n}\n\nconst DEFAULT_COLORS: [string, string, string] = [\n  \"#15234f\", // deep indigo — the dark valleys of the field\n  \"#38bdf8\", // sky — the flowing mid band\n  \"#a5b4fc\", // periwinkle — the bright crests\n];\n\n/** Hex → [r,g,b] in 0–1. Accepts #rgb / #rrggbb. */\nfunction hexToRgb(hex: string): [number, number, number] {\n  let h = hex.replace(\"#\", \"\").trim();\n  if (h.length === 3) {\n    h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];\n  }\n  const int = parseInt(h, 16);\n  if (Number.isNaN(int) || h.length !== 6) return [0.08, 0.14, 0.31];\n  return [((int >> 16) & 255) / 255, ((int >> 8) & 255) / 255, (int & 255) / 255];\n}\n\nfunction clamp(v: number, lo: number, hi: number): number {\n  return Math.min(Math.max(v, lo), hi);\n}\n\n/**\n * Original demoscene-plasma fragment shader. Several layered sine/cosine fields\n * — two axis-aligned, one diagonal, and two travelling radial waves whose\n * centers orbit on their own slow beats — are summed into a single scalar field\n * over space and time. That field indexes a smooth 3-stop palette wrapped into a\n * seamless loop (A→B→C→A), and the lookup itself drifts with time, so the color\n * bands both deform AND palette-cycle — the classic hypnotic flow. The pointer\n * gently displaces the whole field toward the cursor for a subtle warp. Band\n * spatial frequency and vividness scale with `intensity`, keeping the default an\n * elegant cool duotone-to-tritone rather than a garish rainbow. A soft vignette,\n * an exponential tone curve, and film-grain dither kill 8-bit banding.\n * GLSL ES 1.00 (WebGL1/2 compatible); no fract() on spatial coords (only in the\n * hash), so there are no wrap seams.\n */\nconst FRAGMENT = /* glsl */ `\nprecision highp float;\n\nvarying vec2 vUv;\n\nuniform float uTime;\nuniform vec2 uResolution;\nuniform vec2 uPointer;\nuniform float uPointerActive; // eased 0..1 pointer (or ghost) presence\n\nuniform vec3 uColorA;\nuniform vec3 uColorB;\nuniform vec3 uColorC;\nuniform float uSpeed;\nuniform float uIntensity;\n\n// Seamless 3-stop loop palette: A -> B -> C -> A.\nvec3 palette(float x) {\n  float s = fract(x) * 3.0;\n  if (s < 1.0)      return mix(uColorA, uColorB, smoothstep(0.0, 1.0, s));\n  else if (s < 2.0) return mix(uColorB, uColorC, smoothstep(0.0, 1.0, s - 1.0));\n  else              return mix(uColorC, uColorA, smoothstep(0.0, 1.0, s - 2.0));\n}\n\n// Compact value-noise hash (fract only inside) for dither.\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(123.34, 456.21));\n  p += dot(p, p + 45.32);\n  return fract(p.x * p.y);\n}\n\nvoid main() {\n  float aspect = uResolution.x / max(uResolution.y, 1.0);\n  // Pointer influence scales with presence so it releases when nobody is there.\n  vec2 ptr = mix(vec2(0.5), uPointer, uPointerActive);\n  vec2 p = vUv - 0.5;\n  p.x *= aspect;\n\n  // Subtle pointer warp — gently pulls the whole field toward the cursor.\n  p += (ptr - 0.5) * 0.12;\n\n  float t = uTime * uSpeed;\n  float freq = 4.0 + clamp(uIntensity, 0.0, 2.0) * 3.0; // denser bands with intensity\n\n  // Layered sine/cosine fields — the heart of the plasma.\n  float v = 0.0;\n  v += sin(p.x * freq + t);\n  v += sin(p.y * freq * 0.9 - t * 1.1);\n  v += sin((p.x + p.y) * freq * 0.7 + t * 0.8);\n\n  vec2 c1 = vec2(sin(t * 0.31), cos(t * 0.27)) * 0.4;\n  v += sin(length(p - c1) * freq * 1.3 - t * 1.4);\n\n  vec2 c2 = vec2(cos(t * 0.23), sin(t * 0.19)) * 0.5;\n  v += sin(length((p - c2) * vec2(1.2, 0.8)) * freq - t);\n\n  // Map the summed field into a cycling palette index; the lookup drifts with\n  // time so the palette cycles as the bands deform.\n  float idx = v * 0.12 + t * 0.05;\n  vec3 col = palette(idx);\n\n  // Vividness rises gently with intensity (kept restrained by default).\n  col *= 0.82 + 0.26 * clamp(uIntensity, 0.0, 2.0);\n\n  // Soft vignette to seat it as a background.\n  vec2 vg = (vUv - 0.5) * vec2(aspect, 1.0);\n  col *= 1.0 - 0.28 * dot(vg, vg);\n\n  // Exponential tone curve rolls highlights instead of clipping.\n  col = vec3(1.0) - exp(-col * 1.15);\n\n  // Film-grain dither kills 8-bit banding in the smooth gradients.\n  float grain = hash21(gl_FragCoord.xy + fract(t) * 137.0) - 0.5;\n  col += grain * (1.5 / 255.0);\n\n  gl_FragColor = vec4(max(col, 0.0), 1.0);\n}\n`;\n\n/**\n * Plasma — a classic 90s demoscene plasma background. Layered sine/cosine fields\n * over space and time sum into a scalar that indexes a smooth palette wrapped\n * into a seamless loop, so smooth flowing color bands both deform and\n * palette-cycle — organic, hypnotic, endless. The pointer subtly warps the\n * field. Tasteful cool duotone-to-tritone by default; push the `colors` knob for\n * full psychedelia. Built on the `ogl-canvas` harness: DPR-clamped,\n * offscreen-paused, reduced-motion-safe (freezes on a static plasma frame), full\n * GL teardown. Drop it inside any `relative` container; it fills and sits behind\n * content.\n */\nexport function Plasma({\n  colors = DEFAULT_COLORS,\n  speed = 1,\n  intensity = 1,\n  paused = false,\n  idle = true,\n  className,\n  ...props\n}: PlasmaProps) {\n  const uniforms = React.useMemo(\n    () => ({\n      uColorA: { value: hexToRgb(colors[0]) },\n      uColorB: { value: hexToRgb(colors[1]) },\n      uColorC: { value: hexToRgb(colors[2]) },\n      uSpeed: { value: Math.max(speed, 0) },\n      uIntensity: { value: clamp(intensity, 0, 2) },\n    }),\n    [colors, speed, intensity]\n  );\n\n  return (\n    <OglCanvas\n      aria-hidden\n      data-crucible=\"plasma\"\n      className={cn(\"absolute inset-0 -z-10 bg-neutral-950\", className)}\n      fragment={FRAGMENT}\n      uniforms={uniforms}\n      dpr={2}\n      paused={paused}\n      ghost={idle}\n      reducedMotionTime={5}\n      {...props}\n    />\n  );\n}\n"
    }
  ]
}