Search code examples
c++3dgeometrydirectx-11hlsl

Projected grid water horizon detail


I'm trying to implement an ocean scene with C++ and DirectX11. Currently I have a projected grid, Gerstner waves and a basic shading. My problem is that when I aim my camera horizontally, so I can see the water horizon, in the distance, the projected grid becomes insufficient, even at high vertex numbers. These screenshots illustrate the problem:

shaded water surface

wireframe water surface

I know the cause of the problem is in the concept of the projected grid (the grid is detailed near the camera, rough far from it), but there has to be a best practice to solve this.

Any ideas?


Solution

  • Benedikt Bitterli and joojaa answered my question here: https://computergraphics.stackexchange.com/questions/1681/projected-grid-water-horizon-detail

    I chose the laziest solution for now. I calculate an attenuation factor from the distance from the camera in the vertex shader, and I gradually flatten the waves in the distance.

    The function:

    float CalculateWaveAttenuation(float d, float dmin, float dmax)
    {
        // Quadratic curve that is 1 at dmin and 0 at dmax
        // Constant 1 for less than dmin, constant 0 for more than dmax
        if (d > dmax) return 0.f;
        else
        {
            return saturate((1.f / ((dmin-dmax)*(dmin-dmax))) * ((d-dmax) * (d-dmax)));
        }
    }
    

    Here are the results:

    shaded wireframe