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

Similar documents
Computer Graphics CS 543 Lecture 11 (Part 1) Polygon Filling & Antialiasing

CS 4731/543: Computer Graphics Lecture 7 (Part I): Raster Graphics: Polygons & Antialiasing. Emmanuel Agu

? Which intermediate. Recall: Line drawing algorithm. Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path

CS 543: Computer Graphics. Rasterization

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

CS 543: Computer Graphics Lecture 10 (Part II): Raytracing (Part II) Emmanuel Agu

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

Introduction to Ray-tracing Objectives

Computer Graphics and Image Processing Ray Tracing I

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

Lecture 8 Ray tracing Part 1: Basic concept Yong-Jin Liu.

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

Supplement to Lecture 16

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

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

Intro to Ray-Tracing & Ray-Surface Acceleration

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

Painter s HSR Algorithm

Ray Tracing I. Internet Raytracing Competition

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

Ray Tracing I. History

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

COMP371 COMPUTER GRAPHICS

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

Ray Tracing Foley & Van Dam, Chapters 15 and 16

Viewing and Ray Tracing. CS 4620 Lecture 4

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

Viewing and Ray Tracing

Sung-Eui Yoon ( 윤성의 )

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

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

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

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

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

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

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

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

CS 563 Advanced Topics in Computer Graphics. by Emmanuel Agu

3D Rendering and Ray Casting

A Little Background. Motivation. Motivation

1999, Denis Zorin. Ray tracing

Lecture 11: Ray tracing (cont.)

Advanced Ray Tracing

Photorealism: Ray Tracing

3D Rendering and Ray Casting

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

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

Hidden Surface Elimination Raytracing. Pre-lecture business. Outline for today. Review Quiz. Image-Space vs. Object-Space

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

Ray Tracing Part 1. CSC418/2504 Introduction to Computer Graphics. TA: Muhammed Anwar & Kevin Gibson

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

Implementation Issues

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

To Shading and Beyond. CS 6965 Fall 2011

CS 4204 Computer Graphics

Ray Tracing. CS 4620 Lecture 5

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

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

Lecture 11. More Ray Casting/Tracing

Assignment 6: Ray Tracing

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

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

Ray Tracing COMP575/COMP770

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

CS770/870 Spring 2017 Ray Tracing Implementation

Questions??? Announcements Assignment 3 due today

Ray Tracing. Outline. Ray Tracing: History

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

Intersecting Simple Surfaces. Dr. Scott Schaefer

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

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

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

Ray-tracing Cont. Ray-tracing

EF432. Introduction to spagetti and meatballs

Ray Tracing. Kjetil Babington

CS 130 Exam I. Fall 2015

Distribution Ray-Tracing. Programação 3D Simulação e Jogos

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

Assignment 2 Ray Tracing

Rendering. Generate an image from geometric primitives II. Rendering III. Modeling IV. Animation. (Michael Bostock, CS426, Fall99)

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

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

Logistics. CS 586/480 Computer Graphics II. Questions from Last Week? Slide Credits

EF432. Introduction to spagetti and meatballs

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

Project 3 Path Tracing

Ray tracing idea. Ray Tracing. Ray tracing algorithm. Plane projection in drawing. CS 465 Lecture 3

Topics and things to know about them:

Animation and Ray Tracing

Ray Casting. Connelly Barnes CS 4810: Graphics

Werner Purgathofer

Questions from Last Week? Extra rays needed for these effects. Shadows Motivation

CS 431/636 Advanced Rendering Techniques

Global Rendering. Ingela Nyström 1. Effects needed for realism. The Rendering Equation. Local vs global rendering. Light-material interaction

Ray Tracing. Shandong University

Anti-aliasing and Monte Carlo Path Tracing. Brian Curless CSE 457 Autumn 2017

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

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

lecture 19 Shadows - ray tracing - shadow mapping - ambient occlusion Interreflections

Transcription:

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

