Skip to content

Instantly share code, notes, and snippets.

@ayamflow
Forked from activetheory/levels.glsl
Created February 20, 2018 02:09
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 ayamflow/ce1f69b1a95ec31df91b8b792079bb87 to your computer and use it in GitHub Desktop.
Save ayamflow/ce1f69b1a95ec31df91b8b792079bb87 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