7. Underwater Shader - LariWa/BoidSimulation GitHub Wiki
To make our Underwater world more realistic, we decided to add an Underwater Shader. Additionally, we wanted to learn how to program Shaders in Unity. We first tried to do it on our own, but as we had no previous experience with shader programming, we decided to use a Tutorial from Peer Play [1] as a guideline.
To create a hilly underwater world, we created a Tesselation Shader. The vertices are offset by a noise in y-direction, which creates the hills. To create the Simplex Noise for the Shader, we used a provided Unity Package by Peer Play. Additionally, the normals are recalculated, so that they don't all face upwards, but match the created terrein. The result can be seen in Figure 1. Later on, we decided to use a terrain with a height-map instead of the Plane with the Ground Noise Shader. This has the advantage, that we can paint objects such as plants onto the ground, and have a collider matching the mesh of the terrain, which allows the Boids to move between the hills.
Figure 1 - Noise Ground Shader Results
To get the effect of moving water, we added a Post Processing Image Effect. An Image Effect Shader manipulates the position of the pixels. We switch the position in the direction of the generated noise. Using the internal time of the shader, we can create an animated effect. See the animation below for the result.
Figure 2 - Underwater Effect
Next, we created a Depth Effect. For that, we used the Camera Depth Buffer. Depending on the Depth, more or less fog is added. See Figure 3 for the Result.
Figure 3 - Fog Effect
[1] Peer Play, Underwater World Shaders Tutorial, (Jun. 22, 2018). Accessed: May 17, 2022. [Online Video]. Accessed: May 17, 2022. [Online Video]. Available: https://www.youtube.com/playlist?list=PL3POsQzaCw51Cvlnery3cIabH-YqQtMpa