CS 376 Introduction to Computer Graphics 04 / 02 / 2007 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
GR2 Advanced Computer Graphics AGR
Advertisements

SI31 Advanced Computer Graphics AGR
13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
Illumination Model & Surface-rendering Method 박 경 와.
Computer Graphics - Class 10
CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann.
IMGD 1001: Illumination by Mark Claypool
CS6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003 Object-Order vs. Screen-Order Rendering April 24, 2003.
CS 376 Introduction to Computer Graphics 04 / 09 / 2007 Instructor: Michael Eckmann.
Computer Graphics (Fall 2005) COMS 4160, Lecture 16: Illumination and Shading 1
(conventional Cartesian reference system)
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
Global Illumination May 7, Global Effects translucent surface shadow multiple reflection.
CS 376 Introduction to Computer Graphics 03 / 26 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.
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.
CS 376 Introduction to Computer Graphics 04 / 04 / 2007 Instructor: Michael Eckmann.
Coordinate Systems X Y Z (conventional Cartesian reference system) X Y Z.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
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.:
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
CS 445 / 645 Introduction to Computer Graphics Lecture 18 Shading Shading.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Reflections Specular reflection is the perfect reflection of light from a surface. The law a reflection states that the direction of the incoming ray and.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 11 / 2007 Instructor: Michael Eckmann.
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS 1 Shading (Shading) & Smooth Shading Graphics.
CS 376 Introduction to Computer Graphics 04 / 16 / 2007 Instructor: Michael Eckmann.
CS447/ Realistic Rendering -- Radiosity Methods-- Introduction to 2D and 3D Computer Graphics.
University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell Ray Tracing.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
CS 325 Introduction to Computer Graphics 03 / 26 / 2010 Instructor: Michael Eckmann.
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.
CS 325 Introduction to Computer Graphics 03 / 24 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 14 / 2010 Instructor: Michael Eckmann.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Komputer Grafik 2 (AK045206) Shading 1/17 Realisme : Shading.
Illumination and Shading
CS 450: COMPUTER GRAPHICS TRANSPARENT SURFACES SPRING 2015 DR. MICHAEL J. REALE.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Surface Rendering Methods 고려대학교 컴퓨터 그래픽스 연구실.
CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
CSCE 441: Computer Graphics Ray Tracing
Local Illumination and Shading
Illumination and Shading Prof. Lizhuang Ma Shanghai Jiao Tong University.
Render methods. Contents Levels of rendering Wireframe Plain shadow Gouraud Phong Comparison Gouraud-Phong.
CSE 681 Introduction to Ray Tracing. CSE 681 Ray Tracing Shoot a ray through each pixel; Find first object intersected by ray. Image plane Eye Compute.
David Luebke3/16/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
CS 325 Introduction to Computer Graphics 04 / 07 / 2010 Instructor: Michael Eckmann.
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
CS 376 Introduction to Computer Graphics 04 / 13 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 18 / 2007 Instructor: Michael Eckmann.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination and Shading Prof. Lizhuang Ma Shanghai Jiao Tong University.
Unit-7 Lighting and Shading
Chapter 14 Shading Models.
CSC461: Lecture 23 Shading Computation
CS5500 Computer Graphics May 29, 2006
Illumination and Shading
GR2 Advanced Computer Graphics AGR
Chapter 14 Shading Models.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Presentation transcript:

CS 376 Introduction to Computer Graphics 04 / 02 / 2007 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Spring 2007 Today’s Topics Questions? Transparent/translucent surfaces Shading –flat shading –gouraud shading –phong shading Raytracing –how it works generally –computing the intersection of a ray and a sphere –computing the intersection of a ray and a plane

Transparent/Translucent surfaces Transparent, opaque, translucent –Transparent refers to the quality of a surface that we can “see through”. Opaque surfaces, we cannot see through. –some transparent objects are translucent --- light is transmitted diffusely in all directions through the material –translucent materials make the object viewed through them blurry

Transparent/Translucent surfaces Terminology index of refraction of a material –is defined to be the ratio of the speed of light in a vacuum to the speed of light in the material. Snell's Law is a relationship between angle of incidence and refraction and indices of refraction.

Transparent/Translucent surfaces To determine the direction of the refracted ray, the angle ( theta r ) off of -N, we need to know several things –the direction of the incoming ray, the angle ( theta i ) of incidence –the index of refraction (eta i ) of the material the ray is coming from –the index of refraction (eta r ) of the material the ray is entering

Transparent/Translucent surfaces Snell's law states that sin ( theta r ) eta i = sin ( theta i ) eta r which can be written as: sin ( theta r ) = ((eta i ) / (eta r )) * sin ( theta i )

Transparent/Translucent surfaces Assuming all of our vectors are unit vectors, using Snell's law, according to our textbook we can compute the unit refracted ray, T, to be T = (((eta i ) / (eta r )) cos ( theta r ) – cos ( theta r )) N – ((eta i ) / (eta r ))L See page 578 in our text. This assumes L is in the direction shown in the diagram of figure Verifying that the equation above is correct is left as an exercise to the reader. It may appear on a hw assignment.

Transparent/Translucent surfaces Table 10-1 on page 578 in our text shows average indices of refraction for common materials, such as Vacuum (1.0), Ordinary Crown Glass (1.52), Heavy Crown Glass (1.61), Ordinary Flint Glass (1.61), Heavy Flint Glass (1.92), Rock Salt (1.55), Quartz (1.54), Water (1.33), Ice (1.31) Different frequencies of light travel at different speeds through the same material. Therefore, each frequency has its own index of refraction. The indices of refraction above are averages.

Surface Rendering Now that we have an illumination model built, we can use it in different ways to do surface rendering aka shading.

Shading Models Constant shading (aka flat shading, aka faceted shading) is the simplest shading model. It is accurate when a polygon face of an object is not approximating a curved surface, all light sources are far and the viewer is far away from the object. Far meaning sufficiently far enough away that N L and R V are constant across the polygon. If we use constant shading but the light and viewer are not sufficiently far enough away then we need to choose a value for each of the dot products and apply it to the whole surface. This calculation is usually done on the centroid of the polygon. Advantages: fast & simple Disadvantages: inaccurate shading if the assumptions are not met.

Shading Models Interpolated shading model –Assume we're shading a polygon. The shading is interpolated linearly. That is, we calculate a value at two points and interpolate between them to get the value at the points in between --- this saves lots of computation (over computing at each position) and results in a visual improvement over flat shading. –This technique was created for triangles e.g. compute the color at the three vertices and interpolate to get the edge colors and then interpolate across the triangle's surface from edge to edge to get the interior colors. –Gouraud shading is an interpolation technique that is generalized to arbitrary polygons. Phong shading is another interpolation technique but doesn't interpolate intensities.

Shading Models Gouraud shading (aka Gouraud Surface Rendering) is a form of interpolated shading. –How to calculate the intensity at the vertices? we have normal vectors to all polygons so, consider all the polygons that meet at that vertex. Drawing on the board. Suppose for example, n polygons all meet at one vertex. We want to approximate the normal of the actual surface at the vertex. We have the normals to all n polygons that meet there. So, to approximate the normal to the vertex we take the average of all n polygon normals. What good is knowing the normal at the vertex? Why do we want to know that?

Shading Models Gouraud shading. –What good is knowing the normal at the vertex? Why do we want to know that? so we can calculate the intensity at that vertex from the illumination equations. –Calculate the intensity at each vertex using the normal we estimate there. –Then linearly interpolate the intensity along the edges between the vertices. –Then linearly interpolate the intensity along a scan line for the intensities of interior points of the polygon. –Example on the board.

Shading Models Advantages: easy to implement if already doing a scan line algorithm. Disadvantages: –Unrealistic if the polygon doesn't accurately represent the object. This is typical with polygon meshes representing curved surfaces. –Mach banding problem when there are discontinuities in intensities at polygon edges, we can sometimes get this unfortunate effect. let's see an example. –The shading of the polygon depends on its orientation. If it rotates, we will see an unwanted effect due to the interpolation along a scanline. Example on board. –Specular reflection is also averaged over polygons and therefore doesn't accurately show these reflections.

