Quantcast
Channel: Cabbynode Games » Dev
Viewing all articles
Browse latest Browse all 3

Perlin Simplex Noise for C# and XNA

$
0
0

So a while back I was checking out different noise methods for procedural and art generation, and I decided to look into Simplex Noise.

Simplex Noise is basically Ken Perlin’s replacement for classic Perlin Noise. It produces better results, and is a bit faster, too.

I found a really good paper called “Simplex noise demystified”, by Stefan Gustavson, Linköping University (2005).

In it was an algorithm written in Java for 2d, 3d and 4d noise. I ported it to C# for 2d and 3d noise. I didn’t bother porting the 4d noise over, because I’d never use it.

The method signature is as follows:
public static float GetNoise(double pX, double pY, double pZ)

So, you’d call it like this (note that I’ve encapsulated it in a static class called Noise):
float noiseValue = Noise.GetNoise(x, y, z);

It takes doubles for input, as the extra accuracy over floats is needed (floats suck for positional data!), and it returns a single float (between 0 and 1) for the value of the noise at the specified point.

This method is extra handy because you can use it in the following ways…

* Simple 2d noise
Noise.GetNoise(x, y, 0);
and you can replace the z value of 0 with any number you want, giving you a different 2d noise pattern each time (just be sure to use the same Z value for the entire “block” of noise!)
or you could keep z as 0 and modify the x and/or y values to get a different noise pattern, eg. Noise.GetNoise(x + 100, y + 100, 0);

* Animated 2d noise
Noise.GetNoise(x, y, timer);
where timer is a value that changes over time, and you can modify the x, y and/or timer values as above to produce different patterns

* Simple 3d noise
Noise.GetNoise(x, y, z);
full 3d noise, and if you want a different pattern, all you need to do is modify any/all of the values, eg. Noise.GetNoise(x + 100, y + 100, z + 100);

Hope you enjoy the code! :)

-UPDATE-

Have added in a more up to date version of the code, yay! Modified the link for the new code…
Download


Viewing all articles
Browse latest Browse all 3

Trending Articles