Vertex fog producing black artifacts
Posted
by
Nick
on Game Development
See other posts from Game Development
or by Nick
Published on 2012-09-28T01:42:52Z
Indexed on
2012/09/28
3:50 UTC
Read the original article
Hit count: 337
I originally posted this question on the XNA forums but got no replies, so maybe someone here can help:
I am rendering a textured model using the XNA BasicEffect. When I enable fog, the model outline is still visible as many small black dots when it should be "in the fog". Why is this happening?
Here's what it looks like for me -- http://tinypic.com/r/fnh440/6
Here is a minimal example showing my problem: (the ship model that this example uses is from the chase camera sample on this site -- http://xbox.create.msdn.com/en-US/education/catalog/sample/chasecamera -- in case anyone wants to try it out ;))
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Model model;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
model = Content.Load<Model>("ship");
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect be in mesh.Effects)
{
be.EnableDefaultLighting();
be.FogEnabled = true;
be.FogColor = Color.CornflowerBlue.ToVector3();
be.FogStart = 10;
be.FogEnd = 30;
}
}
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
model.Draw(Matrix.Identity * Matrix.CreateScale(0.01f) * Matrix.CreateRotationY(3 * MathHelper.PiOver4),
Matrix.CreateLookAt(new Vector3(0, 0, 30), Vector3.Zero, Vector3.Up),
Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 16f/9f, 1, 100));
base.Draw(gameTime);
}
}
© Game Development or respective owner