i total k s i ambient i i i 1 7 8 lighting in opengl
play

I total = k s I ambient + I i ( i = 1 7 8 Lighting in OpenGL - PDF document

University of British Columbia News: Homework CPSC 314 Computer Graphics homework correction: questions 13-16 should Jan-Apr 2005 use: Tamara Munzner unit square has points A=(0,0,0,1), B=(0,1,0,1), C=(0,1,1,1), D=(0,0,1,1) in world


  1. University of British Columbia News: Homework CPSC 314 Computer Graphics � homework correction: questions 13-16 should Jan-Apr 2005 use: Tamara Munzner � unit square has points A=(0,0,0,1), B=(0,1,0,1), C=(0,1,1,1), D=(0,0,1,1) in world coordinates Lighting and Shading � homework clarification: question 1 � C_i is down one-half unit and sideways one Week 5, Wed Feb 2 unit. http://www.ugrad.cs.ubc.ca/~cs314/Vjan2005 2 News: Project Handin Review: Reflectance � when handing after the deadline, handin has this � specular : perfect mirror with no scattering unfriendly warning message � gloss : mixed, partial specularity � Checking that handin was successful ... /cs/csbox/user FAILED to find user a1b2. Your files � diffuse : all directions with equal energy DO NOT appear to be handed in successfully � Do you want to cancel? + + = � don’t panic � go ahead and complete the handin, do not cancel! specular + glossy + diffuse = � your submission will be put in the LATE directory reflectance distribution 3 4 Review: Reflection Equations Clarification: Calculating The R Vector N l n P � P = N cos � = projection of L onto N I diffuse = k d I light (n • l) L R � why is P = N cos � , not L cos � ? � � � N and R and L are unit length � difference between I specular = k s I light ( v • r ) n shiny � length of projection of u onto v u � scalar: |u| cos � � � in this case length of u is 1 v � cos � u cos scalar length! � � projection of u onto v � vector in direction of v, with scale factor � scale depends on angle between u and v, length of u 2 ( N ( N · L )) – L = R � v |u| cos � � in this case length of u is 1 � v cos � 5 6

  2. Review: Reflection Equations 2 Review: Lighting � lighting models n n h h � Blinn improvement v v � ambient I specular = k s I light ( h • n ) n shiny l l � normals don’t matter � Lambert/diffuse h = ( l + v )/2 � angle between surface normal and light � full Phong lighting model � Phong/specular � combine ambient, diffuse, specular components � surface normal, light, and viewpoint # lights k d ( n • l i ) + k s ( v • r i ) n shiny ) � I total = k s I ambient + I i ( i = 1 7 8 Lighting in OpenGL Lighting in OpenGL !"#$!%&'()*#+#,*-./01*#+234,56.01789+"$!%&+:!971;< � light source: amount of RGB light emitted !"#$!%&'()*#+#,*-./01*#+=,>>?@501A$'+"$!%&+:!971;< � value represents percentage of full intensity !"#$!%&'()*#+#,*-./01*#+@B5C?#2D01EFGH+"$!%&+:!971;< e.g., (1.0,0.5,0.5) !"#$!%&'()*#+#,*-./01*#+BI@,.,I601FJE$&$JK;< !"5K79"G)*#+#,*-./;< � every light source emits ambient, diffuse, and specular light !"37&G:$7"'()1*#+>DI6.01*#+234,56.01789$GK&+:!971;< !"37&G:$7"'()1*#+>DI6.01*#+=,>>?@501A$''LEG+:!971;< � materials: amount of RGB light reflected !"37&G:$7"'()1*#+>DI6.01*#+@B5C?#2D01EFGHL"7:+:!971;< � value represents percentage reflected !"37&G:$7"'()1*#+>DI6.01*#+@-,6,65@@01K1;< e.g., (0.0,1.0,0.5) � warning: glMaterial is expensive and tricky � interaction: multiply components � use cheap and simple glColor when possible � red light (1,0,0) x green surface (0,1,0) = black (0,0,0) � see OpenGL Pitfall #14 from Kilgard’s list http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/ 9 10 Lighting vs. Shading Applying Illumination � lighting � we now have an illumination model for a point � process of computing the luminous intensity on a surface (i.e., outgoing light) at a particular 3-D point, � if surface defined as mesh of polygonal facets, usually on a surface which points should we use? � shading � fairly expensive calculation � the process of assigning colors to pixels � several possible answers, each with different implications for visual quality of result � (why the distinction?) 11 12

  3. Applying Illumination Flat Shading � polygonal/triangular models � simplest approach calculates illumination at a single point for each polygon � each facet has a constant surface normal � if light is directional, diffuse reflectance is constant across the facet. � why? � obviously inaccurate for smooth surfaces 13 14 Flat Shading Approximations Improving Flat Shading � if an object really is faceted, � what if evaluate Phong lighting model at each pixel of the polygon? is this accurate? � better, but result still clearly faceted � no! � for point sources, the � for smoother-looking surfaces direction to light varies we introduce vertex normals at each across the facet vertex � usually different from facet normal � for specular reflectance, � used only for shading direction to eye varies � think of as a better approximation of the real surface across the facet that the polygons approximate 15 16 Vertex Normals Gouraud Shading � vertex normals may be � most common approach, and what OpenGL does � provided with the model � perform Phong lighting at the vertices � computed from first principles � linearly interpolate the resulting colors over faces � along edges � approximated by � along scanlines edge: mix of c 1 , c 2 C 1 averaging the normals of the facets that does this eliminate the facets? share the vertex C 3 C 2 interior: mix of c1, c2, c3 edge: mix of c1, c3 17 18

  4. Gouraud Shading Artifacts Gouraud Shading Artifacts � Mach bands � often appears dull, chalky � eye enhances discontinuity in first derivative � lacks accurate specular component � very disturbing, especially for highlights � if included, will be averaged over entire polygon C 1 C 1 C 3 C 3 C 2 this vertex shading spread C 2 this interior shading missed! over too much area 19 20 Gouraud Shading Artifacts Gouraud Shading Artifacts � Mach bands � perspective transformations � affine combinations only invariant under affine, C 1 not under perspective transformations � thus, perspective projection alters the linear C 4 interpolation! C 3 Image plane C 2 Discontinuity in rate of color change occurs here Z – into the scene 21 22 Gouraud Shading Artifacts Phong Shading � perspective transformation problem � linearly interpolating surface normal across the � colors slightly “swim” on the surface as objects facet, applying Phong lighting model at every move relative to the camera pixel � usually ignored since often only small difference � same input as Gouraud shading � usually smaller than changes from lighting � pro: much smoother results variations � con: considerably more expensive � to do it right � not the same as Phong lighting � either shading in object space � common confusion � or correction for perspective foreshortening � Phong lighting: empirical model to calculate illumination at a point on a surface � expensive – thus hardly ever done for colors 23 24

  5. Phong Shading Phong Shading Difficulties � linearly interpolate the vertex normals � computationally expensive � compute lighting equations at each pixel � per-pixel vector normalization and lighting computation! � can use specular component � floating point operations required # lights ( n shiny ) � ( ) + k s v � r i ( ) � lighting after perspective projection I total = k a I ambient + I i k d n � l i N 1 i = 1 � messes up the angles between vectors remember: normals used in diffuse and specular terms � have to keep eye-space vectors around N 4 � no direct support in hardware N 3 discontinuity in normal’s rate of � but can be simulated with texture mapping change harder to detect N 2 25 26 Shading Artifacts: Silhouettes Shading Artifacts: Orientation � interpolation dependent on polygon orientation � polygonal silhouettes remain view dependence! � A Rotate -90 o B and color same point C B A D � D Gouraud Phong C Interpolate between Interpolate between CD and AD AB and AD 27 28 Shading Artifacts: Shared Vertices Shading Models Summary � flat shading � compute Phong lighting once for entire vertex B shared by two rectangles on the right, but not by the one on polygon C H the left D � Gouraud shading � compute Phong lighting at the vertices and first portion of the scanline interpolate lighting values across polygon B G is interpolated between DE and AC � Phong shading � compute averaged vertex normals second portion of the scanline is interpolated between BC and GH � interpolate normals across polygon and F E A perform Phong lighting across polygon a large discontinuity could arise 29 30

  6. Shutterbug: Flat Shading Shutterbug: Gouraud Shading 31 32 Shutterbug: Phong Shading Non-Photorealistic Shading � draw silhouettes: if , e =edge-eye vector ( e � n 0 )(e � n 1 ) � 0 k w = 1 + n � l � cool-to-warm shading: , c = k w c w + (1 � k w ) c c 2 http://www.cs.utah.edu/~gooch/SIG98/paper/drawing.html 33 34

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend