• Advertisement
Sign in to follow this  

[.net] Alpha Blending (Managed DirectX)

This topic is 4830 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

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
Advertisement
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
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
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
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
Sign in to follow this  

  • Advertisement