OpenGL VRML W3D            
  Home Tutorials Books Applications Tools Docs Models Textures  

 

              Bugs

View Frustum Culling Tutorial   

  View Frustum Culling Tutorial

Index
Introduction
View Frustum's Shape

Geometric Approach
Extracting the Planes
Implementation
Testing Points and Spheres
Testing Boxes
Testing Boxes II
Source Code

Clip Space Approach
Extracting the Planes
Implementation

Radar Approach
Testing Points I
Testing Points II
Implementation
Testing Spheres
Implementation II
Source Code

Notes and Refs
Notes and Optimization
Further Optimization
References


Google

OpenGLTutorials @ Lighthouse3d.com

Led Shader
View Frustum Culling
GLSL Tutorial
Maths Tutorial
Billboarding Tutorial
Picking Tutorial
Terrain Tutorial
Display Lists Tutorial
GLUT Tutorial

   
[Previous: Introduction] [Next: Extracting the Planes]

View Frustum Culling Tutorial


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.

    [Previous: Introduction] [Next: Extracting the Planes]

           


    Site designed and maintained by António Ramires Fernandes
    Your comments, suggestions and references to further material are welcome!

    Lighthouse 3D privacy statement