Computer Graphics
Raimond Tunnel
MTAT.03.015
Previously
Previously
2 / 106
Previously
Shadows
3 / 106
CAM
Shadows
AREA LIGHT
OCCLUDER
NO SHADOW
4 / 106
CAM
Shadows
AREA LIGHT
OCCLUDER
UMBRA�FULL SHADOW
5 / 106
CAM
Shadows
AREA LIGHT
OCCLUDER
PENUMBRA�HALF SHADOW
UMBRA
6 / 106
CAM
Shadows
AREA LIGHT
OCCLUDER
ANTUMBRA�AFTER SHADOW
UMBRA
PENUMBRA
PENUMBRA
7 / 106
Shadows
AREA LIGHT
OCCLUDER
UMBRA
PENUMBRA
PENUMBRA
ANTUMBRA
8 / 106
Shadows
AREA LIGHT
OCCLUDER
UMBRA
PENUMBRA
PENUMBRA
ANTUMBRA
What is happens with our point and directional lights?
9 / 106
Shadow Algorithms
10 / 106
Projection Shadow
Basic 1 bonus task
11 / 106
Ray Traced Shadows
HIT
n
l
OCCLUDER
RAY
SHADOW
CAM
12 / 106
Shadow Mapping
CAM
OBJECT
OBJECT
LIGHT
VIEW FRUSTUM
13 / 106
Shadow Mapping
CAM
LIGHT
14 / 106
Shadow Mapping
LIGHT CAM VIEW
CAM
LIGHT
15 / 106
Shadow Mapping
SHADOW MAP
CAM
LIGHT
16 / 106
Shadow Mapping
SHADOW MAP
17 / 106
Shadow Mapping
SHADOW MAP
DEPTH�TO LIGHT CAM
How to find this depth?
18 / 106
Shadow Mapping
SHADOW MAP
DEPTH�TO LIGHT CAM
SAVED CLOSEST DEPTH�TO LIGHT CAM
19 / 106
Shadow Mapping
SHADOW MAP
DEPTH�TO LIGHT CAM
SAVED CLOSEST DEPTH�TO LIGHT CAM
What happens when…?
DEPTH
CLOSEST
DEPTH
CLOSEST
20 / 106
Shadow Mapping
POINT LIGHT
PERSPECTIVE PROJECTION
21 / 106
Shadow Mapping
DIRECTIONAL LIGHT
ORTHOGRAPHIC PROJECTION
22 / 106
Shadow Mapping
DIRECTIONAL LIGHT
What problems does
the shadow mapping
algorithm have?
ORTHOGRAPHIC PROJECTION
23 / 106
Shadow Mapping
+X axis CAM
512 × 512
24 / 106
Shadow Mapping
+X axis CAM
128 × 128
25 / 106
Shadow Mapping
+X axis CAM
32 × 32
26 / 106
Shadow Volume
CAM
OBJECT
LIGHT
OBJECT
OBJECT
27 / 106
Shadow Volume
SHADOW VOLUME
28 / 106
Shadow Volume
+1
-1
ENTERING �A VOLUME
EXITING� A VOLUME
0
29 / 106
Shadow Volume
+1
ENTERING �A VOLUME
1
30 / 106
Shadow Volume – Volume Creation
LIGHT
MESH
31 / 106
Shadow Volume – Volume Creation
SHADE SIDE
LIT SIDE
SILHOUETTE EDGES
32 / 106
Shadow Volume – Volume Creation
SHADE SIDE
LIT SIDE
SILHOUETTE EDGES
How to find the �silhouette edges?
33 / 106
Shadow Volume – Volume Creation
34 / 106
Shadow Volume – Volume Creation
LIGHT CAP
DARK CAP
SIDE
35 / 106
Shadow Volume – Volume Creation
(x, y, z) → (x, y, z, 0)
PROJECTING THE DARK GAP TO INFINITY
(0, 0, 0)
36 / 106
Shadow Volume – Volume Creation
THE SHADOW VOLUME
37 / 106
Stencil Buffer
FRAMEBUFFER
COLOR�BUFFER
38 / 106
Stencil Buffer
FRAMEBUFFER
COLOR�BUFFER
DEPTH�BUFFER
39 / 106
Stencil Buffer
FRAMEBUFFER
COLOR�BUFFER
DEPTH�BUFFER
STENCIL�BUFFER
RENDER
40 / 106
Stencil Testing
glStencilFunc( function, value, ...)
GL_NEVER�GL_LESS�GL_LEQUAL�GL_GREATER�GL_GEQUAL�GL_EQUAL�GL_NOTEQUAL�GL_ALWAYS
[integer]
41 / 106
Stencil Creation
glStencilOp( sfail , dpfail , dppass )
GL_KEEP�GL_ZERO GL_REPLACE�GL_INVERT
GL_INCR�GL_INCR_WRAP�GL_DECR
GL_DECR_WRAP�
STENCIL
DEPTH
×
ANY
✔
STENCIL
DEPTH
×
✔
✔
STENCIL
DEPTH
TEST:
RESULT:
42 / 106
Shadow Volume – Testing
BACK FACES OF SHADOW VOLUMES THAT PASS THE SCENE DEPTH TESTING
-1
DECREASE STENCIL VALUE
43 / 106
Shadow Volume – Testing
FRONT FACES OF SHADOW VOLUMES THAT PASS THE SCENE DEPTH TESTING
+1
INCREASE�STENCIL VALUE
44 / 106
Shadow Volume – Testing
n
STENCIL VALUE == 0�RENDER DIRECT LIGHTING�
l
45 / 106
Shadow Volume – Depth Pass
+1
+1
+1
+1
+1
-1
46 / 106
Shadow Volume – Depth Pass
One of these has a problem!
+1
+1
+1
+1
+1
-1
47 / 106
Shadow Volume – Depth Fail
Carmack’s Reverse
-1
-1
-1
-1
-1
+1
-1
48 / 106
Shadow Volume
49 / 106
Doom 3 (2004) https://www.youtube.com/watch?v=iZV3NhvA2Ag
Questions?
50 / 106
Conclusion
51 / 106
Conclusion
Avengers: Infinity War, Marvel Studios
Parker Solar Probe, NASA
52 / 106
Conclusion
z
y
x
x
y
z
53 / 106
Conclusion
A
B
C
A
C
B
54 / 106
Conclusion
A
B
C
A
B
C
D
A
B
C
D
A
B
C
D
E
F
G
H
55 / 106
Conclusion
x
y
ORIGIN
v
v
v = (0.8, 1.4)
A
B = (3.44, 1.0)
D
C = (7.2, 2.3)
u
56 / 106
Conclusion
A
B
C
X
A
B
C
57 / 106
Conclusion
Vertex Shader
Culling & Clipping
Rasterization
Fragment Shader
Visibility tests�Blending
Vertex transformations.
Object’s local space → clip space
Clip space → viewport space
Determine front-facing triangles.
Determine which vertices are visible.
Fill the triangle with fragments.
Calculate color values for pixels.
Is the fragment visible?�Blend together multiple fragments.
Construct geometry
Define transformations
Set material properties
58 / 106
Conclusion
α
59 / 106
(2, 1)
(3, 1)
(5, 1)
(7, 1)
Conclusion
1D WORLD
60 / 106
Conclusion
p
61 / 106
Conclusion
Affine
trasnformation
matrix
Must be 1
Translation column
Used for perspective projection...
Linear transformations
62 / 106
Conclusion
NEAR
FAR
C
A
B
CAM
y
z
TOP
BOTTOM
63 / 106
Conclusion
NEAR
FAR
z
CAM
FOVv
WIDTH
HEIGHT
ASPECT RATIO =
WIDTH
HEIGHT
x
y
C
A
B
y
64 / 106
Conclusion
y
x
65 / 106
Conclusion
y
x
66 / 106
y
z
Conclusion
67 / 106
Conclusion
68 / 106
Conclusion
(1, -1, -1)
(1, -1, 1)
(-1, 1, 1)
(1, 1, 1)
(-1, 1, -1)
(-1, -1, -1)
x
y
z
69 / 106
Conclusion
y
x
70 / 106
Conclusion
per polygon
per vertex
per fragment
71 / 106
Conclusion
n
r
v
Light
l
Viewer
72 / 106
Conclusion
(0.5, 0.5, 0.5)
Black and white stripes
73 / 106
Conclusion
1
1
0
74 / 106
Conclusion
Sampled Moiré Alias
Original Signal
75 / 106
Conclusion
TEXTURE
TEXTURE
76 / 106
Conclusion
MIPMAP (8×8)
MIPMAP (4×4)
RESULT (5×5)
1/4
3/4
77 / 106
Conclusion
ALPHA BLEEDING
CORRECT BLENDING
78 / 106
Conclusion
blend(source, destination) =
= sourceRGB * [sourceFactor]� [blendFunction]� destinationRGB * [destinationFactor]
79 / 106
Conclusion
80 / 106
Conclusion
The Last Guardian (2016)
81 / 106
Conclusion
GAME ENGINE
RUNTIME
TOOLS
+
82 / 106
Conclusion
GAME
ENGINE PRODUCT
MID-CORE
LOW-CORE
DEVICE
OS
PLATFORM
GAME ENGINE
83 / 106
Conclusion
84 / 106
Conclusion
SUDDEN JUMP IN MAGNITUDE
85 / 106
Conclusion
p0
p1
p2
p0
p1
p2
86 / 106
Conclusion
87 / 106
Conclusion
88 / 106
Conclusion
89 / 106
Conclusion
90 / 106
Conclusion
91 / 106
Conclusion
92 / 106
Conclusion
A
B
C
e
f
HIT
S
d
93 / 106
Conclusion
RAY
RAY
RAY
RAY
RAY
94 / 106
Conclusion
QUADTREE
95 / 106
Conclusion
n
Ω
d
RANDOM
BOUNCE RAY
d ⇜ Ω
96 / 106
Conclusion
97 / 106
Conclusion
ITERATION
98 / 106
Conclusion
Ω
p
p
p
p
ω
out
ω
out
ω
in
ω
in
ω
in
ω
in
ω
out
n
99 / 106
Conclusion
DIRECT�REFLECTION
INCOMING�LIGHT
PHONG
LAMBERT
1
1
0
100 / 106
Conclusion
AREA LIGHT
OCCLUDER
UMBRA
PENUMBRA
PENUMBRA
ANTUMBRA
101 / 106
Conclusion
102 / 106
Conclusion
z
y
x
x
y
z
103 / 106
Conclusion
104 / 106
Computer Graphics
Thanks for the ride!
The End
105 / 106
What knowledge did you gain today?
What more would you like to know?
Next time: Open mic lecture!�INDUSTRY GUESTS
106 / 106