14
I created a water shader (files.catbox.moe)

So for fun I made a water shader. The waves are done using sum-of-sines (or rather sum of sin^8), im using the depth texture for opacity based on water depth and the screen texture to fake refraction.

The cool thing about sum of sines is that the waves are very configurable, you can also create flatter water or less detailed waves by just changing the shader properties, or even create a water stream with a single flow direction.

top 4 comments
sorted by: hot top controversial new old
[-] GhostOfElectricity@lemmy.zip 2 points 1 year ago* (last edited 1 year ago)

Huh. My browser says the file is corrupt and can't play the video.

Edit: it works in chrome but not mull or firefox on android.

[-] monotrox@discuss.tchncs.de 1 points 1 year ago

I'll maybe have to think about downscaling videos the next time, because it also took a very long time to load for me, maybe it just failed because the download was somehow interrupted?

[-] Faresh@lemmy.ml 1 points 1 year ago* (last edited 1 year ago)

Awesome! It looks great and must have quite a bit of work to implement (or so I imagine, as someone whose most complex shader has been a shader mimicking drug-induced vision distortion). I'm actually intending to use such a water shader in one of my games. Just that this one won't be based on making the sum of a series of sine waves, because what I'm doing is a simulator, so I'm aiming for a realistic non-stylized look. To make realistic waves, one needs a lot of of sine waves, and simply summing them won't scale well. One way to optimize it would be to use an inverse fast Fourier transform (FFT). I'm unfortunately not smart enough to understand the math behind it, so I tried looking at shaders other people already wrote and the only one I found that seemed to do what I needed was this one: https://github.com/tessarakkt/godot4-oceanfft

Unfortunately I wasn't able to run that oceanfft shader, because every time I try I get this bug: https://github.com/godotengine/godot/issues/71929 So for now, I will have to wait until it gets fixed (which will probably take a really long time since it seems to be a really hard problem to reproduce and diagnose). :)

[-] monotrox@discuss.tchncs.de 2 points 1 year ago

I implemented this shader in only like 2 evenings, but I also mostly knew the techniques required for this and with a physics major the maths behind it came somewhat naturally to me :) The fact that everything can be done with just the one shader file also made it a lot easier, because I did not have to deal with creating external textures or compute shaders or anything.

Im also just using a simple quad mesh at the moment, and you can kind of see that the waves are a little short on vertices, so adding a LOD system would probably first be necessary to create more realistic waves. Otherwise, if you play with the parameters and maybe change the function from a sin to something that looks more like an ocean wave, you could probably achieve fairly realistic water with just sum of sine (altough someone will have to calculate the derivative for that new function, or you could think about using a 1d texture and calculating the slope from that).

this post was submitted on 22 Aug 2023
14 points (100.0% liked)

Godot

5840 readers
80 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 1 year ago
MODERATORS