Skip to content

Instantly share code, notes, and snippets.

@activetheory
Created January 5, 2016 00:06
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save activetheory/b68c2d639e2bd272b2a7 to your computer and use it in GitHub Desktop.
Save activetheory/b68c2d639e2bd272b2a7 to your computer and use it in GitHub Desktop.
A GLSL module for color levels manipulation
float levelChannel(float inPixel, float inBlack, float inGamma, float inWhite, float outBlack, float outWhite) {
return (pow(((inPixel * 255.0) - inBlack) / (inWhite - inBlack), inGamma) * (outWhite - outBlack) + outBlack) / 255.0;
}
vec3 levels(vec3 inPixel, float inBlack, float inGamma, float inWhite, float outBlack, float outWhite) {
vec3 o = vec3(1.0);
o.r = levelChannel(inPixel.r, inBlack, inGamma, inWhite, outBlack, outWhite);
o.g = levelChannel(inPixel.g, inBlack, inGamma, inWhite, outBlack, outWhite);
o.b = levelChannel(inPixel.b, inBlack, inGamma, inWhite, outBlack, outWhite);
return o;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment