Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Consecutive recolor/dissolve shader

Discussion in 'Shaders' started by botove, Sep 17, 2019.

  1. botove

    botove

    Joined:
    Apr 10, 2015
    Posts:
    51
    Hello all!
    Have a question regarding consecutive recolor/dissolve (please check the gif). Interested in what approach should i take to make it work for any direction (only consecutive part). Also would be grateful to know how to use this not per screen pixel, but in game pixel resolution (to work with pixel sprites).
    Thanks!
    consecutive.gif
     
    Last edited: Sep 17, 2019
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Assuming this is a single sprite, then you'd need to author a gradient texture that has the "animation" baked into it. The most common example of this technique would be for something like a circular progress bar shader, where you use a radial gradient. Most examples use an alpha test shader and animate the cutoff, but you could also do it in a single shader where you lerp between two color values based on the texture and that "cutoff".

    If this is multiple sprites, then you'd have to have each one have it's own gradient to match the shape, and then figure out the timing offsets yourself.
     
  3. botove

    botove

    Joined:
    Apr 10, 2015
    Posts:
    51
    thanks! yeah, i use alpha/gradient values, thought about the way how i can make it dynamic (so i can approach it from different directions and still save this consecutive feel, don't know maybe reverse/modify the alpha condition depending on it).
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    If you want to make that fill happen from different directions, you could save that gradient data to channels of another image. Then you could pack 4 variants to one image (rgba)? Your example image could be handled with one texture.