Project

General

Profile

Download (18.5 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / main / EffectQueuePostprocess.java @ fe82a979

1 4c1dd6e9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 fe82a979 Leszek Koltunski
package org.distorted.library.main;
21 4c1dd6e9 Leszek Koltunski
22 c90b9e01 Leszek Koltunski
import android.content.res.Resources;
23 194ab46f Leszek Koltunski
import android.opengl.GLES30;
24 4c1dd6e9 Leszek Koltunski
25 fe82a979 Leszek Koltunski
import org.distorted.library.effect.Effect;
26
import org.distorted.library.effect.PostprocessEffect;
27 310e14fb leszek
import org.distorted.library.R;
28 4c1dd6e9 Leszek Koltunski
import org.distorted.library.message.EffectMessage;
29 8fa96e69 Leszek Koltunski
import org.distorted.library.program.DistortedProgram;
30 c90b9e01 Leszek Koltunski
import org.distorted.library.program.FragmentCompilationException;
31
import org.distorted.library.program.FragmentUniformsException;
32
import org.distorted.library.program.LinkingException;
33
import org.distorted.library.program.VertexCompilationException;
34
import org.distorted.library.program.VertexUniformsException;
35 310e14fb leszek
import org.distorted.library.type.Static;
36 4c1dd6e9 Leszek Koltunski
import org.distorted.library.type.Static1D;
37 310e14fb leszek
import org.distorted.library.type.Static2D;
38
import org.distorted.library.type.Static3D;
39 a31dbc5c Leszek Koltunski
import org.distorted.library.type.Static4D;
40 310e14fb leszek
import org.distorted.library.type.Static5D;
41 4c1dd6e9 Leszek Koltunski
42 c90b9e01 Leszek Koltunski
import java.io.InputStream;
43 8fa96e69 Leszek Koltunski
import java.nio.ByteBuffer;
44
import java.nio.ByteOrder;
45
import java.nio.FloatBuffer;
46
47 4c1dd6e9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
48
49
class EffectQueuePostprocess extends EffectQueue
50
  {
51 a31dbc5c Leszek Koltunski
  private static final int MAX_HALO = 50;    // Support effects creating up to MAX_HALO pixels wide 'halo' around the object.
52
53 9d5bb851 Leszek Koltunski
  private static final int POS_DATA_SIZE= 2; // Post Program: size of the position data in elements
54
  private static final int TEX_DATA_SIZE= 2; // Post Program: size of the texture coordinate data in elements.
55 8fa96e69 Leszek Koltunski
56 a31dbc5c Leszek Koltunski
  private static final int NUM_UNIFORMS = 5;
57 4c1dd6e9 Leszek Koltunski
  private static final int NUM_CACHE    = 0;
58 310e14fb leszek
  private static final int INDEX = Effect.POSTPROCESS;
59 4c1dd6e9 Leszek Koltunski
60 cf7394cc leszek
  private static final FloatBuffer mQuadPositions, mQuadTexture, mQuadTextureInv;
61 8fa96e69 Leszek Koltunski
62
  static
63
    {
64 667a1ad9 Leszek Koltunski
    int dataLength      = 4;
65
    int bytes_per_float = 4;
66 8fa96e69 Leszek Koltunski
67 1c67457f Leszek Koltunski
    float[] position  = { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
68
    float[] textureNor= {  0.0f,  0.0f,   0.0f, 1.0f,  1.0f, 0.0f,  1.0f, 1.0f };
69 cf7394cc leszek
    float[] textureInv= {  0.0f,  0.0f,   1.0f, 0.0f,  0.0f, 1.0f,  1.0f, 1.0f };
70 8fa96e69 Leszek Koltunski
71 9d5bb851 Leszek Koltunski
    mQuadPositions = ByteBuffer.allocateDirect(POS_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
72 1c67457f Leszek Koltunski
    mQuadPositions.put(position).position(0);
73 ed5bf324 Leszek Koltunski
    mQuadTexture= ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
74
    mQuadTexture.put(textureNor).position(0);
75 cf7394cc leszek
    mQuadTextureInv= ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*bytes_per_float).order(ByteOrder.nativeOrder()).asFloatBuffer();
76
    mQuadTextureInv.put(textureInv).position(0);
77 8fa96e69 Leszek Koltunski
    }
78 4c1dd6e9 Leszek Koltunski
79 a31dbc5c Leszek Koltunski
  int mQualityLevel;
80
  float mQualityScale;
81 fff1110e leszek
  private int mHalo;
82 a31dbc5c Leszek Koltunski
83
  /////////////////////////////////////////////////////////////////////////////////
84 0d81d0fb Leszek Koltunski
  // BLUR effect
85 ed841982 Leszek Koltunski
  private static final float GAUSSIAN[] =   // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
86
    {                                       // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates.
87
    0.398948f, 0.398769f, 0.398231f, 0.397336f, 0.396086f, 0.394485f, 0.392537f, 0.390247f, 0.387622f, 0.384668f,
88
    0.381393f, 0.377806f, 0.373916f, 0.369733f, 0.365268f, 0.360532f, 0.355538f, 0.350297f, 0.344823f, 0.339129f,
89
    0.333229f, 0.327138f, 0.320868f, 0.314436f, 0.307856f, 0.301142f, 0.294309f, 0.287373f, 0.280348f, 0.273248f,
90
    0.266089f, 0.258884f, 0.251648f, 0.244394f, 0.237135f, 0.229886f, 0.222657f, 0.215461f, 0.208311f, 0.201217f,
91
    0.194189f, 0.187238f, 0.180374f, 0.173605f, 0.166940f, 0.160386f, 0.153951f, 0.147641f, 0.141462f, 0.135420f,
92
    0.129520f, 0.123765f, 0.118159f, 0.112706f, 0.107408f, 0.102266f, 0.097284f, 0.092461f, 0.087797f, 0.083294f,
93
    0.078951f, 0.074767f, 0.070741f, 0.066872f, 0.063158f, 0.059596f, 0.056184f, 0.052920f, 0.049801f, 0.046823f,
94
    0.043984f, 0.041280f, 0.038707f, 0.036262f, 0.033941f, 0.031740f, 0.029655f, 0.027682f, 0.025817f, 0.024056f,
95
    0.022395f, 0.020830f, 0.019357f, 0.017971f, 0.016670f, 0.015450f, 0.014305f, 0.013234f, 0.012232f, 0.011295f,
96
    0.010421f, 0.009606f, 0.008847f, 0.008140f, 0.007483f, 0.006873f, 0.006307f, 0.005782f, 0.005296f, 0.004847f,
97
    0.004432f, 0.000000f
98
    };
99
  private static final int NUM_GAUSSIAN = GAUSSIAN.length-2;
100
101 464e53fa Leszek Koltunski
  // The (fixed-function-sampled) Gaussian Blur kernels are of the size k0=1, k1=2, k2=2, k3=3, k4=3, k5=4, k6=4,...
102 ed841982 Leszek Koltunski
  // i.e. k(i)=floor((i+3)/2).  (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
103
  // in all 4 directions)
104
  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
105 a31dbc5c Leszek Koltunski
  private static float[] weightsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
106
  private static float[] offsetsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
107 ed841982 Leszek Koltunski
108 f2367b75 Leszek Koltunski
  private static DistortedProgram mBlur1Program, mBlur2Program;
109 b7dba709 Leszek Koltunski
  private static int mRadius1H,mOffsets1H,mWeights1H,mDepth1H, mColorTexture1H;
110 7170e4eb leszek
  private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mColorTexture2H;
111 a31dbc5c Leszek Koltunski
  private static float[] mWeights = new float[MAX_HALO];
112
  private static float[] mOffsets = new float[MAX_HALO];
113
  /////////////////////////////////////////////////////////////////////////////////
114
  // GLOW effect
115 0d81d0fb Leszek Koltunski
116 8426bd6a Leszek Koltunski
117 4c1dd6e9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
118
119
  EffectQueuePostprocess(long id)
120
    { 
121
    super(id,NUM_UNIFORMS,NUM_CACHE,INDEX );
122 8426bd6a Leszek Koltunski
123 0ef8fafc Leszek Koltunski
    mQualityLevel = 0;
124
    mQualityScale = 1.0f;
125 4c1dd6e9 Leszek Koltunski
    }
126
127 c90b9e01 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
128
129
  static void createProgram(Resources resources)
130
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
131
    {
132 f2367b75 Leszek Koltunski
    final InputStream blur1VertexStream   = resources.openRawResource(R.raw.blur_vertex_shader);
133
    final InputStream blur1FragmentStream = resources.openRawResource(R.raw.blur1_fragment_shader);
134
135
    try
136
      {
137
      mBlur1Program = new DistortedProgram(blur1VertexStream,blur1FragmentStream,
138 94f6d472 Leszek Koltunski
                                          Distorted.GLSL_VERSION,
139 a31dbc5c Leszek Koltunski
                                          Distorted.GLSL_VERSION + "#define MAX_BLUR "+MAX_HALO, Distorted.GLSL);
140 f2367b75 Leszek Koltunski
      }
141
    catch(Exception e)
142
      {
143
      android.util.Log.e("EFFECTS", "exception trying to compile BLUR1 program: "+e.getMessage());
144
      throw new RuntimeException(e.getMessage());
145
      }
146
147
    int blur1ProgramH = mBlur1Program.getProgramHandle();
148
    mRadius1H       = GLES30.glGetUniformLocation( blur1ProgramH, "u_Radius");
149
    mOffsets1H      = GLES30.glGetUniformLocation( blur1ProgramH, "u_Offsets");
150
    mWeights1H      = GLES30.glGetUniformLocation( blur1ProgramH, "u_Weights");
151
    mDepth1H        = GLES30.glGetUniformLocation( blur1ProgramH, "u_Depth");
152
    mColorTexture1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_ColorTexture");
153
154
    final InputStream blur2VertexStream   = resources.openRawResource(R.raw.blur_vertex_shader);
155
    final InputStream blur2FragmentStream = resources.openRawResource(R.raw.blur2_fragment_shader);
156
157
    try
158
      {
159
      mBlur2Program = new DistortedProgram(blur2VertexStream,blur2FragmentStream,
160 94f6d472 Leszek Koltunski
                                          Distorted.GLSL_VERSION,
161 a31dbc5c Leszek Koltunski
                                          Distorted.GLSL_VERSION + "#define MAX_BLUR "+MAX_HALO, Distorted.GLSL);
162 f2367b75 Leszek Koltunski
      }
163
    catch(Exception e)
164
      {
165
      android.util.Log.e("EFFECTS", "exception trying to compile BLUR2 program: "+e.getMessage());
166 94f6d472 Leszek Koltunski
      // run anyway as compiling Blur2 WILL fail on OpenGL 2.0 contexts
167
      mBlur2Program = mBlur1Program;
168 f2367b75 Leszek Koltunski
      }
169
170
    int blur2ProgramH = mBlur2Program.getProgramHandle();
171
    mRadius2H       = GLES30.glGetUniformLocation( blur2ProgramH, "u_Radius");
172
    mOffsets2H      = GLES30.glGetUniformLocation( blur2ProgramH, "u_Offsets");
173
    mWeights2H      = GLES30.glGetUniformLocation( blur2ProgramH, "u_Weights");
174
    mDepth2H        = GLES30.glGetUniformLocation( blur2ProgramH, "u_Depth");
175
    mColorTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_ColorTexture");
176 4c1dd6e9 Leszek Koltunski
    }
177
178 60c1c622 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
179
180 a31dbc5c Leszek Koltunski
  private boolean compute(long currTime)
181 4c1dd6e9 Leszek Koltunski
    {
182 95c441a2 leszek
    if( currTime==mTime ) return false;
183 4c1dd6e9 Leszek Koltunski
    if( mTime==0 ) mTime = currTime;
184
    long step = (currTime-mTime);
185 e02264ff leszek
186 fff1110e leszek
    mHalo = 0;
187
    int halo;
188
189 4c1dd6e9 Leszek Koltunski
    for(int i=0; i<mNumEffects; i++)
190
      {
191 3a70bd6d leszek
      mCurrentDuration[i] += step;
192
193 4c1dd6e9 Leszek Koltunski
      if( mInter[0][i]!=null && mInter[0][i].interpolateMain(mUniforms ,NUM_UNIFORMS*i, mCurrentDuration[i], step) )
194
        {
195
        for(int j=0; j<mNumListeners; j++)
196
          EffectMessageSender.newMessage( mListeners.elementAt(j),
197
                                          EffectMessage.EFFECT_FINISHED,
198 310e14fb leszek
                                         (mID[i]<<Effect.LENGTH)+Effect.POSTPROCESS,
199 4c1dd6e9 Leszek Koltunski
                                          mName[i],
200
                                          mObjectID);
201
202 310e14fb leszek
        if( PostprocessEffect.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
203 4c1dd6e9 Leszek Koltunski
          {
204
          remove(i);
205
          i--;
206
          continue;
207
          }
208
        else mInter[0][i] = null;
209
        }
210 a31dbc5c Leszek Koltunski
211
      if( mInter[1][i]!=null ) mInter[1][i].interpolateMain( mUniforms, NUM_UNIFORMS*i+1, mCurrentDuration[i], step);
212 fff1110e leszek
213
      halo = (int)mUniforms[NUM_UNIFORMS*i];
214
      if( halo>mHalo ) mHalo = halo;
215 4c1dd6e9 Leszek Koltunski
      }
216 e02264ff leszek
217 95c441a2 leszek
    mTime = currTime;
218
219
    return true;
220 4c1dd6e9 Leszek Koltunski
    }  
221
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
224
  protected void moveEffect(int index)
225
    {
226
    mUniforms[NUM_UNIFORMS*index  ] = mUniforms[NUM_UNIFORMS*(index+1)  ];
227
    mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
228
    mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
229 667a1ad9 Leszek Koltunski
    mUniforms[NUM_UNIFORMS*index+3] = mUniforms[NUM_UNIFORMS*(index+1)+3];
230 a31dbc5c Leszek Koltunski
    mUniforms[NUM_UNIFORMS*index+4] = mUniforms[NUM_UNIFORMS*(index+1)+4];
231 4c1dd6e9 Leszek Koltunski
    }
232
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234 464e53fa Leszek Koltunski
// This implements the 'Better separable implementation using GPU fixed function sampling' from
235
// https://software.intel.com/en-us/blogs/2014/07/15/an-investigation-of-fast-real-time-gpu-based-image-blur-algorithms
236 4c1dd6e9 Leszek Koltunski
237 ed841982 Leszek Koltunski
  private void computeGaussianKernel(int radius)
238 4c1dd6e9 Leszek Koltunski
    {
239 ed841982 Leszek Koltunski
    int offset = radius + radius*radius/4;
240 0d81d0fb Leszek Koltunski
241 ed841982 Leszek Koltunski
    if( weightsCache[offset]==0.0f )
242 a225e5aa Leszek Koltunski
      {
243 ed841982 Leszek Koltunski
      float z, x= 0.0f, P= (float)NUM_GAUSSIAN / (radius>3 ? radius:3);
244
      mWeights[0] = GAUSSIAN[0];
245
      float sum   = GAUSSIAN[0];
246
      int j;
247 9d5bb851 Leszek Koltunski
248 ed841982 Leszek Koltunski
      for(int i=1; i<=radius; i++)
249
        {
250
        x += P;
251
        j = (int)x;
252
        z = x-j;
253 9d5bb851 Leszek Koltunski
254 ed841982 Leszek Koltunski
        mWeights[i] = (1-z)*GAUSSIAN[j] + z*GAUSSIAN[j+1];
255
        sum += 2*mWeights[i];
256
        }
257 9d5bb851 Leszek Koltunski
258 ed841982 Leszek Koltunski
      for(int i=0; i<=radius; i++) mWeights[i] /= sum;
259 a225e5aa Leszek Koltunski
260 ed841982 Leszek Koltunski
      int numloops = radius/2;
261
      weightsCache[offset] = mWeights[0];
262
      offsetsCache[offset] = 0.0f;
263
264
      for(int i=0; i<numloops; i++)
265
        {
266
        offsetsCache[offset+i+1] = mWeights[2*i+1]*(2*i+1) + mWeights[2*i+2]*(2*i+2);
267
        weightsCache[offset+i+1] = mWeights[2*i+1] + mWeights[2*i+2];
268
        offsetsCache[offset+i+1]/= weightsCache[offset+i+1];
269
        }
270
271
      if( radius%2 == 1 )
272
        {
273
        int index = offset + radius/2 +1;
274 fd2db957 Leszek Koltunski
        offsetsCache[index]=radius;
275 ed841982 Leszek Koltunski
        weightsCache[index]=mWeights[radius];
276
        }
277
      }
278 9d5bb851 Leszek Koltunski
    }
279
280 984dc935 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
281
282
  int getHalo()
283
    {
284 fff1110e leszek
    return mNumEffects>0 ? mHalo : 0;
285 984dc935 Leszek Koltunski
    }
286
287 9d5bb851 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
288
289 95c441a2 leszek
  int postprocess(long time, DistortedOutputSurface surface)
290 9d5bb851 Leszek Koltunski
    {
291 cf7394cc leszek
    int numRenders = 0;
292
293 e02264ff leszek
    if( mNumEffects>0 )
294 95c441a2 leszek
      {
295 e02264ff leszek
      compute(time);
296
297 cf7394cc leszek
      for(int i=0; i<mNumEffects; i++)
298
        {
299 310e14fb leszek
        if (mName[i] == PostprocessEffect.BLUR )
300 cf7394cc leszek
          {
301 a31dbc5c Leszek Koltunski
          blur(NUM_UNIFORMS*i,surface);
302
          numRenders += 2;
303
          }
304 310e14fb leszek
        else if (mName[i] == PostprocessEffect.GLOW )
305 a31dbc5c Leszek Koltunski
          {
306
          glow(NUM_UNIFORMS*i,surface);
307 cf7394cc leszek
          numRenders += 2;
308
          }
309
        }
310 95c441a2 leszek
      }
311 93dca704 Leszek Koltunski
312 cf7394cc leszek
    return numRenders;
313
    }
314
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316
317 a31dbc5c Leszek Koltunski
  private void blur(int index, DistortedOutputSurface surface)
318 cf7394cc leszek
    {
319
    DistortedFramebuffer buffer = surface.mBuffer[mQualityLevel];
320
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, buffer.mFBOH[0]);
321
322
    float w1 = buffer.mWidth;
323
    float h1 = buffer.mHeight;
324
325 a31dbc5c Leszek Koltunski
    int radius = (int)(mUniforms[index]*mQualityScale);
326
    if( radius>=MAX_HALO ) radius = MAX_HALO-1;
327 cf7394cc leszek
    computeGaussianKernel(radius);
328
329
    int offset = radius + radius*radius/4;
330
    radius = (radius+1)/2;
331
332
    // horizontal blur
333
    GLES30.glViewport(0, 0, (int)w1, (int)h1);
334
    mBlur1Program.useProgram();
335
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[1], 0);
336
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
337
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[0]);
338
339
    GLES30.glUniform1fv( mWeights1H, radius+1, weightsCache,offset);
340
    GLES30.glUniform1i( mRadius1H, radius);
341
    GLES30.glUniform1f( mDepth1H , 1.0f-surface.mNear);
342
    GLES30.glUniform1i( mColorTexture1H , 0 );
343
    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h1;
344
    GLES30.glUniform1fv( mOffsets1H ,radius+1, mOffsets,0);
345
    GLES30.glVertexAttribPointer(mBlur1Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
346
    GLES30.glVertexAttribPointer(mBlur1Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
347
348
    DistortedRenderState.useStencilMark();
349
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
350
    DistortedRenderState.unuseStencilMark();
351
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
352
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
353
354
    // vertical blur
355
    mBlur2Program.useProgram();
356
    GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[0], 0);
357
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
358
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[1]);
359
360
    GLES30.glColorMask(true,true,true,true);
361
    GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f);
362
    GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
363
364
    GLES30.glUniform1fv( mWeights2H, radius+1, weightsCache,offset);
365
    GLES30.glUniform1i( mRadius2H, radius);
366
    GLES30.glUniform1f( mDepth2H , 1.0f-surface.mNear);
367
    GLES30.glUniform1i( mColorTexture2H , 0 );
368
    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w1;
369
    GLES30.glUniform1fv( mOffsets2H ,radius+1, mOffsets,0);
370
    GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
371
    GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
372
373
    DistortedRenderState.useStencilMark();
374
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
375
    DistortedRenderState.unuseStencilMark();
376
    GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
377
    GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
378 d6e94c84 Leszek Koltunski
    }
379
380 a31dbc5c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
381
382
  private void glow(int index, DistortedOutputSurface surface)
383
    {
384
385
    }
386
387 4c1dd6e9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
388
389 310e14fb leszek
  synchronized long add(PostprocessEffect pe)
390 4c1dd6e9 Leszek Koltunski
    {
391
    if( mMax[INDEX]>mNumEffects )
392
      {
393 310e14fb leszek
      int dim0 = 0;
394
395
      if( pe.mDynamic0 != null )
396 4c1dd6e9 Leszek Koltunski
        {
397 310e14fb leszek
        mInter[0][mNumEffects] = pe.mDynamic0;
398
        dim0 = pe.mDynamic0.getDimension();
399 4c1dd6e9 Leszek Koltunski
        }
400 310e14fb leszek
      else
401 4c1dd6e9 Leszek Koltunski
        {
402
        mInter[0][mNumEffects] = null;
403 310e14fb leszek
404
        if( pe.mStatic0 != null )
405
          {
406
          Static s = pe.mStatic0;
407
          dim0 = s.getDimension();
408
409
          switch( dim0 )
410
            {
411
            case 5 : mUniforms[NUM_UNIFORMS*mNumEffects + 4] = ((Static5D)s).getV();
412
            case 4 : mUniforms[NUM_UNIFORMS*mNumEffects + 3] = ((Static4D)s).getW();
413
            case 3 : mUniforms[NUM_UNIFORMS*mNumEffects + 2] = ((Static3D)s).getZ();
414
            case 2 : mUniforms[NUM_UNIFORMS*mNumEffects + 1] = ((Static2D)s).getY();
415
            case 1 : mUniforms[NUM_UNIFORMS*mNumEffects    ] = ((Static1D)s).getX();
416
            }
417
          }
418 4c1dd6e9 Leszek Koltunski
        }
419
420 85cbbc5e Leszek Koltunski
      mInter[1][mNumEffects] = null;
421 a31dbc5c Leszek Koltunski
422 310e14fb leszek
      if( pe.mStatic1 != null )
423 a31dbc5c Leszek Koltunski
        {
424 310e14fb leszek
        Static s = pe.mStatic1;
425
        int dim1 = s.getDimension();
426 a31dbc5c Leszek Koltunski
427 310e14fb leszek
        switch( dim1 )
428
          {
429
          case 5 : mUniforms[NUM_UNIFORMS*mNumEffects + dim0 + 4] = ((Static5D)s).getV();
430
          case 4 : mUniforms[NUM_UNIFORMS*mNumEffects + dim0 + 3] = ((Static4D)s).getW();
431
          case 3 : mUniforms[NUM_UNIFORMS*mNumEffects + dim0 + 2] = ((Static3D)s).getZ();
432
          case 2 : mUniforms[NUM_UNIFORMS*mNumEffects + dim0 + 1] = ((Static2D)s).getY();
433
          case 1 : mUniforms[NUM_UNIFORMS*mNumEffects + dim0    ] = ((Static1D)s).getX();
434
          }
435 a31dbc5c Leszek Koltunski
        }
436
437 310e14fb leszek
      return addBase(pe);
438 a31dbc5c Leszek Koltunski
      }
439
440
    return -1;
441
    }
442 4c1dd6e9 Leszek Koltunski
  }