Project

General

Profile

« Previous | Next » 

Revision 9e771d06

Added by Leszek Koltunski almost 6 years ago

Progress with thr Glow effect - moving glow app looks ok now.

View differences:

src/main/java/org/distorted/library/effect/PostprocessEffect.java
19 19

  
20 20
package org.distorted.library.effect;
21 21

  
22
import org.distorted.library.main.DistortedFramebuffer;
22 23
import org.distorted.library.main.DistortedMaster;
23
import org.distorted.library.main.DistortedOutputSurface;
24 24
import org.distorted.library.program.DistortedProgram;
25 25

  
26 26
import java.nio.ByteBuffer;
......
139 139
 *
140 140
 * @y.exclude
141 141
 */
142
  public abstract int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers);
142
  public abstract int apply(float[] uniforms, int index, DistortedFramebuffer buffer);
143 143

  
144 144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
/**
146
 * Only for use by the library itself.
147
 *
148
 * @y.exclude
149
 */
150
  public abstract int getQuality();
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
/**
154
 * Only for use by the library itself.
155
 *
156
 * @y.exclude
157
 */
158
  public int getInternalQuality()
159
    {
160
    return mQualityLevel;
161
    }
145
  /**
146
   * Only for use by the library itself.
147
   *
148
   * @y.exclude
149
   */
150
  public abstract boolean getRender();
162 151

  
163 152
///////////////////////////////////////////////////////////////////////////////////////////////////
164 153
  /**
......
166 155
   *
167 156
   * @y.exclude
168 157
   */
169
  public int getWriteColor()
158
  public int getQuality()
170 159
    {
171
    return 0;
160
    return mQualityLevel;
172 161
    }
173 162

  
174 163
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
125 125
    }
126 126

  
127 127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
/**
129
 * Only for use by the library itself.
130
 *
131
 * @y.exclude
132
 */
133
  public int getQuality()
134
   {
135
   return mQualityLevel;
136
   }
128
  /**
129
   * Only for use by the library itself.
130
   *
131
   * @y.exclude
132
   */
133
  public boolean getRender()
134
    {
135
    return false;
136
    }
137 137

  
138 138
///////////////////////////////////////////////////////////////////////////////////////////////////
139 139
/**
......
141 141
 *
142 142
 * @y.exclude
143 143
 */
144
  public int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers)
144
  public int apply(float[] uniforms, int index, DistortedFramebuffer buffer)
145 145
    {
146 146
    if( mProgram1 ==null)
147 147
      {
......
158 158

  
159 159
    DistortedRenderState.useStencilMark();
160 160

  
161
    DistortedFramebuffer buffer = (DistortedFramebuffer)buffers[mQualityLevel];
162

  
163 161
    buffer.setAsOutput();
164 162

  
165 163
    float w= buffer.getWidth();
src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
22 22
import android.opengl.GLES31;
23 23

  
24 24
import org.distorted.library.main.Distorted;
25
import org.distorted.library.main.DistortedEffects;
26 25
import org.distorted.library.main.DistortedFramebuffer;
27
import org.distorted.library.main.DistortedOutputSurface;
28 26
import org.distorted.library.main.DistortedRenderState;
29 27
import org.distorted.library.program.DistortedProgram;
30 28
import org.distorted.library.type.Data1D;
......
129 127
    }
130 128

  
131 129
///////////////////////////////////////////////////////////////////////////////////////////////////
132
/**
133
 * Only for use by the library itself.
134
 *
135
 * @y.exclude
136
 */
137
  public int getQuality()
138
   {
139
   return 0;
140
   }
130
  /**
131
   * Only for use by the library itself.
132
   *
133
   * @y.exclude
134
   */
135
  public boolean getRender()
136
    {
137
    return true;
138
    }
141 139

  
142 140
///////////////////////////////////////////////////////////////////////////////////////////////////
143 141
/**
......
145 143
 *
146 144
 * @y.exclude
147 145
 */
148
  public int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers)
146
  public int apply(float[] uniforms, int index, DistortedFramebuffer buffer)
