An old project that I dug up, got building under Visual Studio 2022 again.
Real-time animated water surface generated entirely on the GPU. The water vertex shader sums:
- 3 sine waves at different wavelengths (0.27, 0.18, 0.13) and three diversified directions, so they don't all reinforce into a clean cross-hatch
- A 4-octave FBM (fractal Brownian motion) Perlin noise layer for fine ripple detail on top of the sines
- A domain-warp pass that uses FBM to perturb the sample position itself before evaluating the waves, so wave fronts curve and meander instead of running in straight lines
Surface normals are computed via finite differences of the height function so the lighting actually reveals the ripple geometry. The fragment shader does a two-tone blue (deep navy in troughs, brighter blue on flat surfaces) with a directional sun and a tight specular highlight.
The "island" is procedural too: 96x96 grid of vertices with a Gaussian falloff for the dome shape plus three sine-based terrain bumps for variation. Per-vertex normals also come from finite differences of the height function. The fragment shader uses a height-based color ramp - sand near the waterline, grass in the mid zone, rock at the peaks.
The base of the island sits a tiny bit below the water surface so you get waves lapping over the beach edge.
Camera is a basic orbital - left click drag to rotate, mouse wheel to zoom.
Open vs-project/base_glfw/base_glfw.sln in Visual Studio 2022 and build the
Debug|x64 configuration. You need the "Desktop development with C++" workload
installed (one of the workload checkboxes in the Visual Studio Installer).
GLFW, glad, glm, and KHR headers are bundled in include/ and lib64/ so
there is no external dependency setup.
The source lives at vs-project/base_glfw/base_glfw/:
main.cpp- scene setup, water grid, island generation, render loopsh_v.glsl- water vertex shader (sines, perlin/fbm, domain warp, normals)sh_f.glsl- water fragment shaderisleVertexShader.glsl/isleFragShader.glsl- island shadersmesh.cpp- obj loader, carried over from the original (not currently used)
The double-nested base_glfw/base_glfw/ folder layout is just how Visual
Studio originally laid the project out - I haven't bothered to clean it up
since the .sln paths are relative to it.
