Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Will Unity support passing array to shader?

Discussion in 'General Discussion' started by cnzjnblxj, Dec 14, 2015.

  1. cnzjnblxj

    cnzjnblxj

    Joined:
    Jul 6, 2015
    Posts:
    14
    Just something like Material.SetVectors and MaterialPropertyBlock.SetVectors
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,327
  3. cnzjnblxj

    cnzjnblxj

    Joined:
    Jul 6, 2015
    Posts:
    14
    Thanks for your reply.
    But this solution is very slow. In Qualcomm's Adreno Profiler, I find unity submit array element one by one to the driver by using this method.
    As far as I know, all major graphic apis support submit an array to shader, and this feature can reduce the cost between application and driver. I have no idea why unity didn't support this simple feature.
    I read the assembly code and did some dirty work to make our project support this feature. But it's really pain to do the assembly work for every release version.
    I hope unity technique team would modify their c++ code to support this feature.
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,327
    Yes, it would be slower than one api call.

    However, it is a working solution, if you just "want to pass array into shader".

    If you want to "pass array into shader in one api call", then you'll need to wait till unity implements that or see if someone from their team chimes in.
     
  5. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    If your target platform support it you can use Compute Buffers.
     
    kaiyum likes this.
  6. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    686
    You can try encoding array values to a 1D texture and look it up in vertex or pixel shader.
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Looks like Unity 5.4 will have MaterialPropertyBlock.SetFloatArray, SetVectorArray etc., as well as GPU instancing support (kinda related, but only indirectly). See http://unity3d.com/unity/roadmap
     
    Ryiah, chingwa and GoGoGadget like this.
  8. cnzjnblxj

    cnzjnblxj

    Joined:
    Jul 6, 2015
    Posts:
    14
    Nice !
     
  9. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    686
    Can't we already do this via, "graphics.drawmeshprocedural()"
     
  10. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yes you can, but it's hard to make that integrate with lighting, shadows, etc.
     
    GoGoGadget and kaiyum like this.