的OpenGL ES 1.1:如何改变纹理颜色又不失亮度? [英] OpenGL ES 1.1: How to change texture color without losing luminance?

查看:1014
本文介绍了的OpenGL ES 1.1:如何改变纹理颜色又不失亮度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我希望能够改变的颜色在code颗粒,所以任何颜色都可以使用。所以,我只有一个质地主要有亮度。

I have particles that I want to be able to change the color of in code, so any color can be used. So I have only one texture that basically has luminance.

我一直在使用 glColor4f(1F,0F,0F,1F); 应用颜色

每blendfunc我已经试过已经接近工作结束了像下面的最后一张照片。我还是想preserve亮度,似在画中游。 (这就好比在Photoshop中叠加或柔光滤镜,如果颜色层是在纹理层的顶部。)

Every blendfunc I've tried that has come close to working ends up like the last picture below. I still want to preserve luminance, like in the middle picture. (This is like the Overlay or Soft Light filters in Photoshop, if the color layer was on top of the texture layer.)

任何想法如何做到这一点不可编程着色器?此外,由于这些颗粒,我不希望它背后的黑盒子,我希望它添加到现场。

Any ideas for how to do this without programmable shaders? Also, since these are particles, I don't want a black box behind it, I want it to add onto the scene.

推荐答案

下面是可能会接近一个解决方案,你要找的是什么:

Here is a solution that might be close to what you're looking for:

glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

glActiveTexture( GL_TEXTURE0 );
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, spriteTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

glActiveTexture( GL_TEXTURE1 );
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, spriteTexture);    
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD );

它的作用是通过所指定的颜色乘以原始纹理,然后添加顶部的原始纹理的像素值:

What it does is multiply the original texture by the specified color and then adds the pixels values of the original texture on top:

final_color.rgba = original_color.rgba * color.rgba + original_color.rgba;

这将导致比你问一个更明亮的图像,但可能不够好一些调整。

This will result in a brighter image than what you've asked for but might be good enough with some tweaking.

如果您想preserve纹理的Alpha值,你需要使用,而不是GL_ADD GL_COMBINE(+设置GL_COMBINE_RGB和GL_COMBINE_ALPHA正确)。

Should you want to preserve the alpha value of the texture, you'll need to use GL_COMBINE instead of GL_ADD (+ set GL_COMBINE_RGB and GL_COMBINE_ALPHA properly).

下面是一些结果使用上的纹理这项技术。

Here are some results using this technique on your texture.

这篇关于的OpenGL ES 1.1:如何改变纹理颜色又不失亮度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