Last active
September 3, 2023 08:53
-
-
Save yiwenl/1c2ce935e66b82c7df5f to your computer and use it in GitHub Desktop.
Greyscale in glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float contrast(float mValue, float mScale, float mMidPoint) { | |
return clamp( (mValue - mMidPoint) * mScale + mMidPoint, 0.0, 1.0); | |
} | |
float contrast(float mValue, float mScale) { | |
return contrast(mValue, mScale, .5); | |
} | |
vec3 contrast(vec3 mValue, float mScale, float mMidPoint) { | |
return vec3( contrast(mValue.r, mScale, mMidPoint), contrast(mValue.g, mScale, mMidPoint), contrast(mValue.b, mScale, mMidPoint) ); | |
} | |
vec3 contrast(vec3 mValue, float mScale) { | |
return contrast(mValue, mScale, .5); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec3 greyscale(vec3 color, float str) { | |
float g = dot(color, vec3(0.299, 0.587, 0.114)); | |
return mix(color, vec3(g), str); | |
} | |
vec3 greyscale(vec3 color) { | |
return greyscale(color, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment