Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Rendering Multiple Models

Started by gdunbar Jan 16, 2007 at 11:20 AM 1 replies 700+ views
Original Post
gdunbar
gdunbar
Hey all, Kind of a newbie question here, but I've been confused by the documentation. So, I'm working on a tile-based game (3D tiles), which means I've got a bunch of models (for the tiles) to render. A lot of the models are the same for many tiles, if that matters. Now, my immediate thought is to load in the models as-is, and just update the world transform each time I want to render the model to put it in the right place. Sounds fine so far. However, in reading the D3D documentation here: http://msdn2.microsoft.com/en-us/library/bb206365.aspx I read: Direct3D uses the world and view matrices that you set to configure several internal data structures. Each time you set a new world or view matrix, the system recalculates the associated internal structures. Setting these matrices frequently-for example, thousands of times per frame-is computationally time-consuming. You can minimize the number of required calculations by concatenating your world and view matrices into a world-view matrix that you set as the world matrix, and then setting the view matrix to the identity. Keep cached copies of individual world and view matrices so that you can modify, concatenate, and reset the world matrix as needed. For clarity, in this documentation Direct3D samples rarely employ this optimization. Now, if I take this warning seriously, I can do all sorts of things to avoid setting the world transform. However, at least as far as I considered, any of these solutions involve me loading models a bunch of times each, and doing lots of transforms manually. I can certainly do these things without undue trouble, but it just seems like I'll be doing all of the computation manually that I'm trying to save, and probably using up a bunch more memory in addition. So in a nutshell, is it appropriate to use the world transform to move models around when rendering, or will I get better results with some other technique? Thanks, Geoff
Supernat02
Supernat02
It depends on many factors. When you say you're drawing models, are you talking about things like player models or potions on the ground, or are you calling each tile on the ground a model? If your question lies in the realm of tile-based optimizations, then unless you're drawing large tiles with limited view (i.e. 3rd person straight down), you'll probably need to optimize the tiles from the start...that is draw more than one at a time. To optimize, you need to group them according to texture, add the first group to a vertex buffer or index buffer, draw that group, and move to the next group. There are many optimizations you can place in that as well. For instance, you could add entire columns and rows to the buffers at a time, preventing having to re-calculate the entire terrain in view.

If you're asking about character models and item models, houses, whatever, then since you're new at Direct3D, I'd recommend simply setting the world matrix and drawing them. You won't be drawing that many per frame most likely, at least if you have some kind of scene organization such as a Quadtree. Get that part working, then move on to geometry instancing and other optimizations later on. It will be more fun to get a working game engine that does minimal stuff than spending so much time on one part that it takes you years to get an entire engine together, and at some point you'll get bored with it.

I recommend making an outline, and define versions of the engine and what it will support, then work towards getting each version complete. Learn about optimizations ahead of time and try your best to keep them in the back of your mind as you're building the engine, so as not to design it in a way that will make optimization complicated later. Put these down on your version outline.

The optimal approach is to get a nice balance between CPU and GPU. While the GPU is drawing several models in a single vertex buffer, you're sorting and building several more to be drawn next. This way, you utilize the GPU and CPU at the same time.

Lastly, don't forget to use static vertices when you can. For example, tiles are going to always be in the same location. Once you lock the vertex buffer and update the position of the tile, you don't have to do it again. Same goes for system memory. Once you create the tile in system memory, all you have to do is copy it to video memory when it is ready to display. I do this by searching a quadtree for which tiles are currently visible, then add them to a vertex buffer for each texture. Don't load a model and call the same SetTransform world transform each frame if it will never move. Update the verts once and leave them. Hope this gives you some ideas and isn't too far off on a tangent.
Chris ByersMicrosoft DirectX MVP - 2005
gdunbar
gdunbar
Thanks, that's all great feedback.

Geoff

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.