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.

Showcase Shader Graph Texture Scaling

Discussion in 'Visual Effect Graph' started by Kennosuke, Jun 3, 2021.

  1. Kennosuke

    Kennosuke

    Joined:
    Jun 29, 2018
    Posts:
    16
    Hey, everyone. In case you were wondering how to set up the Tiling and Offset node to scale your textures from the center outward, I noticed that there wasn't really any examples of that on the web.

    It took me a while to hammer down the correct math, but here is what I came up with.

    upload_2021-6-3_15-53-16.png

    This setup scales the texture from the center outward. In my case, I needed a radial texture to be able to scale inward and outward for some VFX animations. So, if you need a similar effect in your shaders, feel free to follow this example.

    Cheers,
    - Ken (SLAMS Games)

    Edit - Oops, I just realized that this should be "Shader Graph" instead of "VFX Graph," but I don't quite know how to change it.
     
    Last edited: Jun 3, 2021
  2. yoeldg2

    yoeldg2

    Joined:
    Apr 11, 2020
    Posts:
    8
    thank you dude!
     
  3. ViggeBoi

    ViggeBoi

    Joined:
    Jun 20, 2019
    Posts:
    6
    Thanks
     
  4. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    148
    Thanks so much!

    Also, I certainly could be wrong here, but I'm pretty sure we can simplify the graph to the below.

    upload_2022-3-5_9-44-48.png

    When trying to figure out how the graph was working, I used a little algebra to break it down for myself on paper and realized that my equation was simplifying back to the above graph. After making the updates, it looks to be working the same :).

    For those interested, here's how I came to this conclusion as I had fun thinking this through haha. Let's hope I'm not just going crazy and imagining things, lol.

    I created a sort of system of equations for each part of our graph. See the image below for how broke up these equations in my head.

    upload_2022-3-5_10-5-39.png

    After solving this equation for C. I realized I was left with the b equation. This meant to me that the output of our c was just producing the b nodes, making all other nodes unnecessary.

    I definitely could be not thinking this all the way through, so I would be happy for someone smarter than me to come along and correct me if I'm wrong! It's fun to learn together, after all :)
     
  5. KillHour

    KillHour

    Joined:
    Oct 25, 2015
    Posts:
    41
    Multiplying by -1 and then dividing by 2 is the same as just dividing by -2. So in the end, you're offsetting the UV by (Scale / -2) + 0.5. In other words, you can get rid of that multiply.
     
    Meatloaf4 likes this.
  6. MVS_1981

    MVS_1981

    Joined:
    Sep 10, 2020
    Posts:
    3
    where do you get this scale node from?
     
  7. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    446
    That's a Float Property (vector 1) made on the blackboard
     
    Meatloaf4 likes this.
  8. LTravaux

    LTravaux

    Joined:
    Oct 4, 2021
    Posts:
    1
    And to have an even more optimized operation we can replace the divide by -2 with multiply by -0.5, since the multiplication takes less cycle to calculate than the division! It won't make a big difference but if we can do it, we might as well do it!
     
  9. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    805
    In this case it should not matter, because compiler is smart enough to optimize constants and common edge cases. For instance this
    pow(x, 2)
    will be replaced with much cheaper
    x * x
    .