Project

General

Profile

« Previous | Next » 

Revision 1d6d261e

Added by Leszek Koltunski almost 7 years ago

Move to a new way to detecting depth of postprocessing halos.
This switches off stenciling (hopefully temporarily!)

View differences:

src/main/java/org/distorted/library/DistortedNode.java
272 272
      float h = mSurface.getHeight()/2.0f;
273 273

  
274 274
      // Actually draw our object.
275
      buffer1.setAsOutput(currTime);
275
      buffer1.setAsOutput();
276 276
      mState.apply();
277 277
      mEffects.drawPriv(w, h, mMesh, buffer1, currTime, 0);
278 278

  
279 279
      // Mark area of our object + marginInPixels pixels around with 1s in Stencil buffer
280
      buffer2.setAsOutput(currTime);
280
      //buffer2.setAsOutput();
281 281
      DistortedRenderState.setUpStencilMark();
282
      mEffects.drawPriv(w, h, mMesh, buffer2, currTime, effects.getHalo()*buffer2.mMipmap);
282
      mEffects.drawPriv(w, h, mMesh, buffer1, currTime, effects.getHalo()*buffer1.mMipmap);
283 283
      DistortedRenderState.unsetUpStencilMark();
284 284

  
285 285
      return 1;
src/main/java/org/distorted/library/DistortedOutputSurface.java
156 156
      }
157 157
    }
158 158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

  
161
  void createBuffers()
162
    {
163
    float mipmap=1.0f;
164

  
165
    for(int j=0; j<EffectQuality.LENGTH; j++)
166
      {
167
      mBuffer1[j] = new DistortedFramebuffer(1,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
168
      mBuffer2[j] = new DistortedFramebuffer(1,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
169
      mBuffer1[j].mMipmap = mipmap;
170
      mBuffer2[j].mMipmap = mipmap;
171
      mipmap *= EffectQuality.MULTIPLIER;
172
      }
173

  
174
    DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
175

  
176
    GLES30.glStencilMask(0xff);
177
    GLES30.glDepthMask(true);
178
    GLES30.glColorMask(true,true,true,true);
179
    GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f);
180
    GLES30.glClearDepthf(1.0f);
181
    GLES30.glClearStencil(0);
182

  
183
    for(int j=0; j<EffectQuality.LENGTH; j++)
184
      {
185
      mBuffer1[j].setAsOutput();
186
      GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT);
187
      mBuffer2[j].setAsOutput();
188
      GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT);
189
      }
190
    }
191

  
159 192
///////////////////////////////////////////////////////////////////////////////////////////////////
160 193
// Render all children, one by one. If there are no postprocessing effects, just render to THIS.
161 194
// Otherwise, render to a buffer and on each change of Postprocessing Bucket, apply the postprocessing
......
174 207
      currP = child.getEffectsPostprocess();
175 208
      currB = currP==null ? 0 : currP.getBucket();
176 209

  
177
      if( lastB!=currB && lastB!=0 )
178
        {
179
        numRenders += lastP.postprocess(time,this);
180
        }
210
      if( lastB!=currB && lastB!=0 ) numRenders += lastP.postprocess(time,this);
181 211

  
182
      if( currB==0 )
183
        {
184
        numRenders += child.draw(time,this);
185
        }
212
      if( currB==0 ) numRenders += child.draw(time,this);
186 213
      else
187 214
        {
188
        if( mBuffer1[0]==null )
189
          {
190
          float mipmap=1.0f;
191

  
192
          for(int j=0; j<EffectQuality.LENGTH; j++)
193
            {
194
            mBuffer1[j] = new DistortedFramebuffer(1,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
195
            mBuffer2[j] = new DistortedFramebuffer(1,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
196
            mBuffer1[j].mMipmap = mipmap;
197
            mBuffer2[j].mMipmap = mipmap;
198
            mipmap *= EffectQuality.MULTIPLIER;
199
            }
200
          DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now.
201
          }
202

  
215
        if( mBuffer1[0]==null ) createBuffers();
203 216
        numRenders += child.markStencilAndDraw(time,this,currP);
204

  
205
        if( i==num-1 )
206
          {
207
          numRenders += currP.postprocess(time,this);
208
          }
217
        if( i==num-1 ) numRenders += currP.postprocess(time,this);
209 218
        }
210 219

  
211 220
      lastP = currP;
......
222 231
    mJobs.add(new Job(t,n,d));
223 232
    }
224 233

  
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

  
236
  void setAsOutput()
237
    {
238
    GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]);
239
    }
240

  
225 241
///////////////////////////////////////////////////////////////////////////////////////////////////
226 242
// PUBLIC API
227 243
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedRenderState.java
143 143
      }
144 144
    }
145 145

  
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

  
148
  static void switchOffDepthWriting()
149
    {
150
    if( cState.depthMask!=0 )
151
      {
152
      sState.depthMask = cState.depthMask;
153
      cState.depthMask = 0;
154
      GLES30.glDepthMask(false);
155
      }
156
    }
157

  
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

  
160
  static void restoreDepthWriting()
161
    {
162
    if( sState.depthMask!=cState.depthMask )
163
      {
164
      cState.depthMask = sState.depthMask;
165
      GLES30.glDepthMask(cState.depthMask==1);
166
      }
167
    }
168

  
146 169
///////////////////////////////////////////////////////////////////////////////////////////////////
147 170

  
148 171
  static void switchOffDrawing()
......
204 227
      //android.util.Log.d("State", "switch off color writing");
205 228
      GLES30.glColorMask(false,false,false,false);
206 229
      }
207
    if( cState.depthMask!=0 )
230
    if( cState.depthMask!=1 )
208 231
      {
209 232
      sState.depthMask = cState.depthMask;
210
      cState.depthMask = 0;
211
      //android.util.Log.d("State", "switch off depth writing");
212
      GLES30.glDepthMask(false);
233
      cState.depthMask = 1;
234
      //android.util.Log.d("State", "switch on depth writing");
235
      GLES30.glDepthMask(true);
213 236
      }
214 237
    if( cState.stencilMask!= STENCIL_MASK )
215 238
      {
src/main/java/org/distorted/library/EffectQueuePostprocess.java
291 291
      GLES30.glViewport(0, 0, (int)w1, (int)h1);
292 292
      mBlur1Program.useProgram();
293 293
      buffer1.setAsInput();
294
      buffer2.setAsOutput(time);
294
      buffer2.setAsOutput();
295 295

  
296 296
      GLES30.glUniform1fv( mWeights1H, radius+1, weightsCache,offset);
297 297
      GLES30.glUniform1i( mRadius1H, radius);
......
302 302
      GLES30.glVertexAttribPointer(mBlur1Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions);
303 303
      GLES30.glVertexAttribPointer(mBlur1Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
304 304

  
305
      DistortedRenderState.useStencilMark();
305
      //DistortedRenderState.switchOffDepthWriting();
306
      //DistortedRenderState.useStencilMark();
306 307
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
307
      DistortedRenderState.unuseStencilMark();
308
      //DistortedRenderState.unuseStencilMark();
309
      //DistortedRenderState.restoreDepthWriting();
308 310

  
309 311
      // vertical blur
310 312
      GLES30.glViewport(0, 0, (int)w2, (int)h2);
......
324 326
      GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture);
325 327
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
326 328

  
327
      // after each postprocess, clear the STENCIL
328
      buffer2.setAsOutput(time);
329
      // after each postprocess, clear buffers
329 330
      GLES30.glStencilMask(0xff);
331
      GLES30.glDepthMask(true);
332
      GLES30.glColorMask(true,true,true,true);
333
      GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f);
334
      GLES30.glClearDepthf(1.0f);
330 335
      GLES30.glClearStencil(0);
331
      GLES30.glClear(GLES30.GL_STENCIL_BUFFER_BIT);
336

  
337
      buffer1.setAsOutput();
338
      GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT);//|GLES30.GL_STENCIL_BUFFER_BIT);
339
      buffer2.setAsOutput();
340
      GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT);
332 341
      }
333 342

  
334 343
    return mNumEffects;
src/main/res/raw/blur2_fragment_shader.glsl
40 40

  
41 41
void main()
42 42
  {
43
  float depth = TEXTURE(u_DepthTexture,v_TexCoordinate).r;
44

  
45
  if( u_Radius>1 )
46
    {
47
    float offset = u_Offsets[u_Radius];
48

  
49
    depth = min(depth, TEXTURE(u_DepthTexture,vec2(v_TexCoordinate.x,v_TexCoordinate.y+offset)).r);
50
    depth = min(depth, TEXTURE(u_DepthTexture,vec2(v_TexCoordinate.x,v_TexCoordinate.y-offset)).r);
51
    depth = min(depth, TEXTURE(u_DepthTexture,vec2(v_TexCoordinate.x+offset,v_TexCoordinate.y)).r);
52
    depth = min(depth, TEXTURE(u_DepthTexture,vec2(v_TexCoordinate.x-offset,v_TexCoordinate.y)).r);
53
    }
54

  
55
  gl_FragDepth = depth;
43
  gl_FragDepth = TEXTURE(u_DepthTexture,v_TexCoordinate).r;
56 44

  
57 45
  vec4 pixel= TEXTURE(u_ColorTexture,v_TexCoordinate) * u_Weights[0];
58 46

  

Also available in: Unified diff