Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Water

  1. Object
  2. Water

Water surfaces. Each factory returns a ShaderMaterial for a Material.Type.PBR material on a finely subdivided plane (see Primitives.grid): the waves move its vertices, the normals and colour follow them, and the engine’s lighting adds the sky reflection and the sun’s glitter.

import com.codename1.gpu.Material;
import com.codename1.gpu.shaders.Water;

Material sea = new Material(Material.Type.PBR).setShader(Water.ocean()
        .setColorUniform(Water.DEEP, 0x0b3d4f).setUniform(Water.WAVE_HEIGHT, 0.6f));

Waves are computed from world x/z, so place the plane unrotated and unscaled; a translation is fine. Tune with the uniforms named below, every frame if you like.

Fields

public static final String DEEP = "waterDeep"VEC3 colour of deep water, looking straight down.
public static final String SHALLOW = "waterShallow"VEC3 colour where light passes through crests and shallows.
public static final String FOAM = "waterFoam"VEC3 colour of foam.
public static final String WAVE_HEIGHT = "waveHeight"FLOAT height of the largest wave, world units.
public static final String WAVE_LENGTH = "waveLength"FLOAT length of the largest wave, world units.
public static final String WAVE_SPEED = "waveSpeed"FLOAT speed multiplier; 1 moves like deep sea water.
public static final String CHOPPINESS = "waveChop"FLOAT 0 for round swells, 1 for sharp crests.
public static final String FOAM_AMOUNT = "foamAmount"FLOAT how much of the crests turns white, 0 to 1.
public static final String ROUGHNESS = "waterRough"FLOAT surface roughness; lower is a sharper sun glitter.
public static final String DIRECTION = "waveDir"VEC2 the direction the main swell travels.
public static final String FLOW = "waterFlow"FLOAT world units per second the surface drifts, for rivers.

Methods

public static ShaderMaterial ocean()Open sea: four crossing Gerstner waves, foamy crests, cellular foam streaks and fine moving ripples.
public static ShaderMaterial lake()Calm water: two long, low waves and wind ripples, no foam.
public static ShaderMaterial river()Running water: the ripples and foam drift along DIRECTION at FLOW units per second.

Inherited methods

Field details

DEEP

public static final String DEEP = "waterDeep"
VEC3 colour of deep water, looking straight down.

SHALLOW

public static final String SHALLOW = "waterShallow"
VEC3 colour where light passes through crests and shallows.

FOAM

public static final String FOAM = "waterFoam"
VEC3 colour of foam.

WAVE_HEIGHT

public static final String WAVE_HEIGHT = "waveHeight"
FLOAT height of the largest wave, world units.

WAVE_LENGTH

public static final String WAVE_LENGTH = "waveLength"
FLOAT length of the largest wave, world units.

WAVE_SPEED

public static final String WAVE_SPEED = "waveSpeed"
FLOAT speed multiplier; 1 moves like deep sea water.

CHOPPINESS

public static final String CHOPPINESS = "waveChop"
FLOAT 0 for round swells, 1 for sharp crests.

FOAM_AMOUNT

public static final String FOAM_AMOUNT = "foamAmount"
FLOAT how much of the crests turns white, 0 to 1.

ROUGHNESS

public static final String ROUGHNESS = "waterRough"
FLOAT surface roughness; lower is a sharper sun glitter.

DIRECTION

public static final String DIRECTION = "waveDir"
VEC2 the direction the main swell travels.

FLOW

public static final String FLOW = "waterFlow"
FLOAT world units per second the surface drifts, for rivers.

Method details

ocean

public static ShaderMaterial ocean()
Open sea: four crossing Gerstner waves, foamy crests, cellular foam streaks and fine moving ripples.

Returns

a new shader material

lake

public static ShaderMaterial lake()
Calm water: two long, low waves and wind ripples, no foam.

Returns

a new shader material

river

public static ShaderMaterial river()
Running water: the ripples and foam drift along DIRECTION at FLOW units per second.

Returns

a new shader material