Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.

Slides:



Advertisements
Similar presentations
OpenGL Course Notes Chapter 5: Lighting Jim Mims, Spring 2009.
Advertisements

Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
Illumination Lighting and Shading CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford.
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.
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.
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.
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 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);
Now Playing: Multiply Jamie Lidell from Multiply Released June 13, 2005.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red.
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.
Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
CS 445 / 645: Introductory Computer Graphics
Computer Graphics Lighting.
CS324e - Elements of Graphics and Visualization Checkerboard World.
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.
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);
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
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
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.
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
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.
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
@ 2017 by Jim X. Chen George Mason University
Shading in OpenGL Ed Angel
Lighting Phong's Lighting Model normals
Illumination and Shading
Lighting and Materials
CS5500 Computer Graphics April 10, 2006.
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Shading in OpenGL
Presentation transcript:

Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008

Lighting Principles  Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting settings  OpenGL uses an additive color model  Phong lighting computation at vertices

Lighting Principles  Light that is directly reflected off the surface creates a specular highlight  Light that is absorbed into the material before it is reflected creates the color we see. (Diffuse color)  Material's appearance is the result of a combination of several light and material properties

Lighting Principles  Lighting simulates how objects reflect light –Material composition of object –Light’s color and position –Global lighting parameters Ambient light Two sided lighting –Available in both color index and RGBA mode

How OpenGL Simulates Lights  Phong lighting model –Computed at vertices  Lighting contributors –Surface material properties –Light properties –Lighting model properties

Phong Reflection Model I = I a + I d + I s I = L a R a + L d R d + L s R s

Determining Vertex Color  Vertex color = The material emission at that vertex + The global ambient light scaled by the material's ambient property at that vertex + The ambient, diffuse, and specular contributions from all the light sources, properly attenuated

Surface Normals  Color determined by several factors –Surface normal and color –Light position –Eye position N

Surface Normals  Normals define how a surface reflects light Glnormal3f( x, y, z ) –Current normal is used to compute vertex’s color –Use unit normals for proper lighting

Light Sources  glLightfv( light, property, value ); –light specifies which light –multiple lights, starting with GL_LIGHT0  Infinite and local lights  Local lights can also be spot lights ( the local light will shine in a direction and its light will be limited to a cone centered around that direction vector. –GL_SPOT_DIRECTION defaults down -z –GL_SPOT_CUTOFF angle from center of light to edge of cone –GL_SPOT_EXPONENT concentration: 0 is uniform 128 is concentrated

Types of Lights  OpenGL supports two types of lights –Local (point) light sources –Infinite (directional) light sources  Type of light controlled by w coordinate

Turning on the Lights  Flip each light’s switch glEnable( GL_LIGHT n );  Turn on the power glEnable( GL_LIGHTING );

Light in OpenGL  Ambient light  Diffuse light  Specular light

Ambient Light  Uniform light level  Light has been scattered so much that you can't tell where it comes from  Appears to come from all directions  Constant throughout the scene  A kludge  Ambient light is scattered equally in all directions after hitting an object

Diffuse Light  Comes from one direction.  So it's brighter if it comes squarely down on a surface than if it barely glances off the surface.  After hitting a surface, it's scattered equally in all directions. –It appears equally bright, no matter where the eye is located.  Any light coming from a particular position or direction probably has a diffuse component.

Specular Light  Comes from a particular direction.  Bounces off the surface in a preferred direction.  A well-collimated laser beam bouncing off a high-quality mirror produces almost 100 percent specular reflection.  Specularity as shininess.

Specifying Light Sources in OpenGL  Light sources have a number of properties, such as color, position, and direction.  void glLight{if}[v](GLenum light, GLenum pname, TYPEparam);  Creates the light specified by light, which can be GL_LIGHT0, GL_LIGHT1,..., or GL_LIGHT7.  The characteristic of the light being set is defined by pname.

Position  Directional light source –Located infinitely far away from the scene –Rays of light can be considered parallel by the time they reach an object –Sun  Positional light source –Located near to the scene –The direction from which the light rays come –Desk lamp

Which Image Below Uses a Directional Light?

Attenuation  For real-world lights –The intensity of light decreases as distance from the light increases  OpenGL attenuates a light source by multiplying the contribution of that source by an attenuation factor:

Light Sources  Light color properties –GL_AMBIENT –GL_DIFFUSE –GL_SPECULAR  Light attenuation –GL_CONSTANT_ATTENUATION –GL_LINEAR_ATTENUATION –GL_QUADRATIC_ATTENUATION

Lighting Example GLfloat white[] = { 1, 1, 1, 0 }; GLfloat magenta[] = { 0.8, 0, 0.8, 0 }; GLfloat pos[] = { 2.5, 6, 3.5, 1.0 }; glLightfv( GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, magenta ); glLightfv( GL_LIGHT0,GL_SPECULAR,white); glLightfv( GL_LIGHT0, GL_POSITION, pos ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHTING );

Enabling Lighting  Turn on lighting calculations –glEnable( GL_LIGHTING );  Turn on each light –glEnable( GL_LIGHTn );

Spotlights  Lighting attributes GL_SPOT_DIRECTION GL_SPOT_CUTOFF GL_SPOT_EXPONENT

Lighting Features  Light attenuation –decrease light intensity with distance GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION

Material Specification in OpenGL  glMaterial assigns values to material parameters.  Front-facing, is used to shade points, lines, bitmaps, and front-facing polygons.  Back-facing, is used to shade back-facing polygons only when two-sided lighting is enabled.

Material Properties  Define the surface properties of a primitive glMaterialfv( face, property, value ); –Separate materials for front and back

Specifying Material Properties  glMaterialfv( face, property, value );  Material properties –GL_EMISSION –GL_AMBIENT –GL_DIFFUSE –GL_SPECULAR –GL_SHININESS  Polygons have material properties for front and back sides

Setting Material Properties GLfloat green[] = { 0.0, 1.0, 0.0, 0.5 }; GLfloat red[] = { 1.0, 0.0, 0.0, 0.75 }; GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green ); glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, red ); glMaterialfv( GL_FRONT, GL_SPECULAR, white ); glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, );

Ambient Reflectance  Affects the overall color of the object.  Ambient reflectance is most noticeable where an object receives no direct illumination. –Diffuse reflectance is brightest where an object is directly illuminated.  Object’s total ambient reflectance is affected by the global ambient light and ambient light from individual light sources.  Ambient reflectance isn't affected by the position of the viewpoint.

Specular Reflectance  Specular reflection from an object produces highlights.  The amount of specular reflection seen by a viewer does depend on the location of the viewpoint. –It's brightest along the direct angle of reflection.

Specular Reflectance  Characteristics of specular highlight set with shininess exponent ( ) –High value - concentrated specular reflection –Low value - larger less concentrated (more diffuse) specular reflection

Diffuse Reflectance  Plays the most important role in determining what you perceive the color of an object to be.  Affected by the color of the incident diffuse light and the angle of the incident light relative to the normal direction. –It's most intense where the incident light falls perpendicular to the surface.  Position of the viewpoint doesn't affect diffuse reflectance.

Emissive Reflectance  Make an object appear to be giving off light of that color.  Most real-world objects (except lights) don't emit light, you'll probably use this feature mostly to simulate lamps and other light sources in a scene.  Give appearance of slightly glowing. –They're not actually acting as light sources. –Create a light source and position it at the same location as the sphere to create that effect.

 Different material properties that approximate real materials.  1st column has materials (from top to bottom) emerald, jade, obsidian, pearl, ruby, and turquoise.  2nd column resembles brass, bronze, chrome, copper, gold, and silver.  3rd column represents various colors of plastic: black, cyan, green, red, white, and yellow.  4 th column is drawn with similar colors of rubber.

Real-world and OpenGL Lighting  They are VERY different.  OpenGL lighting gives realistic results, while minimizing computation.

Tips for Better Lighting  Recall lighting computed only at vertices –Model tessellation heavily affects lighting results Better results but more geometry to process  Use a single infinite light for fastest lighting –Minimal computation per vertex

Light Position Tutorial

Twelve Spheres With Different Material Parameters. The row properties are as follows: row 1 - No ambient reflection row 2 - Grey ambient reflection row 3 - Blue ambient reflection. Column 1 - uses a blue diffuse material color with no specular properties Column 2 - The second column adds white specular reflection with a low shininess exponent Column 3 - The third column uses a high shininess exponent and thus has a more concentrated highlight. Column 4 - The fourth column uses the blue diffuse color and, instead of specular reflection, adds an emissive component.

Polygon Rendering  Shading calculations require a tremendous amount of processing  Based on polygon normals or vertex normals and pixel color

Local Illumination Algorithms  Wireframe  Faceted or flat shading  Gouraud shading  Phong shading

Wireframe  Shows underlying structure  No surfaces are visible  No shading necessary

Flat or Faceted  Polygon is shaded with a single color  If polygon normal points toward a light, the surface is illuminated

Interpolative Shading - OpenGL  For each polygon. –Calculate lighting at each vertex using the normal for the polygon. –Interpolate color between the vertices. –Interpolate color along the scan lines.

Gouraud Shading  May be done in hardware  Uses vertex normals  Interpolated vertex normals to calculate light at every pixel

Gouraud  Uses vertex normals  Colors are calculated for vertices  Colors are interpolated between the polygon edges  May be done in hardware

Gouraud  Uses vertex normals  Colors are calculated for vertices  Colors are interpolated between the polygon edges  May be done in hardware

Phong Shading  Calculates surface normals at vertices  Interpolates surface normals between vertices  Calculates color of surface

Phong Shading  Almost always done off line  Better quality than Gouraud  Increased rendering time

Phong Shading  Uses vertex normals  Interpolated vertex normals to calculate light at every pixel  Almost always done off line

Lighting Principles Review  Light that is directly reflected off the surface creates a specular highlight  Light that is absorbed into the material before it is reflected creates the color we see. (Diffuse color)  Material's appearance is the result of a combination of several light and material properties

Local Illumination  Local –Contribution from the light that goes directly from the light source and is reflected from the surface –Shading of any surface is independent from the shading of all other surfaces

Global Illumination  Contribution from the light that goes directly from the light source and is reflected from the surface  Contribution from the light that is reflected from other surfaces to the current surface

Photorealism Vs Lighting Visualization  Photorealism –Mimic reality but not physically real (ambient light) –Look real –Approximate interplay of lighting  Lighting visualization –Used when lighting must match real world –Calculates scene lighting from reality –Distinguishes between natural and electric lights

Homework!  me your source code for your completed project 3/21.  Be ready to demonstrate your project 1 in class 3/24.  For Thursday: review chapter 8  For Tuesday: read chapter 10