Skip to content

Instantly share code, notes, and snippets.

@natxopedreira
Created January 30, 2015 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natxopedreira/f4eee5670d191fb6faf8 to your computer and use it in GitHub Desktop.
Save natxopedreira/f4eee5670d191fb6faf8 to your computer and use it in GitHub Desktop.
#version 150
//precision mediump float;
uniform sampler2DRect tex0;
uniform sampler2DRect u_Texture2;
in vec2 v_TexCoordinate;
out vec4 fragColor;
const vec3 W = vec3(0.2125, 0.7154, 0.0721);
vec3 BrightnessContrastSaturation(vec3 color, float brt, float con, float sat)
{
vec3 black = vec3(0., 0., 0.);
vec3 middle = vec3(0.5, 0.5, 0.5);
float luminance = dot(color, W);
vec3 gray = vec3(luminance, luminance, luminance);
vec3 brtColor = mix(black, color, brt);
vec3 conColor = mix(middle, brtColor, con);
vec3 satColor = mix(gray, conColor, sat);
return satColor;
}
vec3 ovelayBlender(vec3 Color, vec3 _filter){
vec3 filter_result;
float luminance = dot(_filter, W);
if(luminance < 0.5)
filter_result = 2. * _filter * Color;
else
filter_result = 1. - (1. - (2. *(_filter - 0.5)))*(1. - Color);
return filter_result;
}
void main()
{
//get the pixel
vec2 st = v_TexCoordinate.st;
vec3 irgb = texture2DRect(tex0, st).rgb;
vec3 _filter = texture2DRect(u_Texture2, st).rgb;
//adjust the brightness/contrast/saturation
float T_bright = 1.3;
float T_contrast = 1.0;
float T_saturation = 1.3;
vec3 bcs_result = BrightnessContrastSaturation(irgb, T_bright, T_contrast, T_saturation);
//more red, less blue
vec3 rb_result = vec3(bcs_result.r*1.15, bcs_result.g, bcs_result.b*0.8);
//add filter (overlay blending)
vec3 after_filter = mix(rb_result, ovelayBlender(rb_result, _filter), 0.8);
fragColor = vec4(after_filter, 1.);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment