Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Rows and Columns (Compute Shader) Columns Not Updating

Discussion in 'Scripting' started by WNTRSWE, Nov 4, 2021.

  1. WNTRSWE

    WNTRSWE

    Joined:
    May 5, 2021
    Posts:
    3
    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:

    https://drive.google.com/file/d/1uz3JzKRkWvhdVObXjNr09heYP31gOHQE/view?usp=sharing

    Here is my current code for updating the rows and columns

    Code (CSharp):
    1.     for (int x = 0; x < SphereColummns; x++)
    2.     {
    3.         IntersectSphere(ray, bestHit, float4(origin, 3.0f, rowsOrigin, 1.0f));
    4.         origin += 5;
    5.     }
    6.    
    7.     for (int y = 0; y < SphereRows; y++)
    8.     {
    9.         IntersectSphere(ray, bestHit, float4(origin, 3.0f, rowsOrigin, 1.0f));
    10.         rowsOrigin += 5;
    11.     }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,935
    You're using
    rowsOrigin
    on both line 3 and 9. Is that correct?
     
  3. WNTRSWE

    WNTRSWE

    Joined:
    May 5, 2021
    Posts:
    3
    Yes
     
  4. WNTRSWE

    WNTRSWE

    Joined:
    May 5, 2021
    Posts:
    3
    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:
    Code (CSharp):
    1.     for (int x = 0; x < SphereColummns; x++)
    2.     {
    3.         //IntersectSphere(ray, bestHit, float4(origin, 3.0f, rowsOrigin, 1.0f));
    4.         origin += 5;
    5.     }
    6.  
    7.     for (int y = 0; y < SphereRows; y++)
    8.     {
    9.         for (int x1 = 0; x1 < origin; x1 += 5)
    10.         {
    11.             IntersectSphere(ray, bestHit, float4(x1, 3.0f, rowsOrigin, 1.0f));
    12.         }
    13.         IntersectSphere(ray, bestHit, float4(origin, 3.0f, rowsOrigin, 1.0f));
    14.         rowsOrigin += 5;
    15.     }
     
    Last edited: Nov 4, 2021