mesh culling (octrees)

Started by
15 comments, last by y2kiah 11 years, 10 months ago
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
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...

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).

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

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.

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?
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.

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?
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;
}
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 :)

This topic is closed to new replies.

Advertisement