Well, I'm experiencing a bug with shaders. The lighting get's off, as the camera rotates. See:
Screenshot1: lighting is ok
Screenshot2: rotating the camera a bit upwards - the lighting get's off
Screenshot3: rotating the camera a bit more - lighting is totally off by now.
Now, I suspect this problem might have to have something to do with normals. I store normals in a render texture, and then later reconstruct these normals on light volumes. (I do all lighting in view space)
How i store the normals in the vertex shader:
Code: Select all
Normal= normalize((gl_NormalMatrix * gl_Normal)).xy;
Normal*= 0.5;
Normal+= 0.5
I then reconstruct the normals as follows:
Code: Select all
vec4 vNormal= texture2D(NormalTex, projCoord.xy);
vNormal.xy*= 2.0;
vNormal.xy-= 1.0;
vNormal.z= -sqrt( -(vNormal.x*vNormal.x) - (vNormal.y*vNormal.y) + 1.0 );
vNormal= normalize(vNormal);
The other option is that the light position is transformed incorrectly from world to view space. Though i doubt it(cos the direction at spot lights gets rotated correctly), here is how I do this(irrlicht)
Code: Select all
irr::core::matrix4 viewMat= Smgr->getVideoDriver()->getTransform(irr::video::ETS_VIEW);
viewMat.transformVect(Pos);
Any ideas will be welcome, as I can't seem to be able to solve this.