在 OpenGL 中将粒子渲染为具有透明度的 GL_TRIANGLE_FAN
我想渲染带有淡出到外部的六边形的粒子。我为每个粒子使用了 TRIANGLE_FAN。不过,透明度看起来不太好。
glBegin(GL_TRIANGLE_FAN);
glColor4f(c.x, c.y, c.z, particle.temperature / 100.0);
glVertex3f(0, 0, 0);
glColor4f(0, 0, 0, 0);
glVertex3f(0.866025404 * H / 2, 0.5 * H / 2, 0);
glVertex3f(0, 1 * H / 2, 0);
// other vertices omitted
glEnd();
我得到的输出是闪烁的,并且黑色透明部分在某些帧上绘制在不透明对象上。我必须如何更改渲染例程才能避免此错误?
I want to render particles with hexagons that fade out to the outside. I've used a TRIANGLE_FAN for each particle. However, the transparency doesn't look very nice.
glBegin(GL_TRIANGLE_FAN);
glColor4f(c.x, c.y, c.z, particle.temperature / 100.0);
glVertex3f(0, 0, 0);
glColor4f(0, 0, 0, 0);
glVertex3f(0.866025404 * H / 2, 0.5 * H / 2, 0);
glVertex3f(0, 1 * H / 2, 0);
// other vertices omitted
glEnd();
I get an output which is flickering and where the black transparent parts are drawn over opaque objects at some frames. How do I have to change my rendering routine to avoid this bugs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您观察到的是其他粒子后面的粒子没有被绘制,因为 Z 缓冲区中存在更接近的 Z 值。
您可以将粒子从后向前绘制。
您也可以禁用深度测试,但标准 Alpha 混合将不正确。使用 ALPHA/ONE 模式,您将累积所有粒子,因此顺序也不重要。
What you're observing is particles behind others that do not get drawn because a closer Z-value is present in the Z-buffer.
You can draw your particles back to front.
You could also disable depth-testing, but standard alpha blending will not be correct. with the ALPHA/ONE mode, you'll get to accumulate all particles, so that order will not be important either.