Revision ffbf279e
Added by Leszek Koltunski almost 8 years ago
src/main/res/raw/main_fragment_shader.glsl | ||
---|---|---|
32 | 32 |
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, |
33 | 33 |
// next describes the Region, i.e. area over which the effect is active. |
34 | 34 |
|
35 |
const vec3 LUMI3= vec3( 0.2125, 0.7154, 0.0721 ); |
|
36 |
const vec3 ZERO3= vec3(0.0,0.0,0.0); |
|
37 |
const vec3 HALF3= vec3(0.5,0.5,0.5); |
|
38 |
const vec2 ONE2 = vec2(1.0,1.0); |
|
39 |
const vec2 HALF2= vec2(0.5,0.5); |
|
40 |
|
|
35 |
const vec3 LUMI = vec3( 0.2125, 0.7154, 0.0721 ); |
|
36 |
|
|
41 | 37 |
////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 38 |
// MACROBLOCK EFFECT |
43 | 39 |
|
44 |
void macroblock(float degree, int effect, inout vec4 pixel)
|
|
40 |
void macroblock(float degree, int effect, inout vec2 tex)
|
|
45 | 41 |
{ |
46 |
vec2 a = degree*(fUniforms[effect].yz-ONE2)+ONE2; |
|
47 |
vec2 tex = ( max((1.0-degree)*v_TexCoordinate,floor(v_TexCoordinate*a)) + degree*HALF2 ) / a; |
|
48 |
|
|
49 |
pixel = texture2D(u_Texture, tex); |
|
42 |
vec2 one = vec2(1.0,1.0); |
|
43 |
vec2 a = degree*(fUniforms[effect].yz-one)+one; |
|
44 |
tex = ( max((1.0-degree)*tex,floor(tex*a)) + degree*vec2(0.5,0.5) ) / a; |
|
50 | 45 |
} |
51 | 46 |
|
52 | 47 |
////////////////////////////////////////////////////////////////////////////////////////////// |
53 | 48 |
// CHROMA EFFECT |
54 | 49 |
|
55 |
void chroma(float degree, int effect, inout vec4 pixel)
|
|
50 |
void chroma(float degree, int effect, inout vec4 color)
|
|
56 | 51 |
{ |
57 |
pixel.rgb = mix( pixel.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
|
|
52 |
color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
|
|
58 | 53 |
} |
59 | 54 |
|
60 | 55 |
////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 56 |
// ALPHA EFFECT (change transparency level) |
62 | 57 |
|
63 |
void alpha(float degree, int effect, inout vec4 pixel)
|
|
58 |
void alpha(float degree, int effect, inout vec4 color)
|
|
64 | 59 |
{ |
65 |
pixel.a *= (degree*(fUniforms[effect].x-1.0)+1.0);
|
|
60 |
color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);
|
|
66 | 61 |
} |
67 | 62 |
|
68 | 63 |
////////////////////////////////////////////////////////////////////////////////////////////// |
69 | 64 |
// BRIGHTNESS EFFECT |
70 | 65 |
|
71 |
void brightness(float degree, int effect, inout vec4 pixel)
|
|
66 |
void brightness(float degree, int effect, inout vec4 color)
|
|
72 | 67 |
{ |
73 |
pixel.rgb = mix(ZERO3, pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
68 |
color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
74 | 69 |
} |
75 |
|
|
70 |
|
|
76 | 71 |
////////////////////////////////////////////////////////////////////////////////////////////// |
77 | 72 |
// CONTRAST EFFECT |
78 | 73 |
|
79 |
void contrast(float degree, int effect, inout vec4 pixel)
|
|
74 |
void contrast(float degree, int effect, inout vec4 color)
|
|
80 | 75 |
{ |
81 |
pixel.rgb = mix(HALF3, pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
76 |
color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
82 | 77 |
} |
83 | 78 |
|
84 | 79 |
////////////////////////////////////////////////////////////////////////////////////////////// |
85 | 80 |
// SATURATION EFFECT |
86 | 81 |
|
87 |
void saturation(float degree, int effect, inout vec4 pixel)
|
|
82 |
void saturation(float degree, int effect, inout vec4 color)
|
|
88 | 83 |
{ |
89 |
float luminance = dot(LUMI3,pixel.rgb);
|
|
90 |
pixel.rgb = mix(vec3(luminance,luminance,luminance), pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
84 |
float luminance = dot(LUMI,color.rgb);
|
|
85 |
color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
91 | 86 |
} |
92 | 87 |
|
93 | 88 |
#endif |
... | ... | |
96 | 91 |
|
97 | 92 |
void main() |
98 | 93 |
{ |
99 |
vec4 pixel = texture2D(u_Texture, v_TexCoordinate); |
|
94 |
vec2 tex = v_TexCoordinate; |
|
95 |
vec4 col = vec4(1.0,1.0,1.0,1.0); |
|
100 | 96 |
|
101 | 97 |
#if NUM_FRAGMENT>0 |
102 | 98 |
vec2 diff; |
103 | 99 |
float pointDegree; |
104 |
|
|
100 |
|
|
105 | 101 |
for(int i=0; i<fNumEffects; i++) |
106 | 102 |
{ |
107 | 103 |
diff = (v_Position.xy - fUniforms[2*i+1].xy)/fUniforms[2*i+1].zw; |
108 | 104 |
pointDegree = max(0.0,1.0-dot(diff,diff)); |
109 | 105 |
|
110 |
if( fType[i]==MACROBLOCK ) macroblock(sign(pointDegree),2*i, pixel);
|
|
111 |
else if( fType[i]==CHROMA ) chroma (sign(pointDegree),2*i, pixel);
|
|
112 |
else if( fType[i]==SMOOTH_CHROMA ) chroma ( pointDegree ,2*i, pixel);
|
|
113 |
else if( fType[i]==ALPHA ) alpha (sign(pointDegree),2*i, pixel);
|
|
114 |
else if( fType[i]==SMOOTH_ALPHA ) alpha ( pointDegree ,2*i, pixel);
|
|
115 |
else if( fType[i]==BRIGHTNESS ) brightness(sign(pointDegree),2*i, pixel);
|
|
116 |
else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness( pointDegree ,2*i, pixel);
|
|
117 |
else if( fType[i]==CONTRAST ) contrast (sign(pointDegree),2*i, pixel);
|
|
118 |
else if( fType[i]==SMOOTH_CONTRAST ) contrast ( pointDegree ,2*i, pixel);
|
|
119 |
else if( fType[i]==SATURATION ) saturation(sign(pointDegree),2*i, pixel);
|
|
120 |
else if( fType[i]==SMOOTH_SATURATION ) saturation( pointDegree ,2*i, pixel);
|
|
106 |
if( fType[i]==MACROBLOCK ) macroblock(sign(pointDegree),2*i,tex);
|
|
107 |
else if( fType[i]==CHROMA ) chroma (sign(pointDegree),2*i,col);
|
|
108 |
else if( fType[i]==SMOOTH_CHROMA ) chroma ( pointDegree ,2*i,col);
|
|
109 |
else if( fType[i]==ALPHA ) alpha (sign(pointDegree),2*i,col);
|
|
110 |
else if( fType[i]==SMOOTH_ALPHA ) alpha ( pointDegree ,2*i,col);
|
|
111 |
else if( fType[i]==BRIGHTNESS ) brightness(sign(pointDegree),2*i,col);
|
|
112 |
else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness( pointDegree ,2*i,col);
|
|
113 |
else if( fType[i]==CONTRAST ) contrast (sign(pointDegree),2*i,col);
|
|
114 |
else if( fType[i]==SMOOTH_CONTRAST ) contrast ( pointDegree ,2*i,col);
|
|
115 |
else if( fType[i]==SATURATION ) saturation(sign(pointDegree),2*i,col);
|
|
116 |
else if( fType[i]==SMOOTH_SATURATION ) saturation( pointDegree ,2*i,col);
|
|
121 | 117 |
} |
122 | 118 |
#endif |
123 | 119 |
|
124 |
gl_FragColor = pixel*0.5*(v_Normal.z+1.0);
|
|
120 |
gl_FragColor = (col * 0.5 * (v_Normal.z+1.0) * texture2D(u_Texture, tex));
|
|
125 | 121 |
} |
Also available in: Unified diff
revert latest changes to the fragment shader.
small things in DistortedObjects.