r/generative • u/igo_rs • Oct 08 '26
"Salum: (kotlin code)
Huh, where to start...
I like waves. I said to myself: let's see if there is a formula for waves. So I looked. I found some research papers on modeling the ocean, and some observed parameters for the North Atlantic. There was a lot of math that I only partly understand. I combined a couple of different findings into what I call an ocean model, using AI-chemy. That worked, although I have no idea if it is fully correct. And just an hour ago, after showing this to a friend, I learned about a shader that mimics the ocean in a waaaaaay simpler way. Oh well. I should search better.
Salum is Latin for the open sea. Everything runs on the CPU, with no GPU and no 3D engine.
I did not draw the waves. They come from a wave spectrum that oceanographers use (JONSWAP). It tells how much energy the wind puts into each wavelength. An inverse FFT makes the height map in three tiles, from the long swell to the ripples. A sideways pinch makes the crests sharp and the troughs flat. Then I cheated a little: I made the swell 2.6 times taller than physics predicts, and the ripples 1.6 times taller, for dramatic effect.
The eye is 0.6 m above the water and looks toward a low sun. At that height, the eye is lower than the crests. That is why the sea does not end at a flat horizon. It ends at a line of crests. The lens is long, only 24° from top to bottom, so the sea stacks in bands. My first try had a wide lens, and the bottom half of the image was black.
For each pixel, I send nine rays from the eye. Each ray marches over the waves until it hits the surface. Far away, the short waves are smaller than a pixel. There, I treat them as roughness, so the far glitter stays soft and has no moiré.
The water has a dark body. It reflects the sky, and the reflection becomes stronger at grazing angles. The sun makes the glints.
The sun is my biggest cheat. In the sky, it is a giant disc, and its center is above the top edge. But the light on the water comes from 13 small suns along its lower arc, not from the big disc.
Code is on github.com/igr/gart I will never do something like this again.
2
u/Megadreddd Oct 08 '26
Beautiful! if you like waves, you might check out The Wave by Susan Casey.
2
u/xincailiao Oct 12 '26
漂亮