Join our Discord Community

React Soap Bubbles 2D Shaders

Realistic soap bubble simulation with procedural noise and cellular patterns. Pure WebGL shaders for React with TypeScript and shadcn/ui—smooth GPU animations.

Powered by

Building soap bubble effects?

Join our Discord community for help from other developers working with WebGL shaders.


Look, we've all tried to build realistic bubble effects. You either end up with basic circle animations that look nothing like proper soap bubbles or JavaScript calculations that can't handle complex bubble physics smoothly. This React component uses advanced WebGL shaders with cellular algorithms and procedural noise that actually runs at 60fps without melting your CPU.

Smooth soap bubbles animation

Mesmerizing 2D soap bubble simulation with realistic refraction and iridescence that won't destroy your performance metrics:

Loading component...

Created by foxes in 2015-08-23

Built for React applications with TypeScript and Next.js in mind. The animation runs entirely on the GPU using WebGL shaders with cellular pattern generation, multi-layered noise, and realistic bubble physics. Works seamlessly with shadcn/ui design systems.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/soap-bubbles-2d-shaders.json
npx shadcn@latest add https://www.shadcn.io/registry/soap-bubbles-2d-shaders.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/soap-bubbles-2d-shaders.json
bunx shadcn@latest add https://www.shadcn.io/registry/soap-bubbles-2d-shaders.json

Usage

import { SoapBubbles2DShaders } from "@/components/ui/soap-bubbles-2d-shaders";

export default function Hero() {
  return (
    <SoapBubbles2DShaders>
      <div className="relative z-10">
        <h1>Your content here</h1>
      </div>
    </SoapBubbles2DShaders>
  );
}

Why most bubble implementations suck

Most developers try to animate bubbles with CSS animations or basic particle systems. Bad idea. You're dealing with unrealistic circular shapes, poor refraction effects, and wondering why your React app feels sluggish. Some use canvas drawing with JavaScript bubble physics, which sounds smart until you realize you're computing cellular algorithms for every bubble on every frame.

This React component uses mathematical cellular pattern generation with multi-layered procedural noise and realistic bubble distortion. The GPU handles everything using optimized hash functions with authentic iridescent color generation. No JavaScript calculations, no particle system overhead, just smooth 60fps mathematical bubble simulation.

Features

  • Zero JavaScript animation overhead - Pure WebGL cellular algorithms run on GPU
  • Cellular pattern generation with sophisticated hash functions for realistic bubble placement
  • Multi-layered procedural noise for authentic bubble surface textures
  • Realistic refraction effects with UV distortion and iridescent coloring
  • TypeScript definitions for proper IDE support in React projects
  • Customizable parameters with 4 props for complete control
  • Performance optimization through efficient cellular algorithms
  • shadcn/ui compatible for consistent design systems
  • Responsive design with automatic canvas resizing

API Reference

SoapBubbles2DShaders

Main container component for the soap bubbles effect.

PropTypeDefaultDescription
speednumber1.0Animation speed multiplier (0.1 to 3.0)
bubbleCountnumber1.0Bubble density and quantity (0.5 to 2.0)
bubbleSizenumber1.0Size of individual bubbles (0.5 to 2.0)
animationIntensitynumber1.0Bubble movement intensity (0.1 to 2.0)
classNamestring-Additional Tailwind CSS classes
...propsHTMLAttributes<HTMLDivElement>-All standard div props

Common gotchas

Animation not working: WebGL might not be supported in the browser. The component logs warnings when WebGL initialization fails. Check browser compatibility.

Performance issues on mobile: Some older phones struggle with complex cellular algorithms and multi-layered noise. Consider reducing speed and animationIntensity props for better performance.

Bubbles too small/large: Adjust the bubbleSize prop. Lower values (0.5-0.7) create smaller, more delicate bubbles, higher values (1.5-2.0) create larger, more prominent bubbles.

Too many/few bubbles: Use the bubbleCount prop to control bubble density. Lower values create sparse bubble fields, higher values create dense bubble clusters.

Movement too chaotic: Lower the animationIntensity prop for more gentle bubble movement. Values around 0.5-0.7 work well for subtle floating effects.

You might also like

Explore other shader-based background components for React applications:

Questions developers actually ask