[.net] Alpha Blending (Managed DirectX)

Started by
3 comments, last by mbelew 19 years, 4 months ago
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.
Advertisement
From my code:

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

Cheers
I used:

device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.SourceColor;
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.
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;


This topic is closed to new replies.

Advertisement