Search Unity

Are parameters set with Shader.SetGlobal* "shared" between materials?

Discussion in 'Shaders' started by Trisibo, Dec 11, 2014.

  1. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    I would like to know if parameters sent to shaders using the methods "Shader.SetGlobal*" are "shared" for all the materials, that is, if the values are sent to the GPU only once for all the materials, or once for each material even if they use the same shader.

    I'm creating a scene for mobile platforms in which I need to send arrays of vectors to multiple objects, each with a copy of the same material. Until now, I was using "Material.SetVector()" for each of the materials; now I've modified the meshes and the arrangment of the scene to optimize a lot the vertex and triangle count, but with the downside that the number of vectors sent to each object would increase because I'll have to repeat many of them for different objects. If I could use only one big array and put there all the vectors I wouldn't have to resend so many identical values, but of course that would not work if that same array was resent for each material.

    By the way, how expensive is sending parameters to shaders? I've tried to find some info, but have been unable. I can modify the techniques used in my scene to send less parameters by increasing the number of vertices (and thus the number of vertex shader executions), but I'm unsure about which aproach would be better... I could test both, but I'm too lazy ;) and only have two devices to test, which are not representative of all the mobile hardware craziness out there.
     
  2. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    Somebody knows? :(