Skip to content

Instantly share code, notes, and snippets.

@Madsy
Last active January 16, 2016 21:53
Show Gist options
  • Select an option

  • Save Madsy/dded8b4c8d8afb398e29 to your computer and use it in GitHub Desktop.

Select an option

Save Madsy/dded8b4c8d8afb398e29 to your computer and use it in GitHub Desktop.
With glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA), scaling both source and destination with the same factor:
Note that:
(src*a*k) + (dst*(1-a)*k) = ((src*a) + (dst*(1-a)))*k
But since k is a part of a, we have to do some trickery:
alpha = (1.0 - (1.0 - alpha)*factor)
alpha = 1.0 - (factor - alpha*factor)
alpha = 1.0 + (alpha-1)*factor
So the fragment shader code becomes:
color_out = vec4(color);
color_out.rgb = color_out.rgb*vec3(factor);
color_out.a = 1.0 + (color_out.a - 1.0)*factor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment