Hi all,
Firstly please let me say that I am a complete newbie to game programming and have loved using MonoGame as my first foray in this mysterious world. As a C# dev I’ve found it easier than both Wave and Unity to get my first project up and running. So kudos to the developers if you’re reading for making things so easy.
Now to get to business, I am trying to render a significant amount of cubes on screen, roughly 200,000 initially with the requirement to go as high as about 1,000,000.
I have followed what was the simplest approach I could find by describing the cube, pushing it into a DynamicVertexBuffer
and drawing. The core of my code looks like this.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Transparent);
GraphicsDevice.SetVertexBuffer(_VertexBuffer);
GraphicsDevice.Indices = _IndexBuffer;
for (int y = 0; y < 414; y++)
{
for (int x = 0; x < 512; x++)
{
Matrix world = Matrix.CreateFromYawPitchRoll(0, 0, 0) * Matrix.CreateTranslation(new Vector3(x * 2, y * 2, 0));
_CubeBasicEffect.World = world;
_CubeBasicEffect.DiffuseColor = Color.Red.ToVector3();
foreach (EffectPass effectPass in _CubeBasicEffect.CurrentTechnique.Passes)
{
effectPass.Apply();
int primitiveCount = _Indices.Count / 3;
effect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
Vertices.Count, 0, primitiveCount);
}
}
}
}
Running this gets me roughly 5 frames per second in release mode. I have found some resources on XNA supporting ‘geometry instancing’ which is apparently invaluable to this type of a problem but from my research it appears that MonoGame does not support this. So what are my options? Would sincerely appreciate any help…
PS: Before anyone goes “Why are you drawing millions of cubes in the first place, there are probably better solutions to your problem” I’m actually displaying a 3D point cloud and want to run some effects on it so as best I can tell this is probably(?) the approach I need to take.