本文介绍了OpenGL ES - 改变纹理中的颜色色调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款适用于iPhone的OpenGL ES简单2D游戏。我的问题是我想使用不同的色调渲染纹理。基本上我想改变我渲染的纹理中的颜色的色调。简单地改变glColor是行不通的,因为它也会影响图像中没有颜色的部分。有什么想法吗?

I'm developing a simple 2D-game in OpenGL ES for the iPhone. My problem is that I want to render a texture using different hues. Basically I want to change the hue of the colors in the texture that i render. Simply changing the glColor will not do since it also affects the parts of the image without color. Any ideas?

推荐答案

感谢您的澄清,这远非我最初的理解。请注意,您提供给OpenGL ES的纹理已经具有色调,因此您要求的是更改现有色调。

Thanks for the clarification, it was far from my initial understanding. Note that the texture you supply to OpenGL ES already has a hue, so what you're asking for is changing the existing hue.

首先,让我回答这个问题声明:

First, let me answer the question as stated:

让我们从纹素的需要开始。由于OpenGL纹理存储为RGB,要转换纹素的色调,您需要转RGB-> HSL->应用新的hue-> RGB。
你可以找到RGB-> HSL和反向转换的实际数学这里。你想如何选择新的色调,我想你必须填写它。

Let's start with what needs to happen to the texels. Since OpenGL textures are stored as RGB, to transform the hue of a texel, you need to go RGB->HSL->apply new hue->RGB.You can find the actual math to do the RGB->HSL and back conversion here. How you want to select the new hue, I suppose you'll have to fill that out.

最大的问题是何时应该进行转换发生。好吧,OpenGL管道不会让你在读取纹理时进行复杂的转换(不是在ES 1.1中,反正-ES 2.0 片段着色器会有所帮助,但是很高成本)。因此,您必须在GL ES纹理管道之外进行所有转换。根据您需要更改色调的频率,我的建议是离线(并存储各种主题纹理),或者在将它们加载到OpenGL ES之前根据需要为新色调计算新纹理。

The biggest question is when should the transformation happen. Well, the OpenGL pipeline won't let you do that complex a transformation on reading a texture (not in ES 1.1 anyways -ES 2.0 fragment shaders would help, but at a high cost). So you'll have to do all the transformations outside of the GL ES texturing pipeline. Depending on how often you need to change the hues, my advice is to either do it offline (and store various themed textures), or compute new textures for the new hues on demand just before loading them to OpenGL ES.

据我所知,GL ES 1.1没有任何内置设施可以直接帮助实现这一目的。

As far as I know, GL ES 1.1 does not have any in-built facility to help do this directly.

现在,后退一步,我不确定是什么阻止你分离2个纹理,如果你可以在运行时使用2个纹理。我指出的数学确实将饱和度与亮度分开,无论纹理是如何产生的(理论上,如果我理解你的情况,色调应该是不变的)。离线计算在任何输入纹理上应该相当容易吗?

Now, taking a step back, I'm not sure what's prevent you from separating out in 2 textures, if you can live with the 2 textures to apply at runtime. The math I pointed to does separate saturation from lightness no matter how the texture was generated (and in theory, hue should be constant, if I understand your case correctly). Doing the computation offline should be fairly easy on any input texture ?

这篇关于OpenGL ES - 改变纹理中的颜色色调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!