1 Lecture 10 Lighting in OpenGL. 2 Sources of light GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 1.0}; GLLightfv(GL_LIGHT0, GL_POSITION, myLightPosition);

Slides:



Advertisements
Similar presentations
OpenGL Course Notes Chapter 5: Lighting Jim Mims, Spring 2009.
Advertisements

GR2 Advanced Computer Graphics AGR
SI23 Introduction to Computer Graphics
5.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 5 A Simple Reflection Model.
CS 480/680 Computer Graphics Shading 2 Dr. Frederick C Harris, Jr.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of New Mexico
Computer Graphics - Class 10
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading III Week.
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Shading II CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3
3/23/2005 © Dr. Zachary Wartell 1 Illumination Models and Surface- Rendering Methods.
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion.
UniS CS297 Graphics with Java and OpenGL Colour and Lighting.
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2006 Shading II Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red.
Illumination and Shading
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
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.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
SET09115 Intro Graphics Programming
CS 445 / 645: Introductory Computer Graphics
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Shading in OpenGL.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
CSC418 Computer Graphics n Illumination n Lights n Lightinging models.
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.
Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
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);
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
11/04/04© University of Wisconsin, CS559 Fall 2004 Last Time Visibility –Z-Buffer and transparency –A-buffer –Area subdivision –BSP Trees –Exact Cell-Portal.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Specular Reflection Lecture 27 Mon, Nov 10, 2003.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
1 Dr. Scott Schaefer Lighting. 2/49 Lighting/Illumination Color is a function of how light reflects from surfaces to the eye Global illumination accounts.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 55 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 55 Computer Graphics Three-Dimensional Graphics V.
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
Shading in OpenGL Ed Angel
Lighting Phong's Lighting Model normals
CSE 470 Introduction to Computer Graphics Arizona State University
Illumination and Shading
Lighting and Materials
Lighting – Light Sources
CS5500 Computer Graphics April 10, 2006.
Lighting – Material Properties
Computer Graphics 4Practical Lesson
ייצוג בעולם 3D ייצוג מצולעים (פוליגונים) צלע קודקוד צלעe0 : {v1,v2}
Presentation transcript:

1 Lecture 10 Lighting in OpenGL

2 Sources of light GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 1.0}; GLLightfv(GL_LIGHT0, GL_POSITION, myLightPosition); glEnable(GL_LIGHTING); //enable lighting glEnable(GL_LIGHT0); //enable this particular source Infinitely remote source (directional light): GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 0.0}

3 RGB Values for Lights and Materials For light the numbers correspond to a percentage of full intensity for each color:  If the R, G, and B values for light’s color are all 1.0, the light is the brightest possible white.  If the values are 0.5, the color is still white, but only half intensity, so it appears gray.  If R=G=1 and B=0, light appears yellow.

4 RGB Values for Lights and Materials For materials, the number corresponds to reflected proportion of those colors. So, if R=1, G=0.5, and B=0 for a material, that material reflects all the incoming green, and none of the incoming red light, half the incoming green, and none of the incoming blue light.

5 RGB Values for Lights and Materials  Hence, OpenGL light has components (LR, LG, LB), and material has corresponding components (MR, MG, MB), then ignoring all other reflective effects, the light arrives at the eye is given by ( LR*MR, LG*MG, LB*MB).  Similarly, if we have two light source that sends (R1, G1, B1) and (R2, G2, B2) to the eye, OpenGL adds the components (R1+R2, G1+G2, B1+B2).  If a color intensity is bigger than 1, OpenGL makes it 1.

6 Lighting Terms Ambient Light  is the light that has a source, but is evenly spread around the room. Objects that have ambient light are evenly lit and always visible.  Light is evenly distributed that there is no way to tell its source. For example, due to reflection of light from walls.

7 Lighting Terms Diffuse Light  is a light that comes from a particular direction and reflects evenly off the surface. Points where the light is directly normal (perpendicular) from the light source to the surface appear brighter.

8 Lighting Terms Specular Light  is similar to the Diffuse light where the light comes from a particular direction, but the reflection is much more dynamic. This effect can usually cause a shine or a glare.

