Pages

Thursday, April 15, 2010

Underwater effects like island demo in unity3d

A lot of times I get asked how to do the underwater effects like the one we see in island demo - where when you / your camera goes under water level you see blurry atmosphere.

Since most of the questions are asked by Non Programmers, (ex http://forum.unity3d.com/viewtopic.php?p=195450 )  here is a "copy paste" style tutorial that you should be able to follow to create your underwater effects.


Level : Beginner heading towards intermediate 


Things you need
1. Underwater script (comes with island demo)
2. Underwater shader (comes with island demo)
3. Blur island script (comes with island demo)
4. Glow Effect Island script (comes with island demo)

Lets get our hands dirty
0. Open your island demo project, create a new scene.
1. Create a terrain.
2. Drag daylight water in the scene.
3. Enlarge it to make it fill your scene / area that you are trying to put water on.
4. Drag first person controller to the scene. Position it where you need it to start walking
5. Click Main camera so that you can now assign scripts to the main camera
6. Go to components > Scripts > Underwater script to add underwater script to the camera.


7. Now you should have underwater effect script on your main camera. However, if you try to go under the water right now, you wont see any effect. For that, you need to add the under water surface first.
8. Go to Game object > Create other > Plane
9. Make the plane to have EXACTLY same X, Y, Z as the daylight water. (You can make the Y of the underwater a little low - just like what I did, but X and Z should be same)


10. Now drag the underwater shader from the water folder from the project window.




11. You can try to play and go underwater now and VOLA!!! You are stuck!! You wanted to see blur and now You cant even get down. That is because your plane has a collider. So remove the collider from the plane and you are good to go down.


12. However, you still cant see any blurriness. That is because your camera dont have any blur script to it. So, select the "main camera" under first person controller prefab and go to
a) Component > Image effect > blur (island)
b) Component > Image effect > Glow (Island)

13. One you assigned all of this, the last thing you need to assign in an audio source. That is because the default script that comes with island demo has audio and your current camera dont have audio. So click the main camera again, and go to
Component > Audio > Audio source

14. Now play it, you should have similar blurry effect.

15. If you want to control the blur, change the iteration or blur speed under blur effect island. (this is under main camera) . Here I changed the iterations from 3 to 1 to have clearer effect.


So hope you can follow this and create your own underwater effects. If you are doing it in a different folder you need to copy the relevant scripts there, but I assume if you can follow this you already know how to copy the scripts needed to your folder.

Drop me a line at avijit.paul   at   mmu.edu.my or avijit.paul.1992     at   gmail.com   or post a comment below if you have any questions.

8 comments:

  1. didnt work for me either..

    ReplyDelete
  2. I had to set the water level and it worked! The effect is pretty subtle though...

    ReplyDelete
  3. Do you have any link for island demo?
    Where can I download the scripts and the Shader?

    ReplyDelete
  4. this is the link to unity 3d island demo
    http://unity3d.com/support/resources/example-projects/islanddemo

    ps: i've download better water 3 (i don't know if it works un unity 3d standard i've unity 3d pro)
    this is the linkt for better water 3: http://forum.unity3d.com/threads/85737-Better-Water-Pro-3

    ReplyDelete
    Replies
    1. The Link to dowload the Better-Watter-Pro-3 on the page you liked to is broken could you link to the package. I realy like how it looks

      Delete
  5. Excellent resource! Thanks for all of the good information. Very informative.

    ReplyDelete