React 3D Prism Background
React 3D prism background with WebGL rendering. Features multiple animation modes, GLSL shaders, and interactive hover effects using OGL.
Building immersive 3D backgrounds?
Join our Discord community for help from other developers working with WebGL.
Remember those mesmerizing screensavers that made you stop scrolling and just watch? The ones where geometric shapes danced through 3D space, casting prismatic light effects that seemed almost alive? Most websites settle for flat gradients or static patterns that feel lifeless. This React component brings that captivating 3D magic to your interface with floating geometric prisms that rotate through space, creating depth and visual intrigue that keeps users engaged.
Floating prisms with WebGL rendering
Watch crystalline structures float and rotate in 3D space with realistic lighting:
Built for React applications with TypeScript and Next.js. Uses WebGL through OGL for hardware-accelerated 3D rendering that maintains 60fps even with dozens of floating elements. The prismatic lighting system creates rainbow reflections that shift as objects rotate. Perfect for hero sections, loading screens, or any interface element that needs to feel premium and modern. Seamless integration with shadcn/ui design systems.
Installation
npx shadcn@latest add https://www.shadcn.io/registry/prism-background.json
npx shadcn@latest add https://www.shadcn.io/registry/prism-background.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/prism-background.json
bunx shadcn@latest add https://www.shadcn.io/registry/prism-background.json
Why flat backgrounds feel dead
Developers throw a gradient background on a div and call it sophisticated design. Maybe add some CSS animation that moves a few pixels left and right. The problem? Users have seen these effects a thousand times. They don't create emotional connection or communicate innovation.
3D prism effects change everything. They tap into our fascination with light, geometry, and depth perception. The floating motion creates a sense of weightlessness—like peering into a crystal cave or watching aurora particles dance. Each prism catches light differently as it rotates, creating natural variety that feels organic rather than programmed.
This component handles the complex WebGL setup automatically. Lighting calculations, particle systems, camera positioning, and animation loops all work together seamlessly. The result feels like a premium digital art installation, not a cheesy web effect.
Features
- Hardware-accelerated 3D rendering using WebGL through OGL for smooth 60fps animation
- Floating particle system with dozens of independently animated geometric prisms
- Realistic lighting model with fresnel effects and prismatic color reflections
- Multiple color modes including rainbow, monochrome, blue, and purple palettes
- Configurable particle count and animation speed for performance optimization
- Responsive canvas rendering that adapts to container dimensions
- TypeScript support with complete prop forwarding and type safety
- Memory efficient cleanup preventing WebGL context leaks on unmount
- Cross-browser compatibility with graceful degradation for older devices
API Reference
PrismBackground
Prop | Type | Default | Description |
---|---|---|---|
particleCount | number | 50 | Number of floating prisms to render (affects performance) |
animationSpeed | number | 0.01 | Speed multiplier for rotation and floating animations |
colorMode | 'rainbow' | 'monochrome' | 'blue' | 'purple' | 'rainbow' | Color palette for prism materials |
className | string | - | Additional CSS classes for the container |
...props | HTMLAttributes<HTMLDivElement> | - | All standard div props supported |
Animation System
The component uses three coordinated animation layers:
System | Purpose | Performance Impact | Customization |
---|---|---|---|
Rotation | Individual prism spinning | Low | Speed via animationSpeed |
Translation | Floating movement patterns | Low | Automatic sine/cosine waves |
Lighting | Dynamic light calculations | Medium | Color via colorMode |
Rendering | WebGL draw calls | High | Count via particleCount |
Color Mode Examples
// Rainbow spectrum (default)
<PrismBackground colorMode="rainbow" />
// Subtle monochrome
<PrismBackground colorMode="monochrome" />
// Ocean theme
<PrismBackground colorMode="blue" />
// Royal theme
<PrismBackground colorMode="purple" />
// Performance optimized
<PrismBackground particleCount={20} animationSpeed={0.005} />
Performance considerations
Particle count scaling: Each prism requires individual draw calls and matrix calculations. Start with 30-50 particles for most devices. High-end devices can handle 100+, while mobile should use 20 or fewer.
WebGL context management: The component automatically handles WebGL context creation and cleanup. Multiple instances on the same page share the GPU efficiently, but avoid rendering dozens simultaneously.
Animation frame optimization: Uses requestAnimationFrame
for smooth 60fps rendering. The animation loop automatically pauses when the component unmounts or the tab becomes inactive.
Memory leak prevention: WebGL contexts are properly disposed when components unmount. The cleanup process releases GPU memory and prevents the browser from running out of WebGL contexts.
Mobile device adaptation: Touch devices may experience thermal throttling with complex 3D scenes. Consider reducing particleCount
and animationSpeed
for mobile users or use media queries to conditionally render simpler alternatives.
Common gotchas
Container sizing: The canvas fills its parent container completely. Ensure the parent has explicit width and height - percentage-based sizing works perfectly for full-screen backgrounds.
Z-index layering: The canvas renders behind other content by default. Content placed inside the component container will appear above the 3D scene. Use CSS z-index for complex layering scenarios.
WebGL support detection: Modern browsers support WebGL, but very old devices might not. The component gracefully handles WebGL initialization failures, though you might want to provide fallback content.
Animation timing consistency: The floating motion uses sine waves with different frequencies per prism. This creates natural variation, but rapid props changes might cause animation jumps during development.
Color mode switching: Changing colorMode
recreates all prism materials, causing a brief rendering pause. For dynamic theming, consider using CSS variables or pre-loading different color instances.
You might also like
Aurora Background
Northern lights effect with flowing gradient animations
Particles Background
Interactive particle system with mouse attraction
Shooting Stars
Animated streaking lights across dark space
Hexagon Background
Geometric honeycomb patterns with depth effects
Questions developers actually ask
React Plasma Background
React plasma background with WebGL 2 rendering. Features organic fluid motion, mouse interaction, and customizable colors with advanced shader mathematics.
React Retro Grid Background
React retro grid background with 80s cyberpunk perspective. CSS infinite scrolling and neon colors create nostalgic vibes with TypeScript and shadcn/ui.