CS184 Section 2
Lighting and Transformations
Brandon Wang
February 5, 2013
Material adapted from James O'Brien, Fu-Chung Huang, Ravi Ramamoorthi, and Carlo Sequin.
Brandon Wang
February 5, 2013
Material adapted from James O'Brien, Fu-Chung Huang, Ravi Ramamoorthi, and Carlo Sequin.
How we determine the color of what we see
i.e. Given our representations of geometry and lights, what color is at a specific pixel?
Does not depend on direction of light, or direction to viewer!
Ambient Term
Diffuse Term
Specular Term
In AS1, you will be programming the Phong Illumination Model!
example_01.cpp
Download it from the class website.
void myDisplay() {
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Start drawing
circle(viewport.w / 2.0 , viewport.h / 2.0 , min(viewport.w, viewport.h) / 3.0);
glFlush();
glutSwapBuffers();
}
void circle(float centerX, float centerY, float radius) {
glBegin(GL_POINTS);
int i,j; // Pixel indices
for (i=0;i<viewport.w;i++) {
for (j=0;j<viewport.h;j++) {
// Location of the center of pixel relative to center of sphere
float x = (i+0.5-centerX);
float y = (j+0.5-centerY);
float dist = sqrt(sqr(x) + sqr(y));
if (dist<=radius) {
// This is the front-facing Z coordinate
float z = sqrt(radius*radius-dist*dist);
setPixel(i,j, 1.0, 0.0, 0.0);
// This is amusing, but it assumes negative color values are treated reasonably.
// setPixel(i,j, x/radius, y/radius, z/radius );
}
}
}
glEnd();
}
void setPixel(int x, int y, GLfloat r, GLfloat g, GLfloat b) {
glColor3f(r, g, b);
glVertex2f(x + 0.5, y + 0.5); // The 0.5 is to target pixel
// centers
// Note: Need to check for gap
// bug on inst machines.
}
We've drawn a circle, but we want you treat it as a sphere.
"Lifting" the points onto a sphere.
Generating a normal.
Argument parsing.
Other slides and worksheet.
Matrix Stacks