Title: Ray Casting
1Ray Casting
2The infamous gamma curve
- A gamma curve x-gtxg is used for many reasons
- CRT response
- Color quantization
- Perceptual effect
- Sometimes with ? gt1, sometimes ? lt1
- These issues are often oversimplified/confused,
including in prominent textbooks - i.e. they are explained wrong
3Cathode Ray Tube gamma
- The relationship between voltage and light
intensity is non linear - Can be approximated by an exponent 2.5
- Must be inverted to get linear response
From Pontons FAQhttp//www.poynton.com/
4Color quantization gamma
- The human visual system is more sensitive to
ratios is a grey twice as bright as another one? - If we use linear encoding, we have tons of
information between 128 and 255, but very little
between 1 and 2! - This is why a non-linear gamma remapping of about
2.0 is applied before encoding - True also of analog signal to optimize
signal-noise ratio - It is a nice coincidence that this is exactly the
inverse of the CRT gamma
5Stevens effect
- Perceived contrast increases with luminance
6Perceptual effect
- We perceive colors in darker environment less
vivid - Must be compensated by boosting colors
7At the end of the day
- At the camera or encoding level, apply a gamma of
around 1/2.2 - The CRT applies a gamma of 2.5
- The residual exponent 2.2/2.5 boosts the colors
to compensate for the dark environment - Seehttp//www.poynton.com/GammaFAQ.html
http//www.poynton.com/notes/color/GammaFQA.html
http//www.poynton.com/PDFs/Rehabilitation_of_gamm
a.pdf
8Gamma is messy
- Because its poorly understood
- Because its poorly standardized
- Half of the images on the net are linear, half
are gamma-compressed - Because it might make your image processing
non-linear - A weighted average of pixel values is not a
linear convolution! Bad for antialiasing - But it is often desirable for other image
processing, because then it corresponds more to
human perception of brightness
9Questions?
10Recap
- Modeling
- splines, hierarchy, transformation
- Animation
- quaternions, skinning, ODEs, mass spring
- Color the atom of images
- Now we need to see how to generate an image given
a scene description
11Overview of Today
- Ray Casting Basics
- Camera and Ray Generation
- Ray-Plane Intersection
- Ray-Sphere Intersection
12Ray Casting
- For every pixel
- Construct a ray from the eye
- For every object in the scene
- Find intersection with the ray
- Keep if closest
13Shading
- For every pixel
- Construct a ray from the eye
- For every object in the scene
- Find intersection with the ray
- Keep if closest
- Shade depending on light and normal vector
14A Note on Shading
- Surface/Scene Characteristics
- surface normal
- direction to light
- viewpoint
- Material Properties
- Diffuse (matte)
- Specular (shiny)
-
- Much more soon!
N
L
V
Diffuse sphere
Specular spheres
15Ray Tracing
- Secondary rays (shadows, reflection, refraction)
- In a couple of weeks
reflection
refraction
16Ray Tracing
17Ray Casting
- For every pixel Construct a ray from the eye
For every object in the scene - Find intersection with the ray
- Keep if closest
- Shade depending on light and normal vector
Finding the intersection and normal is the
central part of ray casting
N
18Ray Representation?
- Two vectors
- Origin
- Direction (normalized is better)
- Parametric line
- P(t) origin t direction
P(t)
direction
origin
19Durers Ray Casting Machine
- Albrecht Durer, 16th century
20Durers Ray Casting Machine
- Albrecht Durer, 16th century
21Durers Ray Casting Machine
- Albrecht Durer, 16th century
22Questions?
Henrik Wann Jensen, Stephen Duck, Fredo
23Overview of Today
- Ray Casting Basics
- Camera and Ray Generation
- Ray-Plane Intersection
- Ray-Sphere Intersection
24Cameras
- For every pixel
- Construct a ray from the eye
- For every object in the scene
- Find intersection with ray
- Keep if closest
25Pinhole Camera
- Box with a tiny hole
- Inverted image
- Similar triangles
- Perfect image if hole infinitely small
- Pure geometric optics
- No depth of field issue
26Oldest Illustration
- From. R. Gemma Frisius, 1545
27Camera Obscura
28Camera Obscura Today
Abelardo Morell www.abelardomorell.net
See http//www.imdb.com/title/tt0118556/goofs
Addicted to Love
29Camera Obscura in Art
Johannes Vermeer 1665
30Simplified Pinhole Camera
- Eye-image pyramid (frustum)
- Note that the distance/size of image are arbitrary
31Camera Description?
- Eye point e (center)
- Orthobasis u, v, w (horizontal, up, -direction)
- Field of view angle
- Image rectangle height, width
32Perspective vs. Orthographic
perspective
orthographic
- Parallel projection
- No foreshortening
- No vanishing point
33Orthographic Camera
- Ray Generation?
- Origin center (x-0.5)sizehorizontal
(y-0.5)sizeup - Direction is constant
34Other Weird Cameras
- E.g. fish eye, omnimax, panorama
35Questions?
36Overview of Today
- Ray Casting Basics
- Camera and Ray Generation
- Ray-Plane Intersection
- Ray-Sphere Intersection
37Ray Casting
- For every pixel Construct a ray from the eye
For every object in the scene - Find intersection with the ray
- Keep if closest
- First we will study ray-plane intersection
38Recall Ray Representation
- Parametric line
- P(t) Ro t Rd
- Explicit representation
P(t)
direction
origin
Rd
Ro
393D Plane Representation?
- Plane defined by
- Po (x,y,z)
- n (A,B,C)
- Implicit plane equation
- H(P) AxByCzD 0 nP D 0
- Point-Plane distance?
- If n is normalized, distance to plane, d H(P)
- d is the signed distance!
40Explicit vs. Implicit?
- Ray equation is explicit P(t) Ro t Rd
- Parametric
- Generates points
- Hard to verify that a point is on the ray
- Plane equation is implicit H(P) nP D 0
- Solution of an equation
- Does not generate points
- Verifies that a point is on the plane
- Exercise Explicit plane and implicit ray
41Ray-Plane Intersection
- Intersection means both are satisfied
- So, insert explicit equation of ray into
implicit equation of plane solve for t - P(t) Ro t Rd
- H(P) nP D 0
- n(Ro t Rd) D 0
- t -(D nRo) / nRd
P(t)
42Additional Housekeeping
- Verify that intersection is closer than previous
- Verify that it is not out of range (behind eye)
P(t) lt tcurrent
P(t) gt tmin
P(t)
43Normal
- For shading
- diffuse dot product between light and normal
- Normal is constant
normal
44A moment of mathematical beauty
- Duality points and planes are dual when you use
homogeneous coordinates - Point (x, y, z, 1)
- Plane (A, B, C, D)
- Plane equation ? dot product
- You can map planes to points and points to planes
in a dual space. - Lots of cool equivalences
- e.g. intersection of 3 planes define a point
- ? 3 points define a plane!
45Questions?
- Image by Henrik Wann Jensen
46Overview of Today
- Ray Casting Basics
- Camera and Ray Generation
- Ray-Plane Intersection
- Ray-Sphere Intersection
47Sphere Representation?
- Implicit sphere equation
- Assume centered at origin (easy to translate)
- H(P) PP - r2 0
Rd
Ro
48Ray-Sphere Intersection
- Insert explicit equation of ray into implicit
equation of sphere solve for t - P(t) Ro tRd H(P) PP - r2
0 - (Ro tRd) (Ro tRd) - r2 0
- RdRdt2 2RdRot RoRo - r2
0 -
Rd
Ro
49Ray-Sphere Intersection
- Quadratic at2 bt c 0
- a 1 (remember, Rd 1)
- b 2RdRo
- c RoRo r2
- with discriminant
- and solutions
50Ray-Sphere Intersection
- 3 cases, depending on the sign of b2 4ac
- What do these cases correspond to?
- Which root (t or t-) should you choose?
- Closest positive! (usually t-)
51Ray-Sphere Intersection
- It's so easy that all ray-tracing images have
spheres!
52Geometric Ray-Sphere Intersection
- Shortcut / easy reject
- What geometric information is important?
- Ray origin inside/outside sphere?
- Closest point to ray from sphere origin?
- Ray direction pointing away from sphere?
53Geometric Ray-Sphere Intersection
- Is ray origin inside/outside/on sphere?
- (RoRo lt r2 / RoRo gt r2 / RoRo r2)
- If origin on sphere, be careful about
degeneracies
O
r
Ro
Rd
54Geometric Ray-Sphere Intersection
- Is ray origin inside/outside/on sphere?
- Find closest point to sphere center, tP - Ro
Rd - If origin outside tP lt 0 ? no hit
O
r
Ro
Rd
tP
55Geometric Ray-Sphere Intersection
- Is ray origin inside/outside/on sphere?
- Find closest point to sphere center, tP - Ro
Rd. - Find squared distance, d2 RoRo - tP2
- If d2 gt r2 ? no hit
O
r
d
Ro
Rd
tP
56Geometric Ray-Sphere Intersection
- Is ray origin inside/outside/on sphere?
- Find closest point to sphere center, tP - Ro
Rd. - Find squared distance d2 RoRo - tP2
- Find distance (t) from closest point (tP) to
correct intersection t2 r2 - d2 - If origin outside sphere ? t tP - t
- If origin inside sphere ? t tP t
O
r
d
Ro
Rd
tP
t
t
57Geometric vs. Algebraic
- Algebraic is simple generic
- Geometric is more efficient
- Timely tests
- In particular for rays outside and pointing away
58Sphere Normal
- Simply Q/Q
- Q P(t), intersection point
- (for spheres centered at origin)
O
Ro
Rd
Q
normal
59Questions?
60Precision
- What happens when
- Origin is on an object?
- Grazing rays?
- Problem with floating-point approximation
61The evil e
- In ray tracing, do NOT report intersection for
rays starting at the surface (no false positive) - Because secondary rays
- Requires epsilons
reflection
shadow
refraction
62The evil e a hint of nightmare
- Edges in triangle meshes
- Must report intersection (otherwise not
watertight) - No false negative
63Assignment 4 5 Ray Casting/Tracing
- Write a basic ray caster
- Orthographic camera
- Sphere Intersection
- Main loop rendering
- 2 Display modes color and distance
- We provide
- Ray origin, direction
- Hit t, Material, (normal)
- Scene Parsing
64Object-Oriented Design
- We want to be able to add primitives easily
- Inheritance and virtual methods
- Even the scene is derived from Object3D!
Object3D bool intersect(Ray, Hit, tmin)
Plane bool intersect(Ray, Hit, tmin)
Sphere bool intersect(Ray, Hit, tmin)
Triangle bool intersect(Ray, Hit, tmin)
Group bool intersect(Ray, Hit, tmin)
65Books
- Peter Shirley Fundamentals of Computer
GraphicsAK Peters - Ray Tracing
66Questions?
67Next Time More Ray Casting
- Other primitives
- Boxes
- Polygons
- Triangles
- IFS?