2D occlusion culling

来源:互联网 发布:网络技术开发合同 编辑:程序博客网 时间:2024/04/29 18:24

Ask:

In my 2D game, I have static and dynamic objects. There can bemultiple cameras. My problem:Determineobjects that intersect with the current camera's viewrectangle.

Currently, I simply iterate over all existing objects (not caringwheter dynamic or static) and do an AABB check with the camerasview rect on them. This seems acceptable for very dynamic objects,but not for static objects, where there can be tens of thousands ofthem (static level geometry scattered over the whole scene).

I have looked into multiple data structures which could solve myproblem:

  • Quadtree

This was the first thing I considered, however the problem is thatit would force my scenes to be of fixed size. (Acceptable forstatic, but not for dynamic objects)

  • Dynamic AABB tree

Seems good, but the overhead for rebalancing it seems just toogreat for many dynamic objects.

  • Spatial hash

The main problem here for me was that if you zoom out with thecamera a lot, a huge number of mostly non-existing spatial hashbuckets had to be queried, causing low performance.

In general, my criterias for a good solution of this problemare:

  • Dynamic size: The solution must not cause the scene size to belimited, or require heavy recomputation for resizing

  • Good query performance (for the camera)

  • Good support of very dynamic objects: The computations needed tohandle objects with constantly changing position should begood:

The maximum sane number of dynamic objects in my game at one timeprobably is at 5000. Consider they all change their position everyframe. Is there even a data structure which can be faster,considering the frequent insertions and deletions, than comparingthe AABBs of the objects with the camera every frame?


Answer

Don't try to find the silver bullet. Just split your scene intodynamic and static parts and use different algorithms for them.

  • Quad trees are obviously suitable for static geometry with fixedbounds.

  • Spatial hashes are ideal for sets of objects with similarsizes
    (particle systems, for example).

  • AFAIK dynamic AABB trees are rarely used for occlusion culling,their main purpose is the broad phase of collision detection.

  • And as you noticed, bruteforce culling is normal for dynamicobjects if the number of them is not really big.

static level geometry scattered over the whole scene

If your scene is highly-sparse, you can divide it into islands,i.e. create a list of scene parts with "good density".


URL:http://stackoverflow.com/questions/6979910/best-solution-for-2d-occlusion-culling


参考:

1、squadTree

http://blog.sina.com.cn/s/blog_61f4999d0102uxmd.html

2、Spatial hashes

http://www.eecs.ucf.edu/~jmesit/publications/scsc 2005.pdf



0 0
原创粉丝点击