#pragma kernel cs_main

Texture2D source_texture;
RWTexture2D<float4> result;

[numthreads(8, 8, 1)]
void cs_main(uint3 id : SV_DispatchThreadID)
{
    //Define a basic 3x3 Gaussian kernel (just for illustration)
    // float3x3 kernel = {
    //     {7, 1, 1},
    //     {1, 20, 1},
    //     {1, 1, 7}
    // };

    float3x3 kernel = {
        { 1, 2, 1 },
        { 2, 4, 2 },
        { 1, 2, 1 }
    };
    
    // Normalize kernel
    //kernel /= 7+1+1+1+20+1+1+1+7;
    kernel /= 16;

    float4 sum = float4(0, 0, 0, 0);

    // Convolution: Multiply the surrounding pixels with the kernel and sum them
    for (int y = -1; y <= 1; y++)
    {
        for (int x = -1; x <= 1; x++)
        {
            sum += source_texture[id.xy + uint2(x, y)] * kernel[x + 1][y + 1];
        }
    }

    result[id.xy] = sum;
}
