Computer Graphics
Shadow Mapping
Prepared by Graphics from learnopengl
Copyright By PowCoder代写 加微信 powcoder
Expected results
Shadow Acne Shadow Acne Removed
COMP 371 – Lab 05
Install instructions
Get Lab08.zip on Moodle.
The lab is standalone, no need to add into previous lab code.
COMP 371 – Lab 05
Shadow Mapping Algorithm
• Createshadowscastbyapointlightsource
1. Place a camera at the light’s position and see how close the nearest object is for every angle
2. Decide wether a surface is in shadow by comparing it’s distance to the light with the closest distance at that angle
How do we do step 1?
(getting the closest distance at each angle)
1. Render a depth map onto a texture that shaders can then access
2. Must create a projection and view matrix that define where the light is looking at
3. Must create a framebuffer that allows opengl to draw onto the texture
Creating the texture and framebuffer
Placing the light and giving it a projection matrix
The shadow shader
all we care about is depth
How do we do step 2?
(deciding if a surface is in the shadow or not)
1. Compute the distance between the 3D position of the fragment and the light
2. Use the light’s projection matrix to see where the 3D position of the fragments ends up on the depth texture
3. Compare the computed distance to the one stored on the depth texture.
computed > depth texture => in shadow
Render the geometry as usual
The scene shader where the magic happens
Problem: shadow acne
Solution: shadow bias
Solution: shadow bias
Solution: shadow bias
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com