Search Unity

array of structures in the editor

Discussion in 'Shaders' started by Kantic, Jan 31, 2021.

  1. Kantic

    Kantic

    Joined:
    Jan 8, 2020
    Posts:
    11
    So, i finished writing my shader to apply a set of textures to my terrain and i would like to make the system more flexible: right now there has to be two textures that will be mapped from the top and two from the side.

    I would like to have an array of structures(containing textures and floats) that i could edit from, well, the editor.
    Does anybody knows how it is done?
    I saw a thread for the same issue were it was suggested to use Material.setArray from a C# script and have every component of the structure in seperate arrays but this solution isn't very convinent, is there another way?
    Thanks in advance!
     
    Last edited: Jan 31, 2021
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You can use a structured buffer to pass an array of structs containing float or integer values. But textures have to be separate. For one, you can’t have an array of textures. You can have a
    Texture2DArray
    , but this is essentially single 3D texture that doesn’t do any filtering between the layers.
     
  3. Kantic

    Kantic

    Joined:
    Jan 8, 2020
    Posts:
    11
    Alright, thank you very much!