Sign in to follow this  

Direct3D optimization

This topic is 4813 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

Thanks for taking the time to read my question. While not very interesting, the question is one I've found a complete lack of documentation on. I'm rather new to Direct3D and so I've recently read a few books and have read every article I could get my hands on lately. After researching all I could, I'm still stuck one my issue. I'm trying to make a “tiled” floor in a 3D world using small tiles (32px squares). Currently what I'm doing to achieve this is to create one vertex buffer defining a square… and then I do world transforms each time I want to place a new tile. I set the texture for these squares and also setup the project and LookAt so I'm looking at the world how I'd like. My question is more of optimization. The "2D" flooring I'm drawing is rather large so it brings up a few issues. The first issue is how the heck do I know what to draw? I mean I'm not looking directly down at my squares so that means toward the top of the screen get smaller. To just try an clarify the problem, the cameras at such an angle so that tile squares toward the top become of a smaller size than those in the middle or bottom. How would I know what tiles I should actually be trying to draw? Another issue that I am running into right now is the method I'm using to draw. It seems like there would have to be a better way to draw a tiled floor than to do a world transform every time I need to draw a tile. I'm using well over 200 tiles incase that bit of information might be helpful to you. Any suggestions, redirections, or flames are welcome. Keith

Share this post


Link to post
Share on other sites
First of all; do you need to do it in 3D? Are you changing camera views etc? Do you need matrices?

If you answered no, then you should look up transformed and lit vertices (T&L Vertices), which, basically, are used for pure 2D geometry.

Secondly. You have a bunch of tiles to be drawn. You want to draw each tile with a call. Using a vertex buffer will draw each tile, and will not batch them == bad. You can draw them separately, and still batch them by using D3DDevice.DrawPrimitiveUP instead of using a vertex buffer. This function will batch them, and then pass them.

If you're using pure device mode, the device should batch them for you anyway, but you should always work on a low-end system [wink]

and besides, 200 tiles is nothing. I've drawn several thousand tiles in VB6 and still had enough room to draw 90,000 line primitives for a grass effect. So don't worry too much about it. Just make sure that you batch you're primitive calls and your set texture calls - the texture one especially will save you a lot of cycles.

And personally, I'd rather have 200 tiles in a vertex buffer and draw them all at once, rather than to have 1 and draw it 200 times.

If nothing else, try a whole bunch of different ways: experiment, benchmark, decide. That's the best way to learn.

Good luck!

Share this post


Link to post
Share on other sites
As for what tiles you should be drawing... if I get it right (I'm no 3d expert), you need something like octrees or something that would chceck if the object you'd like to draw is in the frustum. Try dividing your space into smaller parts, check if each part is visible or not and then, when drawing, check if it's in a visible part of the space/world. Hope it helps

Share this post


Link to post
Share on other sites
Mushu,
I do need to work with untransformed because I am not looking straight down on my map; plus I also do plan on putting some 3D objects on top of the map as well. As far as the 200 tiles but, I meant 200 different textures. There will be over 1000 tiles being drawn per frame but there will be a lot of logic behind it so I'm looking for every bit of speed I can get.

As you explained DrawPrimitiveUP, that sounds far more efficient. The map itself is really going to be huge so I don't really know about using one vertex buffer as you said, plus I don't really see how to set textures for each square using a large vb.

Caesar,
I've seen a neat example of something like you're talking about, they used a binary tree actually and yeah. So your're sort of also suggesting to get like a rough estimate of how many times would be shown and just add some extra space on there and draw at more than I know will be on the screen because a little excess wont hurt?


Thanks you both, I hope some of the new information I've given might also turn up some more help. Thank you both.

Keith

Share this post


Link to post
Share on other sites
Well, using that many different textures is going to cost you. (sorry I didn't get it the first time)

This is usually corrected by merging multiple textures onto a single tile: 4 64x64 textures become 1 128x128, up to 512x512. (which is 64 64x64 textures!!) This can spare you a lot of time when batching textures which is a must, because setting textures really eats up fps.

If you do take this method, you can have multiple "sub-textures" rendered with a single vertex buffer using texture coordinates. Though I'm not sure how you'd fit 200+ textures onto a single texture, you might be able to work something out with multiple vertex buffers, say #1 for textures 1~20... to #whatever.

It just seems to me that for something static like tiles, there shouldn't be any matrix math going on in the background, because you don't need to move them dynamically.

But the one thing you really have to watch out for is calling D3DDevice.settexture too often, as that will bottleneck performance like nothing else.

Share this post


Link to post
Share on other sites
Caesar thanks again for your information I think it'll help me out a bit. Just a side point I'd like to add on, my tiles aren't really static. They are actually fluidly animated; but I think I might change that by rendering my specific animations (such as water) as an effect over the actual tiles and only draw that animation as needed.

Thanks again

Share this post


Link to post
Share on other sites

This topic is 4813 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this