Rendering only what the camera see

Started by
10 comments, last by Anddos 10 years, 6 months ago
For getting higher performance, is there is anyway to render ONLY what the camera see?
Since it's not really important to render anything that the camera can't see
Advertisement

Frustum culling on the CPU. Traverse your draw list and remove items that are outside the frustum, or don't add them in the first place.

You'll have to find some balance between the performance gain and the costs related to some method of frustrum culling. Maybe you'll realise that it actually is faster to render everything all the time (even in this case pixel shaders are NOT executed for pixels outside of the camera frustrum) than to spend CPU power on frustrum culling.

To be able to render only some objects you also must have your meshes divided, which means more draw calls - this applies especially to large static meshes like the terrain. Maybe it will be faster to render the whole terrain in one draw call than to render 10 pieces of the terrain out of 50 pieces?

But this is all MAYBE. It depends strongly on what actually are you rendering, what kind of game, how does is look like, how many objects there are and how complicated they are etc.

In some cases even a very simple, basic and cheap frustrum culling against axis-aligned bounding boxes or bounding spheres can give you huge performance gain.

To elaborate on Tom KQT, here's another example.

Say you have a particle system generating 1000 particles. Do you cull each particle? Not at all! You cull the particle system itself.

A particle system with 1M particles? We might try to split it in spatial chunks.

Granularity is key. Personally I've found that even on rock bottom hardware vertex transform is so fast that I can draw 2x more vertices at 10% more cost (at worse). So I made all my batches (and thus their culling box) twice as big. The performance was about the same. I then made my batches even bigger and found out there was an improvement in performance. Right now the batches are about 10x the original size and they still give better perf than the original. Why? Probably because D3D9 batch dispatching is really that slow.

Previously "Krohm"

To elaborate on what others have said, you want to go through all your objects/batches and test if they are inside the camera frustum. This is usually done by checking each object's bounding box against the camera frustum, which can easily become an expensive operation to perform.

However, it can be optimized in several ways:

  • Including more geometry per batch (see Tom KQT and Krohm's post); this is only valid for static geometry though.
  • Have some kind of tree data structure, such as an Octree so you can easily discard tons of tests by avoiding checking sub-objects of a huge container if the container itself is out of the frustum.

Note: Don't forget that you should still sort your objects by material (texture, shaders, etc) after gathering the visible objects (or while doing so) for maximum performance.

Have some kind of tree data structure, such as an Octree so you can easily discard tons of tests by avoiding checking sub-objects of a huge container if the container itself is out of the frustum.

The lesser-known variant of this is that if a parent node is fully inside the frustum, all of it's child nodes are also going to be fully inside, so you can also skip over checking them too. Only child nodes where the parent intersects the frustum (as well as the root node) need testing; everything else is a trivial accept or trivial reject.

This approach can also be broken down to individual frustum planes (a parent node on one side of a frustum plane has all of it's children on the same side of that plane, in other words) for more efficiency.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

In some cases, occlusion culling is equally and sometimes more important and valuable than frustum culling. If you have a large scene, with the camera on one side facing the other - culling things outside the view won't prevent the entire scene from being dealt with - because it's still all within view, just likely to be covered up by the closest parts of the scene.

There are many resources, articles, and books, that delve into various algorithms and approaches for occlusion culling.

http://en.wikipedia.org/wiki/Hidden_surface_determination

Thanks guys,

Is there is anyway to cull anything which its depth is further than the appearing objects?

Any other suggestions to get high performance?


Is there is anyway to cull anything which its depth is further than the appearing objects?

Frustum culling, which has already been mentioned. A frustum has 6 sides, which include the near and far planes.


Is there is anyway to cull anything which its depth is further than the appearing objects?

Frustum culling, which has already been mentioned. A frustum has 6 sides, which include the near and far planes.

Maybe he was talking about culling objects which are hidden behind other visible objects, not which are further than the far clip plane.

In this case radioteeth's post applies (occlusion culling).

This topic is closed to new replies.

Advertisement