Illumination and Shading

Slides:



Advertisements
Similar presentations
CSPC 352: Computer Graphics
Advertisements

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.
Illumination and Shading
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
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.
IMGD 1001: Illumination by Mark Claypool
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 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
1 CSC 830 Computer Graphics Lecture 5 Shading Course Note Credit: Some of slides are extracted from the course notes of prof. Mathieu Desburn (USC) and.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
Illumination and Shading
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
LIGHTING Part One - Theory based on Chapter 6. Lights in the real world Lights bounce off surfaces and reflect colors, scattering light in many directions.
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
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.
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 |
Taku KomuraComputer Graphics Local Illumination and Shading Computer Graphics – Lecture 10 Taku Komura Institute for Perception, Action.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
CSE 381 – Advanced Game Programming GLSL Lighting.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Illumination and Shading
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.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Local Illumination and Shading
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
In the name of God Computer Graphics. Where We Stand So far we know how to: –Transform between spaces –Draw polygons Next –Deciding a pixel’s intensity.
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
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
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.
CSC Graphics Programming
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
Unit-7 Lighting and Shading
Shading in OpenGL Ed Angel
Lighting Phong's Lighting Model normals
Illumination and Shading
Fundamentals of Computer Graphics Part 6 Shading
Lighting and Materials
Lighting – Light Sources
CS5500 Computer Graphics April 10, 2006.
Chapter IX Lighting.
ייצוג בעולם 3D ייצוג מצולעים (פוליגונים) צלע קודקוד צלעe0 : {v1,v2}
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Presentation transcript:

Illumination and Shading

Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL computes illumination at vertices illumination

Shading Apply the lighting model at a set of points across the entire surface Shading

Illumination Model The governing principles for computing the illumination A illumination model usually considers: Light attributes (light intensity, color, position, direction, shape) Object surface attributes (color, reflectivity, transparency, etc) Interaction among lights and objects (object orientation) Interaction between objects and eye (viewing dir.)

Illumination Calculation Local illumination: only consider the light, the observer position, and the object material properties Example: OpenGL q

Illumination Models Global illumination: take into account the interaction of light from all the surfaces in the scene Example: Ray Tracing (CIS681) object 1 object 2 object 3 object 4

Basic Light Types Directional Point Spot Directional light sun Directional So far away so that light rays are ║ Remember orthogonal projection? Point Light emanates equally in all directions Spot Point source limited to an angle Point light Spot light

Light Source Types from Akenine-Moller & Haines

Object Properties What happens when light hits an object? Properties of light reflection on an object’s surface Reflectance Models Ambient Diffuse Specular Absorption, Emission, Transparency/Translucency Irradiance: All light that arrives at a point on the surface Radiosity: Light leaving a surface in all directions

Object Properties Object Material Shiny (Metal), dull (Matte finish), mirror-like, glass, neon, etc.

Local vs. Global Illumination Illumination depends on local object & light sources only Illumination at a point can depend on any other point in the scene

Simple local illumination The model used by OpenGL – considers three types of light contribution to compute the final illumination of an object Ambient Diffuse Specular Final illumination of a point (vertex) = ambient + diffuse + specular

Ambient lighting example

Diffuse lighting example

Specular light example

Light Reflectance Components Take a point P on the object surface: p L L: Light Vector q q p R N L R: Reflection Vector Reflects about the Normal (N) to the surface q q p φ V R N L V: View Vector

Ambient Reflection Ambient = Ia * ka Background light scattered by the environment Light bounces off of many objects Simple Global Illumination Simple reflectance model Independent of … Light position Object orientation Viewer’s position ka: Ambient reflection coefficient Ambient light an object reflects 0 ≤ ka ≤ 1 Ambient = Ia * ka

Diffuse Reflection Lambert’s Law: Radiant energy D that a small surface patch receives from a light source: Id = light intensity,  = Angle between L and N Also called Lambertian or Matte surfaces D = Id * cos()

