Skip to content

Instantly share code, notes, and snippets.

@wilbefast
Created July 14, 2015 08:46
Show Gist options
  • Save wilbefast/a984348fbfbf5bc46e4e to your computer and use it in GitHub Desktop.
Save wilbefast/a984348fbfbf5bc46e4e to your computer and use it in GitHub Desktop.
Linear-interpolated colour-cycling
extern number time;
extern mat4 palette;
vec4 effect(vec4 colour, Image texture, vec2 texture_coords, vec2 screen_coords)
{
vec4 base = Texel(texture, texture_coords);
number grey = (base.r + base.g + base.b)/3;
vec4 swapped, next;
if(grey < 0.25)
{
swapped = palette[int(mod(floor(time), 4))];
next = palette[int(mod((floor(time) + 1), 4))];
}
else if(grey < 0.5)
{
swapped = palette[int(mod((floor(time) + 1), 4))];
next = palette[int(mod((floor(time) + 2), 4))];
}
else if(grey < 0.75)
{
swapped = palette[int(mod((floor(time) + 2), 4))];
next = palette[int(mod((floor(time) + 3), 4))];
}
else
{
swapped = palette[int(mod((floor(time) + 3), 4))];
next = palette[int(mod((floor(time)), 4))];
}
swapped.a = next.a = 1;
return mix(swapped, next, time - floor(time));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment