How Games Fake Water: The Sine Wave Trick Behind Realistic Oceans




Water in video games looks effortless. Waves roll, light shimmers, and the surface ripples as if a physics engine were tracking every droplet. In reality, almost none of that is simulated. Most game water is a clever illusion built on math you probably met in 8th grade: the sine wave.

In this post, we'll break down why real water simulation is out of reach for games, how stacking simple sine waves creates convincing waves, and how you can build a basic version in Unity.

Why Real Water Simulation Doesn't Work in Games

Simulating water accurately means tracking millions of tiny particles and the forces between them, such as pressure, viscosity, gravity and surface tension. This is called fluid simulation, and it is extremely expensive to compute.

It works for a glass of water, a splash, or a short film shot rendered offline over hours. It does not work for an open-world ocean that has to run at 60 frames per second on a console or a phone. A game has milliseconds per frame, not hours.

So game developers do what they do best: they fake it. The goal is not to simulate water, but to make the player believe it is water.

The Secret Ingredient: The Sine Wave

A sine wave is the smooth, repeating curve you see in school math. It has three properties that matter for water:

  • Amplitude: how tall the wave is.
  • Frequency: how many waves fit in a given distance (how close together the peaks are).
  • Speed (phase): how fast the wave travels over time.

On its own, a single sine wave looks nothing like water. It is too smooth and too perfect, like a rolling hill repeating forever.

Stacking Waves: Where the Magic Happens

Real ocean surfaces are messy because many waves overlap at once: big slow swells, medium waves, and tiny ripples, all travelling in slightly different directions.

We can imitate this by adding multiple sine waves together, each with a different frequency, amplitude and direction. The combined result, called the resultant wave, stops looking mechanical and starts looking natural.

The formula is simple:


   
    height(x, z, t) = sum of  A_i * sin( dot(D_i, (x, z)) * F_i + t * S_i )
   

Where A is amplitude, F is frequency, S is speed, and D is the wave's direction. Three to
eight waves are often enough for a believable surface.

Building It in Unity

Here is the basic recipe:

  1. Create a subdivided plane (a flat mesh with many vertices).
  2. Move each vertex up and down using the sum of several sine waves.
  3. Add two water textures that scroll in different directions.
  4. Add transparency, color and lighting effects.

A simple script that displaces the mesh looks like this:

   
    using UnityEngine;

    [System.Serializable]
    public struct Wave
    {
        public float amplitude;
        public float frequency;
        public float speed;
        public Vector2 direction;
    }

    public class WaterWaves : MonoBehaviour
    {
        public Wave[] waves;

        Mesh mesh;
        Vector3[] baseVerts, verts;

        void Start()
        {
            mesh = GetComponent<MeshFilter>().mesh;
            baseVerts = mesh.vertices;
            verts = new Vector3[baseVerts.Length];
        }

        void Update()
        {
            for (int i = 0; i < baseVerts.Length; i++)
            {
                Vector3 v = baseVerts[i];
                float height = 0f;

                foreach (var w in waves)
                {
                    float phase = Vector2.Dot(w.direction.normalized,
                    new Vector2(v.x, v.z)) * w.frequency
                                + Time.time * w.speed;
                    height += Mathf.Sin(phase) * w.amplitude;
                }

                v.y = height;
                verts[i] = v;
            }

            mesh.vertices = verts;
            mesh.RecalculateNormals();
        }
    }
   

A note for production: this runs on the CPU, which is fine for learning. In a real game,
you would do the same math in a vertex shader (Shader Graph or HLSL) so the GPU handles
thousands of vertices in parallel.

Adding Scrolling Textures for Surface Detail

Wave geometry gives you the big shapes, but it cannot afford enough vertices for fine ripples.
That is where textures come in.

Apply two water normal-map textures to the surface and scroll them in two different directions
at different speeds. Because the two layers keep sliding past each other, their patterns never
line up exactly, and the surface feels alive. The moving textures sit on top of the displaced
mesh, and together they create the look of flowing water.

Making It Look Like Water

Once the motion works, the final polish comes from effects:

  • Transparency: water is see-through, so blend the surface with whatever is beneath it.
  • Color and depth: shallow areas look lighter, deeper areas look darker and bluer.
  • Specular highlights and reflections: the sparkle of light on the surface sells the
    illusion.
  • Foam: white edges where waves meet the shore or objects.

After these touches, you have game water: a plane driven by a few sine waves with textures
and shading on top.

What About Underwater?

Everything above only covers the surface. What happens when the camera dips below it? That
needs its own tricks, such as fog, color tinting, caustics (the dancing light patterns on the
seabed) and screen distortion. That is a topic for a follow-up post.

Key Takeaways

  • Real-time, large-scale fluid simulation is too expensive for games, so developers fake
    water.
  • A single sine wave looks artificial, but several sine waves with different frequencies,
    amplitudes and directions look natural.
  • Scrolling two textures in different directions adds fine detail cheaply.
  • Transparency, color, lighting and foam turn the math into believable water.
  • For production, move the wave math to the GPU with a vertex shader.

FAQ

Do games ever use real water simulation? Sometimes, in small, limited areas like a splash or a
river section, and often with pre-computed or heavily simplified methods. Open oceans almost
always use wave-based tricks.

What is a more advanced version of this technique? Gerstner waves. They also move vertices
horizontally, which gives sharper peaks and rounder troughs than a plain sine wave.

How many sine waves should I use? Start with three to eight. More waves add realism but also
cost performance.

Can I do this in Unreal Engine or Godot? Yes. The idea is engine-independent: sum several
sine waves in a vertex shader and layer scrolling normal maps on top.



Comments

Popular posts from this blog

Bootstrap 6: New Features, Major Changes, and What Developers Need to Know

Why Reflections Disappear in Games When You Tilt the Camera

How Games Fake Underwater Worlds: Fog, Color Absorption and Caustics