Tuesday, November 27, 2012

Rendering Spheres with Triangles

Creating spheres programmatically has turned up a couple of times recently.  So here are my own notes:

There are two general approaches:

The leftmost is termed the uv-sphere and the rightmost an icosphere.

The uv-sphere looks like a globe. For many purposes it is perfectly fine, but for some use cases, e.g. if you want to deform the sphere, it is disadvantageous that the density of vertices is greater around the poles.  The icosphere vertices are distributed evenly.

GLUT tends to use the uv approach: look at the function glutSolidSphere() in the freeglut sourcecode.

And webGL doesn’t have glutSolidSphere().  Oh well.  Here’s my code for creating an untextured icosphere online.

Here is an excellent article on producing an icosphere: http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html

I’ve also experiemented with tiling spheres for RTS games etc.  Here’s an excellent guide to how you might divide the sphere surface into zones: http://kiwi.atmos.colostate.edu/BUGS/geodesic/text.html

Finally, texturing.  http://vterrain.org/Textures/spherical.html gives an excellent description of how you might choose to texture them, and http://www.iquilezles.org/www/articles/patchedsphere/patchedsphere.htm is - as iñigo is - brilliant.


  1. williamedwardscoder posted this

 ↓ click the "share" button below!