Skip to content

3D Software Rasterizer

Built from scratch in C++ using SDL3 — no engines, no graphics APIs, no shortcuts.

Final render
Final render — Phong (left) and Toon shading (right), two lights, shadow mapping, ~30 FPS on CPU.

What is this

Every pixel, every frame on screen — every triangle, shadow, and reflection — is the result of a complex process that transforms objects with 3D coordinates into colored pixels. Game engines abstract this entire process, and GPUs accelerate it in hardware. This project aims to understand exactly what happens at each step — and the only way to do that is to build it in software: every mathematical operation happening in plain C++ code, with nothing hidden underneath.

A software rasterizer takes a 3D scene, applies a series of mathematical transformations, and writes the final colors directly into a framebuffer — the list of pixels that ends up painted on screen. All of it without graphics APIs like OpenGL or Vulkan. Just math, memory, and a lot of debugging.

Why from scratch

The question that started all of this: how does a flat screen trick our eyes into seeing depth? The only way to truly answer it is to build the thing yourself. Not use it — build it.

Every concept in this project was understood before it was coded. Before writing a single line, I made sure I could explain it, draw it, and derive it on paper. If I couldn't reconstruct the reasoning from scratch, I didn't implement it yet. Nothing was copied without understanding where it came from.

The result is a renderer I can explain from first principles — and this documentation is the attempt to do exactly that: explain each concept as clearly and intuitively as possible.

What it does

Math Custom Vec2 · Vec3 · Vec4 · Mat4 from scratch
Rasterization Barycentric coords · perspective-correct interpolation
Depth Z-buffer with per-pixel depth testing
Pipeline Model · View · Projection — full MVP from scratch
Parsing OBJ + BMP parser — zero external libraries
Camera Free WASD + mouse look · yaw · pitch
Textures UV mapping · perspective-correct sampling
Culling Backface · frustum culling
Lighting Phong · directional + spot lights · toon shading
Shadows Shadow mapping · bias · spotlight perspective
Threads Multithreaded rasterizer across CPU cores

Stack

Language C++17
Windowing SDL3
Build CMake
IDE CLion
Dependencies SDL3 only — everything else is written from scratch

How to read this

Each section covers one stage of the pipeline in the order it was built. The goal is educational: every concept is explained from first principles, with interactive visualizations embedded directly in the page to make the math tangible before looking at the code.

Each page also shows how the process actually went — including the bugs, the dead ends, and the moments where something only made sense after drawing it on paper. The Process & Research section has the actual handwritten notes from a reMarkable tablet, and Bugs — Hall of Fame collects the most interesting failures.

The interactive visualizations were designed by me and built with Claude — each one targets a concept I found genuinely hard to understand the first time.