Project

General

Profile

« Previous | Next » 

Revision 5ec42229

Added by Leszek Koltunski almost 3 years ago

Workaround for the fact that one some devices (for example the LG K30's V@415 driver on the Adreno 308) the Glow halo wasn't visible.

View differences:

src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
34 34
  {
35 35
  private static final int MAX_RADIUS = 50;
36 36

  
37
  private Data2D mBlurHaloAndRadius;
37
  private final Data2D mBlurHaloAndRadius;
38 38

  
39 39
  private static final float[] GAUSSIAN =   // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
40 40
    {                                       // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates.
......
56 56
  // i.e. k(i)=floor((i+3)/2).  (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
57 57
  // in all 4 directions)
58 58
  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
59
  private static float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
60
  private static float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
61
  private static float[] mWeights = new float[MAX_RADIUS];
62
  private static float[] mOffsets = new float[MAX_RADIUS];
59
  private static final float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
60
  private static final float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
61
  private static final float[] mWeights = new float[MAX_RADIUS];
62
  private static final float[] mOffsets = new float[MAX_RADIUS];
63 63

  
64 64
  private static DistortedProgram mProgram1, mProgram2;
65 65
  private static int mIndex1, mIndex2;
src/main/java/org/distorted/library/main/DistortedLibrary.java
160 160
  private static DistortedProgram mBlitDepthProgram;
161 161
  private static int mBlitDepthTextureH;
162 162
  private static int mBlitDepthDepthTextureH;
163
  private static int mBlitDepthDepthH;
164 163
  private static int mBlitDepthTexCorrH;
165 164

  
166 165
  /// Program Handles ///
......
311 310
    int blitDepthProgramH   = mBlitDepthProgram.getProgramHandle();
312 311
    mBlitDepthTextureH      = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Texture");
313 312
    mBlitDepthDepthTextureH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture");
314
    mBlitDepthDepthH        = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Depth");
315 313
    mBlitDepthTexCorrH      = GLES30.glGetUniformLocation( blitDepthProgramH, "u_TexCorr");
316 314
    }
317 315

  
......
665 663
      GLES30.glUniform1i(mBlitDepthTextureH, 0);
666 664
      GLES30.glUniform1i(mBlitDepthDepthTextureH, 1);
667 665
      GLES30.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
668
      GLES30.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
669 666
      GLES30.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
670 667
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
671 668
      }
src/main/res/raw/blit_depth_fragment_shader.glsl
26 26
uniform sampler2D u_DepthTexture;
27 27

  
28 28
//////////////////////////////////////////////////////////////////////////////////////////////
29
// why -0.000001 ? On some drivers (for example Qualcomm's V@331, V@415 on Adreno 308 - also on
30
// some Mali devices ) without it the depth test - when postprocessing a flat 2D object - does
31
// not pass (for unknown reasons) and we don't see the Glow halo.  See for example the 'Glowing
32
// Leaf' test app.
33
// 0.000001 shouldn't hurt anyway.
29 34

  
30 35
void main()                    		
31 36
  {
32
  gl_FragDepth = texture(u_DepthTexture,v_TexCoordinate).r;
37
  gl_FragDepth = texture(u_DepthTexture,v_TexCoordinate).r -0.000001;
33 38
  fragColor    = texture(u_Texture     ,v_TexCoordinate);
34 39
  }
src/main/res/raw/blit_depth_vertex_shader.glsl
22 22
in vec2 a_Position;           // Per-vertex position.
23 23
out vec2 v_TexCoordinate;     //
24 24

  
25
uniform float u_Depth;        // distance from the near plane to render plane, in clip coords
26 25
uniform vec2  u_TexCorr;      // when we blit from postprocessing buffers, the buffers can be
27 26
                              // larger than necessary (there is just one static set being
28 27
                              // reused!) so we need to compensate here by adjusting the texture
......
33 32
void main()
34 33
  {
35 34
  v_TexCoordinate = (a_Position + 0.5) * u_TexCorr;
36
  gl_Position     = vec4(2.0*a_Position,u_Depth,1.0);
35
  gl_Position     = vec4(2.0*a_Position,0.0,1.0);
37 36
  }

Also available in: Unified diff