CS770/870 Spring 2017 Ray Tracing Implementation

Similar documents
1.5 Equations of Lines and Planes in 3-D

Geometric Queries for Ray Tracing

Computer Graphics Ray Casting. Matthias Teschner

CS348B Lecture 2 Pat Hanrahan, Spring Greeks: Do light rays proceed from the eye to the light, or from the light to the eye?

Intro to Modeling Modeling in 3D

1.5 Equations of Lines and Planes in 3-D

Ray scene intersections

Curves and Surfaces Computer Graphics I Lecture 10

Homework #2. Shading, Projections, Texture Mapping, Ray Tracing, and Bezier Curves

Curve and Surface Basics

True/False. MATH 1C: SAMPLE EXAM 1 c Jeffrey A. Anderson ANSWER KEY

Background for Surface Integration

1999, Denis Zorin. Ray tracing

Lines and Planes in 3D

Lecture 25 of 41. Spatial Sorting: Binary Space Partitioning Quadtrees & Octrees

Outcomes List for Math Multivariable Calculus (9 th edition of text) Spring

Vectors and the Geometry of Space

Functions of Several Variables

9. Three Dimensional Object Representations

Curves and Surfaces Computer Graphics I Lecture 9

The Three Dimensional Coordinate System

Surfaces. Ron Goldman Department of Computer Science Rice University

Ray Tracing. Shandong University

MAT175 Overview and Sample Problems

Supplement to Lecture 16

COMPUTER AIDED ENGINEERING DESIGN (BFF2612)

GEOMETRIC TOOLS FOR COMPUTER GRAPHICS

Directional Derivatives. Directional Derivatives. Directional Derivatives. Directional Derivatives. Directional Derivatives. Directional Derivatives

Ray casting. Ray casting/ray tracing

Accelerating Geometric Queries. Computer Graphics CMU /15-662, Fall 2016

Practice problems from old exams for math 233 William H. Meeks III December 21, 2009

8.1 Geometric Queries for Ray Tracing

14.6 Directional Derivatives and the Gradient Vector

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

Lagrange Multipliers. Lagrange Multipliers. Lagrange Multipliers. Lagrange Multipliers. Lagrange Multipliers. Lagrange Multipliers

Implicit Surfaces & Solid Representations COS 426

Ray Tracing I. History

SUMMARY. CS380: Introduction to Computer Graphics Ray tracing Chapter 20. Min H. Kim KAIST School of Computing 18/05/29. Modeling

Lecture 11: Ray tracing (cont.)

Intersecting Simple Surfaces. Dr. Scott Schaefer

Second degree equations - quadratics. nonparametric: x 2 + y 2 + z 2 = r 2

1 EquationsofLinesandPlanesin 3-D

9. Visible-Surface Detection Methods

Answer Key: Three-Dimensional Cross Sections

Intro to Curves Week 1, Lecture 2

Illumination Models III: Ray Tracing (View Dependent Global Illumination)

Homework #2. Hidden Surfaces, Projections, Shading and Texture, Ray Tracing, and Parametric Curves

Polygon Meshes and Implicit Surfaces

Polygon Meshes and Implicit Surfaces

Sung-Eui Yoon ( 윤성의 )

ds dt ds 1 dt 1 dt v v v dt ds and the normal vector is given by N

Advanced 3D-Data Structures

while its direction is given by the right hand rule: point fingers of the right hand in a 1 a 2 a 3 b 1 b 2 b 3 A B = det i j k

Questions??? Announcements Assignment 3 due today

Ray Tracing. Foley & Van Dam, Chapters 15 and 16

Ray Tracing Foley & Van Dam, Chapters 15 and 16

Implicit Generalized Cylinders using Profile Curves

Curves and Surface I. Angel Ch.10

11/1/13. Polygon Meshes and Implicit Surfaces. Shape Representations. Polygon Models in OpenGL. Modeling Complex Shapes

Shape Representation Basic problem We make pictures of things How do we describe those things? Many of those things are shapes Other things include

3D Rendering and Ray Casting

Ray Casting. 3D Rendering. Ray Casting. Ray Casting. Ray Casting. Ray Casting

CS 536 Computer Graphics Intro to Curves Week 1, Lecture 2

The goal is the definition of points with numbers and primitives with equations or functions. The definition of points with numbers requires a

An introduction to interpolation and splines

First of all, we need to know what it means for a parameterize curve to be differentiable. FACT:

Ray tracing idea. Ray Tracing. Ray tracing algorithm. Plane projection in drawing. CS 465 Lecture 3

Ray Tracer I: Ray Casting Due date: 12:00pm December 3, 2001

3D Rendering and Ray Casting

Central issues in modelling

From Vertices To Fragments-1

Topics and things to know about them:

Equation of tangent plane: for implicitly defined surfaces section 12.9

Spatial Data Structures

Ray Tracing COMP575/COMP770

Reading. Parametric surfaces. Surfaces of revolution. Mathematical surface representations. Required:

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Spatial Data Structures

Math 366 Lecture Notes Section 11.4 Geometry in Three Dimensions

CMSC427 Final Practice v2 Fall 2017

CS 563 Advanced Topics in Computer Graphics Lecture 2: Bare-Bones Raytracer. by Emmanuel Agu

Hidden Surface Elimination: BSP trees

CS 4620 Final Exam. (a) Is a circle C 0 continuous?

Geometric Modeling Mortenson Chapter 11. Complex Model Construction

Multi-level Partition of Unity Implicits

Measuring Lengths The First Fundamental Form

What you will learn today

Lecture 11. More Ray Casting/Tracing

Spatial Data Structures

TNM079 Modeling & Animation Lecture 6 (Implicit surfaces)

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

Quadric Surfaces. Philippe B. Laval. Spring 2012 KSU. Philippe B. Laval (KSU) Quadric Surfaces Spring /

Culling. Computer Graphics CSE 167 Lecture 12

Werner Purgathofer

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

Practice problems from old exams for math 233

CS3621 Midterm Solution (Fall 2005) 150 points

Point Cloud Filtering using Ray Casting by Eric Jensen 2012 The Basic Methodology

521493S Computer Graphics Exercise 2 Solution (Chapters 4-5)

Notes on Spherical Geometry

Transcription:

