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

Similar documents
Sung-Eui Yoon ( 윤성의 )

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

Lecture 11: Ray tracing (cont.)

Intro to Ray-Tracing & Ray-Surface Acceleration

Photorealism: Ray Tracing

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

Ray Tracing I. Internet Raytracing Competition

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

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Ray Tracing I. History

Enhancing Traditional Rasterization Graphics with Ray Tracing. October 2015

CS 130 Exam I. Fall 2015

6.837 Introduction to Computer Graphics Final Exam Tuesday, December 20, :05-12pm Two hand-written sheet of notes (4 pages) allowed 1 SSD [ /17]

Effects needed for Realism. Computer Graphics (Fall 2008) Ray Tracing. Ray Tracing: History. Outline

CPSC GLOBAL ILLUMINATION

Topics and things to know about them:

Pipeline Operations. CS 4620 Lecture 10

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

Ray Tracing Foley & Van Dam, Chapters 15 and 16

Ray Tracing. Outline. Ray Tracing: History

Topic 12: Texture Mapping. Motivation Sources of texture Texture coordinates Bump mapping, mip-mapping & env mapping

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

Topic 11: Texture Mapping 11/13/2017. Texture sources: Solid textures. Texture sources: Synthesized

Lighting. To do. Course Outline. This Lecture. Continue to work on ray programming assignment Start thinking about final project

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

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Topic 11: Texture Mapping 10/21/2015. Photographs. Solid textures. Procedural

CS354 Computer Graphics Ray Tracing. Qixing Huang Januray 24th 2017

Last week. Machiraju/Zhang/Möller

Ray Tracing III. Wen-Chieh (Steve) Lin National Chiao-Tung University

CS452/552; EE465/505. Clipping & Scan Conversion

COMP 4801 Final Year Project. Ray Tracing for Computer Graphics. Final Project Report FYP Runjing Liu. Advised by. Dr. L.Y.

Supplement to Lecture 16

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

CS 130 Exam I. Fall 2015

Werner Purgathofer

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

Level of Details in Computer Rendering

Computer Graphics Ray Casting. Matthias Teschner

Last Time: Acceleration Data Structures for Ray Tracing. Schedule. Today. Shadows & Light Sources. Shadows

Lecture 11. More Ray Casting/Tracing

CS770/870 Spring 2017 Ray Tracing Implementation

Questions??? Announcements Assignment 3 due today

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

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

Computer Graphics. - Ray Tracing I - Marcus Magnor Philipp Slusallek. Computer Graphics WS05/06 Ray Tracing I

Computer Graphics and Image Processing Ray Tracing I

Spatial Data Structures

Accelerating Ray-Tracing

Spatial Data Structures

CS559 Computer Graphics Fall 2015

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

Computer Graphics. Rendering. by Brian Wyvill University of Calgary. cpsc/enel P 1

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

Spatial Data Structures

Deferred Rendering Due: Wednesday November 15 at 10pm

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

Review for Ray-tracing Algorithm and Hardware

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Real-Time Shadows. Computer Graphics. MIT EECS Durand 1

Introduction to Visualization and Computer Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

CS 428: Fall Introduction to. Raytracing. Andrew Nealen, Rutgers, /18/2009 1

Spatial Data Structures and Speed-Up Techniques. Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

3D Rendering. Course Syllabus. Where Are We Now? Rendering. 3D Rendering Example. Overview. Rendering. I. Image processing II. Rendering III.

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

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

Ray Tracing. Computer Graphics CMU /15-662, Fall 2016

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Pipeline Operations. CS 4620 Lecture 14

Culling. Computer Graphics CSE 167 Lecture 12

CS 4204 Computer Graphics

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

Shadows. COMP 575/770 Spring 2013

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

lecture 18 - ray tracing - environment mapping - refraction

Direct Rendering of Trimmed NURBS Surfaces

Reading. Ray Tracing. Eye vs. light ray tracing. Geometric optics. Required: Watt, sections , (handout) Further reading:

CS580: Ray Tracing. Sung-Eui Yoon ( 윤성의 ) Course URL:

Rendering Algorithms: Real-time indirect illumination. Spring 2010 Matthias Zwicker

The Traditional Graphics Pipeline

Reading. Ray Tracing. Eye vs. light ray tracing. Geometric optics. Required:

Advanced Ray Tracing

CS 464 Review. Review of Computer Graphics for Final Exam

The Traditional Graphics Pipeline

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Geometric Queries for Ray Tracing

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

Ray Casting. Outline in Code. Outline. Finding Ray Direction. Heckbert s Business Card Ray Tracer. Foundations of Computer Graphics (Fall 2012)

Ray Tracing. Brian Curless CSEP 557 Fall 2016

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

CS-184: Computer Graphics. Administrative

1999, Denis Zorin. Ray tracing

Interpolation using scanline algorithm

Transcription:

CS380: Introduction to Computer Graphics Ray tracing Chapter 20 Min H. Kim KAIST School of Computing Modeling SUMMARY 2 1

Types of coordinate function Explicit function: Line example: Implicit function: Circle example: y = f (x) y = mx +b f (x, y)=0 (x a) 2 +( y b) 2 r 2 =0 Explicit parametric function: x = x(t) w(t) ; y = y(t) w(t) Line example: x = a 0 +a 1 t; y = b 0 +b 1 t Circle example: x = a+rcos(t); y = b+rsin(t) 3 Subdivision surfaces First, let f be a face in M i surrounded by the vertices v j (and let m f be the number of such vertices). We set the geometry of each new face-vertex v f in M i+1 to be (m f = 4) v f = 1 m f The centroid of the vertices in M i defining that face. j v j 4 2

Subdivision surfaces Next, let e be an edge in M i connecting the vertices v 1 and v 2, and separating the faces f 1 and f 2. We set the geometry of the new edge-vertex in M i+1 to be: v e = 1 4 (v 1 +v 2 +v f 1 +v f2 ) 5 Subdivision surfaces Finally let v be a vertex in M i connected to the n v vertcies v j (n v =4) and surrounded by the n v faces f j. Then, we set the geometry of the new vertexvertex in M i+1 to be: v v = n 2 v v + 1 2 v n v n j + 1 2 v v v v j n v For an ordinary vertex, with valence n v =4, this becomes: v j + v f 16 j 16 j j v v = 1 2 v + 1 1 j v f j 6 3

Tangent, Normal, Curvature Tangent (time parametric) Normal (length parametric) For T (s) = (x'(s), y'(s)), normal is defined as! n(s) = ( y'(s), x'(s)) Curvature (length parametric): k(s): signed curvature,! n(s): normal T (t) = α '(t) α '(t) κ(s) = k(s) dt ds = k(s)! n(s) 7 Chapter 20 RAY TRACING 8 4

Photo vs. Graphics 9 Photo vs. Graphics 10 5

Photo vs. Graphics 11 Photo vs. Graphics (a) (b) (c) Fiero Ardi Al Dean Jorge Jimenez Answers: Graphics Graphics Graphics All of them are purely computer graphics images, created by the latest graphics techniques 12 6

Fundamental elements for rendering Geometry Material model Light Rendering Virtual photography 13 Fundamental elements for rendering Geometry 3D scanning, 3D modeling Color, Texturing, BRDFs Material model Light Color, spectrum Rendering Virtual photography Global illumination 14 7

Cornell Box rendering Meyer, Rushmeier, Cohen, Torrance and Greenberg, ACM TOG, 1986 15 Ray tracing result 16 8

Ray tracing Different approach to organizing the rendering process It is pixel and ray based, instead of triangle based. Historically, it has not been hardware accelerated, and is used for offline rendering. It is very flexible and so various optical effects can be put in very easily. It is at the heart of photorealistic methods of light simulation. We will cover it only briefly. 17 Ray tracing pipeline Courtesy of Hendrik Lensch 18 9

Ray tracing pipeline Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 19 Ray tracing pipeline Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 20 10

Ray tracing pipeline Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 21 Ray tracing pipeline Space subdivision Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 22 11

Ray tracing pipeline Space subdivision Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 23 Ray tracing pipeline Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 24 12

Ray tracing pipeline Ray cast only Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 25 Ray tracing pipeline Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 26 13

Ray tracing pipeline Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 27 Ray tracing pipeline Ray cast with shadow Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 28 14

Ray tracing pipeline Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 29 Ray tracing pipeline Color mixture Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 30 15

Ray tracing pipeline Ray-Generation Ray-Traversal Intersection Shading Framebuffer Courtesy of Hendrik Lensch 31 Ray tracing 32 16

Rasterization vs. ray-casting Rasterization is organized therefore: initialize z-buffer for all triangles for all pixels covered by the triangle compute color and z if z is closer than what is already in the z-buffer update the color and z of the pixel In basic ray casting, we reverse the loop orders to obtain: for all pixels on the screen for all objects seen in this pixel if this is the closest object seen at the pixel compute color and z set the color of the pixel 33 Rasterization The rasterization algorithm has the nice property that each triangle in the scene is touched only once, and in a predictable order. Good for memory usage Use in Pixar Renderman Setup is reduced over a triangle 34 17

Ray-casting Shading is automatically deferred, until after visibility is done. We can maintain depth order of fragments with minimal memory. Letting us easily model non-refractive transparency Letting us easily model constructive solid geometry (CSG). Using root finding, we can directly intersect rays with smooth geometries and do not need to triangulate. 35 Ray-casting Easy to use ray infrastructure for tons of generalizations Shadows reflection Note: many of these things can be done to varying degrees in a rasterize, but with some extra effort expended. Also note that with programmable GPUs shading is the bigger cost, not the rasterization, and that the GPUs can be used to do ray calculations as well. 36 18

RAY CASTING 37 Intersection The main computation needed in ray tracing is computing the intersection of a geometric ray ( p, d) with an object in the scene. Here p (the eye frame origin, COP) is the start of the ray, which goes off in the direction d d p 38 19

Ray-plane Q P R 39 Courtesy of Doug A. Bowman Implicit surface (a plane) P = (1, 1, 1), Q = (1, 2, 0), R = (-1, 2, 1). We seek the coefficients of an equation Ax + By + Cz = D, where P, Q and R satisfy the equations, thus: A + B + C = D A + 2A + 0C = D -A + 2B + C = D Subtracting the first equation from the second and then adding the first equation to the third, we eliminate a to get B - C = 0 4B + C = 2D Adding the equations gives 5B = 2D, or B = (2/5)D, then solving for C = B = (2/5)D and then A = D - B - C = (1/5)D. So the equation (with a nonzero constant left in to choose) is D(1/5)x + D(2/5)y + D(2/5)z = D, so one choice of constant gives x + 2y + 2z = 5 or another choice would be (1/5)x + (2/5)y + (2/5)z = 1 Given the coordinates of P, Q, R, there is a formula for the coefficients of the plane that uses determinants or cross product. 40 20

Ray-plane Plane described by the equation We start by representing every point along the ray using a single parameter λ Plugging this into the plane equation, we get x y z = p x p y p z Eye origin + λ d x d y d z Pixel ray vector 0 = A(p x + λd x ) + B(p y + λd y ) + C(p z + λd z ) + D = λ(ad x + Bd y + Cd z ) + (Ap x + Bp y + Cp z + D) Ax +By +Cz +D =0 d p 41 Ray-plane And we see that λ = (Ap x + Bp y + Cp z + D) (Ad x + Bd y + Cd z ) Given a triangle coordinate (P,Q,R), we can determine A, B, C, D per triangle. λ tells us where along the ray the intersection point is Negative valued λ are backwards along the ray. Comparisons between λ values can be used to determine which, among a set of planes, is the first one intersected along a ray. ABCD per triangle, d xyz per pixel, p xyz per camera 42 21

Ray-plane λ<0 λ>0 Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 43 Ray-triangle (Step1) we compute the A, B, C, D of the plane supporting the triangle, and compute the rayplane intersection of (x, y, z) with the ray (d x, d y, d z ) as above. (Step2) we need a test to determine if the intersection point is inside or outside of the triangle. We can build such a test using the counter clockwise calculation 44 22

