Skip to content

Instantly share code, notes, and snippets.

@veeneck
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veeneck/23854616813f74819d66 to your computer and use it in GitHub Desktop.
Save veeneck/23854616813f74819d66 to your computer and use it in GitHub Desktop.
Gradient and masking shader
void main() {
// Load the pixel from our original texture, and the same place in the gradient circle
vec4 val = texture2D(u_texture, v_tex_coord);
vec4 grad = texture2D(u_gradient, v_tex_coord);
// [1 - ORIGINAL CHECK] If the original is transparent AND
// [2 - HEALTH CHECK] The gradient image has a black value less than the remaining health AND
// [3 - MASKING] The gradient pixel is not transparent
if (val.a < 0.1 && grad.r < u_health && grad.a > 0.8) {
gl_FragColor = vec4(0.0,1.0,0.0,1.0);
} else {
gl_FragColor = val;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment