Can I get this water effect in Unity(free)? Image inside.

I’m working with the new 2D tools for Unity. I have a water trigger and I am wondering if it’s possible to get the camera to display a different hue of color when looking at the water trigger. I’m thinking that I can get the position of the water surface and then display a different hue under that y.position. It seems a little tricky though so I would appreciate a push in the right direction.


Make 2 cameras, BelowWaterCam (with Depth set to 0) and AboveWaterCam (with Depth set to 1, and Clear Flags set to Depth only). Parent one camera to the other (doesn’t matter which), and make sure they’re facing the same direction and are in the same position. From here on out, in-game, only move the parent camera; the other one will automatically follow its position and orientation.

Make a new layer called BelowWaterMask. Set BelowWaterCam’s Culling Mask not have BelowWaterMask checked. This means that any GameObjcets on the BelowWaterMask layer will not be rendered by BelowWaterCam.

Each frame, during OnPreRender(), enable / disable fog (or just change fog settings) as needed for each of these cameras. Refer here for an example. To match the screenshot, UnderWaterCam should have fog enabled and coloured cyan with its fogMode set to Linear and a fogEndDistance of something like 20-30. AboveWaterCam should have fog doing whatever you want it to do normally above water, if anything.

Use a material with a depth mask shader on a mesh that completely covers any below water stuff from your AboveWaterCam’s view. For our purposes, open the shader’s code and change Tags {"Queue" = "Geometry+10" } to Tags {"Queue" = "Geometry-10" } to make it mask out everything queued to render after Geometry (read up on Unity3D render queues if curious what render queues are). Create a new material that uses the depth mask shader. If you apply this material to an object, you’ll notice it’ll seem to go invisible in the Editor, and you’ll see straight through it to Unity’s default grey background (even if there’s something behind your mesh!). This is normal, so don’t worry.

With this change in place, a mesh with a material using the depth mask shader will now cut a hole in what a camera is rendering, as long as that mesh is in the camera’s view frustrum. To make the mesh only block out stuff for the BelowWaterCam and not the AboveWaterCam, put the mesh’s GameObject on the BelowWaterMask layer. This way, BelowWaterCam will not render the mesh, whereas AboveWaterCam will.

Optionally also have 2 projectors with a water caustic texture as the cookie, and make the projectors face downwards and rotate on the vertical axis at different rates. This makes a convincing moving water caustic pattern in my experience (for reference I use the technique in this game made for a small gamejam).