     // ============================
     // Iterations:
     // ============================
-    // Compute offset (for each iteration step) in the right direction.
     vec2 offset = isHorizontal ? vec2(inverseScreenSize.x, 0.0) : vec2(0.0, inverseScreenSize.y);
     
-    // Compute UVs to explore on each side of the edge, orthogonally. 
-    // The QUALITY allows us to step faster.
     vec2 uv1 = currentUv - offset;
     vec2 uv2 = currentUv + offset;
 
-    // Read the lumas at both current extremities of the exploration segment, 
-    // and compute the delta wrt to the local average luma.
-    float lumaEnd1 = getLum(texture(renderedTexture, uv1).rgb);
-    float lumaEnd2 = getLum(texture(renderedTexture, uv2).rgb);
-    lumaEnd1 -= lumaLocalAverage;
-    lumaEnd2 -= lumaLocalAverage;
-
-    // If the luma deltas at the current extremities are larger than the local gradient, 
-    // we have reached the side of the edge.
-    bool reached1 = abs(lumaEnd1) >= gradientScaled;
-    bool reached2 = abs(lumaEnd2) >= gradientScaled;
+    // Read the pixelLums at both current extremities of the exploration segment, 
+    // and compute the delta wrt to the local average pixelLum.
+    float pixelLumEnd1 = getLum(texture(renderedTexture, uv1).rgb);
+    float pixelLumEnd2 = getLum(texture(renderedTexture, uv2).rgb);
+    pixelLumEnd1 -= pixelLumLocalAverage;
+    pixelLumEnd2 -= pixelLumLocalAverage;
+
+    bool reached1 = abs(pixelLumEnd1) >= gradientScaled;
+    bool reached2 = abs(pixelLumEnd2) >= gradientScaled;
     bool reachedBoth = reached1 && reached2;
 
-    // If the side is not reached, we continue to explore in this direction.
     if (!reached1) {
         uv1 -= offset;
     }

        uv2 += offset;
    }   

    // If both sides have not been reached, continue to explore.
    if (!reachedBoth) {
        for (int i = 2; i < ITERATIONS; i++) {
            // If needed, read luma in 1st direction, compute delta.
            if (!reached1) {
                lumaEnd1 = getLum(texture(renderedTexture, uv1).rgb);
                lumaEnd1 = lumaEnd1 - lumaLocalAverage;
            }
            // If needed, read luma in opposite direction, compute delta.
            if (!reached2) {
                lumaEnd2 = getLum(texture(renderedTexture, uv2).rgb);
                lumaEnd2 = lumaEnd2 - lumaLocalAverage;
            }
            // If the luma deltas at the current extremities is larger than 
            // the local gradient, we have reached the side of the edge.
            reached1 = abs(lumaEnd1) >= gradientScaled;
            reached2 = abs(lumaEnd2) >= gradientScaled;
            reachedBoth = reached1 && reached2;

            // If the side is not reached, we continue to explore in this direction, 
            // with a variable quality.
            if (!reached1) {
                uv1 -= offset * QUALITY[i];
            }

    // ============================
    // Estimating the gradient:
    // ============================
    float pixelLumDownLeft  = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,-1)).rgb);
    float pixelLumUpRight   = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,1)).rgb);
    float pixelLumUpLeft    = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,1)).rgb);
    float pixelLumDownRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,-1)).rgb);

    float pixelLumDownUp       = pixelLumDown + pixelLumUp;
    float pixelLumLeftRight    = pixelLumLeft + pixelLumRight;
    float pixelLumLeftCorners  = pixelLumDownLeft + pixelLumUpLeft;
    float pixelLumDownCorners  = pixelLumDownLeft + pixelLumDownRight;
    float pixelLumRightCorners = pixelLumDownRight + pixelLumUpRight;
    float pixelLumUpCorners    = pixelLumUpRight + pixelLumUpLeft;

    // Compute an estimation of the gradient
    float edgeHorizontal = abs(-2.0 * pixelLumLeft + pixelLumLeftCorners) + 
        abs(-2.0 * pixelLumCenter + pixelLumDownUp ) * 2.0 + abs(-2.0 * pixelLumRight + pixelLumRightCorners);
    float edgeVertical = abs(-2.0 * pixelLumUp + pixelLumUpCorners) + 
        abs(-2.0 * pixelLumCenter + pixelLumLeftRight) * 2.0  + abs(-2.0 * pixelLumDown + pixelLumDownCorners);

    // ============================
    // Choosing Edge Orientation:
    // ============================
    bool isHorizontal = (edgeHorizontal >= edgeVertical);
    float pixelLum1  = isHorizontal ? pixelLumDown : pixelLumLeft;
    float pixelLum2  = isHorizontal ? pixelLumUp : pixelLumRight;
    
    // Gradients
    float gradient1 = pixelLum1 - pixelLumCenter;
    float gradient2 = pixelLum2 - pixelLumCenter;

    bool is1Steepest = abs(gradient1) >= abs(gradient2);
    float gradientScaled = 0.25 * max(abs(gradient1), abs(gradient2));

    // Step size (one pixel) according to the edge direction.
    float stepLength = isHorizontal ? inverseScreenSize.y : inverseScreenSize.x;

    float pixelLumLocalAverage = 0.0;

    if (is1Steepest) {
        stepLength = - stepLength;
        pixelLumLocalAverage = 0.5 * (pixelLum1 + pixelLumCenter);
    } else {
        pixelLumLocalAverage = 0.5 * (pixelLum2 + pixelLumCenter);
    }

    vec2 currentUv = texCoord;
    if (isHorizontal) {
        currentUv.y += stepLength * 0.5;
