混合多个纹理以制作粒子系统

发布于 2024-10-10 15:41:38 字数 568 浏览 9 评论 0原文

事情是这样的,我想制作一个基于纹理的粒子系统,并且我有一个云纹理。我将纹理映射到 10 个不同的多边形,每个多边形都具有相同的大小和纹理。 当我将它们相互混合时,出现了一个问题,即 5 个多边形中的像素变得太白!我不想要这个。我想要的是类似累积缓冲区的效果。我想要实现这样的效果:

当页面中只有 1 多边形并且像素在其中时,将 Rx、Bx、Gx 表示为每个像素的颜色。现在我们有 n 个多边形,每个多边形都有相同的大小和纹理。

R总计 = R1/n+R2/n+...+Rn/n Gtotal 和 Btotal 相同

我该怎么做才能从 alpha 混合获得这样的结果。

顺便说一句,这里是初始化。

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST) ;
glDepthFunc(GL_ALWAYS);

glEnable(GL_NORMALIZE);
glColor4f(.5,.5, .5,.2); 
glBlendFunc (GL_SRC_ALPHA, GL_DST_ALPHA);

Here is the deal, I want to make a particle system based on textures and I have a cloud texture. I map the texture to 10 different polygons each having same size and textures.
when I blend them over each other, a problem rises and pixels which are in say 5 polygons become too white! i don't want this. What I want is something like accumulation buffer's effect. I want to take an effect like this:

say Rx,Bx,Gx be each pixels color when only 1 polygon is in page and pixel is inside it. Now we have n polygons each having same size and texture.

Rtotal = R1/n+R2/n+...+Rn/n
same for Gtotal and Btotal

What can I do to get such results from alpha blending.

BTW here is the initialization.

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST) ;
glDepthFunc(GL_ALWAYS);

glEnable(GL_NORMALIZE);
glColor4f(.5,.5, .5,.2); 
glBlendFunc (GL_SRC_ALPHA, GL_DST_ALPHA);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带上头具痛哭 2024-10-17 15:41:38

很难使结果完全符合您的要求,因为您需要知道每个像素有多少个片段。

如果足以让粒子看起来不错,那么更改混合模式就足够了。

它们累积为白色,因为您可能正在使用附加 alpha 混合:

result = source_color*source_alpha + destination_color

或普通附加混合:(

result = source_color + destination_color

其中源是“给定片段的颜色”,目标是“该位置的帧缓冲区中已有的内容”)。

两者都会衰减成带有很多“层”的白色。但您可以使用“真正的”alpha 混合:

result = source_color * source_alpha + destination_color * (1-source_alpha)

它不会衰减为白色。

在 OpenGL 中,这对应于:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

这并不完全是您想要的,因为结果将取决于顺序,但对于粒子系统来说应该 100% 足够。希望有帮助。

(另外,不要忘记在粒子之前渲染实体几何体,然后禁用 z-write。)

It's difficult to make the result exactly as you want it to be, as you'd need to know for each pixel how many fragments were there.

If it's enough for you to make the particles look OK, then it should be enough to change the blending mode.

They are accumulating to white because you probably are using additive alpha blending:

result = source_color*source_alpha + destination_color

Or plain additive blending:

result = source_color + destination_color

(where source is "the color of a given fragment" and destination is "what was already in the framebuffer in that place").

Both of those decay to white with a lot of "layers". But you can use "true" alpha blending:

result = source_color * source_alpha + destination_color * (1-source_alpha)

which will not decay to white.

In OpenGL, this corresponds to:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

That's not exactly what you wanted since the result will be order-dependent, but it should be 100% sufficient for a particle system. Hope that helps.

(Also, don't forget to render the solid geometry before the particles and disable z-write then.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文