Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
CS 475 / CS 675Computer Graphics
Lecture 19 : Ray Tracing 2
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Transforming normals
q
q '
sc t
s 'c ' t 'M
M−1
We also need the normal at the point of intersection. How does the normal transform when the object undergoes an affine transformation?
Object Space
World SpaceN
N '
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Transforming normals
Incorrect
Correct
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
● If is an vector in the tangent plane then after the transformation it becomes
● The correct transformation to be applied to the normal should keep it perpendicular to the tangent vector.
Ray Tracing
● Transforming normals – think about the tangents instead
N
VT
N '
V ' T
N '
V ' T
Incorrect Incorrect
V 'T =M.V T
V T
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Transforming normals – think about the tangents instead
N
V T
N '
V ' T
N '
V ' T
Incorrect Incorrect
N T V T=0⇒N T
M−1 M V T=0⇒N T . M−1 M.V T =0
⇒N T . M−1V 'T=0
⇒ N 'T V ' T=0
⇒ N '=N T . M−1T=M−1
T . N
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Ray Casting – Single Step Ray Tracing
– For every pixel in the image● Shoot a ray ● Find closest intersection with object● Find normal at the point of intersection● Compute illumination at point of
intersection● Assign pixel color
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Recursive Ray Tracing
Viewer
ViewPlane
A
B
C
D
E
F
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Recursive Ray Tracing
A
BC
D
EF
Eye
D
DC
C F
E
Eye
● Primary Rays - from the Eye
● Secondary Rays – Reflection, Refraction
● Shadow Rays
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Reflected Ray
– Angle of Incidence = Angle of Reflection
I
I
N
R
−I . N N
−I . N NR=I−2 I . N N
I R
Incident Ray
Reflected Ray
Surface Normal
I
R
N
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Transmitted Ray
I sinI =T sin T
I
T
N
M
M sinI
I
T
−N
−N cos I
T
I
I
T
=sinT
sin I
=R
I=M sin I −N cosI
⇒ M= IN cosI /sinI
T =−N cosTM sinT
=−N cosT IN cosI sinT
sinI
=RI R cos I −cosT N
=RI R cosI −1− R
2 1−cos2 I N
=RI R −N .I −1− R
2 1−−N .I 2 N
Normalize the result!
Snell-Descartes Law
- Incident Ray
So the transmitted ray is given by:
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Transmitted Ray
I sin I=T sin T
I
T
N
M
M sinI
I
T
−N
−N cosI
T
I
I
T
=sinT
sinI
=R
I=M sinI −N cosI
⇒ M= IN cosI/sin I
T=−N cosT M sinT
=−N cosT IN cosI sinT
sinI=R
I R cosI−cosT N
=RI R cosI−1− R
2 1−cos2 I N
=RI R −N .I −1− R
2 1−−N .I 2 N
Snell-Descartes Law
So the transmitted ray is given by:
What happens when the square root is imaginary?
- Incident Ray
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Transmitted RayN
T=m
I=1
Entering and Leaving transmissive material is different – check dot product with normal.
N
I =m
T=1
I
T
I
T
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Total Internal Reflection
Image from Color and light in nature by David K. Lynch, William Charles LivingstonCS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
Whitted, T. "An improved illumination model for shaded display”, Communications of the ACM, 23(6):343-349, 1980.
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
Enright, D., Marschner, S. and Fedkiw, R., "Animation and Rendering of Complex Water Surfaces", SIGGRAPH 2002, ACM TOG 21, 736-744 (2002).
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Illumination : The Phong Model
– For a single light source total illumination at any point is given by:
I=k a I ak d I dk s I s
where
is the contribution due to ambient reflection
is the contribution due to diffuse reflection
is the contribution due to specular reflection
k a I a
kd I d
k s I s
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Components of the Phong Model
● Ambient Illumination:
– Represents the reflection of all indirect illumination.
– Has the same value everywhere.
– Is an approximation to computing Global Illumination.
I a
From http://en.wikipedia.org/wiki/Global_illumination (14/08/2009) CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Components of the Phong Model
● Diffuse Illumination:
– Assumes Ideal Diffuse Surface – that reflects light equally in all direction.
– Surface is very rough at microscopic level. For e.g., Chalk and Clay.
Id=I L cosL
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Components of the Phong Model
● Diffuse Illumination:
– Reflects light according to Lambert's Cosine Law
I d=I L cosL
Id=I L cosL
=I L L . N
: vector to the light source
: intensity of the light source
: surface normal
L
N
I L
=I L L . N N−L
≡
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Components of the Phong Model
● Diffuse Illumination:
– Reflects light according to Lambert's Cosine Law
Id=I L cosL
I d=I L cosL
=I L L . N N−L
≡
If and are in opposite directions then the dot product is negative. Use to get the correct value.
If is distance to the light source and is its true intensity then a distance based attenuation is modelled by an inverse square falloff, i.e.,
L Nmax L . N , 0
r I t
I L= I t /r2
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Components of the Phong Model
● Specular Illumination:
– Ideal specular surface reflects only along one direction.
– Reflected intensity is view dependent – Mostly it is along the reflected ray but as we move away some of the reflection is slightly offset from the reflected ray due to microscopic surface irregularites.
I s=I L cosnv=I L R . V
n
NL R
L
NL R
L VV
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Components of the Phong Model
● Specular Illumination:– is called the coefficient of shininess and
I s=I L cosnv=I L R . V
n
n
cosn
I L= I t /r2
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● The Phong Illumination Model
I=k a I ak d I dk s I s
– are material constants defining the amount of light that is reflected as ambient, diffuse and specular. They may be defined in as three values with R, G, B components.
ka , kd , k s
http://en.wikipedia.org/wiki/Phong_shading
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● The Blinn-Phong Illumination Model
H=LV
∥LV∥
NL R
H
v=
=
⇒v−= or v=2I s=I L cosn 'ϕ=I L(H⃗ . N⃗ )
n
V
v
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
● Local Illumination Model
Global Illumination Model
● Reflected and transmitted components may also be attenuated based on distance the ray travels.
Ray Tracing
I local=k a I a ∑1≤i≤m
kd I dik s I si
I global=I localk r I reflectedk t I transmitted
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
● Surface Material Properties
● Colour – For each object there can be a
– Diffuse colour, Specular colour, Reflected colour and Transmitted colour
– Remember differently coloured light is at different wavelength so:
● Accounting for shadows:
Ray Tracing
I =k a C d I a ∑1≤i≤m
kd C d I dik s C s I sik r C r I rk t C t I t
I =k aC d Ia ∑
1≤i≤m
S i k d C d I dik sC s
I si k r C r I rk t C t I t
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Recursive Ray Tracing
A
B C
D
EF
Eye
D
Eye
L1
L2
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Recursive Ray Tracing
A
B C
D
EF
Eye
D
Eye
L1
L2
C D
L1
L2
L1
L2
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Recursive Ray Tracing
A
B C
D
EF
Eye
D
Eye
L1
L2
C D L1
L2
L1
L2
C
E
FL1
L2
● Stop
– When a ray leaves the scene
– Contributed intensity is too less
L1
L2
L1
L2
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Recursive Ray Tracing
A
B C
D
EF
Eye
D
Eye
L1
L2
C D L1
L2
L1
L2
C
E
FL1
L2
● Complexity?
L1
L2
L1
L2
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Recursive Ray Tracing
A
B C
D
EF
Eye
D
Eye
L1
L2
C D L1
L2
L1
L2
C
E
FL1
L2
● Complexity = h x w x Nobjects
x interesection cost x depth of recursion x N
shadow_rays x ...
L1
L2
L1
L2
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Aliasing – Discrete samples of a continuous world
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Anti-aliasing – Shoot more rays per pixel - super sample!
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
● Sampling strategies for anti-aliasing
Regular super sampling
Adaptive super sampling
Stochastic or jittered super sampling
● Aliasing vs. Noise
● Aggregating the samples.
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Ray Tracing
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
Distributed Ray Tracing
http://www.cs.utexas.edu/~fussell/
http://web.cs.wpi.edu/~matt/courses/cs563/talks/dist_ray/dist.html
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
The Rendering EquationLo x , , , t=L e x , , , t ∫
f r x , ' , , , t Li x , ' , , t −⋅nd '
Lo x , , , t is the total amount of light of wavelength , directed outward along direction at time t , from a particular position x
Le x , , , t is the emitted light.
L i x , ' , , t is the light of wavelength , coming inward toward xfrom direction ' at time t
f r x , ' , , , t is the bidirectional reflectance distribution function (BRDF),i.e., the proportion of light reflected from ' to at position x , time t ,and at wavelength
∫
... d ' is the integral over a sphere of inward directions
−⋅n is the attenuation of incident light due to incident angle
CS475/CS675: Lecture 18 Parag Chaudhuri, 2015
The Rendering EquationLo x , , , t=L e x , , , t ∫
f r x , ' , , , t L i x , ' , ,t −⋅nd '
● Is this enough?● BTDF - Refraction, BSDF – Sub surface
scattering● Phosphoresence● Diffraction● Atmospheric Scattering