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.

Slides:



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

2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
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
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.
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,
Course Website: Computer Graphics 16: Illumination.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
Illumination.
CS 445 / 645: Introductory Computer Graphics
Computer Graphics Lighting.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
CS 638, Fall 2001 Admin Grad student TAs may have had their accounts disabled –Please check and the lab if there is a problem If you plan on graduating.
Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
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 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.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
David Luebke 1 10/26/2015 Lighting CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
03/14/02 (c) 2002 University of Wisconsin, CS559 Last Time Some more visibility (Hidden Surface Removal) algorithms –A-buffer –Scanline –Depth sorting.
CSE 381 – Advanced Game Programming GLSL Lighting.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
Illumination.
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.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
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.
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
03/19/2002(c) University of Wisconsin, CS 559 Last Time BSP Tree rendering and exact visibility in mazes Local Shading –Diffuse term –Specular term.
Computer Graphics: Illumination
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.
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.
© University of Wisconsin, CS559 Spring 2004
Shading in OpenGL Ed Angel
Lighting and Materials
Lighting – Light Sources
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Material Colours and Lighting
CS 480/680 Computer Graphics Shading.
Computer Graphics Shading in OpenGL
Presentation transcript:

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 Project 2

11/04/04© University of Wisconsin, CS559 Fall 2004 Today Lighting and Shading – Part 1

11/04/04© University of Wisconsin, CS559 Fall 2004 Where We Stand So far we know how to: –Transform between spaces –Draw polygons –Decide what’s in front Next –Deciding a pixel’s intensity and color

11/04/04© University of Wisconsin, CS559 Fall 2004 Normal Vectors The intensity of a surface depends on its orientation with respect to the light and the viewer The surface normal vector describes the orientation of the surface at a point –Mathematically: Vector that is perpendicular to the tangent plane of the surface What’s the problem with this definition? –Just “the normal vector” or “the normal” –Will use n or N to denote Normals are either supplied by the user or automatically computed

11/04/04© University of Wisconsin, CS559 Fall 2004 Transforming Normal Vectors Normal vectors are directions To transform a normal, multiply it by the inverse transpose of the transformation matrix Recall, rotation matrices are their own inverse transpose Don’t include the translation! Use (n x,n y,n z,0) for homogeneous coordinates

11/04/04© University of Wisconsin, CS559 Fall 2004 Local Shading Models Local shading models provide a way to determine the intensity and color of a point on a surface –The models are local because they don’t consider other objects –We use them because they are fast and simple to compute –They do not require knowledge of the entire scene, only the current piece of surface. Why is this good for hardware? For the moment, assume: –We are applying these computations at a particular point on a surface –We have a normal vector for that point

11/04/04© University of Wisconsin, CS559 Fall 2004 Local Shading Models What they capture: –Direct illumination from light sources –Diffuse and Specular reflections –(Very) Approximate effects of global lighting What they don’t do: –Shadows –Mirrors –Refraction –Lots of other stuff …

11/04/04© University of Wisconsin, CS559 Fall 2004 “Standard” Lighting Model Consists of three terms linearly combined: –Diffuse component for the amount of incoming light from a point source reflected equally in all directions –Specular component for the amount of light from a point source reflected in a mirror-like fashion –Ambient term to approximate light arriving via other surfaces

11/04/04© University of Wisconsin, CS559 Fall 2004 Diffuse Illumination Incoming light, I i, from direction L, is reflected equally in all directions –No dependence on viewing direction Amount of light reflected depends on: –Angle of surface with respect to light source Actually, determines how much light is collected by the surface, to then be reflected –Diffuse reflectance coefficient of the surface, k d Don’t want to illuminate back side. Use

11/04/04© University of Wisconsin, CS559 Fall 2004 Diffuse Example Where is the light? Which point is brightest (how is the normal at the brightest point related to the light)?

11/04/04© University of Wisconsin, CS559 Fall 2004 Illustrating Shading Models Show the polar graph of the amount of light leaving for a given incoming direction: Show the intensity of each point on a surface for a given light position or direction Diffuse?

11/04/04© University of Wisconsin, CS559 Fall 2004 Specular Reflection (Phong Reflectance Model) Incoming light is reflected primarily in the mirror direction, R –Perceived intensity depends on the relationship between the viewing direction, V, and the mirror direction –Bright spot is called a specularity Intensity controlled by: –The specular reflectance coefficient, k s –The Phong Exponent, p, controls the apparent size of the specularity Higher n, smaller highlight L R V

11/04/04© University of Wisconsin, CS559 Fall 2004 Specular Example

11/04/04© University of Wisconsin, CS559 Fall 2004 Illustrating Shading Models Show the polar graph of the amount of light leaving for a given incoming direction: Show the intensity of each point on a surface for a given light position or direction Specular?

11/04/04© University of Wisconsin, CS559 Fall 2004 Specular Reflection Improvement Compute based on normal vector and “halfway” vector, H –Always positive when the light and eye are above the tangent plane –Not quite the same result as the other formulation (need 2H) LV NH

11/04/04© University of Wisconsin, CS559 Fall 2004 Putting It Together Global ambient intensity, I a : –Gross approximation to light bouncing around of all other surfaces –Modulated by ambient reflectance k a Just sum all the terms If there are multiple lights, sum contributions from each light Several variations, and approximations …

11/04/04© University of Wisconsin, CS559 Fall 2004 Color Do everything for three colors, r, g and b Note that some terms (the expensive ones) are constant Using only three colors is an approximation, but few graphics practitioners realize it –k terms depend on wavelength, should compute for continuous spectrum –Aliasing in color space –Better results use 9 color samples

11/04/04© University of Wisconsin, CS559 Fall 2004 Approximations for Speed The viewer direction, V, and the light direction, L, depend on the surface position being considered, x Distant light approximation: –Assume L is constant for all x –Good approximation if light is distant, such as sun Distant viewer approximation –Assume V is constant for all x –Rarely good, but only affects specularities

11/04/04© University of Wisconsin, CS559 Fall 2004 Distant Light Approximation Distant light approximation: –Assume L is constant for all x –Good approximation if light is distant, such as sun –Generally called a directional light source What aspects of surface appearance are affected by this approximation? –Diffuse? –Specular?

11/04/04© University of Wisconsin, CS559 Fall 2004 Local Viewer Approximation Specularities require the viewing direction: –V(x) = ||c-x|| –Slightly expensive to compute Local viewer approximation uses a global V –Independent of which point is being lit –Use the view plane normal vector –Error depends on the nature of the scene Is the diffuse component affected?

11/04/04© University of Wisconsin, CS559 Fall 2004 Describing Surfaces The various parameters in the lighting equation describe the appearance of a surface (k d,r,k d,g,k d,b ): The diffuse color, which most closely maps to what you would consider the “color” of a surface –Also called diffuse reflectance coefficients (k s,r,k s,g,k s,b ): The specular color, which controls the color of specularities –The same as the diffuse color for metals, white for plastics –Some systems do not let you specify this color separately (k a,r,k a,g,k a,b ): The ambient color, which controls how the surface looks when not directly lit –Normally the same as the diffuse color

11/04/04© University of Wisconsin, CS559 Fall 2004 OpenGL Model Allows emission, E: Light being emitted by surface Allows separate light intensity for diffuse and specular Ambient light can be associated with light sources Allows spotlights that have intensity that depends on outgoing light direction Allows attenuation of light intensity with distance Can specify coefficients in multiple ways Too many variables and commands to present in class The OpenGL programming guide goes through it all (the red book)

11/04/04© University of Wisconsin, CS559 Fall 2004 OpenGL Commands (1) glMaterial{if}(face, parameter, value) –Changes one of the coefficients for the front or back side of a face (or both sides) glLight{if}(light, property, value) –Changes one of the properties of a light (intensities, positions, directions, etc) –There are 8 lights: GL_LIGHT0, GL_LIGHT1, … glLightModel{if}(property, value) –Changes one of the global light model properties (global ambient light, for instance) glEnable(GL_LIGHT0) enables GL_LIGHT0 –You must enable lights before they contribute to the image –You can enable and disable lights at any time

11/04/04© University of Wisconsin, CS559 Fall 2004 OpenGL Commands (2) glColorMaterial(face, mode) –Causes a material property, such as diffuse color, to track the current glColor() –Speeds things up, and makes coding easier glEnable(GL_LIGHTING) turns on lighting –You must enable lighting explicitly – it is off by default Don’t use specular intensity if you don’t have to –It’s expensive - turn it off by giving 0,0,0 as specular color of the lights Don’t forget normals –If you use scaling transformations, must enable GL_NORMALIZE to keep normal vectors of unit length Many other things to control appearance

11/04/04© University of Wisconsin, CS559 Fall 2004 Light Sources Two aspects of light sources are important for a local shading model: –Where is the light coming from (the L vector)? –How much light is coming (the I values)? Various light source types give different answers to the above questions: –Point light source: Light from a specific point –Directional: Light from a specific direction –Spotlight: Light from a specific point with intensity that depends on the direction –Area light: Light from a continuum of points (later in the course)

11/04/04© University of Wisconsin, CS559 Fall 2004 Point and Directional Sources Point light: –The L vector depends on where the surface point is located –Must be normalized - slightly expensive –To specify an OpenGL light at 1,1,1: Directional light: L(x) = L light –The L vector does not change over points in the world –OpenGL light traveling in direction 1,1,1 (L is in opposite direction): Glfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); Glfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position);

11/04/04© University of Wisconsin, CS559 Fall 2004 Spotlights Point source, but intensity depends on L: –Requires a position: the location of the source –Requires a direction: the center axis of the light –Requires a cut-off: how broad the beam is –Requires and exponent: how the light tapers off at the edges of the cone Intensity scaled by (L·D) n glLightfv(GL_LIGHT0, GL_POSITION, light_posn); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_dir); glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0); glLightfv(GL_LIGHT0, GL_SPOT_EXPONENT, 1.0); cut-off direction