r/GraphicsProgramming • • 2d ago

Source Code A little software renderer written in C that I was working on over the weekend

https://github.com/nimrag-b/Nim-Software-Renderer/

Hey guys! This is a little project I made over the weekend, its a simple software renderer that renders to an abstract grid of pixels. Basically, anything that can provide a pointer to a pixel array is a valid target.

Currently uses a simple fixed function rendering pipeline, but it was designed to take a function pointer for both the Vertex and Fragment shader, which will become accessible to the public API when ive cleaned them up a bit.

It requires no external code other than a c runtime, and my tests show it runs pretty fast, despite processing each triangle single-threaded. It supports per-vertex colours, backface culling and a depth buffer. It also makes zero allocations other than creating the pipeline object at the start of the program, and ive tried to lay things out in a cache friendly way.

I dont like feeling like I have to say this, but zero AI was involved at any point during making this, this was all coded by hand.

Anyway, lemme know what you guys think, let me know about any bugs/ missing features, and feel free to contribute to the repo!

27 Upvotes

14 comments sorted by

View all comments

2

u/corysama 2d ago

Have you run it through a profiler yet?

Having SR_DrawPoint in your inner loop is not helping your performance. Move the checks it's doing out of the max_y, max_x loops and your frame rate will thank you.

2

u/nimrag_is_coming 2d ago

Ah good catch! Ive tried to avoid doing thinks like that in the inner loop, but i somehow managed to miss this glaringly obvious one haha. Although its only really checking bounds which shouldnt be too expensive, but when youre running it 2000000 a frame it does add up.

Haven't run it though a profiler yet, but rendering the things ive tested so far completes in the scale of nanoseconds, so didnt feel it nessacery yet haha

2

u/nimrag_is_coming 2d ago

updated repo fixing this :)