Skip to content
Simon Dietz edited this page Jan 24, 2025 · 16 revisions

Dev Log

Date: 2025-01-24

Adding Backface Culling to the Voxel Engine

Today, I continued optimizing the voxel engine and added backface culling to improve rendering performance.

Backface culling is a technique in 3D graphics where polygons (or faces) of an object that are not visible to the camera (i.e., their "back side") are not rendered. This reduces the number of faces processed by the GPU and helps improve performance, especially in complex scenes.

Processing does not provide direct access to this feature, so I utilized the PGL graphics context to implement it myself. To make it reusable, I added two new methods to my custom graphics context:

void enableFaceCulling();

void disableFaceCulling();

The Processing-specific implementation looks as follows:

public void enableFaceCulling() {
    PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
    pgl.pgl.frontFace(PGL.CCW); // Counter-clockwise winding order for front faces
    pgl.pgl.enable(PGL.CULL_FACE); // Enable face culling
    pgl.pgl.cullFace(PGL.BACK); // Cull back faces
}

public void disableFaceCulling() {
    PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
    pgl.pgl.disable(PGL.CULL_FACE); // Disable face culling
}

By enabling face culling, only the outer faces of the objects are rendered, significantly reducing the number of rendered polygons. This is especially useful in voxel-based systems where many internal faces are hidden and unnecessary for rendering.

Clone this wiki locally