View Frustum’s Shape
Prev: Index | Next: Geometric Approach - Extracting the Planes |
Shape of the View Frustum
In this section the shape of the view frustum is related to the instructions issued by the OpenGL application. It is assumed that a perspective projection is defined using the gluPerspective
function, and that the camera is positioned with the gluLookAt
function.
First let’s recall the parameters (all floats) of these functions:
gluPerspective(fov, ratio, nearDist, farDist);
gluLookAt(px,py,pz, lx,ly,lz, ux,uy,uz);
The apex of the pyramid is the position of the camera (px,py,pz). A view ray can be computed with direction d = l – p, where l = (lx,ly,lz) and origin p = (px,py,pz). The near and far planes are perpendicular to the view ray and are placed at distances nearDist and farDist. The rectangular boundaries of the view frustum in those planes, near and far, have dimensions that are a function of the distance and the fov (vertical field of view), and ratio (ratio between the horizontal and vertical fields of view).
The height and width of the rectangular boundary on the near plane are defined as follows:
Hnear = 2 * tan(fov / 2) * nearDist Wnear = Hnear * ratio
The same reasoning can be applied to the far plane:
Hfar = 2 * tan(fov / 2) * farDist Wfar = Hfar * ratio
In order to perform view frustum culling, two steps are required:
- Extract the frustum volume information – this has to be done every time the frustum changes, i.e., when the camera moves or when the perspective changes
- Test the objects against the frustum’s volume to determine whether to cull or not – this has to be performed for every object in every frame. If the culling status of each object is kept from frame to frame then the test itself may be done only when the camera moves, i.e. when the frustum is updated or perspective changes.
The demo opens three windows: the user camera view, a window where the user camera and the view frustum can be seen from the top, and finally a third with a view from the right. The spheres inside the frustum are shown in green, the ones that intersect the frustum are drawn in yellow, and the ones outside the frustum are rendered in red.
Prev: Index | Next: Geometric Approach - Extracting the Planes |