Archived

This topic is now archived and is closed to further replies.

Need advice on rendering 1000+ cubes

This topic is 5110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using C# and managed DirectX to create a simple puzzle game. I am hoping that I can get some design help on how to represent some of the game objects internally so I don’t pick the most inefficient way. The game consists of between 50-1000 cubes. During each frame update, each cube could potentially · Decrease/increase its height · Decrease/increase its length · Change color/texture (could get rid of this) · Move left or right parallel to X axis · Width remains constant I am new to this but this is how I would approach it. · Create each cube as an indexed primitive. · Before each frame update, modify the vertex as needed. If I have 1000 cubes, that is a lot of drawindexedprimitive calls. I have contemplated trying to think of a way to make only 1 call, but not sure how I would do that. Looking at what the cubes have to do each frame, how would you approach this? I appreciate your feedback!!!!

Share this post


Link to post
Share on other sites
If mostly every cube will change somehow every frame, then I would think using translation and scaling matrices would be better. However, with such a small amount of geometry being drawn for each call, maybe it would be better to modify everything on the CPU and make one DIP call.

Share this post


Link to post
Share on other sites
The majority of the time, many of the cubes will only get their lengths extended by the same quantity. Therefore, I could set the world to use that scaling and then call DIP on any cube that only needs lengthing. great idea....

Share this post


Link to post
Share on other sites
You only need the mesh (or vertexbuffer) for 1 cube.
The rest can be done with transformations of the world matrix (scale, translate) and setting a material (for the color)

Share this post


Link to post
Share on other sites
1000 cubes is not much.
If it is to work on 1Ghz+ machines, just any trivial way should be fine. If you want to do more than 1000, or if you plan to work with slower cpus, batch count is going to be the limit, so static VBs won''t do it anymore.
Then use dynamic VBs and IB, using the NO OVERWRITE and DISCARD patterns.
You can get a few million polys per second doing that (I do 7Million per second with complex shaders and quad texturing on a modern machine).
Have a dispatcher pick the batch according to texture, so in the end, you will only have one call per texture.

Doing this is not very complicated, and polygon throughput will not be a bottleneck, once you get performance bugs out of the way.
Trust me on this.
If fillrate is an issue (ie more than 10x overdraw), layer your batches. So you will have K layers (front to back) and N render states. That will give you K*N batches.

Share this post


Link to post
Share on other sites