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

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

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

Photorealism: Ray Tracing

Supplement to Lecture 16

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

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

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

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

Lighting and Shading

Ray-Tracing. Misha Kazhdan

CS5620 Intro to Computer Graphics

Intro to Ray-Tracing & Ray-Surface Acceleration

Topics and things to know about them:

CPSC GLOBAL ILLUMINATION

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

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

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

Reflection and Shading

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

Visual cues to 3D geometry. Light Reflection and Advanced Shading. Shading. Recognizing materials. size (perspective) occlusion shading

Illumination Models & Shading

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

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

Sung-Eui Yoon ( 윤성의 )

Interpolation using scanline algorithm

Lecture 11: Ray tracing (cont.)

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

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

CS559 Computer Graphics Fall 2015

Ray Tracing. Kjetil Babington

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

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

Computer Graphics. Lecture 14 Bump-mapping, Global Illumination (1)

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

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

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

COMP371 COMPUTER GRAPHICS

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

Introduction to Computer Graphics 7. Shading

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

Lecture 10: Ray tracing

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

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

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

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

03 RENDERING PART TWO

CMSC427 Final Practice v2 Fall 2017

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

Ray Tracing Foley & Van Dam, Chapters 15 and 16

CS 325 Computer Graphics

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

CS 130 Exam I. Fall 2015

Raytracing CS148 AS3. Due :59pm PDT

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

Comp 410/510 Computer Graphics. Spring Shading

Illumination. Michael Kazhdan ( /657) HB Ch. 14.1, 14.2 FvDFH 16.1, 16.2

Spring 2012 Final. CS184 - Foundations of Computer Graphics. University of California at Berkeley

Introduction to Ray-tracing Objectives

Shading, Advanced Rendering. Week 7, Wed Feb 28

CS 130 Final. Fall 2015

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Assignment 6: Ray Tracing

Computer Graphics. Illumination and Shading

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

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

Illumination & Shading: Part 1

CPSC / Illumination and Shading

8.1 Geometric Queries for Ray Tracing

Review for Ray-tracing Algorithm and Hardware

CS 130 Exam I. Fall 2015

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

Movie: Geri s Game. Announcements. Ray Casting 2. Programming 2 Recap. Programming 3 Info Test data for part 1 (Lines) is available

Lecture 19: All Together with Refraction

Lecture 11. More Ray Casting/Tracing

Computer Graphics. Illumination and Shading

Overview: Ray Tracing & The Perspective Projection Pipeline

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

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

Ray Tracing. Shandong University

A Little Background. Motivation. Motivation

Illumination and Shading

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

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

CS384G Midterm Examination Spring 2008

Questions??? Announcements Assignment 3 due today

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

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

Deferred Rendering Due: Wednesday November 15 at 10pm

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

Shading. Why we need shading. Scattering. Shading. Objectives

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

CS452/552; EE465/505. Intro to Lighting

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

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

Ray Tracing. Brian Curless CSEP 557 Fall 2016

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

Computer Graphics. Lecture 02 Graphics Pipeline. Edirlei Soares de Lima.

Shading I Computer Graphics I, Fall 2008

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

Transcription:

Lecture 11 Ray tracing

Introduction Projection vs. ray tracing Projection Ray tracing Rendering

Projection vs. ray tracing Projection Ray tracing Basic methods for image generation Major areas of computer graphics: Modelling ( creating 3d virtual worlds ) Rendering ( creating 2d images from 3d models ) Animation ( creating motion from sequences of 2d images ) Two basic methods for rendering: Projective methods Ray tracing

Projection vs. ray tracing Projection Ray tracing Projective methods A popular method for generating images from a 3D-model is projection, e.g.: 3D triangles project to 2D triangles Project vertices Fill/shade 2D triangle Q: what if two or more triangles project onto the same pixels?

Projection vs. ray tracing Projection Ray tracing Projective methods Used by OpenGL and DirectX Very fast: hardware supported Real-time applications (games) You will do this in the practicals this year

Projection vs. ray tracing Projection Ray tracing Ray tracing / ray casting For photo-realistic rendering, usually ray tracing algorithms are used: for every pixel Compute ray from viewpoint through pixel center Determine intersection point with first object hit by ray Calculate shading for the pixel (possibly with recursion)

Projection vs. ray tracing Projection Ray tracing Ray tracing / ray casting Global Illumination Traditionally (very) slow Recent developments: real-time ray tracing This was done in last year s practicals

Projection vs. ray tracing Projection Ray tracing Examples: landscapes (www.terragen.org)

Projection vs. ray tracing Projection Ray tracing Examples: office (www.povray.org)

Projection vs. ray tracing Projection Ray tracing Examples: last year s practicals This year we will do shader programming

Projective methods vs. ray tracing Projective methods: Object-order rendering, i.e. For each object...... find and update all pixels that it influences Ray tracing: Image-order rendering, i.e. For each pixel...... find all objects that influence it and update it accordingly

A basic ray tracing algorithm FOR each pixel DO find 1st object hit by ray and surface normal n set pixel color to value computed from hit point, light, and n

Lines and rays Introduction We need to shoot a ray from the view point e through a pixel s on the screen towards the scene/objects Hmm, that should be easy with...

Lines and rays Introduction... a parametric line equation: where p(t) = e + t( s e) e is a point on the line (aka its support vector) s e is a vector on the line (aka its direction vector)

Lines and rays Introduction With this, our ray... starts at e (t = 0), goes throught s (t = 1), and shoots towards the scene/objects (t > 1) Hmm, calculation would become much easier if we would have...

Coordinate system Introduction... a camera coordinate system: That s easy! Using our camera position e our viewing direction w and a view up vector t we get u = w t v = w u

Coordinate system Introduction... a camera coordinate system: That s easy! Using our camera position e our viewing direction w and a view up vector t we get u = w t v = w u

Coordinate system Introduction... a camera coordinate system: That s easy! Using our camera position e our viewing direction w and a view up vector t we get u = w t v = w u

Coordinate system Introduction... a camera coordinate system: That s easy! Using our camera position e our viewing direction w and a view up vector t we get u = w t v = w u

Coordinate system Introduction Normalizing, i.e. w/ w u/ u v/ v gives us our coordinate system. Q: why did we chose w as viewing direction and not w?

Viewing window Introduction With this new coordinate system we can easily define our viewing window: left side: u = l right side: u = r top: v = t bottom: v = b

Viewing window Introduction Assuming our window has n x n y pixels, this becomes a simple window transformation from (r l) (t b) to n x n y. Hence, we can express a pixel at position (i, j) in our new coordinate system as (u, v) with u = l+(r l)(i+0.5) n x v = b+(t b)(j+0.5) n y

Viewing rays Introduction For orthographic views, viewing rays have the same direction w but different origin We get the origin with the previously introduced mapping from (i, j) to (u, v): u = l+(r l)(i+0.5) n x v = b+(t b)(j+0.5) n y and can write it as e + u u + v v

Viewing rays Introduction For perspective views, viewing rays have the same origin e but different direction If d denotes the origin s distance to the plane, and u, v are calculated as before, we can write the direction as d w + u u + v v.

A basic ray tracing algorithm FOR each pixel DO find 1st object hit by ray and surface normal n set pixel color to value computed from hit point, light, and n

Ray-object intersection (implicit surface) In general, the intersection points of a ray p(t) = e + td and an implicit surface f( p) = 0 can be calculated by f( p(t)) = 0 or f( e + td) = 0

Spheres Introduction The implicit equation for a sphere with center c = (x c, y c, z c ) and radius R is (x x c ) 2 +(y y c ) 2 +(z z c ) 2 R 2 = 0 or in vector form ( p c) ( p c) R 2 = 0

Intersections between rays and spheres Intersection points have to fullfil the ray equation p(t) = e + t d the sphere equation (x x c ) 2 + (y y c ) 2 +(z z c ) 2 R 2 = 0 Hence, we get ( e + t d c) ( e + t d c) R 2 = 0 which is the same as ( d d)t 2 +2 d ( e c)t+( e c) ( e c) R 2 = 0

Intersections between rays and spheres ( d d)t 2 +2 d ( e c)t+( e c) ( e c) R 2 = 0 is a quadratic equation in t, i.e. At 2 + Bt + C = 0 that can be solved by t 1,2 = B + B 2 4AC 2A and can have 0, 1, or 2 solutions.

Ray-object intersection (parametric surface) The intersection points of a ray p(t) = e + t d and a parametric surface f(u, v) can be calculated by x e + tx d = f(u, v) y e + ty d = f(u, v) z e + tz d = f(u, v) or e + t d = f(u, v) Notice that these are 3 equations with 3 unknowns (t, u, v).

For ray-triangle intersections: We first calculate the intersection point of the ray with the plane defined by the triangle. Then we check if this point is within the triangle or not.

Plane specification Introduction Recall that the plane V through the points a, b, and c can be written as p(β, γ) = a + β( b a) + γ( c a)

Plane specification Introduction Recall that the plane V through the points a, b, and c can be written as p(β, γ) = a + β( b a) + γ( c a)

Plane specification Introduction Recall that the plane V through the points a, b, and c can be written as p(β, γ) = a + β( b a) + γ( c a)

Ray-plane intersection Again, intersection points must fullfil the plane and the ray equation. Hence, we get e + t d = a + β( b a) + γ( c a) That give us...

Ray-plane intersection... the following three equations x e + tx d = x a + β(x b x a ) + γ(x c x a ) y e + ty d = y a + β(y b y a ) + γ(y c y a ) z e + tz d = z a + β(z b z a ) + γ(z c z a ) which can be rewritten as or as (x a x b )β + (x a x c )γ + x d t = x a x e (y a y b )β + (y a y c )γ + y d t = y a y e (z a z b )β + (z a z c )γ + z d t = z a z e x a x b x a x c x d β x a x e y a y b y a y c y d γ = y a y e z a z b z a z c z d t z a z e

Ray-plane intersection If we write x a x b x a x c x d β x a x e y a y b y a y c y d γ = y a y e z a z b z a z c z d t z a z e as then we see that β x a x e A γ = y a y e t z a z e β x a x e γ = A 1 y a y e t z a z e

Rays: parametric representation We can use t to calculate the intersection point p(t) (or β, γ to calculate p(β, γ)). And we can use β and γ to verify if it is inside of the triangle or not: β > 0 γ > 0 β + γ < 1

Ray-object intersection (implicit plane) Of course, we can also get the ray-plane intersection if the latter is given as implicit equation: ( p p 1 ) n = 0 Putting our ray p(t) = e + t d in this equation and solving for t gives us: t = ( p 1 e) n d n

If the plane was defined by a planar polygone, we can easily check if the resulting intersection point p(t) is within the polygone or not. Do you remember how?

A basic ray tracing algorithm FOR each pixel DO find 1st object hit by ray and surface normal n set pixel color to value computed from hit point, light, and n

model Introduction Remember our shading model: c = c r (c a + c l max(0, n l)) + c l ( h n) p with Ambient shading Lambertian shading Phong shading and Gouraud interpolation.

A basic ray tracing algorithm FOR each pixel DO compute viewing ray IF (ray hits an object with t [0, )) THEN Compute n Evaluate shading model and set pixel to that color ELSE set pixel color to background color

Shadows Ideal specular reflection Refraction Shadow feelers Shadows can be implemented fairly easy by so called shadow feelers / rays. Shoot a shadow ray p + t l from a point p towards a light source l. If ray hits object, p is in the shadow. Otherwise it s not. Because of potential precision issues, we often look at point p + ɛ l instead of p.

