# Help me with this(Occlusion culling out door)

I am following this tutorial.

http://www.gamasutra.com/view/feature/2979/rendering_the_great_outdoors_fast_.php

I have got it working. I am trying on a Iphone simulator one box as occluder and 100 cars at the same position. Actual the frame rate drops 3 times when I enable the culling.
All advices are welcome but my biggest concern is how to build the convex hull. Previously

std::vector<Edge> edges
for(All vertices, i+=3){
edge1(vertex1,vertex2)
edge2(vertex2,vertex3)
edge2(vertex3,vertex1)
loop edges and check if edge1 exist(comparing 3 floats, not good I know)
same for edge 2 and 3
loop edges…
loop edges…
}

My new plan is to create a class

class Edge{
private:
vector normal;
Edge *opposite;
}

First I will create all edges between all vertices. And create a vector of edges (std::vector<Edge> edges).

the I will do something like

``````
for(size_t i = 0; i < edges.size(); i++ ){
for(size_t j = i + 1; j < edges.size(); j++ ){
if(edges[i] and edges[j] sharing the same vertices){
edge[i].opposite = edge[j];
edge[j].opposite = edge[i];
}
}

}
``````

Now my list of edges knows it neighbors. All I do know to create the convex hull.

``````
for(All edges){
if(isFacingCamera(edges[i].normal)){
if(edges[i].opposite == NULL or  !isFacingCamera(edges[i].opposite.normal))
}

}
``````

Sorry for my bad “code”. Its just my thoughts. How would you compute the convex Hull?

For occlusion culling you want something that you can draw fast (otherwise you could just draw your objects and rely on the depth test to get things right), so it should be a simple shape, possibly just a box.
And you only want to construct this shape once (or at most update it only occasionally), so having something like isFacingCamera() is probably not a good idea as that changes quite often.
So instead of constructing a tight convex hull you might want to try simply building an object aligned bounding box by taking the largest and smallest x,y,z values over all vertices and render that as your occlusion test geometry.

But how can the Bounding box be used for culling. For example a giraffe. Ok its not a good occluder but I hope you get my point. Between the legs things that not are suppose to be culled will be culled. The convex hull of a bounding box will also change when moving the camera around.

Occluders should be totally enclosed by actual geometry object.
And not much to do with convex hull, just simplified geometry.

So you mean that every geometry should have a simplified version of it self? Now I am calculating the edges surrounding the occluder(That is the convex hull from the cameras point of view?). Say it is a box witch I am actually testing against now.
I do have to calculate the edges?

I have implemented my thoughts yesterday but no improvement. I guess my test to check if its inside the occlusion planes are to slow. I am currently just doing this test with a simple box and 100-1000 cars behind it to be occluded. Shouldn’t my occlusion be faster than opengls depth test? I would like to provide some more input so you maybe could help me. What would you like to know or see(code)?

I have found the bottle neck. Building the occlusion volume takes no time at all almost. I am having the same FPS as with culling disabled. When I enable the testing the FPS drops dramatically. Whats is wrong.

``````void OcclusionManager::occlude(const btVector3 cameraPositon){

for (size_t i = 0; i < m_occluders.size() ; i++) {

//std::cout << "Boulding occlusion volume " << i << std::endl;
m_occluders[i]->buildOcclusionVolume(cameraPositon);
for (size_t j = 0; j < m_items.size() ; j++) {
/*if(m_occluders[i]->isOccluded(m_items[j])){
//RiAvObject* graphicObject = m_items[j]->getGraphicObject();
//graphicObject->SetAppCulled(true);
((std::cout << "Culling object " << std::endl;
} else {
//RiAvObject* graphicObject = m_items[j]->getGraphicObject();
//graphicObject->SetAppCulled(false);
//m_items[j]->SetAppCulled(false);
//std::cout << "---------------------" << std::endl;
}*/
}

}

}
``````

Here is what slows everything down

``````bool OccludingVolume::outsideConvexHull(const btVector3 min, const btVector3 max) const{
for (size_t i = 0; i < m_planes.size() ; i++) {
if(m_planes[i].inFrontOf(max)){
return true;
}
if (m_planes[i].inFrontOf(min)) {
return true;
}

}
return false;
}
``````

It is working!

FPS Without culling 15:
FPS With culling 60:

The problem was related to the bounding boxes.

Thanks!