     }
 
     int2 tilePos = make_int2(
-        idxCur.x % gradientTileSize,
-        idxCur.y % gradientTileSize);
+        curPos.x % gradientTileSize,
+        curPos.y % gradientTileSize);
 
     // NOTE
     // Atomic functions for CUDA.


inline __device__ bool testReprojectedDepth(float z1, float z2, float dz)
{
    float z_diff = abs(z1 - z2);
    return z_diff < 2.0 * (dz + 1e-3f);
}

#define AT_IS_INBOUND(x, a, b)  (((a) <= (x)) && ((x) <= (b)))

    encryptTea(teaArg);
    teaArg.x %= gradientTileSize;
    teaArg.y %= gradientTileSize;
    int2 prevPos = make_int2(
        ix * gradientTileSize + teaArg.x,
        iy * gradientTileSize + teaArg.y);

    float4 motionDepth;
    surf2Dread(&motionDepth, motionDetphBuffer, prevPos.x * sizeof(float4), prevPos.y);

    // NOTE
    // motion = prev - cur
    //  => -motion = cur - prev
    //  => prev + (-motion) = prev + (cur - prev) = cur
    int2 curPos = make_int2(prevPos.x - motionDepth.x, prevPos.y - motionDepth.y);

    // Check if position is in screen.
    if (!AT_IS_INBOUND(curPos.x, 0, width)
        || !AT_IS_INBOUND(curPos.y, 0, height))
    {
        return;
    }

    int curIdx = getIdx(curPos.x, curPos.y, width);
    int prevIdx = getIdx(prevPos.x, prevPos.y, width);

    float4 curNmlDepth = curAovNormalDepth[curIdx];
    float4 prevNmlDepth = curAovNormalDepth[prevIdx];
