Deferred rendering moving light

Started by
1 comment, last by oggs91 9 years, 4 months ago

Hi I was browsing the web for a solution to my problem and I encountered this forum, I am new to graphics and never posted here so I apologise if I posted wrongly somehow. I have also posted this question elsewhere, so I am sorry if cross-posting is against the rule and please don't hesitate deleting this topic if so

I am new to both this site and deferred rendering (and very new to graphics in general), so sorry in advance if the question is bad.
I am in the middle of the implementation of the Light pass for a deferred renderer, the Gbuffer pass is working perfectly.
To test it I have a simple shader
Vertex Shader:


layout(location=0) in vec3 vertex;
uniform mat4 world_mat;
uniform mat4 view_mat;
uniform mat4 persp_mat;

out vec3 v_pos;

void main(void){
v_pos =  (view_mat * world_mat * vec4(vertex,1.0)).xyz; 
gl_Position = persp_mat * vec4(v_pos,1.0);

}
Fragment shader;

    ....

out vec4 col; 

void main(){

vec2 texCoord = gl_FragCoord.xy / textureSize(N_tex, 0); 
vec3 N = texture(N_tex, texCoord).rgb;
float Depth = texture(depthTexture, uv).r;
vec4 light_pos_view_space = (view_mat * light_pos);

vec4 gbuff_pos = vec3(texCoord, Depth,1.0);
gbuff_pos *= 2.0; 
gbuff_pos -= 1.0;
gbuff_pos *= inverse(persp_mat); 

vec3 L = normalize((gbuff_pos - light_pos_view_space).rgb);

col = vec4(vec3(dot(N,L)),1.0);
}
And this shader is called using a sphere centered in the light position. When I render the scene what I obtain is:
udA6p.png
But then if I move the camera around a bit
cCsgF.png
The teapot that was fully lit is now a bit out. More generally as I move the camera the portion of the scene lit varies, it looks like the sphere is a "window" through which I see the scene. Isn't the light supposed to lit always the same portion of scene? What am I doing wrong? The view matrix and persp matrix used in the shader above are the same used to fill the GBuffer.
Thank you
Advertisement

I think you need to do

texCoord *= 2.0;
texCoord -= 1.0;

vec4 gbuff_pos = vec3(texCoord, Depth,1.0);
gbuff_pos *= inverse(persp_mat);

instead.

Henning

http://ogldev.atspace.co.uk/

have a look on the deferred rendering tutorials :)

This topic is closed to new replies.

Advertisement