Illumination and Shading

Slides:



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

1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
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.
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.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of New Mexico
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.
Lighting and Shading Wen-Chieh (Steve) Lin
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
CS 445 / 645: Introductory Computer Graphics
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
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 |
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);
11/04/04© University of Wisconsin, CS559 Fall 2004 Last Time Visibility –Z-Buffer and transparency –A-buffer –Area subdivision –BSP Trees –Exact Cell-Portal.
Illumination and Shading
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.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
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.
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
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
Computer Graphics: Illumination
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.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
Shading To determine the correct shades of color on the surface of graphical objects.
Lecture 16: Shading and OpenGL Li Zhang Spring 2008
Illumination and Shading
@ 2017 by Jim X. Chen George Mason University
Open GL: Colors and Lighting
Shading in OpenGL Ed Angel
Illumination and Shading
CS5500 Computer Graphics April 10, 2006.
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Presentation transcript:

Illumination and Shading Mengxia Zhu Fall 2007 .

Why? What light source is used and how the object response to the light makes difference Lighting gives you a 3D view to an object A unlit sphere looks no different from a 2D disk To get realistic pictures, the color computation of pixels must include lighting calculations

Local and Global Illumination Local illumination: a surface point receives light directly from all light sources in the scene. Consider in isolation Global illumination: a point receives light after light rays interact with other objects in the scene. Shadow Refract through transparent object Reflection and transmission rays

Illumination Vs. Shading Illumination (lighting) model: To model the interaction of light with surfaces to determine the final color & brightness of the surface Shading model: applies the illumination models at a set of points and colors the whole image.

Local illumination Only consider the light, the observer position, and the object material properties V L

Types of Light Ambient Diffuse Specular Light that’s been scattered so much by the environment that its direction is impossible to determine - it seems to come from all directions Diffuse Light that comes from one direction, but it gets scattered equally in all directions Specular Light comes from a particular direction, and its tends to bounce off the surface in a preferred direction

OpenGL Lighting Model OpenGL approximates lighting as if light can be broken into red, green, and blue components The RGB values for lights mean different than for materials For light, the numbers correspond to a percentage of full intensity for each color For materials, the numbers correspond to the reflected proportions of those colors

Ambient light (background light) The light that is the result from the light reflecting off other surfaces in the environment A general level of brightness for a scene that is independent of the light positions or surface directions Has no direction Each light source has an ambient light contribution, Ia For a given surface, we can specify how much ambient light the surface can reflect using an ambient reflection coefficient : Ka (0 < Ka < 1)

Ambient Light Ambient, omni-directional light So the amount of light that the surface reflect is therefore Ka ambient coefficient Iamb =

Diffuse Light The illumination that a surface receives from a light source and reflects equally in all directions This type of reflection is called Lambertian reflection The brightness of the surface is independent of the observer position (since the light is reflected in all direction equally) L

Lambert’s Law Lambert’s law: the radiant energy for a given light source is: Id * cos(q) Id : the intensity of the light source is the angle between the surface normal (N) and light vector (L) If N and L are normalized, cos(q) = Surface’s material property: assuming that the surface can reflect Kd (0<Kd<1), diffuse reflection coefficient) amount of diffuse light.

The Diffuse Component Brightness is inversely proportional to the area of the object illuminated (dot product of light vector and surface normal) greatest when N and L are parallel smallest when N and L are orthogonal In calculations, max {N.L, 0} is used to avoid negative values The total diffuse reflection = ambient + diffuse

Specular Light These are the bright spots on objects (such as polished metal, apple ...) Light reflected from the surface unequally to all directions.

Phong’s Model for Specular Brightness depends on the angle between reflection vector (R) and viewer vector (V), i.e, on direction of viewer

Summing the Components Ambient + Diffuse + Specular = final

Phong Illumination Curves Specular exponents are much larger than 1, and Values of 100 are not uncommon. The specular reflection exponent n is 1 for a slightly glossy surface and infinity for a perfect mirror. : glossiness, rate of falloff

Changing Specular exponent n

Double length of vector Reflected Ray N How to calculate R? R + L = 2(N*L) N R = 2(N*L) N - L L R f f a V f L 2N(N•L) Double length of vector f L R = 2N(N•L) - L Subtract L f L N(N•L) Project L onto N

Half Vector An alternative way of computing phong lighting is: H (halfway vector): halfway between V and L: (V+L) L N H V

Putting It All Together Single Light:

Attenuation Attenuation factor The intensity becomes Light attenuates with distance from the source where d = distance between the light and object kc = constant attenuation A light source does not give an infinite amount of light kl = linear term kq = quadratic term Models the theoretical attenuation from a point source The intensity becomes

