Project

General

Profile

« Previous | Next » 

Revision 42e08626

Added by Leszek Koltunski over 8 years ago

Remove the MACROBLOCK Effect altogether.

View differences:

src/main/java/org/distorted/library/DistortedObject.java
567 567

  
568 568
///////////////////////////////////////////////////////////////////////////////////////////////////
569 569
// Fragment-based effects  
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571
/**
572
 * Creates macroblocks at and around point defined by the Region.
573
 * 
574
 * @param size   1-dimensional Dynamic which, at any given time, returns the size of the macroblocks.
575
 * @param region Region this Effect is limited to.
576
 * @return       ID of the effect added, or -1 if we failed to add one.
577
 */
578
  public long macroblock(Data1D size, Data4D region)
579
    {
580
    return mF.add(EffectNames.MACROBLOCK, size, region);
581
    }
582

  
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584
/**
585
 * Creates macroblocks on the whole Object.
586
 *
587
 * @param size   1-dimensional Data which, at any given time, returns the size of the macroblocks.
588
 * @return       ID of the effect added, or -1 if we failed to add one.
589
 */
590
  public long macroblock(Data1D size)
591
    {
592
    return mF.add(EffectNames.MACROBLOCK, size);
593
    }
594

  
595 570
///////////////////////////////////////////////////////////////////////////////////////////////////
596 571
/**
597 572
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
src/main/java/org/distorted/library/EffectNames.java
120 120
 /////////////////////////////////////////////////////////////////////////////////
121 121
 // FRAGMENT EFFECTS
122 122
 // Always 8 Uniforms: 4-per effect interpolated values, 4 dimensional Region.
123
 /**
124
   * Create square-shaped macroblocks.
125
   * <p>
126
   * Uniforms: (macroblockSize,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
127
   * Unity: macroblockSize = 1
128
   */
129
  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
130 123
 /**
131 124
   * Make a given Region (partially) transparent.
132 125
   * <p>
src/main/java/org/distorted/library/EffectQueueFragment.java
141 141
///////////////////////////////////////////////////////////////////////////////////////////////////
142 142
// Do various post-processing on already computed effects.
143 143
// 1) move all Points and scale all Region radii by a ModelView matrix
144
// 2) in case of macroblock, pre-compute some values so that we don't have to do it in the fragment shader.
145
  
144

  
146 145
  void postprocess(float[] MVmatrix)
147 146
    {
148 147
    if( mNumEffects>0 )
......
160 159
        mUniforms[NUM_UNIFORMS*i+5] = MVmatrix[1]*tx + MVmatrix[5]*ty + MVmatrix[13]; //
161 160
        mUniforms[NUM_UNIFORMS*i+6] = w*mBuf[4*i+2];                                  // in fragment shader rx and ry radii are the last two values of the second vec4
162 161
        mUniforms[NUM_UNIFORMS*i+7] = h*mBuf[4*i+3];                                  //
163

  
164
        if( mName[i]==EffectNames.MACROBLOCK.ordinal() ) // fill up the .y and .z components of the Interpolated values already to avoid having to compute this in the fragment shader
165
          {
166
          mUniforms[NUM_UNIFORMS*i+1] = 2.0f*mObjHalfX/mUniforms[NUM_UNIFORMS*i];
167
          mUniforms[NUM_UNIFORMS*i+2] = 2.0f*mObjHalfY/mUniforms[NUM_UNIFORMS*i];
168
          }
169 162
        }
170 163
      }
171 164
    }
172 165
  
173 166
///////////////////////////////////////////////////////////////////////////////////////////////////
174
// macroblock, alpha, brightness, contrast, saturation
167
// alpha, brightness, contrast, saturation
175 168

  
176 169
  synchronized long add(EffectNames eln, Data1D data)
177 170
    {
......
201 194
    }
202 195
  
203 196
///////////////////////////////////////////////////////////////////////////////////////////////////
204
// macroblock, alpha, brightness, contrast, saturation
197
// alpha, brightness, contrast, saturation
205 198

  
206 199
  synchronized long add(EffectNames eln, Data1D data, Data4D region)
207 200
    {
src/main/res/raw/main_fragment_shader.glsl
33 33
                                        // next describes the Region, i.e. area over which the effect is active.
34 34

  
35 35
const vec3 LUMI = vec3( 0.2125, 0.7154, 0.0721 );                                        
36
 
37
//////////////////////////////////////////////////////////////////////////////////////////////
38
// MACROBLOCK EFFECT
39

  
40
void macroblock(float degree, int effect, inout vec2 tex)
41
  {
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;
45
  }
46 36

  
47 37
//////////////////////////////////////////////////////////////////////////////////////////////
48 38
// CHROMA EFFECT
......
91 81

  
92 82
void main()                    		
93 83
  {  
94
  vec2 tex = v_TexCoordinate;
95
  vec4 col = texture2D(u_Texture, tex);
84
  vec4 pixel = texture2D(u_Texture,v_TexCoordinate);
96 85

  
97 86
#if NUM_FRAGMENT>0
98 87
  vec2 diff;
......
103 92
    diff = (v_Position.xy - fUniforms[2*i+1].xy)/fUniforms[2*i+1].zw;
104 93
    pointDegree = max(0.0,1.0-dot(diff,diff));
105 94

  
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);
95
         if( fType[i]==CHROMA            ) chroma    (sign(pointDegree),2*i,pixel);
96
    else if( fType[i]==SMOOTH_CHROMA     ) chroma    (     pointDegree ,2*i,pixel);
97
    else if( fType[i]==ALPHA             ) alpha     (sign(pointDegree),2*i,pixel);
98
    else if( fType[i]==SMOOTH_ALPHA      ) alpha     (     pointDegree ,2*i,pixel);
99
    else if( fType[i]==BRIGHTNESS        ) brightness(sign(pointDegree),2*i,pixel);
100
    else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness(     pointDegree ,2*i,pixel);
101
    else if( fType[i]==CONTRAST          ) contrast  (sign(pointDegree),2*i,pixel);
102
    else if( fType[i]==SMOOTH_CONTRAST   ) contrast  (     pointDegree ,2*i,pixel);
103
    else if( fType[i]==SATURATION        ) saturation(sign(pointDegree),2*i,pixel);
104
    else if( fType[i]==SMOOTH_SATURATION ) saturation(     pointDegree ,2*i,pixel);
117 105
    }
118 106
#endif
119 107

  
120
  gl_FragColor = vec4(col.rgb * 0.5 * (v_Normal.z+1.0), col.a);
108
  gl_FragColor = vec4(pixel.rgb * 0.5 * (v_Normal.z+1.0), pixel.a);
121 109
  }

Also available in: Unified diff