Shader problem:normal and negative scaling

I try to inverse x axis of my model by calling scalef(-1.0f,1.0f,1.0f);
the vertex position turn out right but the lighting is incorrect.

eg.
when light is on the left side of the x-inverse model the right side of the model become lit.

In my shader I already Multiply gl_Normal with gl_NormalMatrix before lighting calculation.

Please help me this is the first time I encouter this problem (never use scaling before )

Of course! You have to invert also the x coordinate of the normals :slight_smile:

does this mean invert has to be seperate from scaling term for the lighting to turn out right ?

I thought that gl_NormalMatrix already take care of scaling normal.

Update:

It look like my two side lighting implementation caused the problem.

In order to implement two side lighting , I have this code in fragment program of deferred shader geomatric pass.

if(gl_FrontFacing == false){
normalizedNormal *= -1.0;
}

but it look like when scaling with negative value, facing of the polygon will also be reverse.

I known this by call glCullFace(GL_BACK) and all the front face of the geometry are culled in stead of the back face.

so I fixed this by adding

if(gl_FrontFacing == false){
normalizedNormal *= -1.0;
}
normalizedNormal *= scaleX;

scaleX is the value taken from localMatrix[0].x (x scaling term)

But I am not sure if this a safe way to fix the problem.

Please someone give me some advice.