FBO and the FB's depth

导读:





[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.
Could you reword that please? It makes my brain go into an infinite loop.
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.
Good idea KC. Thanks.

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;

Turn on depth mask (or is it the other way around?)
Render partially-alpha textures
Render pixel lighting texture
Turn off depth mask
Flip backbuffer
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?
Translucent textures/objects are done after the main scene:
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!
Oh thanks now KC will never be alive in #allegro >:E
--
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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值