I've run through this so many times I think I've created a block for myself. Right now I have this vertex shader (GLSL):
varying vec3 V, N;
void main(void)
{
// set the vertex position
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
// setup lighting
V = gl_ModelViewMatrix * gl_Vertex;
N = gl_NormalMatrix * gl_Normal;
// setup texturing
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
}
and this fragment shader:
uniform sampler2D detail, normalmap;
varying vec3 V, N;
void main(void)
{
vec3 normal = normalize(2.0 * texture2D(normalmap, gl_TexCoord[1]).xyz - 1.0);
vec3 L = normalize(gl_LightSource[0].position.xyz - V);
vec3 E = normalize(-V);
float diffuse = dot(normal, L);
vec3 R = normalize(2.0 * diffuse * normal - L);
// ambient
vec4 Iamb = gl_FrontLightProduct[0].ambient;
// diffuse
vec4 Idiff = gl_FrontLightProduct[0].diffuse * diffuse;
// specular
float specular = pow(max(dot(R, E), 0.0), gl_FrontMaterial.shininess);
vec4 Ispec = gl_FrontLightProduct[0].specular * specular;
// final color
vec4 tv = texture2D(detail, gl_TexCoord[0]);
gl_FragColor = tv * (gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec);
}
But I'm getting an odd clipping effect of some kind. I think it's actually just light being applied in odd places, but it basically looks like if you had binoculars and moved them down and to the right, so you could only see the bottom left of what you're looking at, through a semi-circle. Hard to describe, I know, but that's basically it. I can grab a screenshot if that would help.
I guess I'm just completely lost on how to use GLSL to make use of Doom3 style normal maps. I figured it'd just be a matter of doing a lookup in the texture to grab the normal, but that doesn't seem to be working.
Thanks in advance for any help.