Special Effects: Living Noise

Nov 1, 2009

The Living Noise is an animated “flow” of particles. The particle trajectory is changed by using Perlin Noise (long live Ken Perlin!) I’m so excited. Perlin noise is used pretty much in all special effects – explosions, texture generation, water, clouds, mountains, terrain generation, twinkling stars, halo/weapon effects, etc..

Click below to see the Living Noise sample, which is just one way to use Noise:

Living Noise

Download the source code for Living Noise

Basic Explanation of Noise

If you hear about Perlin Noise for the first time, I bet you have a lot of questions like “how does it work?” and “what is it?” and maybe even “can my neighbors produce it?”

Here is my short explanation. I’m not very good at maths, thus will use my own words to describe things. If you’re math-savvy, check out Wikipedia or some scientific site out there for the exact description.

Perlin Noise is a “continuous noise”. What does it mean?

  • It’s noise, meaning that it appears to be random in nature. E.g. If you have a function color=Noise(x,y) and plot this on a picture, you’ll get random dots (or “noise”) everywhere! 
  • It’s continuous, meaning that it looks “smooth” when plotted on a surface (no “hard edges”)

The “continuous” part is very important! As you probably noticed, in nature things doesn’t just jump up-and-down, but look smooth and “continuous”. Take water for example: if you look at ocean waves, they do look kind of random, but at the same time they look smooth as well:

 

The Noise() function looks like this:

value = Noise(x, y, z)

Where value would typically be (depends on who implements it) between -1 and 1

The above noise is 3D because its function has 3 parameters: x, y, and z. There are also 1-D noise, 2-D noise, 4-D noise and so on.

For the Living Noise sample, I just need 2D but I implemented the 3D version for fun. It’s also slower, so if you’re using only 2D, don’t run the 3D version “just because” as I did.

Now is the time to look at how a 3D noise looks like. Take a look at this external sample, showing a 3d noise on a 2d surface. The Z coordinate means “time” in that sample, so you’ll see nice animated noise that looks like clouds a little bit J If you also read here you’ll better understand the meaning of “frequency”, “amplitude” and the other parameters as well.

Using Perlin Noise To Make Living Noise

By now you should be familiar with Perlin Noise and continuous noise. If you’re not please drop me a comment so I can explain it better 

Imagine a dot (or “particle”) on the screen. Let’s give our particle has some velocity (vx, vy) measured in [pixels/time], and a location (x,y). If we continuously draw the particle over time, we’ll see a straight line, which is boring and dull.

To make the particle more “interesting” we’ll modify its velocity over time as well.

Here are 3 examples of how can we modify the velocity:

  • Completely random: the particle will appear to jump everywhere (mostly around where it started)
  • Sinusoidal of some sort – the particle will appear to follow a sine-wave trajectory, better but not perfect…Anyone could see the motion is predictable.
  • Using continuous noise: the particle could go anywhere, but smoothly. There will be no jumpiness in behavior like in the first case, or predictable motion as in the second case: Living Noise! The particle travels smoothly, because the noise function is smooth. See Basic Explanation of Noise above and the external links for more info.

First, I compute the noise and store it into an image. Storing into an image is not the best way to do it (slower), but it helped me “debug” the noise visually.

The noise is pre-computed because it doesn’t need to change over time.

On every time step (CompositionTarget.Rendering), get the particle’s location, and find how its velocity will change based on the noise (see NoiseParticle.cs)

Adding Lots of Particles

Since we can do it for one particle, we can as well do it for 3000 to get a nice “flow-like” image. We’ll also add some color to each particle to make everything more interesting.

Making It Look Good

Now we have a screenfull of particles, they look pretty impressive, but it’s still just a “neat effect” and I could say not production-ready yet.

Here’s why:

  • The particles are just dots – too small and need to have quite a bit of those to make something useful
  • The particles doesn’t relate to each other, e.g. if two particles are close nearby I’d like them to “light up” or something like that. 
  • Third, I’d like all this to be able to look “organic”, meaning I should be able to compose complex particle interaction and behavior in code-behind (not just modify opacity)

The implication from the Third requirement is the most important – it means I intentionally chose to render the scene on WritableBitmap rather than having 3000 <Image /> controls on a Silverlight surface.

