Jump to content

  • Log In with Google      Sign In   
  • Create Account

mesh culling (octrees)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 20 May 2012 - 09:27 PM

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 Posted Image

Edited by Xcrypt, 20 May 2012 - 09:28 PM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 30388

Like
1Likes
Like

Posted 20 May 2012 - 10:59 PM

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?

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

#3 Ashaman73   Crossbones+   -  Reputation: 7517

Like
1Likes
Like

Posted 20 May 2012 - 11:56 PM

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

#4 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 21 May 2012 - 05:30 AM

What was the date on those articles? 15 years ago when octrees were cool, the world rendering loop looked more like for each polygon: set states, draw polygon instead of for each batch, set states, draw triangles. 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

#5 AgentC   Members   -  Reputation: 1342

Like
0Likes
Like

Posted 21 May 2012 - 07:14 AM

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.

Every time you add a boolean member variable, God kills a kitten. Every time you create a Manager class, God kills a kitten. Every time you create a Singleton...

Urho3D (engine)  Hessian (C64 game project)


#6 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 21 May 2012 - 08:02 AM

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?

#7 TiagoCosta   Crossbones+   -  Reputation: 2201

Like
0Likes
Like

Posted 21 May 2012 - 01:30 PM

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, 21 May 2012 - 01:35 PM.


#8 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 21 May 2012 - 01:56 PM

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 Posted Image )
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, 21 May 2012 - 02:08 PM.


#9 kalle_h   Members   -  Reputation: 1389

Like
1Likes
Like

Posted 21 May 2012 - 02:31 PM

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[i].normal.x * center.x + planes[i].normal.y * center.y + planes[i].normal.z
	 * center.z) < (-radius - planes[i].d))
    return false;
  return true;
}


#10 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 21 May 2012 - 03:25 PM

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, 21 May 2012 - 03:27 PM.


#11 synulation   Members   -  Reputation: 271

Like
1Likes
Like

Posted 21 May 2012 - 04:29 PM

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

#12 Hodgman   Moderators   -  Reputation: 30388

Like
0Likes
Like

Posted 21 May 2012 - 09:55 PM

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 Posted Image

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.

#13 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 22 May 2012 - 12:15 AM


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 Posted Image

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.

Nvm that! It doesn't make much sense :) I confused it with something else.

#14 Shael   Members   -  Reputation: 277

Like
0Likes
Like

Posted 22 May 2012 - 01:23 AM

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)

#15 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 29 May 2012 - 07:13 PM

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.

#16 Digitalfragment   Members   -  Reputation: 845

Like
0Likes
Like

Posted 29 May 2012 - 10:16 PM

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.

#17 y2kiah   Members   -  Reputation: 975

Like
0Likes
Like

Posted 30 May 2012 - 04:32 PM


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.

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS