r/GraphicsProgramming • • Sep 07 '25

CPU Software Rasterization Experiment in C++

Inspired by Tsoding's post about Software Rasterization on the CPU, I gave it a try in C++. Here are the results. The experiment includes depth testing, back-face culling, blending, MSAA, trilinear filtering, gamma correction and per-pixel lighting.

I am impressed that a CPU can draw 3206 triangles at 1280x720 with 4x MSAA at ~20FPS. I wouldn't try to build a game with this renderer, but it was a fun experiment.

216 Upvotes

26 comments sorted by

View all comments

Show parent comments

2

u/fgennari Sep 07 '25

It sounds like you need a depth prepass. Or you can sort triangles from front to back and use the depth buffer. I haven't actually written a software rasterizer, but it seems like the same tricks would apply to reducing overdraw.

3

u/-Memnarch- Sep 08 '25

Yup, they do. In my softwarerenderer I have implemented a hierachical Z-Buffer. It has a low resolution version to allow for early Z rejection when large polygons are used. That way, a wall will occlude anything behind it and it can skip over it fairly quickly without invoking pixelshaders