This is a direct port of danielshervheim/unity-stylized-water from Unity to Defold, but I have made some additions, such as basic LOD for sparkles and foam, and added textured edge foam.
Even though this is a port, not all functions are the same. Unity has some built-in helper functions for shaders, which I tried to replicate as closely as possible, but the end result may still differ. The Unity version also includes shadows, while the Defold version does not. I left shadows and horizon blending to the user, since every game may require a different approach.
This is mostly suited for desktop games. It may suffer on mobile browsers, especially on budget phones. It might work on native mobile builds, but unfortunately I am not able to test it on a device, since I have a problematic phone with a Mali-G52 GPU, and it crashes as soon as I set flags = render.TEXTURE_BIT. for depth buffer. This is probably due to a driver issue, so I am not entirely sure
. You may try turning sparkles, reflections, and similar features on or off. Most importantly, I am not a shader expert, I am still learning, so please keep that in mind as well.
Reflections and refractions are not perfect. Reflections are not screen-space, they are only for cubemaps. Refractions are based on screen-space, but pushing them too far may cause artifacts, which is a generic problem.
This repo contains a few different kinds of caustics, foam, and wave textures and normals. Of course, you can also use your own or other textures. I highly recommend experimenting with different textures.
Test it
Day: defold-stylized-water-shader 1.0
Sunset: defold-stylized-water-shader 1.0
Also, I am working on a fake floating simulation ( this sounds like a big claim
). It is just a simple wave sampling, and it works well so far. I think I will be able to share it next week.
It should be tested using duck ![]()
