Frustum culling

View frustum culling feature show case.

November 25, 2017 - 2 minute read -
opengl cpp mac

The goal of view frustum culling is to be able to identify what is inside the frustum (totally or partially), and cull everything that is not inside. Only the stuff that is inside the frustum, even if only partially, is sent to the graphics hardware. This Process is not only working with meshes, but also wording with particles and lights.

frustum culling

Bounding Box

A bounding box will be generated during the loading process for each GameObject.

bounding box

Obtain a light’s volume radius by solving the attenuation equation. However, this equation will never exactly reach the value zero, so there won’t be a solution. But solve it for a brightness value that is close to zero.

float lightMax = glm::max(glm::max(this->color.x, this->color.y), this->color.z) * this->intensity;
this->radius = 8 * glm::sqrt(lightMax / 5);

Demo

The frustum process will never be seen by player, however I created a test camera which can switch between default perspective and test perspective.

Implementation

Frustum culling process is only happening with the main camera. So I make it a component, which only need to be attached to camera object.

GameObject* camera = new GameObject();
camera->addComponent<Camera>();
camera->addComponent<Transform>();
camera->addComponent<FrustumCulling>();
scene->mainCamera = camera;
scene->addGameObject("mainCamera", camera);

Assets