Shading Intro. Shading & Lighting. Light and Matter. Light and Matter

Similar documents
CHAPTER5. We have learned to build three-dimensional graphical models and to LIGHTING AND SHADING

Lighting. Figure 10.1

Comp 410/510 Computer Graphics. Spring Shading

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

Computer Graphics. Illumination and Shading

Virtual Reality for Human Computer Interaction

Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Illumination & Shading

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Shading. Why we need shading. Scattering. Shading. Objectives

CS130 : Computer Graphics Lecture 8: Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

WHY WE NEED SHADING. Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like.

Illumination and Shading

Objectives. Introduce Phong model Introduce modified Phong model Consider computation of required vectors Discuss polygonal shading.

Computer Graphics. Shading. Based on slides by Dianna Xu, Bryn Mawr College

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Shading I Computer Graphics I, Fall 2008

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Why we need shading?

Illumination and Shading

Introduction to Computer Graphics 7. Shading

Shading and Illumination

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

Illumination & Shading: Part 1

Illumination and Shading

CEng 477 Introduction to Computer Graphics Fall

Reading. Shading. An abundance of photons. Introduction. Required: Angel , 6.5, Optional: Angel 6.4 OpenGL red book, chapter 5.

Reflection and Shading

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics V. Guoying Zhao 1 / 65

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

Computer Graphics. Illumination and Shading

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

CS452/552; EE465/505. Intro to Lighting

Shading , Fall 2004 Nancy Pollard Mark Tomczak

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

surface: reflectance transparency, opacity, translucency orientation illumination: location intensity wavelength point-source, diffuse source

Visualisatie BMT. Rendering. Arjan Kok

Light Transport Baoquan Chen 2017

CS 4600 Fall Utah School of Computing

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

Reading. Shading. Introduction. An abundance of photons. Required: Angel , Optional: OpenGL red book, chapter 5.

CS5620 Intro to Computer Graphics

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

CPSC 314 LIGHTING AND SHADING

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

Sung-Eui Yoon ( 윤성의 )

w Foley, Section16.1 Reading

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Illumination and Shading

M jrs M jgs M jbs Intensity of light reflected from surface j when illuminated by source i: I ijr

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

Illumination in Computer Graphics

Objectives. Shading II. Distance Terms. The Phong Reflection Model

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

University of Victoria CSC 305 Shading. Brian Wyvill 2016

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

CS Surface Rendering

CS770/870 Spring 2017 Color and Shading

CPSC / Illumination and Shading

OpenGL Lighting Computer Graphics Spring Frank Palermo

Simple Lighting/Illumination Models

Illumination and Shading ECE 567

Illumination & Shading I

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Computer Graphics I Lecture 11

CS 325 Computer Graphics

Computer Graphics. Illumination Models and Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

6. Illumination, Lighting

Computer Graphics. Ray Tracing. Based on slides by Dianna Xu, Bryn Mawr College

CS 4731: Computer Graphics Lecture 16: Phong Illumination and Shading. Emmanuel Agu

Illumination Models & Shading

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

5.2 Shading in OpenGL

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Ambient reflection. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 407

Shading II. CITS3003 Graphics & Animation

INF3320 Computer Graphics and Discrete Geometry

So far, we have considered only local models of illumination; they only account for incident light coming directly from the light sources.

Chapter 10. Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

CHAPTER 1 Graphics Systems and Models 3

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Virtual Reality for Human Computer Interaction

Shading in OpenGL. Outline. Defining and Maintaining Normals. Normalization. Enabling Lighting and Lights. Outline

Supplement to Lecture 16

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Lighting/Shading III. Week 7, Wed Mar 3

Ray-Tracing. Misha Kazhdan

Graphics for VEs. Ruth Aylett

Today we will start to look at illumination models in computer graphics

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

CS230 : Computer Graphics Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

Lighting and Shading

Topics and things to know about them:

CS Illumination and Shading. Slide 1

Transcription:

