Ray casting. Ray casting/ray tracing

Similar documents
1999, Denis Zorin. Ray tracing

Lecture 11. More Ray Casting/Tracing

Ray surface intersections

Loop Boundary - ignore edge vertex near boundary rule. use the same edge vertex rule. Deadline changed to Friday night(7/20) 11:59p Selection - extra

Quadric Surfaces. Philippe B. Laval. Today KSU. Philippe B. Laval (KSU) Quadric Surfaces Today 1 / 24

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

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

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

Ray Tracing Foley & Van Dam, Chapters 15 and 16

Section 12.2: Quadric Surfaces

Supplement to Lecture 16

Key Idea. It is not helpful to plot points to sketch a surface. Mainly we use traces and intercepts to sketch

4 = 1 which is an ellipse of major axis 2 and minor axis 2. Try the plane z = y2

Ray Tracing. CS334 Fall Daniel G. Aliaga Department of Computer Science Purdue University

What you will learn today

Ray Tracer Due date: April 27, 2011

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

Computer Graphics Ray Casting. Matthias Teschner

Geometric Queries for Ray Tracing

Functions of Several Variables

Lecture 11: Ray tracing (cont.)

3D Rendering and Ray Casting

Computer Graphics and Image Processing Ray Tracing I

3D Rendering and Ray Casting

Intersecting Simple Surfaces. Dr. Scott Schaefer

Surfaces. Ron Goldman Department of Computer Science Rice University

Chapter 15: Functions of Several Variables

12.6 Cylinders and Quadric Surfaces

1.6 Quadric Surfaces Brief review of Conic Sections 74 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. Figure 1.18: Parabola y = 2x 2

So far, we have considered only local models of illumination; they only account for incident light coming directly from the light sources.

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

Cylinders and Quadric Surfaces A cylinder is a three dimensional shape that is determined by

Photorealism: Ray Tracing

MAT175 Overview and Sample Problems

Quadric Surfaces. Six basic types of quadric surfaces: ellipsoid. cone. elliptic paraboloid. hyperboloid of one sheet. hyperboloid of two sheets

CS770/870 Spring 2017 Ray Tracing Implementation

Vectors and the Geometry of Space

Lecture 17: Recursive Ray Tracing. Where is the way where light dwelleth? Job 38:19

Recursive Ray Tracing. Ron Goldman Department of Computer Science Rice University

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

Ray Casting. Connelly Barnes CS 4810: Graphics

Introduction Ray tracing basics Advanced topics (shading) Advanced topics (geometry) Graphics 2010/2011, 4th quarter. Lecture 11: Ray tracing

ü 12.1 Vectors Students should read Sections of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

CPSC GLOBAL ILLUMINATION

Section 2.5. Functions and Surfaces

1.5 Equations of Lines and Planes in 3-D

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

Ray Tracing. Outline. Ray Tracing: History

From Vertices To Fragments-1

Questions??? Announcements Assignment 3 due today

Ray Tracing. Shandong University

Effects needed for Realism. Ray Tracing. Ray Tracing: History. Outline. Foundations of Computer Graphics (Spring 2012)

Ray Tracing I. Internet Raytracing Competition

Shading, Advanced Rendering. Week 7, Wed Feb 28

CSC418 / CSCD18 / CSC2504

Introduction to Visualization and Computer Graphics

Fog and Cloud Effects. Karl Smeltzer Alice Cao John Comstock

4.1 Rays, Lines, and Planes

Assignment 6: Ray Tracing

Quadric surface. Ellipsoid

Practice problems from old exams for math 233

8.1 Geometric Queries for Ray Tracing

Ray Tracing I. History

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

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

Last week. Machiraju/Zhang/Möller

Motivation. Sampling and Reconstruction of Visual Appearance. Effects needed for Realism. Ray Tracing. Outline

Computer Graphics. Si Lu. Fall uter_graphics.htm 11/22/2017

COMP environment mapping Mar. 12, r = 2n(n v) v

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

Unit 3 Functions of Several Variables

CS 4204 Computer Graphics

Computer Graphics. Ray Tracing. Based on slides by Dianna Xu, Bryn Mawr College

Intro to Modeling Modeling in 3D

CPSC / Texture Mapping

Solid Modeling. Michael Kazhdan ( /657) HB , FvDFH 12.1, 12.2, 12.6, 12.7 Marching Cubes, Lorensen et al.

TNM079 Modeling & Animation Lecture 6 (Implicit surfaces)

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

Implementation Issues

Computer Graphics. Lecture 9 Environment mapping, Mirroring

B.Stat / B.Math. Entrance Examination 2017