It also means that everything will get slower, and we’ll have to account for that (see Making It Scale below).

I’ll use a quite “hacky” method to implement the First and Third requirement:

Modified Blur

To make a dot appear “larger” than it is, we just blur it on every frame. That’s good but only blur will provide blurry image…we really need some definition in there as well.

The solution is to blur the “screen” and overlay with “sharp” scene on every frame. This means that the longer a pixel stays on screen the blurrier it gets (you can think about the dots “dissolving” into thin air), and also definition and sharpness of newly created dots is preserved.

Interestingly enough, dots that are close to each other will provide a bigger “blur cloud” which makes for some non-trivial effect of multiple dots gathering at the same place (Second requirement)

We also need to fade the screen just a bit on every frame otherwise we’ll end up with some huge color field (which might be good for another demo).

Making It Scale

If you follow everything so far, and used the classic algorithm for Blur, you’ll end up with the Living Noise. At this point, it might be too slow. We want to make it full screen, and also have it use not-too-much CPU, so that whatever we’re doing can have extra cycles for something else (e.g. in-game AI or other effects).

Optimized Blur

The default Gaussian blur is quite slow. The hack I’m using averages the 2 horizontal neighboring pixels for each pixel on screen, to achieve horizontal blur. Then do the same vertically, to get vertical blur. The 2 combined give us the so-called “box blur”, which is much faster than Gaussian blur without any noticeable fidelity decrease for the Living noise (if you don’t believe it, try both and see for yourself).

Multithreading

The nice thing about our optimized blur is that it can easily be multi-threaded. Since many people now have at least a dual-core system, having 2 threads to compute the blur really allows us to take it full screen!

As a further optimization, you can apply the blur every second, third, or fourth frame without having the quality degrade too bad – good if your game, or whatever you’re doing doesn’t have “make Living Noise” as the primary goal.

Making It Stick To Objects

Here you’ll see how the Third requirement in “Making It Look Good” pays off.

Adding “sticky” is easy: 

  1. Create a new WritableBitmap hitTestSurface
  2. Draw TextBlock or whatever you’d like the noise to “stick” to there 
  3. When calculating the velocity over time for the particles on every frame, revert the time for particles that hit a non-zero pixel on hitTestSurface

You’re Done!

Usages Of Living Noise

These come up from the top of my head: 

  • Just show it on the main menu like a cool tweak 
  • Use it as “living ornaments” to stuff (menus again) 
  • Explosions 
  • Weird space effect 
  • Engine exhaust. Should be fairly easy once and you can pick your “exhaust of choice” by changing the x or y value of the start location of the exhaust) 
  • Holes in the fabric of space – if you create particles from a circular shape, it can look like someone tore the space time continuum  

Further Noise Usage

I have not experimented a lot with these yet, but here are some ideas of what you could do with Noise in general: 

  • Clouds, in particular if you play with the octaves/sliding you can make clouds that appear moving towards or against you. 
  • If you draw a line dot by dot and modify every dot’s location based on noise you’ll likely get lightning effect 
  • Draw mountains by hand then modify the image with noise to add terrain artifacts. Note: there are many “noise generated terrains” out there. I’m proposing a manual + automated method to achieve best results and allow more tweaking 
  • Have some sin/cos movements (e.g. enemy battle ships), but modify the location of the ship using perlin noise. The ship will still move according to predictable trajectory, but it will look more interesting
  • Explosions (take the Living noise example and make the particles “die” fast). Also, it would be nice to make the particles fade more the further they are from the explosion for 2 reasons: o Looks more life-like o You can ensure that the explosion stays within a certain rage (e.g. 64x64 pixels) – this allows you to render an explosion fast, without the need to go fullscreen. You can have lots of explosions that way, and maybe one big “boss” explosion 
  • Lava flowing down a mountain (I have yet to see this): add gravity to the Living Noise, and instead of velocity modify the particle positions. You can use the “sticky” properly of the Living Noise to have it burn around rocks and/or other objects 
  • Other stuff  

References/Very Cool Stuff Links

Fast Blur: http://www.gamasutra.com/view/feature/3102/four_tricks_for_fast_blurring_in_.php