Ray Casting (Appel, 1968) direct illumination

Recursive ray tracing (Whitted, 1980)

Pseudocode for Ray Tracer Basic idea color Raytracer{ for(each pixel direction){ determine first object in this pixel direction calculate color shade return shade color } }

More Detailed Ray Tracer Pseudocode Define the objects and light sources in the scene Set up the camera For(int r = 0; r < nrows; r++){ for(int c = 0; c < ncols; c++){ 1. Build the rc-th ray 2. Find all object intersections with rc-th ray 3. Identify closest object intersection 4. Compute the hit point where the ray hits the object, and normal vector at that point 5. Find color of light to eye along ray 6. Set rc-th pixel to this color } }

Build the RC-th Ray Parametric expression ray starting at eye and passing through pixel at row r, and column c ray r( t) r( t) = origin + ( direction) t = eye + dir = o + dt rc t But what exactly is this dir rc (t)? need to express ray direction in terms of variables r and c Now need to set up camera, and then express dir rc in terms of camera r and c

Building the Ray

Building the Ray

Camera: Perspective Viewing

Pixel Screen Coordinates

Calculate Pixel Position

Calculating Primary Rays Given (in world coordinates) Camera (eye point) location O Camera view out direction (Z v ) Camera view up vector (Y v ) Distance to image plane (d) Horizontal camera view angle (θ) Pixel resolution of image plane (h res,v res ) Calculate set of rays (d) that equally samples the image plane

Calculate Preliminary Values Camera view side direction (X v ) Y v Z v Horizontal length of image plane (s j ) Next slide Vertical length of image plane (s k ) s k =s j (v res /h res ) Assume square pixels

Calculating s j h = d tan(θ/2) s j = 2h s j = 2d tan(θ/2)

Calculate Preliminary Values Position of top left pixel (P 0,0 ) O + d Z v -(S j /2) X v + (S k /2) Y v All in world coordinates!

Calculate Those Rays! P 0,0 + α X v - β Y v sweeps out image plane 0 α S j; 0 β S k for (j=0; j++; j < h res ) for (k=0; k++; k < v res ) { } d j,k = (P 0,0 + S j (j/(h res -1)) X v -S k (k/(v res -1)) Y v ) - O; d j,k = d j,k / d j,k ; Image[j,k] = ray_trace(o, d j,k, Scene);

Parameters X and Y resolution of image Camera location & direction Distance between camera & image plane Camera view angle Distance between pixels These are not independent! Goal Choose your independent variables and calculate your d s

I recommend setting X and Y resolution of image (h res,v res ) Camera location & orientation O & Z v & Y v Distance between camera & image plane d (a positive scalar, e.g. 10) Camera view angle θ

Find Object Intersections with rc-th ray Much of work in ray tracing lies in finding intersections with generic objects Break into two parts Deal with untransformed, generic (dimension 1) shape Then embellish to deal with transformed shape Ray generic object intersection best found by using implicit form of each shape. E.g. generic sphere is F( x, y, z) 2 2 2 = x + y + z 1 Approach: ray r(t) hits a surface when its implicit eqn = 0 So for ray with starting point o and direction d r( t) = o + dt F( o + d ) = 0 t hit

Ray Intersection with Generic Plane Generic Plane? Yes! Floors, walls, in a room, etc Generic plane is xy-plane, or z = 0 For ray r( t) = o + dt There exists a t hit such that o z + d zth = 0 Solving, t hit = o d z z

Hit point P hit is given by Ray Intersection with Generic Plane Phit = o d( o z / d z ) Numerical example? Where does the ray r(t) = (4, 1, 3) + (-3, -5, -3)t hit the generic plane? Soln: t hit = o d z z = 3 = 3 1 And hit point is given by o + d = ( 1, 4,0)

Ray-Sphere Intersection G. Drew Kessler Larry Hodges Georgia Institute of Technology

