Ray Intersection Steve Marschner CS 4620 Cornell University - - PowerPoint PPT Presentation

ray intersection
SMART_READER_LITE
LIVE PREVIEW

Ray Intersection Steve Marschner CS 4620 Cornell University - - PowerPoint PPT Presentation

Ray Intersection Steve Marschner CS 4620 Cornell University Cornell CS4620 Fall 2020 Steve Marschner 1 Ray Intersection 1. Ray-sphere intersection Cornell CS4620 Fall 2020 Steve Marschner 2 Ray: a half line Standard


slide-1
SLIDE 1

Steve Marschner CS 4620 Cornell University

Steve Marschner • Cornell CS4620 Fall 2020

Ray Intersection

1

slide-2
SLIDE 2
  • 1. Ray-sphere intersection

Steve Marschner • Cornell CS4620 Fall 2020

Ray Intersection

2

slide-3
SLIDE 3
  • Standard representation: origin point and direction

– this is a parametric equation for the line – lets us directly generate the points on the line – if we restrict to then we have a ray – note replacing with doesn’t change ray (for )

p d r(t) = p + td t > 0 d αd α > 0

Steve Marschner • Cornell CS4620 Fall 2020

Ray: a half line

3

slide-4
SLIDE 4
  • Condition 1: point is on ray
  • Condition 2: point is on sphere

– assume unit sphere; see book or notes for general

  • Substitute:

– this is a quadratic equation in t

Steve Marschner • Cornell CS4620 Fall 2020

Ray-sphere intersection: algebraic

4

slide-5
SLIDE 5
  • Solution for t by quadratic formula:

– simpler form holds when d is a unit vector but we won’t assume this in practice (reason later) – I’ll use the unit-vector form to make the geometric interpretation

Steve Marschner • Cornell CS4620 Fall 2020

Ray-sphere intersection: algebraic

5

slide-6
SLIDE 6

Steve Marschner • Cornell CS4620 Fall 2020

Ray-sphere intersection: geometric

6

slide-7
SLIDE 7
  • With eye ray generation and sphere intersection

Surface s = new Sphere((0.0, 0.0, 0.0), 1.0); for 0 <= iy < ny for 0 <= ix < nx { ray = camera.getRay(ix, iy); hitSurface, t = s.intersect(ray, 0, +inf) if hitSurface is not null image.set(ix, iy, white); }

Steve Marschner • Cornell CS4620 Fall 2020

Image so far

7

slide-8
SLIDE 8
  • 2. Ray-triangle intersection

Steve Marschner • Cornell CS4620 Fall 2020

Ray Intersection

8

slide-9
SLIDE 9
  • A coordinate system for triangles

– algebraic viewpoint: – geometric viewpoint (areas):

  • Triangle interior test:

[Shirley 2000] Steve Marschner • Cornell CS4620 Fall 2020

Barycentric coordinates

9

slide-10
SLIDE 10
  • A coordinate system for triangles

– geometric viewpoint: distances – linear viewpoint: basis of edges

Steve Marschner • Cornell CS4620 Fall 2020

Barycentric coordinates

10

slide-11
SLIDE 11
  • Linear viewpoint: basis for the plane

– in this view, the triangle interior test is just

[Shirley 2000] Steve Marschner • Cornell CS4620 Fall 2020

Barycentric coordinates

11

slide-12
SLIDE 12
  • Every point on the plane can be written in the form:

for some numbers β and .

  • If the point is also on the ray then it is

for some number t.

  • Set them equal: 3 linear equations in 3 variables

…solve them to get t, β, and all at once!

Steve Marschner • Cornell CS4620 Fall 2020

Barycentric ray-triangle intersection

12

p + td a + β(b − a) + γ(c − a) p + td = a + β(b − a) + γ(c − a)

γ γ

slide-13
SLIDE 13

p + td = a + β(b − a) + γ(c − a) β(a − b) + γ(a − c) + td = a − p ⇥a − b a − c d⇤ 2 4 β γ t 3 5 = ⇥a − p⇤ 2 4 xa − xb xa − xc xd ya − yb ya − yc yd za − zb za − zc zd 3 5 2 4 β γ t 3 5 = 2 4 xa − xp ya − yp za − zp 3 5

Steve Marschner • Cornell CS4620 Fall 2020

Barycentric ray-triangle intersection

13

Cramer’s rule is a good fast way to solve this system (see text Ch. 2 and Ch. 4 for details)

slide-14
SLIDE 14
  • 3. Ray intersection software

Steve Marschner • Cornell CS4620 Fall 2020

Ray Intersection

14

slide-15
SLIDE 15
  • Rays are a useful datatype: pair origin with direction
  • Also very useful to make rays into ray segments

– store a start (minimum ) and end (maximum ) – ray intersections only count if is between start and end

t t t

Steve Marschner • Cornell CS4620 Fall 2020

Rays

15

class Ray { Point origin Vector direction float start float end; }

slide-16
SLIDE 16
  • All surfaces need to be able to intersect rays with themselves

– surfaces with multiple intersections must return the first one – convenient to return when there is no intersection

t = +∞

Steve Marschner • Cornell CS4620 Fall 2020

Surfaces

16

class Surface { boolean intersect(Hit hit, Ray r) … } is there any intersection? information about first intersection ray to be intersected class Hit { float t Surface surface Vector position Vector normal … }

slide-17
SLIDE 17

Intersection with ray segments

Steve Marschner • Cornell CS4620 Fall 2020 17

[ ] t = 0 tstart tend [ ] [ ] [ ]

slide-18
SLIDE 18
  • Scenes contain many objects
  • Need to find the first intersection along the ray

– that is, the one with the smallest positive t value in [start, end]

Steve Marschner • Cornell CS4620 Fall 2020

Scenes

18

class Scene { List<Surface> surfaces … }

slide-19
SLIDE 19
  • Input is a ray and a collection of surfaces
  • Simple linear time algorithm:
  • This is fine for small scenes, too slow for large ones

– real applications use sublinear methods (acceleration structures) which we will see later

Steve Marschner • Cornell CS4620 Fall 2020

Intersection against many shapes

19

function intersect(ray, surfaceList) for surface in surfaceList intersect ray against surface if hit, reduce ray.end to of hit return surface corresponding to minimum- intersection

t t