Skip to main content
GameDev.net gamedev.net
🔒 Locked

How do they do it?

Started by SFloyd Apr 18, 2011 at 2:42 PM 7 replies 2.4k views
Original Post
SFloyd
SFloyd
I know back then, a color was just a few pixels to change, now, there are massive bitmaps, ranging up to 512x512 in some modern RTS. I always wondered how they changed the team colors, obviously they arent using a seperate bitmap for each team. That would be so ineffecient. If anyone has any ideas please respond!
Hi.
ileonte
ileonte
If we're talking OpenGL I think this could easily be done in a pixel shader.
SFloyd
SFloyd

If we're talking OpenGL I think this could easily be done in a pixel shader.



Yes, I am trying to figure it out for my OpenGL game, do you know how?
Hi.
PieGuy
PieGuy
I have a book about RTS game-development. Unfortunately for you, it's Direct3D. I haven't made it to shader programming yet, but I'm pretty sure you're looking for something like the following:
(but in GLSL rather)

float4 Main(float2 UV : TEXCOORD0, float shade : TEXCOORD1) : COLOR
{
float4 c0 = tex2D(unitTexture, UV);
float Inv = 1.0f - c0.a;

//Weigh pixel and team color using the alpha channel
float4 c1 = float4(c0.rgb * Inv + tmCol.rgb * c0.a, 1.0f);

//return Shaded pixel
return c1 * shade;
}


Apparently they use the inverse alpha channel of the original texture, and fill it with a solid color (filling the empty places with the team color).
LegendInStone
LegendInStone

[quote name='ileonte' timestamp='1303139653' post='4799919']
If we're talking OpenGL I think this could easily be done in a pixel shader.



Yes, I am trying to figure it out for my OpenGL game, do you know how?
[/quote]

Well, if you don't need anything translucent, then you could use the alpha channel and multiply it against the team colour in the pixel shader after disabling alpha blending
BuffaloJ
BuffaloJ
You could also do the team colors in fixed function by setting the polygon color to the team color and apply the texture as a decal. Where ever the texture is translucent, you will see the team color show thru
inavat
inavat
I'll tell you how we did it. Bind a "team color mask" texture which is zero where you don't want team color and 1 (or intermediary values if you want more control) where you do. In the pixel shaded read that texture value to determine team color contribution. The team color value is set as a uniform.
AndyEsser
AndyEsser

I'll tell you how we did it. Bind a "team color mask" texture which is zero where you don't want team color and 1 (or intermediary values if you want more control) where you do. In the pixel shaded read that texture value to determine team color contribution. The team color value is set as a uniform.


This is the same way we did it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.