Sign in to follow this  
Asheh

[.net] Alpha Blending (Managed DirectX)

Recommended Posts

Asheh    354
Hey, Ive been trying to get alpha blending to work with my game, but I just cant get it right, ive tried various file formats and such but its just not working right. Heres the code to enable alpha: mDevice.RenderState.AlphaBlendEnable = true; mDevice.RenderState.AlphaSourceBlend = Blend.SourceAlpha; mDevice.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha; I think this should work its the same as unmanaged directx ( I assume ) and this is what I used before. Am i missing somthing? Regards. ash.

Share this post


Link to post
Share on other sites
ernow    732
From my code:

device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

Cheers

Share this post


Link to post
Share on other sites
MikeyO    100
I used:

device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.SourceColor;

Share this post


Link to post
Share on other sites
Asheh    354
Ok ive tried both of these and neither of them work! Im loading up a PNG file with an alpha channel, And yet nothing of the image is hidden..

Somone help?

Regards.Ash.

Share this post


Link to post
Share on other sites
mbelew    157
Quote:
Original post by Asheh
Ok ive tried both of these and neither of them work! Im loading up a PNG file with an alpha channel, And yet nothing of the image is hidden..

Somone help?

Regards.Ash.


Once you set the render states, you should then set up the color blending math. Here's what I use:

//Render States
device.RenderState.AlphaBlendEnable = true;
device.RenderState.AlphaFunction = Compare.Greater;
device.RenderState.AlphaTestEnable = true;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DiffuseMaterialSource = ColorSource.Material;

//Color blending ops
device.TextureState[0].ColorOperation = TextureOperation.Modulate;
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;

//set the first alpha stage to texture alpha
device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;


Share this post


Link to post
Share on other sites

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