13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

31
13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing

Transcript of 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

Page 1: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.1si31_2001

SI31Advanced Computer

GraphicsAGR

SI31Advanced Computer

GraphicsAGR

Lecture 13

An Introduction to Ray Tracing

Page 2: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.2si31_2001

Ray TracingRay Tracing

Ray tracing is an alternative rendering approach to the polygon projection, shading and z-buffer way of working

It is capable of high quality images through taking account of global illumination

Page 3: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.3si31_2001

Ray Tracing ExampleRay Tracing Example

Page 4: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.4si31_2001

Firing RaysFiring Rays

pixel positionson view plane

camera

The view planeis marked with agrid correspondingto pixel positionson screen.

A ray is traced fromthe camera througheach pixel in turn.

light

Page 5: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.5si31_2001

Finding IntersectionsFinding Intersections

pixel positionson view plane

camera

We calculate theintersection of the ray with all objectsin the scene.

The nearest inter-section will be thevisible surface forthat ray

light

Page 6: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.6si31_2001

Intensity CalculationIntensity Calculation

pixel positionson view plane

camera

The intensity at this nearest intersectionis found from the usual Phongreflection model.

Stopping at thispoint gives us a verysimple renderingmethod.

Often called:ray casting

light

Page 7: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.7si31_2001

Phong Reflection ModelPhong Reflection Model

lightsourceN

LR

Veye

surface

I() = Ka()Ia() + ( Kd()( L . N ) + Ks( R . V )n ) I*() / dist

Note: R.V calculation replaced by H.N for speed - H = (L+V)/2

dist = distance attenuation factor

Here V is direction of incoming ray, N is normal, L is direction tolight source, and R is direction of perfect spec. reflection.

Page 8: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.8si31_2001

Intensity CalculationIntensity Calculation

pixel positionson view plane

camera

Thus Phong reflectionmodel gives us intensity at point based on alocal model:

I = I local

whereI local = I ambient +

I diffuse + I specular

Intensity calculatedseparately for red, green, blue

light

Page 9: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.9si31_2001

ShadowsShadows

pixel positionson view plane

camera

To determine ifthe point is in shadow,we can fire a ray atthe light source(s) -in direction L.

If the ray intersectsanother object, then point is in shadowfrom that light.In this case, we just useambient component:I local = I ambient

Otherwise the point isfully lit.

light

shadowray

Note this has tobe done for every

light source in scene.

Page 10: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.10si31_2001

Reflected RayReflected Ray

pixel positionson view plane

camera

Ray tracing modelsreflections by lookingfor light coming inalong a secondaryray, making a perfectspecular reflection.

R1 = V - 2 (V.N) N

R1

light

Page 11: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.11si31_2001

Reflected Ray- Intersection and Recursion

Reflected Ray- Intersection and Recursion

We calculate theintersection of thisreflected ray, with allobjects in the scene.

The intensity at thenearest intersection point is calculated, and added as a contributionattenuated by distance.

This is done recursively.pixel positionson view plane

camera

light

Page 12: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.12si31_2001

Reflected Ray - Intensity Calculation

Reflected Ray - Intensity Calculation

pixel positionson view plane

camera

light

The intensity calculationis now:I = I local + k r * I reflected

Here I reflected

is calculated recursively

k r is a reflection coefficient (similar to k s )

Page 13: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.13si31_2001

Ray TerminationRay Termination

pixel positionson view plane

camera

Rays terminate:- on hitting diffusesurface- on going to infinity- after severalreflections - why?

Page 14: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.14si31_2001

Transmitted RayTransmitted Ray

If the object is semi-transparent, we alsoneed to take into account refraction

pixel positionson view plane

camera

light

Thus we follow alsotransmitted rays,eg T1.

T1

Page 15: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.15si31_2001

RefractionRefraction

N

V

T

ir

r

i Change in directionis determined by therefractive indices ofthe materials, i and r

Snell’s Law:sin r = (i / r ) * sin i

T = (i / r ) V - ( cos r - (i / r ) cos i ) N

Page 16: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.16si31_2001

Refraction ContributionRefraction Contribution

The contribution due to transmitted light is taken as:

kt * It( ) – where

kt is the transmission coefficient

It( ) is the intensity of transmitted light, again calculated separately for red, green, blue

Page 17: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.17si31_2001

Intensity CalculationIntensity Calculation

pixel positionson view plane

camera

The intensity calculationis now:I = I local + k r * I reflected

+ k t * I transmitted

I reflected and I transmitted

are calculated recursively

Page 18: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.18si31_2001

Binary Ray Tracing TreeBinary Ray Tracing Tree

S1

S2 S3

S4

pixel positionson view plane

camera

S1

S2 S3

S4

R1T1

T1R1

The intensity iscalculated bytraversing the treeand accumulatingintensities

light

Page 19: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.19si31_2001

Calculating Ray Intersections

Calculating Ray Intersections

A major part of ray tracing calculation is the intersection of ray with objects

Two important cases are:– sphere– polygon

Page 20: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.20si31_2001

Ray - Sphere IntersectionRay - Sphere Intersection

Let camera position be (x1, y1, z1)Let pixel position be (x2, y2, z2)

Any point on ray is:x(t) = x1 + t * (x2 - x1) = x1 + t * iy(t) = y1 + t * (y2 - y1) = y1 + t * jz(t) = z1 + t * (z2 - z1) = z1 + t * k

As t increases from zero, x(t), y(t), z(t) traces outthe line from (x1, y1, z1) through (x2, y2, z2).

Equation of sphere, centre (l, m, n) and radius r:(x - l)2 + (y - m)2 + (z - n)2 = r2

Page 21: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.21si31_2001

Ray - Sphere IntersectionRay - Sphere Intersection

Putting the parametric equations for x(t), y(t), z(t) inthe sphere equation gives a quadratic in t:

at2 + bt + c = 0

Exercise: write down a, b, c in terms of i, j, k, l, m, n, x1, y1, z1

Solving for t gives the intersection points:

b2 - 4ac < 0 no intersectionsb2 - 4ac = 0 ray is tangentb2 - 4ac > 0 two intersections, we want smallest positive

Page 22: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.22si31_2001

Ray - Polygon IntersectionRay - Polygon Intersection

Equation of ray:x(t) = x1 + t * iy(t) = y1 + t * jz(t) = z1 + t * k

Equation of plane:ax + by + cz + d = 0

Intersection:t = - (ax1 + by1 + cz1 + d) / (ai + bj + ck)

Need to check intersection within the extent of the polygon.

Page 23: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.23si31_2001

Ray Tracing - LimitationsRay Tracing - Limitations

This basic form of ray tracing is often referred to as Whitted ray tracing after Turner Whitted who did much of the early work...

Ray tracing in its basic form is computationally intensive

Much research has gone into increasing the efficiency and this will be discussed in next lecture.

Page 24: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.24si31_2001

Ray Tracing ExampleRay Tracing Example

Page 25: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.25si31_2001

Depth 0Depth 0

Page 26: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.26si31_2001

Depth 1Depth 1

Page 27: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.27si31_2001

Depth 2Depth 2

Page 28: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.28si31_2001

Depth 3Depth 3

Page 29: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.29si31_2001

Depth 4Depth 4

Page 30: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.30si31_2001

Depth 7Depth 7

Page 31: 13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.

13.31si31_2001

AcknowledgementsAcknowledgements

As ever, thanks to Alan Watt for the excellent images