23
Ray tracing secondary rays: refraction, reflection and supersampling COSC342 Lecture 12 2 Apr 2015

Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

Ray tracing secondary rays:refraction, reflection and supersampling

COSC342

Lecture 122 Apr 2015

Page 2: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

Whitted’s ray tracer clearly supported refraction

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 2

Page 3: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

i

r

n

What is refraction?

sin i = n sin r

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 3

Page 4: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

Effect of refraction

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 4

Page 5: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 6: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 7: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

Refracted ray

The refracted ray v′ will have:

I a ‘parallel’ part v′par in the direction of v − (v · n)n, and magnitude‖v′par‖ = ‖v − (v · n)n‖n1

n2

I and a ‘normal’ part, the right size to make up a unit vectorv′nor = k(v · n)n

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 = 1

I So, we have:

k =

√1− (v′par )2

((v · n)n)2

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 7

Page 8: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

n

r

i

Total internal reflection

I n1 sin i = n2 sin r

I sin r = n1n2

sin i

I if n1 > n2,

I sin r can be > 1

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 8

Page 9: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 10: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

Ray propagation—from the eye . . .

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 10

Page 11: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

. . . to the reflected/refracted rays . . .

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 11

Page 12: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

. . . and considering shadow rays from each hit point

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 12

Page 13: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 14: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 15: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 16: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 17: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 18: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

We would like to avoid aliasing effects

I The jaggies,

I versus antialiased output:

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 18

Page 19: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 20: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

Supersampling

I Fire multiple rays per pixel

I How expensive will this be?

COSC342 Ray tracing secondary rays: refraction, reflection and supersampling 20

Page 21: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 22: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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

Page 23: Ray tracing secondary rays: refraction, reflection and supersampling · 2016. 2. 17. · 1 sini = n 2 sinr I n for air is almost 1.0 I (Also, note that this is the third unrelated

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