Simple water shader written in HLSL. This shader is composed of 4 main layers.
- A simple depth layer meant to simulate the light’s struggle to penetrate the water. It interpolates between 2 colours by using a formula that reads the camera depth buffer, and then compares the height of submerged objects with the height of the water vertex positions.
- A foam layer using the depth information from the previous layer with a cutoff to create a border around intersecting objects. This is then animated with a noise layer.
- A refraction layer that also uses the same depth information together with an animated noise layer to offset the position of the depth sampling in the first layer.
- And finally, a wave layer. This layer uses a simple calculation of specular reflections as well as a selection of sine waves to simulate the movement of water. Note that this water shader is displayed on a quad (with no tessellation) for performance reasons, so all the movement you see is done through calculating normal vectors and modifying base colour only. No vertices are created or moved.
