Project

General

Profile

« Previous | Next » 

Revision 667a1ad9

Added by Leszek Koltunski almost 8 years ago

improve Postprocessing; new icon; minor things.

View differences:

src/main/java/org/distorted/library/EffectNames.java
241 241

  
242 242
  /////////////////////////////////////////////////////////////////////////////////
243 243
  // POSTPROCESSING EFFECTS.
244
  // Always 1 Uniform: 1 per-effect interpolated value.
244
  // Always 4 Uniforms: 4 per-effect interpolated values.
245 245
 /**
246 246
   * Blur the area around the center.
247 247
   * <p>
248
   * Uniforms: (radius)
248
   * Uniforms: (radius,UNUSED,UNUSED,UNUSED)
249 249
   * <p>
250
   * Unity: radius==0
250
   * Unity: radius = 0
251 251
   */
252 252
  BLUR             ( EffectTypes.POSTPROCESS,new float[] {0.0f}          , 1, false, false );
253 253

  
src/main/java/org/distorted/library/EffectQueueFragment.java
127 127
        mUniforms[NUM_UNIFORMS*i+7] = mCache[NUM_CACHE*i+3];
128 128
        }
129 129

  
130
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName    ,0);
131
      GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
130
      GLES20.glUniform1iv( mTypeH    ,                 mNumEffects, mName    ,0);
131
      GLES20.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
132 132
      }  
133 133
    }
134 134

  
src/main/java/org/distorted/library/EffectQueuePostprocess.java
42 42

  
43 43
class EffectQueuePostprocess extends EffectQueue
44 44
  {
45
  private static final int BYTES_PER_FLOAT   = 4;
46 45
  private static final int POSITION_DATA_SIZE= 2; // Post Program: size of the position data in elements
47 46
  private static final int TEX_DATA_SIZE     = 2; // Post Program: size of the texture coordinate data in elements.
48 47

  
49
  private static final int NUM_UNIFORMS = 3;
48
  private static final int NUM_UNIFORMS = 4;
50 49
  private static final int NUM_CACHE    = 0;
51 50
  private static final int INDEX = EffectTypes.POSTPROCESS.ordinal();
52 51

  
......
61 60

  
62 61
  static
63 62
    {
64
    int dataLength = 4;
63
    int dataLength      = 4;
64
    int bytes_per_float = 4;
65 65

  
66 66
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
67 67
    float[] textureData = {  0.0f,  0.0f,   0.0f, 1.0f,  1.0f, 0.0f,  1.0f, 1.0f };
68 68

  
69
    mQuadPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
69
    mQuadPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
70 70
    mQuadPositions.put(positionData).position(0);
71
    mQuadTexture   = ByteBuffer.allocateDirect(TEX_DATA_SIZE     *dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
71
    mQuadTexture   = ByteBuffer.allocateDirect(TEX_DATA_SIZE     *dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
72 72
    mQuadTexture.put(textureData).position(0);
73 73
    }
74 74

  
......
140 140
        else mInter[0][i] = null;
141 141
        }
142 142

  
143
      if( mInter[1][i]!=null )
144
        {
145
        mInter[1][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+1, mCurrentDuration[i], step);
146
        }
147

  
148 143
      mCurrentDuration[i] += step;
149 144
      }
150 145
     
......
158 153
    mUniforms[NUM_UNIFORMS*index  ] = mUniforms[NUM_UNIFORMS*(index+1)  ];
159 154
    mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
160 155
    mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
156
    mUniforms[NUM_UNIFORMS*index+3] = mUniforms[NUM_UNIFORMS*(index+1)+3];
161 157
    }
162 158

  
163 159
///////////////////////////////////////////////////////////////////////////////////////////////////
......
184 180

  
185 181
    if( mNumEffects>0 )
186 182
      {
187
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName    ,0);
188
      GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
183
      GLES20.glUniform1iv( mTypeH    ,                  mNumEffects, mName    ,0);
184
      GLES20.glUniform4fv( mUniformsH, (NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
189 185
      }
190 186

  
191 187
    GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
src/main/java/org/distorted/library/EffectQueueVertex.java
146 146
        mUniforms[NUM_UNIFORMS*i+7] = mCache[NUM_CACHE*i+2]-halfZ;
147 147
        }
148 148

  
149
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName    ,0);
150
      GLES20.glUniform4fv( mUniformsH,3*mNumEffects, mUniforms,0);
149
      GLES20.glUniform1iv( mTypeH    ,                 mNumEffects, mName    ,0);
150
      GLES20.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
151 151
      }
152 152
    }
153 153

  
src/main/res/raw/post_fragment_shader.glsl
22 22
varying vec2 v_TexCoordinate;
23 23
uniform sampler2D u_Texture;
24 24
uniform vec2 u_objD;
25
uniform int pNumEffects;                   // total number of postprocessing effects
25
uniform int pNumEffects;                 // total number of postprocessing effects
26 26

  
27 27
#if NUM_POSTPROCESS>0
28
uniform int pType[NUM_POSTPROCESS];        // their types.
29
uniform vec4 pUniforms[2*NUM_POSTPROCESS]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1].
28
uniform int pType[NUM_POSTPROCESS];      // their types.
29
uniform vec4 pUniforms[NUM_POSTPROCESS]; // i-th effect is 1 vec4: [i].
30 30

  
31 31
//////////////////////////////////////////////////////////////////////////////////////////////
32 32
// BLUR EFFECT
33 33

  
34
void blur(out vec4 pixel)
34
void blur(out vec4 pixel,float radius)
35 35
  {
36 36
  pixel = vec4(0.0);
37 37

  
38 38
  float blurSizeH = 1.0 / u_objD.x;
39 39
  float blurSizeV = 1.0 / u_objD.y;
40
  float denom     = 1.0 / ((2.0*radius+1.0)*(2.0*radius+1.0));
40 41

  
41
  for (float x = -4.0; x <= 4.0; x+=1.0)
42
    for (float y = -4.0; y <= 4.0; y+=1.0)
42
  for (float x = -radius; x <= radius; x+=1.0)
43
    for (float y = -radius; y <= radius; y+=1.0)
43 44
      {
44
      pixel += texture2D( u_Texture, vec2(v_TexCoordinate.x + x * blurSizeH, v_TexCoordinate.y + y * blurSizeV) ) / 81.0;
45
      pixel += texture2D( u_Texture, vec2(v_TexCoordinate.x + x*blurSizeH, v_TexCoordinate.y + y*blurSizeV) ) *denom;
45 46
      }
46 47
  }
47 48

  
......
56 57
#if NUM_POSTPROCESS>0
57 58
  for(int i=0; i<pNumEffects; i++)
58 59
    {
59
    if( pType[i]==BLUR ) blur(pixel);
60
    if( pType[i]==BLUR ) blur(pixel,pUniforms[i].x);
60 61
    }
61 62
#endif
62 63

  

Also available in: Unified diff