Advertisement

Shadow mapping in Vulkan issue

Started by December 29, 2024 02:54 PM
0 comments, last by snoken 5 days, 3 hours ago

Hi all,

I am trying to do shadow mapping in vulkan however, the result I am getting is not correct. For shadow mapping we can use a sampler2DShadow and textureProj which is what I am doing but the result comes out incorrect.

I have verified that my LightSpaceMatrix is correct. I have implemented shadow mapping my doing the depth comparisons myself and the result was correct but I want to use textureProj and a sampler2DShadow for smaller code for shadow mapping.

Wondering if anyone might know what is causing the shadows to come out incorrect

layout(set = 0, binding = 0) uniform sampler2DShadow shadowMap;

float compute_shadow(vec3 worldPos)
{
	vec4 fragposLightSpace = Light.LightSpaceMatrix * vec4(worldPos, 1.0);
	float shadow = textureProj(shadowMap, fragposLightSpace);
	return shadow;
}

// Sampler
VkSamplerCreateInfo samplerInfo{};
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerInfo.magFilter = VK_FILTER_LINEAR;
samplerInfo.minFilter = VK_FILTER_LINEAR;
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
samplerInfo.minLod = 0.0f;
samplerInfo.maxLod = VK_LOD_CLAMP_NONE;
samplerInfo.mipLodBias = 0.f;
samplerInfo.maxAnisotropy = 16.0; 
samplerInfo.anisotropyEnable = VK_TRUE;
samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
samplerInfo.compareEnable = VK_TRUE;
samplerInfo.compareOp = VK_COMPARE_OP_LESS; 
Advertisement