• Advertisement
Sign in to follow this  

mesh culling (octrees)

This topic is 2064 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, I've gotten to the point in my engine where I want to implement mesh culling.

But I don't really understand octree culling that seems to be so popular:

1) If we take into account that every mesh can be moving, we would have to do [number of meshes in the scene (tested against octree leaves)]+[number of octree aabbs (tested against view frustrum)] aabb tests each frame.
But without an octree, I would just have to do [number of meshes in the scene (tested against view frustrum)] aabb tests per frame. So why would I use an octree?

2) I have read some articles that do octree culling for polygons, and not entire meshes. Why would I want to do that? It just seems like more draw calls to me. And then there's instancing as well, I don't see how it can work with that?

Thanks smile.png Edited by Xcrypt

Share this post


Link to post
Share on other sites
Advertisement
1) If we take into account that every mesh can be moving, we would have to do [number of meshes in the scene (tested against octree leaves)]+[number of octree aabbs (tested against view frustrum)] aabb tests each frame.
But without an octree, I would just have to do [number of meshes in the scene (tested against view frustrum)] aabb tests per frame. So why would I use an octree?
So maybe a naiive octree isn't the best data structure for your particular type of scene? N.B. there's a lot of variations of octrees that are better designed for dynamic data.
2) I have read some articles that do octree culling for polygons, and not entire meshes. Why would I want to do that? It just seems like more draw calls to me. And then there's instancing as well, I don't see how it can work with that?[/quote]What was the date on those articles? 15 years ago when octrees were cool, the world rendering loop looked more like [font=courier new,courier,monospace]for each polygon: set states, draw polygon[/font] instead of [font=courier new,courier,monospace]for each batch, set states, draw triangles[/font]. Often this was done using immediate mode, instead of using batching at all...

Share this post


Link to post
Share on other sites

But without an octree, I would just have to do [number of meshes in the scene (tested against view frustrum)] aabb tests per frame. So why would I use an octree?

As hodgman stated, octrees are not the best fitting data structure for every cases. They are very easy and good for (almost) static data, for dynamic data, take a look i.e sweep'n'prune.

You should build an interface around a collection of data structures (i.e. use octtree for static, grid for terrain, sweep'n'prune for dynamic data) to ease its access. When you want to start with a single data structure, stick to a dynamic one (I'm still only using sweep'n'prune for static and dynamic objects in my engine).

Share this post


Link to post
Share on other sites

What was the date on those articles? 15 years ago when octrees were cool, the world rendering loop looked more like [font=courier new,courier,monospace]for each polygon: set states, draw polygon[/font] instead of [font=courier new,courier,monospace]for each batch, set states, draw triangles[/font]. Often this was done using immediate mode, instead of using batching at all...

I guess they were pretty old indeed :)


octrees are not the best fitting data structure for every cases. They are very easy and good for (almost) static data, for dynamic data, take a look i.e sweep'n'prune.

You should build an interface around a collection of data structures (i.e. use octtree for static, grid for terrain, sweep'n'prune for dynamic data) to ease its access. When you want to start with a single data structure, stick to a dynamic one (I'm still only using sweep'n'prune for static and dynamic objects in my engine).

Thanks, looking into swee'n'prune now

Share this post


Link to post
Share on other sites

So why would I use an octree?


When a mesh moves, you can test first against the former octant's AABB to check if it still belongs there. This should account for most cases during a frame, and as an AABB <> AABB check, it should be less expensive than an AABB <> frustum check.

Also if an octant is entirely visible (inside the frustum), all its child octants and the meshes contained within are known to be visible without any further intersection tests.

Share this post


Link to post
Share on other sites

When you want to start with a single data structure, stick to a dynamic one (I'm still only using sweep'n'prune for static and dynamic objects in my engine).


I'm sorry but, I don't see how sweep and prune applies to this. It seems like something for collision detection between several AABBs, which I can imagine to be very useful in collision detection engines, but how does this apply to view frustrum culling?

Share this post


Link to post
Share on other sites
I'm sorry but I haven't understood if you have view frustum culling working or not?

If the problem your facing is how to view frustum cull dynamic objects, you can create the AABB and transform it to view space and do the view frustum culling in view space.

Plus, in order to speed frustum culling in my engine I group meshes in nodes, and each node has a bounding sphere. So I test if the node bounding sphere is inside the view frustum:
- if yes - all meshes of the node are inside view frustum;
- if no - all meshes of node are outside view frustum;
- if the sphere intersects the view frustum - check if the AABB of each mesh are inside the view frustum. Edited by TiagoCosta

Share this post


Link to post
Share on other sites

I'm sorry but I haven't understood if you have view frustum culling working or not?

If the problem your facing is how to view frustum cull dynamic objects, you can create the AABB and transform it to view space and do the view frustum culling in view space.

Plus, in order to speed frustum culling in my engine I group meshes in nodes, and each node has a bounding sphere. So I test if the node bounding sphere is inside the view frustum:
- if yes - all meshes of the node are inside view frustum;
- if no - all meshes of node are outside view frustum;
- if the sphere intersects the view frustum - check if the AABB of each mesh are inside the view frustum.

Well it's not about getting it to work - testing an AABB against a view frustrum is not particularly difficult- it's about getting a to work fast.

Your optimisation of grouping them into spheres is a good example of what I'm looking for, but I'm just wondering if there are other exotic ways of doing it.
I can't seem to find any recent articles on frustum culling either ( other than the basics sad.png )
Octree looks great for static objects, but I'm not sure what to do for dynamic objects (objects that move a lot). Sweep and prune has been mentioned but that looks more like a way of testing the AABBs against each other than testing them against a view frustum, so I'm not sure how it applies to frustum culling.

A question about your culling system: based on what parameters do you group meshes into spheres? Edited by Xcrypt

Share this post


Link to post
Share on other sites
http://publications....Battlefield.pdf
How many objects do you have? Less than 15k? Just use brute force and linear arrays. It's ridiculous fast.
Just tested that I can do around 1000 sphere vs frustum check in 2ms with java code on my android. My data is not even linear there are no structs on java and its cheap chinese android phone. Just pick the simplest way. Optimize it 5minutes and pick more interesting problem. If it's gonna be bottleneck its easy to optimize further or offload to another core.


/**
* Returns wheter the given sphere is in the frustum.
*
* @param center
* The center of the sphere
* @param radius
* The radius of the sphere
* @return Wheter the sphere is in the frustum
*/
public boolean sphereInFrustum(Vector3 center, float radius) {
for (int i = 0; i < 6; i++)
if ((planes.normal.x * center.x + planes.normal.y * center.y + planes.normal.z
* center.z) < (-radius - planes.d))
return false;
return true;
}

Share this post


Link to post
Share on other sites
can't really access the data linearly as state caching is more important than culling. Looking at that link you give me now though, thanks for sharing :) Edited by Xcrypt

Share this post


Link to post
Share on other sites
FWIW I also use a system similar to what is presented in that Battlefield paper. On my Xeon W3550, my SSE optimized code clocks in at 16k sphere-frustum checks in at about 0.12ms (1 thread), which is plenty fast enough for me. It didn't take too much effort to rework the data structures so the spheres were accessed linearly in memory and really the code ended up considerably simpler (IMO).

Share this post


Link to post
Share on other sites

can't really access the data linearly as state caching is more important than culling. Looking at that link you give me now though, thanks for sharing smile.png
This doesn't make sense to me -- the culling data is positions/bounds, which aren't render-states. Storing positions/bounds in a linear array should have no impact on your render state caching/sorting.

Share this post


Link to post
Share on other sites

[quote name='Xcrypt' timestamp='1337635513' post='4942013']
can't really access the data linearly as state caching is more important than culling. Looking at that link you give me now though, thanks for sharing smile.png
This doesn't make sense to me -- the culling data is positions/bounds, which aren't render-states. Storing positions/bounds in a linear array should have no impact on your render state caching/sorting.
[/quote]
Nvm that! It doesn't make much sense :) I confused it with something else.

Share this post


Link to post
Share on other sites
I've just recently come across this question myself so I thought I'll just add to this thread instead of creating a new one.

I'm actually more interested in the higher level design of managing a scene and incorporating multiple culling techniques rather then implementation details of said techniques. To be more specific here's a number of questions:

1) Is there such thing as a scene manager these days? If so, what is its purpose exactly? Does it manage a group of spatial views and automagically determine which one an object gets inserted into?
2) When and who determines what culling technique are applied to objects? (Eg. static vs. dynamic objects)

Share this post


Link to post
Share on other sites
I'm not an expert on the matter, but from what I have read in recent articles, scene graphs are a no-go today. I would like some enlightenment on the topic too.

Share this post


Link to post
Share on other sites

I'm not an expert on the matter, but from what I have read in recent articles, scene graphs are a no-go today. I would like some enlightenment on the topic too.

Scenegraphs themselves can be useful, but having them heavily tied into other systems is a no-go. All the scenegraph should be responsible for is concatenation of transforms - and thats a distinct process that can be done in isolation before culling even begins.

Share this post


Link to post
Share on other sites

[quote name='Xcrypt' timestamp='1338340402' post='4944509']
I'm not an expert on the matter, but from what I have read in recent articles, scene graphs are a no-go today. I would like some enlightenment on the topic too.

Scenegraphs themselves can be useful, but having them heavily tied into other systems is a no-go. All the scenegraph should be responsible for is concatenation of transforms - and thats a distinct process that can be done in isolation before culling even begins.
[/quote]
Not to confuse the issue or nitpick, but what you are describing is a hierarchical tree and not a graph. A hierarchical tree generally has only one meaningful way to traverse, (that is from top-down) and can therefor only be optimized for a single purpose.

A scene graph in the traditional sense is a multipurpose database that can be traversed in many different ways to visit nodes in different optimal orders for different purposes. The thing about "scenegraph" is that it has turned into a blanket term that gets thrown around and misrepresented. If you're just storing a tree to do transforms to/from world space, then you don't have a scene graph so don't even call it that.

They are not an obsolete concept and they did not die out with the fixed function pipeline, as I think is a commonly held belief. They are just as applicable today as they ever were, they just didn't turn out to be all that useful in practice and are really more trouble than they are worth.

On the other hand, if you were to embed an existing graph database and actually squeeze some good real-time performance out of it, you'd have a potentially very powerful tool at your disposal. I just don't see the need, it's overkill in most cases.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement