# Scanline filling of polygons that share edges and vertices

In the image below (a perspective projection of an icosahedron), the scanline (red) intersects that vertex at the top. In an icosahedron each edge belongs to two triangles. From edge a, only one triangle is visible, the other one is in the back. Same for edge d. Also, in order to determine what color the current pixel should be, each polygon has a flag which can either be 'in' or 'out', depending upon where on the scanline we currently are. Flags are flipped according to the intersection of the scanline with the edges.

Now, as we go from a to d (because all edges are intersected with the scanline at that vertex), this happens: the triangle behind triangle 1 and triangle 1 itself are set 'in', then 2 is set in and 1 is 'out', then 3 is set 'in', 2 is 'out' and finally 3 is 'out' and the one behind it is set 'in', which is not the desired behavior because we only need the triangles which are facing us to be set 'in', the rest should be 'out'.

How do process the edges in the Active Edge List (a list of edges that are currently intersected by the scanline) so the right polys are set 'in'?

Also, I should mention that the edges are unique, which means there exists an array of edges in the data structure of the icosahedron which are pointed to by edge pointers in each of the triangles.

Once you've produced a z-buffer using linear interpolation, you will no longer be operating on the full edge list of your underlying projected geometry, but rather a reduced subset due to occlusion.

This subset is produced as follows:

You will produce the z-buffer itself which stores only depth; and in order to to maintain only unoccluded vertices you will at the same time build a separate, matching structure (same resolution) which contains no information except for (at the pertinent "pixel" locations) IDs of each projected vertex that was unoccluded after your z-buffer was built (that is, those that are actually visible in your z-buffer). It is this second buffer that you will now use to do in-out checks for scanline rasterisation.

HTH.

• Thanks, that is exactly what I did, except instead of scanlining the whole screen at once, i scanline each individual polygon.
– toby
Commented Nov 28, 2012 at 13:19