I'm implementing a software renderer with this rasterization method, however, I was wondering if there is a possibility to improve it, or if there exists an alternative technique that is much faster. I'm specifically interested in rendering small triangles, like the ones from this 100k poly dragon:


As you can see, the method I'm using is not perfect either, as it leaves small gaps from time to time (at least I think that's what's happening).

I don't mind using assembly optimizations. Pseudocode or actual code (C/C++ or similar) is appreciated.

  • \$\begingroup\$ you should try to find out what happens in the gaps \$\endgroup\$ – Maik Semder Nov 23 '12 at 8:48
  • \$\begingroup\$ I think the answer to your question is, yes, it can be improved upon. Your question is a bit too broad. There isn't a correct answer. You're basically saying: "This is how I'm currently doing things, are there any other ways of doing it?" Yes, lots of ways. But your question isn't a good fit for this site. Try a more discussion oriented site, like gamedev.net or reddit.com/r/gamedev \$\endgroup\$ – MichaelHouse Nov 26 '12 at 3:01

Rasterizing triangles in software is commonly done using either Bresenham's algorithm or using a differential digital analyzer (DDA) with fixed point math to interpolate the values. Bresenham uses a lot of branching, so is probably less efficient than a fixed-point DDA on modern CPUs.

The tutorial you have linked uses an odd mix of C++ classes, floating point math, and a per-pixel function call to set the colors. You can do a lot better than that example by just writing less inefficient code! Both Bresenham and DDA will get you more numerical stability than mixing floats and ints haphazardly as in the linked tutorial (a probable cause of the gaps you see).

| improve this answer | |
  • \$\begingroup\$ Thanks, I implemented a floating point DDA that works very good. \$\endgroup\$ – toby Nov 28 '12 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.