Game Engine Occlusion Example

Hello,

Please find attached a simple blend file (v2.58) and a screen shot that demonstrates occlusion culling in the blender game engine. I often see videos on you tube where FPS is suffering due to what I suspect is overly complex objects and a lack of culling.

It took me a short while to figure out how the scene was to be set up to use the bullet physics based occlusion culling but it appears to do the job when running. Obviously there are no real benefits in this scene but were there several rooms full of complex objects there would be a significant benefit.

Instructions: Open the Blend file, while hovering mouse over the 3D window hit P to start the game engine. Use the mouse and WASD keys to move the camera around the scene.

When moving around the scene you should see that objects that are blocked by the walls of the largest cube are removed from the scene and only reappear when they become visible through the doorway. If you go to the world tab and switch off Occlusion Culling you will see the difference to the scene. If you switch into solid or textured drawing mode you will see that there are no impacts on what you can actually see.

Attachments

occlusion_test.blend (74.2 KB)


1 Like

It would be good to present some screenshots showing what you mean.

If you mention the BGE version it would be easier to open the file with the right version ;).
Please add a short manual here or in the file (what keys are used, what the user is supposed to see and why). Otherwise it is hard to guess how to use this file.

Correction: Occulision is used for rendering not for physics (bullet). You can see that by enabling “Show Physics Visualisation” in the Game menu.

Thanks very much for the above advice, I have made appropriate corrections to the posting to make it more useful.

While occlusion is a function of the rendering pipeline in deciding what to send to the GPU, it is my understanding that blender implements firstly view frustum occlusion and then utilises the Bullet physics engines dynamic bounding volume tree (DBVT) feature to decide which objects are occluded in the scene. While this isn’t strictly a physics function it is a physics engine feature.

Much better description right now :).

Now I understand why you are referencing the Bullet Engine. I didn’t know that. I thought occlusion is a feature of the 3D engine. But I never looked at the internals.
So I learned something today

Thanks
Monster

Thanks. I’ll have to study this later. I’ve always wanted to learn to use it properly.

Yes, o-culling is very important and i am glad we found it in GE.
Great example.

Cheers for the example, havent had a chance to check out Occlusion culling properly yet.

So the idea is to enclose any large group of random objects with an “occlude” box so as to prevent the rendering of all unseen objects, right? And we add such an “occlude” cube inside the walls of every building (for example) just like collision boxes around the players and enemies?

Can anyone please confirm if I understood it correctly?

Kind of. If I’m correct, I believe the idea is to ‘occlude’, or hide high-poly objects with low-poly objects. An example would be a gate occluding the rest of a scene - there’s no reason to render the rest if the gate is in the way. Once you move the gate aside, the scene will render.

Why does the GE render objects it can’t see? Basically, why the need for occluders? Shouldn’t this happen anyway? If I’m standing in a room, why does the GE render a table on the other side of the wall? Or a table behind me for that matter. Shouldn’t the ge simply create an on the fly picture of what I can see? I’ve always been confused on this point.

Thanks, that’s what I had in mind, but in addition my point was that Occlude objects don’t only stop other out-of-view objects from being rendered, they also let moving ones (e.g. player) pass through. So we need these two “layers” I was talking about in the previous post: one low-poly Occlude object that optimizes rendering and a second Static wall/door object that “covers” it, holds textures and stops the player from going “noclip mode”.

–8<–

Because all polys/tris are rendered. On the Unity website I read this:

This [i.e. Occlusion Culling] does not happen automatically in 3D computer graphics since most of the time objects farthest away from the camera are drawn first and closer objects are drawn over the top of them (this is called “overdraw”).

Also occlusion culling is not always efficient:

If the occluders are small and don’t hide many objects.
In that case, occlusion culling is just dragging your CPU down.
If the occluders are large but hides simple objects.
In that case you’re better off sending the objects to the GPU.
If the occluders are large and hides many complex objects but in a very predictable way.
Example: a house full of complex objects. Although occlusion culling will perform well in this case, you will get better performance by implementing a specific logic that hides/unhides the objects; for instance making the objects visible only when the camera enters the house.

Thanks. That’s a bit odd. Seems like a weird reason to draw objects you can’t see, but then again I know nothing of how game engines work. Why would the computer need to render objects behind the player? No overdraw there.

I like to set my camera clipping to a hair further than largest distance I will see in a level - if a 20’ hall way is the longest distance I can see in a level, I’ll set my clipping to 20’ + a bit. It has a good affect on frame rate - I guess it’s forcing the ge to completely ignore things beyond it’s draw distance. It will still render things through walls, but perhaps a well considered draw distance + occluders is the best solution.

@Man - Ah, yes. My mistake.
@3D - Yes, I believe objects that are out of the clipping range of the camera aren’t drawn. One could make fairly easy Level of Detail on complex objects by simply sliding them out of the range of the camera, and sliding them back up when it’s time to look at it.

Any reasonable rendering engine would already do occlusion culling… i think BGE does it too… im’ not sure i understand why we need this…

Any reasonable rendering engine would already do occlusion culling… i think BGE does it too… im’ not sure i understand why we need this…
Are you basing “reasonable” on what you think should be the case, or you know is the case - “I wish I had a million dollars vs. my account balance is 1 million”. I don’t mean this in a sarcastic manner. Do you know for a fact that a specific GE occludes automatically? You were not very precise - I can’t imagine why the developers would create something we don’t need - “Hey, the GE culls automatically, and that’s great, but you know what, let’s make a manual culler as well, just for fun.”

@gizmo - The BGE most definitely does not already occlusion cull, which is why we have the occluder type. As you might have seen three posts above, the Unity game engine, a powerful, professional, non-free game engine doesn’t automatically do occlusion culling either. EDIT: And if you check out Unity’s page in the post above, you’ll see it’s a little complex to set up. Bullet’s is most likely slower, but is far easier to set up, as well.

If you designed your occlusion scene in the vein of Unity’s example, using a mixture of occlusion objects and cells to hide nearby objects, it would probably perform well…

oh you guys forgot link from one of my favorite books :smiley: :
http://http.developer.nvidia.com/GPUGems/gpugems_ch29.html
Its really worth giving a read, explains quite a bit on how to set up occluders properly.

I dont think many game engines have automatic occlusion culling, for the obvious reason occluders arent always optimised. They could instead slow your game down if used improperly. UDK has automatic occlusion culling as far as I can remember but its not for all types of objects I suppose (I am sure it isnt for terrains but dunno how much for static objects.)

i got confused with the Frustum Culling and the Occlusion culling… this makes sense now… :smiley:

lol same thing happened with me some time back. :smiley: