Sign in to follow this  

Direct3d9 Material Alpha

This topic is 2042 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,

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.

Share this post


Link to post
Share on other sites
I think you wanted this setting:
[code]
d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
[/code]

That's the right way to tell the device to use [b]alpha[/b] as the blending factor.
You are using the [b]color [/b]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

Share this post


Link to post
Share on other sites
[quote name='Tom KQT' timestamp='1336749389' post='4939317']
I think you wanted this setting:
[code]
d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
[/code]

That's the right way to tell the device to use [b]alpha[/b] as the blending factor.
You are using the [b]color [/b]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
[/quote]

Thanks! That did the job indeed. Not sure why MSDN mentioned that colour blending there. Oh well...

Share this post


Link to post
Share on other sites
Yea, you're right, I also found the MSDN page with COLOR blend. It's also in the DirectX .chm file.
To be fair, it's not an error, it's a valid setting. But IMHO very unusual.

Share this post


Link to post
Share on other sites

This topic is 2042 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.

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