Mobile depth water shader
Hello, my name is Paul and I'm in unity for few years now. For the last few month I was dealing
with a lot of optimization routines on work while making mobile game. One of the problem was
about a lot of overdraw which is critical for mobile hardware. We couldn't just turn off effects and
simplify game graphics, so I needed to find a solution.
After few days of research I got it. The main problem was in transparent textures, so I decided
to refuse them and write a shader that is making pretty much the same but without transparent
texture. It makes all calculations right in the main geometry drawcalls. And it works!
That effect was a bit specific for our project and I can't put it into asset store. But I made a
mobile depth water by the same way and it works really fast.
This demo scene was tested on several devices and here are results:
- Xiaomi Mi 4i: 58-60 fps
- Samsung Galaxy S4 mini GT-I9195: 56-60 fps
- Sony Xperia Z3 Compact: 47-48 fps
- Sony XPERIA S: 28-30 fps
Work process
Ordinary water shader uses transparent texture, so if there are a lot of water on the screen,
performance is going down to hell. Another problem of usual depth shader is using depth texture,
that is rendering by camera. It's very heavy operation for mobiles.
As I said, the main idea is drawing water right in main geometry drawcalls. So while drawing it
we can get depth of each pixel without using any depth textures. Moreover we don't need
transparent texture anymore! All two problems are solved.