Search Unity

How does setfloats work?

Discussion in 'Shaders' started by Haravin, Nov 18, 2017.

  1. Haravin

    Haravin

    Joined:
    Aug 21, 2017
    Posts:
    6
    I'm trying to figure out how setfloats works for compute shaders.

    I have a shader constant like this:

    Code (C#):
    1. float3 _SizeData : register(u1); //x is the heightscale, or the maximum height possible. y is the gridscale, or the space between each grid position. z is the mip level, the amount of pixels skiped for each pixel calculated.
    Do I just make an array and pass it like this?

    Code (CSharp):
    1.         float[] sizeData = new float[3] { HeightScale, GridSize, MipLevel };
    2.         MapCalculator.SetFloats("_SizeData", sizeData);
    The docs aren't very clear, and I can't seem to get this to work properly.
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Pretty sure you want to do:

    Code (csharp):
    1. yourMaterial.SetVector("_SizeData", new Vector3(HeightScale, GridSize, MipLevel);
    IIRC SetVector handles non Vector4 sizes (if not new up a Vec4 and just leave w 0).
     
  3. Haravin

    Haravin

    Joined:
    Aug 21, 2017
    Posts:
    6
    I passed it in as an array, and it seems to be working fine. The method I originally gave works, not the one you provided. Hopefully someone in the future will find this thread help. Thanks for the reply.