Rene's blog (this demo was inspired by his realtime noise, although I used another slower algorithm): http://kodierer.blogspot.com/

Rick Barazza's cool samples: http://www.cynergysystems.com/blogs/page/rickbarraza (found this from a colleague after he saw my demo)

Hope you liked this post! Please comment!

 

  

Comments

11/2/2009 10:00:44 PM #

Rene Schulte

Great effect. I like it a lot how you combined various techniques to get this superb particle effect. What were your references?

Rene Schulte | Reply

11/2/2009 10:51:26 PM #

nokola

Thanks Rene!
I got inspired by your blog post on Silverlight Perlin Noise (nice job!), although didn't use your code (picked it up from a repository I had from before.)
For the blur, I read Wikipedia on Gaussian blur, smoothing filters and so on, but mainly used this resource: www.gamasutra.com/.../...for_fast_blurring_in_.php
The final effect came into place after looking at LOTS (probably 50+) of sites that feature various lightning effects Smile

nokola | Reply

11/3/2009 9:04:01 AM #

Rene Schulte

Very good work Nikola! I love it. It looks awesome and is really fast.
Keep it up!

Rene Schulte | Reply

11/3/2009 6:28:01 PM #

Rick Barraza

Wow, awesome stuff (as usual)! Loved the optimizations and how you're using multi-threading and rolling your own blur effects. I've downloaded the sample and will definitely comb through it next time I have a spell of free time. Always been a big fan of your site and one of the first ones that got me into shaders (and water ripples) You rock (again), Nokola!

Rick Barraza | Reply

11/4/2009 10:34:31 AM #

nokola

Thanks a lot Rick! Smile I'm a fan of your blog too! Great work on the flow simulaton and vector fields! btw, there are some improvements to the source, it's faster now Smile Just uploaded the new version...

nokola | Reply

12/8/2009 1:46:39 PM #

cash loans

Interesting ... as always - is your blog making any cash advance ? ;)

cash loans | Reply

12/27/2009 12:17:55 PM #

payday loans

Searching for this for some time now - i guess luck is more advanced than search engines Smile

payday loans | Reply

1/6/2010 6:27:13 AM #

buy laptop

Silverlight represents a web application framework explicitly configured for client-side coding, offering a thorough set of rich internet application options.

buy laptop | Reply

1/6/2010 7:03:57 AM #

SEO

Silverlight is a browser plugin or software for playing media files and other Web applications that work on Windows and Macintosh with Firefox, Internet Explorer and Safari browsers.

SEO | Reply

1/9/2010 3:04:10 AM #

KS Personal Loans

I guess there's always an easier way ...

KS Personal Loans | Reply

1/9/2010 7:45:22 AM #

Utah Web Design

Silverlight represents a web application framework explicitly configured for client-side coding, offering a thorough set of rich internet application options.

Utah Web Design | Reply

1/11/2010 10:12:21 AM #

SEO Services

Thanks a lot

SEO Services | Reply

1/11/2010 1:09:30 PM #

learn poker

How to go to the selected place via 3D satellite journey?

learn poker | Reply

1/12/2010 8:50:04 AM #

James

I admire what you have done here. It is good to see your clarity on this important subject can be easily observed. Tremendous post and will look forward to your future update.

Thanks
<a href="http://www.websitedevelopersindia.net">Web Development Firm India</a>

James | Reply

1/13/2010 5:25:35 PM #

Application Development Company

The new version runs at 15-20% in low quality and about 30% in high quality..could be better but I tried... Smile

Application Development Company | Reply

1/14/2010 4:06:49 PM #

SEO Company in India

These are very good methods to create a living noise effects.

Thanks.

SEO Company in India | Reply

1/15/2010 11:26:23 AM #

SEO Services Company

I read your post . it was amazing.Your thought process is wonderful.The way you tell about things is awesome. i always wait for your posts. They are inspiring and helpful.Thanks for sharing your information and stories.

http://www.seoservicesindia.mobi

SEO Services Company | Reply

1/15/2010 11:41:06 AM #

IVA

Very informative article..
thanks for this great information, now i find what i want to know..

IVA | Reply

1/15/2010 2:51:28 PM #

annuity rates

