logoalt Hacker News

Software rendering in 500 lines of bare C++

202 pointsby mpweihertoday at 2:17 PM34 commentsview on HN

Comments

articulatepangtoday at 3:05 PM

I went through this a few months ago in Rust. I wrote all the code by hand, no LLMs. Then I went ahead and added a small "game" on top, plus some special effects like pixelization shaders and chromatic aberration at the edge of a flashlight.

https://github.com/kshitijl/tinyrenderer-rs

if anyone is interested! The repo has lots and lots of in-progress screenshots so you can see the renderer come to life, plus all the hilarious visual bugs along the way.

I learned a lot! My biggest lesson, other than the specifics of how rendering works, was that modern CPUs are really fast: a single-threaded CPU renderer can definitely run an interactive 3D game with some fancy special effects.

show 1 reply
nkanaevtoday at 3:42 PM

This resource, along with Mathematics for Computer Graphics by John Vince [1], was truly indispensable when I wrote my own software renderer [2]. This was long before LLMs, so the whole process took me at least a couple months - most of it trying to wrap my head around math behind computer graphics and tracking down C segmentation faults. Fun times.

[1]: https://www.amazon.co.uk/Mathematics-Computer-Graphics-John-...

[2]: https://github.com/nkanaev/tipsy

bob1029today at 3:00 PM

I wish we could have just one of these tutorials properly cover the concern of triangle clipping. This is the part that I struggle with the most in a software renderer. If you are going to be building a practical one, this is something you will eventually have to deal with, even for super basic scenes. Any time geometry intersects the view frustum you need to clip those triangles.

show 4 replies
espetrotoday at 3:53 PM

Finally an engineering feat that's not built in Rust

0x1ceb00datoday at 6:50 PM

Ok I'm following along but how do I view the tga files that this program produces? Windows can't open them.

show 1 reply
t1234stoday at 2:46 PM

I jumped when the first image loaded on the page.. didn't expect that.

show 3 replies
anthktoday at 4:23 PM

There was a software rendered game in vein of Tomb Raider 1 graphics for both DOS and Unix, but I can't remember its name. It was an exploration game, modern, a bit cyberpunkish, in 3D.

brcmthrowawaytoday at 5:34 PM

How does this differ from POVRay?

show 1 reply
fithisuxtoday at 4:44 PM

This is a very good article.

uncivilizedtoday at 4:11 PM

I thought this would be something new but it’s just ssloy’s tinyrenderer. Article should have a date since it’s old as dirt

show 1 reply
chrisjjtoday at 3:15 PM

"Comments

An error occurred: API rate limit already exceeded "

Sharlintoday at 4:55 PM

I've been wanting to write a series of articles exactly like this for a long time. Good that someone else has done it now =D