Archived

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

Texture Alpha Layer strangeness

This topic is 5148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I having troubles getting a texture with an alpha channel to show up correctly. Below is the code I''m using to set the alpha parameters. What the problem is, there is a white glow around my sprites. Does anyone know how to fix this? gDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA); gDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA); gDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); gDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); gDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); gDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); gDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); gDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); gDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

Share this post


Link to post
Share on other sites
The white glow is because of filtering. Imagine the following pixels, solid black, and transparent white.

0xFF000000 0x00FFFFFF

Now let''s stretch and filter them

0xFF000000 0x80808080 0x00FFFFFF

We now have a 50% transparent medium grey around our black object... That''s no good. Ensure you fill your canvas with color, not just draw to the edge of visible pixels.

Newer versions of photoshop replace transparent parts with white, just to be annoying, and thus hinder this process... Use Photoshop 5.5.

Newer versions of photoshop, when saving TGAs, save with premodulated alpha... ie: If you have black with alpha of 50%, it actually writes out 50% alpha and grey. You could figure out how to make it stop doing that, or just stick with Photoshop 5.5.

Share this post


Link to post
Share on other sites
So I got it working with a premultiplied white by using the folwoing SetTextureState flags. Can anyone varify that this proper code or let me know a better way. The art seems to look ok, but I''m not totaly sure.


gDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
gDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
gDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE | D3DTA_COMPLEMENT);

gDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_BLENDTEXTUREALPHAPM);
gDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
gDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE | D3DTA_COMPLEMENT);

Share this post


Link to post
Share on other sites
Ok, I think this will be my last post on this subject. I played with the premultiplied alpha more and came up with this set of code based off of the formula:

r * alpha / 0xff
g * alpha / 0xff
b * alpha / 0xff

It seem to work great now. Can anyone tell me if I''m doing this even close?

gDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
gDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
gDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

gDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_BLENDTEXTUREALPHA);
gDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE | D3DTA_ALPHAREPLICATE);
gDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE | D3DTA_ALPHAREPLICATE | D3DTA_COMPLEMENT);

Share this post


Link to post
Share on other sites