Hello,
I'm tinkering with cascaded shadow maps and I have an issue when it comes to shadows between splits.
The below picture shows it:
http://s23.postimg.org/ngwk5gnff/image.png
From the camera position to the edge of the shadow is the first split, and then from the end of the shadow starts the other split... the problem is the aliens shadow is in both splits. The alien is not inside the bounding box of the second split and thus the shadow abruptly stops. That is my theory anyway... and ideas?
Heres my lighting pass shader FYI (directional light source, deferred renderering):
#version 430
layout(std140) uniform;
const float DEPTH_BIAS = 0.00005;
uniform UnifDirLight
{
mat4 mVPMatrix[4]; // the bias * crop * projection* view matrices for the directional light
float mSplitDistance[4]; // far distance for each split in camera space
vec4 mLightColor;
vec4 mLightDir;
vec4 mGamma;
vec2 mScreenSize;
} UnifDirLightPass;
layout (binding = 2) uniform sampler2D unifPositionTexture;
layout (binding = 3) uniform sampler2D unifNormalTexture;
layout (binding = 4) uniform sampler2D unifDiffuseTexture;
layout (binding = 6) uniform sampler2DArrayShadow unifShadowTexture;
out vec4 fragColor;
void main()
{
vec2 texcoord = gl_FragCoord.xy / UnifDirLightPass.mScreenSize;
vec3 worldPos = texture(unifPositionTexture, texcoord).xyz; // stored world position; in world space
vec3 normal = normalize(texture(unifNormalTexture, texcoord).xyz);
vec3 diffuse = texture(unifDiffuseTexture, texcoord).xyz;
int index = 3;
if (worldPos.z > UnifDirLightPass.mSplitDistance[0]) // this is problematic when looking anywhere except straight the negative Z axis... any ideas on better comparison?
index = 0;
else if (worldPos.z > UnifDirLightPass.mSplitDistance[1])
index = 1;
else if (worldPos.z > UnifDirLightPass.mSplitDistance[2])
index = 2;
vec4 projCoords = UnifDirLightPass.mVPMatrix[index] * vec4(worldPos, 1.0);
projCoords.w = projCoords.z - DEPTH_BIAS;
projCoords.z = float(index);
float visibilty = texture(unifShadowTexture, projCoords);
float angleNormal = clamp(dot(normal, UnifDirLightPass.mLightDir.xyz), 0, 1);
fragColor = vec4(diffuse, 1.0) * visibilty * angleNormal * UnifDirLightPass.mLightColor;
}