Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: 3D tile visibility

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    595

    3D tile visibility

    Currently I am using the following system for visibility determination of some 3D tiles, that cover the whole z = 0 plane:

    - make an AABB of the frustum in world coordinates
    - check for intersection with z = 0 plane, if not don't draw anything
    - make AABBs of the tiles in world coordinates and check for frustum-AABB intersection in world space, if there's no intersection don't draw anything

    By doing everything in world coordinates I only need to transform the frustum AABB from modelview to world space, otherwise I'd have to transform the tile AABBs into modelview coordinates.

    Anyway, despite all the optimizations, my app still runs too slowly on old machines (about 20 fps) and I'd like to hear some ideas. Maybe I should be using spheres or calculate frustum-plane intersections exactly? The frustum is the linear perspective one.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: 3D tile visibility

    Quote Originally Posted by ugluk
    Anyway, despite all the optimizations, my app still runs too slowly on old machines (about 20 fps) and I'd like to hear some ideas. Maybe I should be using spheres or calculate frustum-plane intersections exactly? The frustum is the linear perspective one.
    Yeah, spheres are dirt cheap. Depending on your frustum, can also be a win to do a sphere-sphere intersect (one being your frustum's bsphere) first before doing a proper sphere-frustum intersect (which often involves a bunch of sphere-plane tests).

    Also, having a hierarchy to your spheres/boxes such as you get from BVH or spatial partitioning scheme is usually a huge win.

  3. #3
    Member Regular Contributor
    Join Date
    Apr 2010
    Posts
    491

    Re: 3D tile visibility

    Hierarchical culling is definitely the way to go, otherwise you only get an improvement if the render time of a tile is larger than the time to do the intersection test(s). Depending on the complexity of each tile that may be difficult to achieve.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    595

    Re: 3D tile visibility

    Ok, but in what situations are then AABBs useful?

  5. #5
    Member Regular Contributor nickels's Avatar
    Join Date
    Feb 2000
    Location
    Colorado
    Posts
    298

    Re: 3D tile visibility

    I use AABB for 'broad-phase' collision detection with good results. I use the sweep and prune algorithm: Basically you keep three sorted lists of all the AABB's endpoints, by dimension (X,Y,Z).
    After objects move, you sweep back through each list and do a bubble or insertion sort (I forget which...). While swapping, if a right endpoint crosses a left, then the two objects intersect in that dim. If a left end crosses a right, then you remove an intersection.
    You then take the intersection of all three dimension's intersectees to get your potentiall set of intersecting objects.

    If you only care about objects intersecting the frustrum, you could only add objects to the intersect pool if one of them is the frustrum....

    works very fast for lots of objects on modern hardware....not sure what hope for older

    I also have a higher level k-d tree each of whose leaves contains one of the sweep and prune sets described.... As objects intersect the outside world they are added to the adjoining k-d boxes and deleted when the leave....
    I'm not sure about the frustrum, though. I haven't included it yet because: 1) It moves very fast, so many swaps?? and 2) it is very big and hence causes touching all groups of objects and enlarges the intersection test, above.

    I also use view space AABB to do light occlusion culling and light screen space determination. I am a big fan of AABB !!

    Is there a similar optimization like s & p for bounding spheres?

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    595

    Re: 3D tile visibility

    I'd like to know, as both spheres and AABBs are rather simple, in what situation to use which.

  7. #7
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: 3D tile visibility

    Quote Originally Posted by ugluk
    I'd like to know, as both spheres and AABBs are rather simple, in what situation to use which.
    When you get a net perf advantage by doing so.

    Spheres are cheap to test against but provide rather course bounds. So they're good "top level" tests. OBB (and sometimes AABB, with proper choice of space) can provide a tighter fit, but are more expensive.

    It all depends on what inner operation you're protecting with the BVH. If it's a cheap operation, it may not be worth a lot of careful culling.

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    595

    Re: 3D tile visibility

    In other words, bench it and see? For now I can give these results:

    - no culling: 9 fps
    - culling, frustum - tile AABB: 20 fps

    The other option is:

    - culling, frustum - tile sphere

    I thought maybe the rule of thumb was: on an old crappy comp, use spheres, on the newer ones, use AABB or OBB.

    The problem is see with the frustum sphere is the need to calculate the bounding sphere for each frustum change. Frustum has 8 points, how do I select the 4 that are needed to calculate the bounding sphere directly? Can I just choose 2 points on the near and 2 on the far plane, like this:

    Code :
    +----
    |   |
    ----+

    + marks the spot for calculating sphere.

  9. #9
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: 3D tile visibility

    Quote Originally Posted by ugluk
    In other words, bench it and see? For now I can give these results:

    - no culling: 9 fps
    - culling, frustum - tile AABB: 20 fps
    fps is non-linear. Use ms/frame. Says you're going from 111 ms/frame (no culling) to 50 ms/frame.

    The other option is:
    Oh no, there are lots of other options.

    - culling, frustum - tile sphere
    That's one. And by frustum I assume you mean culling against 6 planes that define the frustum, right?

    So what are some other permutations?

    1) frustum - tile-sphere, and then if it passes do frustum - tile-AABB
    2) frustum-bphere - tile-bsphere
    3) frustum-bsphere - tile-bsphere, and then if it passes do one or more of the other more expensive tests (frustum - tile-bsphere, frustum-bsphere - tile-AABB, frustum - tile-AABB).

    I thought maybe the rule of thumb was: on an old crappy comp, use spheres, on the newer ones, use AABB or OBB.
    It depends on the expense of the operation you're trying to protect and the expense of protecting it. That depends on more than just your CPU and GPU perf.

    The problem is see with the frustum sphere is the need to calculate the bounding sphere for each frustum change.
    No, this is very cheap. And even then, your frustum as defined in eye-space almost never changes. And if you cull in eye-space, then consequently the frustum bsphere almost never changes. Right? Even then, compared to culling the scene, this is a nothing in terms of cost.

    Frustum has 8 points, how do I select the 4 that are needed to calculate the bounding sphere directly?
    For simple symmetric frusta, I think you can usually get an exact answer by taking the midpoint of a frustum diagonal, and then just expand the bsphere by each frustum corner just to make sure.

    But for the general problem of computing a bounding sphere for a set of points cheaply, google "Welzl's minimum bounding sphere".

    Some other links to explore:

    * View Frustum Culling Tutorial (Lighthouse3D)
    * Frustum Culling (Flipcode)
    * Welzls Minimum Sphere Algorithm Demystified

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    595

    Re: 3D tile visibility

    fps is non-linear. Use ms/frame. Says you're going from 111 ms/frame (no culling) to 50 ms/frame.
    The problem is my that my timer is crap. It gives different results every time. I'd need to run some kind of average. Do you know of a good timing source for Linux? Anyway, the fps's I give here are just inverted timing values, i.e. 1/(time_between_the_frames_in_seconds), so I don't see a problem with them.

    That's one. And by frustum I assume you mean culling against 6 planes that define the frustum, right?

    So what are some other permutations?

    1) frustum - tile-sphere, and then if it passes do frustum - tile-AABB
    2) frustum-bphere - tile-bsphere
    3) frustum-bsphere - tile-bsphere, and then if it passes do one or more of the other more expensive tests (frustum - tile-bsphere, frustum-bsphere - tile-AABB, frustum - tile-AABB).
    Yes, by frustum I mean testing against all the 6 planes. As far as other permutations are concerned; I first calculate the set of tiles that fit inside a frustum AABB, and then check them all against the exact frustum, just to be sure they really are within and not just within the frustum AABB. So the frustum AABB already provides a good starting point. I suppose I need to test every possibility and arrive at a decision based on the tests.

    It depends on the expense of the operation you're trying to protect and the expense of protecting it. That depends on more than just your CPU and GPU perf.
    On newer cards I get more fps, if I don't do any exact frustum-tile AABB overlap tests at all, the cards are so fast, they don't mind clipping. But on older cards this is not the case. It would be interesting to find out, if the old card just isn't capable of gulping down all the geometry coming in at that resolution, despite the cull.

    On a new card, I could do instancing, alas.

    For simple symmetric frusta, I think you can usually get an exact answer by taking the midpoint of a frustum diagonal, and then just expand the bsphere by each frustum corner just to make sure.
    This reminds me of the Ritter sphere algorithm. I kind of doubt it this gives the minimum sphere, as the sphere center is limited to the diagonal and there are more than 1 frustum diagonals, but only one minimum sphere is possible.

    But for the general problem of computing a bounding sphere for a set of points cheaply, google "Welzl's minimum bounding sphere".

    Some other links to explore:

    * View Frustum Culling Tutorial (Lighthouse3D)
    * Frustum Culling (Flipcode)
    * Welzls Minimum Sphere Algorithm Demystified
    One might argue, that Welzl's algorithm is not about calculating the minimum sphere, but to find out which points define it. There are up to 4 of them and if one knew in advance which 1 to 4 of the 8 were "right", then one would not need to run the Welzl's algorithm, but could directly calculate the minimum sphere.

    Maybe I could make 1 experimental run of Welzl's algorithms, see what points it picks and then designate those points as always "right".

    I'll just have to do some benching, I suppose.

    PS: frustum - tile bsphere test also involves 6 planes and is not much cheaper than frustum - tile AABB test, I think.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •