I’ve decided to give up on the textures until I know the normals are coming out right.
So I have a simple vertex shader that allows you to rotate a 3D object around the Y axis, and of course the first thing I noticed is that the lighting/shading does not adjust itself to the rotation. That is, the light is out front, but when you rotate the object, the shading on it corresponds to it’s original, unrotated position. How do I deal with this?
void rotateY (inout vec4 vert, float rads);
uniform float YRot;
varying float Diffuse;
void main() {
rotateY (gl_Vertex, YRot);
vec3 vnormal = normalize(gl_NormalMatrix * gl_Normal);
Diffuse = max(dot(vnormal, gl_LightSource[0].position.xyz), 0.0);
gl_Position = ftransform();
}
void rotateY (inout vec4 vert, float rads) {
vec4 old = vert;
mat2 rotY = mat2(cos(rads), -sin(rads), sin(rads), cos(rads));
vert.xz = old.xz * rotY;
}
The lighting math I took from the “Swiftless Game Programming Site” which seems very good; I’d like to move on to per-pixel lighting but need to understand some things about this first.