In follow up of my previous question: Limit the number of draw calls
I've lowered my draw calls to only 58 a frame!! But now I have another problem. I have 2500 cubes all drawn in the same position. I have no idea why. Everything that was done in my previous question works fine. This is my draw method that draws my chunk.
public void Draw(BasicEffect effect, ThirdPersonCam cam)
{
device.SetVertexBuffer(vertexBuffer);
device.Indices = indexBuffer;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
no++;
pass.Apply();
effect.VertexColorEnabled = false;
effect.TextureEnabled = true;
effect.Texture = grass;
Matrix center = Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, -0.5f));
Matrix scale = Matrix.CreateScale(1f);
Matrix translate = Matrix.CreateTranslation(cubePosition);
effect.World = center * scale * translate;
effect.View = cam.view;
effect.Projection = cam.proj;
effect.FogEnabled = true;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 1.0f;
effect.FogEnd = 50.0f;
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 8, 0, 12);
}
There might be some problems with the way the code is ordered in the method, but this is after moving things around. Changing the values in my DrawIndexedPrimitives line to vertices.Count and cubes.Count draws more cubes, but very strangely. There's 4 rows of 50 and then another row with just 10
World
matrix is applying only a single cube's position to the whole buffer. You need to translate the cube vertices before putting them into the batch buffer, or use instancing. (The former is better, as you will want to cull cube faces intelligently anyway.) You didn't give enough information for me to know if that's the answer or not. \$\endgroup\$