     float sunDiffuse = dotNsunL;
     float illuminated = 1.0;
 
+    vec3 debugColor = vec3(0.0);
     //shadows
     if (uShadowQuality > 0.0) {
         vec4 lightViewPosition = uLightViewMatrix * vec4(vPositionWorld, 1.0);
         float lightDistView = -lightViewPosition.z;
         vec4 lightDeviceCoordsPosition = uLightProjectionMatrix * lightViewPosition;
         vec2 lightDeviceCoordsPositionNormalized = lightDeviceCoordsPosition.xy / lightDeviceCoordsPosition.w;
+        float lightDeviceCoordsZ = lightDeviceCoordsPosition.z / lightDeviceCoordsPosition.w;
         vec2 lightUV = lightDeviceCoordsPositionNormalized.xy * 0.5 + 0.5;
 
         if (uShadowQuality == 1.0) {


//fron depth buf normalized z to linear (eye space) z
//http://stackoverflow.com/questions/6652253/getting-the-true-z-value-from-the-depth-buffer
float ndcDepthToEyeSpace(float ndcDepth) {
    return 2.0 * uLightNear * uLightFar / (uLightFar + uLightNear - ndcDepth * (uLightFar - uLightNear));
}

//fron depth buf normalized z to linear (eye space) z
//http://stackoverflow.com/questions/6652253/getting-the-true-z-value-from-the-depth-buffer
float readDepth(sampler2D depthMap, vec2 coord) {
    float z_b = texture2D(depthMap, coord).r;
    float z_n = 2.0 * z_b - 1.0;

        if (uShadowQuality == 3.0) {
            illuminated = PCF(uShadowMap, uShadowMapSize, lightUV, lightDistView - uBias);
        }
        
        float depth = readDepth(uShadowMap, lightUV);
        float z = (lightDistView-uLightNear)/(uLightFar-uLightNear);
        float z2 = (depth-uLightNear)/(uLightFar-uLightNear);

        if (vPositionWorld.z > 0)
            debugColor = hsv2rgb(vec3(z2, 1.0, 0.5));
        else if (z < 0.0) 
            debugColor = vec3(0.0);
        else if (z > 1.0) 
            debugColor = vec3(0.0);
        else
            debugColor = hsv2rgb(vec3(z, 1.0, 0.5));
        /*debugColor = hsv2rgb(vec3(illuminated, 1.0, 0.5));*/
        /*debugColor = hsv2rgb(vec3(step(lightDist, 8.0), 1.0, 0.5));*/
        /*debugColor = hsv2rgb(vec3(step(-lightDistView, 10.0), 1.0, 0.5));*/
        /*debugColor = vec3(lightUV, 0.0); */
    }
    
    //TODO: No kd? so not really energy conserving