Useful ector Information S770/870 Spring 07 Ray Tracing Implementation Related material:angel 6e: h.3 Ray-Object intersections Spheres Plane/Polygon Box/Slab/Polyhedron Quadric surfaces Other implicit/explicit surfaces ector calculus is helpful notation in ray tracing dot product (also called inner product) Let U = (u x, u y, u z ) and = (v x, v y, v z ) U U = a x * b x a y * b y a z * b z U = U cos α, where α is angle between U and where U is the length of U U / scalar (orthogonal) projection of U onto U cos α = U / scalar (orthogonal) projection of onto U cos α = U / U α U / U 03/0/7 Ray-Sphere Definitions Ray/Sphere Intersection Equation Implicit representation of a sphere of radius, r, and center = ( x c, y c, z c ): ( x - x c ) ( y - y c ) ( z - z c Parametric representation of a ray R(t) = t for t > 0 where = ( x o, y o, z o ) is the ray origin and = ( x v, y v, z v ) is the ray direction as a unit vector This is really 3 equations: x(t) = x o t x v y(t) = y o t y v z(t) = z o t z v Start with sphere equation, with center at origin x y z = r Replace x, y, and z with x(t), y(t), z(t) of ray (x o tx v ) (y o ty v ) (z o tz v Expand the square terms (x v t x v x 0 t x 0 ) (y v t y v y 0 t y 0 ) (z v t z v z 0 t z 0 ) = r ollect like terms (powers of t): at bt c = 0 a = x v y v z v = ( is a unit vector) This simplifies calculations! b = (x o )x v (y o )y v (z o )z v c = (x o ) (y o ) (z o ) r 3 4

Solve quadratic equation Get 0, or solutions: b -4c <0 : 0 intersections t = b b -4c =0 : intersection, ray is tangent to sphere; ignore b 4c t < 0 and t < 0 : on wrong side of ray, ignore t < 0 and t >0 : use t t >0 and t >0 : use t ; it has to be smaller Remember the quadratic equation?, t = b b 4c a= in this case Ray/Arbitrary Sphere Intersection Start with sphere equation for center at (x c, y c, z c ) (x ) (y ) (z Replace x, y, and z with x(t), y(t), z(t) of ray ((x o tx v ) ) ((y o ty v ) ) ((z o tz v ) Simplify terms by collecting constant expressions (tx v x o ) (ty v y o ) (tz v z o (tx v x d ) (ty v y d ) (tz v z d t where x d = x o, y d = y o and z d = z o b - 4c <= 0 t t t t t < 0, t > 0 t < 0, t < 0 t t > 0, t > 0 5 This is the same equation as sphere at origin with (x d, y d, z d ) replacing (x o, y o, z o ) 6 Efficiency Improvement Efficiency Improvement (cont) an we find miss cases more efficiently First find if is inside or outside the sphere if distance from to < r, then is inside sphere distance(, ) = ( ) ( ) But, no need to compute the square root is inside sphere if ( ) ( ) r < 0 But, ( ) ( ) = (x c x o ) (y c y o ) (z c z o ) r = c So is inside sphere if c < 0, for the c term of the quadratic equation. If is inside sphere, we know we have exactly intersection and it is t - If outside, find t c = closest point on ray to Project (- ) onto : (- ) = t c (- ) = -b/ the b from quadratic equation! t=0 If t c > 0, find d, distance from to ray L = t c d where L = R 0 = ( ) ( ) so, d = L t c = ( ) ( ) t c and d r > 0 means ray misses sphere or ( ) ( ) t c r > 0 means miss But c = ( ) ( ) r and t c = b ( ) for b and c from quadratic equation : so condition is c ( b ) > 0 c 4 b > 0 4c b > 0 b 4c 0 t c t c L t=0 - d 7 8

Efficiency Improvement (cont) Ray/Plane Intersections How does this help?. alculate c = (- ) (- )-r. alculate t c = (- ) 3. If c >0 and t c < 0, done; ray is outside and points away 4. alculate h = t c c = 4 b c 5. if h < 0, done, no int. 6. alculate h=sqrt(h ) 7. if c >0, outside: t = t c - h else if c <0, inside: t = t c h 8. Use t to get x,y,z If =(0,0,0), even simpler t c h L h d Ray: R(t) = t for t > 0 Plane (implicit) ax by cz d = 0 where a b c = ote: = ( a, b, c ) is unit normal to plane Substitute ray equations into plane equation a(x o tx v ) b(y o ty v ) c(z o tz v ) d = 0 Solve for t t = (ax o by o cz o d) ax v by v cz v = d ( ) - - t 9 0 Ray/Plane Intersections Steps Ray/Polygon Intersection. alculate v d =(-), == v d == 0 means ray is parallel to plane; no int. v d < 0 normal in opposite direction from ray; if have -sided polygons and back-face culling, done: polygon not visible!. alculate v o = (- )d 3. alculate t = v o / v d t < 0 : intersection behind ray, no int. 4. alculate (x,y,z) from ray equations. - - t. Find Ray/Plane intersection. Project polygon and point along one of major axes onto D plane. 3. Do D point-in-polygon test to determine if intersection point is inside polygon project

Point-in-Polygon Test Ray/Box Intersection. Project 3D polygon along one coordinate axis to xy or yz or xz plane. Which is best? want to avoid a thin projected polygon to maximize projected area, project along axis with maximum coefficient in plane equation: see D analogy on the right. D point-in-polygon draw horiz (or vert) line from projected intersection point to infinity; y=y int intersect y=y int with each edge (pretty simple!) count intersections with edges: odd inside be careful with vertex intersections D analogy x y - 4 = 0 x 3y - 6 = 0 Transform ray back to object space where box is oriented along major axes to origin and even to unit cube Intersect transformed ray with planes: x=0, x=, y=0, y=, z=0, z= Line/plane intersections are trivial; intersection of ray with x=0: x(t) = x o tx v // ray equation for x t 0 = (0 - x o ) / x v = -x o / x v // intersection with x=0 The t for x = is just one more addition t = ( - x o ) / x v = /x v - x o / x v = /x v t 0 3 4 Ray/Slab Intersection onvex Polyhedra Slabs are pairs of parallel planes; they are good for creating tighter bounding volumes Just two sides of a box and once get t for one slab, the t for parallel one is just one addition A polyhedron is a 3D object whose faces are planar Polyhedra can be defined by: the polygons that make up their faces the space defined by the intersection of the negative sides of all the planes that define the faces Polygon representation natural for polygon-based rendering hard to validate correctness: are there gaps between polygons? do any polygons intersect? etc. Planar representation relatively easy correctness computation hard to render (except with ray tracing) 5 6

Ray/Polyhedron Intersection Given a convex polyhedron defined by intersection of half-planes, find intersection of a ray with polyhedron: for each plane, H i P i = intersection of ray with H i if P i on - side of all other planes if is on side of H i return P i return null P 0 doesn t exist P is on side of other planes and R 0, is on side of H Good! P is on side of H, P 3 is on side of H 4, P 4 is on side of all, but R 0 is on side of H 4 H H 3 D analogy P P H 0 H H 4 P 4 P 3 7 Ray/Polyhedron Intersection - Basic algorithm has some weaknesses: If ray starts inside the polyhedron, it fails/ Easily fixed by first testing R0 against all planes; if it is on the side of all planes and changing innermost if test to: if ( is on side of H i ) or ( in polyhedron) return P i eeds extra code to recognize intersections with/near vertices, where the inside test for the other planes could be wrong due to round-off error Only works for convex polyhedra ote that the correctness of the polyhedron specification is not a problem for the rendering since a polyhedron with null volume just won t ever appear 8 Ray v. Quadric Surface Any quadric surface can be represented implicitly by " a b c d% " x% $ ' $ ' e f g h [ x y z ] $ ' $ y ' = 0 $ i j k l' $ z' $ ' $ ' # m n o p& # & Ray v. Generic Implicit Surfaces Ray intersections with implicit surfaces of degree > or non-polynomial surfaces are normally solved with numerical techniques Substitute the parametric equations for the ray into implicit equation and solve for t using the quadratic formula Just like a sphere, but much more algebra! 9 0

Ray vs. Explicit Surfaces SG Surfaces Suppose the surface is defined parametrically (in parameters): S(u,v) = [x(u,v), y(u,v), z(u,v)] an make some progress by representing the ray as the intersection of any two planes that share it: a x b y c z d = 0 a x b y c z d = 0 Intersection of planes an surface yields curves in D: (u,v) = a x(u,v) b y(u,v) c z(u,v) d = 0 (u,v) = a x(u,v) b y(u,v) c z(u,v) d = 0 Use numerical techniques in D to solve intersection in (u,v) space v u onstructive Solid Geometry Define objects as union, intersection or set difference between basic shapes, like parallelopiped and cylinders = Effective representation for analysis validity of representation, many physical properties are easily computed, and much more ot very efficient for rendering purposes, except with ray tracing Ray v. SG Other Kinds of Surfaces Given a SG tree Do a postfix tree walk: for each leaf compute ray/solid intersection in t // each primitive has 0 or ints t t for each operator combine ray classification of its children and simplify by merging B D E left child right child L R L R L R Sweep surfaces specialized algorithms exist for some specific kinds of swept objects and paths. Procedural objects parametric surfaces can be treated as procedural using subdivision techniques Fractal surfaces some can be handled by subdivision techniques but, bounding volume test can be difficult Particle systems and other true procedural surfaces have very specialized intersections olume data based on voxels: not very hard olume data based on octrees: also not hard 3 4