Skip to main content
deleted 265 characters in body; edited title
Source Link
user1430
user1430

Using a FrameBuffer Twice in OpenGL What's wrong with my method of getting intermediate rendering to my postprocessing shader?

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? Thanks in advance!

Oh, one more question: Do you suggest getting depth via a depth buffer texture in the deferred shader, or just using the world position to calculate it? I know it probably depends on the machine, but there's probably a general go-to answer.

Using a FrameBuffer Twice in OpenGL

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? Thanks in advance!

Oh, one more question: Do you suggest getting depth via a depth buffer texture in the deferred shader, or just using the world position to calculate it? I know it probably depends on the machine, but there's probably a general go-to answer.

What's wrong with my method of getting intermediate rendering to my postprocessing shader?

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?

Tweeted twitter.com/#!/StackGameDev/status/550324626006765568
Source Link

Using a FrameBuffer Twice in OpenGL

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? Thanks in advance!

Oh, one more question: Do you suggest getting depth via a depth buffer texture in the deferred shader, or just using the world position to calculate it? I know it probably depends on the machine, but there's probably a general go-to answer.