Hi all,
I've got a small problem with using a .PNG sprite with premultiplied alpha. (I am using DX8/fixed function pipeline.) Previously I was using straight alpha
mD3DDevice.SetRenderState D3DRS_SRCBLEND, D3DBLEND_INVSRCALPHA
mD3DDevice.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
but I realize there are advantages to using premultiplied alpha; in particular it solves the color fringes/interpolation problem nicely. So I switch to using this:
mD3DDevice.SetRenderState D3DRS_SRCBLEND, D3DBLEND_ONE
mD3DDevice.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
which works nicely with premultiplied source images. But, it causes a new problem: I can't fade the sprites in and out using the vertex alpha component like before. Using something like TFACTOR seems inpractical since I can't batch the quads together if they are of varying opacity the way I can now.
Is there something simple I'm overlooking here? With the 'straight alpha' method I just place the desired opacity in the DIFFUSE member of each vertex and it works great; I just fill up the dynamic vertex buffer and render in one DrawPrimitive. I'd love to be able to fade my premultiplied sprites in and out on a per-quad basis the same way, but somehow the math of how to incorporate the vertex alpha into the formula is escaping me!
I'm not sure if the texture stage states are relevant, but they are set up like this:
mD3DDevice.SetTextureStageState 0, D3DTSS_COLORARG1, D3DTA_TEXTURE
mD3DDevice.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_MODULATE
mD3DDevice.SetTextureStageState 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE
mD3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE
mD3DDevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE
mD3DDevice.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT