r/GraphicsProgramming • • Oct 18 '26

Progress on Software Rendered game in C

This is some progress of a free game i have been working. This is fully software rendered on the CPU and OpenGL is only used to render the image. I use multiple threads to render the game at full 1080p. Using SIMD instructions helps a lot to get a decent frame rate. But i am still kinda dissapointed by the performance, i think Michael Abrash's binning technique would improve it, but right now, it is decent. I am getting around 70-140 frames with I5-12400.

502 Upvotes

34 comments sorted by

View all comments

Show parent comment

1

u/deftware Oct 21 '26

Nice. Are you using a z-max (or z-min, or both!) miptree for quickly comparing bounding boxes against the depth buffer? I did see a fun article about single-pass miptree building, where you're basically iterating over all LOD levels of the miptree simultaneously, by walking the image's pixels once and figuring what they contribute to each miplevel's pixels. So at LOD1 each pixel is contributing 25%, at LOD2 it's contributing 1/16th, etc... The trick to avoid precision issues was to sum everything up first, and then divide by number of contributors at the end. Granted, building a miptree is most expensive for the first few levels, and then the rest of the levels are really cheap, but it was a fun idea that I once used when building a high-precision scalar field codec, where it had to be fast. The trade-off is a bit of extra memory being used. :P

Cheers! :]

2

u/Batteryofenergy1 Oct 22 '26

I tried the mip map method before, but i had problems with presicion. I just use the full resolution depth buffer to test against. I first check the edge points of the bbox first, if any of them return true, i can early out. Otherwise i check the entire bbox pixel by pixel.

1

u/deftware Oct 22 '26

check the edge points of the bbox first

Nice. It sounds like the most expensive part then is when a bbox doesn't early-out and you're checking it against all of the pixels. The larger the bbox the more depth pixels it checks against. At that point I would suggest taking another look at getting min/max miptree building cooking, you could build both of them simultaneously - walk the depth buffer once to build both.

I forgot to show this to you https://hacksoflife.blogspot.com/2016/05/simultaneous-mipmap-level-generation.html

Once you have your min depth miptree then each bbox is just a check against one mip pixel.

Anyway, just my two cents. Have you done any profiling yet to see where the slowest parts of your renderer are?

2

u/Batteryofenergy1 Oct 23 '26

I am actually planning to implement some basic precomputed visibility volumes to reduce the surface count i have to cull. I am looking at some methods that are used in Source2 https://developer.valvesoftware.com/wiki/Source_2_Docs/Level_Design/Visibility and Unreal engine https://dev.epicgames.com/documentation/unreal-engine/precomputed-visibility-volumes-in-unreal-engine. Even from thief https://nothings.org/gamedev/thief_rendering.html .

Not slowest, but pixel filling functions take most time(functions that actually output to the pixel buffer). Drawing the static geometry, takes the most time especially since i use Lightmaps.