1
Pradeep Sen
Class 3 – January 24, 2007
ECE 595 / CS 491 / CS 591
Real-Time Rendering &
Graphics Hardware
Pradeep Sen
Advanced Graphics Lab
Class 3
January 24, 2007
Pradeep Sen
Class 3 – January 24, 2007
Pop Quiz!
±
Write the orthographic projection matrix that
projects the volume defined by the
r
,
l
,
t
,
b
,
n
,
f
planes to the unit cube (0, 1)
±
n
,
f
are defined positive and make sure the
resulting projection puts view direction at +z.
n
f
t
b
l
r
+x
+y
-z
+x
+y
+z
0
1
1
1
1
Pradeep Sen
Class 3 – January 24, 2007
Last time
±
Projection transformations
±
Clipping
Pradeep Sen
Class 3 – January 24, 2007
Today
±
Finish the rendering pipeline
– Rasterization
– Texturing
– Framebuffer operations
±
Discuss the project
Pradeep Sen
Class 3 – January 24, 2007
Rasterization
±
There are two problems the rasterizer must
solve:
– Determine which pixels are “touched” by the
triangle
– Determine the value of interpolants at each of
these vertices
Pradeep Sen
Class 3 – January 24, 2007
Rasterization
±
Conversion from floating point screen space
coordinates into integer pixel coordinates on
the screen
Pradeep Sen
Class 3 – January 24, 2007
Bounding box algorithm
void rasterizeTriangle(void) {
for (y = y_min; y < y_max; y++) {
for (x = x_min; x < x_max; x++) {
if insideTriangle(x,y) {
generateFragment(x,y);
}
}
}
}
box
y_min
y_max
x_min
x_max
Pradeep Sen
Class 3 – January 24, 2007
Inside tests
v0
v1
v2
Pradeep Sen
Class 3 – January 24, 2007
Inside tests
void lineEquation(float *v0, float *v1, float *f){
crossProduct(v1, v0, f);
}
bool insideTriangle(int x,y) {
lineEquation(v0, v1, &f0);
lineEquation(v1, v2, &f1);
lineEquation(v2, v0, &f2);
Pt p(x,y,1);
if ((dotProduct(p, f0) > 0) &&
(dotProduct(p, f2) > 0) {
// inside the triangle
return true;
}
return false;
}