Jump to content
  • Advertisement
Sign in to follow this  

Deferred rendering moving light

This topic is 1475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
But then if I move the camera around a bit 
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

Share this post

Link to post
Share on other sites

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






Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!