9 Lighting Terms in OpenGL GLfloat amb0[] = {0.2, 0.4, 0.6, 1.0}; GLfloat diff0[] = {0.8, 0.9, 0.5, 1.0}; GLfloat spec0[] = {1.0, 0.8, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, amb0); //attach them to LIGHT0 glLightfv(GL_LIGHT0, GL_DIFFUSE, diff0); glLightfv(GL_LIGHT0, GL_SPECULAR, spec0);

10 Normals  As far as the API is concerned, a square, or any object, is just a collection of points to form an object.  Even with simple objects, OpenGL knows nothing of the properties of that object.  In order to give more information to OpenGL about an object and light, a normal should be defined.

11 Normals A normal vector is a line perpendicular to a plane in three-dimensional space. OpenGL uses normalized normals: a normal vector of length 1, to calculate how light may reflect off an object.

12 Normals Imagine any triangle ABC on the xy-plane (z values = 0). The coordinates starting from top left and going counter-clock-wise are as follows: ABC = { { 0, 1, 0 }, { -1, -1, 0 }, { 1, -1, 0 } } Normal vectors are only calculated at vertices, and the normals for the triangle are: Normals ABC = { { 0, 0, 1 } }

13 Normals  Triangle ABC is co-planar (actually, any three points that form a triangle define a plane), so the normal to be calculated is the same anywhere on the triangle. At any angle of light, this vertex reflects the light symmetrically through the normal vector. This is how light is able to reflect off an object.  This example was easy because the triangle lies completely on the xy-plane, but what about other triangles that lie anywhere in space?

14 Calculating Normals Objects may have analytic surfaces and non-analytic surfaces I. Calculating normals for analytic surfaces:  Analytic surfaces are surfaces that are non-coplanar, such as spheres.  Because calculating normals are only done at vertices, it becomes incredibly complicated to determine where the vertices are for an object such as a sphere.  If the object being drawn is a predefined GLU shape, then using the gluQuadricNormals() function, will generate the normals for you  GLUT predefined shapes automatically calculate normals).

15 Calculating Normals II. To find a normal of a surface that is non-analytic  Means that the surface lies on the same plane, or is co-planar.  This means that the normal vector on this surface is the same on all vertices.  We have to get two vectors v1, v2 that are non- collinear and share a tail.  The result of the cross product of the two vectors is a vector normal to the surface.

16 Materials OpengGL lighting model makes the approximation that a material’s color depends on the percentage of the incoming red, green, and blue light it reflects. For example, a perfectly red ball reflects all the incoming red light and absorbs all the green and blue light that strikes it. When such a ball is viewed in a white light (composed of equal amounts of red, green and blue light), all the red is reflected and you see a red ball. If the ball is viewed in a pure green light, it appears black (all the green is absorbed and there is no incoming red, so no light is reflected).

17 Materials Like lights, materials have different ambient, diffuse and specular colors, which determine the ambient, diffuse, and specular reflectance’s. A material’s -ambient reflectance is combined with the ambient component of each incoming light source, -the diffuse reflectance with the light’s diffuse component -specular reflectance with the light’s specular component.

18 Materials In addition to ambient, diffuse, and specular colors, materials have an emissive color, which simulates light originating from an object. In OpenGL, the emissive color of a surface adds intensity to the object, but is unaffected by any light source. Materials are what we use to give an object a certain type of reflective (or non-reflective) quality.

19 Materials Example: glEnable( GL_COLOR_MATERIAL ); float red[] = { 0.94, 0.2, 0.15, 1.0 }; glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red ); // draw some objects glDisable( GL_COLOR_MATERIAL );

20 Materials  Enabling the material properties with a call to glEnable allow the materials to be manipulated.  Next, it is needed to set which side the material colors it to be used for.  The only three possible choices are GL_FRONT, GL_BACK, or GL_GL_FRONT_AND_BACK.

21 Materials The next parameter allows you to set the types of light to set (GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, or GL_AMBIENT_AND_DIFFUSE).  One thing to note is that in most cases the ambient and diffuse materials are set to the same values, and this is why OpenGL has an option for combining the two in one line.  The last parameter is an array (vector) of the intensities of the Red, Green, Blue and Alpha values that define the (in our case) ambience and diffuse properties (the second parameter).

22 Materials  Another thing to note is our first time use of the alpha color. If you recall from color section, it was said that the alpha value is used for special effects. For use with lighting, we always set the alpha value to 1.0.  Finally a call to glDisable() may speed up graphic intensive operations if the machine doesn’t have to check for material colors anymore.