Page 1 of 2

Occlusion culling

Posted: Mon Jan 05, 2009 11:46 am
by Katsankat
This is something that has probably been done before but was fun to implement.

download (3.94 Mb)

What is it

Irrlicht has already frustrum culling for the camera. However performances can be much improved with another culling method : occlusion culling.

Basically : dont render polygons that can't be seen.

After having looked at the VIS process, it seemed to me that the bsp format is great, but tends to be generic and is loosing performances there. However bsp is nice because there are good intuitive editors around...

This method is not using bsp at all. But the scene is stored in a binary file, like bsp does.


Implementation

So, the map is divided in several virtual areas.
Each area (leaf) is a bloc defined with just 2 points and it contains a list of models.

The idea is that when you are not inside or in front of a room, then you don't have to render the polygons located in other rooms that can't be seen. This is how bsp works. Render leaves that can be seen from the current leaf you're in.

Here it shows only one leaf at a time. Basic : when you leave a room, load the next one and unload the previous one.

Code: Select all

while (Game loops)
	check every 500 milliseconds
	{
		leaf = getCurrentLeaf(); //what leaf am I in?
		if (leaf != currentLeaf)
		{
			unload(currentLeaf);
			load (currentleaf + 1);
			currentLeaf = leaf;
		}
	}
	renderFrame();
}
The test Scene

Two light scene nodes.

A skydome as half-sphere with a special gradient texture (generated with code from an old day&night cycle project) ...

A first model is used for static geometry that is always drawn (350 polies), models/etage.b3d, it is in an octree and consists of three empty rooms, plus the ground is marked with 256X256 units pink squares (in Max and irrlicht) and this about how I determined the position of the 3 leaves.

Then 3 models, one for each room.

Room1 : a bedroom. 11518 triangles.

Room2 : High poly sofa. 39532 triangles. Looks nice in Max, not that much here ...

Room3 : a table and 4 chairs. 26436 triangles.

Running the demo

without occlusion culling : 77892 triangles, 205 FPS
with occlusion culling : 406 triangles, 956 FPS
How much do you get?

Image
Image


Conclusion

Frustrum culling + occlusion culling = great gain of performance


Todo

* Create BXP file easily with a basic editor (if someone is interested ...)
* Add light info into bxp file, as well as fog (and whole entity list)
* Add special effects and lights, stopped on demand!
* Add LOD, should be optimal for the equation then
* Release the code

Posted: Mon Jan 05, 2009 2:54 pm
by roelor
if this is done through irrlicht you can post it at project anouncements.

Posted: Mon Jan 05, 2009 3:08 pm
by JP
Nice one! Looks like some good performance boost there. There have been two other recent attempts at occlusion culling, one of which i believe is sort of still being worked on...

Posted: Mon Jan 05, 2009 10:58 pm
by christianclavet
Wow! If you release this, It's sure that I would integrate this into my projects.

I want to build massive levels and this would be perfect.

You could even propose your source to the IRRlicht dev so that feature could be integrated in newer versions.

Is the culling is based on portals? or other methods? It's really fast! (Got around 600 to 1200FPS with it and 300 to 400 FPS without it)

This would translate even more with a bigger map!
On HAMMER(Source), we can define certain area manually using AREAPORTAL (Linked to a door, if the door is closed then only the area inside is accounted (if the player is inside it), else the inside of the room is dropped) This info is saved in an entity inside the BSP. We can define also certain parts to not be accounted for PORTALING as "func_detail", for objects like stairs pillars etc. This help the VIS process when creating a map.

If you look at this thread, he using PORTALING to define the pathfinding. Using the code in this project thread and reloading it inside your's (creating the .BXP file)
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=31387

If we could read VIS data from BSP, create some VIS info from this thread in a tool and have your code to load that info, we'd have a complete occlusion culling solution for IRRlicht.

Posted: Mon Jan 05, 2009 11:16 pm
by dlangdev
Looks pretty good, I was looking into GTKRadiant for huge environment editing, but... your toy sounds like a lot of fun, though.

So, keep us posted and I'll see if I can be of any help later.

Posted: Tue Jan 06, 2009 9:47 am
by Katsankat
Yes, it is based on portals. It can be described as an implementation of a very particular VIS algorithm for a linear map (or car race).

But real bsp portals are much better because cool editor + handy entity list + radiosity and voila! It is important to have a robust workflow, saves a lot of time. Not easy, I took a look at Sio2 6DX code, and quake3 source code ... Hard. Only experienced programmers can manage to add VIS to the Q3 namespace.

Dlangdev I'll send you the code, you are using GCC right? (I will send it ONLY if you change your avatar LOL kidding)

Posted: Wed Jan 07, 2009 6:02 am
by dlangdev
Thanks for the offer, looking forward to it. By the way, I use Visual Studio 2005 but I can still deal with Autotools.

Posted: Thu Jan 08, 2009 1:52 am
by dlangdev
I'm just going to throw this article in for reference as it might become useful later.

http://www.gamedev.net/reference/progra ... /page2.asp

Posted: Tue May 12, 2009 8:23 pm
by Malgodur
ITS GREAT!! Are you going to release the source code?

Posted: Wed May 13, 2009 5:19 am
by Katsankat

Posted: Wed May 13, 2009 9:31 am
by Cloudef
With: 700-1600
Without: 300-800

I saw the transition in exclusion at windows when far away, but this isn't really issue. All i can say nice work =) Will defienatly use if or when i go to 3d projects again :wink:

Posted: Wed May 13, 2009 1:00 pm
by Lonesome Ducky
This is some great work! Do you have anything to create the bxp file?

Posted: Wed May 13, 2009 3:14 pm
by Katsankat
Depending on your toolchain, develop an editor, or write a max/blender script to export cubes. Perhaps irredit can do it... I did not have time to try it yet. Or you could use a modified version of your engine to embed a built-in editor. press a key would create a bounding box. There would be a class for loading a map, and another for editing/writing map files. It is fine, but ...

Wait this code looks like binary space partitionning, so how about using some CSG editor to compile a real bsp?

Two weeks ago we decided with Scourge to use BSP to develop platoon, because we are both already familiar with Constructive Solid Geometry so we can start to create maps instantly, instead of writing an editor for months. I could rather use my knowledge of GTK+ to get GTKRadiant exactly how we want it, just like some developers did when creating CODRadiant.

Posted: Sat Oct 17, 2009 3:58 am
by lymantok
Katsankat, the link above is dead. Is the download available elsewhere? Thx.

Posted: Sun Oct 18, 2009 2:25 am
by drr00t
Hi,

Great work!!! Irrlicht scene format could be support this kind of node..., irrlicht blender (irrb) from pc0der too.

I got:
130 - 500 fps without
300 - 600 fps with

with my little Gf 7600 GT