Ray Casting. Outline. Similar to glulookat derivation. Foundations of Computer Graphics

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Math 126C: Week 3 Review

Light: Geometric Optics

LIGHT. Speed of light Law of Reflection Refraction Snell s Law Mirrors Lenses

Dr. Allen Back. Aug. 27, 2014

COMP371 COMPUTER GRAPHICS

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Math (Spring 2009): Lecture 5 Planes. Parametric equations of curves and lines

MAT203 OVERVIEW OF CONTENTS AND SAMPLE PROBLEMS

Ray scene intersections

Chapter 6 Some Applications of the Integral

Optics Course (Phys 311) Geometrical Optics Refraction through Lenses

Raytracing. COSC 4328/5327 Scott A. King

Coordinate Transformations in Advanced Calculus

COMPLETION OF Z-buffer Graphics Pipeline

Texture. Texture Mapping. Texture Mapping. CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

Graphics 2009/2010, period 1. Lecture 8: ray tracing

Transcription:

Ray casting Ray casting/ray tracing Iterate over pixels, not objects Effects that are difficult with Z-buffer, are easy with ray tracing: shadows, reflections, transparency, procedural textures and objects Assume image plane is placed in the virtual space (eg front plane of the viewing frustum) Algorithm: for each pixel shoot a ray r from the camera to the pixel intersect with every object find closest intersection

Ray tracing For each pixel shoot a ray R from camera; pixel = TraceRay(R) The recursive ray tracing procedure: RGBvalue TraceRay(Ray R) shoot rays to all light sources; for all visible sources, compute RGB values r i shoot reflected ray R refl ; r refl =TraceRay(R refl ) shoot refracted ray R trans ;r trans = TraceRay(R trans ) compute resulting RGB value from r i, r refl, r trans using the lighting model Some primitives Finite primitives: polygons spheres, cylinders, cones parts of general quadrics Infinite primitives: planes infinite cylinders and cones general quadrics A finite primitive is often an intersection of an infinite with an area of space

