Computer Graphics. Shi-Min Hu. Tsinghua University

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

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

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

CPSC GLOBAL ILLUMINATION

Lecture 10: Ray tracing

Lecture 11: Ray tracing (cont.)

Photorealism: Ray Tracing

Sung-Eui Yoon ( 윤성의 )

Ray Tracing. Kjetil Babington

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

Ray Tracing. Last Time? Reading for Today. Reading for Today

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

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

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

Questions??? Announcements Assignment 3 due today

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

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

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

Geometric optics. The University of Texas at Austin CS384G Computer Graphics Don Fussell

Lighting and Shading

COMP 175 COMPUTER GRAPHICS. Lecture 11: Recursive Ray Tracer. COMP 175: Computer Graphics April 9, Erik Anderson 11 Recursive Ray Tracer

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

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

Computer Graphics. Lecture 13. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura

Computer Graphics Ray Casting. Matthias Teschner

Consider a partially transparent object that is illuminated with two lights, one visible from each side of the object. Start with a ray from the eye

CS 325 Computer Graphics

Supplement to Lecture 16

Ray Tracing. Brian Curless CSEP 557 Fall 2016

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

Ray Tracing. CSCI 420 Computer Graphics Lecture 15. Ray Casting Shadow Rays Reflection and Transmission [Ch ]

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

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

Raytracing. COSC 4328/5327 Scott A. King

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

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

Introduction to Visualization and Computer Graphics

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

Computer Graphics Global Illumination

COMP371 COMPUTER GRAPHICS

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

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

MIT Ray Tracing Ray Tracing

Topics and things to know about them:

Computer Graphics. Lecture 10. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura 12/03/15

CS-184: Computer Graphics. Administrative

Raytracing CS148 AS3. Due :59pm PDT

Intro to Ray-Tracing & Ray-Surface Acceleration

Ray Tracing. Outline. Ray Tracing: History

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

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

Shading, Advanced Rendering. Week 7, Wed Feb 28

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

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Ground Truth. Welcome!

Last Time? Ray Casting. Administrivia: Lab & Office Hours. Notes on Assignments. Ray Casting. Overview of Today

Homework #2. Shading, Ray Tracing, and Texture Mapping

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

CHAPTER 1 Graphics Systems and Models 3

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

The Traditional Graphics Pipeline

Ray-tracing Cont. Ray-tracing

Reflection and Shading

Ray Tracing. CPSC 453 Fall 2018 Sonny Chan

Ray Tracing. Last Time? Today. Ray Casting. Durer s Ray Casting Machine. Reading for Today

CS 130 Exam I. Fall 2015

Raytracing & Epsilon. Today. Last Time? Forward Ray Tracing. Does Ray Tracing Simulate Physics? Local Illumination

Lecture 32 of 41. Lab 6: Ray Tracing with ACM SIGGRAPH Demo & POV-Ray

I have a meeting with Peter Lee and Bob Cosgrove on Wednesday to discuss the future of the cluster. Computer Graphics

Ray Tracing: Special Topics CSCI 4239/5239 Advanced Computer Graphics Spring 2018

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

Computer Graphics Global Illumination

CS5620 Intro to Computer Graphics

Photorealistic 3D Rendering for VW in Mobile Devices

The Traditional Graphics Pipeline

COMPUTER GRAPHICS AND INTERACTION

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

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]

Review for Ray-tracing Algorithm and Hardware

Ray-Tracing. Misha Kazhdan

Rendering Part I (Basics & Ray tracing) Lecture 25 December 1, 2015

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

Chapter 11 Global Illumination. Part 1 Ray Tracing. Reading: Angel s Interactive Computer Graphics (6 th ed.) Sections 11.1, 11.2, 11.

Computer Graphics and Image Processing Ray Tracing I

Programming projects. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

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

Movie: For The Birds. Announcements. Ray Tracing 1. Programming 2 Recap. Programming 3 Info Test data for part 1 (Lines) is available

Ray Tracing COMP575/COMP770

Chapter 7 - Light, Materials, Appearance

The Traditional Graphics Pipeline

Ray Tracer Due date: April 27, 2011

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Ray Tracing. Quiz Discussion. Announcements: Final Projects. Last Time? Durer s Ray Casting Machine. Today

A Little Background. Motivation. Motivation

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Mach band effect. The Mach band effect increases the visual unpleasant representation of curved surface using flat shading.

Assignment 2 Ray Tracing

CS770/870 Spring 2017 Ray Tracing Implementation

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

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Transcription:

Computer Graphics Shi-Min Hu Tsinghua University

History of Ray Tracing ( 光线跟踪 ) In 1980, Whitted proposed a ray tracing model, include light reflection and refraction effects. A Milestone of Computer Graphics.

Turner Whitted,An improved illumination model for shaded display, Communications of the ACM, v.23 n.6, p.343-349, June 1980. http://www.raytracing.co.uk/study/home.htm

After receiving his PhD from NCSU in 1978, Turner Whitted left for Bell Labs and proceeded to shake the CGI world with an algorithm that could ray-trace a scene in a reasonable amount of time. He only has 14 papers, and Ray tracing is his first paper.

He was elected as member of National Academy of Engineering in 2003.

Ray Tracing( 光线跟踪 ) Introduction of ray tracing Ray intersection( 光线求交 ) shadows( 阴影 ) Transparence and specular reflection ( 透明和镜面反射 ) textures( 纹理 )

Introduction of ray tracing Ray tracing Because of its effectiveness, ray tracing is a widely used and very powerful rendering (drawing) technique Why we see objects? Light can be interpreted as a collection of rays that begin at the light sources and bounce around the objects in the scenes. We see objects become rays finally come into our eyes.

Basic Idea of ray tracing Think of the frame buffer as a simple array of pixels, with eye looking through it into the scene For each pixel, what can we see? a ray casting from the eye through the center of the pixel and out into the scene, its path is traced to see which object the ray hits first calculate the shading value of the point by the Phong model continue to trace the ray in the scene to achieve reflection, refraction..

Introduction of ray tracing Features Easy to incorporate interesting visual effects, such as shadowing, reflection and refraction, since the path of a ray is traced through the scene Besides geometric primitives (such as spheres, cones, cubes), easy to work with a richer class of objects, including polygonal meshes, compound objects.

Recursive Ray Tracing

Recursive Ray Tracing IntersectColor( vbeginpoint, vdirection) { Determine IntersectPoint; Color = ambient color; for each light Color += local shading term; if(surface is reflective) color += reflect Coefficient * IntersectColor(IntersecPoint, Reflect Ray); else if ( surface is refractive) color += refract Coefficient * IntersectColor(IntersecPoint, Refract Ray); } return color;

demos of ray tracing DENG Jia ( 计 2 邓嘉 ) s Demo Play Video Deng Jia, 2002-2006, Tsinghua University, No. 1 in GPA. 2006-, Princeton Univetrsity, published a paper on relief in ACM SIGGRAPH 2007 Deng Jia s story in Media computing (late)

Ray intersection ( 光线求交 ) Ray tracing Ray Representation Plane intersection Triangle intersection Polygon intersection Sphere intersection Box intersection

Ray representation Parametric representation P(t) = R o + t * R d where R o =(x o,y o,z o ) is the original point of the ray, R d =(x d,y d,z d ) is the direction the ray is going on, usually the direction is normalized t value determines the point the ray arrives at, its value is P(t) always larger than 0 direction R d origin R o

P' H(p) = d < 0 Plane Intersection Plane Definition Explicit: P o =(x o,y o,z o ), n=(a,b,c) Implicit: H(P) = Ax+By+Cz+D = 0 = n P + D = 0 Point Plane Distance If n is normalized, P the distance is d = H(P) But note that, d is signed distance H(p) = d > 0 normal P o H

Plane Intersection Where does the ray intersect this plane? Given a plane with equation: n P + D = 0; Intersection means satisfy both equations: P(t) = R o + t * R d n P(t)+D = 0; So we have t = -(D+n R o )/(n R d ) P(t) Just need to verify if t>0

Triangle Intersection In real-time graphics, triangle geometry (triangle mesh) is usualy stored, and each triangle is defined by three vertices. There exists many different ray/triangle intersection methods, main steps are: First compute the intersection point between the ray and the triangle s plane Thereafter, project the intersection point onto the triangle s plane Decide whether or not the point is inside the triangle

Triangle Intersection Barycentric coordinates: A point P, on a triangle P 0 P 1 P 2, is given by the explicit formula: P P0 P1 P2 where (,, ) are the barycentric coordinates, which must satisfy 0,, 1, 1 Note that the barycentric coordinates could be used for texture mapping, normal interpolation, P color interpolation, etc. P 0 P 1 P 2

Triangle Intersection Since =1, we can write 1 We have: P (1 ) P P P 0 1 2 Set ray equation equal to barycentric equation: Ro+ trd (1 ) P0 P1 P2 Rearrange the terms, gives: t ( Rd P0 P1 P0 P2 ) P0 R0 The means the barycentric coordinate and distance t can be found by solving this linear system of equations

Triangle Intersection Denoting E1 P0 P1, E 2 P0 P2, S P0 R0 the solution to the equation above is obtained by Cramer s rule: t det( S, E, E ) 1 2 1 det( dse,, 2) det( d, E1, E2) det( d, E1, S) Then check 0, 1, 1 to determine whether or not the intersect point is inside the triangle

Polygon Intersection Even though triangles are the most common rendering primitive, a routine to compute the intersection between a ray and a polygon is useful. A polygon of n vertices is defined by an ordered vertex list {v 0,v 1,,v n-1 }, where vertex v i forms an edge with for 0 <= i < n-1, and the polygon is closed by the edge from v n-1 to v 0. The plane of the polygon is denoted by : n x d 0 p p p

Polygon Intersection We first compute the P intersection between the ray and the plane. The solution has been presented in previous slides. If there is an intersection, next we need to determine whether or not the intersection point P is inside the polygon. This is done by projecting all vertices and P to one of the xy-,xz-,yz planes, as shown in the figure

Polygon Intersection The question left is a 2D point-in-polygon problem. Here we review one of the most useful algorithm the crossing test The crossing test is based on Jordan Curve Theorem, which says that a point is inside a polygon if a ray from this point in an arbitrary direction crosses an odd( 奇数的 ) number of edges. This test is also known as the even-odd test.

Polygon Intersection The crossing test is illustrated in the right figure: Two black points inside polygon (cross one edge) two black points outside polygon (one crosses 2 edges and the other crosses 0 edge) The crossing test is the fastest test that does not use preprocessing ( 预处理 )

Polygon Intersection The test point P can also be thought of as being at the origin, and the edges may be tested against the positive x-axis instead If the y-coordinates of the edge have the same sign, then the edge does not cross x-axis Else, compute the x-coordinate of the intersection between x-axis and the edge If positive, the edge crosses x-axis, the number of crossing increases by 1 Else, the edge does not cross the x-axis

The other method

Sphere Intersection Now, let s look at the intersection test between a ray and a sphere Mathematical solution sphere defined as: a center point, and a radius r ; the implicit formula for the sphere is : f ( P) P P r 0 c To solve for the intersection between a ray and a sphere, simply replace P in the ray equation to yield: P( t) P r 0 c P c

Sphere Intersection: Algebra method The equation of last page is simplified as follows: P( t) P r 0 c R0 trd Pc r ( R tr P ) ( R tr P ) r 0 d c 0 d c t ( R R ) 2 t( R ( R P )) ( R P ) ( R P ) r 0 2 2 d d d 0 c 0 c 0 c Since Rd is normalized: t 2 t( R ( R P )) ( R P ) ( R P ) r 0 2 2 d 0 c 0 c 0 c Rewrite as: Solution is: 2 t tb c 2 0 2 t b b c 2

Sphere Intersection Previous algebra solution could be improved, e.g., observing that intersections behind the ray origin are not needed An optimized Solution: Geometric method Easy reject (No intersection testing) Easy to check ray origin inside or outside the sphere Easy to check which point is closed to ray from sphere origin Ray direction: pointing to or away from sphere

Sphere Intersection: Geometric Method Optimized Solution We first compute the vector l from the ray origin to the center of the sphere: l P R c 0 Pc r R d R o

Sphere Intersection Optimized Solution compute the vector from the ray origin to the center of the sphere: Is ray origin inside/outside the sphere? Inside the sphere: Outside the sphere: On the sphere: c l l P R If ray origin is on the sphere, be careful about degeneracy 0 l l l 2 2 2 r r r 2 2 2

Sphere Intersection Next, Find closest point to sphere center: t p l R d If origin outside & t P < 0 no hit the sphere is behind the ray origin and we can reject the intersection Pc r t R d R o

Sphere Intersection Next, find squared distance d from the sphere center to the closest point If d>r, no hit 2 2 2 d l t p Pc d r R d R o t P

Sphere Intersection Find distance (t ) from closest point (t P ) to correct intersection: t 2 = r 2 - d 2 Then the solution will be If origin outside sphere t = t P - t () If origin inside sphere t = t P + t O d r R d R o t P t

Box Intersection Ray/Box intersection test are important in graphics, since we often bound geometric objects with boxes, which is called bounding box( 包围盒 ). With bounding box, when testing a ray intersect with an object, we first test the ray intersect with the bounding box, if not intersected, then the ray will not intersect with the object definitely.

Box Intersection Here, we introduce a slab based method for box intersection test, proposed by Haines A slab is simply two parallel planes, which are grouped for faster computation A box is composed of 3 slabs As illustrated in the right figure in 2D Slabs

Box Intersection For each slab, intersecting with the ray, there is a minimum t value and maximum t min max value, these are called t i and t i. (i=0,1,2) The next step is to compute: t max( t, t, t ); min min min min 0 1 2 t min( t, t, t ); max max max max 0 1 2 Now, the clever test: min max if t t,then the ray intersects the box min max t is the enter-point, t is the exit point Otherwise, no intersections

Box Intersection Look at the right figure, there are 2 rays: The left ray intersects with the box it has min max t t The right ray misses it does not have t min t max The idea is the same with Liang-Barsky Clipping max t 0 min t 1 max t 1 min t 0 max t 0 min t 0 max t 1 min t 1

Box Intersection Woo s Method for intersection between a ray and an axis-aligned box( 和坐标轴平行 ) Woo introduced some smart optimization specific for axis-aligned box min t 1 t 0 min

Box Intersection Woo s Method First, identity three candidate planes out of the six planes. For each pair of parallel planes, the back facing plane can be omitted for further consideration. After finding the three planes we computed the intersection distances (t-value) between the ray and the planes. The largest of the t-values corresponds to a potential hit min t 1 t 0 min

Box Intersection Woo s Method Use the potential hit t-value to compute the intersection point if the intersection point is located on the face of the box, then it is a real hit Slabs method vs Woo s Method Comparable in performance With above discussion of ray intersection, let s ray tracing

The Simplest Ray Tracing:Ray Casting For each pixel Cast a ray from the eye, through the center of pixel, to the scene For each object in the scene Find the intersection with the ray Store the closest point Calculate local shading term of the point according to light, material and normal

The Simplest Ray Tracing: Ray Casting Shading results depend on surface normal, light direction, light intensity, view direction, material property and so on Do not account for secondary ray, so do not have shadow, reflection and refraction effects

Sample Code of Ray casting for each pixel cast a ray and find the intersection point if have intersection color = ambient for each light color += shading from this light (depending on light property and material property) return color Else return background_color

Add Shadows For each pixel Cast a ray and find the intersection point color = ambient for each light if intersection point is not in shadow area of the light (evaluated by shadow rays) color += shading from this light return color

Add Shadows As illustrated in the figure below, casting a shadow ray from intersection point to the light, if there is an intersection, this point is in shadow We only want to know whether there is an intersection, not which one is closest