Shading Intro Shading & Lighting Move from flat to 3-D models Orthographic view of sphere was uniformly color, thus, a flat circle A circular shape with many gradations or shades of color Courtesy of Vincent Costa Rendering is based on physics Physically either emit light or reflect it Multiple interactions among light sources and reflective surfaces determine the color point of a object Light and Matter Light and Matter View as a recursive process that results in an integral equation called the rendering equation which, in general, is unsolvable Best technique is to use ray tracing and radiosity, but they are presently too slow

Light and Matter Use a simpler rendering model based on Phong reflection Follow rays of light from light-emitting surfaces, called light sources Consider only single interactions between light sources and surfaces Viewer sees only the light that leaves the source and reaches the eye Light and Matter Viewer sees the color of the light reflected from the surface Replace the viewer by a projection plane Clipping window is mapped to the screen, each rectangle is a pixel Color of light source and surfaces determine the color of one or more pixels in the frame buffer Most rays never contribute to the image Light-Material Interaction Light-Material Interactions specular surface diffuse surface translucent surface Specular surfaces appear shiny because most of the light that is reflected is scattered in a narrow range of angles close to the angle of reflection (mirrors are perfect specular surfaces) Diffuse surfaces are characterized by reflected light being scattered in all directions Translucent surfaces allow some light to penetrate the surface and to emerge from another location on the object in a process called refraction

Material Properties Light Sources blue diffuse no specular white specular low shininess white specular high shininess blue diffuser emissive no ambient reflection gray ambient reflection blue ambient reflection Light can leave a surface through two fundamental processes: self-emission and reflection Light source is an object with a surface Each point (x,y,x) on the surface can emit light that is characterized by the direction of emission (θ,φ) and the intensity of energy emitted at each wavelength λ General light source is a six variable illumination function I(x,y,z,θ,φ,λ) Easiest to model with polygons u=θ f=φ I(x,y,z,θ,φ,λ) Light Sources Color Sources Light sources emit different amounts of light at different frequencies Best physical model is based on three color theory We use each of the three color sources (red, green, blue) to obtain a corresponding color component that a human sees We describe a source through a three component intensity or luminance function: I I = I I r g b

Light Sources Ambient Lighting Point Sources Spotlights Distant Lights These are sufficient for rendering most scenes Ambient Light Ambient Light is the uniform lighting in an environment background glow Ambient illumination is characterized by an intensity, I a, that is identical at every point in the scene It has three color components: I Ia = I I ar ag ab We use the scalar I a to denote any on of the red, green or blue components Point Sources An ideal point source emits light equally in all directions Characterize a point source located at a point p 0 by: I r ( p0) I(p0) = I g ( p0) Ib( p0) Point Sources The intensity of illumination received from a point source is proportional to the inverse square of the distance between the source and the surface At a point p, the intensity of light received from the point source is given by: 1 I(p, p0) = I( p0) 2 p p 0 Distance between p and p 0 can be replaced with: ( a+ bd + cd 2 1 )

Point Sources Spotlights Point sources tend to have high contrast Larger the light source, softer the scene Some areas in full shadow, umbra, others in partial shadow, penumbra Mitigate high contrast by adding ambient light -θ φ θ θ Spotlights are characterized by a narrow range of angles through which light is emitted Given a point source, limit the angles at which light from the source can be seen Use a cone whose apex is at p s, which points in the direction l s, and width is determined by an angle θ Distant Light Distant Light Point on the surface to the light source doesn t change much as the distance increases Replace a point source with a parallel source that illuminates objects with parallel rays of light Replace location of the light source with direction of the light source x y p 0 = z 1 point source x y p 0 = z 0 direction vector source

If the goal in shading a computer synthesized image is to simulate a real physical object, then the shading model should in some way imitate real physical shading situations. Bui-Tuong Phong Phong Reflection Model Shading model was introduced in 1975 Close approximation to physical reality Model supports three types of materiallight interactions: ambient, diffuse and specular I = 1 α ( kd Ldl n+ ksls ( r v) k a+ bd + cd ) + 2 a L a Utah Teapot Phong Reflection Model Model uses four vectors to calculate a color for an arbitrary point p on a surface n is the normal at p v is in the direction from p to the viewer or COP l is in the direction of a line from p to the light source r is in the direction that a perfectly reflected ray from l would take 1975 Martin Newell of University of Utah creates the first environmentally mapped object

Phong Reflection Model Model supports three types of material-light interactions: ambient, diffuse and specular Given a set of point sources, assume each has separate ambient, diffuse and specular components for each of the primary colors 3x3 illumination matrix for the i th light source at any point p on the surface: L Li = L L ira ird irs L L L iga igd igs L L L iba ibd ibs Phong Reflection Model How much of the incident light is reflected at a point Amount of reflection depends on the material properties, surface orientation, light source direction and distance 3x3 reflection matrix for the i th light source at any point p on the surface: R Ri = R R ira ird irs R R R iga igd igs R R R iba ibd ibs Phong Reflection Model Now we compute the contribution for each color source by adding the ambient, diffuse and specular components e.g., the red intensity that we see at p from source i is I = R L + R L + R L = I + I + I ir ira ira ird ird Obtain the total intensity by adding the contributions of all sources and a global ambient term. Thus, the red term is r i ira ird irs irs irs = ) I ( I + I + I + I ira ar ird irs Phong Reflection Model Note that the necessary computations are the same for each source and for each primary color They differ depending on whether we are considering the ambient, diffuse or specular terms We can omit the subscript and write I = I + I + I = R L + R L + R L a d s a understanding that the computation will be done for each of the primaries and each source a d d s s

Ambient Reflection The intensity of ambient light L a is the same at every point on the surface Amount reflected is given by the ambient reflection coefficient, R a =k a Thus I a = k a L a where 0 k a 1 Diffuse Reflection A perfectly diffuse reflector scatters the light that it reflects equally in all directions Amount of light reflected is dependent on the material and the orientation of the light source Diffuse Reflection Diffuse Reflection The relationship between brightness and surface orientation is called Lambert s law θ θ Lambert s law states R d cosθ, where θ is the angle between the normal n and the direction of the light source l. If these are unit vectors, then cosθ = l n If we add the diffuse reflection coefficient k d, we have the diffuse reflection term: I d = k d (l n)l d

Specular Reflection We need to add highlights that are reflected from shiny objects Color is different from the color of the reflected ambient and diffuse light Specular Reflection Surface is smooth Smoothest surface resembles a mirror Reflected light is concentrated in a smaller range of angles as the surface gets smoother Modeling is complex, (wavelength of light and reflection angle) Specular Reflection Phong proposed an approximate model similar to the one used for diffuse surfaces I s =k s L s cos α φ where the coefficient k s (0 k s 1) is the fraction of the incoming specular light that is reflected, φ is the angle between the direction of the perfect reflector, r, and the direction of the viewer, v, and α is a shininess coefficient If we normalize r and v we can use the dot product and the specular reflection term is: I s =k s L s (r v) α Specular Reflection As it is increased, the reflected light is concentrated in a narrower region, centered on the angle of a perfect reflector

Phong Reflection Model Teapots, Teapots, We can add a quadratic attenuation term for distance from the light source and finally arrive at the Phong model: I = 1 α ( kd Ldl n+ ksls ( r v) k a+ bd + cd ) + 2 This formula is computed for each light source and for each primary color a L a Computation of Vectors Computation of Vectors Smooth curved surfaces are approximated by a large number of small flat polygons. Vectors perpendicular to these polygons can be used as the surface normals The surface appears faceted, since the normal direction is discontinuous across the polygonal boundaries. In many cases, however, an exact mathematical description exists for the surface, and true surface normals can be calculated at every point. Using the true normals improves the rendering considerably

Normal Vectors For smooth, flat surfaces, the vector normal to the surface exists at every point Plane: ax + by + cz + d = 0 Also, n (p - p 0 ) = 0 where p 0 is a point on the plane, p is any point (x,y,z) on the plane and n is the normal to the plane Normal Vectors Given three noncollinear points, p 0, p 1, p 2 and vectors p 2 - p 0 and p 1 - p 0 are parallel to the plane Normal: n = (p 2 - p 0 ) (p 1 - p 0 ) Order of the vectors in the cross product is important, since it determines pointing in or out OpenGL does not determine the normal automatically Normal Vectors For curved surfaces, there are different methods for representation (bezier, b-spline, NURBS) Unit Sphere, Implicit form: 2 2 2 f ( x, y, z) = x + y + z 1= 0 Also, f(p) = p p 1 = 0 Normal Vectors Normal is given by the gradient vector f 2 n x f x = = 2y = 2p y f 2 z z

Normal Vectors We usually have to work with a collection of vertices and approximate a normal vector OpenGL takes the do-it-yourself approach to normals The user program must determine the normal We associate a normal with a vertex through the function glnormal3f(nx, ny, nz); All subsequent glvertex calls use that normal Angle of Reflection We use the normal n and the direction of the light source l to determine the direction of a perfect reflection Ideal mirror: The angle of incidence is equal to the angle of reflection angle of incidence θ i θ r angle of reflection Angle of Reflection For three dimensions: At a point p on the surface, the incoming light ray, the reflected light ray, and the normal at the point must all lie in the same plane We are concerned with the direction of r Unit-length vectors make rendering calculations easier Normalize l, n, and r such that l = n =1 and r = 1 Halfway Vector With the phong model, r v must be recalculated for every point of the surface Halfway vectors are used to simplify this calculation, replace r v with n h h = (l + v )/ l + v, it is a unit vector halfway

Transmitted Light Transmitted Light Ideal condition is a surface that transmits all the light that strikes it Light is bent at the surface due to the difference in the speed of light in the materials η l and η t are the indices of refraction, the relative speed of light in two materials Snell s law, sinθ l ηt = sinθ η t l θ l θ t ideal reality Phong Shading Polygonal Shading Assuming we can compute normal vectors, we can use our lighting models and apply them to every point on the surface Computationally expensive Polygons simplify this process Decompose curved surfaces into many small polygons where each polygon is flat and it has a well defined normal vector Polygonal Mesh

Flat Shading l, n, and v vary from point to point on a surface For a flat polygon, n is constant Over a distance, l and v are constant Distance can be interpreted by relative size of the polygon to the viewer Flat Shading If the three vectors are constant, then the shading calculation needs to be carried out only once for each polygon Each point on the polygon is assigned the same shade This technique is called flat shading glshademodel(gl_flat); OpenGL uses the normal associated with the first vertex of a single polygon Flat Shading Flat Shading Flat shading will show differences in shading for the polygons in our mesh Modeling a smooth surface will be disappointing Human visual system is very sensitive to small differences in light intensity because of lateral inhibition

Mach Bands Mach Bands The solid black curve represents the amount of light being reflected from the figure at the top. The red curve represents the brightness of this figure as it is usually perceived. To the left of the point where the figure just starts to get lighter people usually see a dark bar that is slightly darker that the area to the left of it This phenomenon was discovered by the famous physicist, Ernst Mach Interpolative Shading OpenGL interpolates colors assigned to vertices across a polygon (rotating cube) If the light source and viewer are distant, then we can use interpolative shading to shade a polygon in a constant shade OpenGL interpolates colors for primitives other than vertices via glshademodel(gl_smooth) Assign to each vertex the normal of the polygon being shaded Interpolative Shading Multiple polygons meet at interior vertices of the mesh, each with its own normal The normal at the vertex is discontinuous

Gourand Shading In Gourand shading, we define the normal at a vertex to be the normalized average of the normals of the polygons that share the vertex In the previous diagram, the vertex normal is given by n1 + n2 + n3 + n4 n= n + n + n + n 1 2 3 Gourand shading is deceptively simple 4 Gourand Shading How do we find the normals that we should average? We need a data structure to represent the mesh Key info: which polygons meet at each vertex Phong Shading Phong proposed interpolating normals across each polygon Compute vertex normals by interpolating over the normals of the polygons that share the vertex Use bilinear interpolation to interpolate the normals over the polygon Determine the normal at any interior point with n(α, β)=(1-β)n C +βn D Make independent shading operation for each point and combine with scan conversion Phong Shading Produces smoother renderings but at a significant cost Gourand shading is built into hardware Phong Shading is usually done off line

Approximating A Sphere Tetrahedron No sphere in OpenGL Polygonal approximation to a sphere Recursive subdivision is a powerful technique for generating approximations to curves and surfaces to any desired accuracy Start with a tetrahedron http://www.math.umn.edu/~roberts/java.dir/jgv/tetrahedron1.html Recursive Subdivision Four equilateral triangles Four vertices All four lie on the unit sphere centered at the origin ( 0,0,1),(0,2 2, 1 ),( 6, 2, 1 ),( 6, 2, 1 ) 3 3 3 3 3 3 3 3 Recursive Subdivision but it s not a sphere Closer approximation by subdividing each facet of the tetrahedron into smaller triangles Connect bisectors of the sides of the triangle, forming four equilateral triangles

Recursive Subdivision Subdividing Continues but four new triangles are still in the same plane as the original triangle Move the new vertices created by bisection to the unit sphere Normalize each bisected vertex Light Sources OpenGL supports the four types of light sources and up to 8 light sources Format: gllightfv(source, parameter, pointer_to_array); Light and Position Nate Robins' Light and Position Tutorial Glfloat light0_pos[ ]={1.0, 2.0, 3.0, 1.0}; Position of the source Glfloat diffuse0[ ]={1.0, 0.0, 0.0, 1.0}; Amount of diffuse Glfloat ambient0[ ]={1.0, 0.0, 0.0, 1.0}; Amount of ambient Glfloat specular0[ ]={1.0, 1.0, 1.0, 1.0}; Amount of specular www.xmission.com/~nate/tutors.html glenable(gl_lighting); glenable(gl_light0); gllightfv(gl_light0, GL_POSITION, light0_pos); gllightfv(gl_light0, GL_AMBIENT, ambient0); gllightfv(gl_light0, GL_DIFFUSE, diffuse0); gllightfv(gl_light0, GL_SPECULAR, specular0);

Materials Material properties in OpenGL match up directly with the supported light sources and the Phong reflection model Can specify different material properties for front and back faces of a surface Material properties are modal: values remain the same until changed Format: glmaterialfv(face, type, pointer_to_array); Glfloat light0_pos[ ]={1.0, 2.0, 3.0, 1.0}; Glfloat ambient[ ]={0.2, 0.2, 0.2, 1.0}; Glfloat diffuse[ ]={1.0, 0.8, 0.0, 1.0}; Glfloat specular[ ]={1.0, 1.0, 1.0, 1.0}; Light and Material Nate Robins' Light and Material Tutorial www.xmission.com/~nate/tutors.html glmaterialfv(gl_front_and_back, GL_AMBIENT, ambient); glmaterialfv(gl_front_and_back, GL_DIFFUSE, diffuse); glmaterialfv(gl_front_and_back, GL_SPECULAR, specular); glmaterialfv(gl_front_and_back, GL_SHININESS, 100.0); Global Rendering Limitation to the local model Spheres close to the source block some of the light In local model, each sphere is shaded independently Ray Tracing Only rays that contribute to our images are those that enter the lens and pass through the COP Most rays do not contribute to our image Reverse the direction and consider only those ray that start at the COP, cast rays

Ray Tracing Ray Tracing cast rays Rule the image plane into pixel-sized areas Cast at least one ray through each pixel Intersect a surface or light source, or go off to nowhere, getting a background color Calculate a shade for surfaces that a ray strikes Ray Tracing Ray Tracing handled recursively shadow ray ray tree

Ray Tracing Easiest way to describe a ray tracer is recursively Most of the work in ray tracing goes into the calculation of intersections between rays and surfaces Best suited for highly reflective environments Radiosity Radiosity is ideal for a scene consisting of only perfectly diffuse surfaces Diffuse-diffuse interactions shading model Assume all surfaces are perfectly diffuse Simulates the actual behavior of light The goal of the radiosity method is to find the point of equilibrium of all the radiation in the system. Radiosity Radiosity

Radiosity One Last Ugly Teapot