2011-01-06 19:00:03 +00:00
|
|
|
uniform sampler2D sample;
|
2007-07-04 09:59:07 +00:00
|
|
|
uniform float textureWidth;
|
|
|
|
uniform float textureHeight;
|
2008-08-27 12:20:34 +00:00
|
|
|
uniform float opacity;
|
|
|
|
uniform float brightness;
|
|
|
|
uniform float saturation;
|
2011-01-06 19:00:03 +00:00
|
|
|
uniform int u_forceAlpha;
|
|
|
|
|
|
|
|
varying vec2 varyingTexCoords;
|
2007-07-04 09:59:07 +00:00
|
|
|
|
|
|
|
// Converts pixel coordinates to texture coordinates
|
2008-08-27 12:20:34 +00:00
|
|
|
vec2 pix2tex( vec2 pix )
|
2007-07-04 09:59:07 +00:00
|
|
|
{
|
2008-08-27 12:20:34 +00:00
|
|
|
return vec2( pix.s / textureWidth, pix.t / textureHeight );
|
2007-07-04 09:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2011-01-06 19:00:03 +00:00
|
|
|
vec4 tex = texture2D( sample, pix2tex( varyingTexCoords ));
|
2008-08-27 12:20:34 +00:00
|
|
|
if( saturation != 1.0 )
|
|
|
|
{
|
|
|
|
vec3 desaturated = tex.rgb * vec3( 0.30, 0.59, 0.11 );
|
|
|
|
desaturated = vec3( dot( desaturated, tex.rgb ));
|
|
|
|
tex.rgb = tex.rgb * vec3( saturation ) + desaturated * vec3( 1.0 - saturation );
|
|
|
|
}
|
2011-01-06 19:00:03 +00:00
|
|
|
tex.rgb = tex.rgb * opacity * vec3( brightness );
|
|
|
|
tex.rgb = vec3(1.0) - tex.rgb;
|
|
|
|
tex.a = tex.a * opacity;
|
|
|
|
if (u_forceAlpha > 0) {
|
|
|
|
tex.a = 1.0;
|
|
|
|
}
|
2007-07-04 09:59:07 +00:00
|
|
|
|
2008-08-27 12:20:34 +00:00
|
|
|
gl_FragColor = tex;
|
2007-07-04 09:59:07 +00:00
|
|
|
}
|