ray tracing secondary rays: refraction, reflection and ... · refraction recursion: inescapable i...
Post on 21-Aug-2020
9 Views
Preview:
TRANSCRIPT
Ray tracing secondary rays:refraction, reflection and supersampling
COSC342
Lecture 1526 Apr 2016
Whitted’s ray tracer clearly supported refraction
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 2
i
r
n
What is refraction?
sin i = n sin r
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 3
Effect of refraction
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 4
Refractive index n
I The refractive index n is actually a ratio.
I Velocity of light in a medium = cn
I n depends on the medium
I n1 sin i = n2 sin r
I n for air is almost 1.0
I (Also, note that this is the third unrelated type of ‘n’ that we havediscussed recently, alongside normal vectors (n) and the Phongspecular exponent.)
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 5
n
iv
Using vectors
I Ray is u + tv
I n, v are unit vectors
I sin i = ‖v − (v · n)n‖
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 6
Refracted ray
The refracted ray v′ will have:
I a ‘parallel’ part v′par in the direction of v − (v · n)n, i.e., the directionthat’s perpendicular to n . . .
I . . . but whose magnitude is affected by the refractive index, i.e., thechange of speed of the light: ‖v′par‖ = ‖v − (v · n)n‖n1
n2
I Ray v′ also has a ‘normal’ part v′nor , that is the right size for v′ to bea unit vector. So v′nor = k(v · n)n for some scalar k .
I We know that that ‖v′‖ = 1, and v′ = v′par + v′nor
I From Pythagoras’ Theorem,(v′par
)2+ (k(v · n)n)2 = 12
I So, we have:
k =
√1− (v′par )2
((v · n)n)2
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 7
n
r
i
Total internal reflection
I n1 sin i = n2 sin r
I sin r = n1n2
sin i
I if n1 > n2, then we forsome i angles we needsin r > 1 (impossible!)
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 8
The truth is more complicated
I As the incident ray approaches the critical angle the proportion oflight reflected goes up to 100%.
I The amount of reflected and transmitted light is given by Fresnel’sequations. . .
I . . . but those are not part of COSC342 (phew!)
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 9
Ray propagation—from the eye . . .
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 10
. . . to the reflected/refracted rays . . .
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 11
. . . and considering shadow rays from each hit point
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 12
Refraction recursion: inescapable
I Where we just have reflections, we can avoid recursion:I Do the rest of the illumination before sending the reflective rayI i.e., use an accumulator to collect the colour so far, and pass it forward
to the code that handles the reflected ray.
I But when we have refraction, we can spawn two, new, recursive raysat each and every intersection point.
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 13
How deep should we go in terms of recursion?
I Real reflection and refraction is never perfect. We will always lose alittle light energy at each surface interaction.
I So our coefficients kd , ks , kr , kt , for diffuse, specular, reflection andrefraction are all less than 1.0
I For an object with kr = 0.8, after 30 reflections the contribution willbe 0.830 < 1
1000
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 14
Do it in the right order...
void ray(fraction, depth, u, v ...)
{
if (depth > LIMIT) return;
if (fraction < TINY) return;
get hit... do local lighting...
shadows...
ray(fraction*kr, depth+1,
hit, r(v) ...)
ray(fraction*kt, depth+1,
hit, t(v) ...)
}
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 15
Our progress compared to Whitted’s ray tracer
We can now achieve:
I Ambient,
I Lambert,
I Phong,
I shadows,
I reflection,
I refraction,
I point light sources.
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 16
Actually, in some ways this is just the beginning . . .
Problems that we have yet to discuss in detail:
I Aliasing artefactsI No surface/surface illumination
I If you want to read up on this, you might enjoyhttp://escience.anu.edu.au/lecture/cg/
GlobalIllumination/printNotes.en.html
I No caustics
I Shadows are hard (i.e., have hard edges)
I Colour problems
I Very slow
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 17
We would like to avoid aliasing effects
I The jaggies,
I versus antialiased output:
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 18
Aliases
I A given set of samples can represent more than one picture.
I The alternatives are called aliases.
I Antialiasing is mostly about getting the samples to look like thepicture we want.
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 19
Supersampling
I Fire multiple rays per pixel
I How expensive will this be?
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 20
There are many potential patterns for supersampling rays
I What are the pros and cons of the different patterns shown here?
I Is there an answer that will suit all potential scenes?
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 21
Adaptive Sampling
I Another approach is to determine what rays to fire depending on theresults of rays you have alread fired, i.e., adaptive sampling.
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 22
Jittering
I Even when just using one sample per pixel this is an improvement onuniform sampling.
COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 23
top related