gamma.fs 673 B

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