ray tracing i: basics - computer graphics · cs348b lecture 2 pat hanrahan, spring 2016 ray tracing...
TRANSCRIPT
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray Tracing I: Basics
Today
■ Basic algorithms
■Overview of pbrt
■ Ray-surface intersection
Next lecture
■ Techniques to accelerate ray tracing of large numbers of geometric primitives
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Light Rays
Three ideas about light rays
1. Light travels in straight lines (mostly)
2. Light rays do not interfere with each other if they cross (light is invisible!)
3. Light rays travel from the light sources to the eye (but the physics is invariant under path reversal - reciprocity).
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray Tracing in Computer Graphics
Appel 1968 - Ray casting
1. Generate an image by casting one ray per pixel
2. Check for shadows by sending a ray to the light
Ray Tracing in Computer Graphics
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Spheres and Checkerboard, T. Whitted, 1979
“An improved Illumination model for shaded display” T. Whitted, CACM 1980
Time: - VAX 11/780 (1979) 74m - PC (2006) 6s - GPU (2012) 1/30s
512 x 512
Ray Tracing Video
Spheres-over-plane.pbrt (depth=1)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Spheres-over-plane.pbrt (mirror depth=2)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Spheres-over-plane.pbrt (mirror depth=3)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Spheres-over-plane.pbrt (mirror depth=10)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Spheres-over-plane.pbrt (glass depth=1)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Spheres-over-plane.pbrt (glass depth=2)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Spheres-over-plane.pbrt (glass depth=3)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Spheres-over-plane.pbrt (g/m depth=10)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
PBRT Render Loop
CS348b Lecture 2 Pat Hanrahan, Spring 2016
PBRT Intersection Methods
CS348b Lecture 2 Pat Hanrahan, Spring 2016
PBRT Intergrater
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray-Surface Intersection
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray-Plane Intersection
Ray:
t= +P O D!! !
O!
D!0 t≤ < ∞
P!
t
N!
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray-Plane Intersection
Ray:
Plane:
t= +P O D!! !
O!
D!0 t≤ < ∞
t
N!
!P!( ) 0
0ax by cz d− • ="
+ + + =
P P N! ! !
P!
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray-Plane Intersection
Ray:
Plane:
Solve for intersection
t= +P O D!! !
O!
D!0 t≤ < ∞
t
N!
!P!( ) 0
0ax by cz d− • ="
+ + + =
P P N! ! !
− • = + − • =" "
− •"= −
•
!! ! ! ! ! !
! ! !! !
( ) ( ) 0( )
t
t
P P N O D P NO P ND N
P!
Optimize Ray-Convex Polyhedra?
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Polyhedra defined as the intersection of N half-planes
Triangles
CS348b Lecture 2 Pat Hanrahan, Spring 2016
1P!
2P!3P
! P!
1s
2s3s
1 1 2 2 3 3s s s= + +P P P P! ! ! !
Barycentric coordinates
1
2
3
1 2 3
0 10 10 1
1
sss
s s s
≤ ≤
≤ ≤
≤ ≤
+ + =
Inside triangle criteria
s1 = area(4PP2P3)/area(4P1P2P3)
s2 = area(4P1PP3)/area(4P1P2P3)
s3 = area(4P1P2P)/area(4P1P2P3)
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Triangle Inside Test
Test whether a point is inside the triangle
= + +! ! ! !
1 1 2 2 3 3s s sP P P P
[ ] [ ]! "# $ =# $# $% &
1
1 2 3 2
3
sss
P P P P
[ ] [ ]−
" #$ % =$ %$ %& '
11
2 1 2 3
3
sss
P P P P
Moller-Trumbore Algorithm
CS348b Lecture 2 Pat Hanrahan, Spring 2016
+ = − − + +! ! ! ! !
1 2 0 1 1 2 2(1 )t b b b bO D P P P
= −! ! !1 1 0E P P= −
! ! !2 2 0E P P
= −! ! !
0S O P
! "•! "# $# $ = •# $# $ • # $# $ •% & % &
! !! !
! !! !
2 2
1 11 1
2 2
1tbb
S ES S
S ES D
= ×! ! !1 2S D E= ×
! ! !2 1S S E
Where:
Cost = (1 div, 27 mul, 17 add)
Ray-Sphere Intersection
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray:
Sphere: ( )2 2 0R− − =P C!!
O!
C!
D! t= +P O D
!! !
P!
Ray-Sphere Intersection
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray:
Sphere:O!
C!
D!
( )2 2 0t R+ − − =O D C! !!
2 0at bt c+ + =2a = D!
2( )b = − •O C D! ! !
2 2( )c R= − −O C! !
2 42
b b acta
− ± −=
P!
( )2 2 0R− − =P C!!
t= +P O D!! !
Ray-Sphere Intersection
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray:
Sphere:O!
C!
D!
( )2 2 0t R+ − − =O D C! !!
2 0at bt c+ + =2a = D!
2( )b = − •O C D! ! !
2 2( )c R= − −O C! !
2 42
b b acta
− ± −=
P!
( )2 2 0R− − =P C!!
t= +P O D!! !
Shapes
Shapes in pbrt
CS348b Lecture 2 Pat Hanrahan, Spring 2016
class Shape {
public:
// Shape interface
virtual BBox ObjectBound() const = 0;
virtual BBox WorldBound() const;
virtual bool CanIntersect() const;
virtual void Refine(vector<Reference<Shape>> &refined) const;
virtual bool Intersect(const Ray &ray, float *tHit,
float *rayEpsilon, DifferentialGeometry *dg) const;
virtual bool IntersectP(const Ray &ray) const;
virtual void GetShadingGeometry(const Transform &obj2world,
const DifferentialGeometry &dg,
DifferentialGeometry *dgShading) const {
*dgShading = dg;
}
virtual float Area() const;
// Shape Public Data
const Transform *ObjectToWorld, *WorldToObject;
};
Quadrics
CS348b Lecture 2 Pat Hanrahan, Spring 2016
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Geometric Methods: Normals
e.g. Sphere
= −N P C!! !
θ φ
θ φ
θ
=
=
=
=!
sin cossin sincos( , , )
xyz
x y zP
N!
S! T
!, ,u vP!
θ φ θ φ θθ
∂= −
∂
!(cos cos ,cos sin , sin )P
θ φ θ φφ
∂= −
∂
!( sin sin ,sin cos ,0)P
θ φ
∂ ∂= ×∂ ∂
! !! P PN
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Geometric Methods: Parameters
e.g. Sphere
sin cossin sincos
xyz
θ φ
θ φ
θ
=
=
=
1
1
tan ( , )cos
x yz
φ
θ
−
−
=
=
θ θ θ θ
φ φ
= + −
=min max min
max
( )vu
θ θ θ θ
φ φ
= − −
=min max min
max
( ) /( )/
vu
Differential Geometry Representation
CS348b Lecture 2 Pat Hanrahan, Spring 2016
struct DifferentialGeometry { // Filled in by Shape::Intersect() Point p; Normal nn; float u, v; const Shape *shape; Vector dpdu, dpdv; Normal dndu, dndv; };
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray-Implicit Surface Intersection
1. Substitute ray equation
2. Find positive, real roots
Univariate root finding
■Newton’s method
■ Regula-falsi
■ Interval methods
■…
( , , ) 0f x y z =
*( ) 0f t =
0 1
0 1
0 1
x x x ty y y tz z z t
= +
= +
= +
CS348b Lecture 2 Pat Hanrahan, Spring 2016
Ray-Algebraic Surface Intersection
( , , ) 0np x y z =
*( ) 0np t =
Degree n
■ Linear: Plane
■Quadric: Spheres, …
■Quartic: Tori
Polynomial root finding
■Quadratic, cubic, quartic
■…
0 1
0 1
0 1
x x x ty y y tz z z t
= +
= +
= +