Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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