Shadows Ideal specular reflection Refraction Ideal specular or mirror reflection Key characteristic of a mirror: If looking from direction d to a spot on the reflecting surface, the viewer sees the same image as if looking from the surface point in direction r. Hence, we need to calculate the reflection vector: r = d 2( d n) n Then we shoot a ray in that direction.

Shadows Ideal specular reflection Refraction Ideal specular or mirror reflection

Shadows Ideal specular reflection Refraction Refraction Light traveling from one transparent medium into another one is refracted.

Shadows Ideal specular reflection Refraction Snell s law The angles before and after refraction are related as follows: n sin θ = n t sin φ. where n and n t are the refractive indices of the source and target media, respectively, and θ and φ the angles indicated in the image.

Shadows Ideal specular reflection Refraction Getting rid of sines An equation that relates sines of the angles θ and φ is not as convenient as an equation that relates the cosines of the angles. With the identity sin 2 φ + cos 2 φ = 1 we derive the following equation from Snell s law: cos 2 φ = 1 n2 (1 cos 2 θ) n 2 t

Shadows Ideal specular reflection Refraction Getting rid of sines Snell s law: n sin θ = n t sin φ sin φ = n n t sin θ Trigonometric identity: sin 2 φ + cos 2 φ = 1 And hence cos 2 φ = 1 sin 2 φ sin 2 φ = 1 cos 2 φ

Shadows Ideal specular reflection Refraction Constructing an orthonormal basis How do we find the refracted vector t? Assume the incoming vector d and the normal n are normalized. First, t lies in the plane spanned by d and n. Next, we can set up an orthonormal basis in this plane by picking an appropriate vector b.

Shadows Ideal specular reflection Refraction Finding the refraction vector We have t = b sin φ n cos φ d = b sin θ n cos θ

Shadows Ideal specular reflection Refraction Finding the refraction vector We have t = b sin φ n cos φ d = b sin θ n cos θ So we can solve for b: b = d+ n cos θ sin θ and for t: t = sin φ( d+ n cos θ) sin θ = n( d+ n cos θ) n t = n( d n( d n)) n t n cos φ n cos φ n 1 n2 (1 ( d n) 2 ) n 2 t

Instancing Constructive Solid Geometry Copying and transforming objects Instancing is an elegant technique to place various transformed copies of an object in a scene. Expl.: circle elipse O M 1 O M 3 O M 2 O M 4 O

Instancing Constructive Solid Geometry Copying and transforming objects Instead of making actual copies, we simply store a reference to a base object, together with a transformation matrix. That can save us lots of storage. Hmm, but how do we compute the intersection of a ray with a randomly rotated elipse? O M 1 O M 3 O M 4 O M 2 O

Instancing Constructive Solid Geometry Ray-instance intersection O p M 1 r MO Mp r

Instancing Constructive Solid Geometry Ray-instance intersection To determine the intersection q of a ray r with an instance MO, we first compute the intersection p of the inverse transformed ray M 1 r and the original object O. The point q is then simply M p. O MO p M 1 r Mp This way, complicated intersection tests (e.g. ray/ellipsoid) can often be replaced by simpler tests (ray/sphere). r

Instancing Constructive Solid Geometry Ray-instance intersection Two pitfalls: Surface normals transform differently! use (M 1 ) T instead of M 1 for normals The direction vector of the ray should not be normalized O MO p M 1 r Mp r

Instancing Constructive Solid Geometry Constructive Solid Geometry C S For ray tracing, we can basically use any object that allows us to calculate its intersection with a 3D line. Using Constructive Solid Geometry (CSG), we can build complex objects from simple ones with set operations. C S S C C S C S

Instancing Constructive Solid Geometry Intersections and CSG Big advantage: instead of actually constructing the objects, we can calculate ray-object intersections with the original objects and perform set operations on the resulting intervals. S C C S C S

Instancing Constructive Solid Geometry Intersections and CSG For every base object, we maintain an interval (or set of intervals) representing the part of the ray inside the object. The intervals for combined objects are computed with the same set operations that are applied to the base objects. S C C S C S