Skip to content

Instantly share code, notes, and snippets.

@DylanYasen
Last active July 1, 2021 04:16
Show Gist options
  • Save DylanYasen/1329ae457b7b9496830177e63db1ff31 to your computer and use it in GitHub Desktop.
Save DylanYasen/1329ae457b7b9496830177e63db1ff31 to your computer and use it in GitHub Desktop.
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