1
\$\begingroup\$

I'm working on a project in OpenGL. Earlier this week, I successfully implemented Deferred Shading, but I'm not sure how to pass the information from the Deferred Shader to the Post Processing Shader.

glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glViewport(0, 0, int(ScreenSize.x), int(ScreenSize.y)); // Render on the whole framebuffer, complete from the lower left corner to the upper right

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//...Drawing for Opaque objects, pass all transparent objects to a seperate texture
//after having drawn them using Forward Shading

//glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, int(ScreenSize.x), int(ScreenSize.y));

// Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Use our shader
glUseProgram(quad_programID);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gBuffTextures[0]);
glUniform1i(gBuffPosnID, 0);

//More Textures

//Uniforms

glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0 );

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // 2*3 indices starting at 0 -> 2 triangles

glDisableVertexAttribArray(0);

So far this works just fine. Now here's the difficult part - passing the final image to the post processing shader.

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, int(ScreenSize.x), int(ScreenSize.y));

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glUseProgram(post_programID);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gBuffTextures[0]);
glUniform1i(UniformPostImage, 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, gBuffDepthTextures);
glUniform1i(UniformDepthImage, 1);

glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, dirt);
glUniform1i(UniformDirtImage, 2);

glUniform1f(UniformTime, (float)currentTime);

glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0 );

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // 2*3 indices starting at 0 -> 2 triangles

glDisableVertexAttribArray(0);

I'm loading the image from the deferred shader normally, and passing it using:

layout(location = 0) out vec3 image;

All I recieve is the first texture I pass, the position shader. Can anyone tell me how to pass the image from the deferred shader to the post processing shader?

\$\endgroup\$
1
  • \$\begingroup\$ Please ask a single question per post; I removed your secondary question but you are welcome to re-post it on its own. \$\endgroup\$
    – user1430
    Commented Jan 21, 2015 at 16:47

1 Answer 1

1
\$\begingroup\$

Your problem is where you commented out glBindFramebuffer(GL_FRAMEBUFFER, 0);. You need to bind to a different FBO there, otherwise you lose everything you just rendered when you call glClear a couple lines down. Because of this reading from and writing to the same FBO texture at once cannot work. You'll need a separate FBO and texture to write to.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .