Thursday, April 17, 2008

Perlin Noise And Fractals

I read up on Ken Perlin and wanted to try do some terrain using Fractal Brownian Motion. Ken's homepage has tons of little Java applications that each do something innovative with noise - it's good to play about with. Ken came up with a fast way of creating noise and used it to create natural looking textures. He even won an Oscar for this technique! I had a look at his code and to be honest it was very difficult to follow, sort of like it had been obfuscated. So I looked elsewhere for info but found a lot of people did a sort of hack on Perlin Noise - basically fill an array with random noise and smooth each pixel using the values of neighbouring pixels. I tried this technique out and I wasn't that impressed with the results. It doesn't look too bad but when on an actual terrain, I think it looks too artificial - like the mountains have a grid-like pattern (I tried to highlight this in red on the terrain).

 PerlinHeightMap perlinhack

So with the proper Perlin Noise/Fractal Brownian Motion implementation, I think the results are a lot better. To start I wrote a little app so I could quickly try out different combinations of the parameters, here's a screen of it, and some of the results:

perlinnoiseapp

O_7F_0.01A_1L_2P_0.4O_7F_0.015A_1L_2P_0.4  O_8F_0.025A_2L_2.4P_0.56 

Here's some terrain built with a Perlin/fBm height-map:

perlinterrain

Another cool thing about Perlin/fBm (if you're a geek I suppose) is that it can be applied to three dimensions too, so I should be able to use it for seamless planet height-maps and textures... but haven't worked it out yet. Often when applying a 2d texture to a sphere artifacts appear, like pinching at the poles, but Perlin/fBm should be fine - we'll see!

Next I really need to do some clean up on my code and after that I'll either look at:

  • making a sphere by recursively splitting a cube's face or...
  • generating the grass, snow and rock textures with Perlin noise

1 comment:

Tantilloon said...

Nice info, I got to the same "grid" stage and didn't know where to go next.