cs 775 advanced computer graphicsparagc/teaching/2015/cs775/lectures/07_… · cs775: lecture 7...

39
CS 775 Advanced Computer Graphics Lecture 7 : Ray Tracing 2

Upload: others

Post on 23-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS 775Advanced Computer Graphics

Lecture 7 : Ray Tracing 2

Page 2: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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 '

Page 3: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Transforming normals

Incorrect

Correct

Page 4: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

V T

N '

V 'T

N '

V 'T

Incorrect Incorrect

V 'T=M.V T

V T

Page 5: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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−1

V 'T=0⇒ N 'T V 'T=0

⇒ N '=NT . M−1T=M−1

T . N

Page 6: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 7: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Recursive Ray Tracing

Viewer

ViewPlane

A

B

C

D

E

F

Page 8: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 9: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Reflected Ray

– Angle of Incidence = Angle of Reflection

I

I

N

R

−I . N N

−I . N NR=I−2I . N N

I R

Incident Ray

Reflected Ray

Surface Normal

I

R

N

Page 10: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Transmitted Ray

I sinI=T sin T

I

T

N

M

M sinI

I

T

−N

−N cosI

T

I

I

T=

sinT

sin I

=R

I=M sinI−N cosI

⇒ M= IN cosI /sinI

T =−N cosTM sinT

=−N cosT IN cosI sinT

sin I=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

Normalize the result!

Snell-Descartes Law

- Incident Ray

So the transmitted ray is given by:

Page 11: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Transmitted Ray

I sinI=T sin T

I

T

N

M

M sinI

I

T

−N

−N cosI

T

I

I

T=

sinT

sin I

=R

I=M sinI−N cosI

⇒ M= IN cosI /sinI

T =−N cosTM sinT

=−N cosT IN cosI sinT

sin I=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

Page 12: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 13: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Total Internal Reflection

Image from Color and light in nature by David K. Lynch, William Charles Livingston

Page 14: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

Whitted, T. "An improved illumination model for shaded display”, Communications of the ACM, 23(6):343-349, 1980.

Page 15: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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).

Page 16: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

k d I d

k s I s

Page 17: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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)

Page 18: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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.

I d=I L cosL

Page 19: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

I d=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

Page 20: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

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

Page 21: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 22: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 23: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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.

k a , k d , k s

http://en.wikipedia.org/wiki/Phong_shading

Page 24: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 25: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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 localkr I reflectedk t I transmitted

Page 26: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

k d Cd I dik s C s I sik r C r I rk t C t I t

I =k a C d I a ∑1≤i≤m

Si k d Cd I dik s C s I sik r C r I rk t C t I t

Page 27: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Recursive Ray Tracing

A

B C

D

EF

Eye

D

Eye

L1

L2

Page 28: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Recursive Ray Tracing

A

B C

D

EF

Eye

D

Eye

L1

L2

C D

L1

L2

L1

L2

Page 29: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 30: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 31: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 32: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Aliasing – Discrete samples of a continuous world

Page 33: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

● Anti-aliasing – Shoot more rays per pixel - super sample!

Page 34: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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.

Page 35: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

Page 36: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

Ray Tracing

Page 37: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 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

Page 38: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

The Rendering EquationLo x , , , t =L ex , , , t ∫

f r x , ' , , , t L i 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 ' toat 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

Page 39: CS 775 Advanced Computer Graphicsparagc/teaching/2015/cs775/lectures/07_… · CS775: Lecture 7 Parag Chaudhuri, 2015 Ray Tracing Transforming normals q q' s ct M s' c' t' M−1 We

CS775: Lecture 7 Parag Chaudhuri, 2015

The Rendering EquationLo x , , , t =L ex , , , t ∫

f r x , ' , , , t L i x , ' , , t −⋅nd '

● Is this enough?● BTDF - Refraction, BSDF – Sub surface

scattering● Phosphoresence● Diffraction● Atmospheric Scattering