GLSL Lighting Problem

Started by
0 comments, last by Lord Faron 17 years, 9 months ago
Hey, I'm adding normal mapping to a Quake 3 BSP map via a GLSL shader, and so far, everything has worked great. However, I've come to a problem with regards to my light in the scene (there is currently only one) moving with my camera. I'm guessing this is a matrix error somewhere, but so far I haven't been able to correct it. When the camera shifts left, the light moves with it, and when rotated, does the same. Weird. Here is my rendering code:

void RenderScene() 
{
	glLightfv (GL_LIGHT0,GL_POSITION,g_lightpos);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	Camera.Look();  //Note: Camera.Look() just calls gluLookAt...could this 
                        //be the problem?

	BSP.Render(Camera.Position());

	SwapBuffers(g_hDC);	
}
And here is my vertex shader:

varying vec4 pos;

void main( void )
{
	gl_Position = ftransform();
	pos = gl_ModelViewMatrix * gl_Vertex;
	gl_TexCoord[0] = gl_MultiTexCoord0;
}
The BSP level is rendered fine. Any ideas?
Advertisement
Setting fixed-function light postion has to be done in eye space. So call
glLightfv (GL_LIGHT0,GL_POSITION,g_lightpos);

after You called Camera.Look();

BTW. If You want to use GLSL then using uniforms and pixel shaders instead fixed-fuction lights gives better results.
if (time() == $) { $ = 0; }

This topic is closed to new replies.

Advertisement