Sign in to follow this  

Optimizations

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

Hiya folks! I'm a little new to the whole graphics business, and, well, I'm working on a little DirectX Engine, and I was wondering if you guys could help me out with a few questions I have on optimizations (not API specific, at least not most of them). Thanks! Firstly, I hear a lot of talk about 'Rendering Trees' BSP, etc. I was wondering what these things are (links would be fine, no need for a detailed description if you can point me in the right direction), and I was wondering if they would be necessary in any type of engine. Secondly, I also hear a lot of talk about 'Frustum Culling'. I read about this in a book, and, while I have the theory down at least, is this alone enough of an optimization (again, we're not talking something that's going to be shooting out massive amounts polygons per frame) in and of itself, or will (many) other optimizations need to be implimented as well? Last but not least, and I'm afraid this one is kind of Direct3D specific, do I need to cull out faces that are behind other faces and thus are not visible manually, or will the Z-Buffer handle that for me in a fast fashion? My thanks for your time, I'm sure I must come off sounding really rather 'enthusiastic but obtuse' here, but believe me, I really want to get this stuff down, and correctly. Thanks!

Share this post


Link to post
Share on other sites
Trees:

(very brief) Trees are used to sub-divide the world into smaller parts. a BSP tree (binary space parition tree) uses planes to divide up the world. Octrees use boxes. Quadtrees use squares. They can also be used to speed up frustum culling...

Frustum Culling

the process of taking an object and seeing if it falls into the field of view of the camera. Most game objects are surrounded by a box which you check against the frustum (the viewable area). If it's partially or completely inside then the object should be drawn. If not, then there's no need to send it to the graphics card. Objects need to be chekced each frame.

Trees help frustum culling because trees can also contain objects. If an entire node ("space") isn't visible then nothing from that node should be drawn. If it is completely inside the frustum then EVERYTHING should be drawn. If it's partially inside the frustum, then all the objects the node contains need to be checked individually.

Nodes can also contain other nodes, which can contain more nodes. The actual content of a node is called a leaf.


Google: bsp tree, octree, kdtree, frustum culling

I would point you to gametutorials.com for frustum culling, but they seemed to have sold out and now want $5 for one of the most common techniques used in gamedev.

Oh, if you really want to get into it, google "scene graph management" (the collective term for managing objects in the world).


You don't need to cull triangles manually - ever. Just make sure Direct3D is only drawing the front-facing triangles (don't know how - I'm a gl guy) and the zbuffer will take care of the rest.

Share this post


Link to post
Share on other sites
http://www.devmaster.net/articles/rendering_trees/ just appeared. It's refering to 2D games, but it had an excellent description of trees, nodes and children.

Share this post


Link to post
Share on other sites
To enable backface culling, you can do:
pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );

Another thing to make sure is to use lots of batching... So, instead of making 1000 drawprimitive calls, each one with 10 polygons, make 10 drawprimitive calls with 1000 polys. (Or whatever). Also, try not to change render states too often, since I guess this screws with the pipelined nature of how video cards work.

Anyways, to answer your question:

Quote:
is (frustum culling) alone enough of an optimization (again, we're not talking something that's going to be shooting out massive amounts polygons per frame) in and of itself, or will (many) other optimizations need to be implimented as well?


Short answer: yes :)

Long answer: If your objective is to make a basic game from start to finish and you don't want to waste lots of time, then frustum culling should be enough. However, if you're serious about learning graphics programming, or if you want your game to be able to handle lots of polys or heavy use of shaders, then it's definitely worth it to spend some time looking into optimizations.

Hope that helps,

roos

Share this post


Link to post
Share on other sites
Thanks again, both of you. I knew I could count on GD to pull me through [grin]

roos: I am rather serious about this, as, although my engine will no doubt be small, and not much to look at in the beginning, I have a (some might say bad) habit of continually working on things, even when they are 'done', so I will no doubt be adding in new functionality just as soon as I learn it [smile] In the 'end' (What end? There is no end for the programmer, only another release, there' always another bug to quash...) I will be aiming for a good (high) quality graphics engine, so I may as well get the foundation right [grin]

Thanks for the tip on the 'drawprimative' calls, I'll keep that in mind!

Share this post


Link to post
Share on other sites
Occlusion culling is an optimization when frustum culling is not enough. It consists of not drawing objects that are hidden by another objects. Much is described here: http://www.hybrid.fi/main/academic/aila/TIMOAILA_thesis.pdf.

Share this post


Link to post
Share on other sites
Np... Good luck man :) I think if you're shooting for hi quality, it's definitely worth spending time w/ optimization. Even if modern video cards can push a ridiculous number of polys, optimization will really pay off when you start integrating effects like per-pixel lighting and shadows. Some techniques also require you to render the scene more than once from different viewpoints (e.g. dynamic cubemap), so that would just be downright painful w/o good optimization.

Share this post


Link to post
Share on other sites

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