导读:
本文转自
http://www.allegro.cc/forums/thread/596061
[OpenGL] FBO and the FB's depth |
Archon
Member #4,195
January 2004
![]() |
I have a complex problem with the framebuffer objects, blending and depth in OpenGL:
In previous threads, I've been asking how to create a FBO as well as use it to implement a 2D lighting system that would be blended straight on top of the scene. But what I need to do is copy the default framebuffer's depth buffer into the lighting FBO's depth buffer so that, when I do the lighting portion of the rendering, the lights wont appear in front of objects where they are supposed to be behind. Either that, or preferably I could just use the depth buffer directly when rendering to the FBO's texture. However, I don't know how to do this. Does this require another extension? Additionally, what could be done about objects that are partially translucent (alpha < 1.0) and where there is supposed to be light behind it? |
Arthur Kalliokoski
Member #5,540
February 2005
![]() |
Quote:
do the lighting portion of the rendering, the lights wont appear in front of objects where they are supposed to be behind.
Does BillG lay awake at night, worrying whether the financial institutions entrusted with his loot are running Windows software?
|
Kitty Cat
Member #2,815
October 2002
![]() |
I think what he's asking for is being able to copy the depth buffer from the main framebuffer (0), that he's already rendered, into the FBO so that drawing to the FBO will be properly affected by the depth test.
The two ways I can think of to do it efficiently would either be to use a PBO (so copy the depth channel like backbuffer->pbo->depth_texture).. or render the scene using the FBO, copy it to the main backbuffer, then clear the FBO's color buffer (leaving the depth buffer alone) to render the lights, then blend that onto the backbuffer.
--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham Got APEG? [kcat.strangesoft.net] |
Archon
Member #4,195
January 2004
![]() |
Quote:
or render the scene using the FBO, copy it to the main backbuffer, then clear the FBO's color buffer (leaving the depth buffer alone) to render the lights, then blend that onto the backbuffer.
However, do you know what I could do about lighting and partially alpha-ed textures? Maybe I'd need to render the scene in three loops: Render normal, solid textures;Does that sound correct? |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote:
However, do you know what I could do about lighting and partially alpha-ed textures?
1) Render opaque objects (roughly sorted near to far) with depth testing and writing on. Most masked images (where alpha is only 1 or 0, but not in between) can be done here with alpha testing turned on. 2) Render translucent objects far to near with depth testing on and depth writing off. 3) Copy the FBO to backbuffer and clear the FBO's color buffer 4) Render lights with depth testing on and depth writing off. 5) Blend the FBO onto the backbuffer and flip
--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham Got APEG? [kcat.strangesoft.net] |
Archon
Member #4,195
January 2004
![]() |
Thanks, I should be OK from that.
If not, I'll just bother you in IRC! |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Quote:
If not, I'll just bother you in IRC!
--
Thomas Fjellstrom - [ website [strangesoft.net]] - [ email [mailto:tfjellstrom@strangesoft.net]] - [ Allegro Wiki] - [ Allegro SVN Snapshots [strangesoft.net]] - [ Allegro TODO] "laughing at people in general is fun" -- X-G | "God Bless Joe Pesci" -- George Carlin [religiousfreaks.com] "Well.. now that you mention it, you are kind of.. nothing." -- Inphernic "I'm sure someone will come along and declare their own stupidity (usually demonstrated with the phrase "old")" -- Thomas Harte "Goto is the buldozer of coding. Sometimes, the buldozer is just the right tool for the job. Not often, but sometimes." -- LordBob |
本文转自
http://www.allegro.cc/forums/thread/596061