rasterizer

C++ software renderer

Clone

Loading...

Screenshots

Screenshots from the rasterizer

Overview

Interactive software rasterizer written in C++, just to grok some GPU pipeline rendering, associated graphics APIs and math. Attempts to do things more classically in the GPU way. Like a depth buffer instead of sorting, Pineda-style edge triangle rasterization, homogeneous clipping, and floating-point math instead of ints.

  • The rasterizer outputs to a color buffer that's blitted to the screen by SDL_UpdateTexture().

  • Primitive assembly -> backface culling -> early near plane rejection -> frustum culling.

  • Clipping -> NDC and perspective -> depth test -> rasterize -> color buffer.

  • The math and the pipeline is handled internally. SDL handles window creation, input events and window surface updates.

  • Some clarity on conventions, this uses a right-handed Z-up coordinate system. So X+ is forward, Y- is right and Z+ is up. The math is all in row-major matrices and row vectors. So v' = v \* m.

  • Currently the scene is hardcoded, just some .obj files that are parsed and loaded at runtime. No textures as of right now.

  • There is some initial perspective correct interpolation. I've only validated it with debug textures/patterns seems to check out though.

  • Contains a free cam and mouselook, typical [W][A][S][D] and [Q][E] for +Z, -Z respectively.

Local setup

Build script for each platform, acquiring SDL is skipped. -r for the release build.

Windows

.\build_win32.bat

Linux

./build_linux.sh

MacOS

./build_macos.sh

/assets holds the meshes. Scene composition is handled manually in initialize_scene().

To-do

  • Texture sampling
  • Transparency and alpha blending
  • Shading
  • SIMD/Autovec

Resources