1 Ray Casting. CLASS 1 Ray Casting 2 3 Overview of Today Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection.

Slides:



Advertisements
Similar presentations
Transformations in Ray Tracing MIT EECS 6.837, Durand and Cutler.
Advertisements

Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Announcements Project 2 due today Project 3 out today –demo session at the end of class.
3D Graphics Rendering and Terrain Modeling
Light Issues in Computer Graphics Presented by Saleema Amershi.
Christian Lauterbach COMP 770, 2/11/2009
MC930/MO603 Ray Casting. Light is bouncing photons.
CS6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003 Object-Order vs. Screen-Order Rendering April 24, 2003.
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
Now Playing: Melody Day Caribou from Andorra Released August 21, 2007.
CS485/685 Computer Vision Prof. George Bebis
Implicit Surfaces Tom Ouyang January 29, Outline Properties of Implicit Surfaces Polygonization Ways of generating implicit surfaces Applications.
Projective geometry Slides from Steve Seitz and Daniel DeMenthon
Parallelizing Raytracing Gillian Smith CMPE 220 February 19 th, 2008.
Global Illumination May 7, Global Effects translucent surface shadow multiple reflection.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 14: Ray Tracing
Ray Tracing Outline For each pixel { Shoot ray r from eye to center of pixel with trace( r ) } function trace( r ) For each object { Find object with closest.
1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok
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.
Advanced Computer Graphics (Fall 2010) CS 283, Lecture 2: Basic Ray Tracing Ravi Ramamoorthi Some slides courtesy.
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.
Week 13 - Wednesday CS361.
CSE 681 Ray Tracing Geometry. The Camera Model Based on a simpile pin-hole camera model –Simplest lens model –Pure geometric optics – based on similar.
Computer graphics & visualization Ray-Tracing – A Quick review.
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.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
Ray Tracing Chapter CAP4730: Computational Structures in 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.
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
Binary Space Partitioning Trees Ray Casting Depth Buffering
Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera Anthony Steed University College London.
Background Mathematics Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006.
Computer Graphics Zhen Jiang West Chester University.
Alex YAU Important Notes Website for Assignment #2 You.
Basic Ray Tracing CMSC 435/634.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Computer Graphics Lecture 08 Fasih ur Rehman. Last Class Ray Tracing.
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.
MIT EECS 6.837, Cutler and Durand 1 Ray Casting II.
Rendering Pipeline Fall, D Polygon Rendering Many applications use rendering of 3D polygons with direct illumination.
CSCE 441: Computer Graphics Ray Tracing
A Photograph of two papers
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Line Clipping & Line Rasterization.
CS 445 / 645 Introduction to Computer Graphics Lecture 16 Lighting Lighting.
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
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Ray Tracing I. Reading Hill, Chapter 14, Sections 14.1 to 14.5 Hill, Chapter 14, Sections and
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 / 18 / 2007 Instructor: Michael Eckmann.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Basic Ray Tracing CMSC 435/634.
Rendering Pipeline Fall, 2015.
MIT EECS 6.837, Cutler and Durand
CSCE 441 Computer Graphics 3-D Viewing
3D Graphics Rendering PPT By Ricardo Veguilla.
Ray Tracing Geometry CSE 681.
Ray Tracing Geometry CSE 681.
Merle Norman Cosmetics, Los Angeles
Ray Casting II MIT EECS Frédo Durand and Barb Cutler
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Presentation transcript:

1 Ray Casting

CLASS 1 Ray Casting 2

3 Overview of Today Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection

4 Ray Casting For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest

5 Shading For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Shade depending on light and normal vector

6 A Note on Shading Surface/Scene Characteristics: –surface normal –direction to light –viewpoint Material Properties –Diffuse (matte) –Specular (shiny) –… Much more soon! Diffuse sphereSpecular spheres N L V

7 Ray Tracing Secondary rays (shadows, reflection, refraction) In a couple of weeks reflection refraction

8 Ray Tracing

9 Ray Casting For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest Shade depending on light and normal vector N Finding the intersection and normal is the central part of ray casting

10 Ray Representation? Two vectors: –Origin –Direction (normalized is better) Parametric line –P(t) = origin + t * direction origin direction P(t)

11 Overview of Today Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection

12 Cameras For every pixel Construct a ray from the eye For every object in the scene Find intersection with ray Keep if closest

13 Pinhole Camera Box with a tiny hole Inverted image Similar triangles Perfect image if hole infinitely small Pure geometric optics No depth of field issue

14 Simplified Pinhole Camera Eye-image pyramid (frustum) Note that the distance/size of image are arbitrary

15 Camera Description? Eye point e (center) Orthobasis u, v, w (horizontal, up, -direction) Field of view angle Image rectangle height, width

16 Perspective vs. Orthographic Parallel projection No foreshortening No vanishing point perspectiveorthographic

MIT EECS 6.837, Durand 17 Orthographic Camera Ray Generation? –Origin = center + (x-0.5)*size*horizontal + (y-0.5)*size*up –Direction is constant

18 Other Weird Cameras E.g. fish eye, omnimax, panorama

19 Overview of Today Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection

MIT EECS 6.837, Durand 20 Ray Casting For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest First we will study ray-plane intersection

21 Recall: Ray Representation Parametric line P(t) = R o + t * R d Explicit representation RdRd RoRo origin direction P(t)

22 3D Plane Representation? Plane defined by –P o = (x,y,z) –n = (A,B,C) Implicit plane equation –H(P) = Ax+By+Cz+D = 0 = n·P + D = 0 Point-Plane distance? –If n is normalized, distance to plane, d = H(P) –d is the signed distance! H PoPo normal P P' H(p) = d < 0 H(p) = d > 0

23 Explicit vs. Implicit? Ray equation is explicit P(t) = R o + t * R d –Parametric –Generates points –Hard to verify that a point is on the ray Plane equation is implicit H(P) = n·P + D = 0 –Solution of an equation –Does not generate points –Verifies that a point is on the plane Exercise: Explicit plane and implicit ray

24 Ray-Plane Intersection Intersection means both are satisfied So, insert explicit equation of ray into implicit equation of plane & solve for t P(t) = R o + t * R d H(P) = n·P + D = 0 n·(R o + t * R d ) + D = 0 t = -(D + n·R o ) / n·R d P(t)

25 Additional Housekeeping Verify that intersection is closer than previous Verify that it is not out of range (behind eye) P(t) > t min P(t) < t current P(t)

26 Normal For shading –diffuse: dot product between light and normal Normal is constant normal

27 A moment of mathematical beauty Duality : points and planes are dual when you use homogeneous coordinates Point (x, y, z, 1) Plane (A, B, C, D) Plane equation  dot product You can map planes to points and points to planes in a dual space. Lots of cool equivalences –e.g. intersection of 3 planes define a point –  3 points define a plane!

CLASS 2 Ray Casting 28

29 Overview of Today Ray-Sphere Intersection Ray-Triangle Intersection Implementing CSG

30 Sphere Representation? Implicit sphere equation –Assume centered at origin (easy to translate) –H(P) = P·P - r 2 = 0 RdRd RoRo

31 Ray-Sphere Intersection Insert explicit equation of ray into implicit equation of sphere & solve for t P(t) = R o + t*R d H(P) = P·P - r 2 = 0 (R o + tR d ) · (R o + tR d ) - r 2 = 0 R d ·R d t 2 + 2R d ·R o t + R o ·R o - r 2 = 0 RdRd RoRo

32 Ray-Sphere Intersection Quadratic: at 2 + bt + c = 0 –a = 1 (remember, ||R d || = 1) –b = 2R d ·R o –c = R o ·R o – r 2 with discriminant and solutions

33 Ray-Sphere Intersection 3 cases, depending on the sign of b 2 – 4ac What do these cases correspond to? Which root (t+ or t-) should you choose? –Closest positive! (usually t-)

MIT EECS 6.837, Durand 34 Ray-Sphere Intersection It's so easy that all ray-tracing images have spheres!

MIT EECS 6.837, Durand 35 Geometric Ray-Sphere Intersection Shortcut / easy reject What geometric information is important? –Ray origin inside/outside sphere? –Closest point to ray from sphere origin? –Ray direction: pointing away from sphere?

MIT EECS 6.837, Durand 36 Geometric Ray-Sphere Intersection Is ray origin inside/outside/on sphere? –(R o ·R o r 2 / R o ·R o = r 2 ) –If origin on sphere, be careful about degeneracies… RoRo r O RdRd

37 Geometric Ray-Sphere Intersection Is ray origin inside/outside/on sphere? Find closest point to sphere center, t P = - R o · R d –If origin outside & t P < 0 → no hit RoRo O RdRd tPtP r

38 Geometric Ray-Sphere Intersection Is ray origin inside/outside/on sphere? Find closest point to sphere center, t P = - R o · R d. Find squared distance, d 2 = R o ·R o - t P 2 –If d 2 > r 2 → no hit RoRo O RdRd d tPtP r

MIT EECS 6.837, Durand 39 Geometric Ray-Sphere Intersection RoRo O RdRd d t t’t’ Is ray origin inside/outside/on sphere? Find closest point to sphere center, t P = - R o · R d. Find squared distance: d 2 = R o ·R o - t P 2 Find distance (t ’ ) from closest point (t P ) to correct intersection: t ’ 2 = r 2 - d 2 –If origin outside sphere → t = t P - t ’ –If origin inside sphere → t = t P + t ’ tPtP r

40 Geometric vs. Algebraic Algebraic is simple & generic Geometric is more efficient –Timely tests –In particular for rays outside and pointing away

41 Sphere Normal Simply Q/||Q|| –Q = P(t), intersection point –(for spheres centered at origin) Q normal RoRo O RdRd

42 Questions?

43 Overview of Today Ray-Sphere Intersection Ray-Triangle Intersection Implementing CSG

Ray-Triangle Intersection First, intersect ray with plane Then, check if point is inside triangle P P0P0 V

Ray-Triangle Intersection Check if point is inside triangle parametrically P P0P0 Compute  P =  (T 2 -T 1 ) +  (T 3 -T 1 ) Check if point inside triangle. 0   1 and 0   1  V   T1T1 T2T2 T3T3

46 Ray-Triangle Intersection Use general ray-polygon Or try to be smarter –Use barycentric coordinates RoRo RdRd c a b P

47 Barycentric Definition of a Plane P(  ) =  a +  b +  c with  =1 Is it explicit or implicit? [Möbius, 1827] c a b P P is the barycenter: the single point upon which the plane would balance if weights of size  are placed on points a, b, & c.

48 Barycentric Definition of a Triangle P(  ) =  a +  b +  c with  =1 AND 0 <  < 1 & 0 <  < 1 & 0 <  < 1 c a b P

49 How Do We Compute  Ratio of opposite sub-triangle area to total area –  = A a /A  = A b /A  = A c /A Use signed areas for points outside the triangle  c a b P AaAa A

50 Intuition Behind Area Formula P is barycenter of a and Q A a is the interpolation coefficient on aQ All points on lines parallel to bc have the same   All such triangles have same height/area) Q c a b P AaAa A

