Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sending arbitrary amount of float2's to compute shader?

Discussion in 'Shaders' started by Bas-Smit, Sep 2, 2019.

  1. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    Hi, I'm writing a compute shader that deals with 2d polygons. If I hardcode the vertices the shader works:

    Code (hlsl):
    1. float2 Polygon[5];
    2. Polygon[0] = float2(100,100);
    3. Polygon[1] = float2(200,100);
    4. Polygon[2] = float2(200,200);
    5. Polygon[3] = float2(100,200);
    6. Polygon[4] = float2(100,100);
    I am having a hard time figuring out how to pass an arbitrary amount of float2's to the shader from the cpu though. Could someone tell me which type to use in the shader and the accompanying api to populate it from the cpu?

    Thanks, Bas
     
  2. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    found the issue, the compiler failed silently doing if's in a loop of arbitrary length :(