Specular Problem

I noticed a strange situation:
I use one infinite direction light with (0,1,0) orientation and a cube with specular materials enabled.Lighting in flat surfaces that are parallel to the light direction is appearing to “flicker” when i change my view instead of moving smooth from dark to bright and dark again,like when i am rendering a sphere or a cylinder.

You have to split up the flat surface into more triangles to get it smoother.

Mikael

Originally posted by mikael_aronsson:
[b]You have to split up the flat surface into more triangles to get it smoother.

Mikael[/b]

I’ve done that,nothing changed.
The problem is not the smoothness of the shading.I think I figured out what’s wrong,but i don’t know how to fix it.

I am pretty sure that if the dot product of the surface normal and the light direction is negative,the specular highlights are off.This is kind of strange,because normals are not part of the specular lighting equation.In my case,the surface normal is (0,0,1) and the light direction is (0,1,0),so their dot product is exactly 0.When rotating the view,those two are rotated as well,using the modelview matrix.It seems then that their dot product is not exactly zero but varies in the range[-x,x],where x is a really small value.So when the dot product is [0,x] the speculars are on and when it is [-x,0] the speculars are off.The problem has to do with precision,obviously,but how can we deal with it?

I think that this artifact is not visible with diffuse lighting(although it too is set off when the dot product is negative)because at the range[-x,x] the diffuse reflectance is really small,close to zero.But the specular reflectance can be any considerable value,so the “blinking” when specular goes off and on is very noticeable.

[This message has been edited by mikeman (edited 02-09-2004).]