Simplex Noise was actually designed by the same person who designed Perlin Noise, Ken Perlin. He considered Perlin Noise to have too many problems and to be poorly done and he wanted to correct those. Not only did he fix the problems that Perlin Noise had, he also successfully made a faster algorithm. Speed is going to be vital to us when we start moving around the planet because we want to render this in real time so this algorithm works perfectly for us. Let's take a look at how it works.
We can see here that the bulk of our algorithm is in the method called RawNoise3D. Simplex Noise has the advantage of being able to be done in multiple dimensions. We are rendering a 3D planet so we want 3-dimensions. This means that noise will wrap around the planet evenly and we will not see differences across different faces. Perfect!
The actual algorithm uses a "seed" of permutations to manipulate the data around a certain point, not the actual point itself. The math behind it is rather complex so I will not be going over it in detail. The next snippet we see is our two methods that we will use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float SimplexNoise::OctaveNoise3D( const float octaves, const float persistence, const float scale, const float x, const float y, const float z ) { | |
float total = 0; | |
float frequency = scale; | |
float amplitude = 1; | |
float maxAmplitude = 0; | |
for( int i=0; i < octaves; i++ ) { | |
total += RawNoise3D( x * frequency, y * frequency, z * frequency ) * amplitude; | |
frequency *= 2; | |
maxAmplitude += amplitude; | |
amplitude *= persistence; | |
} | |
return total / maxAmplitude; | |
} | |
float SimplexNoise::ScaledOctaveNoise3D( const float octaves, const float persistence, const float scale, const float loBound, const float hiBound, const float x, const float y, const float z ) { | |
return OctaveNoise3D( octaves, persistence, scale, x, y, z ) * ( hiBound - loBound ) / 2 + ( hiBound + loBound ) / 2; | |
} |
We can see here that this looks a lot like Perlin Noise! That's because it is. They both generate similar results but they do so in different ways. This will be what we use to make our terrain for our planet.
As usual the code is in Github here. I hope you enjoyed this and learned something new. Thanks for reading.
No comments:
Post a Comment