1gr2-00 gr2 advanced computer graphics agr lecture 13 an introduction to ray tracing
TRANSCRIPT
![Page 1: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/1.jpg)
1GR2-00
GR2Advanced Computer
GraphicsAGR
GR2Advanced Computer
GraphicsAGR
Lecture 13
An Introduction to Ray Tracing
![Page 2: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/2.jpg)
2GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/3.jpg)
3GR2-00
Ray Tracing ExampleRay Tracing Example
![Page 4: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/4.jpg)
4GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/5.jpg)
5GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/6.jpg)
6GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/7.jpg)
7GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/8.jpg)
8GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/9.jpg)
9GR2-00
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
![Page 10: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/10.jpg)
10GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/11.jpg)
11GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/12.jpg)
12GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/13.jpg)
13GR2-00
Ray TerminationRay Termination
pixel positionson view plane
camera
Rays terminate:- on hitting diffusesurface- on going to infinity- after severalreflections - why?
![Page 14: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/14.jpg)
14GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/15.jpg)
15GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/16.jpg)
16GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/17.jpg)
17GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/18.jpg)
18GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/19.jpg)
19GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/20.jpg)
20GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/21.jpg)
21GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/22.jpg)
22GR2-00
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/23.jpg)
23GR2-00
Ray Tracing - LimitationsRay Tracing - Limitations
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: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/24.jpg)
24GR2-00
Ray Tracing ExampleRay Tracing Example
![Page 25: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/25.jpg)
25GR2-00
Depth 0Depth 0
![Page 26: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/26.jpg)
26GR2-00
Depth 1Depth 1
![Page 27: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/27.jpg)
27GR2-00
Depth 2Depth 2
![Page 28: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/28.jpg)
28GR2-00
Depth 3Depth 3
![Page 29: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/29.jpg)
29GR2-00
Depth 4Depth 4
![Page 30: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/30.jpg)
30GR2-00
Depth 7Depth 7
![Page 31: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing](https://reader035.vdocuments.us/reader035/viewer/2022070306/5515f536550346d46f8b55d1/html5/thumbnails/31.jpg)
31GR2-00
AcknowledgementsAcknowledgements
As ever, thanks to Alan Watt for the excellent images