Add Ray reflection and refraction Ray tracing gives the ability to have objects with mirror reflections or objects with refractions. The first step is to determine where a ray intersects the object. The next step is to determine the direction the ray will travel when it reflects off the surface or refracts through the object. a new ray direction is calculated based on the incoming ray and the surface normal.

Ray Reflections The law of reflection: the angle of incidence = the angle of reflection incoming ray, reflection ray and normal is in the same plane The reflection ray is calculated as: R I 2( I N) N Normal N where I,N and R are all unit vectors Incidence I Reflection R

Ray Reflections As in the figure, reflection ray is symmetric with respect to the normal from the view direction

Ray Refraction When light travels from one transparent medium into another, the direction of light can change because of the relative densities of the media

Ray Refraction The law of refraction (also called Snell s Law): the ratio of the sines of the angles of incidence and of refraction is a constant that depends on the media The constant is called the relative refractive index

Ray Refractions Snell s law gives: sin sin i i T T sin sin 2 2 2 2 i i T T (1 cos ) (1 cos ) 2 2 2 2 i i T T 2 2 i (1 cos i) cos T 1 2 T η i η T M sin Ө i I Ө i -N N N cos Ө i The transmitted ray direction can now be calculated by : i i T I (cos T ) N T T Ө T T M

Ray Refractions The right way to catch fishes

Recursive Ray Tracing

Recursive Ray Tracing IntersectColor( vbeginpoint, vdirection) { Determine IntersectPoint; Color = ambient color; for each light Color += local shading term; if(surface is reflective) color += reflect Coefficient * IntersectColor(IntersecPoint, Reflect Ray); else if ( surface is refractive) color += refract Coefficient * IntersectColor(IntersecPoint, Refract Ray); } return color;

Recursive Ray Tracing Does it ever end? Stopping criteria: Recursion depth Stop after a number of bounces Ray contribution Stop if reflected / refracted contribution becomes too small

Recursion ray tracing results 0 recursion 1 recursion 2 recursions

Add Texture( 纹理 ) Computer generated images can be more realistic by painting textures on various surfaces. 2D Texture 3D Texture As shown in the figure, the floor is textured by a chess board

Add Texture( 纹理 ) 2D texture Take a rectangle for example Specify 2D texture coordinate( 纹理坐标 ) for 4 corner points calculate the 2D texture coordinate of the intersection point Use this 2D texture coordinate to look-up the texture image, assign this value to the intersection point We will discuss more at Texture course

Consideration of Ray Tracing Epsilon problem. when a ray is tangent( 相切 ) to a plane/sphere, a ray intersects with a polygon at its vertex Acceleration Bounding box Hierarchical Structure

Does Ray Tracing simulate physics? Photons go from the light to the eye, not the way we used in ray tracing algorithm What we do is backward ray tracing, photon go from the eye to the light

Forward Ray Tracing Start from the light source But low probability to reach the eye What can we do about it? Always send a ray to the eye. still not efficient

Does Ray Tracing Simulate Physics? Ray Tracing is full of dirty tricks For example, shadows of transparent objects: opaque? multiply by transparency color? (ignores refraction & does not produce caustics)

Some demos of ray tracing

Some demos of ray tracing

Some demos of ray tracing

Some demos of ray tracing DENG Jia ( 计 2 邓嘉 ) s Demo Play Video Deng Jia s story in Media computing

Video Repetition

Flamingo coming

I want a super car

Some demos of ray tracing GAO Yue( 计 2 高岳 ) s Demo Gao Yue is a PhD in GCC Group Launch Application

Further Demo 1

Further Demo 2

另一个大作业 http://www.siggraph.org/education/materials/hypergra ph/raytrace/rtrace0.htm

Assignments Projects (60%) Project 1 (Simple Ray Tracing) (30%) Contain primitives of cube, polyhedron, sphere Effects : phong model, texture, mirror, transparent, shadow Optional: other BRDF models, acceleration techniques, high dimensional texture, soft shadows CANNOT use OpenGL Thanks!