I have a very strange problem with rendering a scene, even with one point shadow map.
NOTE: This problem has been solved. Apparently I was trying to read my cubeMaps into an array of samplerCubes, but this does not work for me for some reason.
I am rendering a scene with one floor with a shader which recieves a singe shadow cube map, and 9 cubes with a light shader with no shadow map.
Whenever I render the scene without testing for the shadow map depth comparison, it renders just fine (but without the shadows), but if i render the scene WITH shadow map depth testing, the floor just... disappears
It doesn't give me an error message or anything.
Here are pictures of what I am talking about:
Without shadow map depth testing:
With shadow map depth testing:
Here is the GLSL code for the floor object (specular code omitted):
#version 400
in vec2 outUV;
in vec3 outNormals;
in vec4 outPosition;
in vec4 outEyePosition;
out vec4 outColor;
uniform vec4 diffuseColor;
uniform vec4 specularColor;
uniform float diffuseAmount;
uniform float specularAmount;
uniform float specularOffset;
uniform float ambientAmount;
uniform float emmisionAmount;
uniform unsigned int specularHardness;
uniform vec3 lightPositions[8];
uniform vec3 lightColors[8];
uniform float lightIntensities[8];
uniform float lightDistances[8];
uniform sampler2D diffuse;
uniform samplerCube shadowCubeMaps[8];
vec3 calcPointLightColor(int index, inout vec3 lightDirection, vec3 viewDirection, vec3 currentNormal, float inShadow)
{
float lightDistance;
float lightIntensity;
vec3 lightColor;
lightColor = vec3(0.0, 0.0, 0.0);
if(inShadow == 0.0)
{
lightDistance = lightDistances[index];
lightDirection = outPosition.xyz - lightPositions[index];
lightDistance = length(lightDirection) / lightDistance;
lightDistance = clamp(lightDistance, 0.0, 1.0);
lightDistance = (lightDistance * -1.0) + 1.0;
lightDirection = normalize(lightDirection);
lightIntensity = dot(currentNormal, -lightDirection);
if(lightIntensity < 0.0)
{
lightIntensity = 0.0;
}
lightIntensity = lightIntensity * lightDistance;
lightColor = vec3((lightColors[index] * lightIntensities[index]) * lightIntensity);
}
return lightColor;
}
float shadowMapComparison(int index)
{
float lengthToPixel;
float shadowDistance;
float inShadow1;
inShadow1 = 0.0;
vec3 directionToShadowMap = outPosition.xyz - lightPositions[index];
shadowDistance = texture(shadowCubeMaps[index], directionToShadowMap).r;
lengthToPixel = length(directionToShadowMap);
if(shadowDistance + 0.001 >= lengthToPixel)
{
inShadow1 = 1.0;
}
else
{
inShadow1 = 0.0;
}
return inShadow1;
}
void main()
{
vec3 viewDirection;
vec3 currentNormal;
vec3 lightDirections[8];
vec4 finalColor;
vec4 diffuseColorFinal;
float inShadow[8];
diffuseColorFinal = diffuseColor * diffuseAmount;
currentNormal = normalize(outNormals);
viewDirection = outPosition.xyz - outEyePosition.xyz;
viewDirection = normalize(viewDirection);
viewDirection = -viewDirection;
inShadow[0] = shadowMapComparison(0);
finalColor += vec4(calcPointLightColor(0, lightDirections[0], viewDirection, currentNormal, inShadow[0]), 1.0);
finalColor.a = 1.0;
finalColor = finalColor * vec4(texture(diffuse, outUV).rgb, 1.0);
finalColor = finalColor * diffuseColorFinal;
outColor = finalColor;
}
So yeah. The shadow maps are fine, I debugged them by outputting to a quad, and they look fine. They are point light shadow maps, so they check for distance stored in the red component, instead of a depth component, for spherical distance.
I am guessing this is just a runtime GLSL error, but I cannot figure out what I am doing wrong.
I am following this tutorial: http://ogldev.atspace.co.uk/www/tutorial43/tutorial43.html