149 147
    {
150 148
    if( mProgram1 ==null)
151 149
      {
......
162 160

  
163 161
    DistortedRenderState.useStencilMark();
164 162

  
165
    DistortedFramebuffer  inBuffer = (DistortedFramebuffer)buffers[0];
166
    DistortedFramebuffer outBuffer = (DistortedFramebuffer)buffers[mQualityLevel];
163
    buffer.setAsOutput();
167 164

  
168
    float w= outBuffer.getWidth();
169
    float h= outBuffer.getHeight();
170
    float n= 1.0f - outBuffer.getNear();
165
    float w= buffer.getWidth();
166
    float h= buffer.getHeight();
167
    float n= 1.0f - buffer.getNear();
171 168

  
172
    float corrW = inBuffer.getWidthCorrection();
173
    float corrH = inBuffer.getHeightCorrection();
169
    float corrW = buffer.getWidthCorrection();
170
    float corrH = buffer.getHeightCorrection();
174 171
    float offsetCorrW = corrW/w;
175 172
    float offsetCorrH = corrH/h;
176 173

  
......
180 177

  
181 178
    int offset = radius + radius*radius/4;
182 179
    radius = (radius+1)/2;
183

  
184 180
    GLES31.glViewport(0, 0, (int)w, (int)h);
185 181

  
186
    // horizontal glow
182
    // horizontal blur
187 183
    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrW;
188 184

  
189 185
    mProgram1.useProgram();
190
    outBuffer.setAsOutput();
191
    outBuffer.bindForOutput(1);
192
    inBuffer.setAsInput(0);
186
    buffer.bindForOutput(1);
187
    buffer.setAsInput(0);
193 188

  
194 189
    GLES31.glColorMask(true,true,true,true);
195 190
    GLES31.glClearColor(1.0f,1.0f,1.0f,0.0f);
......
201 196
    GLES31.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
202 197
    GLES31.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
203 198
    GLES31.glUniform1i ( mProgram1.mUniform[5] , radius);
204
    GLES31.glUniform4f ( mProgram1.mUniform[6] , uniforms[index+1], uniforms[index+2], uniforms[index+3], uniforms[index+4]);
205 199
    GLES31.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadPositions);
206 200
    GLES31.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadTexture);
207 201
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
208 202

  
209
    // vertical glow
203
    // vertical blur
210 204
    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrH;
211 205

  
212 206
    mProgram2.useProgram();
213
    outBuffer.bindForOutput(0);
214
    outBuffer.setAsInput(1);
207
    buffer.bindForOutput(0);
208
    buffer.setAsInput(1);
215 209

  
216
    if( mQualityLevel==0 )
217
      {
218
      GLES31.glEnable(GLES31.GL_BLEND);
219
      }
210
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
220 211

  
221 212
    GLES31.glUniform1f ( mProgram2.mUniform[0] , n );
222 213
    GLES31.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
......
224 215
    GLES31.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
225 216
    GLES31.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
226 217
    GLES31.glUniform1i ( mProgram2.mUniform[5] , radius);
227
    GLES31.glUniform4f ( mProgram1.mUniform[6] , uniforms[index+1], uniforms[index+2], uniforms[index+3], uniforms[index+4]);
228 218
    GLES31.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadPositions);
229 219
    GLES31.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadTexture);
230 220
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
231 221

  
232
    if( mQualityLevel==0 )
233
      {
234
      GLES31.glDisable(GLES31.GL_BLEND);
235
      }
236

  
237 222
    DistortedRenderState.unuseStencilMark();
238 223

  
239
    // blit back to inBuffer if we have to
240
    if( mQualityLevel>0 )
241
      {
242
      inBuffer.setAsOutput();
243
      inBuffer.bindForOutput(0);
244
      outBuffer.setAsInput(0);
245
      GLES31.glEnable(GLES31.GL_BLEND);
246
      DistortedEffects.blitPriv(inBuffer);
247
      GLES31.glDisable(GLES31.GL_BLEND);
248
      return 3;
249
      }
250

  
251 224
    return 2;
252 225
    }
253 226

  
......
262 235
    final String glowVertex =
263 236

  
264 237
        Distorted.GLSL_VERSION   +
265
      "precision lowp float;  \n"+
266
      "in vec2 a_Position;    \n"+
267
      "in vec2 a_TexCoord;    \n"+
268
      "out vec2 v_TexCoord;   \n"+
