Lighting Phong's Lighting Model normals

Slides:



Advertisements
Similar presentations
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
Advertisements

2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
CSPC 352: Computer Graphics
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
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.
CS 4731: Computer Graphics Lecture 16: Illumination Models Part 2 Emmanuel Agu.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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);
Now Playing: Multiply Jamie Lidell from Multiply Released June 13, 2005.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
Illumination and Shading
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 6: Shading Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
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.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Computer Graphics I, Fall 2010 Shading in OpenGL.
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
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.
08 |Lighting and Shading Eriq Muhammad Adams J |
Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
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.
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.
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[] =
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
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 and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
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.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
Illumination and Shading
@ 2017 by Jim X. Chen George Mason University
School of Computer Science
Shading in OpenGL Ed Angel
Lighting and Shading Lab 8:.
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
Lighting and Shading Lab 8:.
ייצוג בעולם 3D ייצוג מצולעים (פוליגונים) צלע קודקוד צלעe0 : {v1,v2}
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Lighting Calculations
Presentation transcript:

Lighting Phong's Lighting Model normals OpenGL Light and Material Properties glLightModelfv glMaterialfv glColorMaterial Direction/Position local/infinite viewpoint attenuation spotlights

Phong's Lighting Model Ambient light - even light all around. Direction of light and viewer don't matter. Diffuse - fine scale graininess of surface. Direction of light source matters, direction of viewer doesn't matter. Specular - shininess of surface. Direction of light source and viewer both matter.

Run sphereInBox1.cpp Observe box and ball materials and lighting. Look at code later.

Normals To get proper reflection, we need to know "surface direction".

angle of incidence and angle of reflection

sphereInBox1.cpp notice no ambient, has diffuse and specular

SphereInBox1.cpp normals Experiment: Change the value of ONE_BY_ROOT_THREE to see the effect. Try 0, 1.

Phong's Lighting Model Light reflected off of object O due to nature of light and nature of the surface

Ambient Ambient light - from light scattered all around. Direction of light and viewer don't matter.

Diffuse Diffuse - fine scale graininess of surface. Direction of light source matters, direction of viewer doesn't matter.

Specular Specular - shininess of surface. Direction of light source and viewer both matter.

For Phong Model Each light source has ambient, diffuse, and specular components for each color. There is global ambient light, with components for each color. Each point on the surface of an object has ambient, diffuse, and specular componets for each color. Specular material also has a shininess factor Some items have "inner glow" - emissive component.

Light Source Matrix Liamb,R Liamb,G Liamb,B Lidif,R Lidif,G Lidif,B For each light source i, 0<=i<N, there is a matrix Liamb,R Liamb,G Liamb,B Lidif,R Lidif,G Lidif,B Lispec,R Lispec,G Lispec,B

Material Matrix Vamb,R Vamb,G Vamb,B Vdif,R Vdif,G Vdif,B Vspec,R For each vertex of an object, there is a material matrix Vamb,R Vamb,G Vamb,B Vdif,R Vdif,G Vdif,B Vspec,R Vspec,G Vspec,B

Global Ambient Light Vector For the global ambient light there is a vector globAmbR globAmbG globAmbB

For each vertex there is an Emissive Light Vector For each vertex there is an emissive light vector Vemit,R Vemit,G Vemit,B

Total ambient light of color X at a vertex V (X=R, G, or B) Sum, for all Light sources i, ∑ (Liamb,X * Vamb,X) for all Light sources i + globAmbX*Vamb,X

Total diffuse light of color X at a vertex V (X=R, G, or B) Sum, for all Light sources i, ∑ (cos(ϴi)*Lidif,X * Vdif,X) for all Light sources i ϴi is the angle between the light and the normal to the surface. If cos(ϴi)<0, then use 0 instead.

Total specular light of color X at a vertex V (X=R, G, or B) Sum, for all Light sources i, ∑ (cos(ϴi)f * Lispec,X * Vspec,X) for all Light sources i ϴi is the angle between the light and the normal to the surface. f is the shininess factor of the material.

Shininess factor f cos(ϴ)f

Total lighting at vertex, color X Vemit,X + globAmbX*Vamb,X + ∑ (Liamb,X * Vamb,X + for all Light sources i max{ cos(ϴi), 0}*Lidif,X * Vdif,X + max{cos(ϴi)f,0} * Lispec,X * Vspec,X )

For more details of the math, see the book, section 11.2

Lots of things to specify for each light and material of objects Ambient R, G, B Diffuse R, G, B Specular R, G, B For material, also emissive - looks like light coming from object. Material also has a shininess component. Got to here class 12

Light in OpenGL setting light properties glLightfv(light, parameter, value) light: GL_LIGHT0, GL_LIGHT1, ... parameter: GL_AMBIENT,GL_DIFFUSE, GL_SPECULAR, GL_POSITION,... value: an array of values, eg, rgba factors for GL_AMBIENT, position (homogeneous) for GL_POSITION

