Wednesday, February 17, 2010

GLSL mesh deformer in spherical coordinates - part 3






Getting closer on properly re-calculating the normals after radial deformation in GLSL. To recap, I built a radial deformer like a jellyfish or spore type form when applied to a sphere. While displacing vertices is fairly easy, re-calculating the normals has been tricky. The visual appearance is getting very close to the phong-shaded deformed sphere I'm shooting for.. However it still isn't perfect.

Since last time, here are the advancements that have brought me closer to the goal:

- Don't normalize any vectors in Spherical coordinates. Since they're measuring angles & radius, a normalization doesn't make sense. This was causing all kinds of crazy problems.
- Cartesian-to-spherical function modified to check for bounds of asin and check hemisphere for atan. Holes in mesh have been fixed.
- Now using the proper built in GLSL matrix functionality.

The current method for calculating normals for deformed vertex is as follows:

- Convert incoming vertex to spherical
- Displace this vertex by 3 component (r, theta, phi) deform function
- Find unit tangent vector U (in Cartesian coords)
- Find binormal vector V (in Cartesian coords)
- Convert these to spherical coords
- Find Jacobian matrix for current vertex (in Spherical coords)
- Multiply U by Jacobian to get U' (transformed unit tangent vector)
- Multiply V by Jacobian to get V' (transformed binormal vector)
- Convert these back into cartesian
- Transformed normal, in Cartesian is normalize(U'X V')


With this method, the shading/highlights still don't look perfect when deformed. I'm almost positive that the culprit is my Jacobian matrix, since when the deformation amount is zero, the object looks perfect: In other words, when the deformation is zero, the whole process of renormalization is still happening, but just coming out identical to the inputs. I'm wondering if my method of simply replacing x,y,z with r,t,p in the Jacobian is legit.. Maybe I have to convert the functions somehow. More reading to come..

No comments: