14 Ray
14 Ray
14 Ray
Ray Casting
Ray-Surface Intersections
Barycentric Coordinates
Reflection and Transmission
[Shirley, Ch.9]
Ray Tracing Handouts
Announcements
Assignment 2 Grades Returned
Assignment 3 Out Today
1
Local vs. Global Rendering Models
Local rendering models (graphics pipeline)
Object illuminations are independent
No light scattering between objects
No real shadows, reflection, transmission
Global rendering models
Ray tracing (highlights, reflection, transmission)
Radiosity (surface interreflections)
2
Forward Ray Tracing
Rays as paths of photons in world space
Forward ray tracing: follow photon from light
sources to viewer
Problem: many rays will
not contribute to image!
3
Shadow Rays
Determine if light really hits surface point
Cast shadow ray from surface point to light
If shadow ray hits opaque object,no contribution
Improved diffuse reflection
Reflection Rays
Calculate specular component of illumination
Compute reflection ray (recall: backward!)
Call ray tracer recursively to determine color
Add contributions
Transmission ray
Analogue for transparent or
translucent surface
Use Snells laws for refraction
Later:
Optimizations, stopping criteria
4
Ray Casting
Simplest case of ray tracing
Required as first step of recursive ray tracing
Basic ray-casting algorithm
For each pixel (x,y) fire a ray from COP through (x,y)
For each ray & object calculate closest intersection
For closest intersection point p
Calculate surface normal
For each light source, calculate and add contributions
Critical operations
Ray-surface intersections
Illumination calculation
5
Angle of Reflection
Recall: incoming angle = outgoing angle
r = 2(l n) n l
For incoming/outgoing ray negate l !
Compute only for surfaces
with actual reflection
Use specular coefficient
Add specular and diffuse
components
Refraction
Index of refraction is relative speed of light
Snells law
l = index of refraction for upper material
t = index of refraction for lower material [U = ]
6
Raytracing Example
www.povray.org
Raytracing Example
rayshade gallery
7
Raytracing Example
rayshade gallery
Raytracing Example
www.povray.org
8
Raytracing Example
Raytracing Example
www.povray.org
9
Raytracing Example
www.povray.org
Raytracing Example
rayshade gallery
10
Raytracing Example
Intersections
11
Ray-Surface Intersections
General implicit surfaces
General parametric surfaces
Specialized analysis for special surfaces
Spheres
Planes
Polygons
Quadrics
Do not decompose objects into triangles!
CSG is also a good possibility
12
Rays and Implicit Surfaces
Ray in parametric form
Origin p0 = [x0 y0 z0 1]T
Direction d = [xd yd zd 0]t
Assume d normalized (xd2 + yd2 + zd2 = 1)
Ray p(t) = p0 + d t for t > 0
Implicit surface
Given by f(q) = 0
Consists of all points q such that f(q) = 0
Substitute ray equation for q: f(p0 + d t) = 0
Solve for t (univariate root finding)
Closed form (if possible) or numerical approximation
Ray-Sphere Intersection I
Common and easy case
Define sphere by
Center c = [xc yc zc 1]T
Radius r
Surface f(q) = (x xc)2 + (y yc)2+ (z zc)2 r2 = 0
Plug in ray equations for x, y, z:
13
Ray-Sphere Intersection II
Simplify to
where
14
Simple Optimizations
Factor common subexpressions
Compute only what is necessary
Calculate b2 4c, abort if negative (why?)
Compute normal only for closest intersection
Other similar optimizations [Handout]
Ray-Polygon Intersection I
Assume planar polygon
1. Intersect ray with plane containing polygon
2. Check if intersection point is inside polygon
Plane
Implicit form: ax + by + cz + d = 0
Unit normal: n = [a b c 0]T with a2 + b2 + c2 = 1
Substitute:
Solve:
15
Ray-Polygon Intersection II
Substitute t to obtain intersection point in plane
Test if point inside polygon [see Handout]
Ray-Quadric Intersection
Quadric f(p) = f(x, y, z) = 0, where f is
polynomial of order 2
Sphere, ellipsoid, paraboloid, hyperboloid,
cone, cylinder
Closed form solution as for sphere
Important case for modelling in ray tracing
Combine with CSG
[see Handout]
16
Barycentric Coordinates
17
Barycentric Coordinates in 1D
Linear interpolation
p(t) = (1 t)p1 + t p2, 0 t 1
p(t) = p1 + p2 where + = 1
p is between p1 and p2 iff 0 , 1
Geometric intuition
Weigh each vertex by ratio of distances from ends
p1 p p2
, are called barycentric coordinates
Barycentric Coordinates in 2D
Given 3 points instead of 2
p1
p
p2
p3
18
Barycentric Coordinates for Triangle
Coordinates are ratios of triangle areas
Area(CC1C 2 )
C1 =
Area(C0C1C 2 )
Area(C0CC2 )
C =
Area(C0C1C 2 )
C2 Area (C0C1C)
= = 1
Area(C0C1C 2 )
C0
19
Ray Tracing Preliminary Assessment
Global illumination method
Image-based
Pros:
Relatively accurate shadows, reflections, refractions
Cons:
Slow (per pixel parallelism, not pipeline parallelism)
Aliasing
Inter-object diffuse reflections
20
21