Join our Discord Community

React 3D Prism Background

React 3D prism background with WebGL rendering. Features multiple animation modes, GLSL shaders, and interactive hover effects using OGL.

Powered by

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:

Loading component...

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

PropTypeDefaultDescription
particleCountnumber50Number of floating prisms to render (affects performance)
animationSpeednumber0.01Speed multiplier for rotation and floating animations
colorMode'rainbow' | 'monochrome' | 'blue' | 'purple''rainbow'Color palette for prism materials
classNamestring-Additional CSS classes for the container
...propsHTMLAttributes<HTMLDivElement>-All standard div props supported

Animation System

The component uses three coordinated animation layers:

SystemPurposePerformance ImpactCustomization
RotationIndividual prism spinningLowSpeed via animationSpeed
TranslationFloating movement patternsLowAutomatic sine/cosine waves
LightingDynamic light calculationsMediumColor via colorMode
RenderingWebGL draw callsHighCount 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

Questions developers actually ask