Problem will fragment program lighting when scalef is used

Hello.
I use an ARB_vertex_program and an ARB_fragment_program to do the lighting.
When I rotate or translate some object the lighting is correct. But when I try to scalef something then the ligting is wrong.
eg: if i use glScalef(0.1, 0.1, 0.1) before I render the object it seems like the light radius also is divided 0.1.
I have hear a lot of people have the same problem… what is the solution about this problem?
thanks in advance.

Hello,
Maybe there’s a missing normalization of your light vector in your fragment program - if you do some kind of phong based lighting.

Don’t know if it is applyable to fragments too, but i think you could use or
glEnable(GL_NORMALIZE);
or
glEnable(GL_RESCALE_NORMAL);

If you’re using a VP, you’ll need to re-normalize vectors yourself after their transform.

It’s more correct to do this renormalization in the fragment program, but it may be cheaper on some hardware to do it in the vertex program.

When you transform normals, you transform them by the inverse transpose of the modelview matrix. If the modelview matrix has a scale factor in it, then the inverse of that matrix has an equivalent reciprocal scale.

In the general case, you just have to renormalize, but if the scale is uniform ( glScalef( a, a, a) )
then the constant scale factor can be applied to
the matrix “for free”. Not so lucky for non-uniform scales though ( glScalef( a, b, c) ).
The only right answer there is to renormalize.

I was thinking to just multiply the vector pointing to the light by the scale factor. (scale will be always like this: glScalef(a,a,a) :wink:

I done it and it works. It seems very cheap to me because I only execute one instruction:

MUL lightVec, lightVec, ScaleFactor;

Is it correct? maybe I am gonna have problems somewere else?

One thing to be aware of is that interpolating two vectors will cause them to denormalize.

If you’re trying to renormalize in the fragment program, you really need to use “real” normalization.

If you’re doing vertex lighting, the rescale approach is just fine.