Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

MyIsaak

[REALISTIC] Water Effect Script

Recommended Posts

Hey guys its Isaak here! I was working on a polygon reduction plugin for unity, but i got bored and tried to see what would happen if I manipulated each vertex in a mesh using the Mathf.Sin function. And I ended up with this:

a224ca8ffe93e7c6747a819c2f7d710d.gif

 

A smooth wave that works seamlessly with Unity; Plus it performs very well, and don't be put off by the framerate only staying at 70 as it continues to stay at 70 when duplicating the mesh above 100 times.

 

How well does this script perform?

The performance obviously lies behind 2 main factors:

  1. The shader used on the mesh. The image above used Unity's new Reflective shader, but works perfectly well with any other shader, including transparent or translucent.
  2. The number of verticies. This mesh is a plane, and thus wouldn't have as many vertices as a high poly character. This script could probably withstand 250 000 verticies.

 

How to get it?

How to use this script?

Drag this script onto any GameObject with a MeshRenderer component attached (e.g. any 3d model basically), and press play!

 

What variables to mess around with?

Wave Speed - Just like you learnt back in high school, waves have a velocity, and yup... you guessed it... makes the waves flow faster.
Wave Amplitude - Amplitude means how high and low the wave will be.
Wave Length - Equivalent towards lambda in wave physics.
TickFrequency - How many seconds to await for next update. In other words, despite performance, how smooth you want your wave to be.
*NEW* Noise - Adds harmonic noise on a second layer to the water, to make it appear bumpy and more realistic
 
What licensing does this code have?
I normally like to use the MIT licensing, but as i kind gesture, I'm leaving this snipplet free of charge and of any copyright. You may use this for commercial and/or personal use, as long as you make it look good ( :P ). Have fun guys!
 
How to fix waves that lag or appear to be choppy?
Make sure you have set the TickFrequency variable for the script to a low value, ensuring fast update times. Set to 0 for smoothest results possible.
 
Any other uses for this script?
Yes! A Flag came first to my mind, plus nobody knows how to use the complicated cloth renderer first time, with wind and all that stuff. In this case, beginners just drag this script over a mesh and your done.
  • Like 5

Share this post


Link to post
Share on other sites

Looks good man ++. If you want to test yourself in the future, try a ripple from a given vertex. But nice work

  • Like 1

Share this post


Link to post
Share on other sites

Wow, I've never seen anything like this before. Very interesting, nice job dude.

  • Like 1

Share this post


Link to post
Share on other sites
Please login or register to see this quote. Okay so far I'm using an expensive function of progressively finding new neighbors verticies, of their neighbors, of their neighbors, to achieve sets of verticies that expand radially to achieve that ripple effect from a specific vertex.

The problem is that the frame rate just dropped like crazy because I'm looping through the vertex array multiple times to check for neighbors. I need to find another method: One proposition that Mark from Unity forums gave me was to cache my calculated radial neighbors verticies in a dictionary. So I should be done with your challenge soon ;)

Share this post


Link to post
Share on other sites

Excellent effect, I'm surprised it hasn't had more responses. 

  • Like 1

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

Thanks Athlor, it's a great free effect I know. Why don't you tell us what you're using it for? I'm Isaak by the way ;)

Share this post


Link to post
Share on other sites

Mate, Could you be a pal, and send me the code?

It's for educational purposes (It will probably be altered) and I will credit you if wanted. ;) 

Share this post


Link to post
Share on other sites
Please login or register to see this quote.

Share this post


Link to post
Share on other sites

Ha... My current project is a desert environment and I can't use it there but I've tested this and it's a gem. Even today, few new games even implement real waves. I highly recommend purchasing the complete wave package. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×