Hi, Ive been trying to get omnidirectional shadows to work, but I seem to have something wrong in my code. Im using samplerCubeShadow with:
glGenFramebuffers(1, &framebufferHandle);
glBindFramebuffer(GL_FRAMEBUFFER, framebufferHandle);
glGenTextures(1, &textureHandle);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureHandle);
for (int i = 0; i < 6; ++i)
{
glTexImage2D(static_cast<GLenum>(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i), 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowTexture.textureHandle, 0);
And in shader:
float shadowCubeValue(in samplerCubeShadow shadowMap, in vec3 lightToSurface, in float distanceToLight)
{
return texture(shadowMap, vec4(lightToSurface, distanceToLight));
}
but it seems the texture function returns 1 only for fragments that have the same depth value that is in the shadow map, in fact when I change GL_TEXTURE_COMPARE_FUNC to GL_LESS or GL_GREATER the function always returns 0.
I am using glCullFace(GL_FRONT) when creating shadow map, and glCullFace(GL_BACK) when when computing lights.
Here is an image:
Thanks.