Shading Models Phong shading (aka Phong Surface Rendering). –Assume we are using a polygon mesh to estimate a surface. –Compute the normals at the vertices like we did for Gouraud. –Then instead of computing the intensity (color) at the vertices and interpolating the intensities, we interpolate the normals. –So, given normals at two points of a polygon, we interpolate over the surface to estimate the normals between the two points. –Example picture on the board. –Then we have to apply the illumination equation at all the points in between to compute intensity. We didn't have to do this for Gouraud. –Problems arise since the interpolation is done in the 3d world space and the pixel intensities are in the image space.

Shading Models Recap –Flat Shading –Gouraud Shading --- interpolates intensities –Phong Shading --- interpolates normal vectors (before calculating illumination.) –For these three methods, as speed/efficiency decreases, realism increases (as you'd expect.) –They all have the problem of silhouetting. Edges of polygons on the visual edge of an object are apparent. –Let's see examples of Gouraud and Phong shading.

Game plan Since your fourth programming assignment is to implement a raytracer I will cover ray tracing next Other topics for the remainder of the semester will be –ray tracing –texture mapping & bump mapping –radiosity –3d model representations –parametric curves mathematical representation of surfaces as opposed to polygon mesh approximations.

Ray Casting Recall Ray Casting which we discussed recently in our topic of Visible Surface Determination. To determine which surface is visible at a pixel, draw a ray starting at the CoP/PRP/eye through the center of the pixel and determine which surface it hits first. This method could be used to determine the color of the pixel with any of the illumination models discussed.

Ray Tracing Ray Tracing is a generalization of Ray Casting. Ray tracing is an image generation method that determines the color of a pixel in the image by –tracing a ray from the eye (CoP/PRP) through the center of the pixel and out into the world –determining if the ray intersect any surfaces –if it does, consider only the closest surface. –then bounce the ray off this surface one ray each in the direction of the light sources one reflected ray (if surface is specularly reflective) one refracted ray (if surface is transparent/translucent)

Ray Tracing then bounce the ray off this surface one ray each in the direction of the light sources one reflected ray (if surface is specularly reflective) one refracted ray (if surface is transparent/translucent) The rays that are in the direction of each of the light sources are called Shadow Rays. If a shadow ray directly hits a light source without first hitting another object then that light influences the color of the surface at that point. The reflected ray is bounced off the object at the angle it makes with the normal vector at the intersection, but on the other side of it (like we saw in the illumination model discussion of specular reflection.) The refracted ray is transmitted through the surface according to Snell's law which we recently covered.

Ray Tracing Further, the reflected ray and the refracted ray may also recursively generate shadow, reflected and refracted rays. –terminate a path (the bounces) when a ray doesn't intersect a reflective/refractive surface or when we hit the maximum levels of recursion that we specify This ray tracing is done for each pixel in the image!

Ray Tracing The image on the next slide shows the original ray from the eye through a pixel and out into the world. It intersects with an object (the pyramid) and only the reflected rays are shown. A more accurate picture to depict ray tracing would show the shadow rays, and the refracted rays (if any).

Ray Tracing The original ray and it's reflected and refracted rays, and those reflected and refracted rays' reflected and refracted rays and so on can form a tree. Example of this tree on the next slide. Each node in the tree also has shadow rays (but they are not edges in the tree, since they cannot spawn further rays and they are treated differently.) The shadow rays are used to calculate the color/shading of the point on the surface (both the diffuse and specular components.) –If a shadow ray does not reach a light source (that is, an object is in the way) then the point we're determining the color of is in the shadow of that light. The reflected ray and refracted ray are used for determining ambient and transparent illumination of the point, respectively.

Ray Tracing From the description thusfar of ray tracing, it should be obvious that it often needs to –determine if a ray intersects with anything –and if so, where does it intersect Ray Tracing is time consuming / computationally expensive. We would like to have efficient methods to –determine if a ray intersects with anything –compute intersection points Since spheres are among the simplest shapes to ray trace, we'll discuss how to determine intersections between a ray and a sphere first. Then cover ray-polygon intersection calculations.

Ray Tracing After we discuss intersection calculations, we'll cover (again) how to compute the reflection ray and the refraction ray, given an incident ray. I'll provide a handout with psuedocode for a ray tracing algorithm.

Ray / Sphere Intersection A sphere with radius r and center point P c, the points P on the surface satisfy the equation: |P – P c | 2 – r 2 = 0 If P = (x,y,z) and P c = (x c,y c,z c ) then we can rewrite this as (x – x c ) 2 + (y – y c ) 2 + (z – z c ) 2 – r 2 = 0

Ray / Sphere Intersection A ray is a “line” starting at some point and continuing out to infinity. P(s) = P 0 + R d s where P 0 is the starting point of the ray, R d is a unit directional vector and s is the parameter which represents the distance from P 0 If P = (x,y,z) and P 0 = (x 0, y 0, z 0 ) and R d = (x d, y d, z d ) this ray equation can be rewritten as 3 equations like so: x = x 0 + x d s y = y 0 + y d s z = z 0 + z d s

Ray / Sphere Intersection Substitute the ray equation into the sphere equation to find the value for s (the distance along the ray where the intersection occurs). (x 0 + x d s – x c ) 2 + (y 0 + y d s – y c ) 2 + (z 0 + z d s – z c ) 2 – r 2 = 0 This ends up being a quadratic equation of the form C 2 s 2 + C 1 s + C 0 = 0 where C 2 = x d 2 + y d 2 + z d 2 = 1 C 1 = – 2 ( R d (Pc – P0)) C 0 = |(Pc – P0)| 2 – r 2 To compute s, use the quadratic formula

Ray / Sphere Intersection This ends up being a quadratic equation of the form C 2 s 2 + C 1 s + C 0 = 0 Solve for s: s = (-C 1 +/- srqt(C 1 2 – 4C 2 C 0 ) ) / 2C 2 but C 2 = 1, so s = (-C 1 +/- srqt(C 1 2 – 4C 0 ) ) / 2

Ray / Sphere Intersection A sphere and a ray can intersect/not intersect in several distinct cases If the discriminant is negative –the ray does not intersect the sphere If the discriminant is 0, then the ray is tangent to the sphere. If the discriminant is positive choose the smaller positive value for s of the 2 computed from the quadratic formula. Compute the intersection point based on s. For efficiency we can precompute some of the values, like r 2 etc. There may also be problems with rounding error which will show up when s is computed to be very small. We may not get the correct intersection. Examples on the board of possible cases of ray / sphere intersection. –2 +, 2 -, 1 +/1 - (inside), 1+ (tangent), 0

Ray / Plane Intersection Calculating a plane and a ray intersection is the first step in calculating a polygon and a ray intersection. So, let's discuss this process first.

Ray Equation again A ray is a “line” starting at some point and continuing out to infinity. P(s) = P 0 + R d s where P 0 is the starting point of the ray, R d is a unit directional vector and s is the parameter which represents the distance from P 0 If P = (x,y,z) and P 0 = (x 0, y 0, z 0 ) and R d = (x d, y d, z d ) this ray equation can be rewritten as 3 equations like so: x = x 0 + x d s y = y 0 + y d s z = z 0 + z d s

Ray / Plane Intersection The plane equation, as we've seen before is Ax + By + Cz + D = 0 Normal vector N = [A,B,C] We can get the equation of the plane to have [A,B,C] be a unit vector (magnitude 1). How could we do that? Then A 2 + B 2 + C 2 = 1

Ray / Plane Intersection Substitute the ray equation into the plane equation to find the value for s (the distance along the ray where the intersection occurs). A(x 0 + x d s) + B(y 0 + y d s) + C(z 0 + z d s) + D = 0 Solve for s on the board. This will work out to be s = - (N P 0 + D) / (N R d ) Let's see some possible situations on the board. –(ray/plane parallel (N R d )=0), –s > 0, when intersection is in front of P 0 –s < 0, when intersection is behind P 0