如何通过简单的乘法与其下面的颜色混合纹理颜色?

发布于 2024-11-27 19:02:37 字数 175 浏览 7 评论 0原文

所以我希望我的纹理颜色与其下面的颜色相乘,如何使用 glBlendFunc() 来完成此操作?

例如:如果我有一个纹理颜色 (0.31, 0.51, 0.124) 并且其下有一个颜色 (0.83, 0.64, 0.12),则结果颜色将为 0.31*0.83, 0.51*0.64, 0.124*0.12。如何做到这一点?

So i want my texture colors to multiply with the colors under it, how this can be done with glBlendFunc() ?

For example: if i have a texture color (0.31, 0.51, 0.124) and there is a color (0.83, 0.64, 0.12) under it, the resulting color would be 0.31*0.83, 0.51*0.64, 0.124*0.12. How to do this?

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

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

发布评论

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

评论(1

萌化 2024-12-04 19:02:37

所以我希望我的纹理颜色与其下面的颜色相乘,如何使用 glBlendFunc() 来完成此操作?

通过“纹理颜色”,我假设您的意思是“glTexEnv 过程输出的颜色”。或者,使用更严格的OpenGL规范语言,片段颜色。

无论如何,这都是一个简单的混合问题。如果您使用的是 OpenGL 2.1 或更高版本:

glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); //No, that's not a typo. Read the wiki article.
glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);

这会导致目标颜色(帧缓冲区中的内容)与源颜色(glTexEnv 中的内容)相乘,并添加到零(从技术上讲,零乘以目标颜色)。

So i want my texture colors to multiply with the colors under it, how this can be done with glBlendFunc() ?

By "texture colors", I'm going to assume that you mean "the color output by the glTexEnv process". Or, using more rigorous OpenGL spec language, the fragment color.

In any case, this is a simple matter of blending. If you're using OpenGL 2.1 or above:

glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); //No, that's not a typo. Read the wiki article.
glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);

This causes the destination color (what's in the framebuffer) to be multiplied with the source color (what comes out of glTexEnv), and added to zero (technically, zero times the destination color).

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