Iam very happy to read this article..thanks for giving us nice info.Fantastic walk-through. I appreciate this post.

annuity rates | Reply

1/16/2010 2:25:00 PM #

australian pr

Great blog post. It’s useful information.

australian pr | Reply

1/18/2010 12:55:27 PM #

Strollers

Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

Strollers | Reply

1/19/2010 12:18:24 PM #

Money Saving Tips

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

Money Saving Tips | Reply

1/26/2010 8:28:28 AM #

amazon tours

Cheers for the info. It was a good read.

amazon tours | Reply

1/27/2010 11:33:40 PM #

online personal loans

Real success comes in small portions day by day. You need to take pleasure in life's daily little treasures. It is the most important thing in measuring success.

online personal loans | Reply

1/28/2010 11:04:25 AM #

Dating Chat Rooms

This article gives the light in which we can observe the reality.I enjoyed every little bit of it and I have you bookmarked to check out new stuff you post.

Dating Chat Rooms | Reply

1/28/2010 2:20:02 PM #

RubyKb28

This outcome related to this post seems to be good! Therefore people not have to accomplish the <a href="http://www.topthesis.com">thesis</a> or just legal dissertation by their own, they would use your support.

RubyKb28 | Reply

1/30/2010 10:13:22 AM #

quick loans

Action itself, so long as I am convinced that it is right action, gives me satisfaction.

quick loans | Reply

1/30/2010 4:41:25 PM #

prepress service

This blogs has very interesting news i enter every day to read it is very useful to do my work.

prepress service | Reply

1/31/2010 9:57:32 PM #

Apartments Buenos Aires

Thanks for taking the time to explain it succinctly to us. now I understand a little more about it.

Apartments Buenos Aires | Reply

2/1/2010 7:20:51 AM #

business opportunity

Awesome tips. I’ll be passing this post on for sure

business opportunity | Reply

2/1/2010 8:43:24 AM #

Life insurance

Hi,

How long have you been in this field? You seem to know a lot more than I do, I’d love to know your sources!

Life insurance | Reply

2/1/2010 9:08:19 AM #

Apex Professionals LLC

This is a cool screen idea ! It is very interesting indeed.Thank you for your info.i love to read all info.This article gives the light in which we can observe the reality.

Apex Professionals LLC | Reply

2/1/2010 11:39:03 AM #

hardwood floors

Hi,

Insightful piece, thanks a lot!

hardwood floors | Reply

2/1/2010 1:37:50 PM #

Blog Post Writer

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It's always nice when you can not only be informed, but also entertained! I'm sure you had fun writing this article.

Blog Post Writer | Reply

2/4/2010 7:51:47 AM #

IVA

I’m not very good at maths, thus will use my own words to describe things. If you’re math-savvy, check out Wikipedia or some scientific site out there for the exact description.

IVA | Reply

2/4/2010 9:17:19 AM #

Plastic Surgery

I will keep visiting this blog very often.It is good to see you verbalise from the heart and your clarity on this important subject can be easily observed.

Plastic Surgery | Reply

2/4/2010 9:35:38 AM #

farmville cheats

Thanks for your post, i will be back in next months.

farmville cheats | Reply

2/4/2010 12:51:28 PM #

Online diamond jewelry

It's really great post, i also searching for something like that, good information, I would like to appreciate your work, Thanks for sharing

Online diamond jewelry | Reply

2/5/2010 1:01:53 PM #

UK Online Sports Betting

I always wanted to write in my site something like that but I guess you'r faster

UK Online Sports Betting | Reply

2/7/2010 12:37:51 AM #

ehliyet sınav sonuçları

Thanks for good information.

ehliyet sınav sonuçları | Reply

2/8/2010 10:12:34 AM #

playedonline

Very useful informations about these subject. Great info.I like all your post.Interesting article..

playedonline | Reply

2/8/2010 4:41:06 PM #

holistic nutrition college

All the links that listeners sent to us above, I have now added to the our website, in the category “Links from Listeners,” at the right. Thanks!

holistic nutrition college | Reply

2/8/2010 4:48:10 PM #

ssk sorgulama

Thanks for good information.

ssk sorgulama | Reply

Add comment




biuquote
  • Comment
  • Preview
Loading



nokola.com | Terms | Log in