【发布时间】:2012-01-24 09:42:37
【问题描述】:
我有一个问题。 当我尝试在 XNA 4.0 中渲染我的模型时,我的纹理的某些地方是透明的。纹理本身有问题还是我做错了什么?模型和纹理从 Blender 中导出。我尝试禁用颜色键或预乘 alpha,但没有运气。
截图:
http://i43.tinypic.com/2evg56u.jpg
这是我的绘制方法:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 1.0f, 0);
DrawModel(model, position);
spriteBatch.Begin();
spriteBatch.DrawString(font, "Camera\nX = " + cameraPosition.X.ToString() +
"\nY = " + cameraPosition.Y.ToString() +
"\nZ = " + cameraPosition.Z.ToString(), new Vector2(10, 10), Color.White);
spriteBatch.DrawString(font, "Look at\nX = " + cameraLookAt.X.ToString() +
"\nY = " + cameraLookAt.Y.ToString() +
"\nZ = " + cameraLookAt.Z.ToString(), new Vector2(10, 150), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
void DrawModel(Model model, Vector3 position)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.SpecularColor = new Vector3(0.25f);
effect.SpecularPower = 16;
effect.World = Matrix.CreateTranslation(position);
effect.Projection = projection;
effect.View = view;
}
mesh.Draw();
}
}
【问题讨论】:
-
您是否启用了深度缓冲区?你考虑过 CullMode 状态吗?
-
感谢您的回复。我尝试了 CullMode 但这没有帮助,我认为默认情况下应该启用深度缓冲区,但是 Neil Knigh 的回答解决了我的问题。