Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. We are looking for feedback on the naming of a new user research platform that we are working on.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How to control values in shader globally?

Discussion in 'Scripting' started by monkeybrother, Sep 13, 2011.

  1. monkeybrother

    monkeybrother

    Joined:
    Oct 14, 2010
    Posts:
    83
    Hi. I have made a shader in Strumpy's shader editor and use it on a large object (an arena) that has hundreds of individual pieces (meshes), each with it's own material but with the same shader. Now, if I want to change let's say the specular value on all these pieces that use the same shader, is there a simple way of doing that?
    It doesn't really matter if it's something in the editor or if you can do it with a script, I just don't want to select every piece individually and change the value by hand. Any help appreciated!
     
  2. Nemox

    Nemox

    Joined:
    Feb 16, 2010
    Posts:
    396
    I'm not sure if it's applicable to your particular setup, but you could perhaps combine all the smaller objects into one larger object with a texture atlas, so all of them can use the same material. At that point, you can just change that single material.

    Otherwise, you'd need to keep a list of all the objects in script, and use a loop to change the specular value of each one.
     
  3. ivkoni

    ivkoni

    Joined:
    Jan 26, 2009
    Posts:
    978
    Nith666 and Alekxss like this.
  4. monkeybrother

    monkeybrother

    Joined:
    Oct 14, 2010
    Posts:
    83
    Thanks for your answers.

    ivkoni: That looks like exactly what I need, but even though I'm pretty certain I've done it right, it just doesn't change anything.

    Here's the line in the shader:
    and this is what I'm using in Startup() in the main controller script:
     
  5. monkeybrother

    monkeybrother

    Joined:
    Oct 14, 2010
    Posts:
    83
    Nevermind. I searched the forums and found that the values you want to changed can't be exposed in the shader. Unfortunately you can't not expose values in Strumpy's (?), but at least it works if you edit by hand.

    Thanks again.
     
  6. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    If you're using global variables, you don't define it as a property in the shader. You simply define the value like you would any other builtin value.

    i.e. inside your shader where you declare your other inputs (sampler2D, float4, etc...) you write;
    Code (csharp):
    1. float _BlowOut;
    And the shader will know that it's to use the globally defined float called _BlowOut automatically.
     
    jq911, HugoStudica and NicRule like this.
unityunity