Week 2 Day 4 - Rasterization
Last time we talked about Raytracing, so we talked a bit more about it, and then contrasted it with the more common way of rendering a scene - rasterization. Triangle rasterization is when you take a triangle and fill all the pixels inside of it with the right color. (This could be a flat color, or you could do texturing, lighting, and all the other super cool PBR materials stuff.)
The simplest way of rasterizing a triangle is to start with its AABB (Axis Aligned Bounding Box) and go through every pixel to see if it is inside the triangle. You can do this with three cross products, or you can do it with the line intersection test - you draw a line from infinitely far away (which is outside the triangle) and if it crosses a boundary then its inside, and if it crosses another boundary it is outside.
If you have a lot of overdraw (multiple triangles rasterizing to the same place on the screen) the frame buffer might get overwritten over and over again, so you might run up against the fill rate limit of your video card (the fill rate is how many pixels per second it can write to the frame buffer), so engines will do a lot of tricks to figure out when a triangle is fully occluded and to not rasterize it at all. If they do render to the same spot, then a "Z-Buffer" is used which holds how away each pixel in the buffer is. If two are drawn to the same spot, the nearer one is drawn and the other is discarded. If they're the same distance, you'll get a Z-buffer conflict and you'll see flashing as one of them will randomly appear over the other on each pixel.
Your homework assignment will be to just do line rasterization, AKA wireframe mode. You can do this by taking your earlier Voroni code and only drawing a color on an edge. You can detect an edge by simply seeing where there is a change between the current pixel and a neighboring pixel. If all the neighbors (in the four cardinal directions) are the same color - draw black. Otherwise draw an edge.