views:

98

answers:

4

This is a difficult question to search in Google since it has other meaning in finance.

Of course, what I mean here is "Drawing" as in .. computer graphics.. not money..

I am interested in preventing overdrawing for both 3D Drawing and 2D Drawing.
(should I make them into two different questions?)

I realize that this might be a very broad question since I didn't specify which technology to use. If it is too broad, maybe some hints on some resources I can read up will be okay.

EDIT:
What I mean by overdrawing is:

  • when you draw too many objects, rendering single frame will be very slow
  • when you draw more area than what you need, rendering a single frame will be very slow
A: 

I'm not sure what you mean by "overdrawing". Maybe you mean clipping?

troelskn
It is when you draw more than you should. Rendering one frame will be slow.
afriza
This sounds like a BTree sorting problem - ensuring you only draw vertices (and their corresponding faces) from the top of the tree as sorted according to viewport orientation. Here's a Wiki article all about it: http://en.wikipedia.org/wiki/Hidden_surface_determination
Jonners
+4  A: 

It's quite complex topic.

First thing to consider is frustum culling. It will filter out objects that are not in camera’s field of view so you can just pass them on render stage.

The second thing is Z-sorting of objects that are in camera. It is better to render them from front to back so that near objects will write “near-value” to the depth buffer and far objects’ pixels will not be drawn since they will not pass depth test. This will save your GPU’s fill rate and pixel-shader work. Note however, if you have semitransparent objects in scene, they should be drawn first in back-to-front order to make alpha-blending possible.

Both things achievable if you use some kind of space partition such as Octree or Quadtree. Which is better depends on your game. Quadtree is better for big open spaces and Octree is better for in-door spaces with many levels.

And don't forget about simple back-face culling that can be enabled with single line in DirectX and OpenGL to prevent drawing of faces that are look at camera with theirs back-side.

nailxx
+2  A: 

Reduce the number of objects you consider for drawing based on distance, and on position (ie. reject those outside of the viewing frustrum).

Also consider using some sort of object-based occlusion system to allow large objects to obscure small ones. However this may not be worth it unless you have a lot of large objects with fairly regular shapes. You can pre-process potentially visible sets for static objects in some cases.

Your API will typically reject polygons that are not facing the viewpoint also, since you typically don't want to draw the rear-face.

When it comes to actual rendering time, it's often helpful to render opaque objects from front-to-back, so that the depth-buffer tests end up rejecting entire polygons. This works for 2D too, if you have depth-buffering turned on.

Remember that this is a performance optimisation problem. Most applications will not have a significant problem with overdraw. Use tools like Pix or NVIDIA PerfHUD to measure your problem before you spend resources on fixing it.

Kylotan
+4  A: 

Question is really too broad :o) Check out these "pointers" and ask more specifically.

Typical overdraw inhibitors are:

  • Z-buffer
  • Occlusion based techniques (various buffer techniques, HW occlusions, ...)
  • Stencil test

on little bit higher logic level:

  • culling (usually by view frustum)
  • scene organization tehniques (usually trees or tiling)
  • rough drawing front to back (this is obviously supporting technique :o)

EDIT: added stencil test, has indeed interesting overdraw prevention uses especially in combination of 2d/3d.

MaR