Rows and Columns (Compute Shader) Columns Not Updating

So I heard about Compute Shaders and wanted to try it out and learn to program in HLSL and etc. So I have a pretty “noob” question. I have followed the tutorial by David Kuri about how to do raytracing in Unity. And I wanted to have a slider so I can in runtime choose how many Spheres and I have split them up in rows and columns. But when I update the rows the columns dont update. Here is a video of what I mean more specifically:

Here is my current code for updating the rows and columns

    for (int x = 0; x < SphereColummns; x++)
    {
        IntersectSphere(ray, bestHit, float4(origin, 3.0f, rowsOrigin, 1.0f));
        origin += 5;
    }
   
    for (int y = 0; y < SphereRows; y++)
    {
        IntersectSphere(ray, bestHit, float4(origin, 3.0f, rowsOrigin, 1.0f));
        rowsOrigin += 5;
    }

You’re using rowsOrigin on both line 3 and 9. Is that correct?

Yes

So I have managed to fix some of the issue but now I have some ghost spheres:

And it goes (6 Spheres, 9 Shadows), (9 Spheres, 12 Shadows) and etc

Here is the code from me just experimenting and just trying diffrent stuff:

    for (int x = 0; x < SphereColummns; x++)
    {
        //IntersectSphere(ray, bestHit, float4(origin, 3.0f, rowsOrigin, 1.0f));
        origin += 5;
    }
 
    for (int y = 0; y < SphereRows; y++)
    {
        for (int x1 = 0; x1 < origin; x1 += 5)
        {
            IntersectSphere(ray, bestHit, float4(x1, 3.0f, rowsOrigin, 1.0f));
        }
        IntersectSphere(ray, bestHit, float4(origin, 3.0f, rowsOrigin, 1.0f));
        rowsOrigin += 5;
    }