please excuse another newbie question.
I’m working on converting some HLSL code to GLSL. I have an HLSL vertex shader that distorts a mesh via a number of different surface formulae. The formulae output vertex position (as a vec4), and bitangent and tangent vec3s (all presumably in Object coordinates).
I’ve been able to transform the vertex coordinates by multiplication with the gl_ModelViewProjectionMatrix. What I’m having trouble trying to do is figure out how to create the normal from the Bi and Tan variables, and transform it into the correct coordinate space, so I can use it to apply lighting effects.
I’m currently not applying any transformation to Bi and Tan, and using the following code to attempt to calculate the normal:
normal = normalize(gl_NormalMatrix * cross(Tan,Bi));
which doesn’t seem to do the job, as I get a black unlit surface with my Phong Directional lighting.
I’ve tried setting normal to the mesh’s original normal using
normal = normalize(gl_NormalMatrix * gl_Normal);
(where normal is a varying vec3)
This results in a lit surface (though obviously it’s not correctly-lit, as the normals from the original plane mesh are incorrect for the distorted mesh).
I infer from this that it’s definitely a problem with the way the normal is calculated.
Anyone know what might be going wrong?
Thanks in advance!