2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods Jack van Wijk TU/e.

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.
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.
Illumination and Shading
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.
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.
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.
CS 376 Introduction to Computer Graphics 03 / 30 / 2007 Instructor: Michael Eckmann.
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.
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
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.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
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.
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 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.
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.
Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] =
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
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.
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.
Chapter 14 Shading Models.
Shading in OpenGL Ed Angel
Illumination and Shading
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Chapter 14 Shading Models.
CS 480/680 Computer Graphics Shading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods Jack van Wijk TU/e

OpenGL Illumination example Glfloat lightPos[] = {2.0, 0.0, 3.0, 0.0}; Glfloat whiteColor[] = {1.0, 1.0, 1.0, 1.0}; Glfloat pinkColor[] = {1.0, 0.5, 0.5, 1.0}; glShadeModel(GL_SMOOTH); // Use smooth shading glEnable(GL_LIGHTING); // Enable lighting glEnable(GL_LIGHT0); // Enable light source #0 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); // position LS 0 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteColor); // set color LS 0 glMaterialfv(GL_FRONT, GL_DIFFUSE, pinkColor); // set surface // color glBegin(GL_TRIANGLES); glNormal3fv(n1); glVertex3fv(v1); // draw triangle, give glNormal3fv(n2); glVertex3fv(v2); // first normal, followed glNormal3fv(n3); glVertex3fv(v3); // by vertex glEnd(); What is going on here?

Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model, or Shading Model Surface rendering: Apply the Illumination model to color all pixels of the surface. H&B 17:

Introduction 2 Example: Illumination model gives color vertices, Surface is displayed via interpolation of these colors. H&B 17:

Introduction 3 Illumination: Physics: –Material properties, light sources, relative positions, properties medium Psychology: –Perception, what do we see –Color! Often approximating models H&B 17:

Light sources 1 Light source: object that radiates energy. Sun, lamp, globe, sky… Intensity I = (I red, I green, I blue ) If I red = I green = I blue : white light H&B 17-1:

Light sources 2 Simple model: point light source -position P and intensity I -Light rays along straight lines -Good approximation for small light sources H&B 17-1:

Light sources 3 Simpler yet: point light source at infinity -Direction V and intensity I -Sunlight V H&B 17-1:

Light sources 4 Damping: intensity of light decreases with distance Energy is distributed over area sphere, hence I l = I / d 2, with d distance to light source. In practice often too ‘agressive’, hence I l = I / (a 0 +a 1 d+a 2 d 2 ) If light source at infinity: No damping with distance d H&B 17-1:

Light sources 5 Directed light source, spotlight: Light is primarily send in direction of V light. P Q ll light cone  V light H&B 17-1:

Light sources 6 More subtle: Let I decrease with increasing angle  P Q ll light cone  V light H&B 17-1:

Surface illumination 1 When light hits a surface, three things can happen: reflection transmission absorption H&B 17-2:

Surface illumination 2 Suppose, a light source radiates white light, consisting of red, green and blue light. reflection transmission absorption If only red light is reflected, then we see a red surface. H&B 17-2:

Surface illumination 3 Diffuse reflection: Light is uniformly reflected in all directions Specular reflection: Light is stronger reflected in one direction. specular reflection diffuse reflection H&B 17-2:

Surface illumination 4 Ambient light: light from the environment. Undirected light, models reflected light of other objects. H&B 17-2:

Basic illumination model 1 Basic illumination model: Ambient light; Point light sources; Ambient reflection; Diffuse reflection; Specular reflection. H&B 17-3:

Basic illumination model 2 Ambient light: environment light. Undirected light, models reflected light of other objects. H&B 17-3:

Basic illumination model 3 Perfect diffuse reflector: light is reflected uniformly in all directions. dA/cos   dA H&B 17-3:

Basic illumination model 4 Perfect diffuse reflector: light is reflected uniformly in all directions.. N L  dA/cos   dA Lambert’s law: Reflected energy is proportional with cos , where  denotes the angle between the normal N and a vector to the light source L. H&B 17-3:

Basic illumination model 5 Perfect diffuse reflector: light is reflected uniformly in all directions. N L IlIl P surf P source H&B 17-3:

Basic illumination model 6 Perfect specular reflector: light is only reflected in one direction. Angle of incidence is angle of reflection. N L R   H&B 17-3:

Basic illumination model 7 Imperfect specular reflector: light is distributed in the direction of the angle of reflection, dependent on the roughness of the surface. N L R N L R gladruw     H&B 17-3:

Basic illumination model 8 Phong model: empirical model for specular reflection N  L  R V  H&B 17-3:

Basic illumination model 9 Phong model: empirical model for specular reflection N  L  R V  H&B 17-3:

Basic illumination model 10 Phong model: calculating the vectors N L R L N.L V H&B 17-3:

Basic illumination model 11 N L  R V  H Phong model: variant with halfway vector H. Use  instead of  If light source and viewer far away: H  constant. H&B 17-3:

Basic illumination model 12 All together: H&B 17-3:

Color (reprise): Light intensity I and reflection coefficients k: (r,g,b) triplets So for instance: Plastic: k d is colored (r,g,b), k s is grey (w,w,w) Metal: k d and k s same color Basic model: simple but effective. It can be done much better though… Basic illumination model 13 H&B 17-3:

Transparancy 1 Transparant object: -reflected and transmitted light -refraction -scattering H&B 17-4:

Transparancy 2 Snell’s law of refraction: N ii L R T ii rr H&B 17-4:

Transparancy 3 Thin surface: -double refraction -shift of light ray H&B 17-4:

Transparancy 3 Very thin surface: -Discard shift Poor result for silhouette edges… H&B 17-4:

Atmospheric effects 1 Atmospheric effects: -dust, smoke, vapor -colors are dimmed -objects less well visible H&B 10-5:

Atmospheric effects 2 = [ 1  0.25 ] H&B 10-5:

Rendering polygons 1 Basic illumination model: Can be used per point, but that’s somewhat expensive More efficient: Illumination model gives color for some points; Surface is filled in using interpolation of these colors. H&B 17-10:

Rendering polygons 2 Constant-intensity rendering aka flat surface rendering: Determine color for center of polygon; Fill the polygon with a constant color. Ok if: Object consists of planar faces, and Light sources are far away, and Eye point is far away, or Polygons are about a pixel in size. H&B 17-10:

Rendering polygons 2 Constant-intensity rendering aka flat surface rendering: Determine color for center of polygon; Fill the polygon with a constant color. Highlights not visible, Facetted appearance, increased by Mach banding effect. H&B 17-10:

Human perception: edges are given emphasis, contrast is increased near edges. Mach banding Angel (2000) H&B 17-10:

Rendering polygons 2 Gouraud surface rendering: Determine average normal on vertices; Determine color for vertices; Interpolate the colors per polygon (incrementally). N1N1 N2N2 N3N3 N4N4 V H&B 17-10:

Rendering polygons 3 Gouraud surface rendering: Much better result for curved surfaces Errors near highlights Linear interpolation still gives Mach banding Silhouettes are still not smooth GouraudFlat

Rendering polygons 4 Phong surface rendering: Determine average normal per vertex; Interpolate normals per polygon (incrementally); Calculate color per pixel. Fast Phong surface rendering: Like Phong surface rendering, but use 2 nd order approximation of color over polygon: H&B 17-10:

Rendering polygons 5 Phong surface rendering: Even better result for curved surfaces No errors at high lights No Mach banding Silhouettes remain coarse More expensive than flat or Gouraud shading H&B 17-10:

Rendering polygons 5 Gouraud Flat Phong H&B 17-10:

OpenGL Illumination Glfloat lightPos[] = {2.0, 0.0, 3.0, 0.0}; Glfloat whiteColor[] = {1.0, 1.0, 1.0, 1.0}; Glfloat pinkColor[] = {1.0, 0.5, 0.5, 1.0}; glShadeModel(GL_SMOOTH); // Use smooth shading glEnable(GL_LIGHTING); // Enable lighting glEnable(GL_LIGHT0); // Enable light source #0 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); // position LS 0 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteColor); // set color LS 0 glMaterialfv(GL_FRONT, GL_DIFFUSE, pinkColor); // set surface // color glBegin(GL_TRIANGLES); glNormal3fv(n1); glVertex3fv(v1); // draw triangle, give glNormal3fv(n2); glVertex3fv(v2); // first normal, followed glNormal3fv(n3); glVertex3fv(v3); // by vertex glEnd(); H&B 17-11:

OpenGL Light-sources 1 H&B 17-11: First, enable lighting in general: glEnable(GL_LIGHTING); OpenGL provides (at least) eight light-sources: lightName = GL_LIGHT0, GL_LIGHT1, …, GL_LIGHT7 Enable the one(s) you need with: glEnable(lightName); Set properties with glLight*(lightName, lightProperty, propertyValue); * = i, f, iv, or fv (i: integer, f: float, v vector)

OpenGL Light-sources 2 H&B 17-11: Position light-source: Glfloat sunlightPos[] = {2.0, 0.0, 3.0, 0.0}; Glfloat lamplightPos[] = {2.0, 0.0, 3.0, 1.0}; glLightfv(GL_LIGHT1, GL_POSITION, sunlightPos); glLightfv(GL_LIGHT2, GL_POSITION, lamplightPos); Fourth coordinate = 0: source at infinity Fourth coordinate = 1: local source Specified in world-coordinates, according to the current ModelView specification – just like geometry. Hence, take care when you specify the position. Light from above looks more natural

