COMPUTER GRAPHICS, SPRING 2013Notes from March 6 classGeneral introduction to rendering
Different approaches:
Painter's algorithm
Objects in front are painted later.
Problem 1: interpenetrating objects.
Problem 2: Objects that can't be ordered back-to-front.
Z-buffer
Used in just about all computer games, and most CGI films.
More on this in a bit!
Ray tracing
Some cool examples of rendering
Reflection and refraction
Radiosity
Soft shadows and reflections
Realism
Sub-surface scattering
Caustics
We will focus for the next few weeks on Z-bufferThis week: scan conversion
Next week: depth/shading/lighting
The rendering pipeline
Geometry Polygons
Polygons + motion Transformed polygons
Transformed polygons + depth Depth sorted polygons
Depth sorted polygons + lighting,materials Shaded Image
Scan-converting a sceneGoal: end up with an image of shaded pixels. Core data structure: the frame buffer
The idea comes from television
Each displayed "pixel" is actually three dots: R,G,B
In software, a frame buffer is a packed array:
int pix[] = new int[NROWS * NCOLS];
int getPixel(int col, int row) {
return pix[col + NCOLS * row];
}
void setPixel(int col, int row, int rgb) {
pix[col + NCOLS * row] = rgb;
}
// RED bits GREEN bits BLUE bits
// 23...........16 15...........8 7...........0
int getRed(int rgb) { return rgb >> 16 & 255; }
int getGrn(int rgb) { return rgb >> 8 & 255; }
int getBlu(int rgb) { return rgb & 255; }
int packRGB(int r, int g, int b) {
return 255 << 24 | r << 16 | g << 8 | b;
}
Fun with frame buffers
demo!!!!
Basic operation: scan converting polygonsThe slow way The fast way
Splitting your triangle into trapezoids:
(1) Sort vertices into A,B,C according to their top to bottom order.
(2) Compute D: same scan line as B, on opposite edge:
t = (yB - yA) / (yC - yA)
xD = xA + t * (xC - xA)
(3) Split triangle into two trapezoids - one of two cases: