Occlusion culling

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Occlusion culling

Post 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
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

Post by roelor »

if this is done through irrlicht you can post it at project anouncements.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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...
Image Image Image
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post 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.
Last edited by christianclavet on Tue Jan 06, 2009 12:47 am, edited 1 time in total.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post 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.
Image
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post 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)
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post 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.
Image
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post 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
Image
Malgodur
Posts: 195
Joined: Sun Mar 15, 2009 8:22 pm

Post by Malgodur »

ITS GREAT!! Are you going to release the source code?
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post by Katsankat »

Cloudef
Posts: 123
Joined: Wed Dec 03, 2008 9:02 pm
Location: Finland

Post 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:
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

This is some great work! Do you have anything to create the bxp file?
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post 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.
lymantok
Posts: 67
Joined: Mon Dec 31, 2007 6:13 am

Post by lymantok »

Katsankat, the link above is dead. Is the download available elsewhere? Thx.
drr00t
Posts: 14
Joined: Wed Aug 05, 2009 2:11 pm
Location: Brasilia/DF - Brasil

Post 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
Post Reply