Search Unity

How to pass an array of floats to vfxgraph

Discussion in 'Visual Effect Graph' started by DylanF, Feb 24, 2021.

  1. DylanF

    DylanF

    Joined:
    Jun 25, 2013
    Posts:
    55
    This took a little time to figure out, so I thought I'd share a quick code example.


    void Start() {
    sizes = new float[11];
    sizesTexture = new Texture2D(sizes.Length, 1, TextureFormat.RFloat, false);
    vfx.SetTexture(Shader.PropertyToID("Sizes"), sizesTexture);
    }

    void Update() {
    //update the "sizes" array of values every frame here
    sizesTexture.SetPixelData<float>(sizes, 0);
    sizesTexture.Apply();
    }


    In the Update Particle block of your graph, create a block similar to this image:
     

    Attached Files:

  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hey @DylanF ,

    Thanks for sharing! You may be also interested to know that work has been done on adding Graphics Buffer support for the VFX Graph, which will hopefully be available in 2021.2. This would allow you to pass a lot more data to the VFX graph from code without having to rely on textures.
     
  3. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    Any advice on how to actually access the buffer using VFX?
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307