To implement gray scaling we need to modify slightly the fragment shader.
Conversion equation that I am using is,
Red * 0.299 + Green * 0.587 + Blue 0.144
The fragment shader used to do gray scaling is shown below,
uniform sampler2D u_sampler; uniform int u_compliment; varying vec2 v_texturecoord; void main() { vec4 clr = texture2D(u_sampler, v_texturecoord); float l = clr.r*0.299 + clr.g*0.587 + clr.b*0.114; l = clamp(l, 0.0, 1.0); if (u_compliment == 1) { l = 1.0 - l; } gl_FragColor = vec4(l, l, l, clr.a); }
For complete source code visit https://github.com/trsquarelab/glexamples
No comments:
Post a Comment