Week 4 Day 1 - Barycentric Coordinates + Writing a Z-Buffer

Channel:
Subscribers:
2,640
Published on ● Video Link: https://www.youtube.com/watch?v=LreaB5gsR-Y



Duration: 1:00:10
65 views
1


Today I continue implementing some rendering code in the terminal. Last time we stopped by marking the area inside of a triangle, today we colored it using Barycentric coordinates to interpolate between the colors of the three vertices.


We then set up two triangles and had one draw over another. This is how simple 3D rendering used to go. It's called the Painter's Algorithm, and basically you'd have to manually draw things back to front. This doesn't work well when they overlap in complex ways, as sometimes you need both to render at the same time for it to work, but it saves on memory.


Nowadays memory is cheap, so we use z-buffering. A z-buffer holds how far away each pixel on the screen is from the camera. It's just a 2D vector of doubles. Whenever we go to write a pixel on the screen, we check to see if the pixel we're going to write is closer than what is in the z-buffer right now (I initialize it with the maximum finite double value). If the new pixel is closer, then we output it to the screen and record the new z-value in the buffer. Otherwise, we leave it alone and don't output anything.







Tags:
is50b
barycentric coordinates
z-buffering
c++