Sheet 07: Frustum Culling

Exercise: Bounding Boxes and View Frustum Culling

By default the scene contains 256×256 stationary teapots on a large ground plane, each with its own position and rotation. Configure the grid size with the teapotsPerSide parameter of FrustumApp. Implement the three functions in Culling.h. The rendering and camera are already provided. Use world coordinates consistently for the bounding boxes.

Task 1: World-Space Bounding Boxes

Implement computeAABB in Culling.h. Transform every mesh vertex by the instance's model matrix and calculate the minimum and maximum coordinates on each world axis.

The teapots are stationary, so each box is computed once at startup. Make sure the world-space box encloses the teapot after applying its rotation and translation.

Task 2: View Frustum Test

Implement intersectsFrustum in Culling.h. Test the box against all six planes of the camera frustum and return false only if it is completely outside at least one plane. Boxes intersecting a plane must remain visible.

Pay particular attention to rotation, near and far planes, and boxes that cross the frustum boundary. The six-plane test is conservative: some boxes outside near a corner can still be accepted.

Task 3: Merging Bounding Boxes

Implement mergeAABBs(a, b) in Culling.h. Return the smallest AABB containing both input boxes.

The provided hierarchy first groups neighboring teapots into 2×2 blocks, then groups 2×2 of these blocks, continuing until one root box encloses the scene. At odd-sized edges, a block has fewer than four children. Each frame, an entire subtree is skipped when its box is outside the frustum.

Reference Solution

Loading

Reference solution. Hold W/S to fly forward/backward in the viewing direction and A/D to strafe. Drag with the left mouse button to look around; the mouse wheel moves forward/backward. Press C to toggle culling, B for bounding boxes, H to cycle merged boxes through individual levels, all levels together, then off, F for distance fog, O to show or hide the overview (hidden by default), and R to reset the camera. The overview shows submitted teapots in red; skipped teapots are omitted there as well. The yellow lines show the camera frustum; merged boxes use a different color for each hierarchy level.

Text description and demo controls

A large ground plane contains a grid of stationary teapots with different rotations. The main view shows the scene from a movable camera. Hierarchical view frustum culling skips groups of teapots outside that camera's frustum. A top-down overview in the upper-left quarter shows the teapots selected for rendering in red and the camera frustum as yellow lines. Skipped teapots are omitted from both views.

Individual bounding boxes can be displayed around selected teapots. Merged boxes on a chosen hierarchy level, or all merged-box levels together, appear as colored lines in both views, including boxes outside the frustum. These boxes group 2×2 teapots, then 2×2 of those groups, and so on. Each merged-box level has its own color. Individual teapot boxes remain separately controlled by B. Distance fog softens the far clipping boundary in the main view; the overview remains fog-free. Disabling culling submits all teapots in both views.

Focus the demo with Tab. Hold W or S to fly forward or backward along the viewing direction; A and D move sideways. C toggles culling; B toggles individual bounding boxes; H cycles through individual merged-box levels, then all levels together, then hides them; F toggles fog; O shows or hides the overview, which is hidden initially; R resets the camera position and orientation. Changing the viewing direction currently requires dragging with the left mouse button. The mouse wheel also moves forward or backward.