...the long road to rasterization

Published October 14, 2008
Advertisement
I've finally found time to implement the first few steps of rasterization.

The first thing I implemented was a triangle fill function. I pretty much just started with the "brute-force" approach, which was basically my own best guess at an implementation. I basically started by sorting the points of the triangle by their Y screenspace coordinates. I divided my triangle in half (horizontally at the mid-point) so that I could scan convert each half separately. I won't go into the details of the algorithm (you can find many articles on basic triangle filling online) but essetially, i'd iterate through each scanline of the triangle half and fill in pixels within the bounds of the triangle edges. On my very first try, triangles were generally looking right, except that on occasion, the triangles would warp out of shape. I realized that my inverse slope calculations were off because I was using floating point coordinates instead of converting to discreet integer values beforehand.

Things were looking quite great at this point, but there seemed to be some noticeable overdraw in some places. After reading up on a few rasterization articles online, I discovered that I wasn't properly using a "Fill convention". For those who don't know, its just a standard way of filling pixels such that adjacent primitives will not overlap or leave a gap between each other. The used whats known as a "top-left" fill convention. This basically means that all pixels that intersect the top-left edges of the primitive will be filled, but pixels intersecting other edges will not be.

The next big thing to add is some depth testing.

Here are some progress pics:



Previous Entry .. clipping!!!
Next Entry depth testing woes
0 likes 5 comments

Comments

Aardvajk
Awesome. I tried to write a software renderer many years ago, and rasterizing triangles is the point I gave up. I guess this is the point that all the work you've done recently starts really coming together.
October 15, 2008 12:28 AM
HopeDagger
Excellent to hear that you're still tinkering away at this project. What's the next step after depth testing? Some gouraud shading? Textures?
October 15, 2008 11:29 AM
benryves
Good to see further progress on this project! [smile]
October 15, 2008 01:42 PM
Clapfoot
I feel like i've almost reached that point when "things start falling together", but not quite yet. The next real step is getting a solid per-pixel (perspective correct) interpolator function in place, then things will really start to fly.

After depth testing, i'll probably want to start adding additional per-vertex information like normals, colour, and texture coordinates. From there, adding diffuse lighting or basic texture mapping shouldn't be too far.

Thanks for all the great encouragement!
October 15, 2008 06:31 PM
ApochPiQ
Very cool... what kind of performance are you getting right now?
October 17, 2008 12:47 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement