compositing.glslf 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #version GLSL_VERSION
  2. #include <precision_statement.glslf>
  3. #include <std.glsl>
  4. #include <color_util.glslf>
  5. uniform sampler2D u_color;
  6. uniform float u_brightness; // -1..1
  7. uniform float u_contrast; // -1..1
  8. uniform float u_exposure; // 0..inf
  9. uniform float u_saturation; // 0..inf
  10. /*==============================================================================
  11. SHADER INTERFACE
  12. ==============================================================================*/
  13. GLSL_IN vec2 v_texcoord;
  14. //------------------------------------------------------------------------------
  15. GLSL_OUT vec4 GLSL_OUT_FRAG_COLOR;
  16. /*==============================================================================
  17. MAIN
  18. ==============================================================================*/
  19. void main(void) {
  20. vec4 tex_input = GLSL_TEXTURE(u_color, v_texcoord);
  21. vec3 color = tex_input.rgb;
  22. // brightness
  23. if (u_brightness < 0.0)
  24. color = color * (1.0 + u_brightness);
  25. else
  26. color = color + ((1.0 - color) * u_brightness);
  27. // contrast
  28. color = (color - 0.5) * (tan((u_contrast + 1.0) * M_PI_4)) + 0.5;
  29. // exposure
  30. color *= u_exposure;
  31. // saturation
  32. float intensity = luma(vec4(color, 0.0));
  33. color = mix(vec3(intensity), color, u_saturation);
  34. //GLSL_OUT_FRAG_COLOR = vec4(sqrt(color), tex_input.a);
  35. //GLSL_OUT_FRAG_COLOR = vec4(pow(color, vec3(1.0/2.2)), tex_input.a);
  36. GLSL_OUT_FRAG_COLOR = vec4(color, tex_input.a);
  37. }