Specular Mapping in the Lighting Equation

I was wondering what is the correct lighting equation for use with specular mapping ? I’m using something like this but the specularity doesn’t seem to be too correct :

FinalColor=
AmbientLight * DiffuseTexture
+DiffuseLight * DiffuseTexture
+SpecularLight* SpecularTexture.r;

Also, where’s the best place to compute the half angle ? vertex or pixel shader ?

What does the specular map store?
If it is for approximating pow(), then your equation looks correct.
I have always computed half angle vector in the VS.

Good question, I thought it was either the specular color or the shining exponent used in pow, but I’m not really sure what it is.

As a note, I already compute

SpecularLight=pow( max( 0.0, n_dot_h),shinyness);

Do you use that same equation in your specular mapping shader and everything looks ok ?

Yes, except I don`t want pow to be called if value is 0.0 because it was causing to return some positive value on certain driver.


float n_dot_h= dot(halflight, normal);
if(dotproduct > 0.0)
   SpecularLight=pow(n_dot_h, shinyness);