Jump to content
  • Advertisement
Sign in to follow this  
mrmrcoleman

Alpha problems.

This topic is 4971 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!