You are on page 1of 388

Rendering

186.101
Károly Zsolnai-Fehér

Institute of Computer Graphics and Algorithms (E186)


Vienna University of Technology
http://www.cg.tuwien.ac.at/staff/KarolyZsolnai.html
Assignments

Assignments – 40%
Playful practical assignments with ray tracing
programs, and later with LuxRender
Simple mathematical problems you’ll find
very interesting

5
Assignments

Assignments – 40%
Playful practical assignments with ray tracing
programs, and later with LuxRender
Simple mathematical problems you’ll find very
interesting

Oral exam – 60%


Mostly the explanation of what you did in your
homework assignments – what was correct,
what went wrong
A bit of discussion on the topic of ray tracing

6
Assignments
Assignments – 40%
Playful practical assignments with ray tracing programs, and later
with LuxRender
Simple mathematical problems you’ll find very interesting

Oral exam – 60%


Mostly the explanation of what you did in your homework
assignments – what was correct, what went wrong
A bit of discussion on the topic of ray tracing

Individual contribution in any of below – (+10%, may go over 100)


Demonstration or image creation to be used on the course,
Fix, make something better on the slides, course materials,
Make smallpaint or LuxRender better (any patch, bugfix goes)

7
Reading material

http://pbrt.org/ 8
What you shouldn’t expect of this course

9
What you shouldn’t expect of this course

Rigorous derivations of every imaginable equation


you encounter,

10
What you shouldn’t expect of this course

Rigorous derivations of every imaginable equation


you encounter,

Endless stream of formulae without explanation,

11
What you shouldn’t expect of this course

Rigorous derivations of every imaginable equation


you encounter,

Endless stream of formulae without explanation,

Tutorial on how to write the most complicated


rendering engine ever created,

12
What you shouldn’t expect of this course

Rigorous derivations of every imaginable equation


you encounter,

Endless stream of formulae without explanation,

Tutorial on how to write the most complicated


rendering engine ever created,

You don’t have to memorize any of the formulae.

13
What you should expect of this course

14
What you should expect of this course

How light can be simulated in a simple and


elegant way,

15
What you should expect of this course

How light can be simulated in a simple and


elegant way,

Why nature looks like as it does in real life,

16
What you should expect of this course

How light can be simulated in a simple and


elegant way,

Why nature looks like as it does in real life,

How most state of the art algorithms on ray


tracing and global illumination work,

17
What you should expect of this course

How light can be simulated in a simple and


elegant way,

Why nature looks like as it does in real life,

How most state of the art algorithms on ray


tracing and global illumination work,

How to read, understand and visualize seemingly


complicated mathematical formulae easily.

18
What you should expect of this course

And most importantly:

19
What you should expect of this course

And most importantly:

You will see the world differently.

20
Quick radiometry recap

What to measure in a simulation?


Radiant flux (or power): total amount of energy passing
through a surface (measured per second).

21
Quick radiometry recap

What to measure in a simulation?


Radiant flux (or power): total amount of energy passing
through a surface (measured per second).

22
Quick radiometry recap

What to measure in a simulation?


Radiant flux (or power): total amount of energy passing
through a surface (measured per second).

Why not radiant flux?

23
Quick radiometry recap

What to measure in a simulation?


Radiant flux (or power): total amount of energy passing
through a surface (measured per second).

Why not radiant flux?

Answer: when we measure a large flux somewhere, we don’t


know if:
lots of energy passes through small surface OR
a small amount of energy passes through a huge surface.

They result in the same radiant flux. It’s ambiguous.


24
Quick radiometry recap

25
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area (irradiance).

26
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area (irradiance).

27
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area (irradiance).

Why not irradiance?

28
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area (irradiance).

Why not irradiance?

Answer: we now know what surface area to expect, but we


haven’t fixed the angle in which the light arrives to the surface,
so:
a large amount of energy in a large angle OR
a small amount of energy in a small angle.

They result in the same irradiance.


29
It’s still ambiguous.
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area and unit angle.

30
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area and unit angle.

31
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area and unit angle.

32
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area and unit angle.

(angle in more dimensions is called solid angle, for which the unit is not degrees but
steradians)
33
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area and unit angle.

Why not radiance?

(angle in more dimensions is called solid angle, for which the unit is not degrees but
steradians)
34
Quick radiometry recap

What to measure in a simulation?


Solution: compute the flux by unit area and unit angle.

Why not radiance?


Just kidding, it’s fine.

(angle in more dimensions is called solid angle, for which the unit is not degrees but
steradians)
35
The most fundamental question

How much light exits a surface point in a given


direction?

Solution: the Maxwell equations!

36
The most fundamental question

How much light exits a surface point in a given


direction?

Solution: the Maxwell equations!

In practice, we don’t do that. We mainly work with the ray


representation of light, and we only consider it as an
electromagnetic wave where it is inevitable.

38
The most fundamental question

How much light leaves a surface point in a given


direction?

Solution: the rendering equation!

39
The scalar product

Definition:

We’ll usually work with vectors of unit length,


therefore:

40
Terminology

41
Terminology

42
Terminology

43
Terminology

44
Terminology

45
Terminology

46
Terminology

V should start from the same point as the other vectors to make
computations possible, so in the regular notation, we just flip it.
47
Terminology

Like this.
48
Terminology

Like this.
49
Light attenuation

