Oscar Kempe Söderholm

Portfolio About

Ocean Shader

This project focuses on the technical aspects of creating an efficient and optimized ocean shader.

While the common aproach to simulating waves has long been using gerstner waves, I experimented with the balance of looks vs performance and ended up with a modified sin wave, sometimes called a semi-sine wave. These semi-sine waves will look very simlar to gerstner waves and are far cheaper to run, they also come with the benefit of not inverting into themselves as the input sharpness increases.

In a custom HLSL function I make use of a for loop to go through the waves with iteratively higher frequencies and lower wave heights.

By sampling the wave function three times, one a the original position, and two with an offset in x and y respectively, used to calculate normals.

I created a cheap "sub-surface" effect by taking the dot-product of the camera vector and the sun vector and then multiplying that by the height map. This results in the tips of the waves taking on a slightly brighter color when looking in the direction of the sun. It's a small tweak that really helps define the outline of the waves and add more visual variety.

The ship controlled by the player has a particle system attached to it that is only visible to a screen capture component also attached to the player. This results in a a trail being created wherever the player goes. I then sample this texture based on a playerposition that is set in the actor blueprint to create a mask for where to place a foam texture and thereby creating the foam trail behind the player.

Base color and world normal render passes.

If I had more time

The main thing I'd like to improve in the future about this project is adding support for shadows. Early renditions of this project actually had shadows in the water there was however an issue with how they looked at grazing angles.

When the angle between the water surface and the camera became to much an artifact in the form of a sharp cutoff into a black color appeared.

What I learned

Through my research for this project I got to explore to main aspects.

First is the math required to fake an ocean simulation. More specifically how to manipulate sine waves into different shapes and comparing them to more complex equations such as gerstner waves.

Second is how to make use of scene captures and runtime textures. And more importantly the possibilities for effects this opens up.