Ray/Sphere Intersection (Algebraic Solution) Ray is defined by R(t) = R o + R d *t where t > 0. R o = Origin of ray at (x o,y o,z o ) R d = Direction of ray [x d, y d,z d ] (unit vector) Sphere's surface is defined by the set of points {(x s,y s,z s )} satisfying the equation: (x s - x c ) 2 + (y s -y c ) 2 + (z s - z c ) 2 - r s2 = 0 Center of sphere: (x c,y c,z c ) Radius of sphere: r s

Possible Cases of Ray/Sphere Intersection 1 2 1. Ray intersects sphere twice with t>0 2. Ray tangent to sphere 3 4 5 3. Ray intersects sphere with t<0 4. Ray originates inside sphere 5. Ray does not intersect sphere

Solving For t Substitute the basic ray equation: x = x o +x d *t y = y o + y d *t z = z o +z d *t into the equation of the sphere: (x 0 +x d t-x c ) 2 + (y 0 +y d t-y c ) 2 + (z 0 +z d t-z c ) 2 -r s 2 = 0 This is a quadratic equation in t: At 2 + Bt + C = 0, where A = x d2 + y d2 + z d 2 B = 2[x d (x 0 -x c ) + y d (y 0 -y c ) + z d (z 0 -z c )] C = (x 0 -x c ) 2 + (y 0 -y c ) 2 + (z 0 -z c ) 2 -r s 2 Note: A=1

Relation of t to Intersection We want the smallest positive t - call it t i t 0 t 1 t 0 Discriminant = 0 t 0 t 1 t 1 t 0 Discriminant < 0 t t 0 1 B = B + = B 2 B 2 2 2 4AC 4AC

Actual Intersection Intersection point, (x i, y i, z i ) = (x o +x d *t i, y o +y d *t i, z o +z d *t i ) Unit vector normal to the surface at this point is N = [(x i -x c ) / r s, (y i -y c ) / r s, (z i -z c ) / r s ] If the ray originates inside the sphere, N should be negated so that it points back toward the center. N N

Summary (Algebraic Solution) 1. Calculate A, B and C of the quadratic intersection equation 2. Calculate discriminant (If < 0, then no intersection) 3. Calculate t 0 4. If t 0 < 0, then calculate t 1 (If t 1 < 0, no intersection point on ray) 5. Calculate intersection point 6. Calculate normal vector at point Helpful pointers: Precompute r s 2 Precompute 1/r s If computed t is very small then, due to rounding error, you may not have a valid intersection

Antialiasing Raster displays have pixels as rectangles Aliasing: Discrete nature of pixels introduces jaggies

Aliasing effects: Distant objects may disappear entirely Objects can blink on and off in animations Antialiasing Antialiasing techniques involve some form of blurring to reduce contrast, smoothen image Three antialiasing techniques: Prefiltering Postfiltering Supersampling

Basic idea: compute area of polygon coverage use proportional intensity value Example: if polygon covers ¼ of the pixel use ¼ polygon color add it to ¾ of adjacent region color Prefiltering Cons: computing pixel coverage can be time consuming

Supersampling Useful if we can compute color of any (x,y) value on the screen Increase frequency of sampling Instead of (x,y) samples in increments of 1 Sample (x,y) in fractional (e.g. ½) increments Find average of samples Example: Double sampling = increments of ½ = 9 color values averaged for each pixel Average 9 (x, y) values to find pixel color

Postfiltering Supersampling uses average Gives all samples equal importance Post-filtering: use weighting (different levels of importance) Compute pixel value as weighted average Samples close to pixel center given more weight Sample weighting 1/16 1/16 1/16 1/16 1/16 1/2 1/16 1/16 1/16

References/Shamelessly stolen Kevin Suffern, Ray Tracing from the Ground up David Breen, Drexel University CS 431/636 Advanced Rendering Techniques Hill and Kelley, Computer Graphics using OpenGL, 3 rd edition