# GLSL Lighting Problem

## Recommended Posts

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 );

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?

##### Share on other sites
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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978697

• 21
• 14
• 12
• 10
• 12