XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

rendering seems slow with 800 (simple) 3d objects

Last post 4/4/2009 7:21 PM by Sangretu. 2 replies.
  • 4/4/2009 6:09 PM

    rendering seems slow with 800 (simple) 3d objects

    I'm trying out XNA's 3D capabilities, and created a simple pac-man style map to test out my code. Everything displays fine, but the updates seem a bit slow.

    The map consists of 800+ grid points, each of which contains a wall, a pellet, or nothing. There are actually only 4 .fbx models, each one being displayed multiple times. Each instance calls the following code to display itself:


    public static void drawModel(Model m, Matrix[] boneTransforms, float rotation, Vector3 position, float aspectRatio, Vector3 cameraPosition, Vector3 cameraLookAt) 
            { 
                m.CopyAbsoluteBoneTransformsTo(boneTransforms); 
     
                foreach (ModelMesh mesh in m.Meshes) 
                { 
                    foreach (BasicEffect effect in mesh.Effects) 
                    { 
                        effect.World = boneTransforms[mesh.ParentBone.Index] * Matrix.CreateRotationZ(rotation) * Matrix.CreateTranslation(position); 
                        effect.View = Matrix.CreateLookAt(cameraPosition, cameraLookAt, Vector3.Up); 
                        effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000); 
                        effect.EnableDefaultLighting(); 
                    } 
                    mesh.Draw(); 
                } 
            } 

    Am I doing something stupid that's causing this to use a lot more resources than necessary? XNA's 3d graphics API kind of makes my brain melt, so there's a great deal of it that I just don't understand.

    (the rest of the code is available if it'll help)
  • 4/4/2009 6:16 PM In reply to

    Re: rendering seems slow with 800 (simple) 3d objects

    GPUs prefer many triangles arranged in few Draw calls. 800+ draw calls is going to give the result you are seeing right now even if the models are simple.

    You have a couple of choices. Check out Instancing - http://creators.xna.com/en-US/sample/meshinstancing

    If your meshes don't change position or animate  you can loop through them all and create a single large triangle buffer than you draw in a few draw calls.

    If there's no way round it then you should render the far away ones into 2d rendertargets and use imposters which can be drawn in bigger batches.
    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 4/4/2009 7:21 PM In reply to

    Re: rendering seems slow with 800 (simple) 3d objects

    Thanks ZMan, that looks like what I need - I'll check it out.
Page 1 of 1 (3 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG