Project

General

Profile

« Previous | Next » 

Revision 4018b3b7

Added by Leszek Koltunski over 8 years ago

fix fragment effects :)

View differences:

src/main/res/raw/main_fragment_shader.glsl
33 33
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,
34 34
                                        // next describes the Region, i.e. area over which the effect is active.
35 35

  
36
const vec3 LUMI = vec3( 0.2125, 0.7154, 0.0721 );                                        
37
 
36
const vec3 LUMI3= vec3( 0.2125, 0.7154, 0.0721 );
37
const vec3 ZERO3= vec3(0.0,0.0,0.0);
38
const vec3 HALF3= vec3(0.5,0.5,0.5);
39
const vec2 ONE2 = vec2(1.0,1.0);
40
const vec2 HALF2= vec2(0.5,0.5);
41

  
38 42
//////////////////////////////////////////////////////////////////////////////////////////////
39 43
// MACROBLOCK EFFECT
40 44

  
41
void macroblock(float degree, int effect, inout vec2 tex)
45
void macroblock(float degree, int effect, inout vec4 pixel)
42 46
  {
43
  vec2 one = vec2(1.0,1.0);  
44
  vec2 a = degree*(fUniforms[effect].yz-one)+one;
45
  tex = ( max((1.0-degree)*tex,floor(tex*a)) + degree*vec2(0.5,0.5) ) / a;
47
  vec2 a = degree*(fUniforms[effect].yz-ONE2)+ONE2;
48
  vec2 tex = ( max((1.0-degree)*v_TexCoordinate,floor(v_TexCoordinate*a)) + degree*HALF2 ) / a;
49

  
50
  pixel = texture2D(u_Texture, tex);
46 51
  }
47 52

  
48 53
//////////////////////////////////////////////////////////////////////////////////////////////
49 54
// CHROMA EFFECT
50 55

  
51
void chroma(float degree, int effect, inout vec4 color)
56
void chroma(float degree, int effect, inout vec4 pixel)
52 57
  {
53
  color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
58
  pixel = vec4( mix( pixel.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x), pixel.a);
54 59
  }
55 60

  
56 61
//////////////////////////////////////////////////////////////////////////////////////////////
57 62
// ALPHA EFFECT (change transparency level)
58 63

  
59
void alpha(float degree, int effect, inout vec4 color)
64
void alpha(float degree, int effect, inout vec4 pixel)
60 65
  {
61
  color.a *= (degree*(fUniforms[effect].x-1.0)+1.0); 
66
  pixel.a *= (degree*(fUniforms[effect].x-1.0)+1.0);
62 67
  }
63 68

  
64 69
//////////////////////////////////////////////////////////////////////////////////////////////
65 70
// BRIGHTNESS EFFECT
66 71

  
67
void brightness(float degree, int effect, inout vec4 color)
72
void brightness(float degree, int effect, inout vec4 pixel)
68 73
  {
69
  color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
74
  pixel.rgb = mix(ZERO3, pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
70 75
  }
71
  
76

  
72 77
//////////////////////////////////////////////////////////////////////////////////////////////
73 78
// CONTRAST EFFECT
74 79

  
75
void contrast(float degree, int effect, inout vec4 color)
80
void contrast(float degree, int effect, inout vec4 pixel)
76 81
  {
77
  color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
82
  pixel.rgb = mix(HALF3, pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
78 83
  }
79 84

  
80 85
//////////////////////////////////////////////////////////////////////////////////////////////
81 86
// SATURATION EFFECT
82 87

  
83
void saturation(float degree, int effect, inout vec4 color)
88
void saturation(float degree, int effect, inout vec4 pixel)
84 89
  {
85
  float luminance = dot(LUMI,color.rgb);
86
  color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); 
90
  float luminance = dot(LUMI3,pixel.rgb);
91
  pixel.rgb = mix(vec3(luminance,luminance,luminance), pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
87 92
  }
88 93

  
89 94
#endif
......
92 97

  
93 98
void main()                    		
94 99
  {  
95
  vec2 tex = v_TexCoordinate;
96
  vec4 col = vec4(1.0,1.0,1.0,1.0);
100
  vec4 pixel = texture2D(u_Texture, v_TexCoordinate);
101

  
102
#if NUM_FRAGMENT>0
97 103
  vec2 diff;
98 104
  float pointDegree;
99
  
100
#if NUM_FRAGMENT>0  
105

  
101 106
  for(int i=0; i<fNumEffects; i++)
102 107
    {
103 108
    diff = (v_Position.xy - fUniforms[2*i+1].xy)/fUniforms[2*i+1].zw;
104 109
    pointDegree = max(0.0,1.0-dot(diff,diff));
105 110

  
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);
111
         if( fType[i]==MACROBLOCK        ) macroblock(sign(pointDegree),2*i, pixel);
112
    else if( fType[i]==CHROMA            ) chroma    (sign(pointDegree),2*i, pixel);
113
    else if( fType[i]==SMOOTH_CHROMA     ) chroma    (     pointDegree ,2*i, pixel);
114
    else if( fType[i]==ALPHA             ) alpha     (sign(pointDegree),2*i, pixel);
115
    else if( fType[i]==SMOOTH_ALPHA      ) alpha     (     pointDegree ,2*i, pixel);
116
    else if( fType[i]==BRIGHTNESS        ) brightness(sign(pointDegree),2*i, pixel);
117
    else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness(     pointDegree ,2*i, pixel);
118
    else if( fType[i]==CONTRAST          ) contrast  (sign(pointDegree),2*i, pixel);
119
    else if( fType[i]==SMOOTH_CONTRAST   ) contrast  (     pointDegree ,2*i, pixel);
120
    else if( fType[i]==SATURATION        ) saturation(sign(pointDegree),2*i, pixel);
121
    else if( fType[i]==SMOOTH_SATURATION ) saturation(     pointDegree ,2*i, pixel);
117 122
    }
118 123
#endif
119 124
 
120
  gl_FragColor = (col * 0.5 * (v_Normal.z+1.0) * texture2D(u_Texture, tex));
125
  gl_FragColor = pixel*0.5*(v_Normal.z+1.0);
121 126
  }

Also available in: Unified diff