csc 305 ray tracing i - university of victoria

29
CSC 305 Ray Tracing I Brian Wyvill The University of Victoria Graphics Group

Upload: others

Post on 13-Nov-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 305 Ray Tracing I - University of Victoria

CSC 305Ray Tracing I

Brian Wyvill

The University of VictoriaGraphics Group

Page 2: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 2

P201 Shirley

Page 3: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 3

Page 4: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 4

Page 5: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 5

Refraction

Page 6: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 6

Reflectionsand Transparency

Page 7: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 7

Ray Traced Images

Sphere with hard shadowpoint sampling source

Sphere with soft shadowsampling wide light source

Ray Traced Shadows

Page 8: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 8

Shadows(hard edged)

Shadows (soft edged)

Page 9: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 9

Realism

depth of field

Page 10: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 10

VEOeecrdisc

ecrd

rbdcbe

•=−−=

−−=

=+

=+

)(

)(222

222

222

222

if (disc<=0) then no intersection;else {

};)(

;VdeEP

discd−+=

=

Vis the unit vector in the direction of the ray origin E.

Ray – sphere intersection test

Test is designed to quickly eliminate the rays that miss the sphere.

d brEe

VUnit Vector

Oc

P

We know: ray origin E ray direction VO, r for the sphere.Find P.

Page 11: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 11

(See Shirley for better method)

Page 12: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 12

Ray Tracing Basics for Implementation

Screen-space point

Film plane point in canonical view volume

World-space ray

(0,0,0)=Px

y

z

Page 13: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 13

Eye Ray

e

Ray Equation:

P(t) = e + t(s – e) parametric line equationv = s-e p(0)=e p(1)=sFor +(ve) t going from t1 < t2then p(t1) closer to the eye than p(t2)(-)ve t behind the eye

s

Page 14: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 14

e

s

Computing s

In our viewing coordinate system (u,v,w) (ws=n)We wish to place the eye at an arbitrary viewing point, e.A window transform: [-0.5, nx-0.5]x[-0.5,ny-0.5] to [l,r]x[b,t]

Page 15: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 15

Arbitrary view point

In matrix form:

=

xu xv xw 0yu yv yw 0zu zv zw 00 0 0 1

1 0 0 xe

0 1 0 ye

0 0 1 ze

0 0 0 1

xs

ys

zs

1

us

vs

ws

1

Page 16: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 16

Page 17: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 17

Level 15Pythagorus Tree

Need to make ray tracing faster!

Page 18: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 18

This implicit treecould not be renderedwith polygons due to insufficient memory.

It had to be ray traced.

Page 19: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 19

Ray Tracing

Flexible, accurate, high-quality renderingSlowSimplest ray tracer:– Test every ray against every object in the scene– N objects, M rays → O(N * M)

Using an acceleration scheme:– Acceleration scheme = sub-linear complexity of N– Grids and hierarchies– N objects, M rays → O(log(N) * M)– Log(N) is a theoretical estimate, in reality it depends on the

scene– Speedups of over 100x for complex scenes are possible

Page 20: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 20

Page 21: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 21

Uniform Grid

Ray steps through the grid and is tested against objects in the grid cells along the path of the rayCan avoid testing the vast majority of the objects for each rayGrid traversal overhead can negate savings…

Page 22: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 22

Uniform Grid

Page 23: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 23

Uniform Grid: problems

Grid does not adapt to empty space and local complexity– Works best for uniformly distributed objects (seldom happens in reality)– Typical scenes have areas of complex geometry with empty space

between themEmpty space:– Time is wasted tracing the ray through empty grid cells

Local complexity:– Too many objects in each grid cell– Could increase grid resolution, but that makes the empty space problem

worseDifficult to choose optimal grid resolution that minimizes rendering time: tradeoff between these two problemsDespite this, a grid is still much better than nothing

Page 24: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 24

Page 25: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 25

Page 26: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 26

Page 27: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 27

Page 28: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 28

Hierarchies

Need a scheme that adapts to the distribution of objects in the sceneBuild a hierarchy or spatial treeThe scene is recursively subdivided into nodes that enclose space and objects– Empty space is not subdivided– Complex areas are subdivided– Subdivide until criteria is met: e.g.

Number of objects in the node is below a certain threshold (4-8 works well)Tree depth reaches a specified maximum

Solves both empty space and local complexity problemsRepresented as a tree data structure in memoryExamples…

Page 29: CSC 305 Ray Tracing I - University of Victoria

University of Victoria Island Graphics Lab. CSC 305 2007 page 29

Hierarchy of Grids

Grid cells/nodes may be empty, contain objects, or contain another grid (e.g. if a cell contains more than 1 object)An object may span multiple nodes or grid cells