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. Dismiss Notice

Question Set shader property from script and affect all materials

Discussion in 'Shader Graph' started by lambch0p, Feb 13, 2022.

  1. lambch0p

    lambch0p

    Joined:
    Oct 22, 2014
    Posts:
    62
    Hi,

    I have a world curvature shader that has 2 float values to affect the amount of curve in the horizontal and vertical axes. All of the objects in my scene have materials based on this shader, but each one has a different material.

    The curve floats need to be the same across every material to ensure they all bend in the same manner. I want to modify the value of the curve at runtime to create the effect of a meandering tunnel but it feels very inefficient to iterate through each material every frame and change the horizontal and vertical curve amounts.

    As they all use the same shader, is there a way to modify these values at a shader level so that they affect all materials that use this shader (I'm pretty new to shaders to this may be a fundamental misunderstanding of how they work), or is there some other more efficient method of changing these properties on the materials.

    In case it matters, I'm using URP.
    Thanks
    Mick
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Last edited: Feb 13, 2022
  3. lambch0p

    lambch0p

    Joined:
    Oct 22, 2014
    Posts:
    62
    I hadn't (you don't know what you don't know), but will certainly have a look now. Thanks!