Jump to content
  • Advertisement
Sign in to follow this  
Exustio

Question about blending

This topic is 2491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way to multiply a certain color channel of a texture with a color, lets say taking the red channel of a texture and multiplying it with the color RGB(0.3, 0.5,0.3)? And it would be even better if it is possible to use all three color channels at once, and multiply them with three different colors. Like in the picture below, where the top section of the image has been converted into the bottom through multiplying 3 different colors to the red, green and blue channel.

[attachment=7247:colors.png]

The reason I am asking this question is that I want to use a texture in a 2d game, let's say a spaceship, and I want the player to be able to customize the colors of different parts of the ship. The only other way I can think of is to use three separate textures, all in gray scale, representing different parts of the ship, and then use glColor() with the wanted color before drawing each part of the ship.

Share this post


Link to post
Share on other sites
Advertisement
Yes, you can use a fragment shader to do this, should be very easy to implement.
in pseudoshadercode:

uniform color1,color2,color;

void main{}
{
vec4 mask = tex2D(blabla);
return color1 * mask.r + color2*mask.g + color3*mask.b;

}

If you don't want to use shaders, your solution requires more drawing but works :)

Share this post


Link to post
Share on other sites
+1 vote for shaders, but if you're stuck doing it without another option is to use the GL_COLOR mode of glMatrixMode. It lets you supply a 4x4 matrix that gets multiplied by the input RGBA to produce an output color. You could easily produce your image this way.

Share this post


Link to post
Share on other sites
You will most likely want to divide the result by 3 as well because your addition may lead to numbers like 1.5,1.9, 2.0, that will just make it all white and cap to 1.0,1.0,1.0

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!