Computer Graphics - Class 10

Slides:



Advertisements
Similar presentations
OpenGL Course Notes Chapter 5: Lighting Jim Mims, Spring 2009.
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 Computer Graphics Chapter 9 Rendering. [9]-2RM Rendering Three dimensional object rendering is the set of collective processes which make the object.
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
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
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
7M836 Animation & Rendering
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
1 Lecture 10 Lighting in OpenGL. 2 Sources of light GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 1.0}; GLLightfv(GL_LIGHT0, GL_POSITION, myLightPosition);
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Illumination and Shading
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
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.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
CSC418 Computer Graphics n Illumination n Lights n Lightinging models.
Computer Graphics I, Fall 2010 Shading in OpenGL.
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
Taku KomuraComputer Graphics Local Illumination and Shading Computer Graphics – Lecture 10 Taku Komura Institute for Perception, Action.
Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.
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,
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Illumination and Shading
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
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.
Specular Reflection Lecture 27 Mon, Nov 10, 2003.
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.
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,
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)
Computer Graphics: Illumination
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.
Computer Graphics (fall,2010) School of Computer Science University of Seoul Minho Kim.
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
School of Computer Science
Shading in OpenGL Ed Angel
Lighting Phong's Lighting Model normals
Illumination and Shading
Computer Graphics Material Colours and Lighting
CS 480/680 Computer Graphics Shading.
Presentation transcript:

Computer Graphics - Class 10 Today’s class Simple shadows Shading Lighting in OpenGL Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Simple shadows Simple shadows can be gotten by using projection matrices Consider a light source and the shadows it will cause on the floor (e.g. the xz-plane, y=0) Here the shadow will be a flat polygon The shadow polygon is the projection of the original object onto the surface Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Shadow setup Let the light source be located at (xl, yl, zl), where yl is positive Let the projection plane be y = 0 Translate the light source to the origin Now have a perspective projection through the origin (like we did previously for z = d), but the projection plane is now y = -yl Translate back Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Shadow projection matrix The three transformation matrices are: It will be easy to implement this as 3 transformations in OpenGL Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Example program RotatingCubeShadow.cpp shows an example of generating a simple shadow Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Shading models Shading models combine information about light sources with data about roughness and color of a face’s surface to approximate how the actual light reflects from the surface of the face Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Two approaches Flat shading Model is applied to only one point on the face The shade determined there fills the entire face Smooth shading Model applied to several points on the face Shades blended to yield shade at each point Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 A simple model Total light = point light sources + ambient light I = Isrc + Iamb Isrc consists of two components - diffuse and specular Isrc = Id + Isp Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Geometry of light hitting an object r is reflected light ray = -s+2(s·un)un p s n v light  r  Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Diffuse light Uniformly reemitted from a surface after absorbing incident light Brightness is proportional to surface orientation (Lambert’s law; depends on cos ) Id = Isrd(us·un) Is is the intensity of the light source rd is the diffuse reflection coefficient, usually chosen by trial and error Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Specular light Light reflected from a surface Intensity eye sees is proportional to angle between reflected ray and eye () Isp = Isrs(ur·uv)f rs is the specular reflection coefficient, usually chosen by trial and error f is usually between 1 and 200 Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Ambient light Soft, non-directional light Assigned an intensity (Ia), experimentally chosen Assigned a reflection coefficient (ra), usually the same as rd Total ambient light for a surface is Iamb=Iara Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Total light Combining the terms just developed gives the total light for a point: I = Isrc + Iamb = Id + Isp + Iamb = Is[rd(us·un) + rs(ur·uv)f] + Iara Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Flat shading Total intensity is an expensive number (computationally) to compute Want to do it as infrequently as possible Calculate it once per face and use this value to color the face Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Flat shading algorithm For each visible face: Choose a point p on the face (easiest choice is a vertex, but a better approximation would be the center - just average the vertices) Find the normal to the face Compute I at p using the equation Fill the projected polygon with the computed shade Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Flat shading pros/cons Advantages to flat shading Fast Simple Disadvantages Image is not very realistic Highlights are rendered poorly A large specular component at a point is spread over the entire face Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Flat shading in OpenGL glShadeModel (GL_FLAT); Color of object is determined by color of: Last vertex for GL_LINES, GL_TRIANGLES, GL_QUADS First vertex for GL_POLYGON Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Ray tracing At the other extreme, we can evaluate I at every point on the face This gives rise to very realistic images at the expense of a huge computational time Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Smooth shading Two approaches to smooth shading Gouraud shading Phong shading Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Gouraud shading Interpolates intensities over the face Assumes polygon face is not planar Computes true intensities at each vertex Takes a scan line approach Interpolates intensities at each end of scan line Interpolates across scan line Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Gouraud shading (cont.) At each vertex, several faces meet To find normal at each vertex, average normal for each face that meets at that vertex Due to interpolation, highlights are poorly handled here as well Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Phong shading Instead of interpolating intensities, the normals are interpolated The interpolated normals are used to compute intensities at each pixel Since better normals are used we get a better effect from specular components Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Color and the lighting model Each light source can be considered to be the sum of red, green and blue components Specular reflection is independent of the color of the object; thus, specularly reflected light is the same color as the incident light Diffuse and ambient components depend upon the color of the surface Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Color and the lighting model (cont.) Define rdR, rdG, and rdB as the diffuse reflection coefficients, which measure the percentage of their respective colors that are reflected The amount of red light that reaches the eye is therefore IR = IsR[rdR(us·un) + rs(ur·uv)f] + IaRraR raR is usually set equal to rdR Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Lighting in OpenGL Light in a scene comes from several light sources Lighting is divided into four components which are independently computed and added together emitted ambient diffuse specular Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Lighting in OpenGL (cont.) Emitted light originates from an object and is unaffected by any light sources Ambient light is from a source that has been scattered so much by the environment that its direction is impossible to determine Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Lighting in OpenGL (cont.) Diffuse light comes from one direction, but once it hits a surface it is scattered equally in all directions, so it appears equally bright no matter where the eye is located Specular light comes from one direction and bounces off a surface in a preferred direction Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Lighting in OpenGL (cont.) A light source delivers a single distribution of frequencies However, the ambient, diffuse, and specular components might be different You can specify the RGB values for each component of light independently RGB values are in [0.0, 1.0]. For multiple lights the RGB values are summed and clamped to 1.0 Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Enabling light in OpenGL Enable lighting with glEnable (GL_LIGHTING); Enable a particular light with glEnable (GL_LIGHT0); glEnable (GL_LIGHT1); etc. Each OpenGL implementation must provide a minimum of 8 light sources Do the enabling after setting the lights’ properties Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Light properties in OpenGL glLight* (light, parameter, value); GL_AMBIENT specifies RGBA values for ambient portion of light GL_DIFFUSE GL_SPECULAR GL_POSITION specifies x, y, z, w for position of light w = 0 is a directional light w  0 is a positional light Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Global ambient light glLightModel* (GL_LIGHT_MODEL_AMBIENT, value); provides global ambient light that is not from a particular light source Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Material properties RGB values correspond to the reflected proportions of the colors glMaterial* (face, parameter, value); specifies properties of objects in the scene face is one of GL_FRONT GL_BACK GL_FRONT_AND_BACK Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

glMaterial* parameters GL_AMBIENT specifies RGBA values for ambient color GL_DIFFUSE GL_AMBIENT_AND_DIFFUSE GL_SPECULAR GL_SHININESS specifies specular exponent GL_EMISSION specifies RGBA values for emissive color Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 What reaches the eye? For a particular lighting component, the light that reaches the eye is the product of the light value and the material value Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10

Computer Graphics - Class 10 Example program sphere.cpp is an example program showing different lighting models The program generates a sphere from a tetrahedron using a technique known as recursive subdivision Wednesday, November 21, 2007 Computer Graphics - Class 10 Wednesday, November 21, 2007 Computer Graphics - Class 10