This page looks best with JavaScript enabled

Exploring a Trochoidal Wave Shader

 ·   ·  ☕ 1 min read

Let’s try to craft some trochoidal waves - a type of fluid simulation that is both fairly simple and also looks pretty good for creating basic waves in an ocean or other fluid. Trochoidal waves are simulated by moving vertices in a circular motion that causes vertices to condense and expand from one another. This can create the swells and dips that you’d expect from an ocean.

We’ll be implementing this using a vertex shader that can manipulate the position of a meshes vertices based on distance.

The vertex shader that creates this effect for us looks like this (this effect is based on changes along the x axis in world space only, some modifications are required if we want this to work along different axis):

void vert (inout appdata_full v) {
    float3 worldSpace = mul(unity_ObjectToWorld, v.vertex);
    float3 rotatedOffset = float3(0,0,0);
    rotatedOffset.x = sin(_Time.x * _DeltaSpeed + worldSpace.x * _Offset) * _Radius;
    rotatedOffset.y = cos(_Time.x * _DeltaSpeed + worldSpace.x * _Offset) * _Radius; += mul(unity_WorldToObject, rotatedOffset);

Freya’s tweet on Trochoidal Wave’s with examples:
Her twitch stream:

Some more background on Trochoidal Wave’s:

More information on writing Surface Shaders in Unity can be found in the Unity manual:

Join the World of Zero Discord Server:

Sam Wronski
Sam Wronski
Maker of things, currently helping build cloud things @ Google. World of Zero is a personal project disconnected from my professional work. Lets make something awesome together!