51 Simplify Since  =1, we can write  P(  ) =  a +  b +  c P(  ) =  a +  b +  c = a +  b-a) +  c-a) c a b P Non-orthogonal coordinate system of the plane rewrite

52 Intersection with Barycentric Triangle Set ray equation equal to barycentric equation P(t) = P(  ) R o + t * R d = a +  b-a) +  c-a) Intersection if  0 (and t > t min … ) RoRo RdRd c a b P

53 Intersection with Barycentric Triangle R o + t * R d = a +  b-a) +  c-a) R ox + tR dx = a x +  b x -a x ) +  c x -a x ) R oy + tR dy = a y +  b y -a y ) +  c y -a y ) R oz + tR dz = a z +  b z -a z ) +  c z -a z ) Regroup & write in matrix form: 3 equations, 3 unknowns      ozz oyy oxx dzzzzz dyyyyy dxxxxx Ra Ra Ra Rcaba Rcaba Rcaba                                t  

54 Cramer’s Rule A RRaba RRaba RRaba dzozzzz dyoyyyy dxoxxxx     A Racaba Racaba Racaba t ozzzzzz oyyyyyy oxxxxxx     A RcaRa RcaRa RcaRa dzzzozz dyyyoyy dxxxoxx     | | denotes the determinant Can be copied mechanically into code Used to solve for one variable at a time in system of equations

55 Advantages of Barycentric Intersection Efficient Stores no plane equation Get the barycentric coordinates for free –Useful for interpolation, texture mapping RoRo RdRd c a b P

56 Overview of Today Ray-Sphere Intersection Ray-Triangle Intersection Implementing CSG

MIT EECS 6.837, Durand 57 For example:

MIT EECS 6.837, Durand 58 How can we implement CSG? Union Intersection Subtraction Points on A, Outside of B Points on B, Outside of A Points on B, Inside of A Points on A, Inside of B

MIT EECS 6.837, Durand 59 Collect all the intersections Union Intersection Subtraction

MIT EECS 6.837, Durand 60 Implementing CSG 1.Test "inside" intersections: Find intersections with A, test if they are inside/outside B Find intersections with B, test if they are inside/outside A 2.Overlapping intervals: Find the intervals of "inside" along the ray for A and B Compute union/intersection/subtraction of the intervals

61 Precision What happens when –Origin is on an object? –Grazing rays? Problem with floating-point approximation

62 The evil  In ray tracing, do NOT report intersection for rays starting at the surface (no false positive) –Because secondary rays –Requires epsilons reflection refraction shadow

63 The evil  a hint of nightmare Edges in triangle meshes –Must report intersection (otherwise not watertight) –No false negative