2D occlusion culling

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值