Planet Rendering – 2D Plane -> Sphere

For my Dissertation I am working on Procedurally Generating and Rendering Planets. This is a huge topic with lots of information out on the internet, so I’m going to write up some parts of my process to help anyone else that wants to do something similar, and so that in future I know what approaches I have already taken.

I’ll start by talking about rendering a planet. There are a lot of different methods for rendering a planet. These mainly involve trying to render a giant sphere, or at least parts of one. There are multiple ways to transform other geometry into a sphere and I started out by using the naive method of trying to wrap a 2D plane (i.e like a sheet of paper) around a sphere.

It’s actually pretty easy to create a sphere using this method. If you loop over the height and width of the 2D plane you can transform the plane to wrap around the sphere. The code to do this is as follows:

What the code does is take some point on the plane and maps from these co-ordinates (x, y) to the angles (theta, phi). Then using spherical co-ordinates we can calculate the position on the sphere in 3D space.

If instead of a standard plane you take a heightmap image, you can evaluate each pixel in the image and alter the radius of the sphere to create dips on the surface and create what looks to be a planet. So instead of just doing:

radius * sin(theta) * cos(phi)

you can add the height at each pixel to the radius like so:

(radius + heightmap.height) * sin(theta) * cos(phi)

This method works well for simple things, however there are problems such as textures warping at the poles when trying to texture the sphere. In order to try solve this I attempted another method of rendering a sphere, a Cube -> Sphere mapping. In the next post I will talk about how I attempted this and the results.