PDA

View Full Version : Accessing FBO during deferred light pass with combined stencil/depth buffer



saski
02-15-2013, 09:13 AM
Hello,

I've hit a problem during my attempt to write a deferred light shader using stencil light volumes. The combined depth/dtencilbuffer setup looks like this:



glGenTextures(1, &ids[depthbuffer]);
glBindTexture(GL_TEXTURE_2D, ids[depthbuffer]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, dim[0], dim[1], 0,
GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, ids[depthbuffer], 0);


During the lighting pass when the stencil buffer is being set it seems that I cannot access the attached depth buffer and write the final color to the screen at the same time. The problem is being discussed in some tutorials and the solution would be to write the lighting pass into a separate color buffer and then blit the color buffer to the FBOs final color buffer (screen). Is there a smarter solution without the need of creating another buffer and copy the color data around?

Thanks & Regards
Saski

tonyo_au
02-15-2013, 05:56 PM
You cannot read back from a output buffer in a fragment shader. You always need 2 passes. One to write to a buffer and another to read. Put antohter way you cannot attach the same buffer both as an input and an output to the same shader.

debonair
02-15-2013, 11:48 PM
Hey i am trying to implement depth stencil textures with FBO but i get a black o/p. Can you post your code or tell me algorithm to implement stencil textures, it would help me. thanks..

saski
02-17-2013, 02:46 AM
hi! take a look at my last thread: http://www.opengl.org/discussion_boards/showthread.php/180940-Deferred-shading-and-light-volumes?p=1248303#post1248303

regards
saski