Animated Water Shader

Due to popular request, I’m posting the source code of my Unity3D Animated Water Shader. It is a complete rewrite of Alzahiel/GraphicRunner’s shader. Brief list of changes:
– It’s a surface shader (not Vertex+Fragment)
– Doesn’t require script file, all animation is done in the shader using built-in _Time variable
– Supports transparency
– Support specular lighting
– Supports reflection map
– Configurable cycle length and water flow speed

By changing normal maps tiling, main color, reflection color, specular color, flow speeds and cycle lengths a variety of effects is possible:

I’m also attaching the flow map and noise map from GraphicsRunner’s demo and water bump map and Sunny sky cube from Unity Standard Assets so that you have something to start playing with. I’m using the same normal map twice but the effect should be even cooler with two different normal maps. Enjoy!

Remember, that for flow map creation you can use FlowEd.

SOURCE CODE (Simplified BSD): AnimatedWaterShader.zip

26 Comments

  • Hi there,

    Is there a way to add reflections to the shader like the normal pro daylight water ?

    (i have unity pro)

    Thanks!

      • Unfortunately I don’t have Pro 😉 It should be possible with very little modification, but I think you will also need the script from Unity water which dynamically renders the reflection texture.

        • Do i need to make a script that dynamically updates the _Cube variable in the shader ?

          Because at shaders i’m a total noob 🙂

          But i’m good at C# and core programming

          • Well it isn’t working i added (tried to) some sort of reflection from the mirrorreflection shader and when i play the water plane just flikkers to white or to black color ??
            Any ideas

          • If you are rendering a cube map then yes, you should be updating whatever texture _Cube in the animated water shader is pointing to and it should work without any modifications. Note that the reflection might be severely distorted due to surface bumpiness, for testing purposes set bump map to the neutral color (.5,.5,1.0 – I believe) or maybe remove it (then Unity might use the neutral values automatically) – that way you should see a uniform reflection and you can sort out the bugs with rendering your cube map.

  • About being distorted you have absolutely right 🙂

    But it is working now there is a reflection on the water plane only now i need to adjust the script so it renders it better (resolution)

    Many thanks for the help !

        • Could be tricky because animated water already uses so many textures, but if you can spare another texture unit just add foam texture (you can resign on one of the normal maps and use the same one twice instead), animate it exactly the same way I animate normal maps and lerp between water and foam color depending on the speed. Or just give me a really nice-looking tile-able foam texture and I can try to do this for you 😉

          • I’ve put it as a new post. If you could prepare a video of the attached demo scene for me, I would be grateful – because of several weird things going on, I have no way of doing that 😉

  • Hello,

    I first want to say that I am an internet hermit and typically never comment or reply to anything.

    I stumbled upon this shader while trying to find a solution to the water in my game. I didn’t need hyper-realistic 3D waves and physics, but I did need a nice looking effect that supported transparency. Your shader was exactly what I was looking for.

    So, thank you for creating this. It will save me a lot of time and hopefully solve the water issues I’ve been having!

  • Hi Stanislaw

    Thank you for sharing. Great shader, exactly what we needed to add a decorative pond to our scene.

    One question. We need to simulate a paused scene. But decreasing the _Speed value to zero does not stop the water from getting animated.

    What do you suggest we modify in order to get this effect?

  • Hi this looks really cool. Could you point me to a resource to learn how to use it? I created a plane(?) and created a new material(?) and changed the shader to the one I downloaded.. at this point do I just need to add some water texture with transparency?

    I can do programming and scripting all day but when it comes to these graphics I’m totally lost lol.. I assume I need the mesh plane to attach all these things to..?

  • How do i actually import this package i don’t see how to download it onto my mac I know I am a clutz for this but i just don’t see how to get it on to my desktop


Leave a Reply

Your email address will not be published. Required fields are marked *