PDA

View Full Version : Problem with omnidirectional shadows



Roozi489
03-16-2016, 05:58 AM
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: http://i.imgur.com/OgFc5fm.png
Thanks.

Dark Photon
03-18-2016, 03:08 PM
...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.

I agree that these results are puzzling, and certainly suggest that you are in-fact casting light-space front faces into the shadow map.

Questions:
* You're not changing glFrontFace at all, are you?
* Is it possible that your object defines some back faces coincident with your front faces? (that is, the walls of your surface are actually two-sided?)

And by the way, before your start believing that casting back faces only into your shadow map is the solution to all of your self-shadowing problems, look at this (http://www.ogre3d.org/forums/viewtopic.php?f=4&t=54729). You might instead read up on normal offset shadow mapping.

Roozi489
03-23-2016, 02:46 PM
Sorry for the delay,
I've found where was the problem, I've been transforming the depth value incorrectly. It seems the "geometry edge bleeding" artifact was unrelated and was caused by low shadow map resolution.
But thank you anyway.