Blender到Xna 4.0 Windows 7.0 Alpha混合问题

时间:2012-06-14 07:41:38

标签: 3d xna textures blender alphablending

我在使用从混合器到xna的alpha混合加载纹理模型时遇到问题。

在blender上我知道纹理具有正确的alpha值,但每当我将模型绘制到我的游戏中时,应该是透明的额外空间将被填充为黑色

这是我的绘制方法的样子。

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();

        }
    }

我是否遗漏了图形设备的任何影响或变化?我一直在寻找几天,但这个问题仍然没有运气。请帮助T.T

1 个答案:

答案 0 :(得分:2)

您是否设置了这些属性?

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

如果您使用的是XNA 4.0,则需要设置混合状态而不是旧的RenderState。

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