opengl z 排序透明度
我在opengl es 2.0中的简单正方形上渲染png,但是当我尝试在正方形后面绘制一些东西时,我已经在顶部正方形中绘制了透明区域,并呈现与背景相同的颜色。
我在每次渲染调用开始时调用这些。
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
im rendering png's on simple squares in opengl es 2.0, but when i try and draw something behind an square i have already drawn the transparent area in my top square are rendered the same color as the background.
I am calling these at the start of every render call.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的标题本质上就是你问题的答案!
一般来说,透明度是通过首先渲染场景中的所有不透明对象(让 z 缓冲区找出可见的对象),然后从后到前渲染所有透明对象来完成的。
Your title is essentially the answer to your question!
Generally transparency is done by first rendering all opaque objects in the scene (letting the z-buffer figure out what's visible), then rendering all transparent objects from back to front.
Drew Hall 给了您一个很好的答案,但另一种选择是使用
glAlphaFunc(GL_GREATER, 0.1f)
设置glEnable(GL_ALPHA_TEST)
。这将完全阻止透明像素(在本例中,alpha < 0.1f 的像素)被渲染。这样它们就不会写入 Z 缓冲区,并且其他内容可以“显示出来”。但是,这仅适用于完全透明的对象。无论 0.1 alpha 边缘在哪里,它都具有粗糙的边缘,对于像素比对象大的远处特征来说,这可能看起来很糟糕。Drew Hall gave you a good answer but another option is to set
glEnable(GL_ALPHA_TEST)
withglAlphaFunc(GL_GREATER, 0.1f)
. This will prevent transparent pixels (in this case, ones with alpha < 0.1f) from being rendered at all. That way they do not write into the Z buffer and other things can "show through". However, this only works on fully transparent objects. It also has rough edges wherever the 0.1 alpha edge is and this can look bad for distant features where the pixels are large compared to the object.想通了。您可以在片段着色器中丢弃
Figured it out. You can discard in the fragment shader