#pragma kernel CSMain

Texture2D<float> Input;
RWTexture2D<float> Previous;
RWTexture2D<float> Result;
float Factor;

[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
    int xOffset = id.x * 256; // 2048 / 8
    int yOffset = id.y * 192; // 1536 / 8
    
    for(int localY = 0; localY < 192; ++localY)
    {
        for(int localX = 0; localX < 256; ++localX)
        {
            uint2 coordinate = uint2(xOffset + localX, yOffset + localY);
            float inputValue = (float)Input[coordinate];
            float previousValue = (float)Previous[coordinate];
            
            Result[coordinate] = abs(inputValue - previousValue) / Factor;
            Previous[coordinate] = Input[coordinate];
        }
    }    
}