WaterShaderProgram

Package: Libraries.Game.Graphics.Worlds · Inherits from: Libraries.Language.Object, Libraries.Game.Graphics.Shaders.Programs.ShaderProgram

WaterShaderProgram draws water: lakes and seas over the terrain. It is a forward program: drawn after the lighting, over what is already there, so it can look through to the ground below. Deeper water is darker, the edge fades softly into the shore, ripples move with time, and the sun and lamps glint on it. The program holds every setting. Give it to WaterSurfaces with their Load action; every surface using one program looks the same. Install it once, before the first surface is loaded. It needs Vulkan.

Example Code

use Libraries.Game.Game
use Libraries.Game.Graphics.Worlds.WaterShaderProgram
use Libraries.Game.Graphics.Worlds.WaterSurface

class Main is Game
WaterShaderProgram water
WaterSurface lake

action Main
    StartGame()
end

action CreateGame
    water:Install()
    water:SetClarity(0.3)
    lake:Load(40, 40, water)
    lake:SetPosition(0, 2, 0)
    Add(lake)
end
end

Actions

FillData(Libraries.Containers.Number32BitArray data)

This action writes the settings, in the order WaterFragmentShader reads them: the shallow and deep colors, the waves (scale, speed, direction), the look (clarity, shore fade, roughness, reflection), and the ripples' strength. WaterShaderMapping calls it each frame.

Parameters

GetClarity()

This action returns how quickly the water darkens with depth.

Returns

number: The value from SetClarity.

GetDeepColor()

This action returns the color of deep water.

Returns

Libraries.Game.Graphics.Color: The deep color.

GetNormalMap()

This action returns the ripple texture: a normal map that tiles, made when the program is installed.

Returns

Libraries.Game.Graphics.Texture: The normal map, or undefined before Install.

GetNormalStrength()

This action returns how strong the ripples look.

Returns

number: The value from SetNormalStrength.

GetReflectionStrength()

This action returns how much of the sky the water reflects.

Returns

number: The value from SetReflectionStrength.

GetRoughness()

This action returns the surface's roughness.

Returns

number: The value from SetRoughness.

GetShallowColor()

This action returns the color of shallow water.

Returns

Libraries.Game.Graphics.Color: The shallow color.

GetShoreFade()

This action returns the depth over which the edge fades.

Returns

number: The value from SetShoreFade.

GetWaveScale()

This action returns the size of a ripple tile.

Returns

number: The value from SetWaveScale.

GetWaveSpeed()

This action returns how fast the ripples move.

Returns

number: The value from SetWaveSpeed.

Install()

This action compiles the program as "Water Shader Program" and makes its ripple texture. Call it once, before loading any WaterSurface with it.

Install(text programName)

This action compiles the program under a name, and makes its ripple texture. Each program installed needs its own name.

Parameters

  • programName text: The name to register the program under.

SetClarity(number value)

This action sets how quickly the water darkens and hides the ground as it gets deeper. 0 is perfectly clear; 1 is muddy within a meter or so.

Parameters

  • value number: How murky the water is, 0 or more.

SetDeepColor(Libraries.Game.Graphics.Color color)

This action sets the color of deep water, and its alpha is how much of the ground shows through deep water, from 0 (all of it) to 1 (none).

Parameters

SetNormalStrength(number strength)

This action sets how strong the ripples look: 0 is a flat mirror, 1 is normal, and 2 is choppy.

Parameters

  • strength number: The ripples' strength.

SetReflectionStrength(number strength)

This action sets how much of the sky the water reflects, from 0 for none to 1 for all the physics allows.

Parameters

  • strength number: The reflection's strength.

SetRoughness(number value)

This action sets how rough the surface is for glints: small values give sharp sun glints, larger ones a broad sheen.

Parameters

  • value number: The roughness, from 0.02 to 1.

SetShallowColor(Libraries.Game.Graphics.Color color)

This action sets the color of shallow water, and its alpha is how much of the ground shows through it, from 0 (all of it) to 1 (none).

Parameters

SetShoreFade(number depth)

This action sets how deep the water is, in world units, before its edge stops fading into the shore. 0 gives a hard edge.

Parameters

  • depth number: The depth over which the edge fades.

SetWaveDirection(number x, number z)

This action sets the way the wind pushes the ripples, along the ground. Only the direction matters.

Parameters

  • x number: The direction's x part.
  • z number: The direction's z part.

SetWaveScale(number size)

This action sets how many world units one tile of the larger ripples covers. The smaller ripples are a little under half that.

Parameters

  • size number: The size of a ripple tile, more than 0.

SetWaveSpeed(number speed)

This action sets how fast the ripples move, in world units a second.

Parameters

  • speed number: The ripples' speed.

Inherited Actions

22 actions from Libraries.Game.Graphics.Shaders.Programs.ShaderProgram
3 actions from Libraries.Language.Object