Skip to main content
gamedev.net
🔒 Locked

Alpha value

Started by King_DuckZ 3 replies 1.4k views
Original Post
King_DuckZ
King_DuckZ
Hello people. I wrote some code to show a mesh over the screen, using the DrawIndexedPrimitive(). Now, this mesh is loaded from a file, so it has its own materials, diffuse colors and maybe alpha values different from 255. My problem is, I need to draw this mesh, but with an altered alpha value. For example, I want the mesh to fade out. I wrote this code:

m_dev->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_dev->SetTexture (0, m_pmMaterial.txTexture);

m_dev->SetRenderState (D3DRS_ALPHABLENDENABLE, TRUE);
m_dev->SetRenderState (D3DRS_TEXTUREFACTOR, 0x0);
m_dev->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
m_dev->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_BLENDFACTORALPHA);

Being the texture factor 0, I expect the mesh to be completely invisible, or at least different from usual. But it shows as it would if I remove all the code after SetTexture()... Any help is greatly appreciated :)
[ King_DuckZ out-- ]
Supernat02
Supernat02
Try this:

SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);

Also, another way to do it (in DX9.0 and later) is using D3DTSS_CONSTANT.
SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
SetRenderState(D3DTSS_CONSTANT, SomeConst);
SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CONSTANT);

You may have to convert SomeConst from dword to float. I can't remember.
Chris ByersMicrosoft DirectX MVP - 2005
King_DuckZ
King_DuckZ
Is there anything else I have to set, other than D3DRS_ALPHABLENDENABLE, to turn alpha blending on? Cause none of your code seems to work.
My hardware doesn't support D3DTSS_CONSTANT, so I tried it in REF mode, but no success.

I tried removing texture and using only diffuse color, set to 0x20FFFFFF on every vertex. Still the mesh is 100% visible, both in REF and HAL mode, so I guess there's something I'm not doing, before calling the DrawIndexedPrimitive().

Here's my code:
m_dev->SetRenderState (D3DRS_ALPHABLENDENABLE, TRUE);m_dev->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);m_dev->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);m_dev->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);m_dev->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
[ King_DuckZ out-- ]
Supernat02
Supernat02
What are your presentation paramters set to? Can you show that code? Does the backbuffer format support alpha?
Chris ByersMicrosoft DirectX MVP - 2005
Muhammad Haggag
Muhammad Haggag
Did you set D3DRS_SRCBLEND and D3DRS_DESTBLEND?
By default, they're one and zero, so you get:
PixelColor = SourceColor

Instead, you want them to be SRCALPHA and INVSRCALPHA.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.