Class Water
java.lang.Object
com.codename1.gpu.shaders.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringFLOAT0 for round swells, 1 for sharp crests.static final StringVEC3colour of deep water, looking straight down.static final StringVEC2the direction the main swell travels.static final StringFLOATworld units per second the surface drifts, for rivers.static final StringVEC3colour of foam.static final StringFLOAThow much of the crests turns white, 0 to 1.static final StringFLOATsurface roughness; lower is a sharper sun glitter.static final StringVEC3colour where light passes through crests and shallows.static final StringFLOATheight of the largest wave, world units.static final StringFLOATlength of the largest wave, world units.static final StringFLOATspeed multiplier; 1 moves like deep sea water. -
Method Summary
Modifier and TypeMethodDescriptionstatic ShaderMateriallake()Calm water: two long, low waves and wind ripples, no foam.static ShaderMaterialocean()Open sea: four crossing Gerstner waves, foamy crests, cellular foam streaks and fine moving ripples.static ShaderMaterialriver()Running water: the ripples and foam drift alongDIRECTIONatFLOWunits per second.
-
Field Details
-
DEEP
-
SHALLOW
VEC3colour where light passes through crests and shallows.- See Also:
-
FOAM
-
WAVE_HEIGHT
-
WAVE_LENGTH
-
WAVE_SPEED
FLOATspeed multiplier; 1 moves like deep sea water.- See Also:
-
CHOPPINESS
-
FOAM_AMOUNT
-
ROUGHNESS
FLOATsurface roughness; lower is a sharper sun glitter.- See Also:
-
DIRECTION
-
FLOW
FLOATworld units per second the surface drifts, for rivers.- See Also:
-
-
Method Details
-
ocean
Open sea: four crossing Gerstner waves, foamy crests, cellular foam streaks and fine moving ripples.
Returns
a new shader material
-
lake
Calm water: two long, low waves and wind ripples, no foam.
Returns
a new shader material
-
river
Running water: the ripples and foam drift along
DIRECTIONatFLOWunits per second.Returns
a new shader material
-