Implementing a Water Shader for 2D games
The Glass Shader introduced in the previous recipe is static; its distortion never changes. It takes just a few changes to convert it to an animated material, making it perfect for 2D games that feature water. This uses a similar technique to the one shown in Chapter 6, Vertex Functions, in the recipe entitled Animating Vertices in a Surface Shader:

Getting ready
This recipe is based on the Vertex and Fragment Shaders described in the Using the grab pass to draw behind objects recipe, as it will rely heavily on GrabPass
.
- Create a new Vertex and Fragment Shader. You can start by copying the one used in the previous recipe, Using the grab pass to draw behind objects, as a base by selecting it and hitting Ctrl+D to duplicate it. Once duplicated, change its name to
WaterShader
. - Create a material that will use the shader (
WaterMat
).
- Assign the material to a flat geometry that will represent your 2D water. In order for this effect to work, you should have something...