How to implement cascade shadowmapping

Hello,
I work on s simple cascade shadow mapping. single shadow mapping works and for glsl version of 4.00 or higher it also works, my problem is, that my design requires that I pass the generated depth maps (one for each cascade) as an array of uniform sampler2D to the phong.fragment shader.
the pseudo code of that shader:

#version 400

const int NUM_CASCADES = 4;

layout (location = 0) out vec3 gShadow;

in VsOut
{
  vec4 fragPosition_LightSpace[NUM_CASCADES];
  vec4 fragPosition_WorldSpace;
} vsOut;

uniform sampler2D depthMap[NUM_CASCADES];
uniform float cascades[NUM_CASCADES]; // has the distances at which the different cascades happen

float shadowCalculation(
  vec4 fragPosition_LightSpace,
  sampler2D depthMap
)
{
  vec3 projCoords = fragPosition_LightSpace.xyz / fragPosition_LightSpace.w;
  projCoords = projCoords * 0.5 + 0.5;
  float currentDepth = projCoords.z;
  float bias = 0.0;
  float closestDepth = texture(depthMap, projCoords.xy).r;
  float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
  return 1.0 - clamp(shadow, 0.0, 1.0);
}

void main()
{
  int cascade = 0;
  for(;cascade<NUM_CASCADES; cascade++)
  {
    if(length(vsOut.fragPosition_WorldSpace) <= cascades[cascade])
    {
      break;
    }
  }
  gShadow = vec3(1.0, 1.0, 1.0)*directionalShadowCalculation(
    vsOut.fragPosition_LightSpace[cascade],
    depthMap[cascade]
  );
}

If i change the #version to 330 i get this error message:
error: sampler arrays indexed with non-constant expressions are forbidden in GLSL 1.30 and later
for this line


...
gShadow = vec3(1.0, 1.0, 1.0)*directionalShadowCalculation(
    vsOut.fragPosition_LightSpace[cascade],
    depthMap[cascade] <-!!!!!
  );
...

I would prefer to be able to run my application on older hardware. How could I design cascade shadows without dynamically indexed arrays of samplers?

Use a 2D texture array instead.

Related reference:

[ul]
[li]Re: Issues with sampler arrays and unrolling [/li][/ul]
(I was going to say 2D bindless textures might be another option. However, this doesn’t help you because it is written against the OpenGL/GLSL 4.00 specs and requires a GL 4.x+ card.)