Deferred light position problem

Hi, I am attempting to make a light pre pass shader. Ive almost got it working, however it only seems to work as expected when the camera is looking in one direction. When the camera is turned the lighting isnt calculated correctly. I am assuming this is something wrong with my world>view calculations of the lighting. But i cant seem to adjust it so that it works.

I am passing in a vector of (0,10,0,1) (without the 1, nothing seems to render). And I would expect the light to be at 0,10,0.

in the vertex shader to convert the vector to view space I use:
viewSpaceLightPos = gl_ModelViewMatrix * worldSpaceLightPos;

and to calculate the lighting I use (view ray is the translated vertex of the lighting sphere):
vec3 normalViewRay = normalize(viewRay.xyz/viewRay.www);
vec3 pixPos = normViewRay*vec3(normalDepth.b);
vec3 pixelToLight = viewSpaceLightPos.xyz-pixPos;
vec3 normPixelToLight = normalize(pixelToLight);
float localLightdist = length(pixelToLight);

So does anyone have ideas?

Thanks

Is your ModelView matrix an identity matrix?

Nope its not

If your worldSpaceLightPos is (0,10,0,1) and your ModelView matrix isn’t an identity matrix, then there’s a good chance your viewSpaceLightPos isn’t (0,10,0,1) if that’s what you were expecting.

Instead of gl_ModelViewMatrix, consider using your camera’s transform matrix against your worldSpaceLightPos to get it into view space. Alternatively, you can always try placing your light using glLight and then using gl_LightSource[x].position in the shader.

I wouldnt be expecting that, the camera would be moving all over the place, so the viewspace coords would be different everyframe. I really dont see why gl_ModelViewMatrix wouldnt be transforming into view space correctly. I will try using the cameras transform matrix.