tags:

views:

217

answers:

1

I have a texture using the D3DFMT_A8 format. I want to render this as if the colour is white (ie the RGB components are all 255) and use the texture data for alpha blending.

I would like to do this without having to write a pixel shader if possible (as to work with existing shaders without changes, and also the fixed function pipeline).

I can get the alpha blending bit to work just like any other texture, however the RGB components are all treated as black, whereas I need them to be treated as white...

+1  A: 

hi,

Seems that color/alpha operations interprets the color component of D3DFMT_A8 textures as rgb(0,0,0).

So you have to select the color component from the material/vertex color and the alpha component from the alphamap:

_d3d9Device.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1)  
_d3d9Device.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CURRENT)
_d3d9Device.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1)  
_d3d9Device.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE)

Then you can modulate the color texture:

_d3d9Device.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE  )  
_d3d9Device.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT)
_d3d9Device.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE)

Of course, alpha blending must be enabled:

_d3d9Device.SetRenderState( D3DRS_ALPHATESTENABLE, False)
_d3d9Device.SetRenderState( D3DRS_ALPHABLENDENABLE, True)
_d3d9Device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)
_d3d9Device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)
SuperPro