269
      "uniform float u_Depth; \n"+
270
      "uniform vec2 u_TexCorr;\n"+
271

  
272
      "void main()                                      \n"+
273
      "  {                                              \n"+
274
      "  v_TexCoord = a_TexCoord * u_TexCorr;           \n"+
275
      "  gl_Position= vec4(2.0*a_Position,u_Depth,1.0); \n"+
276
      "  }";
238
            "precision lowp float;  \n"+
239
            "in vec2 a_Position;    \n"+
240
            "in vec2 a_TexCoord;    \n"+
241
            "out vec2 v_TexCoord;   \n"+
242
            "uniform float u_Depth; \n"+
243
            "uniform vec2 u_TexCorr;\n"+
244

  
245
            "void main()                                      \n"+
246
            "  {                                              \n"+
247
            "  v_TexCoord = a_TexCoord * u_TexCorr;           \n"+
248
            "  gl_Position= vec4(2.0*a_Position,u_Depth,1.0); \n"+
249
            "  }";
277 250

  
278 251
    final String glowFragment1 =
279 252

  
280 253
        Distorted.GLSL_VERSION               +
281
      "#define MAX_BLUR "+MAX_HALO+      "\n"+
282
      "precision lowp float;              \n"+
283
      "in vec2 v_TexCoord;                \n"+
284
      "out vec4 fragColor;                \n"+
285
      "uniform sampler2D u_ColorTexture;  \n"+
286
      "uniform float u_Offsets[MAX_BLUR]; \n"+
287
      "uniform float u_Weights[MAX_BLUR]; \n"+
288
      "uniform int u_Radius;              \n"+
289
      "uniform vec4 u_Color;              \n"+
290

  
291
      "void main()                                                                                           \n"+
292
      "  {                                                                                                   \n"+
293
      "  vec4 pixel = texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                     \n"+
294
      "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
295
      "    {                                                                                                 \n"+
296
      "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x+u_Offsets[i],v_TexCoord.y)) +                 \n"+
297
      "               texture(u_ColorTexture,vec2(v_TexCoord.x-u_Offsets[i],v_TexCoord.y)) ) * u_Weights[i]; \n"+
298
      "    }                                                                                                 \n"+
299
      "  fragColor = vec4( 0.5*(pixel.rgb+u_Color.rgb), sqrt(pixel.a*u_Color.a));                            \n"+
300
      "  }";
254
            "#define MAX_BLUR "+MAX_HALO+      "\n"+
255
            "precision lowp float;              \n"+
256
            "in vec2 v_TexCoord;                \n"+
257
            "out vec4 fragColor;                \n"+
258
            "uniform sampler2D u_ColorTexture;  \n"+
259
            "uniform float u_Offsets[MAX_BLUR]; \n"+
260
            "uniform float u_Weights[MAX_BLUR]; \n"+
261
            "uniform int u_Radius;              \n"+
262

  
263
            "void main()                                                                                           \n"+
264
            "  {                                                                                                   \n"+
265
            "  vec4 pixel= texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                      \n"+
266
            "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
267
            "    {                                                                                                 \n"+
268
            "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x+u_Offsets[i],v_TexCoord.y)) +                 \n"+
269
            "               texture(u_ColorTexture,vec2(v_TexCoord.x-u_Offsets[i],v_TexCoord.y)) ) * u_Weights[i]; \n"+
270
            "    }                                                                                                 \n"+
271
            "  fragColor = pixel;                                                                                  \n"+
272
            "  }";
301 273

  
302 274
    final String glowFragment2 =
303 275

  
304 276
        Distorted.GLSL_VERSION               +
305
      "#define MAX_BLUR "+MAX_HALO+      "\n"+
306
      "precision lowp float;              \n"+
307
      "in vec2 v_TexCoord;                \n"+
308
      "out vec4 fragColor;                \n"+
309
      "uniform sampler2D u_ColorTexture;  \n"+
310
      "uniform float u_Offsets[MAX_BLUR]; \n"+
311
      "uniform float u_Weights[MAX_BLUR]; \n"+
312
      "uniform int u_Radius;              \n"+
313
      "uniform vec4 u_Color;              \n"+
314

  
315
      "void main()                                                                                           \n"+
316
      "  {                                                                                                   \n"+
317
      "  vec4 pixel = texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                     \n"+
318
      "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
319
      "    {                                                                                                 \n"+
320
      "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y+u_Offsets[i])) +                 \n"+
321
      "               texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y-u_Offsets[i])) ) * u_Weights[i]; \n"+
322
      "    }                                                                                                 \n"+
323
      "  fragColor = vec4( 0.5*(pixel.rgb+u_Color.rgb), sqrt(pixel.a*u_Color.a));                            \n"+
324
      "  }";
277
            "#define MAX_BLUR "+MAX_HALO+      "\n"+
278
            "precision lowp float;              \n"+
279
            "in vec2 v_TexCoord;                \n"+
280
            "out vec4 fragColor;                \n"+
281
            "uniform sampler2D u_ColorTexture;  \n"+
282
            "uniform float u_Offsets[MAX_BLUR]; \n"+
283
            "uniform float u_Weights[MAX_BLUR]; \n"+
284
            "uniform int u_Radius;              \n"+
285

  
286
            "void main()                                                                                           \n"+
287
            "  {                                                                                                   \n"+
288
            "  vec4 pixel= texture(u_ColorTexture,v_TexCoord) * u_Weights[0];                                      \n"+
289
            "  for (int i=1; i<=u_Radius; i+=1)                                                                    \n"+
290
            "    {                                                                                                 \n"+
291
            "    pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y+u_Offsets[i])) +                 \n"+
292
            "               texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y-u_Offsets[i])) ) * u_Weights[i]; \n"+
293
            "    }                                                                                                 \n"+
294
            "  fragColor = pixel;                                                                                  \n"+
295
            "  }";
325 296

  
326 297
    mIndex1 = PostprocessEffect.register("GLOW1", glowVertex,glowFragment1);
327 298
    mIndex2 = PostprocessEffect.register("GLOW2", glowVertex,glowFragment2);
src/main/java/org/distorted/library/main/DistortedOutputSurface.java
71 71
  private ArrayList<Job> mJobs = new ArrayList<>();
72 72

  
73 73
  // Global buffers used for postprocessing.
74
  private static DistortedOutputSurface[] mBuffer=null;
74
  private static DistortedFramebuffer[] mBuffer=null;
75 75

  
76 76
  private float mFOV;
77 77
  float mDistance, mNear;
......
181 181

  
182 182
  private static void createPostprocessingBuffers(int width, int height, float near)
183 183
    {
184
    mBuffer = new DistortedOutputSurface[EffectQuality.LENGTH];
184
    mBuffer = new DistortedFramebuffer[EffectQuality.LENGTH];
185 185
    float mipmap=1.0f;
186 186

  
187 187
    for (int j=0; j<EffectQuality.LENGTH; j++)
......
404 404
    DistortedNode child;
405 405
    EffectQueuePostprocess lastQueue=null, currQueue;
406 406
    long lastBucket=0, currBucket;
407
    boolean renderDirectly=false;
407 408

  
408 409
    setCurrFBO(fbo);
409 410

  
410 411
    if( mBuffer!=null )
411 412
      {
412
      for (int i=0; i<EffectQuality.LENGTH; i++)
413
        {
414
        mBuffer[i].setCurrFBO(fbo);
415
        }
413
      for (int i=0; i<EffectQuality.LENGTH; i++) mBuffer[i].setCurrFBO(fbo);
416 414
      }
417 415

  
418 416
    if( oit && numChildren>0 )
......
445 443
        if( mBuffer==null )
446 444
          {
447 445
          createPostprocessingBuffers(mWidth,mHeight,mNear);
448

  
449
          for (int j=0; j<EffectQuality.LENGTH; j++)
450
            {
451
            mBuffer[j].setCurrFBO(fbo);
452
            }
446
          for (int j=0; j<EffectQuality.LENGTH; j++) mBuffer[j].setCurrFBO(fbo);
453 447
          }
454 448

  
455 449
        if( lastBucket!=currBucket )
......
460 454
            }
461 455
          else
