Join our Discord Community

React Plasma Background

React plasma background with WebGL 2 rendering. Features organic fluid motion, mouse interaction, and customizable colors with advanced shader mathematics.

Powered by

Creating fluid plasma effects?

Join our Discord community for help from other developers working with shader effects and WebGL.


Ever watched plasma lamps create those mesmerizing, organic fluid patterns that seem to flow and morph with their own mysterious life? The way tendrils of electric light dance and twist, creating ever-changing ribbons of color that respond to touch and movement? Most backgrounds are static, predictable, and lifeless. This React component recreates that hypnotic plasma effect with WebGL 2 shaders, mathematical fluid dynamics, and mouse interaction that makes digital surfaces feel alive and responsive.

Interactive plasma with fluid dynamics

Watch organic plasma patterns flow and respond to mouse movement with real-time distortion:

Loading component...

Built for React applications with TypeScript and Next.js. Uses advanced WebGL 2 shaders with raymarching algorithms for fluid plasma simulation. The mathematical plasma generation creates authentic organic patterns while mouse interaction adds dynamic distortion effects. Perfect for hero sections, immersive galleries, or any interface needing sophisticated animated backgrounds. Seamless integration with shadcn/ui design systems.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/plasma-background.json
npx shadcn@latest add https://www.shadcn.io/registry/plasma-background.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/plasma-background.json
bunx shadcn@latest add https://www.shadcn.io/registry/plasma-background.json

Why static backgrounds feel dead

Developers add a gradient or animated GIF and call it dynamic. Maybe they add a CSS animation that loops every few seconds. The problem? Predictable patterns don't capture the organic, ever-changing nature of real plasma that makes backgrounds feel alive and responsive to user presence.

Plasma backgrounds with WebGL shaders change everything. They tap into our fascination with organic fluid motion—the way plasma moves in unpredictable but mathematically beautiful patterns, how electrical fields create flowing tendrils that never repeat exactly. The shader-based calculations generate true plasma physics using raymarching algorithms and distance field mathematics.

This component handles complex WebGL 2 automatically. Raymarching, distance field calculations, plasma flow dynamics, and mouse distortion all work together seamlessly. The result feels like controlling real plasma with electromagnetic fields, not a simple animated texture.

Features

  • WebGL 2 shaders with advanced raymarching algorithms for authentic plasma simulation
  • Mouse interaction with electromagnetic-style distortion effects based on cursor position
  • Direction control including forward, reverse, and oscillating pingpong motion
  • Custom color mapping from grayscale plasma intensity to any hex color
  • Scale and speed controls for fine-tuning plasma flow characteristics
  • Opacity management with proper alpha blending for layering effects
  • Performance optimization with automatic device pixel ratio limiting and cleanup
  • Sanitization system preventing NaN and infinity values in shader calculations
  • TypeScript support with complete prop forwarding and type safety
  • Responsive design with automatic canvas resizing and proper cleanup

API Reference

PlasmaBackground

PropTypeDefaultDescription
colorstring"#ffffff"Hex color for plasma tinting (empty for natural colors)
speednumber1Animation speed multiplier (0.1 to 5.0)
direction"forward" | "reverse" | "pingpong""forward"Plasma flow direction
scalenumber1Plasma scale factor (0.5 to 3.0)
opacitynumber1Overall opacity (0.0 to 1.0)
mouseInteractivebooleantrueEnable mouse distortion effects
classNamestring-Additional CSS classes
...propsHTMLAttributes<HTMLDivElement>-All standard div props

Color System

The component supports flexible color control:

Color ValueBehaviorVisual ResultPerformance
undefined or ""Natural plasma colorsFull spectrum rainbowOptimal
Hex color (e.g. "#ff6b35")Color-tinted plasmaMonochromatic variationsGood
Invalid hexFallback orangeDefault plasma tintGood

Direction Modes

// Forward flowing plasma
<PlasmaBackground direction="forward" speed={1.5} />

// Reverse flowing plasma
<PlasmaBackground direction="reverse" speed={0.8} />

// Oscillating plasma (pingpong)
<PlasmaBackground direction="pingpong" speed={2} />

// Static plasma (speed 0)
<PlasmaBackground speed={0} />

Effect Combinations

// Classic plasma lamp
<PlasmaBackground
  color="#9d4edd"
  speed={1.0}
  direction="forward"
  scale={1.2}
  mouseInteractive={true}
/>

// High-energy electric effect
<PlasmaBackground
  color="#00f5ff"
  speed={3.0}
  direction="pingpong"
  scale={0.8}
  opacity={0.9}
/>

// Subtle ambient background
<PlasmaBackground
  color="#ffd60a"
  speed={0.5}
  direction="forward"
  scale={2}
  opacity={0.3}
  mouseInteractive={false}
/>

// Psychedelic rainbow plasma
<PlasmaBackground
  speed={2.5}
  direction="reverse"
  scale={1.5}
  mouseInteractive={true}
/>

Shader mathematics

Raymarching Algorithm: Uses distance field raymarching to trace through 3D plasma fields, calculating surface intersections with mathematical precision for organic fluid shapes.

Plasma Flow Dynamics: Implements trigonometric wave functions with time-based phase shifts to create flowing plasma tendrils that never repeat exactly.

Mouse Distortion: Calculates electromagnetic-style field distortions based on cursor position, using distance-based falloff for realistic plasma response.

Color Space Conversion: Transforms plasma intensity values through proper color space mathematics, supporting both natural spectrum and custom color tinting.

Performance considerations

WebGL 2 Requirement: Component automatically checks for WebGL 2 support. Falls back gracefully but may not render on very old devices.

Device Pixel Ratio: Automatically limits DPR to 2 to prevent performance issues on high-density displays while maintaining visual quality.

Shader Complexity: The raymarching algorithm is computationally intensive. Consider reducing speed or scale on lower-end hardware.

Mouse Interaction: Disabling mouseInteractive slightly improves performance by removing mouse event calculations and shader branching.

Common gotchas

WebGL Context Loss: Component handles WebGL context restoration automatically, but may briefly show blank content during GPU driver updates.

Color Tinting Logic: Empty string or undefined color shows natural plasma colors. Invalid hex codes fall back to orange, not black or transparent.

Direction Pingpong: Uses sine wave oscillation, creating natural acceleration/deceleration rather than linear back-and-forth motion.

Scale Effects: Large scale values (greater than 2) can cause performance issues and visual artifacts. Small values (less than 0.5) may make plasma details too fine to appreciate.

Mouse Coordinates: Mouse distortion uses canvas-relative coordinates, automatically handling canvas scaling and positioning.

NaN Prevention: Built-in sanitization prevents shader NaN/infinity values that could crash the rendering pipeline on some GPUs.

You might also like

Questions developers actually ask