 
 //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 ndcDepthToEyeSpaceProj(float ndcDepth) {
+    /*return ((ndcDepth + (uLightFar + uLightNear)/(uLightFar - uLightNear)) * (uLightFar - uLightNear))/2.0;*/
+    return 2.0 * uLightNear * uLightFar / (uLightFar + uLightNear - ndcDepth * (uLightFar - uLightNear));
+}
+
+//otho
+//z = (f - n) * (zn + (f + n)/(f-n))/2
+//http://www.ogldev.org/www/tutorial47/tutorial47.html
 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
+    return (uLightFar - uLightNear) * (ndcDepth + (uLightFar + uLightNear) / (uLightFar - uLightNear)) / 2;
+}
+
 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);
        }
    }
    
    //TODO: No kd? so not really energy conserving

    vec3 directSpecular = vec3(0.0);
    vec3 color = indirectDiffuse + indirectSpecular + directDiffuse + directSpecular;
    //color = irradianceColor;
    /*color = debugColor;*/
    gl_FragData[0] = vec4(color, 1.0);
    gl_FragData[1] = vec4(vNormalView * 0.5 + 0.5, 1.0);
}
