我有一個問題。 當我嘗試在XNA 4.0中渲染我的模型時,我的紋理的某些位置是透明的。紋理本身有問題,或者我做錯了什麼?模型和紋理從Blender輸出。我試圖禁用彩色鍵或預乘alpha,但沒有運氣。XNA 4.0模型紋理問題
截圖:
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狀態? – Blau 2011-12-20 18:34:24
感謝您的回覆。我嘗試了CullMode,但這並沒有幫助,我認爲默認情況下應該啓用深度緩衝區,但是Neil Knigh的答案解決了我的問題。 – benderto 2011-12-20 19:29:17