Intersecting rays with objects General approach: Use whenever possible the implicit equation F(q) = 0 of the object or object parts Use parametric equation of the line of the ray, q = p+vt Solve the equation F(p+vt) = 0 to find possible values of t Find the minimal nonnegative value of t to get the intersection point (checking that t is nonegative is important: we want intersections with the ray starting from p, not with the whole line! Intersecting a line and a plane Same old trick: use the parametric equation for the line, implicit for the plane In the case of a pixel ray, b = p(i,j)-c c b n q i p ((c + bt i p) n) = 0 t i ((c p) n) = (b n) Check for zero in the denominator; t i should be positive for the intersection to be in front of the camera 3

Intersecting a ray with a sphere Sphere equation: (q-c) r = 0 For a ray q = p+ vt, we get ((p-c) + vt) r = 0 (p-c) + (p-c) v t + v +t r = 0 This quadratic equation in t may have no solutions (no intersection) or two (possibly coinciding) solutions (entry and exit points) The correct point to return is the one that is closest to ray origin General quadrics A general quadric has equation Ax + By + Cz + Dxy + Eyz + Fxz + Gx + Hy +Iz + J =0 Intersections with general quadrics are computed in a way similar to cones and cylinders: for a ray p+ v t, take x = p x + v x t, y = p y + v y t, y = p z + v z t, and solve the equation for t; if there are solutions, take the smaller nonnegative one Infinite cones and cylinders are special cases of general quadrics 4

General quadrics Nondegenerate quadrics Ellipsoid x /a + y /b +z /c + = 0 One-sheet hyperboloid x /a -y /b +z /c + = 0 Two-sheet hyperboloid x /a -y /b +z /c -= 0 General quadrics Nondegenerate quadrics Hyperbolic parabolid x /a -z /c - y= 0 Elliptic parabolid x /a +z /c - y= 0 cone x /a -y /b +z /c = 0 5

General quadrics Degenerate quadrics planes (no quadratic terms), pairs of parallel planes (eg x - = 0) pairs of intersecting planes ( eg x - = 0) elliptic cylinders (eg x +z -=0) hyperbolic cylinders (eg x -z -=0) parabolic cylinders (eg x -z = 0) Possible to get imaginary surfaces (that is, with no points)! Example: x + = 0 Polygon-ray intersections Two steps: intersect with the plane of the polygon check if the intersection point is inside the polygon We know how to compute intersections with the plane (see prev lecture) Let q=[q x,q y,q z ] be the intersection point q 6

Polygon-ray intersections Possible to do the whole calculation using 3d points, but it is more efficient to use d points Converting to the coordinates in the plane is computationally expensive Idea: project to a coordinate plane (XY, YZ, or XZ) by discarding one of the vector coordinates We cannot always discard, say, Z, because the polygon may project to an interval, if it is in a plane parallel to Z Choose the coordinate to discard so that the corresponding component of the normal to the polygon is maximal Eg if n x > n y and n x > n z, discard X D Polygon-ray intersections Now we can assume that all vertices v i and the intersection point q are D points v 4 v 3 q v v Assume that polygons are convex A convex polygon is the intersection of a set of half-planes, bounded by the lines along the polygon edges To be inside the polygon the point has to be in each half-plane Recall that the implicit line equation can be used to check on which side of the line a point is 7

D Polygon-ray intersections Equation of the line through the edge connecting vertices v i and v i+ : y y x x x y ( v v )(x v ) + ( v v )(y v 0 i i+ i i+ i i ) = If the quantity on the right-hand side is positive, then the point (x,y) is to the right of the edge, assuming we are looking from v i to v i+ Algorithm: if for each edge the quantity above is nonnegative for x = q x, y = q y then the point q is in the polygon Otherwise, it is not In the formulas x and y should be replaced by x and z if y coord was dropped, or by y and z if x was dropped Infinite cylinder-ray intersections v a p a r Infinite cylinder along y of radius r axis has equation x + z -r = 0 The equation for a more general cylinder of radius r oriented along a line p a + v a t: (q - p a -(v a (q p a ) ) v a ) -r = 0 where q = (x,y,z) is a point on the cylinder 8

Infinite cylinder-ray intersections To find intersection points with a ray p + vt, substitute q = p + vt and solve: (p - p a + vt - (v a (p - p a + vt))v a ) -r = 0 reduces to with A = B= At C = Δp ( Δp va)v where Δp = p-p a + Bt + C = 0 ( v (v va)va) ((v (v va)va) ( Δp ( Δp va)va) ) ( ) r a Cylinder caps A finite cylinder with caps can be constructed as the intersection of an infinite cylinder with a slab between two parallel planes, which are perpendicular to the axis To intersect a ray with a cylinder with caps: intersect with the infinite cylidner; check if the intersection is between the planes; intersect with each plane; determine if the intersections are inside caps; out of all intersections choose the on with minimal t 9

Cylinder-ray intersections POV -ray like cylinder with caps : cap centers at p and p, radius r Infinite cylinder equation: p a = p, v a = (p -p )/ p -p The finite cylinder (without caps) is described by equations: (q - p a -(v a (q p a ))v a ) -r = 0 and (v a ( q- p )) > 0 and p (v a (q- p )) < 0 r The equations for caps are: (v a (q-p )) = 0, (q- p ) < r bottom cap p (v a ( q- p )) = 0, (q- p ) < r top cap Cylinder-ray intersections Algorithm with equations: Step : Find solutions t and t of At + Bt + C = 0 if they exist Mark as intersection candidates the one(s) that are nonnegative and for which (v a ( q i -p )) > 0 and (v a ( q i -p )) < 0, where q i =p+v t i Step : Compute t 3 and t 4, the parameter values for which the ray intersects the upper and lower planes of the caps If these intersections exists, mark as intersection candidates those that are nonegative and (q 3 -p ) < r (respectively (q 4 -p ) < r ) In the set of candidates, pick the one with min t 0

Pixel rays Goal: Find direction of the ray to the center of the pixel (i,j) Let camera parameters be c α v u s position horizontal field of view viewing direction up direction aspect ration Then the image half-width in the virtual world units is α w = n tg The half-height is α h = sn tg u v View from above α v w n Pixel rays From coordinates in pixel units to virtual world coordinates in image plane: Pixel size: w h N M i + j + pixels pixels Pixel center of pixel (i,j) in pixel coords i +, j + N w Displacements of the pixel from the image center in virtual space units: h j + h, M i + w N w

Pixel rays Virtual world coordinates of pixel (i,j): image center + displacements Image center: c + vn u v pixel (i, j) = c + vn + v u h j + h u + M i + w N w v u Snell s law If a surface separates two media with different refraction indices (eg air and water) the light rays change direction when they go through Snell s law: the refracted ray is stays in the plane spanned by the normal and the direction of the original ray The angles between the normal and the rays are related by n sin θ = n sin θ where n and n are refraction indices normal θ θ

Snell s law If a surface separates two media with different refraction indices (eg air and water) the light rays change direction when they go through Snell s law: the refracted ray is stays in the plane spanned by the normal and the direction of the original ray The angles between the normal and the rays are related by n sin θ = n sin θ where n and n are refraction indices normal θ θ Refracted ray direction V N n n = n ³ T = nv + n(v, N) p n ( (V, N) ) N T n n 3