   Normals For Distorted Sphere
  Is there a conceptual flaw in this GLSL vertex shader method for calculating a normal for a sphere?varying vec3 norm;struct spherical { float r, phi, theta; };spherical cartesianToSpherical(vec3 cPoint) {spherical sCoords;float xyLen = length(cPoint.xy);sCoords.r = length(cPoint);  sCoords.phi = acos(cPoint.z / sCoords.r);sCoords.theta = atan(cPoint.x, cPoint.y);return sCoords;}vec3 sphericalToCartesian(spherical sPoint) {vec3 cCoords;cCoords.x = sPoint.r * sin(sPoint.phi) * cos(sPoint.theta);cCoords.y = sPoint.r * sin(sPoint.phi) * sin(sPoint.theta);cCoords.z = sPoint.r * cos(sPoint.phi);return cCoords;}void main(){vec4 vert = gl_Vertex;spherical sVert = cartesianToSpherical(vert.xyz);float offset = 0.01;spherical tanPos = spherical(sVert.r,sVert.phi + offset,sVert.theta);vec3 tangent = sphericalToCartesian(tanPos);tangent -= vert.xyz;spherical bitanPos = spherical(sVert.r,sVert.phi,sVert.theta + offset);vec3 bitangent = sphericalToCartesian(bitanPos);bitangent -=vert.xyz;norm = gl_NormalMatrix * normalize(cross(tangent,bitangent));//Transform vertex by modelview and projection matricesgl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;//Forward current color and texture coordinates after applying texture matrixgl_FrontColor = gl_Color;gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;}I know how to work out the normal for a sphere the easy way, incidentally. This is just a test. The idea would be to generate 2D/2D perlin noise values based on the cartesian coords of the vertex, tangent and bitangent and use this to displace the points along a line from the point to the centre of the mesh).Hope this makes sense,a|xhttp://machinesdontcare.wordpress.com   