Class Water

java.lang.Object
com.codename1.gpu.shaders.Water

public final class Water extends Object

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.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    FLOAT 0 for round swells, 1 for sharp crests.
    static final String
    VEC3 colour of deep water, looking straight down.
    static final String
    VEC2 the direction the main swell travels.
    static final String
    FLOAT world units per second the surface drifts, for rivers.
    static final String
    VEC3 colour of foam.
    static final String
    FLOAT how much of the crests turns white, 0 to 1.
    static final String
    FLOAT surface roughness; lower is a sharper sun glitter.
    static final String
    VEC3 colour where light passes through crests and shallows.
    static final String
    FLOAT height of the largest wave, world units.
    static final String
    FLOAT length of the largest wave, world units.
    static final String
    FLOAT speed multiplier; 1 moves like deep sea water.
  • Method Summary

    Modifier and Type
    Method
    Description
    Calm water: two long, low waves and wind ripples, no foam.
    Open sea: four crossing Gerstner waves, foamy crests, cellular foam streaks and fine moving ripples.
    Running water: the ripples and foam drift along DIRECTION at FLOW units per second.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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