Lighting and Shading Wen-Chieh (Steve) Lin

Slides:



Advertisements
Similar presentations
Computer Graphics - Shading -
Advertisements

Computer Graphics I, Fall 2010 Shading II.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
CS 480/680 Computer Graphics Shading 2 Dr. Frederick C Harris, Jr.
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.
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
Rendering (彩現 渲染).
Shading II CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Computer Graphics (Fall 2005) COMS 4160, Lecture 16: Illumination and Shading 1
(conventional Cartesian reference system)
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
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 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2006 Shading II Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Coordinate Systems X Y Z (conventional Cartesian reference system) X Y Z.
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.
Shading Surface can either (both) 1.Emit light. E.g. light bult 2.Reflect light. E.g. Mirror.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
Fundamentals of Computer Graphics Part 6 Shading prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
CS 445 / 645: Introductory Computer Graphics
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Shading I Shandong University Software College Instructor: Zhou Yuanfeng
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 6: Shading Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
CSC418 Computer Graphics n Illumination n Lights n Lightinging models.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
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.
CSE 381 – Advanced Game Programming GLSL Lighting.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Illumination and Shading
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Introduction to Computer Graphics with WebGL
Shading. For Further Reading Angel 7 th Ed: ­Chapter 6 2.
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.
Illumination and Shading Sang Il Park Sejong University.
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
Computer Graphics Lecture 25 Fasih ur Rehman. Last Class Shading.
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 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.
Illumination : Hearn & Baker Ch. 10
Unit-7 Lighting and Shading
Fundamentals of Computer Graphics Part 6 Shading
CS5500 Computer Graphics April 10, 2006.
Isaac Gang University of Mary Hardin-Baylor
Computer Graphics (Fall 2003)
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
CS 480/680 Computer Graphics Shading.
CS 480/680 Computer Graphics Shading.
Presentation transcript:

Lighting and Shading Wen-Chieh (Steve) Lin Department of Computer Science I-Chen Lin’ CG Slides, Doug James’ CG Slides, Angel, Interactive Computer Graphics, Chap 6 Shirley, Fundamentals of Computer Graphics, Chap 9

Illumination and Shading Is it a ball or a plate? What color should I set for each pixel? ILE5014 Computer Graphics 10F

Why Do We Need Shading? Suppose we color a sphere model. We get something like But we want ILE5014 Computer Graphics 10F

Shading Why does the image of a real sphere look like Light-material interactions cause each point to have a different color or shade Need to consider Light sources Material properties Location of the viewer Surface orientation ILE5014 Computer Graphics 10F

Factors that affect the “color” of a pixel Light sources Emittance spectrum (color) Geometry (position and direction) Directional attenuation Objects’ surface properties Reflectance spectrum (color) Geometry (position, orientation, and micro-structure) Absorption ILE5014 Computer Graphics 10F

Light and Matter Light strikes A Some of reflected light strikes B Some reflected Some absorbed Some of reflected light strikes B Some of reflected light reflected back to A and B, and so on Rendering equation describes this recursive process ILE5014 Computer Graphics 10F

Rendering Equation The infinite reflection and absorption of light can be described by the rendering equation [outgoing] = [emitted] + [reflected] (+[transmitted]) Cannot be solved in general Ray tracing is a special case for perfectly reflecting surfaces Rendering equation is global and includes Shadows Multiple reflection from object to object ILE5014 Computer Graphics 10F

Global Effects shadow transmission multiple reflection translucent surface ILE5014 Computer Graphics 10F

Local vs Global Illumination Correct shading requires a global calculation Incompatible with a pipeline model which shades each polygon independently (local rendering) However, in computer graphics, especially real time graphics, we are happy if things “look right” many techniques for approximating global effects exist ILE5014 Computer Graphics 10F

Local Illumination Adequate for real-time graphics. No inter-reflection, no refraction, no realistic shadow …. ILE5014 Computer Graphics 10F

Light Sources General light sources are difficult to simulated because we must integrate light coming from all points on the source ILE5014 Computer Graphics 10F

Simple Light Sources Point light Directional light Spotlight Model with position and color Directional light Distant source = infinite distance away (parallel) Spotlight a point light source with a small light cone radius Ambient light Same amount of light everywhere in scene Can model contribution of many sources and reflecting surfaces ILE5014 Computer Graphics 10F

Surface Types The smoother a surface, the more reflected light is concentrated in the direction A very rough surface scatters light in all directions smooth surface rough surface ILE5014 Computer Graphics 10F

Phong Reflection (Lighting) Model A simple model that can be computed rapidly Has three components Ambient Diffuse Specular Uses four vectors To source l To viewer v Normal n Perfect reflector r r = 2 (l · n ) n - l ILE5014 Computer Graphics 10F

Ambient Light The result of multiple interactions between (large) light sources and the objects in the environment. Ia = kaLa ambient light intensity ILE5014 Computer Graphics 10F

Diffuse Reflection Light scatters equally in all directions Reflected intensities vary with the direction of the light. Lambertian Surface Perfect diffuse reflector Id = kd (l·n) Ld ILE5014 Computer Graphics 10F

Specular Surfaces Most surfaces are neither perfectly diffuse nor perfectly specular (ideal reflectors) Incoming light reflects in concentrated directions close to the direction of a perfect reflection specular highlight ILE5014 Computer Graphics 10F

Modeling Specular Relections Phong model Is = ks Ls (r·v)α = ks Ls cosαΦ f shininess coefficient reflected intensity incoming intensity absorption coefficient ILE5014 Computer Graphics 10F

The Shininess Coefficient α Values of α between 100 and 200 correspond to metals Values between 5 and 10 give surfaces that look like plastic ILE5014 Computer Graphics 10F

Distance Terms Account for attenuation Original: Inversely proportional to the square of the distance d between light source and surface Modified: add a factor of the form 1/(a + bd +cd2) to the diffuse and specular terms The constant and linear terms soften the effect of the point source ILE5014 Computer Graphics 10F

Adding up the Components A primitive virtual world with lighting can be shaded by combining the three light components: I = Iambient + Idiffuse + Ispecular = kaLa + kd (l · n) Ld + ks Ls (v · r )α diffuse diffuse + specular diffuse + ambient ILE5014 Computer Graphics 10F

Coefficients 3 color channels and 3 surface types 9 coefficients for each point light source Lra, Lrd, Lrs, Lga, Lgd, Lgs, Lba, Lbd, Lbs Material properties 9 absorption coefficients kra, krd, krs, kga, kgd, kgs, kba, kbd, kbs Shininess coefficient α ILE5014 Computer Graphics 10F

Modified Phong Model r = 2 (l · n ) n - l Problem: In the specular component of Phong model, it requires the calculation of a new reflection vector and view vector for each vertex Blinn suggested an approximation using the halfway vector that is more efficient r = 2 (l · n ) n - l ILE5014 Computer Graphics 10F

The Halfway Vector h is the normalized vector halfway between l and v h = ( l + v )/ | l + v | ILE5014 Computer Graphics 10F

Using the Halfway Angle Replace (v · r )α by (n · h )b b is chosen to match shininess Note that halfway angle is half of angle between r and v if vectors are coplanar n β Θ-β h l r θ θ Φ v ILE5014 Computer Graphics 10F

Blinn lighting model Resulting model is known as the modified Phong or Blinn lighting model Specified in OpenGL standard and most real-time applications ILE5014 Computer Graphics 10F

Example Teapots with different parameters. ILE5014 Computer Graphics 10F

What’s next? So far, we know how to compute the color at a point given lighting model, illumination model, and surface normals The required computation can be huge if we compute for every point on a surface Exploit efficiency by decomposing curved surfaces into many small flat polygons ILE5014 Computer Graphics 10F

Polygonal Shading Curved surfaces are approximated by polygons How do we shade? Flat shading Interpolative shading Gouraud shading Phong shading (not Phong reflection model) Two questions: How do we determine normals at vertices? How do we calculate shading at interior points? ILE5014 Computer Graphics 10F

Flat Shading: Normal: given explicitly before vertex Shading constant across polygon Single polygon: first vertex Triangle strip: vertex n+2 for triangle n glShadeModel(GL_FLAT); glNormal3f(nx, ny, nz); glVertex3f(x, y, z); ILE5014 Computer Graphics 10F

Flat Shading Assessment Inexpensive to compute Appropriate for objects with flat faces Less pleasant for smooth surfaces ILE5014 Computer Graphics 10F

Flat Shading and Perception Lateral inhibition: exaggerates perceived intensity Mach bands: perceived “stripes” along edges ILE5014 Computer Graphics 10F

ILE5014 Computer Graphics 10F

Interpolative Shading Enable with glShadeModel(GL_SMOOTH); Calculate color at each vertex Interpolate color in interior Compute during scan conversion (rasterization) More expensive to calculate ILE5014 Computer Graphics 10F

Gouraud Shading Special case of interpolative shading How do we calculate vertex normals? Gouraud: average all adjacent face normals Requires knowledge about which faces share a vertex—adjacency info ILE5014 Computer Graphics 10F

Gouraud Shading Algorithm Find average normal at each vertex Apply Phong reflection model at each vertex Linearly interpolate vertex shades (colors) across each polygon I1(x1, y1) Ia(xa, ys) Ib(xb, ys) Is(xs, ys) I2(x2, y2) I4(x4, y4) I3(x3, y3) ILE5014 Computer Graphics 10F

Problem with Gouraud Shading See the artifact of specular highlight on a rotating sphere Highlight lies inside a polygon will not be apparent Highlight occurs at vertex will be spread unnaturally across all neighboring polygons if a highlight lies in the middle of a polygon, but does not spread to the polygon's vertex, it will not be apparent in a Gouraud rendering; conversely, if a highlight occurs at the vertex of a polygon, it will be rendered correctly at this vertex (as this is where the lighting model is applied), but will be spread unnaturally across all neighboring polygons via the interpolation method. The problem is easily spotted in a rendering which ought to have a specular highlight moving smoothly across the surface of a model as it rotates. Gouraud shading will instead produce a highlight continuously fading in and out across neighboring portions of the model, peaking in intensity when the intended specular highlight passes over a vertex of the model ILE5014 Computer Graphics 10F

Phong Shading Interpolate normals rather than colors Significantly more expensive Not supported in OpenGL Can be implemented using pixel shader In Phong shading we linearly interpolate a normal vector across the surface of the triangle from the three given normals. The surface normal is interpolated and normalized at each pixel and then used in the Phong reflection model to obtain the final pixel color. Phong shading is more computationally expensive than Gouraud shading since the reflection model must be computed at each pixel instead of at each vertex. In some modern hardware, variants of this algorithm are implemented using pixel or fragment shaders. ILE5014 Computer Graphics 10F

Phong Shading Algorithm Find vertex normals Interpolate vertex normals across edges Interpolate edge normals across each line Compute shades at each pixels of a polygon The most serious problem with Gouraud shading occurs when specular highlights are found in the middle of a large triangle. Since these specular highlights are absent from the triangle's vertices and Gouraud shading interpolates based on the vertex colors, the specular highlight will be missing from the triangle's interior. This problem is fixed by Phong shading. ILE5014 Computer Graphics 10F

Polygonal Shading Summary Gouraud shading Set vertex normals Calculate colors at vertices Interpolate colors across polygon Must calculate vertex normals! Must normalize vertex normals to unit length! ILE5014 Computer Graphics 10F

Problems with Interpolated Shading Polygonal silhouette Perspective distortion Orientation dependence Problems at shared vertices Unrepresentative vertex normals ILE5014 Computer Graphics 10F