Skip to content

Instantly share code, notes, and snippets.

@aferriss
Created April 26, 2017 23:20
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aferriss/9be46b6350a08148da02559278daa244 to your computer and use it in GitHub Desktop.
Save aferriss/9be46b6350a08148da02559278daa244 to your computer and use it in GitHub Desktop.
GLSL Photoshop Style Levels Adjustment
vec3 gammaCorrect(vec3 color, float gamma){
return pow(color, vec3(1.0/gamma));
}
vec3 levelRange(vec3 color, float minInput, float maxInput){
return min(max(color - vec3(minInput), vec3(0.0)) / (vec3(maxInput) - vec3(minInput)), vec3(1.0));
}
vec3 finalLevels(vec3 color, float minInput, float gamma, float maxInput){
return gammaCorrect(levelRange(color, minInput, maxInput), gamma);
}
//use like: vec3 col = finalLevels(someTex.rgb, 34.0/255.0, 1.5, 235.0/255.0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment