Per fragment specular

Hi! After finishing the vertex program point light I decided to move on to per fragment lighting. All went well until I implemented the specular component. Now it looks like in the pictures below. Sharp borders appear where there’s supposed to be a soft transition. If I set specular to 0 everything looks as it’s supposed to look.
http://www.itstudents.ch/users/dave/files/pfspec0.jpg http://www.itstudents.ch/users/dave/files/pfspec1.jpg

Thanks again dave for providing web-space

Looks like you’re getting negative values from your specular.
Try using DP3_SAT so as to clamp your result. Doesn’t really look specularly lit though, just a low exponent?

I’d agree it looks like a clamping issue.

Y.

Thanks for your replies! Yes you’re right, it’s a clamping-isssue and I think I found the problem. I used the wrong specular exponent for some reason. It now looks quite ok! Thanks again.

It looks right to me.

That’s how specular component is defined in OpenGL : clamped if the diffuse contribution is null (i.e. if the dot product between normal and light direction is negative).

To smoothen the clamping, you might modulate the specular contribution with this dot product. Something like :
final_specular_contribution = specular_contribution * (N_dot_L ^ 8)

dbugger: changing the specular exponent might reduce that clamping effect, but it does not disappear. If you move the light and the camera, you will sometimes notice that the specular highlight is still clamped.

Yes I know! But in the pics the exponent is VERY wrong. Using the correct exp (fetched from model file) the clamping can’t be spotted at all.
Thanks / David