Ray-triangle Suppose we wish to test if a point outside of a triangle Δ( p 1 p 2 p 3 ) in 2D Consider the three sub triangle and Δ( q p 2 p 3 ) is inside or When q is inside of Δ( p 1 p 2 p 3 ), then all three sub-triangles will agree on their clockwisedness. When q is outside, then they all disagree. q Δ( p 1 p 2 q),δ( p 1 q p 3 ) 45 RECAP: Math of backface culling Let Δ( p 1 p 2 p 3 ) be the three vertices of the triangle projected down to the (x n, y n,0) plane. Define the vector a = p 3 p 2 and b = p 1 p 2 Next compute the cross! product c = a! b! If the three vertices are counterclockwise in the! plane, then c will be in the +z n direction. 46 23

RECAP: Math of backface culling So the area of the triangle is: Area = 1 a b Taking account of the direction, 2 we could calculate the direction of the cross product of these two vectors. (x 3 n x 2 n )(y 1 n y 2 n ) (y 3 n y 2 n )(x 1 n x 2 n ) If this is negative, the polygon looks backward. 47 Ray-sphere Suppose we have a sphere with radius R and center c modeled as the set of points [x, y,z] t that satisfy the equation Plugging the below into the above: We get (x c x ) 2 + (y c y ) 2 + (z c z ) 2 r 2 = 0 x y z = p x p y p z + λ 0 = (p x + λd x c x ) 2 + (p y + λd y c y ) 2 + (p z + λd z c z ) 2 r 2 0 = (d x 2 + d y 2 + d z 2 )λ 2 + (2d x (p x c x ) + 2d y (p y c y ) + 2d z (p z c z ))λ + (p x c x ) 2 + (p y c y ) 2 + (p z c z ) 2 r 2 d x d y d z 48 24

Ray-sphere We can then use the quadratic formula to find the real roots λ of this equation. If there are two real roots, these represent two intersections, as the ray enters and exits the sphere. If there is one (doubled) real root, then the intersection is tangential. If there are no real roots, then the ray misses the sphere. As above, any of these intersections may be backwards along the ray. At the intersection, the normal of the sphere at [x, y,z] t is in the direction [x c x, y c y,z c z ] t This fact may be useful for shading calculations. 49 Ray-sphere intersection λ>0 λ<0 Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 50 25

RAY TRACING 51 Secondary rays To determine if a scene point is in shadow, one follows a shadow ray from the observed point towards the light to see if there is any occluding geometry. Another easy calculation that can be done is mirror reflection (and similarly refraction). In this case, one calculates the bounce direction bounce ray off in that direction: B( w) = 2( w n) n w 52 26

Reflected ray B( w) = 2( w n) n w Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 53 Shadow ray Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 54 27

Refracted ray Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 55 Scene Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 56 28

Three sources of light Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 57 Directly from light source Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 58 29

Reflection Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 59 Reflection Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 60 30

Refraction Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 61 Three sources of light together Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 62 31

Ray-tracing algorithm (backwards) Min Courtesy H. Kim (KAIST) of Doug A. Foundations Bowman of 3D Computer Graphics, S. Gortler, MIT Press, 2012 63 Examples The color of the point hit by this ray is then calculated and used to determine the color of the original point on the mirror. This idea can be applied recursively some number of times to simulate multiple mirror. Ray-casting only Ray-casting + shadow Rec. ray-tracing + shadow 64 32

Early rejection When computing the intersection between a ray and the scene, instead of testing every scene object for intersection with the ray, we may use auxiliary data structures to quickly determine that some set of objects is entirely missed by the ray. For example, one can use a simple shape (say a large sphere or box) that encloses some set of objects. Bounding volume hierarchy (BVH) Given a ray, one first calculates if the ray intersects this volume. If it does not, then clearly this ray misses all of the objects in the bounded set, and no more ray intersection tests are needed. This idea can be further developed with hierarchies and spatial data structure. 65 Bounding volume hierarchy (BVH) 66 33

Space subdivision 67 34