WIP dynamic water waves

This is a little side project I got hung up lately, it’s another of my feeble attempts at making better water.

The goal is to create a water surface (height map and/or normal) that reacts to objects on it, but I also wanted an ability to draw a line on an image and say “this is my shoreline, you shader, draw me some wave here”.

I’m not sure how sane my idea is but the concept is such:

  1. Create a (buffer?) texture with points/lines that will be the origins of waves
  2. Feed the texture from #1 to a shader that will expand each point to a ring and fade it out over time (this works by using a ping-pong buffer running a kind of cellular automaton shader)
  3. Use the texture from #2 to make a normal map each frame

The code so far looks thus:
github.com/wezu/p3d_wave
The map it generates looks something like this:

At the moment it simulates a rain like effect, by moving some points around in the #1 buffer, but as you can see on the screen, it has a flaw - rings that intersect don’t get added like waves should, but cancel each other out :confused:

If anyone know how to improve my shader or has a better idea how to make an effect like that (possibly without going into the math of sombrero functions) then I’d much welcome the help.

1 Like

I think I have to give up on making a “static shoreline map”, but for rain effects and other things disturbing the water surface it works fine.

The shaders make a normal map like this:

It looks better live (do try, the previous link is still valid, code updated), and this time a wake/wave is drawn based on the mouse movement.

I’ve updated the code with a full water demo, it looks like this:

But a static screen doesn’t show much, you just have to run the demo1.py from:
github.com/wezu/p3d_wave

This is really cool! :slight_smile: Very convincing effect.

The full water demo looks cool, Wezu. Can I use your code for my project?

Yes, sure, use it any way you want to. Credit me if you want to, but you don’t have to. The code is public domain.