The sun shines onto a point of a surface precisely


from above. What portion of the output of one ray
will hit the surface?

50
Light attenuation

The sun shines onto a point of a surface precisely


from above. What portion of the output of one ray
will hit the surface?

51
Light attenuation

The sun shines onto a point of a surface precisely


from above. What portion of the output of one ray
will hit the surface?

52
Light attenuation

The sun shines onto a point of a surface precisely


from above. What portion of the output of one ray
will hit the surface?

53
Light attenuation

The sun shines onto a point of a surface precisely from


above. What portion of the output of one ray will hit
the surface?

The full power. 

54
Light attenuation

The sun shines onto a point of a surface in a 45


degree angle. What portion of the output of one
ray will hit the surface?

55
Light attenuation

The sun shines onto a point of a surface in a 45


degree angle. What portion of the output of one
ray will hit the surface?

56
Light attenuation

The sun shines onto a point of a surface in a 45


degree angle. What portion of the output of one
ray will hit the surface?

57
Light attenuation

The sun shines onto a point of a surface in a 45


degree angle. What portion of the output of one
ray will hit the surface?

58
Light attenuation

The sun shines onto a point of a surface in a 45 degree


angle. What portion of the output of one ray will hit
the surface?

~70% of its power.

59
Light attenuation

The sun shines onto a point of a surface in near 90


degree angle. What portion of the output of one
ray will hit the surface?

60
Light attenuation

The sun shines onto a point of a surface in near 90


degree angle. What portion of the output of one
ray will hit the surface?

61
Light attenuation

The sun shines onto a point of a surface in near 90


degree angle. What portion of the output of one ray
will hit the surface?

None.

62
Light attenuation

The sun shines onto a point of a surface in near 90


degree angle. What portion of the output of one ray
will hit the surface?

None.
We can neatly model light attenuation with the use of the scalar product.
63
Materials

What makes the difference between materials?


How to model it?

64
Materials

What makes the difference between materials?


How to model it?

Answer:
Different materials reflect incoming light to
different directions and absorb different amounts
of it.

65
Materials

66
Materials

Let's make a probability density function that takes


•an incoming light direction

•a point on the surface

as parameters, and outputs the probability of a


given outward direction.

67
Materials

Let's make a probability density function that takes


•an incoming light direction

•a point on the surface

as parameters, and outputs the probability of a


given outward direction.

Something like this:

68
Materials

Let's make a probability density function that takes


•an incoming light direction

•a point on the surface

as parameters, and outputs the probability of a


given outward direction.

Something like this:

Formally:

69
BRDF

Let’s call this function the Bidirectional reflectance


distribution function (BRDF)

70
BRDF?

What about materials that don’t reflect all


incoming light, but which also transmit some of it?
For instance: glass, water, gemstones, etc.

71
Materials

72
Materials

73
BTDF

For these type of transfers, we have the


Bidirectional transmittance distribution function.

74
BSDF, BxDF

To generalize the BRDF and BTDF, literature refers


to these as BSDF (S as scattering function), or BxDF.

75
BSDF, BxDF

To generalize the BRDF and BTDF, literature refers


to these as BSDF (S as scattering function), or BxDF.

76
BRDF properties

1. Helmholtz-reciprocity
– The direction of the ray of light can be reversed,

77
BRDF properties

1. Helmholtz-reciprocity
– The direction of the ray of light can be reversed,
– Formally:

78
BRDF properties

1. Helmholtz-reciprocity
– The direction of the ray of light can be reversed,
– Formally:

2. Positivity
– It is an impossibility for an exit direction to have negative
probability. This is to make mathematicians happy.

79
BRDF properties

1. Helmholtz-reciprocity
– The direction of the ray of light can be reversed,
– Formally:

2. Positivity
– It is an impossibility for an exit direction to have negative
probability. This is to make mathematicians happy.
– Formally:

80
BRDF properties
3. Energy conservation
– This is the most important property:

an object may reflect or absorb incoming light, but no


more can come out than the incoming amount.

81
BRDF properties
3. Energy conservation
– This is the most important property:

an object may reflect or absorb incoming light, but no


more can come out than the incoming amount.

– Formally:

82
BRDF properties
3. Energy conservation
– This is the most important property:

an object may reflect or absorb incoming light, but no more


can come out than the incoming amount.

– Formally:

This means that we add up the incoming energy from all


possible incoming directions, taking light attenuation into
account.

If it equals 1, all light is reflected, if it is less than 1, some of


the light is absorbed. More than 1 is impossible.
83
The Rendering equation

An object can emit light itself. It also receives light


from different directions, which it will either reflect or
absorb. Therefore,

85
The Rendering equation

An object can emit light itself. It also receives light


from different directions, which it will either reflect or
absorb. Therefore,

86
The Rendering equation

An object can emit light itself. It also receives light


from different directions, which it will either reflect or
absorb. Therefore,

Formally:

87
The Rendering equation

An object can emit light itself. It also receives light


from different directions, which it will either reflect or
absorb. Therefore,

Formally:

88
The Rendering equation

89
The Rendering equation

90
The Rendering equation

91
The Rendering equation

92
The Rendering equation

93
The Rendering equation

94
The Rendering equation

95
The Rendering equation

Difficulties:
-The exitant radiance of a point x depends on the
incoming radiance of every other point, which also
depend on x,

96
The Rendering equation

Difficulties:
-The exitant radiance of a point x depends on the
incoming radiance of every other point, which also
depend on x,

-It is absolutely hopeless to compute this integral in closed


form,

97
The Rendering equation

Difficulties:
-The exitant radiance of a point x depends on the
incoming radiance of every other point, which also
depend on x,

-It is absolutely hopeless to compute this integral in closed


form,

-The integral is also infinite-dimensional,

98
The Rendering equation

Difficulties:
-The exitant radiance of a point x depends on the
incoming radiance of every other point, which also
depend on x,

-It is absolutely hopeless to compute this integral in closed


form,

-The integral is also infinite-dimensional,

-It is often singular.

99
The Rendering equation

Difficulties:
-The exitant radiance of a point x depends on the
incoming radiance of every other point, which also
depend on x,

-It is absolutely hopeless to compute this integral in closed


form,

-The integral is also infinite-dimensional,

-It is often singular.

As of now, we have insufficient knowledge to even give an


approximate solution to this.
The Rendering equation

101
The Rendering equation

Surface integral formulation:

102
The Rendering equation

Surface integral formulation:

108
BRDF types

Illumination model for ambient BRDF (simplified):

109
BRDF types

Illumination model for ambient BRDF (simplified):

110
BRDF types

Illumination model for ambient BRDF (simplified):

111
BRDF types

Illumination model for ambient BRDF (simplified):

(In this unit we’ll discuss why this is needed)


112
BRDF types

113
BRDF types

Illumination model for diffuse BRDF (simplified):

114
BRDF types

Illumination model for diffuse BRDF (simplified):

115
BRDF types

Illumination model for diffuse BRDF (simplified):

116
BRDF types

Illumination model for diffuse BRDF (simplified):

117
BRDF types

Illumination model for diffuse BRDF (simplified):

Note: the diffuse, and other coefficients may take


different values for different wavelengths. An object
may absorb most of the green light, but may reflect all
incoming red light in the meantime.
The proper term would be .
118
BRDF types

119
BRDF types

Illumination model for specular BRDF (simplified):

120
BRDF types

Illumination model for specular BRDF (simplified):

121
BRDF types

Illumination model for specular BRDF (simplified):

122
BRDF types

Illumination model for specular BRDF (simplified):

123
BRDF types

Illumination model for specular BRDF (simplified):

124
BRDF types

125
BRDF types

126
BRDF types (diffuse)

127
BRDF types (diffuse)

Where is the light source?

128
BRDF types (diffuse)

129
BRDF types (diffuse)

130
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

131
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Diffuse BRDF:

132
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Diffuse BRDF:

Don’t just look what is in the equation, but what isn’t there.
133
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Diffuse BRDF:

Don’t just look what is in the equation, but what isn’t there.
And that’s the view direction (V).
134
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Diffuse BRDF:

The diffuse interreflection depends only on L and N,


therefore it looks the same from
135
every angle.
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

136
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Specular BRDF:

137
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Specular BRDF:

138
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Specular BRDF:

139
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Specular BRDF:

140
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Specular BRDF:

Small angle between V and R

141
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Specular BRDF:

Small angle between V and R –


Large (close to 1) scalar product

142
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?

Specular BRDF:

Small angle between V and R –


Large (close to 1) scalar product.
Bright!

143
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?
It would be different!

Specular BRDF:

Small angle between V and R –


Large (close to 1) scalar product.
Bright!

144
Would this region look the same if I moved my head in
BRDF types (diffuse)
reality?
It would be different!

Specular BRDF:

Small angle between V and R –


Large (close to 1) scalar product.
Bright!
Intuition: „I am standing in the way of the light”

145
Isn’t this beautifully simple?
BRDF types (diffuse)

146
BRDF types (diffuse)

147
BRDF types (diffuse)

148
The illumination equation
This is the simplification of the rendering equation:

149
The illumination equation
This is the simplification of the rendering equation:

Only accounts for the direct illumination of the


light sources,

150
The illumination equation
This is the simplification of the rendering equation:

• Only accounts for the direct illumination of the


light sources,
• The indirect illumination is neglected, the
ambient term helps to reinject some of the lost
energy into the system,

151
The illumination equation
This is the simplification of the rendering equation:

• Only accounts for the direct illumination of the


light sources,
• The indirect illumination is neglected, the
ambient term helps to reinject some of the lost
energy into the system,
• This is indeed a very crude approximation of
physical reality.

152
The illumination equation
This is the simplification of the rendering equation:

Note: this could be summed for all light sources, we


kept this notation for simplicity.

What’s missing?

153
The illumination equation
This is the simplification of the rendering equation:

Note: this could be summed for all light sources, we


kept this notation for simplicity.

What’s missing?

Let’s discuss the ray tracing algorithm and we’ll see.

154
The algorithm

1. Construction of the camera/eye rays


2. Intersection with the scene objects
3. Shading
4. Reflection/refraction directions
5. ?
The algorithm

1. Construction of the camera/eye rays


2. Intersection with the scene objects
3. Shading
4. Reflection/refraction directions
5. Recursion
A word on recursion

The ray doesn’t stop at the first intersection, we have to


trace it further as it will either get reflected or refracted.

No demonstration image about this for now as you will see it


yourself in the first assignment.
The illumination equation

158
The illumination equation

Reflection

Refraction

159
160
The Fresnel equation (simplified)
Schlick’s approximation:

161
The Fresnel equation (simplified)
Schlick’s approximation:

162
The Fresnel equation (simplified)
Schlick’s approximation:

163
The Fresnel equation (simplified)
Schlick’s approximation:

can be given by:

164
The Fresnel equation (simplified)
Schlick’s approximation:

165
The Fresnel equation (simplified)
Schlick’s approximation:

Air/vacuum-medium interactions are therefore given by:

166
The Fresnel equation (simplified)
Schlick’s approximation:

Air/vacuum-medium interactions are therefore given by:

Where is the index of refraction of the new medium.

167
The Fresnel equation (simplified)
Schlick’s approximation:

It gives the probability of reflection. If the ray is not


reflected, it will be refracted according to the law of energy
conservation. Therefore:

(T as transmission)

168
The Fresnel equation (simplified)
Schlick’s approximation:

Let’s play with it!

169
The Fresnel equation (simplified)
Schlick’s approximation:

Let’s play with it!

170
The Fresnel equation (simplified)
Schlick’s approximation:

Let’s play with it!

171
The Fresnel equation (simplified)
Schlick’s approximation:

Let’s play with it!

172
The Fresnel equation (simplified)
Schlick’s approximation:

Let’s play with it!

We can think of this function as an interpolation OR


transition between these two states.

173
The Fresnel equation (simplified)
Air-glass interaction

174
The Fresnel equation (simplified)
Air-glass interaction

Let’s play with it!

175
The Fresnel equation (simplified)
Air-glass interaction

Let’s play with it!

176
The Fresnel equation (simplified)
Air-glass interaction

Let’s play with it!

What do we expect from the plot? Let’s recheck the


experiment.
177
The illumination equation

178
The Fresnel equation (simplified)

What do we expect?

- very high probability of refraction when the light ray comes


from the direction of the normal (theta is zero). High
probability of refraction means that the reflection
probability is low, the function value should be low at zero.

10% reflection, 90% refraction

Watch this experiment: http://www.youtube.com/watch?v=yfawFJCRDSE


179
The illumination equation

180
The Fresnel equation (simplified)

What do we expect?

- at around 60 degrees, refraction rays seem to be brighter,


so the function value should be low there. 60 degrees in
radians is about 1.

20% reflection, 80% refraction

181
The Fresnel equation (simplified)

What do we expect?

- always reflect the rays when they come from almost


parallel to the surface (we call this grazing angle)

Let’s check if the equation matches reality!

182
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot (0.5/2.5)^2 + ((1-(0.5/2.5)^2)(1-cosx)^5), y=0..1, x=0..pi/2

183
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot (0.5/2.5)^2 + ((1-(0.5/2.5)^2)(1-cosx)^5), y=0..1, x=0..pi/2

184
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot (0.5/2.5)^2 + ((1-(0.5/2.5)^2)(1-cosx)^5), y=0..1, x=0..pi/2

185
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot (0.5/2.5)^2 + ((1-(0.5/2.5)^2)(1-cosx)^5), y=0..1, x=0..pi/2

186
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot (0.5/2.5)^2 + ((1-(0.5/2.5)^2)(1-cosx)^5), y=0..1, x=0..pi/2

187
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot (0.5/2.5)^2 + ((1-(0.5/2.5)^2)(1-cosx)^5), y=0..1, x=0..pi/2

188
The Fresnel equation (simplified)
Let’s do another experiment – vacuum-vacuum interaction:

189
The Fresnel equation (simplified)
Let’s do another experiment – vacuum-vacuum interaction:

Let’s play with it!

190
The Fresnel equation (simplified)
Let’s do another experiment – vacuum-vacuum interaction:

Let’s play with it!

What do we expect from the plot?

191
The Fresnel equation (simplified)
Let’s do another experiment – vacuum-vacuum interaction.

Expectations:

192
The Fresnel equation (simplified)
Let’s do another experiment – vacuum-vacuum interaction.

Expectations:

- Vacuum means empty space. No particles, nothing is inside.

193
The Fresnel equation (simplified)
Let’s do another experiment – vacuum-vacuum interaction.

Expectations:

- Vacuum means empty space. No particles, nothing is inside.


- Only refraction should happen as there is no medium in
which the ray of light could be reflected – we expect a ray of
light in vacuum to travel indefinitely.

194
The Fresnel equation (simplified)
Let’s do another experiment – vacuum-vacuum interaction.

Expectations:

- Vacuum means empty space. No particles, nothing is inside.


- Only refraction should happen as there is no medium in
which the ray of light could be reflected – we expect a ray of
light in vacuum to travel indefinitely.

Only refraction means no reflection. The function should be


constant 0.

195
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot 0 + ((1-0)(1-cos(x))^5), y=0..1, x=0..pi/2

196
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot 0 + ((1-0)(1-cos(x))^5), y=0..1, x=0..pi/2

197
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot 0 + ((1-0)(1-cos(x))^5), y=0..1, x=0..pi/2

198
The Fresnel equation (simplified)

Open http://www.wolframalpha.com/ and check:


plot 0 + ((1-0)(1-cos(x))^5), y=0..1, x=0..pi/2

199
The Fresnel equation (simplified)
The Schlick-approximation is used to efficiently
calculate vacuum-medium type of interactions.

