Water Rendering

Water rendering is easy to achieve in Awakening. You first use a Portal or Ocean to generate reflected / refractive images, the use water shaders to compose them.

All shader files for water rendering can be found at the "effects\water" folder.


Shader File
Preview Explanation
bump_nops.sha   Use a bump map to distort reflected / refractive  image.

Factor:
number
bump_texture
number
reflected_texture
number
refractive_texture

vec4 
vecWaterNormal -- the normalize normal vector of water surface
vec4 vecWaterParam -- x : wave speed

Usage:
material.setTexture(0, bump_texture)
material.setTexture(1,
reflected_texture)
material.setTexture(2,
refractive_texture)

local waternormal=vec4.new(0,1,0)
local wavespeed=0.2
material.setEffectVector('vecWaterNormal',waternormal)
material.setEffectVector('vecWaterParam',vec4.new(wavespeed))

PixelShader: No
bump_norefra_nops.sha   Use a bump map to distort reflected image, no refraction; fast than above shader.
You should check material's
Transparence style for this shader.

Factor:
number
bump_texture
number
reflected_texture

vec4 
vecWaterNormal -- the normalize normal vector of water surface
vec4 vecWaterParam -- x : wave speed

Usage:
material.setTexture(0, bump_texture)
material.setTexture(1,
reflected_texture)

local waternormal=vec4.new(0,1,0)
local wavespeed=0.2
material.setEffectVector('vecWaterNormal',waternormal)
material.setEffectVector('vecWaterParam',vec4.new(wavespeed))

PixelShader: No
lake.sha   Compose reflected / refractive images  and water color by depth map, and use a bump map to distort result.
See
Render scene depth info to a texture for depth map, and you need hide ocean self when rendering the map.

Factor:
number
reflected_texture
number
refractive_texture
number
depth_texture
number
bump_texture

vec4 
vecWaterNormal -- the normalize normal vector of water surface
vec4 vecWaterParam -- x : wave speed; y : bump strength
vec4 vecWaterColor -- self color of water, used water color = vecWaterColor * vecWaterColor.a

Usage:
material.setTexture(0, reflected_texture)
material.setTexture(1,
refractive_texture)
material.setTexture(2,
depth_texture)
material.setTexture(3,
bump_texture)

local waternormal=vec4.new(0,1,0)
local wavespeed=0.2
local bump=2
material.setEffectVector('vecWaterNormal',waternormal)
material.setEffectVector('vecWaterParam',vec4.new(wavespeed,bump))

local wateralpha=0.5
material.setEffectVector('vecWaterColor',vec4.new(.1,.4,.4,wateralpha))

PixelShader: 2.0
lakeRipple.sha   Mainly same with lake.sha, but also use a ripple map to plus the distort result.

Factor:

( ... same with lake.sha here )

number
ripple_texture -- the ripple texture essentially is a height map

vec4 
vecUVRipple -- uvRipple = uvBump* vecUVRipple.xy + vecUVRipple.zw
number fRippleStrength


Usage:
material.setTexture(4, ripple_texture)

-- sample codes for using ripple map

local uvposition=g_ripple_position;
local fuvscale=g_ripple_uvscale
local uvofs=-uvposition*ocean.getUVScale()/10000;
uvofs=uvofs*fuvscale
local vUV=vec4.new(fuvscale,fuvscale,uvofs.x+0.5,-uvofs.z+0.5)
lake.setEffectVector('vecUVRipple',vUV)
lake.setEffectFloat('fRippleStrength', (g_ripple_uvscale-0.5)*0.1)

--- grow ripple ---
g_ripple_uvscale=g_ripple_uvscale*( 1 - AppTimeD*2 )


PixelShader: 2.0

(Remark: if use  the lake.sha or lakeRipple.sha, you needs use Back Buffer Aligned render target for reflected / refractive / depth map, and do not check RTT's 'Consistent with back buffer' style.)

Workflow:

1. Create a surface as water

2. Create a portal on the surface

3. Add two render targets
Right-Click in the Texture Browse Window, select "
Add Render Target" from the context menu. Then select a image file in Open File Dialog. Please ensure the image width is same as height (square image). Do same for another render target.

4. Select render targets
Select the portal, in the Render To Texture rollout of portal panel, select one render target; and check '
Consistent with back buffer' style. Click the 'Actions' button, add two actions:

Message Function Object
Render Texture Begin Hide water surface
Render Texture End Show water surface

In the Render To Texture (Mirror) rollout, select another render target, and do same as above.

5. Add bump texture
Right-Click in the Texture Browse Window, select 'Add Bump Texture' from the context menu. Then select "textures\wave_height.png" in Open File Dialog.

6. Create material
In the Material panel, new a material; set 1st texture to the bump texture; set 2nd texture to the render target in RTT(Mirror); set 3rd texture to the render target in RTT; load shader file "
effects\water\bump_nops.sha".

6. Assign the material to water surface
Please ensure no texture assign to water surface. You can use UV Tool to adjust water surface's texture coordinates for changing wave size.

( if use bump_norefra_nops.sha, no need the 3rd texture; and only need set RTT(Mirror) in the portal. )

Tip: set  Clip Offset for RTT of portal to avoid seams near bank.