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

2

u/deftware Oct 19 '26

Nice! How fast is the actual rendering part, before sending the frame to OpenGL to be put onscreen?

2

u/Batteryofenergy1 Oct 19 '26

It really depends on the geometry. More triangles, slower frames. Frame time is 0.01s on my CPU and the average fps is 70-140

1

u/deftware Oct 20 '26

Well done. Are you doing any kind of spatial partitioning, sorting, visibility determination, occlusion culling, etc?

1

u/Batteryofenergy1 Oct 21 '26

I use a BVH Tree for rendering and collision testing. All static geometry and objects are in the same tree. The tree is traversed and culled using frustrum culling. Then i process the culled amount into a generic RenderSurface struct. After transforming each triangle into screen space, i occlusion cull the screen space bounding box against the previous frame's depth buffer, this causes some pop in. After that i sort the polygons front to back using min screen space depth, this causes the nearest polygons to be rendered first and the polygons in the back can skip expensive shading.

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.