开发者

How to prevent overdrawing?

This is a d开发者_JS百科ifficult 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


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.


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 techniques (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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