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