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.
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:
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.
Prop | Type | Default | Description |
---|---|---|---|
speed | number | 1.0 | Animation speed multiplier (0.1 to 3.0) |
bubbleCount | number | 1.0 | Bubble density and quantity (0.5 to 2.0) |
bubbleSize | number | 1.0 | Size of individual bubbles (0.5 to 2.0) |
animationIntensity | number | 1.0 | Bubble movement intensity (0.1 to 2.0) |
className | string | - | Additional Tailwind CSS classes |
...props | HTMLAttributes<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:
Plasma Shaders
Organic plasma effects with fluid WebGL animations
Sparks Drifting Shaders
Realistic fire simulation with drifting sparks
Sphere Field Shaders
3D sphere field raymarching with organic distortion
Cosmic Waves Shaders
Ethereal wave patterns with cosmic color palettes
Nebula Shaders
Cosmic nebula patterns with deep space aesthetics
Aurora Shaders
Northern lights effects with realistic color gradients
Questions developers actually ask
React Smooth Voronoi Contours
Anti-aliased Voronoi contour lines with numerical gradient smoothing. Pure WebGL abstract patterns for React with TypeScript and shadcn/ui—smooth GPU contour visualization.
React Sparks Drifting Shaders
Realistic fire simulation with drifting sparks and procedural noise. Pure WebGL shaders for React with TypeScript and shadcn/ui—smooth GPU animations.