Sunday, 20 May 2012

Playing around with Brownian Noise

Now that I have acquired large amounts of free time, I am going to be spending my time developing all sorts of things. As part of this, I decided to create this blog as an outlet to write about what I am doing, as well as to show things off which are pretty neat. Some of this will be fairly technical, as I discuss some of the more grognardy parts of what I am currently working on. Hopefully this might be interesting to some of you, and someone might even learn something. First time for everything!

Today I have been looking at techniques for creating natural looking randomness. This comes in the form of various kinds of procedural noise. There are various techniques for procedurally generating noise available and I eventually ended up implementing Fractional Brownian Motion (fBm).
A Brownian Surface. From Wikipedia 

There is an awful lot of confusion on the internet about what each technique is actually called, and a lot of the information I read referred to this as Perlin Noise (including this page, which I based most of my implementation on.) This is incorrect however, as Perlin Noise is a very different technique, but produces a similar result. As far as I can tell, Perlin Noise is very complex and is overkill for most problems, which is where fBm comes in. More information about fBm and comparisons to Perlin Noise can be found here.

I will not go into huge amounts of details of the actual algorithm, but basic premise is that a deterministic function of noise is used and these values are interpolated at different scales and then combined. If you have ever looked at tools such as Photoshop and the generate clouds function, they likely used a function very similar to this.

The first step is to have a function that can allow the generation of deterministic noise. This is a function that will always produce a single result when given the same parameters. The result of basic noise looks like this:

Not exactly very nice to look at. The next step is to apply some basic smoothing to the image. This averages values based on their neighbours. This producing a slightly better looking second stage:

Next, the actual fBm takes place. This page provides a pretty good description of the actual algorithm involved here. After the first pass, it looks like this:

Not quite what I am after...
After three more passes, each adding more and more finer detail, it looks like this:
That's more like it! It's quite easy to see how this sort of function is quite commonly used it terrain generation as well as for procedurally generating textures such as clouds and grass. In future posts, I will be using this sort of noise for investigating generating 3D terrain, so stay tuned!

No comments:

Post a Comment