Software 3D rasterizer based on the course 3D Programming from Scratch taught by Pikuma (Gustavo Pezzi).
The rasterizer features:
- SDL2 based renderer
- Complete graphics pipeline transformation
- Perspective-correct texture interpolation
- Top-left and DDA rasterization algorithms
.obj
+.png
loading for scene population- Visual debugging tools through ImGui
- Cross-platform compilation support, including WASM
All assets are provided by Pikuma as part of the coursework. JetBrains Mono is made available free of charge by JetBrains.
rasterizer/
├── assets/ # Provided assets
├── src/ # Source code
├── wasm/ # WASM specific files
├── external/ # Included external libraries
├── external/ # Included external libraries
└── README.md # Project README
A CMake + Ninja setup is assumed. Both SDL2 and GLM are required to be available as CMake packages. On Windows you can use MSYS2, on MacOS Homebrew and on Linux the package manager of choice (eg: apt for Ubuntu).
The following commands were tested using Clang, though all compilers with good C++23 coverage (eg: GCC) should work.
cmake -DCMAKE_BUILD_TYPE={Debug|Release} -DCMAKE_MAKE_PROGRAM=Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -G Ninja -S . -B ./cmake-build-{debug|release}
cmake --build cmake-build-{debug|release} --target rasterizer -j 14
./bin/rasterizer-{debug|release}
Emscripten is used to build the WebAssembly (WASM) target. SDL2
is provided as a built-in port. Copying GLM into <emcc-folder>/system/include
is recommended as it simplifies the
build step. Otherwise, it can be added to the /external
folder and manually reference it.
Can be built using MSYS2's Emscripten package.
em++ src/main.cpp -std=c++23 -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' -s USE_WEBGL2=1 -s FULL_ES2=1 -I./external/imgui $(find ./external/imgui -name "*.cpp") -O2 -DNDEBUG -fexceptions -s EXPORTED_RUNTIME_METHODS="['FS']" -s ALLOW_MEMORY_GROWTH=1 -s ENVIRONMENT=web -DRESOLUTION_SCALE=1 -o ./bin/rasterizer-wasm.html --preload-file ./assets --shell-file ./wasm/index.html
If GLM was not included as part of Emscripten's system libraries, it can be manually copied into ./external/glm
and
included by adding -I./externa/glm
to the build command.
cd bin
python3 -m http.server 8000
Afterwards, navigate to http://localhost:8000/rasterizer-wasm.html
with the browser of choice.
Key(s) | Action |
---|---|
W / A / S / D |
Move frustum eye around |
↑ / ↓ / ← / → |
Rotate frustum forward direction |
C |
Toggle backface culling |
X / Z |
DDA / Top-Left rasterization |
Esc |
Close app (WASM simply stops updating) |
- C++:
>= C++23
- CMake:
>= 3.28
- SDL:
>= 2.30.9
- GLM:
>= 1.0.1
- ImGui:
>= v1.91.8
(Bundled)
- Implement a floating-point rasterization algorithm