Rate This Topic

讨论了使用帧缓冲对象(FBO)进行渲染时遇到的问题,特别是如何正确地处理透明度(alpha)通道,确保渲染到FBO的内容能正确显示为透明而非黑色背景。
导读:
  gbiv
  Newbie
  Registered: 07/03/04
  Posts: 39
  Loc: ISU VRAC
  Hello,
  I'd like to create a RTT using an FBO which I then use as a texture on a billboard. My problem is that I'm not able to generate a texture that has "alpha" values. For instance if it were a tree that I rendered in the FBO, I'd try to set my clear color to (0,0,0,0) and then render my tree model in the FBO to create the texture. The output however has the tree surrounded by black rather than "clear". Is this the correct behavior or should I be able to setup the FBO properly to create a the texture properly?
  thanks for any input.
  biv
  #237025- 04/14/0801:38 AM Re: FBO's and alpha[Re: gbiv]
  k_szczech
  OpenGL Pro
  
  
  Registered: 02/20/06
  Posts: 1026
  Loc: Poland
  Explain "tree surrounded by black". Do you mean that your entire texture is black, or do you see black edge aroud the tree?
  If you're experiencing the 'black edge' problem, then it's because pixels of texture are filtered with black background pixels. The simplest solution would be to enable alpha testing when rendering tree from texture and set alpha test to (GL_GREATER, 0.95f).
  The nicest solution would be to perform blur on the texture after you rendered tree into it. Texels with alpha >0 should copy their color to neighbour texels that have alpha = 0, but alpha should not be copied.
  #237030- 04/14/0804:28 AM Re: FBO's and alpha[Re: k_szczech]
  babis
  Contributor
  Registered: 12/09/07
  Posts: 76
  Loc: Hull, UK
  For the 'black edge' problem :
  It's even nicer solution,if you can afford it, to render first the blurred tree on the texture ( without writing to alpha as k_szczech said ) &then layer upon it the 'normal' rendered tree. This way you have no blurring on the inside (where alpha == 1)
  #237032- 04/14/0806:17 AM Re: FBO's and alpha[Re: gbiv]
  Dark Photon
  Regular Contributor
  Registered: 10/06/04
  Posts: 191
  Loc: Arlington, TX
   Originally Posted By: gbiv
  I'm not able to generate a texture that has "alpha" values....The output however has the tree surrounded by black rather than "clear".
  This will solve your problem:
  Tom Forsyth's Blog(See Pre-multiplied Alpha article)
  Bottom line: stop using SRC_ALPHA / ONE_MINUS_SRC_ALPHA blending. Use ONE / ONE_MINUS_SRC_ALPHA blending, and pre-multiply the alpha into the color components. Edited by Dark Photon (04/14/0806:19 AM)
  #237051- 04/14/0801:19 PM Re: FBO's and alpha[Re: k_szczech]
  gbiv
  Newbie
  Registered: 07/03/04
  Posts: 39
  Loc: ISU VRAC
  Sorry for the late responses here. By that I mean, the tree renders as expected on the textured quad however the entire quad is visible. The portion of the quad that is not the tree (not just the border of the tree) is black (or whatever I set my clear color to) rather than completely transparent, so the "illusion" of the billboarded trees is lost because you can tell it's just a textured quad. Did that make sense or do I need to post some pics for clarity?
  #237054- 04/14/0802:02 PM Re: FBO's and alpha[Re: gbiv]
  babis
  Contributor
  Registered: 12/09/07
  Posts: 76
  Loc: Hull, UK
  ok so you either got no alpha at all, or you have but you don't use it. How do you render to the texture? &how do you draw it afterwards?
  #237057- 04/14/0803:03 PM Re: FBO's and alpha[Re: babis]
  zed
  OpenGL Guru
  Registered: 07/06/00
  Posts: 2444
  Loc: S41.16.25 E173.16.21
   Quote:
  were a tree that I rendered in the FBO, I'd try to set my clear color to (0,0,0,0) and then render my tree model in the FBO to create the texture. The output however has the tree surrounded by black rather than "clear".
  yes thats the correct behaviour
  glClearColor(...) clears the buffer to that color, it doesnt make that color invisible
  to make the black invisible u have to set those pixels alpha values to say 0.0 (+ the trees pixels alpha values to 1.0) + then do alphatesting or blending etc
  i suppose u could in a shader make black invisible by going
  if ( dot( vec3(0.0), texture_value ) >0.99 )
  discard;
  but #A its pretty messy + #B its gonna be slower
  #237087- 04/15/0805:46 AM Re: FBO's and alpha[Re: zed]
  Dark Photon
  Regular Contributor
  Registered: 10/06/04
  Posts: 191
  Loc: Arlington, TX
   Originally Posted By: zed
   Quote:
  I'd try to set my clear color to (0,0,0,0) and then render my tree model in the FBO to create the texture. The output however has the tree surrounded by black rather than "clear".
  yes thats the correct behaviour
  glClearColor(...) clears the buffer to that color, it doesnt make that color invisible
  Well, he said he cleared to 0,0,0,0, which has alpha = 0, which by convention is 100% transparent. Something else much be wrong. Such as rendering with BLEND disabled or some such.
  babis, check the alpha values in your edge texels in your texture and make sure their alpha is 0. Also check that when you're blending this texture onto the frame buffer you have BLEND mode enabled:
   Code:
  
  glEnable ( GL_BLEND ) ;
  glBlendFunc ( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
  glBlendEquation ( GL_FUNC_ADD ) ;
  #237096- 04/15/0808:32 AM Re: FBO's and alpha[Re: Dark Photon]
  gbiv
  Newbie
  Registered: 07/03/04
  Posts: 39
  Loc: ISU VRAC
  Hello all, thanks for the replies. I've tried most of these but with no success. I think this has to do with my FBO setup. However, I'm not sure how to get around the problem if the clear color isn't setting alpha values in the FBO:
  Here are some screen shots of my problem:
  http://www.vrac.iastate.edu/~biv/fbo_clear_color_problem/clearcolor_black_alpha_0.tiff
  http://www.vrac.iastate.edu/~biv/fbo_clear_color_problem/clearcolor_red_alpha_0.tiff
  The flag is textured with the results of rendering the fire to my FBO. No matter what I set the clear color to, the texture doesn't seem to have any alpha information from the FBO outside of the object that I'm rendering (in this case the fire) so even if my texenv is set to REPLACE, the texture still retains the clear color as is shown on the flag. My texture is of format RGBA and is a color buffer attachment to my FBO so I think this is correct...
  I'm not sure how to access those texels without adding some extra pass to post process the texture info as zed suggested, and I agree, this could get messy. Can anyone else reproduce this problem with a simple FBO rtt? This could help me narrow down if the problem is in my code or not.
  Again thanks for the input here.
  biv
  #237103- 04/15/0801:22 PM Re: FBO's and alpha[Re: gbiv]
  zed
  OpenGL Guru
  Registered: 07/06/00
  Posts: 2444
  Loc: S41.16.25 E173.16.21
   Quote:
  Well, he said he cleared to 0,0,0,0, which has alpha = 0
  i believe those alpha values are the destination alpha values eg GL_DST_ALPHA
  i think what gbiv wants is SRC_ALPHA (ie from the texture)
  ok looked at the screenshot i think he wants
  A/ first to draw textureA(fire) into a FBO textureB
  B/ draw this textureB onto a polygon onscreen
  perhaps try
  A/ set the textureB alphavalues from the textureA alphavalues (many ways of doing this)
  B/ draw this texture onscreen with GL_DST_ALPHA, GL_ONE

本文转自
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=237057
【源码免费下载链接】:https://renmaiwang.cn/s/in99a PDFMerge 是一个实用工具,主要用于将多个独立的PDF文件整合到一个单一的PDF文档中,这对于管理和分享大量的PDF文档非常有帮助。这个工具基于JavaScript开发,因此它可以在Web环境中运行,无需安装任何桌面应用程序。在JavaScript开发领域,这样的工具属于“其它杂项”类别,可能涉及到前端开发、文件处理以及用户交互等多个方面。在JavaScript开发中,实现PDFMerge功能通常会涉及到以下几个关键知识点:1. **文件读取和处理**:JavaScript中的`FileReader` API用于读取用户上传的PDF文件。通过`readAsArrayBuffer`方法,可以将PDF文件转换为二进制数据,为后续的合并操作做准备。2. **PDF解析**:为了合并PDF,需要理解PDF文件的结构。虽然JavaScript中没有内置的PDF解析库,但有一些开源库如`pdfjs-dist`可以帮助解析PDF文档。这些库能解析PDF文件并提取必要的信息,如页面、元数据等。3. **PDF合并**:合并PDF文件的关键在于将各个PDF的页面添加到新的PDF文档中。这通常涉及到创建一个新的PDF文档对象,然后将旧PDF的页面对象复制到新文档中。使用开源库如`pdf-lib`或`PDF.js`可以实现这一过程。4. **文件操作与导出**:完成合并后,需要将新PDF以二进制形式写回,通常会用到`Blob`和`URL.createObjectURL`来生成一个可下载的URL。用户可以通过点击链接下载合并后的PDF。5. **用户界面设计**:为了方便用户使用,需要设计一个友好的用户界面。这包括文件选择控件、进度指示器、错误提示等。React、Vue或Angular等前端框架可以用来构建这样
【源码免费下载链接】:https://renmaiwang.cn/s/crqbb 微信小程序是一种轻量级的应用开发平台,主要用于在微信内提供便捷的服务和丰富的用户体验。这个"微信小程序-商城功能(书店).zip"压缩包显然包含了用于构建一个专门针对书店的微信小程序商城的源代码和资源文件。下面我们将深入探讨相关的知识点。1. **微信小程序基础**:微信小程序是由腾讯公司推出的一种不需要下载安装即可使用的应用,它实现了“触手可及”的梦想,用户扫一扫或搜索即可打开应用。开发者可以使用微信提供的开发工具和框架进行开发。2. **小程序架构**:微信小程序基于 JavaScript、WXML 和 WXSS 三者构建。JavaScript 负责业务逻辑,WXML(WeiXin Markup Language)负责结构描述,而 WXSS(WeiXin Style Sheet)则用于样式设计。3. **商城功能**:商城功能是微信小程序中常见的一种应用场景,包括商品展示、购物车、订单管理、支付、用户评价等模块。在这个书店小程序中,可能包含书籍分类、搜索、详情展示、购买流程等功能。4. **书籍管理**:书籍数据通常存储在后台数据库中,通过API接口与小程序交互。每个书籍条目应包含书名、作者、出版社、价格、库存等信息,以及书籍封面图片。5. **用户界面设计**:WXML 和 WXSS 的组合使得开发者可以创建出原生感强、响应式的界面。书店小程序可能会有轮播图、商品列表、商品详情页、购物车页面等。6. **支付功能**:微信小程序内置了微信支付接口,开发者需要配置商户号、支付密钥等安全参数,用户可以通过小程序直接完成支付操作。7. **订单系统**:订单管理是商城功能的核心部分,包括下单、确认收货、退款/售后等流程。开发者需要设计数据库模型来存储订单信息,如订单号、商品信息、用户信息、状态
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值