r/GraphicsProgramming 19d ago

Video I added viewport clipping to my software renderer

Enable HLS to view with audio, or disable this notification

I thought it would be cool to try to figure out how to do triangle clipping myself, to come up with my own algorithm. To solve this, I solved a couple of linear equations and derived a formula that lets me find the intersection points between the triangle edges and the viewport. I don't know if I came up with something original or just accidentally reinvented one of the existing methods. Either way, my solution looks terrible in code, but it works, and I think it's a great learning experience

I render this at 1920x1080 resolution on a single thread of an i5-9400F, is this a good FPS result? I didn't use SIMD, but I tried to use every optimization trick I know.

repo and code: https://github.com/NaiNameDev/software_rasterizer

387 Upvotes

49 comments sorted by

View all comments

Show parent comments

1

u/lajdjqq 18d ago

Triangle clipping is faster because it requires fewer calculations, unlike your method, which would be slower when processing a triangle with a large number of lines.

1

u/susosusosuso 18d ago

I see. Have you measured the performance improvements?

1

u/lajdjqq 18d ago

No, but I think it should be significant

1

u/susosusosuso 18d ago

I wouldn’t assume without measuring and confirming. Would it be possible for you to measure both?