//////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2016 Leszek Koltunski //
// //
// This file is part of Distorted. //
// //
// Distorted is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 2 of the License, or //
// (at your option) any later version. //
// //
// Distorted is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with Distorted. If not, see . //
//////////////////////////////////////////////////////////////////////////////////////////////
precision lowp float;
uniform sampler2D u_Texture; // The input texture.
varying vec3 v_Position; // Interpolated position for this fragment.
varying vec3 v_Normal; // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
#if NUM_FRAGMENT>0
uniform int fNumEffects; // total number of fragment effects
uniform int fType[NUM_FRAGMENT]; // their types.
uniform vec4 fUniforms[2*NUM_FRAGMENT]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1]. First vec4 is the Interpolated values,
// next describes the Region, i.e. area over which the effect is active.
#if defined(SATURATION) || defined(SMOOTH_SATURATION)
const vec3 LUMI = vec3( 0.2125, 0.7154, 0.0721 );
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// CHROMA EFFECT
#if defined(CHROMA) || defined(SMOOTH_CHROMA)
void chroma(float degree, int effect, inout vec4 color)
{
color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// ALPHA EFFECT (change transparency level)
#if defined(ALPHA) || defined(SMOOTH_ALPHA)
void alpha(float degree, int effect, inout vec4 color)
{
color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// BRIGHTNESS EFFECT
#if defined(BRIGHTNESS) || defined(SMOOTH_BRIGHTNESS)
void brightness(float degree, int effect, inout vec4 color)
{
color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// CONTRAST EFFECT
#if defined(CONTRAST) || defined(SMOOTH_CONTRAST)
void contrast(float degree, int effect, inout vec4 color)
{
color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// SATURATION EFFECT
#if defined(SATURATION) || defined(SMOOTH_SATURATION)
void saturation(float degree, int effect, inout vec4 color)
{
float luminance = dot(LUMI,color.rgb);
color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
}
#endif
#endif // NUM_FRAGMENT>0
//////////////////////////////////////////////////////////////////////////////////////////////
void main()
{
vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
#if NUM_FRAGMENT>0
vec2 diff;
float pointDegree;
int j=0;
for(int i=0; i