http://antongerdelan.net/opengl/index.php?title=Specular_mapping#Shaders

My vertex shader (my vpeye and vneye is different):

uniform mat4 lightMatrix; uniform vec3 lightPos; uniform vec3 lightDir; varying vec4 lpos; varying vec3 normal; varying vec3 light_vec; varying vec3 light_dir; out vec4 vpeye; // vert positions in eye coords out vec4 vneye; // normals in eye coords void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; vec4 vpos = gl_ModelViewMatrix * gl_Vertex; lpos = lightMatrix * vpos; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; vpeye = gl_ModelViewMatrix * gl_Vertex; vneye = normalize(vec4(gl_NormalMatrix * gl_Normal, 0)); light_vec = vpos.xyz - lightPos; light_dir = gl_NormalMatrix * lightDir; normal = normalize(gl_NormalMatrix * gl_Normal); gl_FrontColor = gl_Color; }

Fragment:

uniform sampler2D texture1; uniform sampler2D texture2; uniform sampler2D shadowMap; uniform sampler2D texture4; varying vec4 lpos; varying vec3 normal; varying vec3 light_vec; varying vec3 light_dir; in vec4 vpeye; in vec4 vneye; void main (void) { vec3 smcoord = lpos.xyz / lpos.w; float shadow = max(0.5, float(smcoord.z <= texture2D(shadowMap, smcoord.xy).x)); vec3 lvec = normalize(light_vec); float diffuse = max(dot(-lvec, normal), 0.0); vec4 s_eye = normalize(vec4(lpos - vpeye)); // direction from point to light vec4 v_eye = normalize(-vpeye); // direction from point to viewer vec4 r_eye = reflect(-s_eye, vneye); // reflect vector from light to point based on normal vec4 texColor = texture2D(texture1, gl_TexCoord[0].st) * texture2D(texture2, gl_TexCoord[1].st); vec4 spec = texture2D(texture4, gl_TexCoord[0].st) * pow(max(dot(r_eye, v_eye), 0), 128); gl_FragColor = vec4(gl_Color.xyz * texColor.xyz * diffuse * shadow * 3.0 + spec.xyz, gl_Color.w * texColor.w); //gl_FragColor = vec4(vec3(1,1,1) * pow(max(dot(r_eye, v_eye), 0), 10), 1); }

**Edited by polyfrag, 09 November 2012 - 11:16 PM.**