View Full Version : Per fragment specular

07-15-2003, 10:15 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

07-15-2003, 11:01 PM
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?

07-15-2003, 11:18 PM
I'd agree it looks like a clamping issue.


07-15-2003, 11:25 PM
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.

07-16-2003, 01:56 AM
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)

07-16-2003, 02:01 AM
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.

07-16-2003, 02:20 AM
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