Alpha problems.

Started by
1 comment, last by DrunkenHyena 19 years, 5 months ago
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]
Advertisement
What effect are you trying to get exactly?

Have you tried modulateing the texture with the diffuse color. The HO byte of the of the diffuse color contains alpha info.
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.
Stay Casual,KenDrunken Hyena

This topic is closed to new replies.

Advertisement