Top Banner
CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai
68
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

CSCE 641: Computer Graphics Ray Tracing

Jinxiang Chai

Page 2: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing

Provides rendering method with

Refraction/Transparent surfaces

Reflective surfaces

Shadows

Image taken from http://www.tjhsst.edu/~dhyatt/superap/samplex.jpg

Page 3: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing

Provides rendering method with

Refraction/Transparent surfaces

Reflective surfaces

Shadows

Image taken from http://www.tjhsst.edu/~dhyatt/superap/samplex.jpg

Any difference for rendering three pixels?

Page 4: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Local Illumination vs. Ray Tracing

Page 5: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Results

Click here

Page 6: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Overview

Ray Tracing Algorithm

Shadows, Reflection, Refraction

Surface Intersection

Infinite planes, spheres, polygons

Optimizations

Page 7: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Essential Information for Ray Tracing

Eye point

Screen position/orientation

Objects

Material properties

Reflection/Refraction coefficients

Index of refraction

Light sources

Page 8: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Assumption

The illumination of a point is determined by

- illumination/shadow ray (direct lighting from light sources)

Page 9: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Assumption

The illumination of a point is determined by

- illumination/shadow ray (direct lighting from light sources)

Page 10: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Assumption

The illumination of a point is determined by

- illumination/shadow ray (direct lighting from light sources)

- reflection ray (light reflected by an object)

Page 11: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Assumption

The illumination of a point is determined by

- illumination/shadow ray (direct lighting from light sources)

- reflection ray (light reflected by an object)

- transparent ray (light passing through an object)

Page 12: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Assumption

The illumination of a point is determined by

- illumination/shadow ray (direct lighting from light sources)

- reflection ray (light reflected by an object)

- transparent ray (light passing through an object)

Page 13: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Assumption

The illumination of a point is determined by

- illumination/shadow ray (direct lighting from light sources)

- reflection ray (light reflected by an object)

- transparent ray (light passing through an object)

Page 14: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Illumination / Shadow Rays

A ray is cast from an object’s surface towards a light.

If the light is not occluded, then the light contributes to the object’s surface color.

If the light is occluded, then the light does not contribute to the object’s surface color.

If ray hits a semi-transparent object, scale the contribution of that light and continue to look for intersections

Occluder

Pixels

Page 15: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Reflected Rays

A ray is cast from the surface of an object based on its material properties.

The contribution results in the specular reflection.

Page 16: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Transparency/transmission/refracted Rays

Some objects are transparent or translucent.

The transmitted light also contributes to the surface color, called specular transmission.

The ray can be refracted based on the object’s composition.

Page 17: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

1

2

3

4

L1

L2

Page 18: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

1

2

3

4

L1

L2

Page 19: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

1

2

3

4

L1

L2

Page 20: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

refractedareflectededirect IIII 1

2

3

4

L1

L2

Page 21: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

refractedareflectededirect IIII 1

2

3

4

L1

L2

Page 22: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

refractedareflectededirect IIII 1

2

3

4

L1

L2

speculardiffuseambientdirect IIII

Page 23: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

refractedareflectededirect IIII 1

2

3

4

L1

L2

Page 24: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

1

2

3

4

L1

L2

Page 25: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

1

2

3

4

L1

L2

Page 26: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

1

2

3

4

L1

L2

What are real light paths?

Page 27: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing and Light path

1

2

3

4

L1

L2

Ray tracing paths just reverses real light paths!

Page 28: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing and Light path

1

2

3

4

L1

L2

Ray tracing paths just reverses real light paths!

Page 29: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing and Light path

1

2

3

4

L1

L2

Ray tracing paths just reverses real light paths!

Page 30: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing and Light path

1

2

3

4

L1

L2

Ray tracing paths just reverses real light paths!

Page 31: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing and Light path

1

2

3

4

L1

L2

Ray tracing paths just reverses real light paths!

Page 32: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing and Light path

1

2

3

4

L1

L2

Ray tracing paths just reverses real light paths!

Page 33: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tree

Object 1 L2

Shadow of Obj 4

Object 3

Reflection

ReflectionL2

L1

Object 2

Transmission

ReflectionL2

L1

Eye

Page 34: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

For each pixel

Intersect ray from eye through pixel with all objects in scene

Find closest (positive) intersection to eye

Compute lighting at intersection point

Recur for reflected and refracted rays (if necessary)

Page 35: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

refractedareflectededirect IIII

speculardiffuseambientdirect IIII

directI

reflectedI refractedI

refractedIrefractedIreflectedI reflectedI

e

e e

a

aa

Page 36: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Termination Criterion

1. The ray intersects no surfaces

2. The ray intersects a light source that is not a reflecting surface

3. The tree has been generated to its maximum allowable depth.

Page 37: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Three Issues

Ray-object intersection

- hidden surface removal

Reflection direction

- mirror direction

Refraction direction

- Snell’s law

Page 38: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray-object Intersection

eye

screen

Similar to ray casting!

Page 39: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray-object Intersection

eye

screen

Similar to ray casting!

But how to determine the intersection point between a ray and an object such as sphere or triangle?

Page 40: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Casting

Implementation

- Parameterize each ray as

- Each object Ok returns tk>0 such that first intersection with ok occurs at r(tk)

- Q: given the set {tk}, what is the first intersection point?

)()( cptctr ij

Page 41: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray-Sphere Intersection

Page 42: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray-Triangle Intersection

• First, intersection ray with plane

• Then, check if point is in triangle

Page 43: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray-Plane Intersection

Page 44: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray-Triangle Intersection

Check if point is inside triangle algebraically 

For each side of triangle

0

0

Page 45: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Reflection

Mirror-like/Shiny objects

V

N

Surface

R

VNNVR )(2

Page 46: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Refraction

Bending of light caused by different speeds of light in different medium

Each (semi-)transparent

object has an index of

refraction ni

Use Snell’s law to find

refracted vector

Image taken from http://hyperphysics.phy-astr.gsu.edu/hbase/geoopt/refr2.html

Page 47: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

1

2

2

1

2

1

)sin(

)sin(

n

n

c

c

Page 48: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

How to compute Transmission Ray?

V N1

Surface

2

N R

n1

n2

Page 49: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

cV

||V

Page 50: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

||)sin())(cos( 22 V

VNR

VV

||V

Page 51: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

||)sin())(cos( 22 V

VNR

VV

||V

Page 52: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

||)sin())(cos( 22 V

VNR

VV

||V

Page 53: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

||

)()sin())(cos( 22 V

VNNVNR

Page 54: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

)sin(

)()sin())(cos(

122

VNNVNR

Page 55: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

))(())(cos(1

22 VNNV

c

cNR

Page 56: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

))(()()sin(11

222 VNNV

c

cNR

Page 57: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

))(()()sin(11

22

1

222

1 VNNVc

cN

c

cR

Page 58: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

))(()(1

)sin(1

2

1

21

22

21 VNNV

c

cN

cccR

Page 59: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Snell’s Law

V N1

Surface

2

N R

)sin(

)sin(

2

1

2

1

c

c

))(()(1

))(1(1

2

1

222

21 VNNV

c

cN

cNVccR

Page 60: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

Recur for reflective/transparent objects

Page 61: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Recursive Ray Tracing

Recur for reflective/transparent objects

Page 62: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Optimizations

Lots of rays to cast!

Ray-Surface intersections are expensive

Associate with each object

Bounding box in 3-space

If ray doesn’t intersect box, then ray doesn’t intersect object

Page 63: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Parallel Processing

Ray tracing is a trivially parallel algorithm!

Cast rays in parallel

Cast reflection, refraction, shadow rays in parallel

Calculate ray/surface intersections independently in parallel

Page 64: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Results: Special Effects

Copyright Newline Cinema

Page 65: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Results: Video Games

Page 66: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing Results: Massive Models

Page 67: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Pros and Cons of Ray Tracing

Advantages of ray tracing

All the advantages of the local illumination model

Also handles shadows, reflection, and refraction

Disadvantages of ray tracing

Computational expense

No diffuse inter-reflection between surfaces (i.e., color bleeding)

Not physically accurate

Other techniques exist to handle these shortcomings, at even greater expense!

Page 68: CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.

Ray Tracing References

Peter Shirley, “Realistic Ray Tracing”, ISBN 1-56881-110-1

Andrew Glassner, “An Introduction to Ray Tracing”, ISBN 0-12-286160-4

Steve Pettifer (http://www.cs.man.ac.uk/people/srp)

Anselmo Lastra (http://www.cs.unc.edu/~lastra)

Paul Rademacher (http://www.cs.unc.edu/~rademach)

Mark Harris (http://www.cs.unc.edu/~harrism)

Kenny Hoff (http://www.cs.unc.edu/~hoff)

POV-Ray (http://www.povray.org)