Sign in to follow this  
mrmrcoleman

Alpha problems.

Recommended Posts

mrmrcoleman    320
Hello. I am having a problem in getting some of my render states and texture stage states to work together. In my program I have Direct3D textures which are in the format ARGB32. I use the following states to get the alpha to be applied properly. SRS = SetRenderState STSS = SetTextureStageState SRS(D3DRS_ALPHABLENDENABLE, TRUE); SRS(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); SRS(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); SRS(D3DRS_ZWRITEENABLE, FALSE); SRS(D3DRS_LIGHTING, FALSE); STSS(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STSS(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); STSS(1, D3DTSS_COLOROP, D3DTOP_DISABLE); STSS(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); And all this works fine, however I then needed to be able to fade the whole texture between full transparent to full opaque so somebody suggested that I could use the TFACTOR. I did some tests with the following Render states and texture stage states. SRS(D3DRS_ALPHABLENDENABLE, TRUE); SRS(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); SRS(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); SRS(D3DRS_ZWRITEENABLE, FALSE); SRS(D3DRS_LIGHTING, FALSE); STSS(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STSS(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); STSS(1, D3DTSS_COLOROP, D3DTOP_DISABLE); STSS(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); STSS(0, D3DTSS_ALPHAOP. D3DTOP_SELECTARG1); STSS(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); SRS(D3DRS_TEXTUREFACTOR, ALPHA_MASK); Where alpha mask is defined as an ARGB (x, 0, 0, 0), x being altered to change the transparency of the resultant texture. This also works, however, when I combine the two obviously I can't have the ALPHAOP being both SELECTARG1 and MODULATE. Does anybody have any idea how I could either get around this, or achieve the same affect without using the TFACTOR method? I heard something about using a material value? But does this mean I will have to have lighting enabled also? Will this slow the program? Thanks in advance. Mark Coleman [Edited by - mrmrcoleman on November 10, 2004 10:16:44 AM]

Share this post


Link to post
Share on other sites
DrunkenHyena    805
STSS(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STSS(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
STSS(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
STSS(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

This is the problem with the copy 'n' paste approach, you use those 2 methods to achieve the results but don't understand what they actually do.

You want to keep the alpha transparency from your texture, but want to modulate it by the TFACTOR to globally fade the alpha.

Also, ALWAYS set all the states. Just setting
STSS(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

doesn't mean anything. What is being modulated with what? It depends on defaults and if you change them at any time in your app, then suddenly things break.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this