/
shadow map.txt
36 lines (34 loc) · 1.11 KB
/
shadow map.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
1. Create a GLContext window w.
2. Let the triangles that need to be rendered be tri.
3. Create a framebuffer with depth texture attached to it, and call it dfb.
4. Create shader program depthProg for depth rendering.
vs {
Transform vertex, and send new position to fs.
}
fs {
Write z value to depth.
}
5. Create shader program shadowProg for shadow mapping.
vs {
Send position and normal.
}
fs {
We want to write a color. The color depends on shadow, and normal facing light.
Transform point to lightspace.
Read depth texture at the point and compare z value.
Tranform point and normal to worldspace.
diffuse = max(light.dot(normal), 0)
We should probably add specular here too.
finalColor = diffuse * materialColor * shadow;
}
loop {
3. Render depth texture:
1. Set dfb as target.
2. Set the viewport to fit the texture.
3. Set the projections such that the triangles will be rendered in lightspace.
4. Render the triangles tri with depthProg.
5. Set target back to default frame.
4. Set up matrices to camera space.
5. Set shaders to shadowProg.
6. Render the triangles tri.
}