Implementing a Water Shader for 2D games
The Glass Shader that we introduced in the previous recipe is static; its distortion never changes. It takes just a few changes to convert it into an animated material, making it perfect for 2D games that feature water. This uses a similar technique to the one shown in Chapter 7, Vertex Functions, in the Animating Vertices in a Surface Shader recipe:
Getting ready
This recipe is based on the Vertex and Fragment Shaders described in the Using grab passes to draw behind objects recipe, as it will rely heavily on GrabPass
. Let's get started:
- Create a new Vertex and Fragment Shader. You can start by copying the one used in the previous recipe, Using grab passes to draw behind objects, as a base (
GrabShader
) by selecting it and hitting Ctrl + D to duplicate it. Once duplicated, change its name to2DWaterShader
. - Create a material that will use the...