200
The Fresnel equation (simplified)
The Schlick-approximation is used to efficiently
calculate vacuum-medium type of interactions.

The original Fresnel equation:

201
The Fresnel equation (simplified)
The Schlick-approximation is used to efficiently
calculate vacuum-medium type of interactions.

The original Fresnel equation:

What does it say about the vacuum-vacuum interaction?

202
The Fresnel equation

This better be zero if and .

203
The Fresnel equation

This better be zero if and .

204
The Fresnel equation

This better be zero if and .

Identity:

205
The Fresnel equation

This better be zero if and .

Identity:

206
The Fresnel equation

This better be zero if and .

Identity:

207
The Fresnel equation

This better be zero if and .

Identity:

208
Snell’s law
In what angle are refracted rays continuing their path?

209
Snell’s law
In what angle are refracted rays continuing their path?

First: light slows down when entering a denser medium. The


index of refraction tells us exactly how much.

210
Snell’s law
In what angle are refracted rays continuing their path?

First: light slows down when entering a denser medium. The


index of refraction tells us exactly how much.

211
Snell’s law
In what angle are refracted rays continuing their path?

First: light slows down when entering a denser medium. The


index of refraction tells us exactly how much.

212
Snell’s law
In what angle are refracted rays continuing their path?

First: light slows down when entering a denser medium. The


index of refraction tells us exactly how much.

213
Snell’s law
In what angle are refracted rays continuing their path?

First: light slows down when entering a denser medium. The


index of refraction tells us exactly how much.

Therefore the speed of light in glass is:

214
Snell’s law
In what angle are refracted rays continuing their path?

First: light slows down when entering a denser medium. The


index of refraction tells us exactly how much.

Therefore the speed of light in glass is:

215
Snell’s law

With blue you see light as an electromagnetic wave.


With red you see the Poynting-vector as a ray-representation of light.
216
So why does the light refract inwards?
Snell’s law

219
Snell’s law

Khan academy time!

220
Snell’s law

Think of the light ray as a


vehicle. When this vehicle is
traveling on a road, which
suddenly it enters the mud. The
wheel that enters the mud first
will slow down, but the wheels
on the other side will still go
faster, making the vehicle turn.

221
Snell’s law
In what angle are refracted rays continuing their path?

Snell’s law:
This is the original notation, where
the different numbers mean
different media.

Let’s do the air-glass example seen on the previous image.

Expectations?

222
Snell’s law
In what angle are refracted rays continuing their path?

Snell’s law:
This is the original notation, where
the different numbers mean
different media.

Let’s do the air-glass example seen on the previous image.

Expectations:
- the light is refracted inwards, therefore must hold.

224
Snell’s law
In what angle are refracted rays continuing their path?

Snell’s law:
This is the original notation, where
the different numbers mean
different media.

Let’s do the air-glass example seen on the previous image.

Expectations:
- the light is refracted inwards, therefore must hold.

Let’s see!

225
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

227
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

228
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

229
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

230
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

231
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

232
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

233
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

234
Snell’s law
Let’s pick refraction indices instead of velocities for convenience.

235
Snell’s law
Expectations:
- the light is refracted inwards, therefore must hold.

236
Snell’s law
Expectations:
- the light is refracted inwards, therefore must hold.

237
Snell’s law
Expectations:
- the light is refracted inwards, therefore must hold.

Physics works!

238
Where will the yellow ray be refracted?
Snell’s law

To the241right!
Total internal reflection

242
Total internal reflection

Total internal
243
reflection.
Total internal reflection

244
Total internal reflection
Air-glass interaction

245
Total internal reflection
Air-glass interaction

246
Total internal reflection
Air-glass interaction

247
Total internal reflection
Air-glass interaction

248
Total internal reflection
Air-glass interaction

249
Total internal reflection

250
Total internal reflection
Air-glass interaction

251
Total internal reflection
Air-glass interaction

252
Total internal reflection
Air-glass interaction

253
Total internal reflection
Air-glass interaction

254
Total internal reflection

255
Total internal reflection

Expectation: less than 50 degrees.


256
Total internal reflection
Air-glass interaction

257
Total internal reflection
Air-glass interaction

258
Total internal reflection
Air-glass interaction

259
The representation of a ray

It starts from a point, and it continues its way to a direction.

260
The representation of a ray

It starts from a point, and it continues its way to a direction.

261
The representation of a ray

It starts from a point, and it continues its way to a direction.

The direction vector should always be unit length:

262
The representation of a ray

It starts from a point, and it continues its way to a direction.

The direction vector should always be unit length:

The notation is somewhat alien to someone who is used to


implicit equations.

263
The representation of a ray

It starts from a point, and it continues its way to a direction.

The direction vector should always be unit length:

The notation is somewhat alien to someone who is used to


implicit equations.

Implicit equations look like this:

264
The representation of a ray

It starts from a point, and it continues its way to a direction.

The direction vector should always be unit length:

The notation is somewhat alien to someone who is used to


implicit equations.

Implicit equations look like this:

265
The representation of a ray

It starts from a point, and it continues its way to a direction.

The direction vector should always be unit length:

The notation is somewhat alien to someone who is used to


implicit equations.

Implicit equations look like this:

Parametric equations look like this:

266
The representation of a ray

It starts from a point, and it continues its way to a direction.

The direction vector should always be unit length:

The notation is somewhat alien to someone who is used to


implicit equations.

Implicit equations look like this:

Parametric equations look like this:

267
The representation of a ray
Implicit equations look like this:
Example: 2D circle with center (a,b) and radius r:

Parametric equations look like this:

Example: the equation of a ray

268
The representation of a ray
Implicit equations look like this:
Example: 2D circle with center (a,b) and radius r:

Parametric equations look like this:

Example: the equation of a ray

For now it will remain a secret why it is useful.

269
The representation of a ray
Implicit equations look like this:
Example: 2D circle with center (a,b) and radius r:

Parametric equations look like this:

Example: the equation of a ray

For now it will remain a secret why it is useful.


Let’s see how to compute where a ray hits a sphere.

270
Ray-sphere intersection
Let’s see how to compute where a ray hits a sphere .

Expectation:

271
Ray-sphere intersection
Let’s see how to compute where a ray hits a sphere.

Expectation:

2 hitpoints

272
Ray-sphere intersection
Let’s see how to compute where a ray hits a sphere .

Expectation:

2 hitpoints

1 hitpoint

273
Ray-sphere intersection
Let’s see how to compute where a ray hits a sphere .

Expectation:

2 hitpoints

1 hitpoint

no hits

274
Ray-sphere intersection
Let’s see how to compute where a ray hits a sphere .

Expectation:

2 hitpoints
So the solution for this
intersection scenario should
be able to produce 2
1 hitpoint solutions, 1 solution, or no
solutions at all.

no hits

275
Ray-sphere intersection
Sphere equation:

276
Ray-sphere intersection
Sphere equation:

Ray equation:

277
Ray-sphere intersection
Sphere equation:

Ray equation:

Let’s substitute into the place of :

278
Ray-sphere intersection
Sphere equation:

Ray equation:

Let’s substitute into the place of :

279
Ray-sphere intersection
Sphere equation:

Ray equation:

Let’s substitute into the place of :

280
Ray-sphere intersection

281
Ray-sphere intersection

This sounds a lot like a quadratic equation:

Coefficients could be the following:

282
Ray-sphere intersection

This sounds a lot like a quadratic equation:

Coefficients could be the following:

283
Ray-sphere intersection

This sounds a lot like a quadratic equation:

Coefficients could be the following:

284
Ray-sphere intersection

This sounds a lot like a quadratic equation:

Coefficients could be the following:

285
Ray-sphere intersection

This sounds a lot like a quadratic equation:

Coefficients could be the following:

Two solutions:

286
Ray-sphere intersection

This sounds a lot like a quadratic equation:

Coefficients could be the following:

Two solutions:

Two solutions if OK

287
Ray-sphere intersection

This sounds a lot like a quadratic equation:

Coefficients could be the following:

Two solutions:

Two solutions if OK
One solution if OK
288
Ray-sphere intersection

This sounds a lot like a quadratic equation:

Coefficients could be the following:

Two solutions:

Two solutions if OK
One solution if OK
No (real) solution if OK
289
Ray-sphere intersection
However, if we have 2 solutions, t can also be a negative value.

What does that mean?

290
Ray-sphere intersection
However, if we have 2 solutions, t can also be a negative value.

What does that mean?

291
Ray-sphere intersection
However, if we have 2 solutions, t can also be a negative value.

What does that mean?

Here t means the distance that the ray has traveled (you can
think of it as „time” traveled in the direction d), therefore the
ray is inside a sphere and one of the intersection points is
behind the origin of the ray.

If we find a solution like that, we discard it.


292
Surface normals
For an implicit equation , the surface normal is given as
the gradient of the function: .

293
Surface normals
For an implicit equation , the surface normal is given as
the gradient of the function: .

Definition:
294
Surface normals
For an implicit equation , the surface normal is given as
the gradient of the function: .

Example:
Elliptic paraboloid

Definition:
295
Surface normals
For an implicit equation , the surface normal is given as
the gradient of the function: .

Example:
Elliptic paraboloid

Definition:
296
Surface normals
For an implicit equation , the surface normal is given as
the gradient of the function: .

Example:
Elliptic paraboloid

and are curvatures

Definition:
297
Surface normals
For an implicit equation , the surface normal is given as
the gradient of the function: .

Example:
Elliptic paraboloid

and are curvatures

Definition:
298
Intersection routine

Intersect the ray with all objects in the scene. So what is the
first object that the ray hits?

299
Intersection routine

Intersect the ray with all objects in the scene. So what is the
first object that the ray hits?

Obviously the closest intersection.

300
Intersection routine

Intersect the ray with all objects in the scene. So what is the
first object that the ray hits?

Obviously the closest intersection.

Determining it will be simple because of the use of the


parametric equations for the rays as they have one variable,
and that is distance (t).

301
Intersection routine

Intersect the ray with all objects in the scene. So what is the
first object that the ray hits?

Obviously the closest intersection.

Determining it will be simple because of the use of the


parametric equations for the rays as they have one variable,
and that is distance (t).

From the list of possible intersections, which one do we


choose?

302
Intersection routine

Imagine a list of t values.

Can we take negative t-s?

303
Intersection routine

Imagine a list of t values.

Can we take negative t-s?

No, because these objects lay behind the ray.

304
Intersection routine

Imagine a list of t values.

Can we take negative t-s?

No, because these objects lay behind the ray.

Can we take ?

305
Intersection routine

Imagine a list of t values.

Can we take negative t-s?

No, because these objects lay behind the ray.

Can we take ?

No, it’s self-intersection: the object the ray lies on.

306
Intersection routine

Imagine a list of t values.

Can we take negative t-s?

No, because these objects lay behind the ray.

Can we take ?

No, it’s self-intersection: the object the ray lies on.

Therefore take the smallest non-negative, non-zero t that is


available, and it would be the first intersection point.

307
A bit of beauty

308
A bit of beauty

309
Shadow computation

What is the definition of shadows?

310
Shadow computation

What is the definition of shadows?

Regions that are not visible from light sources.


(at least for ray tracing)

311
Shadow computation

Umbra

312
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

313
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

314
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

315
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

316
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

317
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

318
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

319
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

For a point light source, the visibility signal will always be


binary: a point is either visible, or it’s not.

320
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

For a point light source, the visibility signal will always be


binary: a point is either visible, or it’s not.
In these points we set the intensity to zero.

321
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Umbra

322
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Penumbra Umbra Penumbra

323
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Penumbra Umbra Penumbra

324
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Penumbra Umbra Penumbra

325
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Penumbra Umbra Penumbra

For an area light source, the visibility signal is continuous: there


may be points which are visible from a part of the light source,
but are not from others.

326
Shadow computation

Obstructed/occluded connection
Unobstructed/unoccluded connection

Penumbra Umbra Penumbra

For an area light source, the visibility signal is continuous: there


may be points which are visible from a part of the light source,
but are not from others.
How do we determine the brightness of a point in the
penumbra?
327
Shadow computation

The brightness of a point would be:

328
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

329
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

330
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

331
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

332
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

333
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

334
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

335
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

336
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

Bonus question: is this image correct? Why?

337
Shadow computation

The brightness of a point would be:

We can estimate this by shooting shadow rays from the point,


to different regions of the light source and computing:

Bonus question: is this image correct? Why?


It is not – the black umbra should continuously
change into white(r) as we move outwards.
No jump is allowed, nature is continuous.

338
Shadow computation
Shadow computation
Shadow computation

Point light source!


Shadow computation
Shadow computation

Area light source!


(on the right)
Shadow computation

Have you seen completely black shadows anywhere?


The light would still find its way to the shadowed area, the
difference is that it would reach it indirectly.

A recursive ray tracer only takes the direct effect of the light
sources into account (we call this direct illumination).
Shadow computation

Have you seen completely black shadows anywhere?


The light would still find its way to the shadowed area, the
difference is that it would reach it indirectly.

A recursive ray tracer only takes the direct effect of the light
sources into account (we call this direct illumination).

This is why we use the ambient term in ray tracers – with a


simple color addition, we get an approximation to the indirect
illumination term.
A bit of beauty

346
Camera models
Pinhole camera

347
Camera models
Perspective camera

The starting point of the rays are fixed in the eye of the
viewer, and they are connected to a plane.
348
Camera models
Perspective camera

Parameters:
Plane width,
Plane height,
Field of view,
Aspect ratio

The starting point of the rays are fixed in the eye of the
viewer, and they are connected to a plane.
349
Camera models
Perspective camera

350
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.

351
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.
are given and the desired pixel positions are .

352
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.
are given and the desired pixel positions are .

353
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.
are given and the desired pixel positions are .

354
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.
are given and the desired pixel positions are .

Forget the fov for a bit and let’s play with it:

355
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.
are given and the desired pixel positions are .

Forget the fov for a bit and let’s play with it:

356
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.
are given and the desired pixel positions are .

Forget the fov for a bit and let’s play with it:
This is the bottom left.

357
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.
are given and the desired pixel positions are .

Forget the fov for a bit and let’s play with it:
This is the bottom left.

358
Camera models
Perspective camera construction

We would like to name a pixel position (x,y) pair, and the


calculations should return the corresponding lens (plane)
position.
are given and the desired pixel positions are .

Forget the fov for a bit and let’s play with it:
This is the bottom left.
This is the upper right.
359
Camera models

Forget the fov for a bit and let’s play with it:
This is the bottom left.
This is upper bottom right.
Now consider the fov as a scaling factor:

360
Camera models

Forget the fov for a bit and let’s play with it:
This is the bottom left.
This is upper bottom right.
Now consider the fov as a scaling factor:

361
Camera models

Forget the fov for a bit and let’s play with it:
This is the bottom left.
This is upper bottom right.
Now consider the fov as a scaling factor:

Therefore the bigger we set the fov, the more perspective


distortion we should expect.

362
Camera models

It is implementable right away:

363
Camera models

It is implementable right away:

364
Camera models

Orthographic camera

365
Camera models

Orthographic camera

The camera rays are parallel, and they don’t meet at the eye.

366
Camera models

Orthographic
Perspective camera 367
Perspective
Camera models

Perspective camera 368


(Disregard the background – HDR maps are problematic
Camera models
in the presence of orthographic cameras.)

Orthographic camera (no perspective


369 distortion)
Recursion

The ray tracing algorithm:

1. Construction of the camera/eye rays OK


2. Intersection with the scene objects OK
3. Shading OK
4. Reflection/refraction directions OK
5. Recursion ?

370
Recursion

So far we have only computed the first intersection of the


light ray. After it happened, and we are done with the
shading and reflection/refraction steps, we need to trace the
ray of light further.

371
Recursion

So far we have only computed the first intersection of the


light ray. After it happened, and we are done with the
shading and reflection/refraction steps, we need to trace the
ray of light further.

With the new origin and direction settings, we restart the


whole process until a given maximum ray depth value is
reached.

372
Recursion

The ray tracing algorithm:

1. Construction of the camera/eye rays OK


2. Intersection with the scene objects OK
3. Shading OK
4. Reflection/refraction directions OK
5. Recursion OK

373
The Illumination Equation with recursion

The Illumination Equation with recursion:

374
The Illumination Equation with recursion

The Illumination Equation with recursion:

375
The Illumination Equation with recursion

The Illumination Equation with recursion:

376
The Illumination Equation with recursion

The Illumination Equation with recursion:

377
The Illumination Equation with recursion

The Illumination Equation with recursion:

378
The Illumination Equation with recursion

The Illumination Equation with recursion:

379
Heckbert’s notation for light paths

L – light source
D – diffuse light paths
S – specular light paths
E – eye/camera

380
Heckbert’s notation for light paths

L – light source
D – diffuse light paths
S – specular light paths
E – eye/camera

[D]* - any amount of diffuse bounces (or even zero)


[S|D] – specular or diffuse bounce (but only one of them)

381
Heckbert’s notation for light paths

L – light source
D – diffuse light paths
S – specular light paths
E – eye/camera

[D]* - any amount of diffuse bounces (or even zero)


[S|D] – specular or diffuse bounce (but only one of them)

This notation makes it convenient to discuss what light paths


different rendering algorithms are capable of rendering.

382
Heckbert’s notation for light paths

Light paths that different rendering algorithms take into


consideration:

Ray casting: L[D]E


Radiosity: L[D*]E
Recursive ray tracing: L[D]S*E
Global illumination: L[D|S]*E

383
Heckbert’s notation for light paths

Light paths that different rendering algorithms take into


consideration:

Ray casting: L[D]E


Radiosity: L[D*]E
Recursive ray tracing: L[D]S*E
Global illumination: L[D|S]*E

In recursive ray tracing, at a diffuse bounce, we always


use the perfect reflection direction (as if the ray were
bouncing off of a mirror).
384
Heckbert’s notation for light paths
Assignment #1

Practical part

Let’s play a bit with Paul Heckbert’s „business card” ray tracer.

To compile, you are free to use every compiler/IDE you wish.

The simplest possible compiler for Windows is set up in a zip


file (next slide).

386
Assignment #1

Practical part

- Get http://cg.tuwien.ac.at/~zsolnai/rendering/rendering_assignment1_ray_tracing.zip
- Follow the instructions in the readme.txt file to compile,
- Make images with different DEPTH values in ray.h (1-5),
- What did you experience visually? Why?
- Crank up the DEPTH value (20+). How does it affect the
runtime?
- Analyze the runtime of the algorithm depending on DEPTH.
Does it deteriorate? Why or why not?
Assignment #1

Practical part

- Get http://cg.tuwien.ac.at/~zsolnai/rendering/rendering_assignment1_ray_tracing.zip
- Follow the instructions in the readme.txt file to compile,
- Make images with different DEPTH values in ray.h (1-5),
- What did you experience visually? Why?
- Crank up the DEPTH value (20+). How does it affect the
runtime?
- Analyze the runtime of the algorithm depending on DEPTH.
Does it deteriorate? Why or why not?

If you have trouble with the links in the presentation, either


start a fullscreen slideshow and click the link there, or right
click and choose the option to open it from there.
Assignment #1
Practical part

- For pros: What is the complexity of the algorithm with


reflection and refraction? Complexity as in, how many rays
have to be traced with respect to DEPTH and the resolution?
Use mathematical reasoning and the big O notation (Ordo
notation in some languages).
- For pros: What could we do if we wanted the algorithm to
run with a very high DEPTH value?
- For pros: What would be the new complexity of the
algorithm?
- Play a bit with the AOV value (= fov on our slides). What did
you experience? Why?
- There is also a different business card ray tracer under the
name of card.cpp. Just play with it freely as you wish.
Assignment #1
Practical part

Format for the runtime tables:


Depth time[s]
1 2.71
2 3.14
3 5.97
...

390
Assignment #1
Practical part

Format for the runtime tables:


Depth time[s]
1 2.71
2 3.14
3 5.97
...

Make a plot of your measurements. For this you can use any
software you wish (Excel, gnuplot, anything).

Filenames:
- heckbert_runtimes1.txt,
- heckbert_runtimes1.png for the plot,

391
Assignment #1
Draw the following light paths onto the picture:

- LE
- LDE,
- LSE,
- LDDE,
- LDSE,
- LSDE,

Save as light_paths.(png|jpg)
392
Assignment #1

Practical part
Your observations, should go into the observations.txt file.

Images with the different DEPTH and AOV options should go


into:
- heckbert_depth($value).png
- heckbert_aov($value).png

Example: heckbert_depth3.png
Yes, please convert them from uncompressed ppm to png.

393
Assignment #1

Zip them all up and send them to:


zsolnai@cg.tuwien.ac.at

Subject: [rendering_$year_($assignment_number)]_
($your_matrikelnumber),($your_name)
Filename: same with .zip extension

Example:
[Rendering_SS2048_1]_0123456,Thomas Auzinger

394

You might also like