Jump to content

  • Log In with Google      Sign In   
  • Create Account


Direct3d9 Material Alpha


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Fredericvo   Members   -  Reputation: 320

Like
0Likes
Like

Posted 11 May 2012 - 07:42 AM

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.

Attached Thumbnails

  • alphablendcube.PNG


Sponsor:

#2 Tom KQT   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 11 May 2012 - 09:16 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

Edited by Tom KQT, 11 May 2012 - 09:20 AM.


#3 Fredericvo   Members   -  Reputation: 320

Like
0Likes
Like

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...

#4 Tom KQT   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 12 May 2012 - 09:08 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS