Archived

This topic is now archived and is closed to further replies.

monkeyography

filling alpha with color

Recommended Posts

I want to take any parts of a texture that have alpha on them and fill them with that much of a specified color (to show ownership in my game). It mostly works right now by making a model''s Material''s diffuse color the desired fill color, assigning a texture with alpha to an object, and using this command for color blending: pd3ddevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA ); It looks like this (the ornate thingy belongs to that blue guy, and thus, blue material is showing through the texture''s alpha) The problem is that I''m using lighting and only the parts which are lit/shaded are where the material shows through, the parts that are pure texture are not shaded at all. pd3ddevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); will get everything shaded but the blue comes through everywhere, not just where there''s alpha. Any ideas how to get transparent parts blue, let non-transparent maintain their texture color, and let shading through all at once?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think that you may well be scuppered there if you stick with the fixed function pipeline. I think that the lighting gets applied to the diffuse colour, so you can''t just access the diffuse and specular components of the light directly.

You could do this with a vertex shader and pixel shader though.

Share this post


Link to post
Share on other sites
Thanks a lot silly name person! got things *exactly* as I wanted them (well, in two stages instead of just one but the FPS didn't even take a hit!)

Ok, I've certainly seen this question posed here in the past so, for the sake of archival, all those wishing to blend colors into the alpha parts of a texture like they do in Warcraft3 and so many other RTSs, here is the way:

if you're not using lighting then:
pd3ddevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );
pd3ddevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pd3ddevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );
pd3ddevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_COLORVALUE( blendColorR, blendColorG, blendColorB, blendColorA ) );
pd3ddevice->SetTexture( 0, textureWithAlpha );

if you are using lighting then:
pd3ddevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA );
pd3ddevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pd3ddevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );
pd3ddevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
pd3ddevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT );
pd3ddevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
pd3ddevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_COLORVALUE( blendColorR, blendColorG, blendColorB, blendColorA ) );
pd3ddevice->SetTexture( 0, textureWithAlpha );
pd3ddevice->SetMaterial( aMaterial );


Thanks!

[edited by - monkeyography on January 18, 2004 3:22:50 AM]

Share this post


Link to post
Share on other sites