Diagnosing rendering issues for 3D model in new content pipeline

Hello, I’m new here.
I am trying to get a model exported from blender to display correctly in monogame (latest development build as of yesterday). The model shows, but is all black. I have also tried using .x models from tutorials, and they also appear black. I was able to draw a quad with texture on it in code (so I know the texture is loading correctly), but displaying a textured and/or lighted model is a roadblock.

Quick introduction…

  • Experienced C++ coder, intermediate C#
  • Experienced OpenGL
  • Experienced with several game engines, except XNA
  • No XNA experience, or really even DirectX

I know the tools for diagnosing “black model” issues in other game engines/OpenGL, but I am clueless with how to diagnose this in monogame, and I am having trouble finding information via Google. Is there a way for me to inspect a loaded model’s vertices, normals, UV coords, etc.? How do I examine the state of the system?

If you know why the model is black, that’s a fine answer, but I’m really even more interested in the approach to diagnose the issue here. How do I debug in monogame?

I tried setting a breakpoint in VS 2010 and inspecting the members of the Model class, but I cannot see anything so low-level as actual vertex coordinates, or even whether normals are in use, or how a vertex buffer is configured.

For completeness, I will paste the code I am using. Again, the model displays, but it is black. I have tried enabling and disabling lighting and texturing. This is using the Windows OpenGL template, running in Windows 7.

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Game1
{

    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Model model;
        Texture2D texture;

        public Game1()
            : base()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            texture = Content.Load<Texture2D>("metal_0");
            model = Content.Load<Model>("ship2");

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index];
                    effect.View = Matrix.CreateLookAt(new Vector3(5, 8, 30), new Vector3(0, 1, 0), Vector3.UnitY);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 1f, 10000f);
     
                    effect.TextureEnabled = true;
                    effect.Texture = texture;
                    
                }
                mesh.Draw();
            }
            
            base.Draw(gameTime);
        }

    }
}

Here’s an update after about 10 hours of work on this.
I built MonoGame from source so I could step through the code and understand the content loading process and the rendering process. I understand much more than I did, but it’s still not a full-depth understanding. The point is, I found the tools to diagnose and debug.

Has anyone successfully loaded a 3D model using the new Content Pipeline and displayed it with lighting and texturing?

I still have not figured out why my 3D models loaded from a file show up black. I created a quad in code with the same VertexDeclaration as what is loaded from a 3D model file, and it works perfectly with texturing, vertex coloring, and lighting. The BasicEffect used in both is the same, and I also checked the vertex and pixel shaders, which are the same. I also looked at the data going into the VertexBuffer, and without checking deeply it looks reasonable.

I have the exact same problem with monogame content pipeline, I avoided it by compiling 3d models using xna ( https://msxna.codeplex.com/releases ).

cra0zy,

Have you loaded 3D models in the development build or stable? I just tried using XNA’s content pipeline for preparing a 3D model with the latest monogame source on the develop branch, and it’s still black.

I’ve loaded 3d models with development version from 1 - 2 weeks ago.

Aha, I figured out what my problem was. I had been experimenting with changing settings, and I had vertex colors enabled at the time.

So the winning recipe for me (as you confirmed) was:

  • Use XNA’s content pipeline for the 3D model ( .fbx exported from blender 2.72 )
  • Use either the Model.Draw() method, or follow the idea here if you want to enable lighting: Tutorial 1: Displaying a 3D Model on the Screen
  • Lighting and texturing work, but leave vertex colors at default (disabled)

At this point the Monogame content pipeline is not quite working for 3D models, at least those exported from blender. I found that you must use blender 2.7+ if you use .fbx with the new content pipeline. Blender 2.6 uses an exporter with an older, now-unsupported DOM.

Ah thanks for confirming gents… I’ve a few hours debugging the same “black model” issues using the latest distribution of the Monogame Content Pipeline with FBX models before stumbling on this thread

Looks like it’s time to setup Bootcamp with Windows and roll back to good ole VS2010 and XNA Content Pipeline!

Is the content pipeline still broken? My model also appears black with the BasicEffect shader + DefaultLighting.

Do I have to use the XNA pipeline?

I’ve been having this black model problem as well. I’m very new to both 3d art and 3d game programming. I understand a lot but a lot still eludes me. Like, what’s the advantage of fbx over other formats if any?

I still can’t figure my problem but I don’t want to use the old xna stuff. Rather use monogame’s pipeline from beginning to end. I’ll try some of the suggestions here and report back.

@jalanatherton, can you elaborate on these debugging tools you found?

@damccull

The advantage of .fbx is it’s widely used and many many software packages support it. This is also true of the .obj format, but that does not support skeletal animation. So .fbx supports most features that current animation/modeling software use and is itself supported by most software.

Debugging tools. What I meant by that is that I built monogame from source using MS Visual Studio, and that allows me to use VS’s debugging tools. It means that when I find in the source where a 3D model is loaded from a file, I can set a breakpoint using VS and then run my monogame application through the debugger. When that code is reached, execution is paused and I can inspect each variable to see what it contains. I can check to see if vertices are loaded, texture coordinates, normals, texture map paths, etc. I can also step through the code one line at a time to see where it leads.

My use case for monogame does not require me to use new 3D content often, so I have been using the XNA tools to make my models. I would like to get it working with monogame exclusively, but I have not had the time to reinvestigate that solution.