Lighting and Shading Lab 8:.

Slides:



Advertisements
Similar presentations
CSPC 352: Computer Graphics
Advertisements

Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
Computer Graphics - Class 10
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Hidden Surfaces and Shading CS BSP Tree T1T1 T2T2 E if (f 1 (E) < 0) then draw T 1 draw T 2 else draw T 2 draw T 1 f 1 (p) = 0 is the.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
OpenGL Tutorial Jason Lawrence COS426 Precept Notes 2/16/04.
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Shading in OpenGL.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Computer Graphics I, Fall 2010 Shading in OpenGL.
Lecture 9: Lighting and Shading 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
1 Chapter 6 Blending, Antialiasing, Fog, and Polygon Offset Guihua Yang Jan 14, 2004.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
Computer Graphics I, Fall 2010 Programming with OpenGL Part 3: Three Dimensions.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
实验 2 设计一个真实感图形显示系统. 选题  60 分:有灯光、材质、纹理 (p203,p206) 的场景  80 分:+交互控制场景( figure11.1.c )  100 分:+读入多边形物体+ Bezier 曲面.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] =
In the name of God Computer Graphics. Where We Stand So far we know how to: –Transform between spaces –Draw polygons Next –Deciding a pixel’s intensity.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL & OpenSceneGraph Graphics Programming Katia Oleinik:
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
CSC Graphic Programming Lecture 2 OpenGL Lightning.
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
CSC Graphics Programming
Shading To determine the correct shades of color on the surface of graphical objects.
Jason Lawrence COS426 Precept Notes 2/16/04
Advanced Graphics Algorithms Ying Zhu Georgia State University
Illumination and Shading
Programming with OpenGL Part 2: Complete Programs
School of Computer Science
Programming with OpenGL Part 3: Three Dimensions
Programming with OpenGL Part 2: Complete Programs
Lecture 10, 11, and 12 Lighting & Shading
גרפיקה ממוחשבת: מבוא ל-OpenGL
Shading in OpenGL Ed Angel
CSC461: Lecture 24 Lighting and Shading in OpenGL
Lighting Phong's Lighting Model normals
Programming with OpenGL Part 3: Three Dimensions
o عَلَّمَهُ الْبَيَانَ
Illumination and Shading
Lighting – Light Sources
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Lighting and Shading Lab 8:.
Programming with OpenGL Part 3: Three Dimensions
ייצוג בעולם 3D ייצוג מצולעים (פוליגונים) צלע קודקוד צלעe0 : {v1,v2}
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Programming with OpenGL Part 2: Complete Programs
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Presentation transcript:

Lighting and Shading Lab 8:

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

Smooth Model & Flat Model

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);

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

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

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}; //red,green,blue,alpha 2) Diffuse: Light scattered in all directions after it hits a poly; dependant upon incident angle. (GL_DIFFUSE is (1.0, 1.0, 1.0, 1.0) for GL_LIGHT0, ) The default value for any other light (GL_LIGHT1, ... , GL_LIGHT7) is (0.0, 0.0, 0.0, 0.0). GLfloat diffuse0[] = {1, 0, 0, 1}; 3) Specular: ‘Shininess’ ; dependant upon incident and viewing angles. GL_SPECULAR is (1.0, 1.0, 1.0, 1.0) for GL_LIGHT0 and (0.0, 0.0, 0.0, 0.0) for any other light. 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};

Different types of light

the alpha value can be safely ignored.

Types of lighting implemented

Types of lighting implemented

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.

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();

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(); glOrtho(-1, 1, -1, 1, 1.5, 20); glMatrixMode(GL_MODELVIEW); glutMainLoop(); }