Skip to documentation content

Water

Ripple caustic light across a pool of color or an image, with ripples where the pointer moves.

water-demo

Overview

Water draws the bright, shifting net of light you see on the floor of a sunny pool: caustics. Two layers of light threads drift at different sizes and speeds, a slow surface wave bends whatever lies beneath, and the brightest threads split slightly into color. Underneath is either a gradient from deepColor to shallowColor, or an image passed as src, which covers the container and wobbles with the surface. With ripples, moving the pointer leaves small rings and a tap sends out a larger one.

Use it for a calm hero or a summer campaign, or over a product photo to suggest it is under water. Lower intensity and distortion behind content so the light network stays in the background.

Installation

npm install honestui

Usage

import { Water } from "honestui/shaders"

<div className="h-80">
  <Water className="size-full" deepColor="#0b3a4f" shallowColor="#1d7a8c" />
</div>

With an image beneath the water:

<Water className="size-full" src="/images/pool-floor.jpg" intensity={0.8} />

A remote image must be served with CORS headers so WebGL can read it. Until it loads, and if it fails, the gradient shows instead.

Accessibility

Water is decorative: the canvas is hidden from assistive technology, and text or actions belong in normal HTML above it. If the image carries meaning, describe it in nearby text, because the canvas has no alternative text. The caustics brighten and darken constantly, so test overlaid text across the full animation. Animation and ripples pause while the effect is offscreen, while the document is hidden, and when the user prefers reduced motion; a still frame is rendered instead. Use paused for your own control, and give the container a background for when WebGL is unavailable.

API Reference

PropTypeDefaultDescription
deepColorstring"#0b3a4f"Color of the deeper water, at the bottom of the container.
shallowColorstring"#1d7a8c"Color of the shallower water, at the top of the container.
highlightColorstring"#e6fbff"Color of the caustic light.
intensitynumber1Brightness of the caustics, from 0 to 2.
scalenumber1Size of the caustic pattern. Larger values give bigger, fewer cells.
distortionnumber0.6How much the surface bends what lies beneath it.
dispersionnumber0.3Color fringing along the brightest caustic lines, from 0 to 1.
srcstring–Optional image seen through the water, covering the container. Remote images need CORS headers.
ripplesbooleantrueLeaves ripples where the pointer moves and taps.
speednumber1Animation speed. Changing it never makes the water jump.
pausedbooleanfalseRenders a static frame instead of animating.
classNamestring–Class for sizing and positioning the container.