Thursday, May 26, 2016

Applying Simplex Noise to a Planet

Last time we talked about Simplex Noise, the noise algorithm we will use to create interesting features on our planet. The basic idea is simple, our cube which consists of 6 planes all facing a different way just need to have a 3-dimensional simplex noise algorithm applied to each face. And because we use the 3-dimensional algorithm it should cleanly wrap and easily around the planet making it appear seamless.

While this sounds simple it is actually quite complex and because of this I removed the "chunked level of detail" code from it until I got everything working properly.

Let's first talk about projecting a cube to a sphere briefly. There are a few ways to do this and my way is by no means the "best." One option is to write a Vertex Shader. This provides the advantage that all math related to projecting the cube is done on the graphics card and can actually speed up the process. I have decided to do it in a derived mesh class however. This allows me to more quickly make changes to the code and makes it so I do not need to write another shader. I may change methods in the future but this works in the meantime.

We can see that we apply a simple formula to each vertex. Then when we run it we get 6 planes that appear to be a sphere!

Now that we have the sphere we can apply the simplex noise formula over it. This is just a matter of getting the correct coordinates of the sphere and running the algorithm over those points. We save these points as a black-and-white image and render it on the sphere. When we do this we get a planet that looks like this.

Well it's round but it doesn't look very much like a planet! Since we have seamlessly applied this algorithm we now have a lot of options of what we can do with it! The most obvious one is to use this as a heightmap. In this case we will take a texture and check what color it is at a certain point. If it is less than a certain value we will set it to blue like an ocean! Otherwise it's green, like land! Lets look at how that turns out.
As you can see I only applied the colorization to one face of the planet! I also did some linear interpolation based on the height/depth of the land/ocean. This gives the deeper parts a darker blue and the higher parts a greener. While this still looks nothing like a planet it is progress!

It also opens new doors for what we can do. It is now possible to use noise algorithms for any use we want on a planet! This could be heatmaps to generate biomes or noise-y clouds! That will come at a later time though!

No comments:

Post a Comment