uniform float A, B, C, D; // 0 > 1 range
// The parametric mesh function itself
vec4 heartSphere(in vec4 point)
{
/*
Adapted from Mike Williams' equation, found at
http://www.econym.demon.co.uk/isotut/real.htm#heart1
*/
float u = point.x * PI;
float v = point.y * TWOPI;
vec4 outPos;
outPos.x = (cos(u) * sin(v)) - pow(abs(sin(u) * sin(v)), A) * B;
outPos.y = cos(v) * C;
outPos.z = sin(u) * sin(v);
outPos.w = 1.0;
return outPos;
}
// Structure to hold vertex position and normal values
struct posNorm {
vec4 pos;
vec3 norm;
};
// Calculate vertex position and normal
posNorm surface(in vec4 point)
{
// Initialise output variable
posNorm result;
// Calculate vertex position
result.pos = heartSphere(point);
// Calculate normal
float offset = 0.00001;
vec4 tangent = heartSphere(vec4(point.x, point.y + offset, point.z,1.0)) -
heartSphere(vec4(point.x, point.y - offset, point.z,1.0));
vec4 bitangent = heartSphere(vec4(point.x + offset, point.yz,1.0)) -
heartSphere(vec4(point.x - offset, point.yz,1.0));
result.norm = cross(tangent.xyz, bitangent.xyz);
// Return vertex position and normal
return result;
}
I get a heart-shaped mesh, as I should, but the normals are incorrect, being flipped across the top half of the model. Does anyone know if this method of calculating normals is usable for this kind of parametric surface (basically a modulated sphere form), and if so, what I've done wrong?
I'm multiplying the normal by gl_NormalMatrix, then normalizing it before sending it to the Fragment Shader as a vec3 varying.
Here's what it currently looks like:
http://img360.images...ppednormfq5.png
Any advice, anyone?
a|x
http://machinesdontcare.wordpress.com












