Marble Animation
Paint-like colors swirling together in WebGL
WebGL Marbled Paint Fluid Animation
A WebGL marbling effect where colors swirl and blend like paint on water. A shader-based feedback simulation creates a rich, fluid look that never repeats.
- Built with
- Published
Where to use it
- Hero backgrounds for brand sites
- Setting the mood on concept or recruiting pages
- Memorable intros for campaign sites
How it works
- Two WebGLRenderTargets swap read and write roles every frame (ping-pong buffers), feeding the previous frame back into the shader as a feedback simulation
- The velocity field combines curl noise from fbm (fractal noise) with eight vortices, and sampling the previous frame backward along the flow makes the paint bleed and blend
- The simulation runs at a lower resolution than the display to save GPU time, while the display shader adds faux thickness and pigment grain from the density gradient
- The palette comes from just three uniform colors, so it's easy to match a brand
Make it your own
- Palette (color1–color3 in PARAMS — three uniforms set the whole mood)
- Simulation resolution (the render target scale — lower is lighter but blurrier)
- Flow strength and number of vortices (curl noise coefficients and the eight vortex parameters)
- Pigment grain and thickness (the gradient calculation in the display shader)
Before you ship
- Mobile & touch
- The pixel ratio is capped at 2, so high-density screens don't explode the workload. For low-end devices, consider lowering the simulation resolution further or falling back to a still image.
- Browser support
- Written in GLSL 1.0 rather than WebGL2, so it runs in modern browsers with WebGL. Color bleeding can vary by GPU, so check on real Windows and Mac hardware before launch.
- Performance (load: High)
- Reading and writing two render targets every frame makes this one of the heavier demos. The render loop stops off-screen, and the render targets are released on teardown. Plan for one instance per page.
- Accessibility
- The canvas is a decorative background with no meaningful information. If you layer text or buttons on top, the constantly shifting colors can hurt contrast — add a backing behind the text to keep it readable.
- Reduced motion
- Because the effect runs continuously, the site-wide CSS reset under prefers-reduced-motion: reduce doesn't stop it. To freeze it, check that media query and render a single frame instead of starting the loop.
FAQ
How do I create paint that blends in WebGL?
Use two WebGLRenderTargets as ping-pong buffers, reading and writing them alternately each frame so the previous result keeps feeding back into the shader as a simulation.
How is the fluid velocity field made?
It combines curl noise derived from fbm (fractal noise) with eight vortices. Sampling the previous frame backward along the flow makes the paint bleed and mix.
How do I keep a WebGL marbling effect lightweight?
Run the simulation at a lower resolution than the screen, and let the display shader add thickness and grain from the density gradient.