PDA

View Full Version : Spherical Coordinates and Normals

toneburst
06-24-2009, 02:46 AM
I'm trying to calculate normals for a perlin noise-distorted sphere like this:
http://machinesdontcare.files.wordpress.com/2009/06/nvidiavbombattempt5_05.png

The perlin noise is dynamically generated in a GLSL vertex shader.

I'm currently calculating normals in the shader by a 'neighbour' method, as outlined on tonfilm's blog:
http://tonfilm.blogspot.com/2007/01/calculate-normals-in-shader.html

However, this requires first taking a flat mesh, and bending it around into a sphere, before generating perlin noise based on the vertices XYZ positions, then shifting the vert by the resulting noise value, along a line from the centre of the mesh (what would be the normal, if the original geometry had been a sphere).

The problem here though, is that the texture coordinates become pinched at the poles, and it's hard to prevent holes appearing in the mesh in these areas too, once the vertices are shifted.

I'm wondering if there is another way to do this, taking a sphere mesh as a base, and generating the noise values from sphere vertices directly, without the intermediate grid>sphere stage. Would it still be possible to work out normals in this case, though?

I've tried making tangent and bitangent points by converting the sphere's coordinates into spherical coords, applying a slight offset in the theta and phi directions, then converting them back to cartesian coordinates and fetching the noise value, but this doesn't seem to work.
Is this approach conceptually flawed? Is there a better way of calculating normals in this scenario?

Any tips gratefully received,

a|x
http://machinesdontcare.wordpress.com