Search Unity

  1. We are looking for feedback on our SRP Rendering APIs through this Survey.
    Dismiss Notice
  2. Unity 2020.2 has been released.
    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

Help Wanted Unscaled time on shadergraph

Discussion in 'Shaders' started by pineapuru, Nov 26, 2020.

  1. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    15
    Hey, I've been trying out shadergraph and shader programming in general and noticed shadergraph doesn't have any unscaled time options, also I haven't found many solutions on using unscaled time on shader codes, I searched on the forum and found something from 2015 saying it isn't possible to use unscaled time on shadergraph, is that still true? what would be a good method to make a shader run on unscaled time easily?

    Edit: Just to inform everyone, I animate a lot of my pause scenes with shaders, that's why I need them to act even when time is freezed, they're like background scrolling textures etc.
     
    Last edited: Nov 26, 2020
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,340
    Why can't you just set value from C# side and use that to drive your shader animations.
     
    polemical likes this.
  3. polemical

    polemical

    Joined:
    Jun 17, 2019
    Posts:
    698
    Indeed. To elaborate on that approach, add something like public Renderer ren; to a component and drag whichever to it. Add a Float property to your Shader Graph, call it something like "Unscaled Time" with a reference name like "_UnscaledTime". Then in Shader Graph, connect your Unscaled Time node to whatever, and finally in Update of the component you added ren to:
    Code (CSharp):
    1. ren.sharedMaterial.SetFloat("_UnscaledTime", Time.unscaledTime);
    Note the above expects the renderer is using a single material. If not, use .sharedMaterials[index] instead.
     
    pineapuru likes this.
  4. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    15
    Thanks for teaching me on how to do it! Just had to do some changes as UI images doesn't have renderers aparently, but just had to change the code to:
    Code (CSharp):
    1. img.material.SetFloat("_UnscaledTime", Time.unscaledTime);
    Thank you so much again. :)
     
    polemical likes this.
unityunity