Ray tracing & Environment mapping

advertisement
CSCE 441: 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
Ray Tracing
Provides rendering method with

Refraction/Transparent surfaces

Reflective surfaces

Shadows
Any difference for rendering
three pixels?
Image taken from http://www.tjhsst.edu/~dhyatt/superap/samplex.jpg
Local Illumination vs. Ray Tracing
Ray Tracing Results
Click here
Overview
Ray Tracing Algorithm

Shadows, Reflection, Refraction
Surface Intersection

Infinite planes, spheres, polygons
Optimizations
Readings: HB 21-1
Essential Information for Ray Tracing
Eye point
Screen position/orientation
Objects

Material properties

Reflection/Refraction coefficients

Index of refraction
Light sources
Ray Tracing Assumption
The illumination of a point is determined by
- illumination/shadow ray (direct lighting from light
sources)
Ray Tracing Assumption
The illumination of a point is determined by
- illumination/shadow ray (direct lighting from light
sources)
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)
Ray Tracing Assumption
The illumination of a point is determined by
- illumination/shadow ray (direct lighting from light
sources)
- reflection ray (where the angle of reflection equals the angle of incidence)
- transparent ray (light passing through an object)
Ray Tracing Assumption
The illumination of a point is determined by
- illumination/shadow ray (direct lighting from light
sources)
- reflection ray (where the angle of reflection equals the angle of incidence)
- transparent ray (light passing through an object)
Ray Tracing Assumption
The illumination of a point is determined by
- illumination/shadow ray (direct lighting from light
sources)
- reflection ray (where the angle of reflection equals the angle of incidence)
- transparent ray (light passing through an object)
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
Reflected Rays
A ray is cast from the surface of an object based on its
material properties.
The contribution results in the specular reflection.
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.
Recursive Ray Tracing
3
L1
L2
4
1
2
Recursive Ray Tracing
3
L1
L2
4
1
2
Recursive Ray Tracing
3
L1
L2
4
1
2
Recursive Ray Tracing
3
L1
L2
4
1
I  I direct   e I reflected   a I refracted
2
Recursive Ray Tracing
3
L1
L2
4
1
I  I direct   e I reflected   a I refracted
2
Recursive Ray Tracing
3
L1
L2
4
1
I  I direct   e I reflected   a I refracted
I direct  I ambient  I diffuse  I specular
2
Recursive Ray Tracing
3
L1
L2
4
1
I  I direct   e I reflected   a I refracted
2
Recursive Ray Tracing
3
L1
L2
4
1
2
Recursive Ray Tracing
3
L1
L2
4
1
2
Recursive Ray Tracing
3
L1
L2
4
1
What are real light paths?
2
Recursive Ray Tracing and Light path
3
L1
L2
4
1
Ray tracing paths just reverses real light paths!
2
Recursive Ray Tracing and Light path
3
L1
L2
4
1
Ray tracing paths just reverses real light paths!
2
Recursive Ray Tracing and Light path
3
L1
L2
4
1
Ray tracing paths just reverses real light paths!
2
Recursive Ray Tracing and Light path
3
L1
L2
4
1
Ray tracing paths just reverses real light paths!
2
Recursive Ray Tracing and Light path
3
L1
L2
4
1
Ray tracing paths just reverses real light paths!
2
Recursive Ray Tracing and Light path
3
L1
L2
4
1
Ray tracing paths just reverses real light paths!
2
Ray Tree
Eye
Shadow of Obj 4
Object 1
Reflection
L2
Transmission
L1
L1
Object 3
Object 2
L2
L2
Reflection
Reflection
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)
Recursive Ray Tracing
I  I direct   e I reflected   a I refracted
I direct  I ambient  I diffuse  I specular
I direct
e
I reflected
e
a
a
I refracted
e
I reflected I refracted I reflected



a
I refracted

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.
Three Issues
Ray-object intersection
- hidden surface removal
Reflection direction
- mirror direction
Refraction direction
- Snell’s law
Ray-object Intersection
screen
eye
Similar to ray casting!
Ray-object Intersection
screen
eye
Similar to ray casting!
But how to determine the intersection point between a ray and an object
such as sphere or triangle?
Ray Casting
Implementation
- Parameterize each ray as
r (t )  c  t ( pij  c)
- 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?
Ray-Sphere Intersection
Ray-Triangle Intersection
•
First, intersecting the ray with plane
•
Then, check if point is in triangle
Ray-Plane Intersection
Ray-Triangle Intersection
Check if point is inside triangle algebraically
For each side of triangle
0
0
Ray-Triangle Intersection
Check if point is inside triangle algebraically
For each side of triangle
0
0
P1
Reflection
Mirror-like/Shiny objects
R  2(V  N ) N V
N
V
R


