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've got a minecraftish game that's running nice and smooth with a total of 9.3 million triangles, about 50-70fps average. Then if I try to render 9.9 million triangles I get hell and it drops to < 1 fps. I'm drawing them exactly the same way, it's definitely the drawing as I have a vertex buffer for each chunk, then I run through them all, check if they're in sight and if they are I draw them. It works fine at high fps until I have just those few extra triangles which destroy the FPS.

Edit: Added drawing code:

First I loop through all the chunks. I check if they're visible and if they are I mark them as visible then draw them.

        foreach (Chunk chunk in GlobalWorld.LoadedChunks)
        {
            if (chunk == null || !chunk.DrawThis)
                continue;

            if (!player.ViewFrustrum.Intersects(chunk.Bounding))
            {
                chunk.IsInSight = false;
                continue;
            }
            chunk.IsInSight = true;

            GlobalGame.graphicsDevice.SetVertexBuffer(chunk.VertexBuffer);
            GlobalGame.graphicsDevice.Indices = chunk.IndexBuffer;

            ChunkShader.Parameters["xWorld"].SetValue(chunk.WorldMatrix);
            ChunkShader.CurrentTechnique.Passes[0].Apply();
            GlobalGame.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, chunk.VertexBuffer.VertexCount, 0, chunk.IndexBuffer.IndexCount / 3);
        }

Then after that I draw all the transparent parts of the chunk (so they don't conflict with other chunks). I already made clear if they're visible above so I just check if that bool is true.

        foreach (Chunk chunk in GlobalWorld.LoadedChunks)
        {
            if (chunk == null || !chunk.IsInSight || !chunk.DrawThisTransparent)
                continue;
            GlobalGame.graphicsDevice.SetVertexBuffer(chunk.TransparentVertexBuffer);
            GlobalGame.graphicsDevice.Indices = chunk.TransparentIndexBuffer;

            ChunkTransparencyShader.Parameters["xWorld"].SetValue(chunk.WorldMatrix);
            ChunkTransparencyShader.CurrentTechnique.Passes[0].Apply();
            GlobalGame.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, chunk.TransparentVertexBuffer.VertexCount, 0, chunk.TransparentIndexBuffer.IndexCount / 3);
        }

With 3721 chunks loaded it runs fine with them all being drawn at the same time. With 3844 chunks being loaded it runs fine unless you view all of them. Now that's only just over 100 more chunks yet it's dropping from 60fps to < 1 fps.

share|improve this question
1  
Can you show your draw code? Are you using both an index and vertex buffer? Are you using triangles, trianglestrips or trainglelists? What kind of videocard do you have? –  Roy T. May 8 '12 at 15:33
    
I have 2 vertex buffers and 2 index buffers for each chunk, 1 for transparent materials and the other for normal ones. I added code to the original post. –  jacker May 8 '12 at 16:03
    
So you have 6000 vertex buffers!?! 6000+ draw calls per frame is a lot. –  David Lively May 8 '12 at 16:29
    
How much total data are we talking about (bytes) and how much ram does your video card have? –  David Lively May 8 '12 at 16:31
    
I have a gtx 680 and it has 2gb of ram. There's about 1.86e7 vertices, and 2.79e7 indices when it works at 60fps, and 1.98e7 vertices and 2.97e7 indices when it lags like crazy. Each vertex is 8 bytes (byte4 for position and normals then halfvector2 for texture atlas coords). And each index is 4 bytes. (1.98e7*8+2.97e7*4) bytes in megabytes = 264.358521 megabytes –  jacker May 8 '12 at 16:55

2 Answers 2

up vote 7 down vote accepted

You may be simply running out of VRAM, causing degenerate behavior paging into/out of main RAM when rendering your scene. How many verticies/indicies are you wrangling here? What's your vertex format like? Is this on an xbox 360 or do you have a specific GPU you can point us at?

10 million triangles x (0.5-3) verts per triangle x 5 floats (pos + 1 uv) per vert x 4 bytes per float x = 100-600MB, and that's ignoring fragmentation, indicies, and whatever else you might have loaded (textures)

share|improve this answer
1  
I have a gtx 680 and it has 2gb of ram. There's about 1.86e7 vertices, and 2.79e7 indices when it works at 60fps, and 1.98e7 vertices and 2.97e7 indices when it lags like crazy. Each vertex is 8 bytes (byte4 for position and normals then halfvector2 for texture atlas coords). And each index is 4 bytes. (1.98e7*8+2.97e7*4) bytes in megabytes = 264.358521 megabytes. Copied from the above comment. –  jacker May 8 '12 at 17:02
2  
Please stop making a ridiculous number of assumption and measure you GPUs memory. superuser.com/questions/160291/… –  ClassicThunder May 9 '12 at 6:00
    
I could see the driver "optimizing" those byte4s out into float4s in VRAM or something similarly silly. I'd grab Nvidia's PerfKit if you haven't already, though, just to make sure there's nothing peculiar in those new draw calls like a bunch of transparent full screen rects. –  MaulingMonkey May 9 '12 at 7:10

Mauling Monkey's answer is very right, but to solve your problem, I'll add my response.

I guess you aren't optimizing the cube faces away...
9 300 000 triangles means 4 650 000 faces. If each cube has 6 visible faces, this is 775 000 visible cubes. That number is too high. A correct number should be something like 20 000 cubes (that is how many visible cubes I have in my CraftMania, with a viewing distance of 100 meters).

Two cubes touching each other are having each one invisible face.

  +-----+-----+
 /     /     /|
+-----+-----+ |
|     |     | +
|     |     |/
+-----+-----+
      ^
   (They have this face in common, which is invisible.)

Try to implement this and your results will improve a lot!

share|improve this answer
    
Yeah I did have that, my view distance is about 1.4km though from corner to corner and about 1km^2. –  jacker May 20 '12 at 15:20
    
Oh, that is a lot... To me it looks useless to set the viewing distance that high... –  Martijn Courteaux May 21 '12 at 16:03
1  
Really? Larger view distances look much better. youtube.com/watch?v=440YpjL54Y8 –  jacker May 24 '12 at 18:31
    
Hmm, ok looks nice! –  Martijn Courteaux May 25 '12 at 19:48

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.