Computer Graphics (Fall 2006)To DoMethodology for LectureImportance of LightingOutlineBrief primer on ColorShading ModelsDemo and Color PlatesLightingTypes of Light SourcesMaterial PropertiesSpecifying NormalsSlide 13LightMaterial DemoEmissive TermAmbient TermSlide 17Diffuse TermSlide 19Specular TermSlide 21DemoSlide 23Source Code (in display)Source Code (contd)Slide 26Moving a Light SourceLightposition demoComputer Graphics (Fall 2006)Computer Graphics (Fall 2006)COMS 4160, Lecture 12: OpenGL 3http://www.cs.columbia.edu/~cs4160To DoTo DoHW 3 Milestones due on Thu If stuck, please get help from me or TAsImportant you feel confident you can finish HW 3Programs in class, red book probably most helpMethodology for LectureMethodology for LectureLecture deals with lighting (teapot shaded as in HW1)Some Nate Robbins tutor demos in lectureBriefly explain OpenGL color, lighting, shadingDemo 4160-opengl\opengl3\opengl3-orig.exeLecture corresponds chapter 5 (and some of 4)But of course, better off doing rather than readingImportance of LightingImportance of LightingImportant to bring out 3D appearance (compare teapot now to in previous demo)Important for correct shading under lightsThe way shading is done also importantglShadeModel(GL_FLAT) glShadeModel(GL_SMOOTH)OutlineOutlineBasic ideas and preliminariesTypes of materials and shading Ambient, Diffuse, Emissive, SpecularSource codeMoving light sourcesBrief primer on ColorBrief primer on ColorRed, Green, Blue primary colorsCan be thought of as vertices of a color cubeR+G = Yellow, B+G = Cyan, B+R = Magenta, R+G+B = WhiteEach color channel (R,G,B) treated separatelyRGBA 32 bit mode (8 bits per channel) often usedA is for alpha for transparency if you need itColors normalized to 0 to 1 range in OpenGLOften represented as 0 to 255 in terms of pixel intensitiesAlso, color index mode (not so important)Shading ModelsShading ModelsSo far, lighting disabled: color explicit at each vertexThis lecture, enable lightingCalculate color at each vertex (based on shading model, lights and material properties of objects)Rasterize and interpolate vertex colors at pixelsFlat shading: single color per polygon (one vertex)Smooth shading: interpolate colors at verticesWireframe: glPolygonMode (GL_FRONT, GL_LINE)Also, polygon offsets to superimpose wireframeHidden line elimination? (polygons in black…)Demo and Color PlatesDemo and Color PlatesSee OpenGL color plates 1-8Demo: 4160-opengl\opengl3\opengl3-orig.exeQuestion: Why is blue highlight jerky even with smooth shading, while red highlight is smooth?LightingLightingRest of this lecture considers lighting on verticesIn real world, complex lighting, materials interactWe study this more formally in next unitOpenGL is a hack that efficiently captures some qualitative lighting effects. But not physicalModern programmable shaders allow arbitrary lighting and shading models (not covered in class)Types of Light SourcesTypes of Light SourcesPointPosition, Color [separate diffuse/specular]Attenuation (quadratic model)Directional (w=0, infinitely far away, no attenuation)SpotlightsSpot exponentSpot cutoffAll parameters: page 195 (should have already read HW1)21c l qattenk k d k d=+ +Material PropertiesMaterial PropertiesNeed normals (to calculate how much diffuse, specular, find reflected direction and so on)Four terms: Ambient, Diffuse, Specular, EmissiveSpecifying NormalsSpecifying NormalsNormals are specified through glNormalNormals are associated with verticesSpecifying a normal sets the current normalRemains unchanged until user alters itUsual sequence: glNormal, glVertex, glNormal, glVertex, glNormal, glVertex…Usually, we want unit normals for shadingglEnable( GL_NORMALIZE )This is slow – either normalize them yourself or don’t use glScaleEvaluators will generate normals for curved surfacesSuch as splines. GLUT does it automatically for teapot, cylinder,…OutlineOutlineBasic ideas and preliminariesTypes of materials and shading Ambient, Diffuse, Emissive, SpecularSource codeMoving light sourcesLightMaterial LightMaterial DemoDemoEmissive TermEmissive TermmaterialI Emission=Only relevant for light sources when looking directly at them• Gotcha: must create geometry to actually see light• Emission does not in itself affect other lighting calculationsAmbient TermAmbient TermHack to simulate multiple bounces, scattering of lightAssume light equally from all directionsAmbient TermAmbient TermAssociated with each light and overall lightE.g. skylight, with light from everywhere0* * *nglobal material light i material iiI ambient ambient ambient ambient atten== +�Most effects per light involve linearly combining effects of light sourcesDiffuse TermDiffuse TermRough matte (technically Lambertian) surfacesLight reflects equally in all directionsI N L�:N-LDiffuse TermDiffuse TermRough matte (technically Lambertian) surfacesLight reflects equally in all directionsWhy is diffuse of light diff from ambient, specular?I N L�:N-L0* * *[max ( ,0)]nlight i material iiI diffuse diffuse atten L N==�gSpecular TermSpecular TermGlossy objects, specular reflectionsLight reflects close to mirror directionSpecular TermSpecular TermGlossy objects, specular reflectionsLight reflects close to mirror directionConsider half-angle between light and viewersN0* * *[max ( ,0)]nshininesslight i material iiI specular specular atten N s== ��DemoDemoWhat happens when we make surface less shiny?What happens to jerkiness of highlights?OutlineOutlineBasic ideas and preliminariesTypes of materials and shading Ambient, Diffuse, Emissive, SpecularSource codeMoving light sourcesSource Code (in display)Source Code (in display) /* New for Demo 3; add lighting effects */ /* See hw1 and the red book (chapter 5) for details */ { GLfloat one[] = {1, 1, 1, 1}; // GLfloat small[] = {0.2, 0.2, 0.2, 1}; GLfloat medium[] = {0.5, 0.5, 0.5, 1}; GLfloat small[] = {0.2, 0.2, 0.2, 1}; GLfloat high[] = {100}; GLfloat light_specular[] = {1, 0.5, 0, 1}; GLfloat light_specular1[] = {0, 0.5, 1, 1}; GLfloat light_position[] = {0.5, 0, 0, 1}; GLfloat light_position1[] = {0, -0.5, 0, 1}; /* Set Material properties for the teapot */
View Full Document