In this tutorial, we will create our own custom ocean material and apply it to a level. As the ocean is commonly used in games as an interactive game play element, we will also cover the underwater fog settings to make underwater game play enjoyable for our player.
Getting ready
The Live_Create_Small level should be open in the Editor. Your Time Of Day dialog should be open in the editor and set to a time of 0630. You should also set it to a very high specification to observe the advanced tessellation features.
How to do it...
Let's create a new photo realistic ocean for the level:
First, to see the currently applied ocean material, open the Environment tab in the RollupBar.
Under the Ocean parameter you will see four parameters.
First, let's apply our own material.
Click on the browse button in the Ocean material parameter. This will open the currently applied material.
Create a new material and name it my_ocean.mtl and save it under your root directory /materials/ocean/.
Next, click apply in the Ocean material parameter in the RollupBar. You will notice that there is no water yet. This is because the Ocean requires a specialized shader to render.
To set the shader you must edit your newly created material my_ocean.mtl, set the shader parameter in this material to water.
Now that we have some basic water, we should apply a bump map to create the small ripples and waves on the water's surface. This will allow some refraction to occur, enhancing the overall effect.
For now use the texture located in textures/defaults/oceanwaves_ddn.dds.
To finalize the material ensure that the Sunshine tickbox is active in the Shader Generation Parameters.
Note
Experiment with different shader settings for more stylized and extreme types of water.
Now, let's adjust the Ocean settings available to us in the Time of Day dialog.
Then locate the advanced parameters. Adjust the Ocean Fog Color to a pleasant blue for this particular scene 107, 217, 241 RGB.
Note
The Ocean Fog Color is the overall color setting for the ocean; you can set this to dark blue for deeper water and even green for polluted water.
It is easy to observe the changes of the fog color multiplier and fog density and its overall effect on visibility by moving your perspective view underwater.
After you have moved your camera to an appropriate view, adjust the fog color multiplier and fog density to 0.1 and 0.02 respectively. This setting gives a decent color on the surface of the water as well as a good view distance underwater.
Our final changes will be to the level's environmental affection on the ocean material, which we applied earlier.
Under the Environment tab in the RollupBar, locate the Ocean Animation parameters:
We should first adjust the direction of the virtual wind being applied to our water. To do this, first set the WindSpeed to 8 so as to be able to clearly see in which direction the wind is animating the water.
Next, set the wind direction to a desired value, in this case set it to 4.
Bring the wind speed back to a realistic value around 3.
Finally, we will adjust the size of the waves.
Extreme settings will cause malformations in the waves, so observe these changes closely.
For our purposes, a slightly higher than normal wave height can be achieved by setting Waves Size to 0.5 and by setting the Waves Amount to 1.
Note
If you want to achieve choppier water conditions, then simply increase the waves amount.
How it works...
The environmental parameters of the water and its corresponding time of day parameters are saved within the level.
Using latest graphic card shader programmability, CryENGINE does not suffer from Z buffer intersection with the terrain, but rather gets nice beach foam and underwater fog.
There's more...
You may want to know how the Caustics rendering works or how to animate the water parameters. You might also want to know about the technology used in the CryENGINE for water free from transformation rendering.
Animating water parameters
The time of day parameters for the Ocean can be animated just like any other value in the time of day.
Caustics
Caustics are used by default in CryENGINE 3. Caustics are rendered as material layer, so all objects below water can be affected in and changed in real time.
Very important for realistic water look
Extra rendering pass, can handle opaque/transparent, can be done in a deferred way, but we lack some data such as per pixel normals to give an interesting look
Based on real sun direction projection
Procedural composed using three layers
Chromatic dispersion used
Darken slightly to simulate a wet surface
Stencil pre-pass helps a little bit on performance
Free form transformation FFT water
CryENGINE 3 animates the water through an FFT algorithm on the CPU. There is a unique advantage to this as we get even physics interation, entities, or objects floating on the waves reacting when you jump on them and this works very naturally.
Used statistical Tessendorf animation model
Good tillable results for variety of usage: calm, choppy, and so on
Computed on CPU for a 64x64 grid, Pirates of the Caribbean 3 used 2k x 2k
Upload results into a texture volume
Vertex displacement on GPU
Note
Lower HW specs uses simple sin waves sum.
Additionally, normals maps translation four normal maps layers