grayscale.fs 641 B

12345678910111213141516171819202122232425
  1. #version 100
  2. precision mediump float;
  3. // Input vertex attributes (from vertex shader)
  4. varying vec2 fragTexCoord;
  5. varying vec4 fragColor;
  6. // Input uniform values
  7. uniform sampler2D texture0;
  8. uniform vec4 colDiffuse;
  9. // NOTE: Add here your custom variables
  10. void main()
  11. {
  12. // Texel color fetching from texture sampler
  13. vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor;
  14. // Convert texel color to grayscale using NTSC conversion weights
  15. float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
  16. // Calculate final fragment color
  17. gl_FragColor = vec4(gray, gray, gray, texelColor.a);
  18. }