-
-
Save rafaelbeckel/1e920efebf23631f0be09b3efa57b1a8 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
void main(void) { | |
vec4 color = texture2D(uSampler0, vTextureCoord); | |
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114)); | |
gl_FragColor = vec4(vec3(gray), 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment