A toy software rasterizer


Teapots with different shading and textured triangles


At some point in the past, when I was ill and stuck at home for an extended
period of time, I wrote a small software rasterizer as a sort of teaching
tool.

The source code can be found here: Github page

The rasterizer is intended to be clearly readable and not optimized for speed.
It is devided into a set of pipeline stages:

  1. An input assembler decodes vertices from a vertex buffer/index
    buffer combination and assembles triangles that it passes on first to
    the T&L, then to the rasterizer stage.
  2. Per vertex shading stage runs a confiugrable function on each
    vertex to apply model-view and projection transformation and optional
    lighting calculations. The function can produce values that are
    interpolated accross the triangle during rasterization.
  3. The rasterizer stage performs perspective divide, culls back facing
    triangles, generates pixels and interpolates vertex attributes (depth and
    texture coordinates) in a perspective correct manner.
  4. Per pixel shading stage runs a configurable function on each
    generated pixel to determine final color from interpolated value.
    Texturing and optional extra lighting calculations can be done here.
  5. The pixel processing stage performs depth test, texture lookup and
    blends the pixels that pass the depth test onto a frame buffer.



As can be seen in the screenshot, simple texturing has been implemented, as
well as different lighting/shading functions (per primitive, per vertex
and per pixel lighting).