Project

General

Profile

« Previous | Next » 

Revision bf2e8f97

Added by Leszek Koltunski over 3 years ago

Improve the Blur App to catch the bug where a small part of the Blur (and Glow) halo gets displayed on the other edge of the surface.

View differences:

src/main/java/org/distorted/examples/blur/BlurRenderer.java
24 24
import android.opengl.GLSurfaceView;
25 25

  
26 26
import org.distorted.examples.R;
27
import org.distorted.library.effect.MatrixEffectMove;
27 28
import org.distorted.library.effect.MatrixEffectScale;
28 29
import org.distorted.library.effect.PostprocessEffectBlur;
29 30
import org.distorted.library.main.DistortedLibrary;
30 31
import org.distorted.library.main.DistortedEffects;
31 32
import org.distorted.library.main.DistortedFramebuffer;
32
import org.distorted.library.main.DistortedNode;
33 33
import org.distorted.library.main.DistortedScreen;
34 34
import org.distorted.library.main.DistortedTexture;
35 35
import org.distorted.library.mesh.MeshRectangles;
......
48 48
class BlurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
49 49
{
50 50
    private final static int SIZE = 500;
51
    private final static float PART = 0.5f;
51 52

  
52 53
    private GLSurfaceView mView;
53 54
    private DistortedTexture mTexture;
......
56 57
    private DistortedFramebuffer mBuffer;
57 58
    private MeshRectangles mMesh, mMeshBuffer;
58 59
    private Static2D mHaloRadiusSta;
59
    private Static3D mScale, mBufferScale;
60
    private Static3D mMove, mScale, mBufferScale;
60 61

  
61 62
///////////////////////////////////////////////////////////////////////////////////////////////////
62 63

  
......
72 73
      Dynamic2D haloAndRadiusDyn = new Dynamic2D();
73 74
      haloAndRadiusDyn.add(mHaloRadiusSta);
74 75

  
76
      mMove = new Static3D(0,0,0);
75 77
      mScale= new Static3D(1,1,1);
76 78
      mBufferScale= new Static3D(1,1,1);
77 79

  
78 80
      mBufferEffects = new DistortedEffects();
79 81
      mBufferEffects.apply(new MatrixEffectScale(mBufferScale));
82
      mBufferEffects.apply(new PostprocessEffectBlur(haloAndRadiusDyn));
80 83

  
81 84
      mEffects = new DistortedEffects();
82
      mEffects.apply( new PostprocessEffectBlur(haloAndRadiusDyn) );
83 85
      mEffects.apply(new MatrixEffectScale(mScale));
86
      mEffects.apply(new MatrixEffectMove(mMove));
84 87
      }
85 88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
//   0 --> (SIZE-factor2) * -0.5
91
//  50 --> (SIZE-factor2) *  0.0
92
// 100 --> (SIZE-factor2) * +0.5
93

  
94
   int setMove(int move)
95
     {
96
     float xmove = (1-PART)*SIZE*(move-50)*0.01f;
97
     mMove.set0(xmove);
98
     return (int)xmove;
99
     }
100

  
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

  
103
   int setHalo(int halo)
104
     {
105
     int radius = halo;
106
     mHaloRadiusSta.set0(radius);
107
     return radius;
108
     }
109

  
86 110
///////////////////////////////////////////////////////////////////////////////////////////////////
87 111

  
88 112
   int setBlur(int blur)
......
106 130
    
107 131
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
108 132
     {
109
     float factor1 = 0.8f* (Math.min(width, height));
110

  
133
     float factor1 = Math.min(width, height);
111 134
     mBufferScale.set( factor1,factor1,factor1 );
112 135

  
113
     float factor2 = 0.9f*SIZE;
114

  
136
     float factor2 = PART*SIZE;
115 137
     mScale.set( factor2,factor2,factor2 );
116 138

  
117 139
     mScreen.resize(width, height);
......
141 163
     mTexture.setTexture(bitmap);
142 164

  
143 165
     mScreen.detachAll();
166
     mBuffer.detachAll();
167

  
144 168
     mScreen.attach(mBuffer, mBufferEffects, mMeshBuffer);
145
     mBuffer.attach(new DistortedNode(mTexture,mEffects,mMesh));
169
     mBuffer.attach(mTexture,mEffects,mMesh);
146 170

  
147 171
     PostprocessEffectBlur.enable();
148 172

  

Also available in: Unified diff