462 456
            {
463
            for(int j=bucketChange; j<i; j++) numRenders += lastQueue.preprocess( mBuffer,children.get(j) );
464
            numRenders += lastQueue.postprocess(mBuffer);
457
            for(int j=bucketChange; j<i; j++) numRenders += lastQueue.preprocess( mBuffer[quality],children.get(j) );
458
            numRenders += lastQueue.postprocess(mBuffer[quality]);
465 459

  
466 460
            if( oit )
467 461
              {
......
475 469
            mBuffer[quality].clearBuffer(fbo);
476 470
            }
477 471

  
478
          quality     = currQueue.getQuality();
472
          quality= currQueue.getQuality();
479 473
          bucketChange= i;
474
          renderDirectly = currQueue.getRender();
480 475
          }
481 476

  
482
        mBuffer[quality].setAsOutput(time);
483
        child.drawNoBlend(time,mBuffer[quality]);
477
        if( renderDirectly )
478
          {
479
          setAsOutput(time);
480

  
481
          if( oit )
482
            {
483
            numRenders += child.drawOIT(time, this);
484
            GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT | GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT);
485
            }
486
          else
487
            {
488
            numRenders += child.draw(time, this);
489
            }
490
          }
491
        else
492
          {
493
          mBuffer[quality].setAsOutput(time);
494
          child.drawNoBlend(time, mBuffer[quality]);
495
          }
484 496

  
485 497
        if( i==numChildren-1 )
486 498
          {
487
          for(int j=bucketChange; j<numChildren; j++) numRenders += currQueue.preprocess( mBuffer,children.get(j) );
488
          numRenders += currQueue.postprocess(mBuffer);
499
          for(int j=bucketChange; j<numChildren; j++) numRenders += currQueue.preprocess( mBuffer[quality],children.get(j) );
500
          numRenders += currQueue.postprocess(mBuffer[quality]);
489 501

  
490 502
          if( oit )
491 503
            {
......
543 555

  
544 556
///////////////////////////////////////////////////////////////////////////////////////////////////
545 557

  
546
  private void clearBuffer(int fbo)
558
  void clearBuffer(int fbo)
547 559
    {
548 560
    DistortedRenderState.colorDepthStencilOn();
549 561

  
src/main/java/org/distorted/library/main/EffectQueuePostprocess.java
40 40
  private static final int INDEX = EffectType.POSTPROCESS.ordinal();
41 41

  
42 42
  private int mHalo;
43
  private float mR, mG, mB, mA;
43 44

  
44 45
  private static DistortedProgram mPreProgram;
45 46
  private static int mPreColorH;
47
  private static int mPreTextureH;
46 48

  
47 49
///////////////////////////////////////////////////////////////////////////////////////////////////
48 50

  
......
59 61
    if( mTime==0 ) mTime = currTime;
60 62
    long step = (currTime-mTime);
61 63

  
64
    mR = mG = mB = mA = 0.0f;
62 65
    mHalo = 0;
63 66
    int halo;
64 67

  
......
84 87
      if( halo>mHalo ) mHalo = halo;
85 88
      }
86 89

  
90
    // TODO  (now only really works in case of 1 effect!)
91
    if( mNumEffects>0 )
92
      {
93
      mR = mUniforms[1];
94
      mG = mUniforms[2];
95
      mB = mUniforms[3];
96
      mA = mUniforms[4];
97
      }
98

  
87 99
    mTime = currTime;
88 100
    }
89 101

  
......
115 127
    int preProgramH = mPreProgram.getProgramHandle();
116 128
    EffectQueueVertex.getUniforms( preProgramH,2 );
117 129
    EffectQueueMatrix.getUniforms( preProgramH,2 );
118
    mPreColorH= GLES31.glGetUniformLocation( preProgramH, "u_Color");
119
    }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
// TODO
123

  
124
  private int getWriteColor()
125
    {
126
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getWriteColor() : 0;
127
    }
128

  
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

  
131
  private int getHalo()
132
    {
133
    return mNumEffects>0 ? mHalo : 0;
130
    mPreColorH  = GLES31.glGetUniformLocation( preProgramH, "u_Color"  );
131
    mPreTextureH= GLES31.glGetUniformLocation( preProgramH, "u_Texture");
134 132
    }
135 133

  
136 134
///////////////////////////////////////////////////////////////////////////////////////////////////
137 135
// TODO  (now only really works in case of 1 effect!)
138 136

  
139
  private int getInternalQuality()
