Hi all,
I have been trying to implement shadow mapping using Vulkan but have been experience an odd issue which I cannot seem to understand the cause of. The issue I am facing is that when applying shadows to my scene, it seems to think that the top of the sphere is in shadow but it is not.
I am using FRONT face culling with depth set to LESS_OR_EQUAL for the shadow pass.
I was wondering if anyone might know what might be causing this and could provide some insight into where I might be going wrong. Thanks in advance.
Shadow + Light related code
// C++ light set up
Light ret = {};
auto dir = glm::vec3(0.191, 1.0f, 0.574f);
ret.m_direction = glm::vec4(dir.x, dir.y, dir.z, 1.0);
glm::mat4 proj = glm::ortho(-50.0, 50.0, -50.0, 50.0, 1.0f, 96.0f);
glm::mat4 view = glm::lookAt(position, glm::normalize(glm::vec3(dir.x, dir.y, dir.z)), glm::vec3(0.0f, 1.0f, 0.0f));
ret.LightSpaceMatrix = proj * view;
return ret;
// Fragment shader to calculate shadows based on learnopengl
float Shadow(vec3 WorldPosition)
{
vec4 fragPosLightSpace = LightUBO.LightSpaceMatrix * vec4(WorldPosition.xyz, 1.0);
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
projCoords.xy = projCoords.xy * 0.5 + 0.5;
float closestDepth = texture(shadowMap, projCoords.xy).r;
float currentDepth = projCoords.z;
float bias = 0.005;
float shadow = currentDepth > closestDepth + bias ? 1.0 : 0.0;
return shadow;
}