Water Realism Upgrade (r183-inspired)

Real-time water surface demo using Three.js `Water` with animated wave uniforms, distortion controls, and reflective highlights around a lit island scene.

Key topics: three.js water, watermesh, water realism, reflections, r183, ocean shader

Overview

Convincing water is mostly about reflections, distortion and specular highlights rather than fluid simulation. Three.js includes a production-ready Water object that combines all three. This demo places it around a lit island, animates the waves and exposes the distortion and colour controls, using a generated normal texture so it needs no external assets.

How it works

The Water object from three/examples/jsm/objects/Water.js is a large plane with a specialised shader:

  • Planar reflection. Before the main render, the scene is drawn from a mirrored camera below the water plane into a render target, capturing what the surface should reflect.
  • Normal-map ripples. A tiling normal map is sampled twice at different scales and scrolling directions, and the combined normal distorts the reflection lookup, so the reflection wobbles like real water. distortionScale sets how strong that wobble is.
  • Fresnel and sun glint. At glancing angles water reflects more, and looking straight down it shows more of its own colour. A specular term based on the sun direction creates the bright glints that sell the effect.

Animating is as simple as increasing water.material.uniforms.time each frame. Here the normal map is generated as a DataTexture from code, so the demo does not fetch an image.

Exploring the demo

Increase distortion to turn calm, glassy water into choppy water, and lower it for a mirror-like lake. Orbit to a low angle and notice the reflections strengthen (the Fresnel effect), then look down from above to see more of the water colour. Move around to catch the sun glints.

Practical advice

Planar reflections cost a second render of the scene, so keep the reflection render target modest and hide small objects from the reflection where you can. For a stylised or cheaper look, see the water shader and caustics; for scenes built around water, see the oasis and the underwater scene.

What this code does

- Water Object Pipeline: uses `three/examples/jsm/objects/Water.js` for a production-style reflective water surface.
- Animated Wave Time: increments `water.material.uniforms.time` each frame to drive wave motion.
- Distortion Tuning: distortion scale controls reflection refraction strength and perceived water roughness.
- Local Normal Texture: generated `DataTexture` normal map keeps the demo self-contained without external asset fetches.
- Lighting Response: directional sun + ambient fill create specular highlights and color variation over the surface.
- Practical Pattern: good baseline for lakes, ocean edges, or stylized water scenes where full fluid simulation is overkill.

Continue Learning

JavaScript Implementation

ES6+
import * as THREE from 'three'
import { Water } from 'three/examples/jsm/objects/Water.js'

const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(58, width / height, 0.1, 300)
const renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setSize(width, height)
document.querySelector('#app').appendChild(renderer.domElement)

const waterNormals = buildSeamlessNormals()
const water = new Water(new THREE.PlaneGeometry(120, 120, 180, 180), {
  textureWidth: 512,
  textureHeight: 512,
  waterNormals,
  sunDirection: sun.position.clone().normalize(),
  waterColor: 0x2f6fa7,
  distortionScale: 3.4
})
water.rotation.x = -Math.PI / 2
scene.add(water)

function animate () {
  requestAnimationFrame(animate)
  water.material.uniforms.time.value += 1 / 60
  // Optional: apply Gerstner/spectral displacement to geometry vertices here.
  renderer.render(scene, camera)
}
animate()

Related demos

Trending this week

Most popular