CS 551/651: Advanced Computer Graphics

15
David Luebke 1 08/17/22 CS 551/651: Advanced Computer Graphics Accelerating Ray Tracing

description

CS 551/651: Advanced Computer Graphics. Accelerating Ray Tracing. Ray-Sphere Intersection. Ray R = O + tD x = O x + t * D x y = O y + t * D y z = O z + t * D z Sphere at ( l, m, n ) of radius r is: ( x - l ) 2 + ( y - m ) 2 + ( z - n ) 2 = r 2 - PowerPoint PPT Presentation

Transcript of CS 551/651: Advanced Computer Graphics

Page 1: CS 551/651:  Advanced Computer Graphics

David Luebke 1 04/19/23

CS 551/651: Advanced Computer Graphics

Accelerating Ray Tracing

Page 2: CS 551/651:  Advanced Computer Graphics

David Luebke 2 04/19/23

Ray-Sphere Intersection

Ray R = O + tDx = Ox + t * Dx

y = Oy + t * Dy

z = Oz + t * Dz

Sphere at (l, m, n) of radius r is:(x - l)2 + (y - m)2 + (z - n)2 = r 2

Substitute for x,y,z and solve for t…

Page 3: CS 551/651:  Advanced Computer Graphics

David Luebke 3 04/19/23

Ray-Sphere Intersection

Works out as a quadratic equation:at2 + bt + c = 0

where

a = Dx2 + Dy

2 + Dz2

b = 2Dx (Ox - l) + 2Dy (Oy - m) + 2Dz (Oz - n)

c = l2 + m2 + n2 + Ox2 + Oy

2 + Oz2

- 2(l Ox + m Oy + n Oz + r2)

Page 4: CS 551/651:  Advanced Computer Graphics

David Luebke 4 04/19/23

Ray-Sphere Intersection

If solving for t gives no real roots: ray does not intersect sphere

If solving gives 1 real root r, ray grazes sphere where t = r

If solving gives 2 real roots (r1, r2), ray intersects sphere at t = r1 & t = r2

Ignore negative values Smallest value is first intersection

Page 5: CS 551/651:  Advanced Computer Graphics

David Luebke 5 04/19/23

Ray-Sphere Intersection

Find intersection point Pi = (xi, yi, zi) by plugging t back into ray equation

Find normal at intersection point by subtracting sphere center from Pi and normalizing:

(When might we need the normal? When not?)

r

nz

r

my

r

lxN

iii,,

Page 6: CS 551/651:  Advanced Computer Graphics

David Luebke 6 04/19/23

Ray-Polygon Intersection

Polygons are the most common model representation (Why?)

Basic approach: Find plane equation of polygon Find intersection of ray and plane Does polygon contain intersection point?

Page 7: CS 551/651:  Advanced Computer Graphics

David Luebke 7 04/19/23

Ray-Polygon Intersection

Find plane equation of polygon:ax + by + cz + d = 0

How?N = [a, b, c]

d = N P1

(How to find N ?) x

yN

P1

P2

d

Page 8: CS 551/651:  Advanced Computer Graphics

David Luebke 8 04/19/23

Ray-Polygon Intersection

Find intersection of ray and plane:t = -(aOx + bOy + cOz + d) / (aDx + bDy + cDz)

Does poly contain intersection point Pi ? Book’s algorithm:

Draw line from Pi to each polygon vertex Measure angles between lines (how?) If sum of angles between lines is 360°,

polygon contains Pi

Page 9: CS 551/651:  Advanced Computer Graphics

David Luebke 9 04/19/23

Ray-Box Intersection

Often want to find whether a ray hits an axis-aligned box (Why?)

One way: Intersect the ray with the pairs of parallel planes

that form the box If the intervals of intersection overlap, the ray

intersects the box.

Page 10: CS 551/651:  Advanced Computer Graphics

David Luebke 10 04/19/23

Shadow Ray Problems:Too Much Computation

Light buffer (Haines/Greenberg, 86) Precompute lists of polygons surrounding light source in

all directions Sort each list by distance to light source Now shadow ray need only be intersected with appropriate

list!

Light BufferOccluding Polys

ShadowRay

Current Intersection Point

Page 11: CS 551/651:  Advanced Computer Graphics

David Luebke 11 04/19/23

Shadow Ray Problems:Sharp Shadows

Why are the shadows sharp? A: Infinitely small point light sources What can we do about it? A: Implement area light sources How?

Page 12: CS 551/651:  Advanced Computer Graphics

David Luebke 12 04/19/23

Shadow Ray Problems: Area Light Sources

30% blockage

Could trace a conical beam from point of intersection to light source:

Track portion of beam blocked by occluding polygons:

Page 13: CS 551/651:  Advanced Computer Graphics

David Luebke 13 04/19/23

Shadow Ray Problems:Area Light Sources

Too hard! Approximate instead: Sample the light source over its area and take

weighted average:

50% blockage

Page 14: CS 551/651:  Advanced Computer Graphics

David Luebke 14 04/19/23

Shadow Ray Problems:Area Light Sources

Disadvantages: Less accurate (50% vs. 30% blockage) Oops! Just quadrupled (at least) number of

shadow rays Moral of the story:

Soft shadows are very expensive in ray tracing

Page 15: CS 551/651:  Advanced Computer Graphics

David Luebke 15 04/19/23

The End