Example from sphereInBox1.cpp float lightAmb[] = { 0.0, 0.0, 0.0, 1.0 }; float lightDifAndSpec[] = { 1.0, 1.0, 1.0, 1.0 }; float lightPos[] = { 0.0, 1.5, 3.0, 1.0 }; glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDifAndSpec); glLightfv(GL_LIGHT0, GL_SPECULAR, lightDifAndSpec); glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

global ambient light float globAmb[] = { 0.2, 0.2, 0.2, 1.0 }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globAmb); //global ambient light.

enabling lighting // Turn on OpenGL lighting. glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // Enable particular light source.

Material Properties glMaterial*(face, parameter, value) face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK

Material Properties glMaterial*(face, parameter, value) parameter: GL_AMBIENT, GL_DIFFUSE, ... GL_AMBIENT_AND_DIFFUSE,... GL_SHININESS for full list see: http://www.opengl.org/sdk/docs/man/xhtml/glMaterial.xml

Material Properties glMaterial*(face, parameter, value) value: array with values for that parameter for that face.

lightAndMaterial1.cpp Can change material properties. Discuss all interactions. Quadratic Attenuation. Technique: Disable light to draw text or "colored"objects. Visible lights are fake! got to here

lightAndMaterial2.cpp (with my modifications) Can change light properties. Try all interactions. Infinite vs local viewpoint. Positional vs directional light. Smooth vs Flat shade model.

infinite vs local viewpoint glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, localViewer); 0 infinite 1 at eye

Review Idea of Lighting ? ? ? ? ?

Which normals to use? shpereInBox2.cpp

How to light pixels, flat or smooth?

How many triangles are there? myLitRedSquares.cpp

spotlight.cpp (modified) check out code, user interaction. Placement of light subject to transformations. Uses color for material.

Watch some shorts Luxo Jr.

From Vertices to Faces Think light and color (and more)

Triangle with a red, blue, and green corner.

Squares with red, green, blue, and yellow corners

Understanding the problem and how to get what we want.

Compute the indicated point (7,16) ( ? , ? ) 1/2 (1,4)

Weighted average 1/2 * (1,4) + 1/2* (7,16) = ( .5 , 2 ) + ( 3.5 , 8 ) = ( 4 , 10 ) NOT taking the difference... This doesn't generalize.

Compute the indicated point (7,16) ( ? , ? ) ( 4 , 10 ) 3/4 (1,4)

Compute the indicated point (7,16) (7, 16) is pulling harder than (1,4) ( ? , ? ) ( 4 , 10 ) 3/4 3/4 * ( 7 , 16 ) + 1/4 * ( 1 , 4 ) =( 21/4 , 12 ) + (1/4 ,1) = ( 22/4 , 13 ) = ( 5.5 , 13) (1,4)

Compute the indicated point (7,16) c2 c1 + c2 =1 ( 5.5 , 13 ) ( 4 , 10 ) c1 c1* ( 7 , 16 ) + c2* ( 1 , 4 ) (1,4)

Compute (INTERPOLATE) the indicated color (1,4) (7,16) 1/2 ( 4 , 10 ) Blue: ( 0 , 0 , 1 ) Red: ( 1 , 0 , 0 )

Compute the indicated color (7,16) Blue: ( 0 , 0 , 1 ) 1/2*(1,0,0) + 1/2*(0,0,1)= (0.5 , 0, 0) + (0 , 0, 0.5)= (0.5, 0, 0.5) ( 4 , 10 ) 1/2 (1,4) Red: ( 1 , 0 , 0 )

V is a convex combination of P and Q If P and Q are two points in 3-space, then the segment from P to Q is the set of points of the form V = c1 P + c2 Q where 0≤c1≤1, 0≤c2≤1 and c1 + c2 = 1 V is a convex combination of P and Q

Convex Combinations of three points c1+c2+c3=1 ci≥0, i=1,2,3 P3 P2

Convex Combinations of three points Find c1,c2,c3 ci≥0, i=1,2,3 that give us P1 P2 P3 W P1 W P3 P2

Use Convex Combinations to compute (interpolate) colors in a triangle

P1 is 1. (0,0,1)+0. (0,1,0) +0. (1,0,0) P2 is 0. (0,0,1)+1. (0,1,0) +0 P1 is 1*(0,0,1)+0*(0,1,0) +0*(1,0,0) P2 is 0*(0,0,1)+1*(0,1,0) +0*(1,0,0) P3 is 0*(0,0,1)+0*(0,1,0) +1*(1,0,0) W is .5*(0,0,1) +0*(0,1,0)+.5*(1,0,0) V is .1*(0,0,1) + .3*(0,1,0)+.6*(1,0,0) W V V

Uniqueness For line segments, c1 and c2 are unique. For triangles, c1, c2, and c3 are unique. For other shapes, they are NOT unique.

Interpolation in a quad is not well defined!

How does OpenGL color quads and polygons? It breaks them into triangles, then colors the triangles.

myLitRedSquares more triangles, better lighting.