This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Adding Water

Learn how to create ocean with waves that looks and feels amazingly realistic. In shallow waters along the shore, we are going to create dynamic caustics and foam. But that is not even the half of it. Water in your project will also have reflections on its surface, refraction for submerged object, underwater fog effect, subsurface scattering for additional play of colors — you name it and try it out!

Step 1. Add Water

Due to its reflectance properties, the water is usually set up after or parallel to the light scattering.

  1. On the editor panel, click Add an object button, and then Water in the rollout.

  2. Choose Water for an infinite ocean. Click Ok.

    Here's water that is colorless with default settings. Only light scattering attenuates it at horizon with a blue tint.

  3. Press N to open Nodes settings and rename the node, if necessary.

Step 2. Assign Water Material

Create the custom water material so it can be tweaked.

  1. Press M to open Material settings. For further steps, there should be present a custom library associated with the world (see how to add material library).
  2. Select water_base in the list of materials and click inherit the material.

  3. Choose material library where to save a new material and specify its name.

  4. While we're in Material settings, go to States tab and check Dynamical reflection so that reflection is not baked into a static map, but generated in run-time.
  5. After creating the material, it need to be assigned to our object water. Press N to go the Nodes settings -> Surfaces tab.
    Holding SHIFT or CTRL, select surface and volume surfaces and load new material for them.

  6. Select the created water material in the list:

    The sky and palms start to be reflected by the water surface:

Step 3. Set Environment Lighting

Environment lighting contributes a very important part into the resulting water color, so it should be set prior to actually adjusting the water. Otherwise, without environment light, the water mass will appear black with colored specular highlights.

  1. The environment texture is tiny in size, so it is reasonable to disable all small and unessential objects before grabbing it.

    In our case, that will be the palms.

  2. Choose the camera position somewhere in the middle, so that main components of the scene (the sky, water and ground) are visible. We will choose the position above the island:

  3. Press T to go to Tools settings -> Grabber. In the Mode rollout, select Cube and press the Grab button.
  4. Save the environment texture in .dds format:

  5. Enable all the disabled nodes.
  6. Press R to go to Render settings and load Environment texture.

  7. Select path to the texture.

    The water became brighter - too bright, in fact. HDR reacted to the added environment ambient lighting, darkening the sky:

  8. Slightly decrease the environment light Exposure down to 0.75.

    That will be the base for tweaking water colors:

  9. Even with decreased exposure, some objects appear too bright. For example, the sand became too bluish and dark sunset shadows has lost their intensity.

    Environmental exposure can be additionally tweaked for each material:
    Go to Materials settings -> Parameters tab -> Ambient options -> Environment and decrease it down to 0.1. In the result, we get such a view:

Step 4. Tune Water Color and Reflectivity

Now we can get down to tuning our water material.

  1. Go to Parameters tab -> Shading and set Glossiness to 180 to decrease the highlighted areas on the water surface.

    The highlighting has narrowed to the sun path and we can get a better view of the colors to tweak.

  2. Scroll up and click on the Surface Color field.

  3. Select black color so that the water surface will be transparent. Other colors can be used if creating muddy water or dense liquids like milk or oil.

  4. Click on the Volume Color field to determine the basic underwater color.

  5. Select dark blue, as water color darkens by the sunset.

  6. Go to States tab and enable Subsurface option to allow additional subsurface scattering layer.

    Subsurface color, which is white is by default, is added to volume color

    Move down under the water surface to see it clearly:

  7. Return to Parameters tab and find subsurface parameters appeared. Click on the Subsurface Color field.

  8. Select green color. In combination with blue it will bring nice turquoise tinge.

    The water surface looks like that:

  9. Focus on the shore line. We see that the water looks too shallow:

    Increase Volume Density up to 0.2:

    It will redistribute the volume layer closer to the shore:

  10. Increase the Volume Power up to 1.5:

    It will concentrate the volume spread line, giving the effect of deeper waters:

  11. Tweak subsurface parameters as well:
    • Set Subsurface Density to 0.15, so that subscattering layer is bigger and hence spread closer to the shore.
    • Set Subsurface Power to 1.5, so that the subscattering color will grow intense and prominent faster. It should approximate to the volume power for the balance.

    Now the subscattering color finely compensates the volume color:

  12. Let's move the subsurface layer a bit further from the shore. Set Subsurface Falloff to 0.25:

  13. The Surface which is responsible for reflections also has a spread line. Set Surface Density to 0.25, so that reflections on the water appear closer the shore.

  14. After all manipulations, let's return to shading and adjust the Fresnel effect: increase Fresnel power up to 7.

    After that, the water will appear a little bit less reflective and bottom-exposing when looking from above, than if compared to water near horizon:

  15. The water is still overly reflective. To compensate for that, set Fresnel bias to 0.05.

    With that, we set the minimum level for reflections, so that there are fewer of them.

  16. Increase the Specular component up to 1.2 for brighter and broader sun path.

  17. Now tune reflections from the water surface. Click on the Near Color field in the Reflections group. This option changes the reflection color close to the camera.
  18. Select light gray to ensure that reflections won't be brighter than environment colors.
  19. Click on the Far Color field. This option allows to set reflections in the distance, far from the camera. Choose light gray as well. The highlights became less prominent:

  20. Reflections are almost done with, except that palms above the water are basically mirrored in water which is no good.
    To blur the reflection of objects, go to States tab and set Reflection Filter to One pass.

    Palm reflection becomes vague and hazy:

  21. At last, setup refraction for underwater objects and surfaces. By default, refraction is not intense enough:

    Return to Parameters tab and increase Refraction Scale up to 2 for more distortion.

    The bottom and underwater objects are now rippled with the current:

Step 5. Tune Waves

There are two types of waves: rippling according to normal maps (present by default) and big geometrical waves. We'll tune them in the mentioned order.

  1. First of all, go to Textures tab and load normal maps (Normal 01 and Normal 23) that create two layers of waves.
    We will use a default texture.

  2. Now we'll tune the rippling animation starting with the 1st layer of waves. It is created by the texture Normal 01 being transformed twice, using set expressions: As a result, two Normal 01 textures that were transformed differently, are summed and appear on the screen as the 1st wave layer.

    To see it clearly, let's disable the second layer:
    Go to Parameters tab and inset vec4(0.0,0.0,0.0,0.0) in the Normal 2 and Normal 3 fields:

    Here's what the first layer of waves looks like. The idea is to make the texture go in two circles that differ basically only with rotation direction and thus compensate each other. (See information on circular motion transformation.)

  3. The movement is fine, however, the water is not rippled enough. Double click on the Normal 1 field to edit transformation expression.

  4. The texture coordinate transformation window opens. Here, increase Scale X and Scale Y to 0.02 to add detail.

  5. Enable the 2nd layer of waves again by clicking Set to parent button for the following fields: Similar to the 1st layer, these transform the Normal 23 texture according to set expressions and create the 2nd layer of rippling waves.

    Two layers together:

  6. Double click on the Normal 2 field to edit it.

  7. Increase the Scale X and Scale Y up to 0.04 to add still more ripples.

  8. Double click on the Normal 3 field to edit it.

  9. Increase the Scale X and Scale Y up to 0.06.

    The resulting rippling looks like that:

  10. Now we can add bigger geometrical waves that look like being wind generated.
    Press N to go to Nodes tab -> Water. Here up to four waves can be set. Let's adjust the parameters of the first wave that will be the biggest:
    • Set Amplitude to 0.27 to define the wave height.
    • Set Speed to 0.25 to define the speed with which the wave will move.
    • Set Length to 11 to define the distance between waves following each other in the same direction.

  11. Add the second wave:
    • Set Amplitude to 0.2 to make the wave a little lower.
    • Set Speed to 0.3 so it would move faster.
    • Set Length to 9 so that wave follow each other more frequently.
    • Set Direction to 45 to make it move at an angle of 45 degrees relative to the first wave.

  12. Add the third wave that will be even smaller and faster.
    • Set Amplitude to 0.16.
    • Set Speed to 0.35.
    • Set Length to 7.
    • Set Direction to -60 so that the waves will follow at an angle of 60 degrees counting clockwise. Its direction balances the direction of the fist two waves.

  13. Add the fourth wave, the smallest, the fastest, as well as most recurring. As a result, crests of the waves form plausible pattern on the water surface:

  14. With the added waves the area closer to horizon looks somehow stirred and creased.
    To correct that, go back to Materials settings -> Parameters tab -> Animation parameters. Set Wave radius to 60 units, so that the waves will not spread so far.

    Now the waves fade closer and thus more smoothly:

Step 6. Add Caustics

Let's add caustics to the bottom of the sea that will be seen in the shallow waters near the shore.

  1. Go to States tab and enable Caustics effect.

    That's what we've got by default:

  2. Go to Parameters tab, where options to tweak caustics will appear. There are two expressions that transform caustics animation: Click on Caustic 0 field to edit it.

  3. Change Scale X and Scale Y to 0.02 so that caustics pattern becomes denser and finer.

  4. Click on Caustic 1 field to edit the second animation transformation.

  5. Increase Scale X and Scale Y up to 0.035 for caustics pattern to become even more detailed.

  6. Scroll down for Caustics parameters and click on the Color field.

  7. We'll choose aqua green to match with seashore color.

  8. Caustics pattern is too thin and not clear enough. Decrease Threshold down to 0.35 so it will be more revealed.

  9. Let's make the caustics spread line softer and move it away from the shore: for that, set Density to 0.34.

  10. To limit the spread of caustics in the deep waters, increase Falloff up to 3.5.

  11. The caustics became barely seen. Set Multiplier to 3 to increase its brightness.

    Here's how the result looks like:

Step 7. Add Foam

Let's add one more effect to the water: foam that is is generated near the shore where the waves break.

  1. Go to States tab and enable Foam effect.

    The foam will appear (though hardly visible):

  2. Go to Textures tab and load foam texture if necessary.
    We will use a default texture.

  3. Go back to Parameters tab, where options to tweak foam show up. Decrease Falloff down to 0.3 and the foam will spread wider from the shore.

  4. Increasing Threshold to 1.1 allows to sightly move the foam back from the shore and soften the breaking waves line.

  5. Set Multiplier to 2, which will make the foam brighter and more distinct.

  6. Now let's animate the foam properly. Scroll up to Transform parameters. Foam texture is transformed twice using set expressions: As a result, two foam textures that were transformed differently are summed and appear on the screen.

    Click on the Foam 0 field to edit the first transformation:

  7. The texture coordinate transformation window opens. Here, increase Scale X and Scale Y to 0.11 so that the foam looks finer.

  8. Click on the Foam 1 field to edit the second transformation:

  9. Set Scale X and Scale Y to 0.2 for more sprayed look.

    And here comes the final result:

Last update: 2017-07-03
Build: ()