Workshop 1 - View-Frustum Culling

The base code for this lab can be found on GitHub here

Overview

The goal of this assignment is to implement a simple view-frustum-culling program. The base code draws a simple scene with snowmen and Nefertiti models. Using bounding spheres, we will individually cull each model that is outside the view frustum.

The base code also includes two top-down view of the scene - one with VFC enabled and one without.

Your task is to implement the stubbed VFC functions.

Steps

Step 1: Extract Frustum Planes

Refer to this resource for details on how to extract planes from a composite projection-view matrix. Note that the article begins with an explanation for Direct3D - skip over this to get to the OpenGL explanation (it’s different because of the canonical view volume for each platform).

Your code should go in ExtractVFPlanes

Step 2: Implement Cull Function

Now that we have our planes, we must use them to cull objects!

First, implement DistToPlane to return the distance from a point to a plane (signed distance - positive on one side and negative on the other).

Then, implement ViewFrustCull so that it returns 1 for any object outside of the frustum!

Notes

GLM Matrix Element Access

glm mat4 has the [] operator overloaded so that you can access individual elements. However, it confusing provides access to columns. Also, it indexes from 0 (as it should) instead of from like the matrix resource.

So is equivalent to m[0][2] for us.

Implicit Plane Equation

A plane is defined by a point and a normal . The plane consists of all points for which is perpendicular to .

Or, using the dot product:

And to get the implicit equation:

where

or

The implicit equation gives us a way compute (signed) distances from a plane.