Lambert’s Law (1) How does D change if the light source moves? q p N L D = Id * cos() p L, N L No intensity Max intensity

Lambert’s Law (2) How does D change on an object’s surface? A sphere’s surface has all possible normal directions N

Diffuse Reflection Energy D is reflected equally in all directions on the surface Independent of … Viewer’s position kd: Diffuse reflection coefficient Diffuse light an object reflects 0 ≤ kd ≤ 1 Diffuse = Id * kd * cos() = Id * kd * (N  L) N and L must be normalized … WHY???

Specular Reflection (1) The reflection of the light source on the object Shiny/Glossy surfaces Not a perfect mirror Show up as Specular Highlights, i.e., bright spots

Specular Reflection (2) The object reflects maximum light intensity in the direction of the reflection vector Light intensity increases as V gets closer to R N L R V q q φ V  R = cos(φ) p

Specular Lobe (cos(φ))shine The reflection of the light source is maximum at the reflection direction Falls off quickly as the viewer moves away The size of the lobe determines the shininess of the object The shinier the object  the smaller the lobe (cos(φ))shine

Specular Reflection ks: Specular reflection coefficient Specular light an object reflects 0 ≤ ks ≤ 1 N : surface normal at P Is : light intensity φ : angle between V and R n : shininess factor Spec = Is * ks * cosn(φ) = Is * ks * (V  R)n q q p φ V R N L V and R must be unit vectors … WHY???

Ambient/Diffuse/Specular Just ambient light: Diffuse and change Ambient Left: Sphere with just diffuse reflection Right:Sphere with just specular reflection

Basic Reflectance Equation = Ia * ka + Id * kd * (N  L) + Is * ks * (R  V)n from Akenine-Moller & Haines Ambient Diffuse Specular Final

Put it all together Note that the K’s and the I’s are vectors (RGB). Illumination from a single light source: Illum = ambient + diffuse + specular = Ka x I + Kd x I x max(0,NL) + Ks x I x max(0,RV)n Note that the K’s and the I’s are vectors (RGB).

Put it all together If there are N lights Total illumination for a point P = S (Illum) Some more terms to be added (in OpenGL): Self emission Global ambient Light distance attenuation and spot light effect

Lighting in OpenGL Adopt Phong lighting model (specular) plus diffuse and ambient lights Lighting is computed at vertices Interpolate across surface (Gouraud/smooth shading) OR Use a constant illumination (get it from one of the vertices) Setting up OpenGL Lighting: Light Properties Enable/Disable lighting Surface material properties Provide correct surface normals Light model properties

Light Properties glLightfv(light, property, value) Properties: Colors / Position and type / attenuation glLightfv(light, property, value) 1 2 3 constant: specify which light you want to set the property example: GL_LIGHT0, GL_LIGHT1, GL_LIGHT2 … you can create multiple lights (OpenGL allows at least 8 lights) (2) constant: specify which light property you want to set the value example: GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION (check the red book for more) (3) The value you want to set to the property

Property Example Define colors and position a light colors Position GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0}; GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_position[] = {0.0, 0.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); colors Position What if I set the Position to (0,0,1,0)?

Types of lights OpenGL supports two types of lights Local light (point light) Infinite light (directional light) Determined by the light positions you provide w = 0: infinite light source (faster) w != 0: point light – position = (x/w, y/w, z/w) GLfloat light_position[] = {x,y,z,w}; glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Turning on the lights Turn on the power (for all the lights) glEnable(GL_LIGHTING); glDisable(GL_LIGHTING); Flip each light’s switch glEnable(GL_LIGHTn) (n = 0,1,2,…)

Controlling light position Modelview matrix affects a light’s position You can specify the position relative to: Eye space: the highlight remains in the same position relative to the eye call glLightfv() before gluLookAt() World space: a light’s position/direction appears fixed in the scene Call glLightfv() after gluLookAt() Any model space (not as intuitive). See Nate Robin’s Demo

