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

Similar documents
Photorealism: Ray Tracing

Ray Tracing I. Internet Raytracing Competition

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

Ray Tracing Foley & Van Dam, Chapters 15 and 16

Intro to Ray-Tracing & Ray-Surface Acceleration

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

Ray Tracing I. History

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

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.

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

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

CPSC GLOBAL ILLUMINATION

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

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

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

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

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

Computer Graphics 7: Viewing in 3-D

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

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

Introduction to Ray-tracing Objectives

3D Rendering and Ray Casting

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Rendering. Mike Bailey. Rendering.pptx. The Rendering Equation

CS 130 Exam I. Fall 2015

CSE528 Computer Graphics: Theory, Algorithms, and Applications

8.1 Geometric Queries for Ray Tracing

Computer Graphics and Image Processing Ray Tracing I

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

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

3D Rendering and Ray Casting

Ray Tracing. Outline. Ray Tracing: History

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

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

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

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

Supplement to Lecture 16

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

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

Overview: Ray Tracing & The Perspective Projection Pipeline

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

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

COMP371 COMPUTER GRAPHICS

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

Ray Tracing. Brian Curless CSEP 557 Fall 2016

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

782 Schedule & Notes

Topics and things to know about them:

CS 130 Exam I. Fall 2015

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

Shading, Advanced Rendering. Week 7, Wed Feb 28

Ray Tracing. Kjetil Babington

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

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

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

Intro to Modeling Modeling in 3D

BSP Trees. Chapter Introduction. 8.2 Overview

Algebra Based Physics

Viewing with Computers (OpenGL)

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

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

RAYTRACING. Christopher Peters INTRODUCTION TO COMPUTER GRAPHICS AND INTERACTION. HPCViz, KTH Royal Institute of Technology, Sweden

Last week. Machiraju/Zhang/Möller

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

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

CMSC427 Final Practice v2 Fall 2017

Models and Architectures

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

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Assignment 6: Ray Tracing

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

Ray Tracer Due date: April 27, 2011

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

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

Point Cloud Filtering using Ray Casting by Eric Jensen 2012 The Basic Methodology

Computer Graphics. Lecture 9 Environment mapping, Mirroring

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

Questions??? Announcements Assignment 3 due today

CS 4204 Computer Graphics

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

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

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

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]

CSE328 Fundamentals of Computer Graphics

Chapter 32 Light: Reflection and Refraction. Copyright 2009 Pearson Education, Inc.

Lecture 11. More Ray Casting/Tracing

Computer Graphics. Chapter 1 (Related to Introduction to Computer Graphics Using Java 2D and 3D)

Sung-Eui Yoon ( 윤성의 )

Ray Tracing. Shandong University

Ray-Tracing. Misha Kazhdan

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

COMPUTER GRAPHICS AND INTERACTION

Ray Tracing: Intersection

CHAPTER 1 Graphics Systems and Models 3

Photorealism. Photorealism: Ray Tracing. Ray Tracing

Light: Geometric Optics

CS348B Lecture 2 Pat Hanrahan, Spring Greeks: Do light rays proceed from the eye to the light, or from the light to the eye?

Transcription:

Ray Tracing Basics I Computer Graphics as Virtual Photography Photography: real scene camera (captures light) photo processing Photographic print processing Computer Graphics: 3D models camera model (focuses simulated lighting) tone reproduction synthetic image 1

Ray Tracing in the real world Light is emitted from light source Bounces off of the environment Assumptions Light travels in straight rays Path of light changes based on object interaction. Can simulate using basic geometry. Some light will reach and be focused by camera onto film plane. Lots of light will not! In image synthesis, we are only interested in the light that does Backwards Ray Tracing Light rays are traced backward from the eye (center of projection), through a viewing plane, into scene to see what it hits. The pixel is then set to the color values returned by the ray. This color is a result of the object hit by the ray. Turner Whitted 2

Insert Cheesy Ray Tracing Movie Here Ray Tracing - Basics Sometimes you don t hit an object 3

Ray Tracing - Basics Sometimes you do Ray Tracing - Basics If you do hit an object, additional rays are spawned and sent into world to determine color at intersection point Shadow ray Reflected ray Transmitted ray 4

Ray Tracing - Basics Shadow ray Ray spawned toward each light source to see if point is in shadow. Ray Tracing - Basics Shadow ray 5

Ray Tracing Reflective Ray Ray Tracing Transmitted ray 6

Recursive Ray Tracing Ray Tracing Ray Tracing incorporates into a single framework: Hidden surface removal Shadow computation Reflection of light Refraction of light Global Specular Interaction Extremely elegant and compact 7

Ray Tracing Basics Basic Ray Tracing -- Example Whitted Ray Tracing Assignment For Checkpoint 2: Trace rays through camera model Using ray tracing for visible surface determination. Questions -- Break 8

Ray Tracing through the Camera Issues Ray Geometry Object-Ray Intersection Projection Introducing Ray Use mathematical description of a ray and objects to determine intersection. Parametric representation of a ray: Origin of ray, P o = (x o,y o,z o ) Direction D = (dx, dy, dz) Ray (ω) = P o + ω D If D is normalized, then ω will be the distance from origin of the ray. 9

Ray-Object Intersection Most of the computation in ray tracing is determining ray object-intersection When a ray intersects an object, we need to know: Point of intersection Normal of surface at point of intersection Ray-Sphere Intersection The Sphere A sphere can be defined by: Center (x c, y c, z c ) Radius r Equation of a point (x s, y s, z s ) on a sphere: 2 2 2 2 ( xs! xc ) + ( ys! yc ) + ( zs! zc ) = r 10

Ray-Sphere Intersection Ray - Sphere Intersection Substituting ray equation for (x s, y s, z s ) We get: A ω 2 + B ω + C = 0 where 2 2 2 A = dx + dy + dz B = 2( dx ( x x ) + dy( y y ) + dz ( z o c o c o zc)) 2 2 2 2 C = ( x x ) + ( y y ) + ( z z ) r o c o c o c Ray-Sphere Intersection Using the Quadratic Formula ω B ± = B 2 4AC 2A Note: ω must be positive, otherwise the intersection is BEHIND the origin of the ray 11

Ray-Sphere Intersection Note: If D is normalized A = dx 2 + dy 2 + dz 2 = 1 and ω = B ± B 2 2 4C Ray-Sphere Intersection If B 2 4C is: < 0 no real root, no intersection = 0 one root, ray intersects at sphere s surface > 0 two roots, ray goes through sphere. Use least positive root 12

Ray-Sphere Intersection Once we found a ω i for the point of intersection, the actual point is: (x i, y i, z i ) = (x 0 + dx * ω i, y 0 + dy * ω i, z 0 + dz * ω i ) The normal at the point of intersection is: (x n, y n, z n ) = ((x i - x c )/r, (y i - y c )/r, (z i - z c )/r) (We divide by r to normalize!) Ray-Plane Intersection A plane can be defined by: A normal vector and a point on the plane It has the equation Ax + By + Cz + F = 0 where P n = (A, B, C) gives the normal and if normalized (A 2 + B 2 + C 2 = 1), F will the shortest distance to the plane from the origin of world. 13

Ray-Plane Intersection Ray - Plane Intersection For plane with equation: Ax + By + Cz + F = 0 ω = Plug in equation for ray and we get ( Ax + o By + o Cz + o F ) = ( P n P + F ) /( P Adx + Bdy + Cdz 0 n D ) Ray-Plane Intesection If (P n D) is 0 then ray is parallel to plane, no intersection If ω is < 0 then the ray intersects behind the origin of the ray ignore! > 0 calculate the point of intersection 14

Ray-Plane Intersection Once we found a ω i for the point of intersection, the actual point is: (x i, y i, z i ) = (x 0 + dx * ω i, y 0 + dy * ω i, z 0 + dz * ω i ) And we already have the normal at the point of intersection is: P n = (A, B, C) Ray-Polygon Intesection Find the plane in which the polygon sits Find the point of intersection between the ray and the plane If point of intersection is found, see if it lies within the boundaries of the polygon. 15

Ray-Polygon Intersection Find the plane in which the polygon sits A plane can be defined by: A normal vector and a point And has the equation Ax + By + Cz + F = 0 where P n = (A, B, C) gives the normal and if normalized (A 2 + B 2 + C 2 = 1), F will give the shortest distance to the plane from the origin of the world. Ray-Polygon Intersection Find the point of intersection between the ray and the plane Done previously See if point of intersection lies within the boundaries of the polygon. One algorithm: Draw line from P i to each polygon vertex Measure angles between lines Recall: (A B) = A B cos θ If sum of angles between lines is 360, polygon contains P i 16

Other Intersections To add other geometric primitives to your ray tracer Must mathematically derive the point of intersection between a ray and geometric primitive. Questions? Ray Tracing through the Camera Issues Ray Geometry Object-Ray Intersection Projection 17

Projection Ray Tracing through a camera Set up your scene Determine position / orientation of objects in scene. Spawn a ray and send into scene Define ray direction (remember to normalize) Check for closest intersection Calculate and return color Display or save final image 18

Introducing Ray Use mathematical description of a ray and objects to determine intersection. Parametric representation of a ray: Origin of ray, P o = (x o,y o,z o ) Direction D = (dx, dy, dz) Ray (ω) = P o + ω D If D is normalized, then ω will be the distance from origin of the ray. Graphics Pipeline 3D Object Coordinates 3D World Coordinates 3D Eye Coordinates 3D Eye Coordinates 2D Eye Coordinates 2D Screen Coordinates Object Transformation Viewing Transformation 3D Clipping Projection Window to Viewport Mapping 19

Camera Transformations M u x v x = n x 0 u v n y y y 0 u v n z z z 0 -eye u -eye v -eye n 1 (u x,u y,u z ) are coordinates of unit u vector w.r.t. world space Similar for v, n, (eye) is the origin of view space w.r.t world space If ups are aligned, simply use negative eye location values in the fourth column Graphics Pipeline 3D Object Coordinates 3D World Coordinates 3D Eye Coordinates 3D Eye Coordinates 2D Eye Coordinates 2D Screen Coordinates Object Transformation Viewing Transformation 3D Clipping Projection Window to Viewport Mapping 20

Projection Note: Projection not required as this will be done as part of the ray tracing process & Pu # $! $ Pv! $ P! n $! % 1 " = & p $ $ p M $ p $ % 1 x y z #!!!! " Spawning rays through camera Coordinate spaces Can do in camera space or world space Camera space Must transform all objects/lights to camera space World space Must transform initial rays to world space 21

22 Projection in Camera Space The role of cameras can be described as projecting a 3D scene onto a 2D plane Converting to World Space!!!! " # $ $ $ $ % & =!!!! " # $ $ $ $ % & ' 1 1 1 n v u z y x p p p M P P P

Inverting a 4x4 Matrix Code samples from Graphics Gems Ken Perlin Available on Web Will link on DIARY Tips World Space Need only transform the location of 1 st pixel location on image plane and dx, dy, and dz as you move across and down the plane 23

Tips Calculating Color Find point of intersection Good Safety tip only consider intersections if they occur past the image plane. If intersection Return color Of object Displaying your image You don t really need the full power of a 3D API to do ray tracing Just need the ability to write color values to pixels Some of the matrix operation routines may be helpful. 24

Displaying your image OpenGL gldrawpixels(); Chapter 10, Hill Chapter 8, OpenGL, red book Displaying your image C library Netppm Java Java2D Questions? 25

26