1 / 59

Lighting

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.

vstephens
Download Presentation

Lighting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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.

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

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

  5. angle of incidence and angle of reflection r

  6. sphereInBox1.cpp

  7. SphereInBox1.cppnormals • Experiment: Change the value of ONE_BY_ROOT_THREE to see the effect. Try 0, 1.

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

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

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

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

  12. 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.

  13. Light Source Matrix For each light source i, 0<=i<N, there is a matrix

  14. Material Matrix For each vertex of an object, there is a material matrix

  15. Global Ambient Light Vector For the global ambient light there is a vector

  16. Emissive Light Vector For each vertex there is an emissive light vector

  17. 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

  18. 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.

  19. 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.

  20. Shininess factor f cos(ϴ)f

  21. 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 )

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

  23. 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.

  24. Light in OpenGLsetting 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

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

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

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

  28. Material PropertiesglMaterial*(face, parameter, value) face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK

  29. Material PropertiesglMaterial*(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

  30. Material PropertiesglMaterial*(face, parameter, value) value: array with values for that parameter for that face.

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

  32. 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.

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

  34. Review Idea of Lighting ? ? ? ? ?

  35. Which normals to use?sphereInBox2.cpp

  36. How to light pixels, flat or smooth?

  37. How many triangles are there? myLitRedSquares.cpp

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

  39. Watch some shorts • Luxo Jr.

  40. From Vertices to Faces • Think light and color (and more)

  41. Triangle with a red, blue, and green corner.

  42. Squares with red, green, blue, and yellow corners

  43. Understanding the problem and how to get what we want.

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

  45. 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.

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

  47. 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)

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

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

  50. 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 )

More Related