import { Backgrounds3D } from "@/components/3d/backgrounds";
export default function Example() {
return (
<div style={{ height: 320 }}>
<Backgrounds3D
variant="gradient"
theme="light"
/>
</div>
);
}
Deps: three, @react-three/fiber, @react-three/drei
Installation
Install the runtime dependencies, then copy the component module (and the shared 3D core when the component uses WebGL).
npm install three @react-three/fiber @react-three/drei
# Copy the component module
cp -r src/components/3d/backgrounds <your-project>/src/components/3d/backgrounds
# Copy the shared 3D core
cp -r src/components/3d/core <your-project>/src/components/3d/coreDependencies: three, @react-three/fiber, @react-three/drei
Usage
Every category module exposes one typed component. Pick an implementation with variant and pass props grouped by concern.
import { Backgrounds3D } from "@/components/3d/backgrounds";
export default function Example() {
return (
<div style={{ height: 320 }}>
<Backgrounds3D
variant="gradient"
theme="light"
/>
</div>
);
}
React implementation
With every prop set explicitly. The complete, copyable source of src/components/3d/backgrounds/index.tsx is available in the playground’s Source tab.
import { Backgrounds3D } from "@/components/3d/backgrounds";
export default function Example() {
return (
<div style={{ height: 320 }}>
<Backgrounds3D
variant="gradient"
theme="amoled"
colorA="#7777ff"
colorB="#8d93a8"
speed={1}
density={1}
size={1}
mouse
cameraMotion={0.5}
transparent={false}
quality="medium"
/>
</div>
);
}
Next.js implementation
WebGL needs the browser. Load the scene through next/dynamic with ssr disabled and a sized placeholder to avoid layout shift.
// app/shader-gradient-background/page.tsx (Next.js App Router)
"use client";
import dynamic from "next/dynamic";
// WebGL must never run on the server — load the scene client-side only.
const Backgrounds3D = dynamic(
() => import("@/components/3d/backgrounds").then((m) => m.Backgrounds3D),
{ ssr: false, loading: () => <div aria-busy="true" style={{ height: 320 }} /> },
);
export default function Page() {
return (
<main>
<div style={{ height: 320 }}>
<Backgrounds3D
variant="gradient"
theme="light"
/>
</div>
</main>
);
}
TypeScript interfaces
export type Theme = "light" | "amoled";
export interface ShaderGradientBackgroundProps {
/** Which 3D Backgrounds implementation to render */
variant: "gradient";
theme: Theme;
/* Visual */
colorA?: string; // default "#7777ff"
colorB?: string; // default "#8d93a8"
size?: number; // 0.3–3, default 1
/* Animation */
speed?: number; // 0–3, default 1
/* Rendering */
density?: number; // 0.2–2, default 1
transparent?: boolean; // default false
quality?: "low" | "medium" | "high"; // default "medium"
/* Interaction */
mouse?: boolean; // default true
/* Camera */
cameraMotion?: number; // 0–1, default 0.5
}
Props reference
| Prop | Type | Default | Group | Description |
|---|---|---|---|---|
| variant | "gradient" | — | Core | Selects the implementation. |
| theme | "light" | "amoled" | — | Core | Themes surfaces, materials and lighting. |
| colorA | string (hex) | "#7777ff" | Visual | Primary color |
| colorB | string (hex) | "#8d93a8" | Visual | Secondary color |
| speed | number | 1 | Animation | Animation speed (0 – 3) |
| density | number | 1 | Rendering | Particle density (0.2 – 2) |
| size | number | 1 | Visual | Size / scale (0.3 – 3) |
| mouse | boolean | true | Interaction | Mouse interaction |
| cameraMotion | number | 0.5 | Camera | Camera movement (0 – 1) |
| transparent | boolean | false | Rendering | Transparent background |
| quality | "low" | "medium" | "high" | "medium" | Rendering | Quality preset |
Customization
Colour props accept any hex string. Content props accept plain strings. Every value shown in the playground maps 1:1 to a prop, so you can design visually and copy the generated code. Use Share to send a pre-configured link or Export to download the configuration JSON.
import { Backgrounds3D } from "@/components/3d/backgrounds";
export default function Example() {
return (
<div style={{ height: 320 }}>
<Backgrounds3D
variant="gradient"
theme="light"
colorA="#ff5a36"
/>
</div>
);
}
Animation settings
- speedAnimation speed · 0–3
- mouseMouse interaction
All motion is suspended when prefers-reduced-motion is on.
Theme support
Pass theme="light" or theme="amoled". Lighting rigs, environment reflections, blending modes and canvas backgrounds change with it — AMOLED uses true #000000 with controlled emissive accents; Light uses soft studio lighting with contact shadows. Use the theme switch in the playground toolbar to preview both.
Responsive behavior
The component fills its parent, so size it with the container. Use the playground’s desktop / tablet / mobile selector to test. Canvas resolution adapts through the adaptive DPR range of the active quality preset.
Accessibility notes
- — The canvas is exposed as a labelled image and never receives keyboard focus, so it can't trap navigation.
- — Keep foreground text above 4.5:1 contrast against the brightest area of the background.
- — Motion stops entirely when prefers-reduced-motion is enabled.
Performance notes
- — Particle count scales with the quality preset (LOW ≈ 35%, MEDIUM ≈ 70%, HIGH 100%).
- — Rendering pauses automatically when the canvas leaves the viewport.
- — All motion is computed on the GPU in vertex shaders — the CPU only updates a handful of uniforms per frame.
Presets: LOW (DPR 1, no AA, ~35% density) · MEDIUM (DPR ≤1.5, ~70%) · HIGH (DPR ≤2, full density).
Related components
- 3D Noise FieldA grid of points displaced by animated 3D simplex noise, pushed by the pointer.
- Holographic GridA cyan-to-violet grid with pulsing scan rings expanding from the centre.
- Floating Orb BackgroundLarge instanced chrome orbs floating in studio light.
- Animated Energy FieldElectric filaments of constructive noise that crackle toward your cursor.