Last active
July 1, 2021 04:16
-
-
Save DylanYasen/1329ae457b7b9496830177e63db1ff31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec4 fragPosLightSpace = lightSpaceMatrix * worldPos; | |
float visibility = 1.0 - calcShadow(fragPosLightSpace); | |
vec3 rgb = emissive + (ambient + visibility * (diffuse + specular)) * color; | |
float calcShadow(vec4 fragPosLightSpace) | |
{ | |
vec3 screenSpacePos = fragPosLightSpace.xyz / fragPosLightSpace.w; | |
float bias = 0.005; | |
float fragDepth = screenSpacePos.z - 0.005; | |
// furthest depth light can reach/see | |
float maxDepth = texture(shadowMap, screenSpacePos.xy).r; | |
// if frag depth is beyond what light can see, then it's in shadow | |
return step(minDepth, fragDepth); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment