I'm working on a software rasterizer just for grins and I'm to the point where I want to implement smoothing between different colors at vertices across a polygon.
From what I've read, it consists of calculating a scan line, calculating the colors at the ends of the scan line, and then linearly interpolating across that scan line to get the color at a single point.
My question is how to calculate the color at the end of the scan line for polygons with 4+ points. 3 points is pretty straight forward (though I haven't actually done the calculations yet), but 4 is a bit harder to wrap my head around.
Anyone have any good resources (or code) to get me started?
Okay, so I'm doing some clipping to cut down on the surface area that I'm actually drawing. Right now thats being done before I'm rasterizing the polygon which is resulting in non-triangle polygons when I get to rasterization. So how should I go about avoiding those 4+ vertice polygons?
if you want smooth interpolation, you can calculate per pixel that you set, the distances to the 4 vertices and divide by the sum of those 4 distances, that way you'll get weights to blend the 4 vertex colors, just using the edge color between two vertices or splitting quads in two triangles, won't make it look smooth.
keep in mind, that you also need to interpolate perspective correctly, if you rasterize 3d triangles.