Request: Special Underwater Blurring Script

Hi guys, I’m looking for a decent underwater blur script but with one special property.

I want the blur to fill only half the screen when you (or the camera) is only halfway underwater. Usually when you are in this position, there’s just the water line halfway up the screen, and no blur effect neither above nor below it.

I want it so you can see the water line halfway up the screen, with the blur below the water only. Same goes for if the camera is 3/4 of the way into the water, then only 3/4 of the screen will blur. (And when you move up/down, you can see the water level move accordingly, with the blur underneath)

Thanks in advance for any help.

Hi, welcome to the forum!

I’ve attached a script that gives a split screen effect (you mentioned blurring, but you can apply any image effect to the two cameras). Attach the script to a camera and then create another camera called “TopCam” and make it a child of the camera with the script. The “split” variable controls how high up the screen the split point is. Note that there is a slight subtlety with this. The render textures used to apply the image effects can’t have a height of zero, so if either camera completely covers the screen, a non-fatal warning occurs. If this causes any problems, then you can avoid it by cutting to another view when the split point is at least one pixel away from the top or bottom of the screen. Unfortunately, I’ve struggled to think of a general purpose way to prevent the error, but you may be able to fix something up for your particular situation.

252986–9102–$camsplit_986.cs (1.29 KB)

Heya andeeee,

This is quite interesting but is there any way you could provide a sample project? I’ve been following your instructions but I’m yet to see how it can help with the issue described where the water ‘gap’ appears when the camera is half in and half out of the water.

Cheers

The file Andeeeeeee attached to his post should do the trick for you. In his solution you don’t have ‘one camera half under water.’ Instead, you have two cameras. One with blur fully submerged, one not.

Take a look at the documentation on Normalized Viewport Rect for further information. There’s no one-camera-only rule, or a rule that a camera need take up the entire screen!

Actually, there is an important detail that I left out… the child camera must have a local position of <0,0,0> (ie, it should be in exactly the same place as the parent camera. The two cameras render the scene from the same position, but with different image effects. So, without the script, you could just switch between the two cameras and see the same view, but with the different effects applied. The script just works out how to split the view so that one camera shows the top half and the other the bottom half.

I Just Need A Basic Script For The Underwater Effect , And A Short Note On How To Fix It To My Camera… I Am Noob In Coding. Thanks In Advance, <3 :face_with_spiral_eyes:

Welcome to the forum, Parvathy!

Applying an effect to the whole camera requires Unity Pro. You can import the image effects package (menu: Assets > Import Package > Image Effects) and then add an effect by selecting the camera and choosing the effect from the Component > Image Effects menu. It’s difficult to suggest exactly what effect you should use because it will depend on what type of atmosphere you want for the game (maybe “atmosphere” is the wrong word for an underwater scene :wink: However, blur, fog, noise and sun shafts may all be appropriate.

If you don’t have Unity Pro then you might still get a good underwater effect by using fog on the camera and by choosing colours and lighting carefully.