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
#include "ros/ros.h" #include "std_msgs/String.h" #include <sstream> /** * This tutorial demonstrates simple sending of messages over the ROS system. */ int main(int argc, char **argv) { /** * The ros::init() function needs to see argc and argv so that it can perform * any ROS arguments and name remapping that were provided at the command line. For programmatic * remappings you can use a different version of init() which takes remappings * directly, but for most command-line programs, passing argc and argv is the easiest * way to do it. The third argument to init() is the name of the node. * * You must call one of the versions of ros::init() before using any other * part of the ROS system. */ ros::init(argc, argv, "talker"); /** * NodeHandle is the main access point to communications with the ROS system. * The first NodeHandle constructed will fully initialize this node, and the last * NodeHandle destructed will close down the node. */ ros::NodeHandle n; /** * The advertise() function is how you tell ROS that you want to * publish on a given topic name. This invokes a call to the ROS * master node, which keeps a registry of who is publishing and who * is subscribing. After this advertise() call is made, the master * node will notify anyone who is trying to subscribe to this topic name, * and they will in turn negotiate a peer-to-peer connection with this * node. advertise() returns a Publisher object which allows you to * publish messages on that topic through a call to publish(). Once * all copies of the returned Publisher object are destroyed, the topic * will be automatically unadvertised. * * The second parameter to advertise() is the size of the message queue * used for publishing messages. If messages are published more quickly * than we can send them, the number here specifies how many messages to * buffer up before throwing some away. */ ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000); ros::Rate loop_rate(10); /** * A count of how many messages we have sent. This is used to create * a unique string for each message. */ int count = 0; while (ros::ok()) { /** * This is a message object. You stuff it with data, and then publish it. */ std_msgs::String msg; std::stringstream ss; ss << "hello world " << count; msg.data = ss.str(); ROS_INFO("%s", msg.data.c_str()); /** * The publish() function is how you send messages. The parameter * is the message object. The type of this object must agree with the type * given as a template parameter to the advertise<>() call, as was done * in the constructor above. */ chatter_pub.publish(msg); ros::spinOnce(); loop_rate.sleep(); ++count; } return 0; } #include "ros/ros.h" #include "std_msgs/String.h" /** * This tutorial demonstrates simple receipt of messages over the ROS system. */ void chatterCallback(const std_msgs::String::ConstPtr& msg) { ROS_INFO("I heard: [%s]", msg->data.c_str()); } int main(int argc, char **argv) { /** * The ros::init() function needs to see argc and argv so that it can perform * any ROS arguments and name remapping that were provided at the command line. For programmatic * remappings you can use a different version of init() which takes remappings * directly, but for most command-line programs, passing argc and argv is the easiest * way to do it. The third argument to init() is the name of the node. * * You must call one of the versions of ros::init() before using any other * part of the ROS system. */ ros::init(argc, argv, "listener"); /** * NodeHandle is the main access point to communications with the ROS system. * The first NodeHandle constructed will fully initialize this node, and the last * NodeHandle destructed will close down the node. */ ros::NodeHandle n; /** * The subscribe() call is how you tell ROS that you want to receive messages * on a given topic. This invokes a call to the ROS * master node, which keeps a registry of who is publishing and who * is subscribing. Messages are passed to a callback function, here * called chatterCallback. subscribe() returns a Subscriber object that you * must hold on to until you want to unsubscribe. When all copies of the Subscriber * object go out of scope, this callback will automatically be unsubscribed from * this topic. * * The second parameter to the subscribe() function is the size of the message * queue. If messages are arriving faster than they are being processed, this * is the number of messages that will be buffered up before beginning to throw * away the oldest ones. */ ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback); /** * ros::spin() will enter a loop, pumping callbacks. With this version, all * callbacks will be called from within this thread (the main one). ros::spin() * will exit when Ctrl-C is pressed, or the node is shutdown by the master. */ ros::spin(); return 0; }更改为三个节点形成消息的循环传递
10-27
内容概要:本文档是一份关于交换路由配置的学习笔记,系统地介绍了网络设备的远程管理、交换机与路由器的核心配置技术。内容涵盖Telnet、SSH、Console三种远程控制方式的配置方法;详细讲解了VLAN划分原理及Access、Trunk、Hybrid端口的工作机制,以及端口镜像、端口汇聚、端口隔离等交换技术;深入解析了STP、MSTP、RSTP生成树协议的作用与配置步骤;在路由部分,涵盖了IP地址配置、DHCP服务部署(接口池与全局池)、NAT转换(静态与动态)、静态路由、RIP与OSPF动态路由协议的配置,并介绍了策略路由和ACL访问控制列表的应用;最后简要说明了华为防火墙的安全区域划分与基本安全策略配置。; 适合人群:具备一定网络基础知识,从事网络工程、运维或相关技术岗位1-3年的技术人员,以及准备参加HCIA/CCNA等认证考试的学习者。; 使用场景及目标:①掌握企业网络中常见的交换与路由配置技能,提升实际操作能力;②理解VLAN、STP、OSPF、NAT、ACL等核心技术原理并能独立完成中小型网络搭建与调试;③通过命令示例熟悉华为设备CLI配置逻辑,为项目实施和故障排查提供参考。; 阅读建议:此笔记以实用配置为主,建议结合模拟器(如eNSP或Packet Tracer)动手实践每一条命令,对照拓扑理解数据流向,重点关注VLAN间通信、路由选择机制、安全策略控制等关键环节,并注意不同设备型号间的命令差异。
多旋翼无人机组合导航系统-多源信息融合算法(Matlab代码实现)内容概要:本文围绕多旋翼无人机组合导航系统,重点介绍了基于多源信息融合算法的设计与实现,利用Matlab进行代码开发。文中采用扩展卡尔曼滤波(EKF)作为核心融合算法,整合GPS、IMU(惯性测量单元)、里程计和电子罗盘等多种传感器数据,提升无人机在复杂环境下的定位精度与稳定性。特别是在GPS信号弱或丢失的情况下,通过IMU惯导数据辅助导航,实现连续可靠的位姿估计。同时,文档展示了完整的算法流程与Matlab仿真实现,涵盖传感器数据预处理、坐标系转换、滤波融合及结果可视化等关键环节,体现了较强的工程实践价值。; 适合人群:具备一定Matlab编程基础和信号处理知识,从事无人机导航、智能控制、自动化或相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于多旋翼无人机的高精度组合导航系统设计;②用于教学与科研中理解多传感器融合原理与EKF算法实现;③支持复杂环境下无人机自主飞行与定位系统的开发与优化。; 阅读建议:建议结合Matlab代码与理论推导同步学习,重点关注EKF的状态预测与更新过程、多传感器数据的时间同步与坐标变换处理,并可通过修改噪声参数或引入更多传感器类型进行扩展实验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值