0
votes

I'm having trouble loading a textured model with alpha blending from blender to xna.

On blender I know that the texture has the correct alpha values, but whenever I draw the model into my game the extra space that was supposed to be transparent is instead filled black

This is what my draw method looks like.

public void draw()
    {

        Matrix posTranslated = Matrix.CreateTranslation(position); 
        foreach (ModelMesh mesh in model.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();


                effect.View = view;
                effect.Projection = proj;
                effect.World = modelTransforms[mesh.ParentBone.Index] * posTranslated;
            }

            mesh.Draw();

        }
    }

am I missing any effects or changes to the graphics device? I've been searching for days and have still had little luck with this issue. Please help T.T

1
Are you sure the textures are exporting with their alpha intact? If you look them in to something like Paint.NET do you see the chequered background through the alpha areas?Andy
Yes inside both gimp and blender it displays the correct alpha areasCharles Haro
Thanks for the suggestion thought ^.^Charles Haro

1 Answers

2
votes

Have you set these properties?

graphicsDevice.RenderState.AlphaBlendEnable = true;
graphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
graphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;

If you're using XNA 4.0 you need to set the blend state instead of the old RenderState.

BlendState blendState = new BlendState()
{
    AlphaSourceBlend = Blend.SourceAlpha,
    AlphaDestinationBlend = Blend.InverseSourceAlpha, 
    ColorDestinationBlend = Blend.InverseSourceAlpha, // Required for Reach profile
};
GraphicsDevice.BlendState = blendState;