OpenGL Light-sources 3 H&B 17-11: Color light-source: Glfloat greyColor[] = {0.3, 0.3, 0.3, 1.0}; Glfloat pinkColor[] = {1.0, 0.7, 0.7, 1.0}; Glfloat whiteColor[] = {1.0, 1.0, 1.0, 1.0}; glLightfv(GL_LIGHT1, GL_AMBIENT, greyColor); glLightfv(GL_LIGHT1, GL_DIFFUSE, pinkColor); glLightfv(GL_LIGHT1, GL_SPECULAR, whiteColor); OpenGL light-source has three color properties, dependent on reflection surface. Not realistic, can be used for special effects. If you don’t have ambient light, things often appear black. Colors are always 4-vectors here: Fourth coordinate is alpha. Most cases: set it to 1.0. More settings: See book

OpenGL Global Lighting H&B 17-11: Global parameters: glLightModel*(paramName, paramValue); * = i, f, iv, or fv (i: integer, f: float, v vector) Global ambient light: Glfloat globalAmbient[] = {0.3, 0.3, 0.3, 1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbient); More precise specular reflection, take view position into account: glLightModelI(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); Two-sided lighting: glLightModelI(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

OpenGL Surface properties 1 H&B 17-11: Surface reflection parameters: glMaterial*(surfFace, surfProperty, propertyValue); * = i, f, iv, or fv (i: integer, f: float, v vector) surfFace = GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK Glfloat emissionColor[] = {0.2, 0.3, 0.1, 1.0}; Glfloat diffuseColor[] = {0.6, 0.3, 0.1, 1.0}; Glfloat specularColor[] = {0.1, 0.1, 0.1, 1.0}; glMaterialfv(GL_FRONT, GL_EMISSION, emissionColor); glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor); glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor); glMaterialf(GL_FRONT, GL_SHININESS, 25.0f);

OpenGL Surface properties 2 H&B 17-11: If colors are changed often (for instance, per vertex): glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glBegin(…); for i =... for j =... glColor3f(red(i,j), green(i,j), blue(i,j)); glVertex3f(x(i,j), y(i,j), z(i,j)); glEnd(…);

OpenGL Surface properties 3 H&B 17-11: Transparent surfaces: First, draw all opaque surfaces; Next, draw transparent surfaces, back to front *, using something like: glColor4f(R, G, B, A); // A: alpha, for instance 0.40 glEnable(GL_BLEND); glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);... Draw transparent surfaces. glDisable(GL_BLEND); * OpenGL cannot automatically handle transparency, because of the z-buffer algorithm used for hidden surface removal. More on this later.

OpenGL Surface properties 4 H&B 17-11: Color Blending (see also H&B: ): Source: the new graphics object to be drawn; Destination: the current image built up. (R S, G S, B S, A S ): Source color + alpha (R D, G D, B D, A D ): Destination color + alpha (S R, S G, S B, S A ): Source blending factors (D R, D G, D B, D A ): Destination blending factors Components of Source and Destination are weighted and added: (S R R S + D R R D, S G G S + D G G D, S B B S + D B B D, S A A S + D A A D ) is stored in the current image.

OpenGL Surface properties 5 H&B 17-11: (R S, G S, B S, A S ): Source color + alpha (R D, G D, B D, A D ): Destination color + alpha (S R, S G, S B, S A ): Source blending factors (D R, D G, D B, D A ): Destination blending factors glBlendFunc(sFactor, dFactor): specify the blending factors. glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); // Use alpha of source as transparency glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Use alpha of source as opacity More options available for special effects.

OpenGL Surface-Rendering 1 H&B 17-11: glShadeModel(m): specify the rendering method m = GL_FLAT or m = GL_SMOOTH (Gouraud, default) glNormal*(Nx, Ny, Nz) : specify the normal vector Flat version: glNormal3fv(nV); glBegin(GL_TRIANGLES); glVertex3fv(V1); glVertex3fv(V2); glVertex3fv(V3); glEnd(); Smooth version: glBegin(GL_TRIANGLES); glNormal3fv(nV1); glVertex3fv(V1); glNormal3fv(nV2); glVertex3fv(V2); glNormal3fv(nV3); glVertex3fv(V3); glEnd();

OpenGL Surface-Rendering 2 H&B 17-11: glShadeModel(m): specify the rendering method m = GL_FLAT or m = GL_SMOOTH (Gouraud, default) glNormal*(Nx, Ny, Nz) : specify the normal vector glEnable(GL_NORMALIZE): Let OpenGL normalize the normals for you. And, also take care of effects of scaling, shearing, etc.

Next Now that we know how to render curved surfaces, let’s study how to define these…