1 |
d333eb6b
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
6a06a912
|
Leszek Koltunski
|
|
20 |
8cefe6a3
|
Leszek Koltunski
|
precision lowp float;
|
21 |
6a06a912
|
Leszek Koltunski
|
|
22 |
d333eb6b
|
Leszek Koltunski
|
uniform sampler2D u_Texture; // The input texture.
|
23 |
6a06a912
|
Leszek Koltunski
|
|
24 |
2fce34f4
|
Leszek Koltunski
|
varying vec3 v_Position; // Interpolated position for this fragment.
|
25 |
d333eb6b
|
Leszek Koltunski
|
varying vec3 v_Normal; // Interpolated normal for this fragment.
|
26 |
|
|
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
|
27 |
6a06a912
|
Leszek Koltunski
|
|
28 |
|
|
#if NUM_FRAGMENT>0
|
29 |
ad33f883
|
Leszek Koltunski
|
uniform int fNumEffects; // total number of fragment effects
|
30 |
6a06a912
|
Leszek Koltunski
|
uniform int fType[NUM_FRAGMENT]; // their types.
|
31 |
2fce34f4
|
Leszek Koltunski
|
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,
|
32 |
|
|
// next describes the Region, i.e. area over which the effect is active.
|
33 |
|
|
|
34 |
ad33f883
|
Leszek Koltunski
|
#if defined(SATURATION) || defined(SMOOTH_SATURATION)
|
35 |
ffbf279e
|
Leszek Koltunski
|
const vec3 LUMI = vec3( 0.2125, 0.7154, 0.0721 );
|
36 |
ad33f883
|
Leszek Koltunski
|
#endif
|
37 |
6a06a912
|
Leszek Koltunski
|
|
38 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
341c803d
|
Leszek Koltunski
|
// CHROMA EFFECT
|
40 |
6a06a912
|
Leszek Koltunski
|
|
41 |
81a0b906
|
leszek
|
#if defined(CHROMA) || defined(SMOOTH_CHROMA)
|
42 |
ffbf279e
|
Leszek Koltunski
|
void chroma(float degree, int effect, inout vec4 color)
|
43 |
6a06a912
|
Leszek Koltunski
|
{
|
44 |
ffbf279e
|
Leszek Koltunski
|
color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
|
45 |
6a06a912
|
Leszek Koltunski
|
}
|
46 |
81a0b906
|
leszek
|
#endif
|
47 |
6a06a912
|
Leszek Koltunski
|
|
48 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
49 |
341c803d
|
Leszek Koltunski
|
// ALPHA EFFECT (change transparency level)
|
50 |
6a06a912
|
Leszek Koltunski
|
|
51 |
81a0b906
|
leszek
|
#if defined(ALPHA) || defined(SMOOTH_ALPHA)
|
52 |
ffbf279e
|
Leszek Koltunski
|
void alpha(float degree, int effect, inout vec4 color)
|
53 |
6a06a912
|
Leszek Koltunski
|
{
|
54 |
ffbf279e
|
Leszek Koltunski
|
color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);
|
55 |
6a06a912
|
Leszek Koltunski
|
}
|
56 |
81a0b906
|
leszek
|
#endif
|
57 |
6a06a912
|
Leszek Koltunski
|
|
58 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
341c803d
|
Leszek Koltunski
|
// BRIGHTNESS EFFECT
|
60 |
6a06a912
|
Leszek Koltunski
|
|
61 |
81a0b906
|
leszek
|
#if defined(BRIGHTNESS) || defined(SMOOTH_BRIGHTNESS)
|
62 |
ffbf279e
|
Leszek Koltunski
|
void brightness(float degree, int effect, inout vec4 color)
|
63 |
6a06a912
|
Leszek Koltunski
|
{
|
64 |
ffbf279e
|
Leszek Koltunski
|
color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
65 |
6a06a912
|
Leszek Koltunski
|
}
|
66 |
81a0b906
|
leszek
|
#endif
|
67 |
|
|
|
68 |
6a06a912
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
341c803d
|
Leszek Koltunski
|
// CONTRAST EFFECT
|
70 |
6a06a912
|
Leszek Koltunski
|
|
71 |
81a0b906
|
leszek
|
#if defined(CONTRAST) || defined(SMOOTH_CONTRAST)
|
72 |
ffbf279e
|
Leszek Koltunski
|
void contrast(float degree, int effect, inout vec4 color)
|
73 |
6a06a912
|
Leszek Koltunski
|
{
|
74 |
ffbf279e
|
Leszek Koltunski
|
color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
75 |
6a06a912
|
Leszek Koltunski
|
}
|
76 |
81a0b906
|
leszek
|
#endif
|
77 |
6a06a912
|
Leszek Koltunski
|
|
78 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
341c803d
|
Leszek Koltunski
|
// SATURATION EFFECT
|
80 |
6a06a912
|
Leszek Koltunski
|
|
81 |
81a0b906
|
leszek
|
#if defined(SATURATION) || defined(SMOOTH_SATURATION)
|
82 |
ffbf279e
|
Leszek Koltunski
|
void saturation(float degree, int effect, inout vec4 color)
|
83 |
6a06a912
|
Leszek Koltunski
|
{
|
84 |
ffbf279e
|
Leszek Koltunski
|
float luminance = dot(LUMI,color.rgb);
|
85 |
|
|
color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
86 |
6a06a912
|
Leszek Koltunski
|
}
|
87 |
81a0b906
|
leszek
|
#endif
|
88 |
6a06a912
|
Leszek Koltunski
|
|
89 |
03cb451d
|
Leszek Koltunski
|
#endif // NUM_FRAGMENT>0
|
90 |
6a06a912
|
Leszek Koltunski
|
|
91 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
92 |
|
|
|
93 |
|
|
void main()
|
94 |
|
|
{
|
95 |
42e08626
|
Leszek Koltunski
|
vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
|
96 |
4018b3b7
|
Leszek Koltunski
|
|
97 |
|
|
#if NUM_FRAGMENT>0
|
98 |
6a06a912
|
Leszek Koltunski
|
vec2 diff;
|
99 |
|
|
float pointDegree;
|
100 |
03cb451d
|
Leszek Koltunski
|
int j=0;
|
101 |
|
|
|
102 |
6a06a912
|
Leszek Koltunski
|
for(int i=0; i<fNumEffects; i++)
|
103 |
|
|
{
|
104 |
03cb451d
|
Leszek Koltunski
|
diff = (v_Position.xy - fUniforms[j+1].xy)/fUniforms[j+1].zw;
|
105 |
6a06a912
|
Leszek Koltunski
|
pointDegree = max(0.0,1.0-dot(diff,diff));
|
106 |
341c803d
|
Leszek Koltunski
|
|
107 |
81a0b906
|
leszek
|
#ifdef CHROMA
|
108 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==CHROMA ) chroma (sign(pointDegree),j,pixel); else
|
109 |
81a0b906
|
leszek
|
#endif
|
110 |
|
|
#ifdef SMOOTH_CHROMA
|
111 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==SMOOTH_CHROMA ) chroma ( pointDegree ,j,pixel); else
|
112 |
81a0b906
|
leszek
|
#endif
|
113 |
|
|
#ifdef ALPHA
|
114 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==ALPHA ) alpha (sign(pointDegree),j,pixel); else
|
115 |
81a0b906
|
leszek
|
#endif
|
116 |
|
|
#ifdef SMOOTH_ALPHA
|
117 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==SMOOTH_ALPHA ) alpha ( pointDegree ,j,pixel); else
|
118 |
81a0b906
|
leszek
|
#endif
|
119 |
|
|
#ifdef BRIGHTNESS
|
120 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==BRIGHTNESS ) brightness(sign(pointDegree),j,pixel); else
|
121 |
81a0b906
|
leszek
|
#endif
|
122 |
|
|
#ifdef SMOOTH_BRIGHTNESS
|
123 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==SMOOTH_BRIGHTNESS ) brightness( pointDegree ,j,pixel); else
|
124 |
81a0b906
|
leszek
|
#endif
|
125 |
|
|
#ifdef CONTRAST
|
126 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==CONTRAST ) contrast (sign(pointDegree),j,pixel); else
|
127 |
81a0b906
|
leszek
|
#endif
|
128 |
|
|
#ifdef SMOOTH_CONTRAST
|
129 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==SMOOTH_CONTRAST ) contrast ( pointDegree ,j,pixel); else
|
130 |
81a0b906
|
leszek
|
#endif
|
131 |
|
|
#ifdef SATURATION
|
132 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==SATURATION ) saturation(sign(pointDegree),j,pixel); else
|
133 |
81a0b906
|
leszek
|
#endif
|
134 |
|
|
#ifdef SMOOTH_SATURATION
|
135 |
03cb451d
|
Leszek Koltunski
|
if( fType[i]==SMOOTH_SATURATION ) saturation( pointDegree ,j,pixel); else
|
136 |
81a0b906
|
leszek
|
#endif
|
137 |
|
|
{}
|
138 |
03cb451d
|
Leszek Koltunski
|
|
139 |
|
|
j+=2;
|
140 |
6a06a912
|
Leszek Koltunski
|
}
|
141 |
|
|
#endif
|
142 |
ff8ad0a7
|
Leszek Koltunski
|
|
143 |
c90b9e01
|
Leszek Koltunski
|
gl_FragColor = vec4(pixel.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, pixel.a);
|
144 |
341c803d
|
Leszek Koltunski
|
}
|