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.

  • monotrox@discuss.tchncs.deOP
    link
    fedilink
    arrow-up
    2
    ·
    11 months 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).