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

Slides:



Advertisements
Similar presentations
GR2 Advanced Computer Graphics AGR
Advertisements

13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Ray Tracing & Radiosity Dr. Amy H. Zhang. Outline  Ray tracing  Radiosity.
May Visible Surface Detection Shmuel Wimer Bar Ilan Univ., Eng. Faculty Technion, EE Faculty.
Light Issues in Computer Graphics Presented by Saleema Amershi.
Light: Geometric Optics
Illumination Model & Surface-rendering Method 박 경 와.
CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 09 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 24 / 2010 Instructor: Michael Eckmann.
CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product.
CS 376 Introduction to Computer Graphics 03 / 26 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.
1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok
CS 376 Introduction to Computer Graphics 03 / 30 / 2007 Instructor: Michael Eckmann.
CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing.
Ray Tracing 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
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.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
© 2005 Pearson Prentice Hall This work is protected by United States copyright laws and is provided solely for the use of instructors in teaching their.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
Computer graphics & visualization Ray-Tracing – A Quick review.
COMP 175: Computer Graphics March 24, 2015
12/05/02(c) 2002 University of Wisconsin Last Time Subdivision techniques for modeling Very brief intro to global illumination.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 11 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 16 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
CS447/ Realistic Rendering -- Radiosity Methods-- Introduction to 2D and 3D Computer Graphics.
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
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.
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
CS 376 Introduction to Computer Graphics 04 / 20 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 24 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 14 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 22 / 2010 Instructor: Michael Eckmann.
1 Dr. Scott Schaefer Intersecting Simple Surfaces.
04/30/02(c) 2002 University of Wisconsin Last Time Subdivision techniques for modeling We are now all done with modeling, the standard hardware pipeline.
Basic Ray Tracing CMSC 435/634.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 02 / 2007 Instructor: Michael Eckmann.
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
CSCE 441: Computer Graphics Ray Tracing
In the name of God Computer Graphics. Last Time Some techniques for modeling Today Global illumination and raytracing.
CS 551/651: Advanced Computer Graphics
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
RENDERING : Global Illumination
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.
CS 376 Introduction to Computer Graphics 02 / 21 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 07 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
Ray Tracing I. Reading Hill, Chapter 14, Sections 14.1 to 14.5 Hill, Chapter 14, Sections and
CS 376 Introduction to Computer Graphics 04 / 13 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 18 / 2007 Instructor: Michael Eckmann.
Basic Ray Tracing CMSC 435/634.
CS G140 Graduate Computer Graphics
GR2 Advanced Computer Graphics AGR
Presentation transcript:

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

Michael Eckmann - Skidmore College - CS Spring 2007 Today’s Topics Questions? Raytracing –how it works generally –computing the intersection of a ray and a sphere –computing the intersection of a ray and a plane –computing the intersection of a ray and a polygon

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 the reflected ray at each intersection is shown. It does show one refracted ray in the pyramid. Apparently the sphere and the cube in the picture are not translucent/transparent. A more accurate picture depicting the rays involved with ray tracing would additionally show the shadow rays.

Ray Tracing The original ray and its 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 (P c – P 0 )) C 0 = |(P c – P 0 )| 2 – r 2 To compute s, use the quadratic formula

Ray / Sphere Intersection Quadratic formula for ax 2 + bx + c = 0 is -b +/- sqrt(b 2 – 4ac) x = a

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 –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. (Why smaller positive?) Compute the intersection point P I = (x I, y I, z I ) based on s which is (x 0 + x d s, y 0 + y d s, z 0 + z d s)

Ray / Sphere Intersection 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 / Sphere Intersection The normal to the sphere at the intersection point is to be used for illumination of that point and the further computation of rays (reflected and refracted). If the ray's starting point is inside the sphere, then we want to use the direction of the normal at the intersection towards the center of the sphere (that makes us use the inside of the sphere that the ray hits). Compute the unit normal to the sphere at the intersection P I = (x I, y I, z I ) to be: N = [(x I -x c )/r, (y I -y c )/r, (z I -z c )/r] Just use the negation of N, if the ray starts inside the sphere.

Ray / Sphere Intersection There are several things we can do to increase efficiency that we will cover later –for instance, we should be able to figure out that a sphere and a ray do not intersect without having to go through the whole process just described.

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 The ray equation again is: 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 What do you think we do next?

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 ) Compute the intersection point based on s which is (x 0 + x d s, y 0 + y d s, z 0 + z d s)

Ray / Plane Intersection The normal to the plane at the intersection point is to be used for illumination of that point and the further computation of rays (reflected and refracted). The normal to the plane at the intersection that we need to use is the one that points towards the side that the ray came from (that makes us use the side of the plane that the ray hits). Example on board. You already have a unit plane normal N = [A,B,C]. To determine if it is the correct one to use, just check the sign of (N R d ). –if (N R d ) < 0 then keep N as is –if (N R d ) > 0 then negate N to be [-A, -B, -C]

Ray / Plane Intersection Let's see some possible situations on the board. –(ray/plane parallel (N R d )=0), –(N R d ) < 0 ( keep N as is ) –(N R d ) > 0 ( negate N ) –s > 0, (ray does intersect) –s < 0, (ray doesn't intersect)

Ray / Polygon Intersection The first step in Ray/Polygon intersection is to compute the intersection of the ray with the plane that the polygon lives on. At this point we have –the plane equation Ax+By+Cz+D = 0 –the point of intersection P I = (x I, y I, z I ) of the ray and plane –the vertices V = (x j, y j, z j ) of the polygon on that plane A technique that makes computation easier at this point is to orthographically project the polygon onto either the x-y, y-z, or z-x plane. To do this we just have to ignore the same coordinate of all of the vertices of the polygon and we end up with 2d points. The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.)

Ray / Polygon Intersection The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.) Why do you think this would be the best one to ignore?

Ray / Polygon Intersection The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.) Why do you think this would be the best one to ignore? –it gives us a polygon in 2d with the largest area of the 3 choices –Why is the largest one best?

Ray / Polygon Intersection Note: this technique is a combination of ideas from –Computer Graphics Principles and Practive by Foley, Van Dam, Feiner and Hughes, 1996 Addison-Wesley –Dr. G. Drew Kessler's csc313 course 1999, Lehigh Univ. and –Dr. Xiaoyu Zhang's Advanced Computer Graphics & Visualization page Example: If the plane equation is –0.2 x +0.4 y – z +5 = 0 we would orthographically project the polygon onto the x-y plane (ignore the z coordinate of each vertex) This will yield the largest (area) projection. Once we have done this projection, we can translate the intersection point P I to the origin of this new 2d space (call it u-v coordinates). Then determine whether the origin is inside or outside the polygon by counting the number of polygon edge crossings with the positive u axis.

Ray / Polygon Intersection The n vertices of the polygon are (u i, v i ) where i goes from 0 to n-1. Pseudocode to determine if the origin is inside the polygon initialize numCross to 0 if v 0 > 0 then signHold1 = +1 else signHold1 = -1 for each edge (u a, v a ) to (u b, v b ) { if v b > 0, signHold2 = +1, else signHold2 = -1 if signHold1 != signHold2 { if u a and u b are both > 0, then numCross++ if one of u a or u b is > 0, then { if (crossPosUAxis(u a, v a, u b, v b ) then numCross++ } } signHold1 = signHold2 } if numCross is odd, then the ray and polygon intersect

Ray / Polygon Intersection pseudocode for crossPosUAxis recall the parametric equations of a line: u = u b + (u a - u b )t v = v b + (v a - v b )t = 0 (because we're looking for intersection with u axis) so, use the second equation to solve for t then solve the first for u and get u = (u b + ( u a - u b ) * ( v b / (v b -v a ) ) ) crossPosUAxis(u a, v a, u b, v b ) if ( (u b + ( u a - u b ) * ( v b / (v b -v a ) ) ) > 0 ) return true else return false