To better understand the nitty gritty details of the Graphics Pipeline I decided to build my own software renderer/rasterizer as a hobby project.
Rasterization is simply a rendering method used to map an image described in vector graphics to a raster image. A rasterizer is then a program that takes, as an input, an image described as triangle vertices and converts them into the corresponding pixels that the triangle would cover on a computer display. Rasterization is one of the main stages of the Graphics Pipeine.
The application is written in C++ and apart from maybe window management with SDL2 runs entirely on the CPU. The application can load vertex arrays described as .obj files, parse them and rasterize them to an output surface. It has many standard rendering features such as backfacing and view-frustum culling/clipping and there is also a hierarchical Z-buffer to ensure drawing triangles in the correct order.
The renderer additionally supports some nice to have features such as arbitrary per vertex attributes and interpolation, user programmable vertex & fragment shaders as well as camera controls.
While developing I used 3 main resources: Trenki's excellent blog post on Developing a Software Renderer, JavidX9's Youtube series Code-It-Yourself! 3D Graphics Engine, and many chapters of the online book Scratchapixel. When writing the code, I tried to closely follow the concepts of the graphics pipeline so that the application would behave in a similar manner to a GPU accelerated Graphics API.
To see how it can be used, have a look in the Main.cpp file! The entrypoint for rasterization is in Rasterizer::drawTriangles
found here
Run Rasterizer.exe in the samples/
folder
Or build it locally
- Download the Simple DirectMedia Layer SDK
- Open Cmake in the root directory
- Configure and point it to SDL lib and include folder
- Copy SDL2.dll to where you will build the binaries, e.g
SoftwareRasterizer/build
- Additionally place your .obj file inside the same build folder
- Correct the file path in
Rasterizer::loadModelIntoVertexArray()
- Compile and run!
WASD
as well as RF
translates the camera. Additionally by holding down the right mouse button you can orient yourself in the scene