Project

General

Profile

« Previous | Next » 

Revision 9d5bb851

Added by Leszek Koltunski almost 8 years ago

minor.

View differences:

src/main/java/org/distorted/library/EffectQueuePostprocess.java
45 45
  {
46 46
  private static final int MAX_BLUR = 50;
47 47

  
48
  private static final int POSITION_DATA_SIZE= 2; // Post Program: size of the position data in elements
49
  private static final int TEX_DATA_SIZE     = 2; // Post Program: size of the texture coordinate data in elements.
48
  private static final int POS_DATA_SIZE= 2; // Post Program: size of the position data in elements
49
  private static final int TEX_DATA_SIZE= 2; // Post Program: size of the texture coordinate data in elements.
50 50

  
51 51
  private static final int NUM_UNIFORMS = 4;
52 52
  private static final int NUM_CACHE    = 0;
......
63 63
    float[] textureNor= {  0.0f,  0.0f,   0.0f, 1.0f,  1.0f, 0.0f,  1.0f, 1.0f };
64 64
    float[] textureInv= {  0.0f,  0.0f,   1.0f, 0.0f,  0.0f, 1.0f,  1.0f, 1.0f };
65 65

  
66
    mQuadPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
66
    mQuadPositions = ByteBuffer.allocateDirect(POS_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
67 67
    mQuadPositions.put(position).position(0);
68
    mQuadTextureNor  = ByteBuffer.allocateDirect(TEX_DATA_SIZE     *dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
68
    mQuadTextureNor= ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
69 69
    mQuadTextureNor.put(textureNor).position(0);
70
    mQuadTextureInv  = ByteBuffer.allocateDirect(TEX_DATA_SIZE     *dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
70
    mQuadTextureInv= ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
71 71
    mQuadTextureInv.put(textureInv).position(0);
72 72
    }
73 73

  
......
154 154
    }
155 155

  
156 156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
// w,h - width and height of the input texture. MVP - Model-View-Projection matrix to apply to the
158
// texture; df - output FBO.
159 157

  
160
  synchronized void render(float w, float h, float[] mvp, DistortedFramebuffer df)
158
  private int computeKernel(int radius, float height)
161 159
    {
162
    mBlurProgram.useProgram();
163

  
164
    int radius = (int)mUniforms[0];
165 160
    if( radius>=MAX_BLUR ) radius = MAX_BLUR-1;
166 161

  
167 162
    for(int i=0; i<=radius; i++)
168 163
      {
164
      // Box Blur size 'radius'
169 165
      mWeights[i] = 1.0f / (2.0f*radius+1.0f);
170
      mOffsets[i] = i/h;
166
      mOffsets[i] = i*height;
167

  
168
      // Gaussian Blur size 'radius'
169

  
170

  
171 171
      }
172 172

  
173
    return radius;
174
    }
175

  
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177
// w,h - width and height of the input texture. MVP - Model-View-Projection matrix to apply to the
178
// texture; df - output FBO.
179

  
180
  synchronized void render(float w, float h, float[] mvp, DistortedFramebuffer df)
181
    {
182
    mBlurProgram.useProgram();
183

  
184
    int radius = computeKernel( (int)mUniforms[0], 1/h );
185

  
173 186
    GLES30.glUniform1fv( mWeightsH, radius+1, mWeights,0);
174
    GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0);
175 187
    GLES30.glUniform1i( mRadiusH, radius);
176 188
    GLES30.glUniform2f( mObjDH , w, h );
177 189

  
......
184 196
    Matrix.multiplyMM(mMVPMatrix, 0, mBufferFBO.mProjectionMatrix, 0, mTmpMatrix, 0);
185 197

  
186 198
    // horizontal blur
187

  
199
    GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0);
188 200
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
189
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
190
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mQuadTextureInv);
201
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
202
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv);
191 203
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
192 204

  
193 205
    mBufferFBO.setAsInput();
......
200 212
    // vertical blur
201 213
    GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0);
202 214
    GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0);
203
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
204
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mQuadTextureInv);
215
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
216
    GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv);
205 217
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
206 218
    }
207 219

  
src/main/res/raw/blur_fragment_shader.glsl
31 31
  {
32 32
  vec4 pixel= texture2D(u_Texture,v_TexCoordinate) * u_Weights[0];
33 33

  
34
  for (int x = 1; x <= u_Radius; x+=1)
34
  for (int i=1; i<=u_Radius; i+=1)
35 35
    {
36
    pixel += ( texture2D(u_Texture,vec2(v_TexCoordinate.x+u_Offsets[x],v_TexCoordinate.y)) +
37
               texture2D(u_Texture,vec2(v_TexCoordinate.x-u_Offsets[x],v_TexCoordinate.y)) ) * u_Weights[x];
36
    pixel += ( texture2D(u_Texture,vec2(v_TexCoordinate.x+u_Offsets[i],v_TexCoordinate.y)) +
37
               texture2D(u_Texture,vec2(v_TexCoordinate.x-u_Offsets[i],v_TexCoordinate.y)) ) * u_Weights[i];
38 38
    }
39 39

  
40 40
  gl_FragColor = pixel;

Also available in: Unified diff