Software Rasterizer

Graphics · C++ · 2023

Software Rasterizer

A Complete 3D Rendering Pipeline in Pure Software

Overview

A fully-featured 3D software rasterizer written from scratch in C++. This project implements the complete graphics pipeline in software — no OpenGL, no DirectX, no hardware acceleration. Every stage from vertex transformation to per-pixel output is hand-coded.

The goal was to deeply understand how modern GPUs work internally by rebuilding their core algorithms: clipping, rasterization, depth buffering, perspective-correct interpolation, and programmable shaders — all running on the CPU.

Rendering Pipeline

01

Vertex Processing

Programmable vertex shaders with full MVP transformation support. Built-in shaders include Wave, Twist, Explode, and Spherize effects.

02

Primitive Assembly

Triangles, triangle strips, fans, lines, line strips, loops, and points. Efficient index buffer support for vertex reuse.

03

Clipping

Full 3D frustum clipping via Sutherland-Hodgman against all 6 planes. Proper homogeneous clipping in 4D space with attribute interpolation.

04

Culling

Configurable back-face culling with support for CCW and CW winding orders. Front, back, or no culling modes.

05

Rasterization

Sub-pixel precision with pixel centers at x+0.5, y+0.5. Perspective-correct attribute interpolation via barycentric coordinates.

06

Fragment Processing

Z-buffer depth testing, alpha blending, and per-pixel color output to a software framebuffer.

Additional Features

Edge Equation Rasterizer

Efficient half-space testing — the default rasterization path.

Scanline Rasterizer

Traditional scanline-based triangle rasterization.

Hierarchical Rasterizer

Tile-based approach for improved cache coherence.

Uniform System

Pass custom parameters to vertex shaders at runtime.

Hierarchical Transforms

Parent-child scene graph with dirty-flag caching.

Camera System

Perspective and orthographic projections with look-at support.

Technology

C++SDL2Software Rendering