Guides
Sky and lighting
The water needs a sky to reflect and a light to glitter under. Out of the box it brings its own, a time-of-day sky with clouds, stars and a moon. Your lights can follow it with one call per frame.
time from 16:24 to 20:48 on the sunset preset. The sun colour, the glitter path, the sky reflection and the bound lights all follow; after dark the moon becomes the key light.#The built-in sky
WaterSystem.create() adds a sky dome to your scene. It follows the camera and scales itself to 0.9 × camera.far. It's the analytic sky from the original page: a sun arc from time, zenith and horizon colours, an fbm cloud deck with self-shadowing and silver lining, stars and a moon.
| Param | Default | Effect |
|---|---|---|
time | 14.5 | Hour of day, 0–24. Eases the short way round the clock |
clouds | 0.32 | Cloud cover 0–1. Also dims the sun |
cloudDarkness | 0 | Storm darkening 0–1 |
overcast | 0 | Sky desaturation 0–1 |
fogDensity | 0.00032 | Exponential-squared aerial perspective, per metre |
exposure | 1 | Exposure of the final composite |
water.setParams({ time: 18.2 }); // eases toward sunset
water.setParams({ clouds: 0.9, cloudDarkness: 0.6 }); // a darkening sky
water.stats.sunElevation; // degreesThese params only drive the built-in sky. With an external sky, time, clouds, cloudDarkness and overcast do nothing, and fogDensity still fogs the water.
dusk: blue hour, time: 18.45moonlit: the moon is the key light, time: 23.4#Lights that follow the sky
const sun = new THREE.DirectionalLight();
const hemi = new THREE.HemisphereLight();
scene.add(sun, sun.target, hemi);
renderer.setAnimationLoop(() => {
water.update(dt);
water.bindLights(sun, hemi, { distance: 250, intensity: 1.3 });
water.render();
});bindLights(directional?, hemisphere?, opts?) copies the water's current key light: the sun by day, the moon once the sun is down, from the built-in sky or an external one.
- The directional light is placed
opts.distance(250) metres from itstargetalong the light direction, so move the target to where your shadows should be. Its colour timesopts.intensity(1.3) equals the key light. - The hemisphere light takes the zenith and horizon colours for the sky, and the sky's ground colour.
#Scene fog
With manageFog: true (the default) the water keeps scene.fog as a THREE.FogExp2, coloured by the sky's horizon, with the fogDensity param as its density. Your objects then fade into the same haze as the sea. Pass manageFog: false to manage scene.fog yourself.
const water = await WaterSystem.create({ renderer, scene, camera, manageFog: false });#Use a different sky
setSky() replaces the built-in sky with any object that has a sun, and optionally an environment map, cloud shadows, a fog colour, ambient light and a moon. The built-in dome is removed from the scene, and setSky(null) puts it back.
water.setSky(skySystem); // naturegl-sky's SkySystem fits as is
water.setSky(null); // back to the built-in skyThe full contract, the options and the NatureGL Sky setup are on With other packs.
#BuiltinSky on its own
BuiltinSky is exported, and water.builtinSky is always there, even while an external sky is active.
| Member | |
|---|---|
sun | { direction, color, intensity }: the key light (the moon at night) |
sunDirection | The true sun, which may be below the horizon |
moon.direction, fogColor, ambient.sky, ambient.ground | |
day | 0 at night … 1 with the sun well up |
mesh | The dome |
apply(params) | Recompute from time, clouds, cloudDarkness, overcast, fogDensity |
follow(camera), bindLights(directional, hemisphere, opts), dispose() |