Search Unity

Question How to pass multiple values to shader?

Discussion in 'Shader Graph' started by Nlk29, May 5, 2023.

  1. Nlk29

    Nlk29

    Joined:
    Jan 25, 2022
    Posts:
    39
    Hi,

    I aready know how to pass floats to shaders via modifying materials with code.
    But what if i've got multiple floats i need to pass to my shader? f.ex. a list of player positions. How can i do that?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    If it's 1 player, do the same using float3 instead of float.
    If you have a max of 4 players, just add 4 values and set the float3 to some value not visible.

    Don't think shader graph has any support for structured buffers
     
  3. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    As @DevDunk said there is no support, however if you use custom node it would be possible to sample buffer or array and return calculated value. The thing is the loop must be inside custom node what is rather inconvenient, but still better than writing whole shader from scratch.
     
    DevDunk likes this.