🔒 Locked
Changing colors
Advertisement
Original Post
I'm no expert on the matter, but if your textures are pretty uniform, you can load them, reading them as RGB values, then do a conversion to HLS mode (hue, luminosity, saturation) and add a set value to the hue, convert back to RGB, and then use them. This would only have to be done once when the texture is loaded, so it can save you space and not bog down the system. This is also a good method to allow the user to customize colors :D
hope that helps,
*Cosmic*
p.s. anybody can feel free to shut me up if i'm totally wrong about this subject
[edited by - Cosmic One on February 27, 2004 1:45:32 PM]
hope that helps,
*Cosmic*
p.s. anybody can feel free to shut me up if i'm totally wrong about this subject
[edited by - Cosmic One on February 27, 2004 1:45:32 PM]
There are several ways of doing this, and I have fiddled with almost all of them in multiplayer games before.
1) Use palettes: This requires utilizing a particular graphics format that supports palettes. Change the palette according to which team a player is on. Pretty self-explanatory. Easiest solution.
2) Diffuse colors: Probably not recommended, as it will tint the whole image. However, if you draw something separate (like a flag or something) this would be work.
3) Multiple textures (resource intensive): Have one major texture for each object (space ship, army, whatever) and leave transparent (alpha) sections where the color would be (and use semi-transparents sections in parts where you want shading). Before drawing the texture, draw a texture (or color-filed box) that is the correct color according to team and then draw the final object on top of it. The object will appear colored by the correct team.
4) Texel re-colorization (speed intensive): This actually (IMO) generates the best-looking results outside of palettes, but it is not recommended if you have say 100 or more objects needing re-colorization on the screen. It is speed intensive, as it requires locking the buffers and manually changing the color of particular texels. The reason I think this is best looking is because you can generate new colors that have bright and shadowed spots in precisely the same places as your original image. Basically, it involves taking a set range of colors in your original texture (let's say, all colors close to "absolute red" (255,0,0)) and toggling those colors by a mathematical formula. So, to make your item appear to be blue, you'd swap the red and blue channel for all red colors. To get purple, you'd mix in the equivalent amount of blue... etc. As a warning, this requires a fair amount of coding and testing...
[edited by - The Frugal Gourmet on February 27, 2004 2:06:59 PM]
1) Use palettes: This requires utilizing a particular graphics format that supports palettes. Change the palette according to which team a player is on. Pretty self-explanatory. Easiest solution.
2) Diffuse colors: Probably not recommended, as it will tint the whole image. However, if you draw something separate (like a flag or something) this would be work.
3) Multiple textures (resource intensive): Have one major texture for each object (space ship, army, whatever) and leave transparent (alpha) sections where the color would be (and use semi-transparents sections in parts where you want shading). Before drawing the texture, draw a texture (or color-filed box) that is the correct color according to team and then draw the final object on top of it. The object will appear colored by the correct team.
4) Texel re-colorization (speed intensive): This actually (IMO) generates the best-looking results outside of palettes, but it is not recommended if you have say 100 or more objects needing re-colorization on the screen. It is speed intensive, as it requires locking the buffers and manually changing the color of particular texels. The reason I think this is best looking is because you can generate new colors that have bright and shadowed spots in precisely the same places as your original image. Basically, it involves taking a set range of colors in your original texture (let's say, all colors close to "absolute red" (255,0,0)) and toggling those colors by a mathematical formula. So, to make your item appear to be blue, you'd swap the red and blue channel for all red colors. To get purple, you'd mix in the equivalent amount of blue... etc. As a warning, this requires a fair amount of coding and testing...
[edited by - The Frugal Gourmet on February 27, 2004 2:06:59 PM]
another option might be - pixel shader!
quote:
Original post by The Frugal Gourmet
1) Use palettes: This requires utilizing a particular graphics format that supports palettes. Change the palette according to which team a player is on. Pretty self-explanatory. Easiest solution.
There are almost no cards on the market which support paletted textures. It *would* be an easy way, but not viable.
Here is another (relatively) simple method. Set the part that you want to be coloured by the team to be grayscale. Set the alpha of this area to be an arbitrary value (say 50). Draw your first pass with ALPHATEST >50 which will render the sprite except in the tinted area. Then set AlphaTest == 50, set the Diffuse colour to be the colour you want to tint with and draw that modulating the texture.
OR
Modifying #3 above, rather than having a colour fill, have the Team Colour area done in grayscale and draw that modulated by the Diffuse.
There are a lot of variations. I''m assuming you''re doing something with 2D sprites rather than meshes since you said it''s 2D, though these will work with meshes too.
Stay Casual,
Ken
Drunken Hyena
No palettes? Oh well, I thought it seemed too easy... 
In any case, your idea sounds brilliant. I love it.
BTW, Jower, to activate alpha testing...
In any case, your idea sounds brilliant. I love it.
BTW, Jower, to activate alpha testing...
m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x01 ); // whatever value you want here...
m_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATER );
Make sure the alpha value is correct for the function you''ve specified. In Frugal Gourmet''s code, only things with an alpha value greater than 1 will be rendered, and things with an alpha of 0 or 1 will be invisible.
That idea of Hyena''s is a very neat and fast solution and there''s no reason why it shouldn''t work.
~CGameProgrammer( );
-- Upload up to four 1600x1200 screenshots of your projects, registration optional. View all existing ones in the archives..
That idea of Hyena''s is a very neat and fast solution and there''s no reason why it shouldn''t work.
~CGameProgrammer( );
OK, tell us what exactly you''re doing. You are drawing the models twice, right? You need to draw them once with alpha-testing set so the team-colored areas are transparent, and then you change the alpha-testing and draw the model a second time. The second time, the team-colored areas should be visible and everything else should be transparent.
~CGameProgrammer( );
-- Upload up to four 1600x1200 screenshots of your projects, registration optional. View all existing ones in the archives..
~CGameProgrammer( );
We need more information. What do you set ALPHAREF and ALPHAFUNC to for the first render? What do you set ALPHAFUNC to for the second render? And what alpha values do the colored and noncolored parts of the textures use?
~CGameProgrammer( );
-- Upload up to four 1600x1200 screenshots of your projects, registration optional. View all existing ones in the archives..
[edited by - CGameProgrammer on February 28, 2004 5:20:31 PM]
~CGameProgrammer( );
[edited by - CGameProgrammer on February 28, 2004 5:20:31 PM]
I just do
And it comes out with the right areas colored in the right colors but with transparency enabled
[edited by - Jower on February 28, 2004 6:34:57 PM]
SetRenderState(D3DRS_ALPHATESTENABLE, true)
SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL)
//Render once
SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_EQUAL)
//Render again with color
SetRenderState(D3DRS_ALPHATESTENABLE, false)
And it comes out with the right areas colored in the right colors but with transparency enabled
[edited by - Jower on February 28, 2004 6:34:57 PM]
I still don''t understand what you mean. Can you take a screenshot?
~CGameProgrammer( );
-- Upload up to four 1600x1200 screenshots of your projects, registration optional. View all existing ones in the archives..
~CGameProgrammer( );
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement