Hello,
So I've been trying to fool around with transparent materials a bit and have a small problem.
I used the following code from msdn site:
ZeroMemory(&material, sizeof(D3DMATERIAL9)); // clear out the struct for use
material.Diffuse = D3DXCOLOR(1.0f, 0.4f, 0.0f, 1.0f); // Alpha purpusely set to opaque
material.Ambient = D3DXCOLOR(1.0f, 0.4f, 0.0f, 1.0f); // because that's the odd behaviour
material.Emissive = D3DXCOLOR(1.0f, 0.4f, 0.0f, 1.0f); // I want to solve
material.Specular = D3DXCOLOR(1.0f, 0.4f, 0.0f, 1.0f);
// Enable alpha blending.
d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE,
TRUE);
// Set the source blend state.
d3ddev->SetRenderState(D3DRS_SRCBLEND,
D3DBLEND_SRCCOLOR);
// Set the destination blend state.
d3ddev->SetRenderState(D3DRS_DESTBLEND,
D3DBLEND_INVSRCCOLOR);
d3ddev->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ); // Tell D3D to get Alpha from material
d3ddev->SetMaterial(&material); // set the globably-used material to &material
OK so I DID in fact achieve my goal of transparency and see through the objects behind BUT... not with as much flexibility as I expected. I can't seem to regulate the amount of transparency that I want and even with 100% opaque values my object is still fully see-through.
Direct3d9 Material Alpha
Started by Fredericvo, May 11 2012 07:42 AM
3 replies to this topic
Sponsor:
#2 Members - Reputation: 644
Posted 11 May 2012 - 09:16 AM
I think you wanted this setting:
That's the right way to tell the device to use alpha as the blending factor.
You are using the color in your code and that's why you never get fully opaque model - it would be fully opaque only for white color which has all channels equal to 1.0
d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
That's the right way to tell the device to use alpha as the blending factor.
You are using the color in your code and that's why you never get fully opaque model - it would be fully opaque only for white color which has all channels equal to 1.0
Edited by Tom KQT, 11 May 2012 - 09:20 AM.
#3 Members - Reputation: 210
Posted 12 May 2012 - 07:52 AM
I think you wanted this setting:
d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
That's the right way to tell the device to use alpha as the blending factor.
You are using the color in your code and that's why you never get fully opaque model - it would be fully opaque only for white color which has all channels equal to 1.0
Thanks! That did the job indeed. Not sure why MSDN mentioned that colour blending there. Oh well...






