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 Optimize as possible

Discussion in 'Shader Graph' started by Rachan, Aug 19, 2023.

  1. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    654
    Hi there!

    I'm new in Shader graph and I like it so much!
    so I would like to know how to optimize to improve performance as much as possible,

    for Now I just changed a Precision to Half in Graph Setting, and the Shader seem to be
    low quality a bit, I hope it should be high performance in mobile,

    But another way to optimize I don't know.
    anyone has any suggestion?

    Thanks!!!
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,977
    There isn't enough information here to make suggestions?

    The very broad and general advice is "do less stuff".
     
    Rachan and Qriva like this.
  3. icauroboros

    icauroboros

    Joined:
    Apr 30, 2021
    Posts:
    99
    Most of the time main bottleneck on mobile GPU s are memory bandwidth. So these tips might improve GPU performance on Shaders:
    • Use lower precision
    • Use less Texture
    • Don't use unnecessary texture channel (pack you texture maps)
    • Use lower resolution textures
    • Use cheapest possible Texture format for your use case
    Also from I remember, there is no way to create simple lit equivalent on shader graph, so you might want to check this
    https://github.com/Zallist/unity.zallist.universal-simple-lit-shadergraph-target
     
    Rachan likes this.
  4. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    654
    Thank you very much guy for your answer!

    here is my Shader Graph screenshot


    I changed Precision back to Single, because Half is looks weird in mobile
     
  5. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    This is not always true on mobile, it's more about balancing usage of samplers and math.

    Another advice is to avoid functions like acos, tan, pow when possible as those are more expansive than adding or multiplication.

    Personally I can't see anything that can be heavily optimized, perhaps speed X and Y could be vector2, but I doubt that makes any sagnificant difference. The only thing that could be changed (but not sure if possible for you) to replace voronoi with texture sampling (assuming you target mobile), and that power node after voronoi, but it's up to you if you manage to get good look with plain multiplication.
     
    Rachan likes this.
  6. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    702
    Get as many calculations done before sampling a texture is a good start point for shader optimization.
     
    Rachan likes this.
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,977
    What do you mean?
     
    Rachan likes this.
  8. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    654
    Thank you very much everyone!

    I changed things so much I has remove Pow and some matches node and then I wondering
    about

    Texture Sample vs Preview node

    which one is heavier?
     
  9. icauroboros

    icauroboros

    Joined:
    Apr 30, 2021
    Posts:
    99
    huh? how these two things related? Preview node is for debug purposes, it will be removed in compilation any ways also any calculation that not connected final block will be not performed and removed on compilation.
     
    Qriva likes this.
  10. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    To be precise it will be "removed" not because it's for debugging, but it literally does nothing.

    @Rachan Looks like you are doing premature optimization. Did you try to measure performence? Any tests?
    Or you are just trying to "optimize" just for sake of optimization?