Skip to content

Instantly share code, notes, and snippets.

@wilbefast
Last active August 29, 2015 14:25
Show Gist options
  • Save wilbefast/6eb6571abae0479cfa15 to your computer and use it in GitHub Desktop.
Save wilbefast/6eb6571abae0479cfa15 to your computer and use it in GitHub Desktop.
A giant messy shader for doing a whole bunch of pixel-effects in Soul Harvest
const vec3 colours[10] = vec3[10](
vec3(217.0 / 255.0, 68.0 / 255.0, 54.0 / 255.0), // team 1 colour
vec3(76.0 / 255.0, 106.0 / 255.0, 255.0 / 255.0), // team 2 colour
vec3(179.0 / 255.0, 98.0 / 255.0, 138.0 / 255.0), // team 3 colour
vec3(65.0 / 255.0, 217.0 / 255.0, 65.0 / 255.0), // team 4 colour
vec3(140.0 / 255.0, 255.0 / 255.0, 64.0 / 255.0), // team 1 glow
vec3(255.0 / 255.0, 163.0 / 255.0, 52.0 / 255.0), // team 2 glow
vec3(255.0 / 255.0, 220.0 / 255.0, 64.0 / 255.0), // team 3 glow
vec3(103.0 / 255.0, 245.0 / 255.0, 255.0 / 255.0), // team 4 glow
vec3(1.0, 1.0, 1.0), // white (pain)
vec3(0.0, 0.0, 0.0) // black (dummy)
);
extern Image stipple_1;
extern Image stipple_2;
extern Image stipple_3;
vec4 effect(vec4 args, Image texture, vec2 texture_coords, vec2 screen_coords)
{
// the first field is used to determine brightness
vec4 result = Texel(texture, texture_coords) * vec4(args.x, args.x, args.x, 1.0f);
// the second field determines whether to tint colour or to fill with flat colour
float use_tint = step(args.y, 0.99f);
// the third field is used to determine which colour to select for the "bucket fill"
vec4 colour = vec4(colours[int(args.z * 9.0)], 1.0f - step(result.a, 0.0f));
float use_fill = step(args.z, 0.99f);
result = (1.0f - use_fill)*result + (1.0f - use_tint)*use_fill*colour + use_tint*colour*result;
// the fourth field is used for creating transparency through stipple patterns
vec2 stipple_coords = screen_coords / 16;
float heavy = step(args.a, 0.33f);
float medium = step(args.a, 0.66f)*(1.0f - heavy);
float light = step(args.a, 0.99f)*(1.0f - medium)*(1.0f - heavy);
float none = (1.0f - light)*(1.0f - medium)*(1.0f - heavy);
result.a *= none
+ Texel(stipple_1, stipple_coords).a*light
+ Texel(stipple_2, stipple_coords).a*medium
+ Texel(stipple_3, stipple_coords).a*heavy;
// all done!
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment