XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Alpha blending not working

Last post 05-11-2008 11:49 AM by RuneHunter17. 2 replies.
  • 05-10-2008 11:49 PM

    Alpha blending not working

    I have my alpha blending states setup like this:

                GraphicsDevice.RenderState.AlphaBlendEnable = true;
    GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
    GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
    GraphicsDevice.RenderState.AlphaTestEnable = true;
    GraphicsDevice.RenderState.AlphaFunction = CompareFunction.Always;

    I than draw the ground and than a bunch of spheres above the ground in wireframe mode with an alpha of 0 (as a test to show the problem). If the lines are not above the ground (there not being blended with the ground) than they are in fact invisible. However if they are being blended with the ground with an alpha of 0 than they show up as white or blueish lines. Why is this happening?

  • 05-11-2008 3:32 AM In reply to

    Re: Alpha blending not working

    Answer
    Your alpha test is wrong.  Use these settings:

                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.SourceBlend = Blend.SourceAlpha;
                device.RenderState.AlphaSourceBlend = Blend.One;
                device.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
                device.RenderState.BlendFunction = BlendFunction.Add;
                device.RenderState.AlphaDestinationBlend = Blend.InverseSourceAlpha;

                //  don't write z depth if there is no alpha
                device.RenderState.AlphaTestEnable = true;
                device.RenderState.AlphaFunction = CompareFunction.Greater;
                device.RenderState.ReferenceAlpha = 0;
  • 05-11-2008 11:49 AM In reply to

    Re: Alpha blending not working

    Answer

    Changing that long with drawing the alpha blended content last fixed it. I forgot that you have to draw the alpha stuff after the solid stuff and that you have to sort the stuff out.

    Thanks.

Page 1 of 1 (3 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG