Sunday 20 January 2013

Graphics Programming: Frustum Culling

For a little bit of fun i thought i would try and speed up the frame rate of my graphics applications. I am not really sure if i have done this the correct way and it is a bit different from a few of the tutorials that i found online and i still have not finished tinkering with it, but it has somehow increased the frame rate so here is what I've done so far.

 In my understanding to find out if an object is in view or not you calculate the viewing frustum by using the following plane definitions.

Once you have these definitions you then take a co-ordinate that is transformed into camera space and do the dot product of the co-ordinate and the plane, if the value is positive it is in view and if it is negative it is not in view. 

This is the process that i have followed, i calculate each of the planes and store them in an array. I then have a function which takes in the co-ordinate to be checked, convert it into camera space and calculate the dot product against each of the frustum planes, if the value for any of the planes is less than zero the function will return false and the object will not be drawn else it will return true and the object will be drawn.

The scene i have used to test this is the same scene from the fog example which contains some furniture which is created from multiple geometry objects and some simple terrain generated from a height map. 

gDEbugger is used to display the frame rate and some other performance metrics. 


With all the furniture geometry being drawing this scene is getting a frame rate of ~170fps and there is 634.6K vertices/frame. 



If we rotate the camera around so that the furniture objects are out of view and not being rendered. We can see that the amount of vertices/frame, triangles/frame and primitives/frame all drop and there is a big increase in frame rate to ~ 509fps when we are sending less geometric primitives down the graphics pipeline. 

I am currently passing in the position of the object rather than making use of bounding volumes and bounding volume hierarchy's i am also only calculating the frustum planes once and storing the values compared to other tutorials i have seen where the planes are being calculated every frame. 

I am going to try and continue working on this if i get a chance but i start back at university this week and have some pretty interesting modules this term and get to work on some exciting projects which i am looking forward too! 

If you would like a copy of the code feel free to email me and i will be happy to send it to you. Thanks for reading! Any questions or feedback i would love to hear from you.

Email: 10004794@napier.ac.uk - Please put blog in the subject.
Xbox Gamertag: craigmcmillan01
Twitter: 
steam: craigmcmillan01
add or follow and we can game!

No comments:

Post a Comment