Ray Casting - PowerPoint PPT Presentation

1 / 67
About This Presentation
Title:

Ray Casting

Description:

Ray Casting – PowerPoint PPT presentation

Number of Views:79
Avg rating:3.0/5.0
Slides: 68
Provided by: FredoD5
Category:
Tags: casting | ma | ray | rmv

less

Transcript and Presenter's Notes

Title: Ray Casting


1
Ray Casting
2
The 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

3
Cathode 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/
4
Color 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

5
Stevens effect
  • Perceived contrast increases with luminance

6
Perceptual effect
  • We perceive colors in darker environment less
    vivid
  • Must be compensated by boosting colors

7
At 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

8
Gamma 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

9
Questions?
10
Recap
  • 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

11
Overview of Today
  • Ray Casting Basics
  • Camera and Ray Generation
  • Ray-Plane Intersection
  • Ray-Sphere Intersection

12
Ray Casting
  • For every pixel
  • Construct a ray from the eye
  • For every object in the scene
  • Find intersection with the ray
  • Keep if closest

13
Shading
  • 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

14
A 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
15
Ray Tracing
  • Secondary rays (shadows, reflection, refraction)
  • In a couple of weeks

reflection
refraction
16
Ray Tracing
17
Ray 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
18
Ray Representation?
  • Two vectors
  • Origin
  • Direction (normalized is better)
  • Parametric line
  • P(t) origin t direction

P(t)
direction
origin
19
Durers Ray Casting Machine
  • Albrecht Durer, 16th century

20
Durers Ray Casting Machine
  • Albrecht Durer, 16th century

21
Durers Ray Casting Machine
  • Albrecht Durer, 16th century

22
Questions?
Henrik Wann Jensen, Stephen Duck, Fredo
23
Overview of Today
  • Ray Casting Basics
  • Camera and Ray Generation
  • Ray-Plane Intersection
  • Ray-Sphere Intersection

24
Cameras
  • For every pixel
  • Construct a ray from the eye
  • For every object in the scene
  • Find intersection with ray
  • Keep if closest

25
Pinhole Camera
  • Box with a tiny hole
  • Inverted image
  • Similar triangles
  • Perfect image if hole infinitely small
  • Pure geometric optics
  • No depth of field issue

26
Oldest Illustration
  • From. R. Gemma Frisius, 1545

27
Camera Obscura
28
Camera Obscura Today
Abelardo Morell www.abelardomorell.net
See http//www.imdb.com/title/tt0118556/goofs
Addicted to Love
29
Camera Obscura in Art
Johannes Vermeer 1665
30
Simplified Pinhole Camera
  • Eye-image pyramid (frustum)
  • Note that the distance/size of image are arbitrary

31
Camera Description?
  • Eye point e (center)
  • Orthobasis u, v, w (horizontal, up, -direction)
  • Field of view angle
  • Image rectangle height, width

32
Perspective vs. Orthographic
perspective
orthographic
  • Parallel projection
  • No foreshortening
  • No vanishing point

33
Orthographic Camera
  • Ray Generation?
  • Origin center (x-0.5)sizehorizontal
    (y-0.5)sizeup
  • Direction is constant

34
Other Weird Cameras
  • E.g. fish eye, omnimax, panorama

35
Questions?
36
Overview of Today
  • Ray Casting Basics
  • Camera and Ray Generation
  • Ray-Plane Intersection
  • Ray-Sphere Intersection

37
Ray 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

38
Recall Ray Representation
  • Parametric line
  • P(t) Ro t Rd
  • Explicit representation

P(t)
direction
origin
Rd
Ro
39
3D 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!

40
Explicit 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

41
Ray-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)
42
Additional 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)
43
Normal
  • For shading
  • diffuse dot product between light and normal
  • Normal is constant

normal
44
A 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!

45
Questions?
  • Image by Henrik Wann Jensen

46
Overview of Today
  • Ray Casting Basics
  • Camera and Ray Generation
  • Ray-Plane Intersection
  • Ray-Sphere Intersection

47
Sphere Representation?
  • Implicit sphere equation
  • Assume centered at origin (easy to translate)
  • H(P) PP - r2 0

Rd
Ro
48
Ray-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
49
Ray-Sphere Intersection
  • Quadratic at2 bt c 0
  • a 1 (remember, Rd 1)
  • b 2RdRo
  • c RoRo r2
  • with discriminant
  • and solutions

50
Ray-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-)

51
Ray-Sphere Intersection
  • It's so easy that all ray-tracing images have
    spheres!

52
Geometric 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?

53
Geometric 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
54
Geometric 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
55
Geometric 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
56
Geometric 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
57
Geometric vs. Algebraic
  • Algebraic is simple generic
  • Geometric is more efficient
  • Timely tests
  • In particular for rays outside and pointing away

58
Sphere Normal
  • Simply Q/Q
  • Q P(t), intersection point
  • (for spheres centered at origin)

O
Ro
Rd
Q
normal
59
Questions?
60
Precision
  • What happens when
  • Origin is on an object?
  • Grazing rays?
  • Problem with floating-point approximation

61
The 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
62
The evil e a hint of nightmare
  • Edges in triangle meshes
  • Must report intersection (otherwise not
    watertight)
  • No false negative

63
Assignment 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

64
Object-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)
65
Books
  • Peter Shirley Fundamentals of Computer
    GraphicsAK Peters
  • Ray Tracing

66
Questions?
67
Next Time More Ray Casting
  • Other primitives
  • Boxes
  • Polygons
  • Triangles
  • IFS?
Write a Comment
User Comments (0)
About PowerShow.com