Search Unity

Shader : Lerp a texture (or a material if doable)

Discussion in 'Shaders' started by jdelpuec, Jun 3, 2022.

  1. jdelpuec

    jdelpuec

    Joined:
    May 14, 2020
    Posts:
    3
    Hello everyone,

    Here's my issue : I would like to color an object starting from a specific point and growing outward.
    I found a lot of lerping tutorials but none with this specification.
    I assumed this is impossible with a material cause you can't change a specific pixel of it (not sure about this), so I looked into textures.

    If this isn't clear, imagine the japan flag, and the red circle in the middle would keep on growing until the whole flag became red.
    That's what I'm looking to do.
    Do you guys have any idea on what I should look into ?

    Cheers
     
  2. tmcthee

    tmcthee

    Joined:
    Mar 8, 2013
    Posts:
    119
    Doesn't sound like you want to lerp, that would create a crossfade effect.
    If you wanted the circle to grow, you would probably want to scale the UVs of the circle texture.
     
  3. jdelpuec

    jdelpuec

    Joined:
    May 14, 2020
    Posts:
    3
    Alright, make sense.
    I still have not put myself into textures yet.


    But the way you say it, seems like the circle texture and the 'flag' texture are two different items.
    It's gonna be a single texture at then end.
    From what I've seen on different tutos, Scale allows to do zoom in our out a texture, out to the point it became a mosaic.

    My example wasn't clear enough, so maybe this will do :

    The moment my hand (avatar in the game), touches a certain wall, it became infected and gradually turns red (or whatever).
    Kind of like a parasite growing onto the arm from the hand.

    Do you think we still do this with textures UVs ?
     
  4. Azeew

    Azeew

    Joined:
    Jul 11, 2021
    Posts:
    49
    If you're new to shaders, I highly recommend Shader Graph.

    If the way you UV unwrapped the model allows for it, just do this:
    upload_2022-6-8_14-11-25.png

    If not, you can just use world space position instead. Add a slider and an offset to the Smoothstep inputs to control the size and smoothness/fade amount. Switch the colors with your desired textures. Repeat the same thing for the other PBR maps, if you're using them.
     
  5. jdelpuec

    jdelpuec

    Joined:
    May 14, 2020
    Posts:
    3
    New to shaders indeed !
    Okok thanks a lot, I've seen bunch of tutos on shader graphs, it is probably gonna be my solution.

    Also, I assume the radius of the circle is variable with the edge1 and edge2 values ?
    Are those variables runtime modifiable and can i access to them inside a script ?