Changing Hue of a texture

Started by
17 comments, last by Devil_Inside 18 years, 9 months ago
Everyone knows how do the color themes change in Winamp3+. I would like to implement something simillar in my game. The problem is that i dont know how to change the hue of a texture in OpenGL. I tried glColor3f to change the color of the poly that wears my texture, but that doesn't actualy change the hue, it changes the whole color (even the regions of the texture that shouldn't change at all (white and grey)). In Photoshop you can also change the hue of an image by simply adding a coloured layer over the image, and setting it's blending mode to "Hue". I also tried that one in OpenGl, but i couldn't find a blending mode that suits my needs. Is there any solution? Thanks in advance.
=================* No Brain - No Pain *=================
Advertisement
Changing the hue would require you to convert the texture into a different colour space. Specifically, you need to convert it into HSV, change the hue, and then convert it back into RGB (or however your texture is represented in OpenGL).
James is correct. Unfortunately in this case, the hue of a color is computed with all three of the individual color components. In OpenGL, I have found, there is no way to perform any operation which takes into account all three of the color components at the same time. Each color component is handled separately.

There is, however, one exception to this rule that I have found which may solve your problem: Pixel Shaders. A pixel shader can do a number of very complicated pixel operations on the hardware level. This means you don't have to perform the relatively slow conversions James discussed, but the drawback is that pixel shaders are relatively new technology (introduced in December of 2001, I believe) and if you are going for backwards-compatibility in your game, you may find it tough to do with pixel shaders. Furthermore, while NVidia provides a pixel shader package with tools to ease learning, it is still a new technology that you will need to take time to learn if you so choose.

If this is what you want, however, you may consider visiting http://www.nvidia.com/object/feature_pixelshader.html for more information.
A picture is worth a thousand DWORDs.
I'm a beginner in C++ and OpenGL, so i think it's too early for me to get into shader details.

I've got the functions that transform RGB->HSB and HSB->RGB. The process of loading a texture from a file(tga in my case) stores the image data to the memory, pixel by pixel. Maybe i can load all that data and change the hue of that texture, pixel by pixel, and then save it as another texture?
=================* No Brain - No Pain *=================
That doesn't sound unreasonable. However, unless I've misunderstood, it sounds like you could optimize your texture loading routine. This is how I would do it:

1. Open the file, and read the tga headers to get the texture dimensions and bit depth.2. Read in the actual image data all at once.3. Loop through all the pixels  3.1. Convert the pixel to HSV  3.2. Change the hue  3.3. Convert the pixel back to RGB

Usually, when loading .tga files into OpenGL you would loop through all the pixels to convert from the .tga's BGR representation to RGB anyway. It's probably not too expensive to add the hue change, since you're doing it at loading time anyway.
Ok. That's almost what i was talking about. But is it possible to get the image data of the texture after it was allready loaded. (For example i need "real_time hue changing"). And if it is possible, where do i get it from?
Thanks.
=================* No Brain - No Pain *=================
Unfortunately, once you've created the texture, it's hands-off from that point on. You can't modify the context of the texture, except through calls to glTexSubImage*, or by actually creating a separate texture.
A picture is worth a thousand DWORDs.
Quote:Original post by Devil_Inside
Ok. That's almost what i was talking about. But is it possible to get the image data of the texture after it was allready loaded. (For example i need "real_time hue changing"). And if it is possible, where do i get it from?
Thanks.
glGetTexImage will get the texture data from OpenGL for you. It's pretty slow though because it is reading the data from the video card (that's most likely where the texture is stored). It's better to just keep a copy of the data in system memory and edit that, then update the texture with glTexSubImage2D.
Ok. Thanks 2 all. I'll try this and report back.
=================* No Brain - No Pain *=================
I'm pretty sure you can use the material to modify the color of a texture, in how it shows up. If you have a texture which is black and white stripes, with no set material (or a white material), and then you change the material to one colors 255,0,0 and then render the same texture you will end up with red and black stripes.

Basicly what it does is multiply (in a 0.0 to 1.0 range) the color of the texture with the color of the material. White (1.0) multipled by any material ends up the material color. Black (0.0) multipled by any material ends up black. Things in between end up something in between.

The most obvious example fo this that I can think of is the armor in EverQuest used the Direct3D equiv of this. Base armor was a white/silver/black detail. Then different actual equipment had a material color associated with it. A user could switch between a red BP and blue BP, and while the color would change, the detailing would remain identicial.

This became most interesting with some of the robes, which were not a base white color. When you multiply a texture of pink and purble stripes and peach detail by 0,200,200 you end up with a very different look then when you multiple the same texture by 200,200,0 or 50,255,50.


If you want to use 'Hue' though you must still convert from HSV to RGB. But you don't need to do it every pixel. Convert once, set material to that color.


edit: In retrospect I think I completly missed the point of the question, huh. If you want white and grey areas to not be effected you have to do it entirly yourself, either by changing the texture by hand or pixel shaders.

This topic is closed to new replies.

Advertisement