Advanced Computer Graphics (Fall 2010) CS 283, Lecture 2: Basic Ray Tracing Ravi Ramamoorthi Some slides courtesy.

Slides:



Advertisements
Similar presentations
13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.
Advertisements

Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Graphics Pipeline.
Lecture 14 Illumination II – Global Models
Shadow Rendering Techniques A point is in the shadow of a light source if it can not be “seen” by the light source, i.e. the line segment that connects.
David Luebke1/19/99 CS 551/651: Advanced Computer Graphics David Luebke
Light Issues in Computer Graphics Presented by Saleema Amershi.
Christian Lauterbach COMP 770, 2/11/2009
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Alla Sheffer Advanced Rendering Week.
Advanced Computer Graphics (Spring 2005) COMS 4162, Lecture 15: Ray Tracing/Global Illumination Ravi Ramamoorthi Slides.
CS6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003 Object-Order vs. Screen-Order Rendering April 24, 2003.
Computer Graphics (Fall 2005) COMS 4160, Lecture 21: Ray Tracing
(conventional Cartesian reference system)
CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
3D Graphics Processor Architecture Victor Moya. PhD Project Research on architecture improvements for future Graphic Processor Units (GPUs). Research.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 14: Ray Tracing
Ray Tracing Outline For each pixel { Shoot ray r from eye to center of pixel with trace( r ) } function trace( r ) For each object { Find object with closest.
Ray Tracing Jerry Sui Adam Conner. Part I – Introduction to Ray Tracing Final Product.
1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok
Computer Graphics (Fall 2008) COMS 4160, Lecture 4: Transformations 2
CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
CSC418 Computer Graphics n Raytracing n Shadows n Global Illumination.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
Ray Tracing Primer Ref: SIGGRAPH HyperGraphHyperGraph.
Advanced Rendering University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner.
COMP 175: Computer Graphics March 24, 2015
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
12/05/02(c) 2002 University of Wisconsin Last Time Subdivision techniques for modeling Very brief intro to global illumination.
-Global Illumination Techniques
Ray Tracing Sang Il Park SEjong University With lots of slides stolen from Jehee Lee, Doug James, Steve Seitz, Shree Nayar, Alexei Efros, Fredo Durand.
Ray Tracing Chapter CAP4730: Computational Structures in Computer Graphics.
Raytracing and Global Illumination Intro. to Computer Graphics, CS180, Fall 2008 UC Santa Barbara.
Foundations of Computer Graphics (Spring 2012) CS 184, Lectures 16, 18: Nuts and bolts of Ray Tracing Acknowledgements:
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 4: Transformations 2
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Slides from Brian Curless at U of Washington.
CS380: Computer Graphics Distributed Ray Tracing TA Course URL:
CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U.
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection.
Advanced topics Advanced Multimedia Technology: Computer Graphics Yung-Yu Chuang 2006/01/04 with slides by Brian Curless, Zoran Popovic, Mario Costa Sousa.
CSCE 441: Computer Graphics Ray Tracing
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
CS 445 / 645 Introduction to Computer Graphics Lecture 16 Lighting Lighting.
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
RENDERING : Global Illumination
CSE 681 Introduction to Ray Tracing. CSE 681 Ray Tracing Shoot a ray through each pixel; Find first object intersected by ray. Image plane Eye Compute.
Global Illumination (3) Path Tracing. Overview Light Transport Notation Path Tracing Photon Mapping.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
David Luebke3/12/2016 Advanced Computer Graphics Lecture 3: More Ray Tracing David Luebke
CS559: Computer Graphics Lecture 27: Animation, Depth & Motion Blur, Ray Tracing Li Zhang Spring 2010 Slides from Brian Curless at U of Washington.
CS559: Computer Graphics Lecture 27: Animation, Depth & Motion Blur, Ray Tracing Li Zhang Spring 2010 Slides from Brian Curless at U of Washington.
Ray Tracing I. Reading Hill, Chapter 14, Sections 14.1 to 14.5 Hill, Chapter 14, Sections and
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
CS552: Computer Graphics Lecture 36: Ray Tracing.
Review Ray Tracing III Review. Pseudo codes RayCast-1  Plain ray caster (direct illumination) RayCast-2  RayCast-1 + shadow rays RayTrace-1  Recursive.
Basic Ray Tracing CMSC 435/634.
Advanced Computer Graphics
Computer Graphics CSE 167 [Win 17], Lectures 16, 17:
CSE 167 [Win 17], Lecture 15: Ray Tracing Ravi Ramamoorthi
Photorealistic Rendering vs. Interactive 3D Graphics
© University of Wisconsin, CS559 Fall 2004
GR2 Advanced Computer Graphics AGR
Presentation transcript:

Advanced Computer Graphics (Fall 2010) CS 283, Lecture 2: Basic Ray Tracing Ravi Ramamoorthi Some slides courtesy Thomas Funkhouser and Pat Hanrahan

Basics  Start working on raytracer assignment (if necessary)  First 3 lectures cover basic topics  Rendering: Raytracing (required for homeworks 2, 3)  Fourier Analysis and Sampling  3D objects and meshes  Then we start main part of course  Meshes and assignment 1  This lecture review for most of you  But needed to bring everyone up to speed  Will go through it fast since very basic material

Ray Tracing History

Image courtesy Paul Heckbert 1983

Outline  Camera Ray Casting (choosing ray directions)  Ray-object intersections  Ray-tracing transformed objects  Lighting calculations  Recursive ray tracing

Outline 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 Virtual Viewpoint Virtual ScreenObjects Ray misses all objects: Pixel colored blackRay intersects object: shade using color, lights, materialsMultiple intersections: Use closest one (as does 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

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

Camera coordinate frame  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 Eye Up vector Center

Canonical viewing geometry -w αuαu βvβv

Outline  Camera Ray Casting (choosing ray directions)  Ray-object intersections  Ray-tracing transformed objects  Lighting calculations  Recursive ray tracing

Outline 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 C P0P0

Substitute Simplify

Ray-Sphere Intersection 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:  Normal (for sphere, this is same as coordinates in sphere frame of reference, useful other tasks)

Ray-Triangle Intersection  One approach: Ray-Plane intersection, then check if inside triangle  Plane equation: A B C

Ray-Triangle Intersection  One approach: Ray-Plane intersection, then check if inside triangle  Plane equation:  Combine with ray equation: A B C

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 B C P α β γ

Ray inside Triangle A B C P α β γ

Other primitives  Much early work in ray tracing focused on ray- primitive intersection tests  Cones, cylinders, ellipsoides  Boxes (especially useful for bounding boxes)  General planar polygons  Many more  Many references. For example, chapter in Glassner introduction to ray tracing (see me if interested)

Ray Scene Intersection

Outline  Camera Ray Casting (choosing ray directions)  Ray-object intersections  Ray-tracing transformed objects  Lighting calculations  Recursive ray tracing

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

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

Outline  Camera Ray Casting (choosing ray directions)  Ray-object intersections  Ray-tracing transformed objects  Lighting calculations  Recursive ray tracing

Outline 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 ; }

Shadows Virtual Viewpoint Virtual ScreenObjects Light Source Shadow ray to light is unblocked: object visibleShadow ray to light is blocked: object in shadow

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

Lighting Model  Similar to OpenGL  Lighting model parameters (global)  Ambient r g b (no per-light ambient as in OpenGL)  Attenuation const linear quadratic (like in OpenGL)  Per light model parameters  Directional light (direction, RGB parameters)  Point light (location, RGB parameters)

Material Model  Diffuse reflectance (r g b)  Specular reflectance (r g b)  Shininess s  Emission (r g b)  All as in OpenGL

Shading Model  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)

Outline  Camera Ray Casting (choosing ray directions)  Ray-object intersections  Ray-tracing transformed objects  Lighting calculations  Recursive ray tracing

Mirror Reflections/Refractions Virtual Viewpoint Virtual ScreenObjects Generate reflected ray in mirror direction, Get reflections and refractions of objects

Turner Whitted 1980

Basic idea 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  Highlighted terms are recursive specularities [mirror reflections] and transmission  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 so far Not discussed but possible with distribution ray tracing Hard (but not impossible) with ray tracing; radiosity methods

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

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 Bounding Box Ray Spatial Hierarchies (Oct-trees, kd trees, BSP trees)

Bounding Volume Hierarchies 1

Bounding Volume Hierarchies 2

Bounding Volume Hierarchies 3

Acceleration Structures: Grids

Uniform Grid: Problems

Octree

Octree traversal

Other Accelerations

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  OpenRT project real-time ray tracing (

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  NVIDIA now has CUDA-based raytracing API ! [Purcell et al. 2002, 2003]