Some Shady Stuff

Should have done a lighting thing, that could have lined up a better joke.

Writing shaders is pretty neat, though I can’t say it is my favourite thing in the world to do. I decided on writing a ripple effect shader that I could incorporate into my final project as throwing things into or raising things above water is something that currently looks incredibly dodgy as nothing actually happens. In order to achieve this I needed to know some of the math I thought I would never need from highschool.

The main thing I needed to know was about transforming a sine wave as almost the entire shader functionality focused on sine waves. The ripple itself is created with some transformations to the formula sin(r)/r, with r representing the distance from the center point of the effect.


This default effect didn’t provide enough of an influence as the effect was dragged out over too long. In order to achieve what I wanted I needed to multiply the r value by a factor of 10 and multiply the entire thing by the magnitude variable that gets passed in as this would make the effect far more noticeable. One more large problem however would then stand in the way, the effect would be static and not animated. In order to fix this I needed to pass in a time variable and have that influence both the magnitude and the distance. The final modifications to the formula ended up looking like this.

water verts

After these changes and a script to set the variables, the final effect ended up looking fairly nice. The effect isn’t that complicated but when used in conjunction with my final project I think it will go a long way towards improving the overall feel of the water.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s