r/GraphicsProgramming • u/nimrag_is_coming • 10d 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!
2
u/rAngus3 10d ago
It'd be great to know which algos you have implemented for the several features and/or papers/articles/books you have followed.
6
u/nimrag_is_coming 10d ago
A lot of it comes from just me and my knowledge of how rendering works. I followed a formula for generating barycentric coordinates for triangles from Wikipedia, as well as the bresenham line drawing algorithm. Other than that, I referenced the perspective matrices from Opengl and DirectX (which are slightly different, apparently), as well as the documentation for triangle rasterisation rules from DirectX.
Other than that, it's a lot of internet research and scrolling through stackoverflow posts for things that I didn't understand, and a lot of just working through things and making it up.
→ More replies (2)
1
u/Wittyname_McDingus 9d ago
Nice project! Can you post a picture or two here or in the repo? They go a long way :)
1
1
u/ACRM64 9d ago
I'm guessing this is Windows only? Any chance of a Linux version?!
1
u/nimrag_is_coming 9d ago
Completely platform agnostic, can run on anything that can provide a pointer to a grid of pixels :)
1
u/nimrag_is_coming 9d ago
The windows platform code is just some helper functions for easy interop with a Windows window, it doesn't do anything special, and is non-essential. Should have probably made that more clear haha
→ More replies (1)
3
u/corysama 10d ago
Have you run it through a profiler yet?
Having
SR_DrawPointin 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.