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

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

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

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

Ray Tracing. Outline. Ray Tracing: History

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

Ray Casting. To Do. Outline. Outline in Code. Foundations of Computer Graphics (Spring 2012) Heckbert s Business Card Ray Tracer

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

Sung-Eui Yoon ( 윤성의 )

Lecture 11: Ray tracing (cont.)

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

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

CS559: Computer Graphics

CS Simple Raytracer for students new to Rendering

CPSC GLOBAL ILLUMINATION

Intro to Ray-Tracing & Ray-Surface Acceleration

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. Lecture 10. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura 12/03/15

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

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

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

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

CS 184: Assignment 4 Simple Raytracer

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

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

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

Ray Casting. Outline. Outline in Code

COMP371 COMPUTER GRAPHICS

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

Assignment 6: Ray Tracing

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

Lecture 11. More Ray Casting/Tracing

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

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

03 RENDERING PART TWO

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

Ray-Tracing. Misha Kazhdan

Ray Tracer Due date: April 27, 2011

The Traditional Graphics Pipeline

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

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

Computer Graphics Ray Casting. Matthias Teschner

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

Photorealism: Ray Tracing

Illumination Algorithms

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

Questions??? Announcements Assignment 3 due today

The Traditional Graphics Pipeline

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

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

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

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

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

Ray Tracing Foley & Van Dam, Chapters 15 and 16

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

Announcements. Written Assignment 2 out (due March 8) Computer Graphics

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

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

Chapter 7 - Light, Materials, Appearance

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

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

Graphics Pipeline. CS535 Fall Daniel G. Aliaga Department of Computer Science Purdue University

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics

Advanced Ray Tracing

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

Computer Graphics and Image Processing Ray Tracing I

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

Computer Graphics I Lecture 11

Review for Ray-tracing Algorithm and Hardware

Lecture 10: Ray tracing

Parallelization. Memory coherency helps when distributing rays to various threads/processors

The Traditional Graphics Pipeline

COMS 4160: Problems on Transformations and OpenGL

Introduction to Visualization and Computer Graphics

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

Other Rendering Techniques CSE 872 Fall Intro You have seen Scanline converter (+z-buffer) Painter s algorithm Radiosity CSE 872 Fall

Computer Graphics. Bing-Yu Chen National Taiwan University

Ray tracing. EECS 487 March 19,

A Little Background. Motivation. Motivation

CS-184: Computer Graphics. Administrative

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

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

Supplement to Lecture 16

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

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Global Illumination. COMP 575/770 Spring 2013

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

1999, Denis Zorin. Ray tracing

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Ray Tracing. Cornell CS4620/5620 Fall 2012 Lecture Kavita Bala 1 (with previous instructors James/Marschner)

Ray Tracing. Kjetil Babington

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

Photon Mapping. Due: 3/24/05, 11:59 PM

Raytracing CS148 AS3. Due :59pm PDT

Spatial Data Structures

CHAPTER 1 Graphics Systems and Models 3

Computer Graphics -Ray Tracing- 1 st quarter, 2015 Nara Institute of Science and Technology May 21, 2015

Transcription:

Sampling and Reconstruction of Visual Appearance CSE 274 [Fall 2018], Special Lecture Ray Tracing Ravi Ramamoorthi http://www.cs.ucsd.edu/~ravir Motivation Ray Tracing is a core aspect of both offline and realtime rendering today Basic topic which I cover in CSE 167 But not everyone does, this class also covers 168 (ray tracing is a prelude to key path tracing algorithm) Background for some (most?) of you, but critical topic for those who haven t seen it before, go over it fast Important if you want to do the optional path tracer assignment (includes a ray tracing assignment) http://www.edx.org/course/computer-graphics Effects needed for Realism (Soft) Shadows Reflections (Mirrors and Glossy) Transparency (Water, Glass) Interreflections (Color Bleeding) Complex Illumination (Natural, Area Light) Realistic Materials (Velvet, Paints, Glass) And many more Image courtesy Paul Heckbert 1983 Ray Tracing Different Approach to Image Synthesis as compared to Hardware pipeline (OpenGL) Pixel by Pixel instead of Object by Object Easy to compute shadows/transparency/etc 1

Ray Tracing: History Ray Tracing History Appel 68 Whitted 80 [recursive ray tracing] Landmark in computer graphics Lots of work on various geometric primitives Lots of work on accelerations Real-Time raytracing (historically, slow technique) Ray tracing architecture Ray Tracing History in Code Image Raytrace (Camera cam, Scene scene, int width, int height) { Image image = new Image (width, height) ; for (int i = 0 ; i < height ; i++) for (int j = 0 ; j < width ; j++) { Ray ray = RayThruPixel (cam, i, j) ; Intersection hit = Intersect (ray, scene) ; image[i][j] = FindColor (hit) ; return image ; Ray Casting Produce same images as with OpenGL Visibility per pixel instead of Z-buffer Find nearest object by shooting rays into scene Shade it as in standard OpenGL 2

Ray Casting Comparison to hardware scan-line Per-pixel evaluation, per-pixel rays (not scan-convert each object). On face of it, costly Virtual Viewpoint But good for walkthroughs of extremely large models (amortize preprocessing, low complexity) More complex shading, lighting effects possible Virtual Screen Objects Ray Multiple misses intersects intersections: all object: objects: shade Pixel Use using colored closest color, black one lights, (as does materials OpenGL) Finding Ray Direction Goal is to find ray direction for given pixel i and j Many ways to approach problem Objects in world coord, find dirn of each ray (we do this) Camera in canonical frame, transform objects (OpenGL) Basic idea Ray has origin (camera center) and direction Find direction given camera params and i and j Camera params as in glulookat Lookfrom[3], LookAt[3], up[3], fov Similar to glulookat derivation glulookat(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) Camera at eye, looking at center, with up direction being up Eye Up vector Center From OpenGL lecture on deriving glulookat (see edx MOOC) Constructing a coordinate frame? We want to associate w with a, and v with b But a and b are neither orthogonal nor unit norm And we also need to find u w = a a u = b w b w v = w u From basic math lecture - Vectors: Orthonormal Basis Frames Camera coordinate frame w = a a u = b w b w We want to position camera at origin, looking down Z dirn Hence, vector a is given by eye center The vector b is simply the up vector Up vector Eye v = w u Center 3

Canonical viewing geometry -w αu α = tan fovx j (width / 2) 2 width / 2 βv ray = eye + αu + βv w αu + βv w β = tan fovy 2 (height / 2) i height / 2 Ray/Object Intersections Heart of Ray Tracer One of the main initial research areas Optimized routines for wide variety of primitives Various types of info Shadow rays: Intersection/No Intersection Primary rays: Point of intersection, material, normals Texture coordinates Work out examples Triangle, sphere, polygon, general implicit surface in Code Image Raytrace (Camera cam, Scene scene, int width, int height) { Image image = new Image (width, height) ; for (int i = 0 ; i < height ; i++) for (int j = 0 ; j < width ; j++) { Ray ray = RayThruPixel (cam, i, j) ; Intersection hit = Intersect (ray, scene) ; image[i][j] = FindColor (hit) ; return image ; Ray-Sphere Intersection ray P = P 0 + P 1 t sphere ( P C) i ( P C) r 2 = 0 P 0 C Ray-Sphere Intersection ray P = P 0 t sphere ( P C) i ( P C) r 2 = 0 Substitute Simplify ray P = P 0 t sphere ( P 0 t C) i ( P 0 t C) r 2 = 0 t 2 ( P 1 i P 1 ) + 2t P 1 i ( P 0 C) + ( P 0 C) i ( P 0 C) r 2 = 0 4

Ray-Sphere Intersection t 2 ( P 1 i P 1 ) + 2t P 1 i ( P 0 C) + ( P 0 C) i ( P 0 C) r 2 = 0 Solve quadratic equations for t 2 real positive roots: pick smaller root Both roots same: tangent to sphere One positive, one negative root: ray origin inside sphere (pick + root) Complex roots: no intersection (check discriminant of equation first) Ray-Sphere Intersection Intersection point: ray P = P 0 t Normal (for sphere, this is same as coordinates in sphere frame of reference, useful other tasks) P C normal = P C Ray-Triangle Intersection One approach: Ray-Plane intersection, then check if inside triangle B Plane equation: A n = (C A) (B A) (C A) (B A) Ray-Triangle Intersection One approach: Ray-Plane intersection, then check if inside triangle B Plane equation: A n = (C A) (B A) (C A) (B A) plane P i n A i n = 0 C plane P i n A i n = 0 Combine with ray equation: ray P = P 0 t ( P 0 t) i n = A i n C A i n P t = 0 i n P 1 i n Ray inside Triangle Once intersect with plane, still need to find if in triangle Many possibilities for triangles, general polygons (point in polygon tests) We find parametrically [barycentric coordinates]. Also useful for other applications (texture mapping) A α β P γ B P = αa + βb + γ C α 0, β 0,γ 0 α + β + γ = 1 A Ray inside Triangle B P = αa + βb + γ C α β P α 0, β 0,γ 0 α + β + γ = 1 γ C P A = β(b A) + γ (C A) 0 β 1, 0 γ 1 β + γ 1 C 5

Other primitives Ray Scene Intersection Much early work in ray tracing focused on rayprimitive intersection tests Cones, cylinders, ellipsoids Boxes (especially useful for bounding boxes) General planar polygons Many more Transformed Objects E.g. transform sphere into ellipsoid Could develop routine to trace ellipsoid (compute parameters after transformation) May be useful for triangles, since triangle after transformation is still a triangle in any case But can also use original optimized routines Ray-Tracing Transformed Objects We have an optimized ray-sphere test But we want to ray trace an ellipsoid Solution: Ellipsoid transforms sphere Apply inverse transform to ray, use ray-sphere Allows for instancing (traffic jam of cars) Same idea for other primitives Transformed Objects Consider a general 4x4 transform M Will need to implement matrix stacks like in OpenGL Apply inverse transform M -1 to ray Locations stored and transform in homogeneous coordinates Vectors (ray directions) have homogeneous coordinate set to 0 [so there is no action because of translations] Do standard ray-surface intersection as modified Transform intersection back to actual coordinates Intersection point p transforms as Mp Distance to intersection if used may need recalculation Normals n transform as M -t n. Do all this before lighting 6

in Code Image Raytrace (Camera cam, Scene scene, int width, int height) { Image image = new Image (width, height) ; for (int i = 0 ; i < height ; i++) for (int j = 0 ; j < width ; j++) { Ray ray = RayThruPixel (cam, i, j) ; Intersection hit = Intersect (ray, scene) ; image[i][j] = FindColor (hit) ; return image ; Virtual Viewpoint Shadows Virtual Screen Objects Shadow ray to to light is is unblocked: object visible in shadow Light Source Shadows: Numerical Issues Numerical inaccuracy may cause intersection to be below surface (effect exaggerated in figure) Causing surface to incorrectly shadow itself Move a little towards light before shooting shadow ray n Shading Model I = K a + K e + V i L i (K d max (l i i n,0) + K s (max(h i i n,0)) s ) i=1 Global ambient term, emission from material For each light, diffuse specular terms Note visibility/shadowing for each light (not in OpenGL) Evaluated per pixel per light (not per vertex) Mirror Reflections/Refractions Virtual Viewpoint Virtual Screen Generate reflected ray in mirror direction, Get reflections and refractions of objects Objects Turner Whitted 1980 7

Recursive Ray Tracing For each pixel Trace Primary Eye Ray, find intersection Trace Secondary Shadow Ray(s) to all light(s) Color = Visible? Illumination Model : 0 ; Trace Reflected Ray Color += reflectivity * Color of reflected ray Recursive Shading Model n I = K a + K e + V i L i (K d max (l i i n,0) + K s (max(h i i n,0)) s ) + K s I R + K T I T i=1 Highlighted terms are recursive specularities [mirror reflections] and transmission (latter is extra credit) Trace secondary rays for mirror reflections and refractions, include contribution in lighting model GetColor calls RayTrace recursively (the I values in equation above of secondary rays are obtained by recursive calls) Problems with Recursion Reflection rays may be traced forever Generally, set maximum recursion depth Same for transmitted rays (take refraction into account) Effects needed for Realism (Soft) Shadows Reflections (Mirrors and Glossy) Transparency (Water, Glass) Interreflections (Color Bleeding) Complex Illumination (Natural, Area Light) Realistic Materials (Velvet, Paints, Glass) Discussed in this lecture Not discussed but possible with distribution ray tracing Hard (but not impossible) with ray tracing; path tracing next time Some basic add ons Area light sources and soft shadows: break into grid of n x n point lights Use jittering: Randomize direction of shadow ray within small box for given light source direction Jittering also useful for antialiasing shadows when shooting primary rays More complex reflectance models Simply update shading model But at present, we can handle only mirror global illumination calculations 8

Acceleration Testing each object for each ray is slow Fewer Rays Adaptive sampling, depth control Generalized Rays Beam tracing, cone tracing, pencil tracing etc. Faster Intersections Optimized Ray-Object Intersections Fewer Intersections Acceleration Structures Bounding boxes (possibly hierarchical) If no intersection bounding box, needn t check objects Ray Bounding Box Spatial Hierarchies (Oct-trees, kd trees, BSP trees) We just discuss some approaches at high level Acceleration Structures: Grids Acceleration and Regular Grids Simplest acceleration, for example 5x5x5 grid For each grid cell, store overlapping triangles March ray along grid (need to be careful with this), test against each triangle in grid cell More sophisticated: kd-tree, oct-tree bsp-tree Or use (hierarchical) bounding boxes Some acceleration is critical for path tracing Interactive Raytracing Ray tracing historically slow Now viable alternative for complex scenes Key is sublinear complexity with acceleration; need not process all triangles in scene Allows many effects hard in hardware NVIDIA OptiX ray-tracing API like OpenGL Recent NVIDIA OptiX release major advance Ray tracing now practical for games Integration with Microsoft s DirectX Dedicated Hardware Machine Learning for denoising (later in course) 9

Raytracing on Graphics Hardware Modern Programmable Hardware general streaming architecture Can map various elements of ray tracing Kernels like eye rays, intersect etc. In vertex or fragment programs Convergence between hardware, ray tracing [Purcell et al. 2002, 2003] http://graphics.stanford.edu/papers/photongfx 10