CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Advertisements

Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Intersection Testing Chapter 13 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
Collision Detection CSCE /60 What is Collision Detection?  Given two geometric objects, determine if they overlap.  Typically, at least one of.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 07 / 2007 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.
CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.
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.
CS 376b Introduction to Computer Vision 04 / 15 / 2008 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.
CS 376b Introduction to Computer Vision 03 / 04 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing.
CS 376 Introduction to Computer Graphics 04 / 04 / 2007 Instructor: Michael Eckmann.
CSE 681 Object Intersection. CSE 681 Object Representation Implicit forms F(x,y,z) = 0 Explicit forms Analytic form x = F(y,z) testing generating Parametric.
CS 206 Introduction to Computer Science II 02 / 25 / 2009 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Week 13 - Wednesday CS361.
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
COMP 175: Computer Graphics March 24, 2015
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
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 325 Introduction to Computer Graphics 02 / 01 / 2010 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.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.
CS 376b Introduction to Computer Vision 02 / 22 / 2008 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,
CS 376 Introduction to Computer Graphics 04 / 20 / 2007 Instructor: Michael Eckmann.
CS 376b Introduction to Computer Vision 03 / 21 / 2008 Instructor: Michael Eckmann.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
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.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
CS 325 Introduction to Computer Graphics 02 / 26 / 2010 Instructor: Michael Eckmann.
1 Dr. Scott Schaefer Intersecting Simple Surfaces.
Basic Ray Tracing CMSC 435/634.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
CS 376b Introduction to Computer Vision 03 / 18 / 2008 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
Ray Tracing Optimizations
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.
CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann.
CSE 681 Object Intersection. CSE 681 Object Representation Implicit forms F(x,y,z) = 0 Explicit forms Analytic form x = F(y,z) testing generating Parametric.
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 CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Intersecting Simple Surfaces
Presentation transcript:

CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Spring 2010 Today’s Topics Questions? Reducing Intersection calculations (betweens Rays and Spheres) in ray tracing Review Intersection of Rays w/ polygons

Reducing Intersection calcs Our text says that ray-object intersection calculations can make up up-to 95% of the processing time of the ray tracer. Reducing this would obviously be worth the effort.

Reducing Intersection calcs enclose objects that are near each other within a bounding volume (e.g. a sphere, a cube, etc.)‏ do this for all the clusters of objects that are in your world then when testing for ray object intersections, first determine which bounding volumes the ray intersects with then only among the objects in those bounding volumes that the ray intersects with do we try to compute the ray-object intersection –all the objects in all the bounding volumes that do not intersect the ray can be ignored picture on the board

Reducing Intersection calcs Space subdivision methods –picture the world in a large cube which is subdivided into smaller cubes cubes that contain surfaces can be subdivided into 8 smaller cubes can do this until you get some programmer-defined maximum numbers of allowable surfaces inside a cube –can store these cubes in a binary partition tree or octtree --- so we can efficiently process the cubes –shoot a ray and find out which small cube it first intersects with if the cube doesn't contain any surfaces continue down the ray to find the next cube it hits and so on if there are surface(s) inside the cube determine if there's an intersection if so, that's the one we use; if not, continue with next cube... picture on the board

Reducing Intersection calcs smaller maximum number of surfaces per cube implies less ray-object intersection calculations however, this leads to an increase in the number of cubes which increases the calculation to determine the ray path through the cubes

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 Let's find the intersection of P(s) with a sphere with radius r and center point P c.

Ray / Sphere Intersection Earlier we saw an algebraic solution to the ray-sphere intersection. Here (with the accompanying drawings on the board) is a geometric solution that allows you to find out earlier in the computations if the ray and sphere do not intersect (thereby reducing unneeded computations.)‏ 1. Determine if the ray's origin (P 0 ) is outside or inside of the sphere by: P 0 P c = P c – P 0. If the length squared of P 0 P c < r 2 then P 0 is inside sphere (skip to step 4)‏ otherwise the it is outside the sphere and we continue onto step Find the length L, of the ray from P 0 to the point on the ray that is closest to the center of the sphere. Notice |R d | = 1, so we can multiply by it... L = | P 0 P c | cosA = |P 0 P c | |R d | cosA = P 0 P c R d If L < 0, then ray does not intersect with the sphere, done. Otherwise go to step 3.

Ray / Sphere Intersection 3. Find the square of the distance, E 2 from the point on the ray that is closest to the center of the sphere to the intersection of the the ray with the sphere. From pythagorean theorem, r 2 = E 2 + D 2 so E 2 = r 2 – D 2 Also from pythagorean theorem, D 2 = |P 0 P c | 2 – L 2 So, E 2 = r 2 – (|P 0 P c | 2 – L 2 )‏ If E 2 < 0, ray does not intersect the sphere, done. Otherwise go to step Find s, the parameter of the intersection to use for the ray equation P(s) = P 0 + R d s If ray originates outside the sphere then s = L – E If ray originates inside the sphere then s = L + E 5. Calculate the intersection using s from step 4, (x i, y i, z i ) = P 0 + R d s

Ray / Sphere Intersection 6. Calculate the normal vector at the intersection If ray's origin was outside the sphere, N = [(x i -x c )/r, (y i -y c )/r, (z i -z c )/r] If inside the sphere, N = [(x c -x i )/r, (y c -y i )/r, (z c -z i )/r] (this procedure is based on Drew Kessler's notes from Lehigh, 1999)‏

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.)‏ It gives us a polygon in 2d with the largest area of the 3 choices.

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 next algorithm distinguishes between several different situations to determine when to add 1 to the number of times the polygon's edges cross the positive u axis. For some edge –1) if the signs of the v coordinate in both vertices are the same, then that edge DOES NOT cross the positive u-axis –2) if the signs of the v coordinate in both vertices are different AND both u coordinates are positive then that edge DOES cross the positive u-axis. –3) if the signs of the v coordinate in both vertices are different AND one of the u coordinates is positive then compute the intersection of the line with v=0. If the u coordinate of this intersection is positive then that edge DOES cross the positive u-axis. –4) if the signs of the v coordinate in both vertices are different AND one of the u coordinates is positive then compute the intersection of the line with v=0. If the u coordinate of this intersection is not positive then that edge DOES NOT cross the positive u-axis. –For cases 2 and 3 above, add 1 to a counter. Do this for all edges in the polygon in order and then check the value of the counter --- if it is odd then the point is in the interior of the polygon and hence the ray intersects with the polygon.

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