[英]Rendering particles as GL_TRIANGLE_FANs with transparency in OpenGL
I want to render particles with hexagons that fade out to the outside. 我想渲染带有渐隐到外面的六边形的粒子。 I've used a TRIANGLE_FAN for each particle.
我已经为每个粒子使用了TRIANGLE_FAN。 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?
我该如何更改渲染例程以避免这些错误?
What you're observing is particles behind others that do not get drawn because a closer Z-value is present in the Z-buffer. 您正在观察的是其他粒子之后未被绘制的粒子,因为Z缓冲区中存在更接近的Z值。
You can draw your particles back to front. 您可以将粒子拉回到前面。
You could also disable depth-testing, but standard alpha blending will not be correct. 您也可以禁用深度测试,但是标准的Alpha混合将不正确。 with the ALPHA/ONE mode, you'll get to accumulate all particles, so that order will not be important either.
在ALPHA / ONE模式下,您将积累所有粒子,因此顺序也不重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.