Material Properties The color and surface properties of a material (dull, shiny, etc.) How much the surface reflects the incident lights (ambient/diffuse/specular reflection coefficients) glMaterialfv(face, property, value) Face: material property for which face (e.g. GL_FRONT, GL_BACK, GL_FRONT_AND_BACK) Property: what material property you want to set (e.g. GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_SHININESS, GL_EMISSION, etc) Value: the value you can to assign to the property

Material Example Define ambient/diffuse/specular reflection and shininess GLfloat mat_amb_diff[] = {1.0, 0.5, 0.8, 1.0}; GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat shininess[] = {5.0}; (range: dull 0 – very shiny128) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, shininess); refl. coefficient

Global light properties glLightModelfv(property, value) Enable two-sided lighting property = GL_LIGHT_MODEL_TWO_SIDE value = GL_TRUE (GL_FALSE if you don’t want two sided lighting) Global ambient color Property = GL_LIGHT_MODEL_AMBIENT Value = (red, green, blue, 1.0); Check the red book for others

Surface Normals glBegin(…) Correct normals are essential for correct lighting Associate a normal to each vertex glBegin(…) glNormal3f(x,y,z) glVertex3f(x,y,z) … glEnd() The normals you provide need to have a unit length You can use glEnable(GL_NORMALIZE) to have OpenGL normalize all the normals. Why not always have OpenGL do this?

Lighting revisit Where is lighting performed in the graphics pipeline? v1, m1 modeling and viewing per vertex lighting projection v3, m3 v2, m2 Rasterization texturing shading viewport mapping interpolate vertex colors clipping Display

Polygon shading model Flat shading – compute lighting once and assign the color to the whole polygon

Flat shading Only use one vertex (usually the first one) normal and material property to compute the color for the polygon Benefit: fast to compute It is used when: The polygon is small enough The light source is far away (why?) The eye is very far away (why?) OpenGL command: glShadeModel(GL_FLAT)

Smooth shading Remove edge discontinuity Compute lighting for more points on each face Still has a mach-band – perceived discontinuity due to your eye’s edge detection. Flat shading smooth shading

Smooth shading Two popular methods: Smooth shading (used by OpenGL) Per-fragment lighting (better specular highlight, requires programmable shaders in OpenGL)

Smooth Shading The smooth shading algorithm used in OpenGL glShadeModel(GL_SMOOTH) Lighting is calculated for each of the polygon vertices Colors are interpolated for interior pixels

Smooth Shading Per-vertex lighting calculation Normal is needed for each vertex Per-vertex normals can be computed by averaging the adjacent face normals n n1 n2 n3 n4 n = (n1 + n2 + n3 + n4) / 4.0

Smooth Shading Compute vertex illumination (color) before the projection transformation Shade interior pixels: color interpolation (normals are not needed) C1 for all scanlines Ca = lerp(C1, C2) Cb = lerp(C1, C3) C3 C2 * lerp: linear interpolation Lerp(Ca, Cb)

Smooth Shading Linear interpolation Interpolate triangle color: use y distance to interpolate the two end points in the scanline, and use x distance to interpolate interior pixel colors x = a / (a+b) * v2 + b/(a+b) * v1 a b x v1 v2

Smooth Shading Problem Lighting in the polygon interior can be inaccurate

Smooth Shading Problem Lighting in the polygon interior can be inaccurate

Phong Shading Instead of interpolation, we calculate lighting for each pixel inside the polygon (per pixel lighting) We need to have normals for all the pixels – not provided by the user Phong shading algorithm interpolates the normals and compute lighting during rasterization (need to map the normal back to world or eye space though)

Phong Shading (2) Normal interpolation Slow! You will do this in the ray-tracing class. n1 n2 n3 nb = lerp(n1, n3) na = lerp(n1, n2) lerp(na, nb)

What do Games do? Games typically use pre-computed diffuse illumination. Call light-maps. We will look at these when we look at texture maps. http://abstractmindmaps.blogspot.com/2007_01_01_archive.html