Horde3D
http://horde3d.org/forums/

Sharing Depth buffer between stages
http://horde3d.org/forums/viewtopic.php?f=1&t=454
Page 1 of 1

Author:  DarkAngel [ 04.08.2008, 11:39 ]
Post subject:  Sharing Depth buffer between stages

I'm trying to write a real-time glow shader (based on the forward pipeline).

After the geometry stage, I've added a new stage that renders out the glow geometry to a render-target (which will be blurred and then added to the main target buffer).

My problem is that I need to preserve the depth buffer from the geometry stage, so that glow geometry isn't drawn in places where it should be hidden. I haven't looked at the code yet, but it seems that if my temporary glow RenderTarget has depthBuf set to true, then it will use it's own depth buffer, and if it is set to false then it won't use any depth buffer.
Is this correct? And is there a way to use the main depth buffer when rendering to my RenderTarget?
Or perhaps it is sharing the depth buffer, but I require a way to set the depth test to "less or equal" instead of just "less"?

Author:  swiftcoder [ 04.08.2008, 15:45 ]
Post subject:  Re: Sharing Depth buffer between stages

I wanted to to do the same for my atmosphere shaders, so I have been experimenting a bit. At this point, I am not sure it is actually possible using OpenGL. I was able to share a depth texture between 2 FBOs, but I wasn't able to use the main depth buffer with an FBO. Perhaps someone more familiar with the FBO extension can give us some suggestions.

Author:  DarkAngel [ 05.08.2008, 01:15 ]
Post subject:  Re: Sharing Depth buffer between stages

Thanks for the info swift.

The only reason I want to keep the depth buffer is so that I only have to render "glow geometry" in the second stage.

...but I could easily change things so that non-glowing geometry also gets rendered in this stage and simply outputs black pixels. I guess I'll go with that for now.

Author:  marciano [ 05.08.2008, 21:04 ]
Post subject:  Re: Sharing Depth buffer between stages

DarkAngel wrote:
My problem is that I need to preserve the depth buffer from the geometry stage, so that glow geometry isn't drawn in places where it should be hidden. I haven't looked at the code yet, but it seems that if my temporary glow RenderTarget has depthBuf set to true, then it will use it's own depth buffer, and if it is set to false then it won't use any depth buffer.
Is this correct? And is there a way to use the main depth buffer when rendering to my RenderTarget?

Funnily I was thinking about a similar issue very recently. It would make sense in several scenarios to share a depth buffer between render targets. Currently that is not possible with the pipelines. From GL side I also don't think that it works to share the main framebuffer depth data with a FBO. But as swift states it should be possible to share depth attachments between several FBOs. We just would need a nice way of exposing that feature to the pipeline (call for proposals :) )

A workaround for your problem could be to bind the depth texture of your temporary render target and draw a fullscreen quad to the main buffer that copies over the depth values by setting gl_FragDepth in a very small fragment shader.

Author:  DarkAngel [ 06.08.2008, 07:48 ]
Post subject:  Re: Sharing Depth buffer between stages

Yes, it seems the spec says that when an FBO is bound, you can't access the default depth-buffer.
Quote:
Additionally, when rendering to or reading from an application
created-framebuffer object,
...
- The only depth buffer bitplanes are the ones defined by the
framebuffer attachment point DEPTH_ATTACHMENT_EXT.


I'll have a think about the nicest way to share depth attachments between RenderTargets. Perhaps we could implement a generic technique so that colour attachments could be shared as well?

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/