All projects

Engine-0

I built a real-time graphics engine in C++17 and OpenGL 4.6, with an entity-component architecture and a scene editor. The engine supports multi-pass deferred physically based rendering, GPU light culling, and adaptive terrain.

  • C++17
  • OpenGL 4.6
  • GLSL
  • Dear ImGui
View source on GitHub
An industrial corridor rendered in Engine-0, with warm overhead lights, pipes, and concrete panels
Industrial corridor with 34 point lights, emissive fixtures, and environment lighting.

Engine architecture

The entity-component system organizes scene data into transforms, geometry, materials, lights, terrain, and environment probes. Factories assemble entities from components and reuse meshes, shaders, and textures from shared resource libraries.

The scene registry supplies entities to the rendering, lighting, and probe systems. The Dear ImGui editor exposes scene properties and individual render targets for editing and inspection.

Earlier engine editor with a rendered terrain viewport, scene outliner, and render-target controls
An earlier view of the Dear ImGui editor with the scene outliner and render-target controls.View full resolution

Rendering pipeline

  1. Geometry

    Write positions, normals, and material data to the G-buffer.

  2. Directional shadows

    Render a variance shadow map.

  3. Screen-space ambient occlusion

    Calculate occlusion from view-space geometry.

  4. Tiled light culling

    Build per-tile point-light lists on the GPU.

  5. Point-light shadow

    Render a depth cubemap for the selected caster.

  6. Deferred PBR lighting

    Combine direct light, environment lighting, occlusion, and emission in HDR.

  7. Bloom and tone mapping

    Apply bloom, then tone map the HDR result.

  8. Sky composition

    Composite the sky using scene depth.

Physically based rendering

The deferred shader evaluates a Cook-Torrance microfacet BRDF with a GGX normal distribution, a Smith geometry term using Schlick-GGX factors, and Schlick Fresnel. Materials use a metallic-roughness workflow with maps for base color, normals, roughness, metallic, and material occlusion. Base color, roughness, and metallic also support constant values.

Five shader balls with gold, ceramic, copper, steel, and textured wood finishes
Gold, ceramic, copper, steel, and textured wood under the same studio environment.View full resolution
A five-by-five sphere grid with metallic decreasing down the rows and roughness increasing across columns
Metallic decreases from 1.00 to 0.00 down the rows. Roughness increases from 0.05 to 0.95 across the columns. Base color, lighting, and camera are fixed.View full resolution

Deferred rendering

The geometry pass writes surface and material data to the G-buffer. The deferred pass reads those attachments to combine direct and environment lighting with occlusion and emission. Emissive surfaces contribute to bloom, while analytical lights illuminate nearby geometry.

Individual attachments can be inspected to isolate material and lighting issues.

G-buffer views
A window and warm bulb illuminate a vintage film camera and a wooden shelf

Interior render targets. Material AO is stored in the G-buffer. Screen-space ambient occlusion is computed in a separate pass.

View full resolution

Image-based lighting and shadows

HDR environments are processed into diffuse irradiance cubemaps and roughness-prefiltered specular cubemaps. Deferred lighting combines these with a BRDF integration lookup texture. Local probes blend precomputed HDR environments with the sky using distance-based weights. Reflections sample the HDR maps.

The directional light uses variance shadow mapping. One selected point light can cast shadows using a six-face radial-depth cubemap.

HDR environment lighting

The same spheres lit by a starry sky over a rocky landscape
Material spheres lit by an afternoon HDR environment

Only the HDR environment changes. Camera, materials, and exposure are fixed.

Local reflection probe

Vintage camera model with added Kloofendal probe lighting
Vintage camera model with Kloppenheim sky lighting

The local Kloofendal probe changes the camera model’s lighting and reflections while Kloppenheim remains the visible sky.

Shadow mapping

The same interior with directional and point-light shadows disabled
A window and warm bulb illuminate a vintage film camera and a wooden shelf

Directional and point-light shadow mapping enabled and disabled. Lighting, ambient occlusion, and exposure remain unchanged.

Tiled deferred lighting

A compute shader projects conservative point-light bounds, assigns overlapping lights to 16 × 16 screen-space tiles, and writes candidate counts and indices to shader storage buffers. The deferred pass reads the current tile’s list and checks each candidate against its light radius at the fragment.

Point-light comparison

The same corridor lit by the key point light, with glowing fixtures
Industrial corridor illuminated by all 34 point lights

Both views use tiled lighting with fixed camera, exposure, environment lighting, fixture emission, and shadow caster.

Candidate counts read from the GPU and overlaid on the lit corridor, with red tiles indicating higher counts
GPU-assigned candidate counts overlaid on the corridor. Cooler colors indicate fewer candidates.Full-resolution density map and legend

Light culling results

Uploaded point lights
34
Tile size
16 × 16 px
Mean candidates per tile
21.08
Candidates per tile
10–34
Overflowing tiles
0

34-light corridor at 1280 × 720.

Adaptive terrain

A 16-bit, 1025 × 1025 heightmap generates a 1024 × 1024 m terrain. Geomipmapping selects distance-based LODs on a 16 × 16 patch grid and culls patches against the camera frustum. Neighboring patches differ by at most one LOD step, with stitched indices along mixed-resolution boundaries.

World-space triplanar materials blend by slope and elevation. Stochastic hex sampling breaks up visible texture repetition.

Terrain views
Shaded terrain with rocky peaks, grassy slopes, and a gravel transition

Terrain with slope-dependent triplanar materials.

View full resolution

Terrain geometry reduction

Geomipmapping with patch frustum culling reduced submitted triangles by 91.7% from the same camera.

ConfigurationSubmitted triangles
Full-resolution mesh2,097,152
Geomipmapping with patch culling173,584
Asset credits

The Poly Haven models, textures, and HDR environments use CC0 1.0. Poly Haven asset license

Material study

Interior and reflection probes

Environment maps

Industrial corridor

Terrain

The window frame reuses Wood Table maps. A Python script procedurally generated the 16-bit terrain heightmap offline.

The MaterialX viewer shader ball and AO map are credited to Autodesk’s Solid Angle team, with a mesh contribution by Ben Nadler at Lucasfilm. The matrix uses the MaterialX preview sphere with smooth normals added during preparation. MaterialX Apache 2.0 license

View source on GitHub