Search Unity

Is there such a shader which can offset colours sequentially in a loop?

Discussion in 'Shaders' started by San_Holo, Apr 13, 2016.

  1. San_Holo


    Sep 26, 2014
    Hi, I was wondering you know if a shader exists which can produce an effect I have in mind which simply rotates the set of colours of a texture or offsets each colour which I hope may produce an animation like effect, you know like the old 8bit Atari logo boot demo or such like... hopefully I've described it well, enough but I haven't found such a thing so if you know of anything similar then I'd love to try it out, thanks
  2. smd863


    Jan 26, 2014
    You could just use a look-up texture. Use a two channel texture (i.e. red and green). Sample the main texture, and use the red component to sample into your look-up table texture. That would be a one-pixel wide texture containing the gradient of colors you wanted to animate. Multiply the result by your green component from the main texture.

    The red channel is your color indices, and the green channel is your luminance mask (because black in your red channel doesn't mean black anymore; it could be hot pink). To animate the effect you add an offset to red before sampling the look-up texture. Set up a shader property and loop it from 0 to 1 from a script incrementing it each frame.
    San_Holo likes this.
  3. Zicandar


    Feb 10, 2014
    If you have the same color along one axis, (all pixels at that position in x are the same), you could get away with a single texture sample. Normally the nr of texture samples don't matter much, except when they have to wait on eachother.
    In this case one axis is the color used for each place. The other axis you only sample a single "row" from, (I suggest to allow sampling inbetween rows for smoother transitions), based on time or some other value you control.
    Basically a texture built using gradients of gradients.
    This shader would be rather simple and cheap to run as it'd mainly be the vertex shader that needs extra work, (changing the UV-coordinates.
    If you want the colors to also shift along both axises, ex: darker at the bottom and brighter at the top, you could use 2 textures and multiply/add them to eachother. This would still be cheaper as it's not a texture->texture lookup.
    San_Holo likes this.