137
  int getQuality()
140 138
    {
141
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getInternalQuality() : 0;
139
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getQuality() : 0;
142 140
    }
143 141

  
144 142
///////////////////////////////////////////////////////////////////////////////////////////////////
145 143
// TODO  (now only really works in case of 1 effect!)
146 144

  
147
  int getQuality()
145
  boolean getRender()
148 146
    {
149
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getQuality() : 0;
147
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getRender() : false;
150 148
    }
151 149

  
152 150
///////////////////////////////////////////////////////////////////////////////////////////////////
153 151

  
154
  int preprocess(DistortedOutputSurface[] buffers, DistortedNode node)
152
  int preprocess(DistortedOutputSurface buffer, DistortedNode node)
155 153
    {
156
    int quality = getInternalQuality();
157
    DistortedOutputSurface surface = buffers[quality];
158

  
159
    surface.setAsOutput();
154
    buffer.setAsOutput();
160 155
    DistortedSurface input = node.getInternalSurface();
161 156

  
162 157
    if( input.setAsInput() )
163 158
      {
164 159
      MeshObject mesh = node.getMesh();
165
      int  writeColor = getWriteColor();
166
      float    margin = getHalo()*surface.mMipmap;
160
      float    margin = mHalo*buffer.mMipmap;
167 161

  
168 162
      float halfW = input.getWidth() / 2.0f;
169 163
      float halfH = input.getHeight()/ 2.0f;
170 164
      float halfZ = halfW*mesh.zFactor;
171 165

  
172
      DistortedRenderState.setUpStencilMark(writeColor!=0);
166
      DistortedRenderState.setUpStencilMark(mA!=0.0f);
173 167

  
174
      GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
168
      GLES31.glViewport(0, 0, buffer.mWidth, buffer.mHeight );
175 169

  
176 170
      mPreProgram.useProgram();
177 171

  
......
181 175
      GLES31.glVertexAttribPointer(mPreProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
182 176
      GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
183 177

  
184
      node.getEffects().send(halfW, halfH, halfZ, margin, surface, 2);
185

  
186
      float a = (writeColor&255);
178
      node.getEffects().send(halfW, halfH, halfZ, margin, buffer, 2);
187 179

  
188
      if( a!=0.0f )
180
      if( mA!=0.0f )
189 181
        {
190
        writeColor = (writeColor>>8);
191
        float b = writeColor&255;
192
        writeColor = (writeColor>>8);
193
        float g = writeColor&255;
194
        writeColor = (writeColor>>8);
195
        float r = writeColor&255;
196

  
197
        GLES31.glUniform4f(mPreColorH, r, g, b, a);
182
        GLES31.glUniform4f(mPreColorH, mR, mG, mB, mA);
183
        GLES31.glUniform1i(mPreTextureH, 0);
198 184
        }
199 185

  
200 186
      GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
......
208 194

  
209 195
///////////////////////////////////////////////////////////////////////////////////////////////////
210 196

  
211
  int postprocess(DistortedOutputSurface[] buffers)
197
  int postprocess(DistortedFramebuffer buffer)
212 198
    {
213 199
    int numRenders = 0;
214 200

  
......
216 202

  
217 203
    for(int i=0; i<mNumEffects; i++)
218 204
      {
219
      numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, buffers);
205
      numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, buffer);
220 206
      }
221 207

  
222 208
    GLES31.glEnable(GLES31.GL_BLEND);
src/main/res/raw/preprocess_fragment_shader.glsl
19 19

  
20 20
precision highp float;
21 21

  
22
in vec2 v_TexCoordinate;                // Interpolated texture coordinate per fragment.
22 23
out vec4 fragColor;
23 24
uniform vec4 u_Color;
25
uniform sampler2D u_Texture;            // The input texture.
24 26

  
25 27
//////////////////////////////////////////////////////////////////////////////////////////////
26 28

  
27 29
void main()
28 30
  {
29
  fragColor = u_Color;
31
  vec4 color = texture(u_Texture,v_TexCoordinate);
32

  
33
  if( color.a != 0.0 )
34
    {
35
    fragColor = u_Color;
36
    }
37
  else
38
    {
39
    discard;
40
    }
30 41
  }

Also available in: Unified diff