Surface
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
Snell’s Law
V
N
1
Surface
N
2
R
sin( 1 ) c1 n2
 
sin(  2 ) c2 n1
How to compute Transmission Ray?
V
n1
N
1
Surface
n2
N
2
R
Snell’s Law
V
V
1
c1 sin( 1 )

c2 sin(  2 )
N
V||
Surface
N
2
R
Snell’s Law
V
V
1
c1 sin( 1 )

c2 sin(  2 )
N
V||
Surface
N
2
R
  V 

R  cos( 2 )(  N )  sin(  2 )
 | V | 
Snell’s Law
V
V
1
c1 sin( 1 )

c2 sin(  2 )
N
V||
Surface
N
2
R
  V 

R  cos( 2 )(  N )  sin(  2 )
 | V | 
Snell’s Law
V
V
1
c1 sin( 1 )

c2 sin(  2 )
N
V||
Surface
N
2
R
  V 

R  cos( 2 )(  N )  sin(  2 )
 | V | 
Snell’s Law
V
c1 sin( 1 )

c2 sin(  2 )
N
1
Surface
N
2
R
 (V  N ) N  V 

R  cos( 2 )(  N )  sin(  2 )
| V |


Snell’s Law
V
c1 sin( 1 )

c2 sin(  2 )
N
1
Surface
N
2
R
 (V  N ) N  V 

R  cos( 2 )(  N )  sin(  2 )
 sin( 1 ) 
Snell’s Law
V
c1 sin( 1 )

c2 sin(  2 )
N
1
Surface
N
2
R
c2
R  cos( 2 )(  N )  ((V  N ) N  V )
c1
Snell’s Law
c1 sin( 1 )

c2 sin(  2 )
N
V
1
Surface
N
2
R
c2
R  1  sin(  2 ) ( N )  ((V  N ) N  V )
c1
2
Snell’s Law
c1 sin( 1 )

c2 sin(  2 )
N
V
1
Surface
N
2
2
R
c2
c2
R  1  sin( 1 ) 2 ( N )  ((V  N ) N  V )
c1
c1
2
Snell’s Law
c1 sin( 1 )

c2 sin(  2 )
N
V
1
Surface
N
2
R
1
c2
R  c1  c2 sin( 1 )
( N )  ((V  N ) N  V )
c1
c1
2
2
2
Snell’s Law
V
c1 sin( 1 )

c2 sin(  2 )
N
1
Surface
N
2
R
1
c2
R  c1  c2 (1  (V  N ) ) ( N )  ((V  N ) N  V )
c1
c1
2
2
2
Recursive Ray Tracing
Recur for reflective/transparent objects
Recursive Ray Tracing
Recur for reflective/transparent objects
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
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
Ray Tracing Results: Special Effects
Copyright Newline Cinema
Ray Tracing Results: Video Games
Ray Tracing Results: Massive Models
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!
Ray Tracing References
Peter Shirley, “Realistic Ray Tracing”, ISBN 1-56881110-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)
Environment Mapping
How to create this effect?
Environment Mapping
An efficient technique for approximating the appearance of a reflective
surface by means of a precomputed texture image.
Environment Mapping
Cheap attempt at modeling reflections
Makes surfaces look metallic
Use six textures to model faces of a cube
Assume cube faces infinitely far away
The normal (or reflected eye vector) is used to find
which of the textures to use and what texture
coordinate
Environment Mapping
Environment Mapping
Environment Mapping
Environment Mapping
Environment Mapping
Reflected ray: r=2(n·v)n-v
viewer
n
v
r
reflective surface
environment
texture image
Texture is transferred in the direction of the reflected ray r from the
environment map onto the object
What is in the map?
How to represent the map
viewer
How to represent the map
viewer
How to represent the map
viewer
How to represent the map
viewer
Store colors of every possible direction in texture maps
How to represent the map
viewer
c
c
c
c
c
v
Store colors of every possible direction in texture maps
How to represent the map
viewer
c
c
c
c
c
v
Store colors of every possible direction in texture maps
Look up texture maps based on reflected vector
Cubic Mapping
The map resides on the surfaces of a cube around the
object

Typically, align the faces of the cube with the coordinate axes
To generate the map:

For each face of the cube, render the world from the center of the object
with the cube face as the image plane

Rendering can be arbitrarily complex (it’s off-line)
To use the map:

Index the R ray into the correct cube face

Compute texture coordinates
Cubic Map Example
How to represent the map
viewer
Store colors of every possible direction in texture maps
Sphere Mapping
Map lives on a sphere
To generate the map:

Render a spherical panorama from the designed
center point
To use the map:

Use the orientation of the R ray to index directly
into the sphere
Example
Environmental Mapping: Limitations
Assume distant environment
Only work for convex objects (i.e., no selfinterreflections)
Download