gamma.fs 580 B

1234567891011121314151617181920212223242526272829
  1. #version 150
  2. uniform sampler2D source[];
  3. in Vertex {
  4. vec2 texCoord;
  5. };
  6. out vec4 fragColor;
  7. const float saturation = 1.0;
  8. const float gamma = 1.0;
  9. const float luminance = 1.0;
  10. vec3 grayscale(vec3 col)
  11. {
  12. // Non-conventional way to do grayscale,
  13. // but bSNES uses this as grayscale value.
  14. return vec3(dot(col, vec3(0.3333)));
  15. }
  16. void main() {
  17. vec3 res = texture(source[0], texCoord).xyz;
  18. res = mix(grayscale(res), res, saturation); // Apply saturation
  19. res = pow(res, vec3(gamma)); // Apply gamma
  20. fragColor = vec4(clamp(res * luminance, 0.0, 1.0), 1.0);
  21. }