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 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.
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.