Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 is a minimal example showing my problem: (the ship model that this example uses is from the chase camera sample on this site — 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);  
    }  
}  
share|improve this question
    
The image is a jpg so it's impossible to check the actual pixel values of your "black pixels". What it looks to me is that this is a vertex fog and you're looking at polygons almost from the side, but it could be something else too, like conflicting antialiasing setting or bad normals or some such.. –  Jari Komppa Sep 28 '12 at 10:51
    
I see black pixels at the bottom front of the ship as well as at the tail. They look like antialiasing artifacts due to incorrect blending with the background — like the ship's edge is being blended with a black background instead of blue. I don't know how to fix that in XNA, sorry. –  Kevin Reid Sep 29 '12 at 16:17
add comment

1 Answer 1

Texture contains dark & almost transparent pixels. Fog is internally controlled by alpha to support alpha blending with fog enabled.

You should remove alpha from the texture (or set it to 100% everywhere) if you intend to use the fixed function pipeline. If you have shaders in mesh effects, you can alternatively implement fog differently in those.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.