Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lighting and Shading Lab 8:.

Similar presentations


Presentation on theme: "Lighting and Shading Lab 8:."— Presentation transcript:

1 Lighting and Shading Lab 8:

2 Shading models Shading refers to how the lighting equations are applied to a rasterized poly. OpenGL supports two shading models: GL_ SMOOTH. GL_FLAT.

3 Polygon shading GL_SMOOTH: Lighting is evaluated at each vertex, and pixel coolers are linearly interpolated across polys. This is more expensive, but it looks much better. glShadeModel(GL_SMOOTH);

4 Smooth Model glBegin(GL_TRIANGLES); glEnd(); void display (void) {
glShadoModel(GL_SMOOTH); glColor3f(1,0,0); glVertex2f(5,5); glColor3f(0,1,0); glVertex2f(25,5); glColor3f(0,0,1); glVertex2f(5,25); glEnd(); }

5 Gouraud shading GL_FLAT: Lighting is evaluated once per poly, and the resulting colour value is used for the whole thing. glShadeModel(GL_FLAT);

6 Flat Model glBegin(GL_TRIANGLES); glEnd(); void display (void) {
glShadoModel(GL_FLAT); glColor3f(1,0,0); glVertex2f(5,5); glColor3f(0,1,0); glVertex2f(25,5); glColor3f(0,0,1); glVertex2f(5,25); glEnd(); }

7 Smooth Model & Flat Model

8 Types of lighting implemented
1) Ambient: No source point; affects all polys independent of position, orientation and viewing angle; used as a ‘fudge’ to approximate 2nd order and higher reflections. GLfloat ambient0[] = {1, 0, 0, 1}; 2) Diffuse: Light scattered in all directions after it hits a poly; dependant upon incident angle. GLfloat diffuse0[] = {1, 0, 0, 1}; 3) Specular: ‘Shininess’ ; dependant upon incident and viewing angles. GLfloat spedular0[] = {1, 1, 1, 1}; 4) Emissive: Makes a poly appear as though it is glowing; does not actually give off light. GLfloat light0_pos[] = {1.0, 2.0, 3.0, 1.0};

9 Types of lighting implemented

10 Types of lighting implemented

11 Different types of light

12 Enable & Disable opengl has two important functions called glEnable(GL_LIGHTING) and glDisable(GL_LIGHTING). while these functions don't enable or disable anything in particular, they are reliant on the parameter passed to them. so in other words, you will be using these functions a lot when programming in opengl to turn a particular feature on or off.

13 Exercise void init(){ glClearColor(1.0, 1.0, 1.0, 0.0); //glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void display(){ // Create light components GLfloat ambientLight[] = { 1.0f, 0.0f, 0.0f, 1.0f }; GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f }; GLfloat specularLight[] = { 0.9f, 0.9f, 0.9f, 1.0f }; GLfloat position[] = { -8.5f, 5.0f, -10.0f, 1.0f }; // Assign created components to GL_LIGHT0 glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight); glLightfv(GL_LIGHT0, GL_POSITION, position); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glLoadIdentity(); gluLookAt(0, 0, 5, 0, 0.0, 0.0, 0.0, 1.0, 0.0); glutSolidSphere(1.5,30,10); //glutSolidTeapot(1.5); glFlush();

14 Exercise void main(int argc, char** argv){ glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(800, 500); glutInitWindowPosition(100, 100); glutCreateWindow(""); init(); glutDisplayFunc(display); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1, 1, -1, 1, 1.5, 20); glMatrixMode(GL_MODELVIEW); glutMainLoop(); }


Download ppt "Lighting and Shading Lab 8:."

Similar presentations


Ads by Google