Spotlight Effect When the vertex lies inside the cone of illumination produced by spotlight, its contribution to the light intensity is Where D gives the spotlight’s direction. The intensity is maximum in the center of cone and is attenuated toward the edge of the cone s is 1 if the source is not spotlight m is exponent determining the concentration of the light The intensity of light source is

Putting All Together Multiple lighting calculation in RGB mode gives Vertex color

Adding Lighting to the Scene Define normal vectors for each vertex of each object Create, select, and position one or more light sources Create and select a lighting model Define material properties for the objects in the scene

Creating Light Sources Properties of light sources are color, position, and direction void glLight{if}(GLenum light, GLenum pname, TYPE param); void glLight{if}v(GLenum light, GLenum pname, TYPE *param); Creates the light specified by light that can be GL_LIGHT0, GL_LIGHT1, … or GL_LIGHT7 Pname specifies the characteristics of the light being set Param indicates the values to which the pname characteristic is set glEnable(GL_LIGHT0);

Color for a Light Source 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}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

Position of Light Source Positional light source (x, y, z) values specify the location of the light GLfloat light_position[] = {x, y, z, w}; glLightfv(GL_LIGHT0, GL_POSITION, light_position); Directional light source (x, y, z) values specify the direction of the light located at the infinity No attenuation GLfloat light_position[] = {x, y, z, 0};

Attenuation Attenuation factor for a positional light Needs to specify three coefficients glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 1.0); Ambient, diffuse, and specular contributions are all attenuated

Spotlights The shape of the light emitted is restricted to a cone glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0); The cutoff parameter is set to 45 degrees GLfloat spot_direction[] = {-1.0, -1.0, 0.0]; glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction); specifies the spotlight’s direction which determines the axis of the cone of light glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 2.0); Controls how concentrated the light is

Multiple Lights You can define up to eight light sources Need to specify all the parameters defining the position and characteristics of the light OpenGL performs calculations to determine how much light each vertex gets from each source Increasing number of lights affects performance

Defining Material Properties Specifying the ambient, diffuse, and specular colors, the shininess, and the color of any emitted light void glMaterial{if}(GLenum face, GLenum pname, TYPE param); void glMaterial{if}v(GLenum face, GLenum pname, TYPE *param); Specifies a current material property for use in lighting calculations Face can be GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK Pname identifies the particular material property being set Param defines the desired values for that property

Reflectance Diffuse and ambient reflection Gives color GLfloat mat_amb_diff[] = {0.1, 0.5,0.8,1.0}; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff); Specular reflection Produces highlights GLfloat mat_specular[] = {1.0,1.0,1.0,1.0); Glfloat low_shininess[] = {5.0}; glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);

Shading Models for Polygons Constant Shading (flat shading) Compute illumination at any one point on the surface. Use face or one normal from a pair of edges. Good for far away light and viewer or if facets approximate surface well. Per-Pixel Shading Compute illumination at every point on the surface. Interpolated Shading Compute illumination at vertices and interpolate color

Constant Shading Compute illumination only at one point on the surface Okay to use if all of the following are true The object is not a curved (smooth) surface (e.g. a polyhedron object) The light source is very far away (so N.L does not change much across a polygon) The eye is very far away (so V.R does not change much across a polygon) The surface is quite small (close to pixel size)

Un-lit

Flat Shading

Mach Band ?

Polygon Mesh Shading Shading each polygonal facet individually will not generate an illusion of smooth curved surface Reason: polygons will have different colors along the boundary, unfortunately, human perception helps to even accentuate the discontinuity: mach band effect

Smooth Shading Need to have per-vertex normals Gouraud Shading Interpolate color across triangles Fast, supported by most of the graphics accelerator cards Phong Shading Interpolate normals across triangles More accurate, but slow. Not widely supported by hardware

Gouraud Shading Normals are computed at the polygon vertices If we only have per-face normals, the normal at each vertex is the average of the normals of its adjacent faces Intensity interpolation: linearly interpolate the pixel intensity (color) across a polygon surface

Linear Interpolation If v1 and v2 are known, then Calculate the value of a point based on the distances to the point’s two neighbor points If v1 and v2 are known, then x = b/(a+b) * v1 + a/(a+b) * v2

Linear Interpolation in a Triangle To determine the intensity (color) of point P in the triangle, we will do: determine the intensity of 4 by linearly interpolating between 1 and 2 determine the intensity of 5 by linearly interpolating between 2 and 3 determine the intensity of P by linear interpolating between 4 and 5

Mach Band ?

Image

Phong Shading Model Gouraud shading does not properly handle specular highlights, specially when the n parameter is large (small highlight). Reason: colors are interpolated. Solution: (Phong Shading Model) 1. Compute averaged normal at vertices. 2. Interpolate normals along edges and scan-lines. (component by component) 3. Compute per-pixel illumination.

References Slides from Karki at LSU Jian Huang at UTK