Project

General

Profile

« Previous | Next » 

Revision 80f37d1b

Added by Leszek Koltunski over 6 years ago

New 'Triblur' testapp.

Shows that the Blur effect doesn't fully work (probably it is the 'blitWithDepth' function which needs to be corrected)

View differences:

src/main/AndroidManifest.xml
45 45
        <activity android:name=".mirror.MirrorActivity"/>
46 46
        <activity android:name=".blur.BlurActivity"/>
47 47
        <activity android:name=".multiblur.MultiblurActivity"/>
48
        <activity android:name=".triblur.TriblurActivity"/>
48 49
        <activity android:name=".stencil.StencilActivity"/>
49 50
        <activity android:name=".glow.GlowActivity"/>
50 51
        <activity android:name=".movingglow.MovingGlowActivity"/>
src/main/java/org/distorted/examples/TableOfContents.java
63 63
import org.distorted.examples.mirror.MirrorActivity;
64 64
import org.distorted.examples.blur.BlurActivity;
65 65
import org.distorted.examples.multiblur.MultiblurActivity;
66
import org.distorted.examples.triblur.TriblurActivity;
66 67
import org.distorted.examples.stencil.StencilActivity;
67 68
import org.distorted.examples.glow.GlowActivity;
68 69
import org.distorted.examples.movingglow.MovingGlowActivity;
......
349 350
      activityMapping.put(i++, MultiblurActivity.class);
350 351
   }
351 352

  
353
   {
354
      final Map<String, Object> item = new HashMap<>();
355
      item.put(ITEM_IMAGE, R.drawable.icon_example_triblur);
356
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_triblur));
357
      item.put(ITEM_SUBTITLE, getText(R.string.example_triblur_subtitle));
358
      data.add(item);
359
      activityMapping.put(i++, TriblurActivity.class);
360
   }
361

  
352 362
   {
353 363
      final Map<String, Object> item = new HashMap<>();
354 364
      item.put(ITEM_IMAGE, R.drawable.icon_example_stencil);
src/main/java/org/distorted/examples/multiblur/MultiblurActivity.java
130 130
        case 1 : quality1(null); break;
131 131
        case 2 : quality2(null); break;
132 132
        case 3 : quality3(null); break;
133
        default: android.util.Log.e("Glow", "error - unknown quality!");
133
        default: android.util.Log.e("MultiBlur", "error - unknown quality!");
134 134
        }
135 135
      }
136 136

  
src/main/java/org/distorted/examples/triblur/TriblurActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.examples.triblur;
21

  
22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
24
import android.os.Bundle;
25
import android.view.View;
26
import android.widget.CheckBox;
27
import android.widget.SeekBar;
28

  
29
import org.distorted.examples.R;
30
import org.distorted.library.effect.EffectQuality;
31
import org.distorted.library.main.Distorted;
32

  
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

  
35
public class TriblurActivity extends Activity implements SeekBar.OnSeekBarChangeListener
36
{
37
    private int mQuality;
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
    @Override
42
    protected void onCreate(Bundle savedState) 
43
      {
44
      super.onCreate(savedState);
45
      setContentView(R.layout.triblurlayout);
46

  
47
      SeekBar radiusBar0 = (SeekBar)findViewById(R.id.triblurSeek0);
48
      SeekBar radiusBar1 = (SeekBar)findViewById(R.id.triblurSeek1);
49
      SeekBar radiusBar2 = (SeekBar)findViewById(R.id.triblurSeek2);
50

  
51
      radiusBar0.setOnSeekBarChangeListener(this);
52
      radiusBar1.setOnSeekBarChangeListener(this);
53
      radiusBar2.setOnSeekBarChangeListener(this);
54

  
55
      if( savedState==null )
56
        {
57
        radiusBar0.setProgress(20);
58
        radiusBar1.setProgress(50);
59
        radiusBar2.setProgress(70);
60

  
61
        mQuality = EffectQuality.HIGH.ordinal();
62
        }
63
      }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
    
67
    @Override
68
    protected void onPause() 
69
      {
70
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.triblurSurfaceView);
71
      view.onPause();
72
      Distorted.onPause();
73
      super.onPause();
74
      }
75

  
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
    
78
    @Override
79
    protected void onResume() 
80
      {
81
      super.onResume();
82
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.triblurSurfaceView);
83
      view.onResume();
84
      }
85
    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87
    
88
    @Override
89
    protected void onDestroy() 
90
      {
91
      Distorted.onDestroy();  
92
      super.onDestroy();
93
      }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

  
97
    @Override
98
    public void onSaveInstanceState(Bundle savedInstanceState)
99
      {
100
      super.onSaveInstanceState(savedInstanceState);
101

  
102
      TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
103
      TriblurRenderer renderer = view.getRenderer();
104

  
105
      savedInstanceState.putBooleanArray("checkboxes", renderer.getChecked() );
106
      savedInstanceState.putInt("quality", mQuality);
107
      }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

  
111
    @Override
112
    public void onRestoreInstanceState(Bundle savedInstanceState)
113
      {
114
      super.onRestoreInstanceState(savedInstanceState);
115

  
116
      boolean[] checkboxes = savedInstanceState.getBooleanArray("checkboxes");
117

  
118
      TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
119
      TriblurRenderer renderer = view.getRenderer();
120

  
121
      if( checkboxes!=null )
122
        {
123
        for(int i=0; i<checkboxes.length; i++)
124
          {
125
          renderer.setChecked(i,checkboxes[i]);
126
          }
127
        }
128

  
129
      mQuality = savedInstanceState.getInt("quality");
130

  
131
      switch(mQuality)
132
        {
133
        case 0 : quality0(null); break;
134
        case 1 : quality1(null); break;
135
        case 2 : quality2(null); break;
136
        case 3 : quality3(null); break;
137
        default: android.util.Log.e("TriBlur", "error - unknown quality!");
138
        }
139
      }
140

  
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

  
143
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
144
      {
145
      switch (bar.getId())
146
        {
147
        case R.id.triblurSeek0: TriblurSurfaceView view0 = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
148
                                view0.getRenderer().setRange(0,progress);
149
                                break;
150
        case R.id.triblurSeek1: TriblurSurfaceView view1 = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
151
                                view1.getRenderer().setRange(1,progress);
152
                                break;
153
        case R.id.triblurSeek2: TriblurSurfaceView view2 = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
154
                                view2.getRenderer().setRange(2,progress);
155
                                break;
156
        }
157
      }
158

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

  
161
    public void onStartTrackingTouch(SeekBar bar) { }
162

  
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

  
165
    public void onStopTrackingTouch(SeekBar bar)  { }
166

  
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

  
169
  public void onClick(View view)
170
    {
171
    CheckBox box = (CheckBox)view;
172
    int id = box.getId();
173
    boolean checked = box.isChecked();
174
    TriblurSurfaceView sView = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
175

  
176
    switch(id)
177
      {
178
      case R.id.triblurCheckBox0  : sView.getRenderer().setChecked(0,checked); break;
179
      case R.id.triblurCheckBox1  : sView.getRenderer().setChecked(1,checked); break;
180
      case R.id.triblurCheckBox2  : sView.getRenderer().setChecked(2,checked); break;
181
      }
182
    }
183

  
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

  
186
  public void quality0(View v)
187
    {
188
    TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
189
    TriblurRenderer renderer = view.getRenderer();
190
    renderer.setQuality(EffectQuality.HIGHEST);
191
    mQuality = EffectQuality.HIGHEST.ordinal();
192
    }
193

  
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

  
196
  public void quality1(View v)
197
    {
198
    TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
199
    TriblurRenderer renderer = view.getRenderer();
200
    renderer.setQuality(EffectQuality.HIGH);
201
    mQuality = EffectQuality.HIGH.ordinal();
202
    }
203

  
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

  
206
  public void quality2(View v)
207
    {
208
    TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
209
    TriblurRenderer renderer = view.getRenderer();
210
    renderer.setQuality(EffectQuality.MEDIUM);
211
    mQuality = EffectQuality.MEDIUM.ordinal();
212
    }
213

  
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

  
216
  public void quality3(View v)
217
    {
218
    TriblurSurfaceView view = (TriblurSurfaceView) this.findViewById(R.id.triblurSurfaceView);
219
    TriblurRenderer renderer = view.getRenderer();
220
    renderer.setQuality(EffectQuality.LOW);
221
    mQuality = EffectQuality.LOW.ordinal();
222
    }
223
}
src/main/java/org/distorted/examples/triblur/TriblurRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.examples.triblur;
21

  
22
import android.graphics.Bitmap;
23
import android.graphics.BitmapFactory;
24
import android.opengl.GLSurfaceView;
25

  
26
import org.distorted.examples.R;
27
import org.distorted.library.effect.EffectQuality;
28
import org.distorted.library.effect.FragmentEffectChroma;
29
import org.distorted.library.effect.MatrixEffectMove;
30
import org.distorted.library.effect.MatrixEffectQuaternion;
31
import org.distorted.library.effect.MatrixEffectScale;
32
import org.distorted.library.effect.PostprocessEffectBlur;
33
import org.distorted.library.main.Distorted;
34
import org.distorted.library.main.DistortedEffects;
35
import org.distorted.library.main.DistortedNode;
36
import org.distorted.library.main.DistortedScreen;
37
import org.distorted.library.main.DistortedTexture;
38
import org.distorted.library.main.MeshCubes;
39
import org.distorted.library.type.Static1D;
40
import org.distorted.library.type.Static3D;
41
import org.distorted.library.type.Static4D;
42

  
43
import java.io.IOException;
44
import java.io.InputStream;
45

  
46
import javax.microedition.khronos.egl.EGLConfig;
47
import javax.microedition.khronos.opengles.GL10;
48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

  
51
class TriblurRenderer implements GLSurfaceView.Renderer
52
{
53
    private static final int[] OBJECTS =
54
        {
55
        -1, 0, 0, 255,   0,  0,  // x,y,z, R,G,B
56
         0, 0, 0, 255, 255,  0,  //
57
        +1, 0, 0,   0, 255,  0,  //
58
        };
59

  
60
    private static final int NUM_OBJECTS = OBJECTS.length/6;
61
    private static final int OBJ_SIZE    = 100;
62

  
63
    private GLSurfaceView mView;
64
    private DistortedTexture mTex;
65
    private DistortedNode[] mNode;
66
    private Static3D[]  mMoveVector;
67
    private Static3D[]  mChromaVector;
68
    private Static1D[]  mBlurVector;
69
    private DistortedScreen mScreen;
70
    private PostprocessEffectBlur[] mBlur;
71
    private FragmentEffectChroma[] mChroma;
72
    private int mDistance;
73
    private boolean[] mBlurStatus;
74
    private Static3D mMove, mScale, mCenter;
75

  
76
    Static4D mQuat1, mQuat2;
77
    int mScreenMin;
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

  
81
    TriblurRenderer(GLSurfaceView v)
82
      {
83
      mView = v;
84
      mDistance = OBJ_SIZE/2;
85

  
86
      MeshCubes mesh = new MeshCubes(1,1,1);
87

  
88
      mTex = new DistortedTexture(OBJ_SIZE,OBJ_SIZE);
89

  
90
      mQuat1 = new Static4D(0,0,0,1);  // unity
91
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
92

  
93
      mScreen = new DistortedScreen();
94
      mScreen.setDebug(DistortedScreen.DEBUG_FPS);
95

  
96
      mBlurStatus   = new boolean[NUM_OBJECTS];
97
      mMoveVector   = new Static3D[NUM_OBJECTS];
98
      mChromaVector = new Static3D[NUM_OBJECTS];
99
      mBlurVector   = new Static1D[NUM_OBJECTS];
100
      mNode         = new DistortedNode[NUM_OBJECTS];
101
      mBlur         = new PostprocessEffectBlur[NUM_OBJECTS];
102
      mChroma       = new FragmentEffectChroma[NUM_OBJECTS];
103

  
104
      DistortedEffects[] effects= new DistortedEffects[NUM_OBJECTS];
105

  
106
      mMove   = new Static3D(0,0,0);
107
      mScale  = new Static3D(1,1,1);
108
      mCenter = new Static3D(0,0,0);
109

  
110
      MatrixEffectMove moveEffect = new MatrixEffectMove(mMove);
111
      MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale);
112
      MatrixEffectQuaternion quatEffect1 = new MatrixEffectQuaternion(mQuat1, mCenter);
113
      MatrixEffectQuaternion quatEffect2 = new MatrixEffectQuaternion(mQuat2, mCenter);
114

  
115
      for(int i=0; i<NUM_OBJECTS; i++)
116
        {
117
        mMoveVector[i]   = new Static3D(0,0,0);
118
        mChromaVector[i] = new Static3D(OBJECTS[6*i+3],OBJECTS[6*i+4],OBJECTS[6*i+5]);
119
        mBlurVector[i]   = new Static1D(10);
120
        mBlur[i]         = new PostprocessEffectBlur(mBlurVector[i]);
121
        mChroma[i]       = new FragmentEffectChroma( new Static1D(0.3f), mChromaVector[i]);
122
        effects[i]       = new DistortedEffects();
123

  
124
        effects[i].apply(mBlur[i]);
125
        effects[i].apply(mChroma[i]);
126
        effects[i].apply(moveEffect);
127
        effects[i].apply(scaleEffect);
128
        effects[i].apply(quatEffect1);
129
        effects[i].apply(quatEffect2);
130
        effects[i].apply(new MatrixEffectMove(mMoveVector[i]));
131

  
132
        mBlurStatus[i] = true;
133
        mNode[i] = new DistortedNode(mTex, effects[i], mesh);
134
        mScreen.attach(mNode[i]);
135
        }
136

  
137
      setQuality(EffectQuality.HIGH);
138
      }
139

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

  
142
    void setQuality(EffectQuality quality)
143
      {
144
      for(int i=0; i<NUM_OBJECTS; i++)
145
        {
146
        mBlur[i].setQuality(quality);
147
        }
148
      }
149

  
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

  
152
    public void onDrawFrame(GL10 glUnused) 
153
      {
154
      mScreen.render(System.currentTimeMillis());
155
      }
156

  
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
    
159
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
160
      {
161
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.cat);
162
      Bitmap bitmap;
163
        
164
      try 
165
        {
166
        bitmap = BitmapFactory.decodeStream(is);
167
        }
168
      finally 
169
        {
170
        try 
171
          {
172
          is.close();
173
          }
174
        catch(IOException e) { }
175
        }  
176

  
177
      mTex.setTexture(bitmap);
178

  
179
      PostprocessEffectBlur.enable();
180
      FragmentEffectChroma.enable();
181

  
182
      try
183
        {
184
        Distorted.onCreate(mView.getContext());
185
        }
186
      catch(Exception ex)
187
        {
188
        android.util.Log.e("Triblur", ex.getMessage() );
189
        }
190
      }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

  
194
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
195
      {
196
      mScreenMin = width<height ? width:height;
197

  
198
      float factor = 0.24f*mScreenMin/OBJ_SIZE;
199
      mScale.set(factor,factor,factor);
200
      mCenter.set((float)OBJ_SIZE/2, (float)OBJ_SIZE/2, -(float)OBJ_SIZE/2 );
201
      mMove.set( (width -factor*OBJ_SIZE)/2 ,(height-factor*OBJ_SIZE)/2 ,0);
202
      computeMoveVectors();
203
      mScreen.resize(width, height);
204
      }
205

  
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

  
208
    private void computeMoveVectors()
209
      {
210
      float size= 0.026f*OBJ_SIZE*mDistance;
211

  
212
      for(int i=0; i<NUM_OBJECTS; i++)
213
        {
214
        mMoveVector[i].set(size*OBJECTS[6*i], size*OBJECTS[6*i+1], size*OBJECTS[6*i+2]);
215
        }
216
      }
217

  
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

  
220
    void setRange(int object, int range)
221
      {
222
      if( object>=0 && object<NUM_OBJECTS )
223
        {
224
        mBlurVector[object].set(range / 2);
225
        }
226
      }
227

  
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

  
230
    boolean[] getChecked()
231
     {
232
     return mBlurStatus;
233
     }
234

  
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

  
237
    void setChecked(int object, boolean checked)
238
      {
239
      if( object>=0 && object<NUM_OBJECTS )
240
        {
241
        if( checked && !mBlurStatus[object] )
242
          {
243
          mBlurStatus[object] = true;
244
          mNode[object].getEffects().apply(mBlur[object]);
245
          }
246
        if( !checked && mBlurStatus[object] )
247
          {
248
          mBlurStatus[object] = false;
249
          mNode[object].getEffects().abortEffect(mBlur[object]);
250
          }
251
        }
252
      else
253
        {
254
        android.util.Log.e("renderer", "Error, number: "+object+" checked: "+checked );
255
        }
256

  
257
      //android.util.Log.d("renderer", "setting box "+number+" BLUR state to "+checked);
258
      }
259
}
src/main/java/org/distorted/examples/triblur/TriblurSurfaceView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.examples.triblur;
21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLSurfaceView;
26
import android.util.AttributeSet;
27
import android.view.MotionEvent;
28
import android.widget.Toast;
29

  
30
import org.distorted.examples.R;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
class TriblurSurfaceView extends GLSurfaceView
35
{
36
    private int mX, mY;
37
    private TriblurRenderer mRenderer;
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
    public TriblurSurfaceView(Context context, AttributeSet attrs)
42
      {
43
      super(context, attrs);
44

  
45
      mX = -1;
46
      mY = -1;
47

  
48
      if(!isInEditMode())
49
        {
50
        mRenderer = new TriblurRenderer(this);
51
        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
52
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
53
        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
54
        setRenderer(mRenderer);
55
        Toast.makeText(context, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show();
56
        }
57
      }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

  
61
    public TriblurRenderer getRenderer()
62
      {
63
      return mRenderer;
64
      }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
    
68
    @Override public boolean onTouchEvent(MotionEvent event) 
69
      {
70
      int action = event.getAction();
71
      int x = (int)event.getX();
72
      int y = (int)event.getY();
73
           
74
      switch(action)
75
         {
76
         case MotionEvent.ACTION_DOWN: mX = x;
77
                                       mY = y;
78
                                       break;
79
                                       
80
         case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 )
81
                                         {
82
                                         float px = mY-y;
83
                                         float py = mX-x;
84
                                         float pz = 0;
85
                                         float plen = (float)Math.sqrt(px*px + py*py + pz*pz);
86
                                         
87
                                         if( plen>0 )
88
                                           {
89
                                           px /= plen;
90
                                           py /= plen;
91
                                           pz /= plen;
92

  
93
                                           float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
94
                                           float sinA = (float)Math.sqrt(1-cosA*cosA);
95
                                         
96
                                           mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
97
                                           }
98
                                         }                             
99
                                       break;
100
                                       
101
         case MotionEvent.ACTION_UP  : mX = -1;
102
                                       mY = -1;
103
        	                           
104
                                       float qx = mRenderer.mQuat1.get1();
105
                                       float qy = mRenderer.mQuat1.get2();
106
                                       float qz = mRenderer.mQuat1.get3();
107
                                       float qw = mRenderer.mQuat1.get4();
108

  
109
                                       float rx = mRenderer.mQuat2.get1();
110
                                       float ry = mRenderer.mQuat2.get2();
111
                                       float rz = mRenderer.mQuat2.get3();
112
                                       float rw = mRenderer.mQuat2.get4();
113

  
114
                                       // This is quaternion multiplication. (tx,ty,tz,tw)
115
                                       // is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw)
116
                                       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
117
                                       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
118
                                       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
119
                                       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
120

  
121
                                       // The point of this is so that there are always
122
                                       // exactly 2 quaternions: Quat1 representing the rotation
123
                                       // accumulating only since the last screen touch, and Quat2
124
                                       // which remembers the combined effect of all previous
125
                                       // swipes.
126
                                       // We cannot be accumulating an ever-growing list of quaternions
127
                                       // and add a new one every time user swipes the screen - there
128
                                       // is a limited number of slots in the EffectQueueMatrix!
129
                                       mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
130
                                       mRenderer.mQuat2.set(tx, ty, tz, tw);
131
                                       
132
                                       break;
133
         }
134
             
135
      return true;
136
      }
137
         
138
}
139

  
src/main/res/layout/triblurlayout.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:orientation="vertical" >
6

  
7
    <org.distorted.examples.triblur.TriblurSurfaceView
8
        android:id="@+id/triblurSurfaceView"
9
        android:layout_width="fill_parent"
10
        android:layout_height="0dp"
11
        android:layout_weight="1" />
12

  
13
    <LinearLayout
14
        android:orientation="horizontal"
15
        android:background="@color/red"
16
        android:layout_width="match_parent"
17
        android:layout_height="50dp"
18
        android:paddingBottom="10dp"
19
        android:paddingTop="10dp">
20

  
21
        <CheckBox
22
            android:layout_height="fill_parent"
23
            android:layout_width="wrap_content"
24
            android:id="@+id/triblurCheckBox0"
25
            android:paddingLeft="10dp"
26
            android:onClick="onClick"
27
            android:checked="true"/>
28

  
29
        <SeekBar
30
            android:id="@+id/triblurSeek0"
31
            android:layout_height="fill_parent"
32
            android:layout_width="fill_parent"
33
            android:paddingLeft="10dp"
34
            android:paddingRight="10dp" />
35
    </LinearLayout>
36

  
37
    <LinearLayout
38
        android:orientation="horizontal"
39
        android:background="@color/yellow"
40
        android:layout_width="match_parent"
41
        android:layout_height="50dp"
42
        android:paddingBottom="10dp"
43
        android:paddingTop="10dp">
44

  
45
        <CheckBox
46
            android:layout_height="fill_parent"
47
            android:layout_width="wrap_content"
48
            android:id="@+id/triblurCheckBox1"
49
            android:paddingLeft="10dp"
50
            android:onClick="onClick"
51
            android:checked="true"/>
52

  
53
        <SeekBar
54
            android:id="@+id/triblurSeek1"
55
            android:layout_height="fill_parent"
56
            android:layout_width="fill_parent"
57
            android:paddingLeft="10dp"
58
            android:paddingRight="10dp" />
59
    </LinearLayout>
60

  
61
    <LinearLayout
62
        android:orientation="horizontal"
63
        android:background="@color/green"
64
        android:layout_width="match_parent"
65
        android:layout_height="50dp"
66
        android:paddingBottom="10dp"
67
        android:paddingTop="10dp">
68

  
69
        <CheckBox
70
            android:layout_height="fill_parent"
71
            android:layout_width="wrap_content"
72
            android:id="@+id/triblurCheckBox2"
73
            android:paddingLeft="10dp"
74
            android:onClick="onClick"
75
            android:checked="true"/>
76

  
77
        <SeekBar
78
            android:id="@+id/triblurSeek2"
79
            android:layout_height="fill_parent"
80
            android:layout_width="fill_parent"
81
            android:paddingLeft="10dp"
82
            android:paddingRight="10dp" />
83
    </LinearLayout>
84

  
85
    <LinearLayout
86
        android:id="@+id/linearLayout3"
87
        android:layout_width="fill_parent"
88
        android:layout_height="wrap_content"
89
        android:gravity="center|fill_horizontal"
90
        android:orientation="horizontal"
91
        android:background="@color/blue"
92
        android:paddingBottom="10dp"
93
        android:paddingTop="10dp" >
94

  
95
        <RadioGroup
96
            android:id="@+id/triblurRadioGroup"
97
            android:layout_width="match_parent"
98
            android:layout_height="wrap_content"
99
            android:orientation="horizontal">
100

  
101
            <RadioButton
102
                android:id="@+id/triblurRadioQuality0"
103
                android:layout_width="match_parent"
104
                android:layout_height="wrap_content"
105
                android:layout_weight="1"
106
                android:onClick="quality0"
107
                android:text="@string/quality0"
108
                android:textSize="14sp"/>
109

  
110
            <RadioButton
111
                android:id="@+id/triblurRadioQuality1"
112
                android:layout_width="match_parent"
113
                android:layout_height="wrap_content"
114
                android:layout_weight="1"
115
                android:checked="true"
116
                android:onClick="quality1"
117
                android:text="@string/quality1"
118
                android:textSize="14sp"/>
119

  
120
            <RadioButton
121
                android:id="@+id/triblurRadioQuality2"
122
                android:layout_width="match_parent"
123
                android:layout_height="wrap_content"
124
                android:layout_weight="1"
125
                android:onClick="quality2"
126
                android:text="@string/quality2"
127
                android:textSize="14sp"/>
128

  
129
            <RadioButton
130
                android:id="@+id/triblurRadioQuality3"
131
                android:layout_width="match_parent"
132
                android:layout_height="wrap_content"
133
                android:layout_weight="1"
134
                android:onClick="quality3"
135
                android:text="@string/quality3"
136
                android:textSize="14sp"/>
137

  
138
        </RadioGroup>
139

  
140
    </LinearLayout>
141

  
142
</LinearLayout>
src/main/res/values/strings.xml
147 147
    <string name="example_blur_subtitle">Postprocessing effect: Blur.</string>
148 148
    <string name="example_multiblur">Multiblur</string>
149 149
    <string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</string>
150
    <string name="example_triblur">Triblur</string>
151
    <string name="example_triblur_subtitle">Three different, blurred, obstructing objects.</string>
150 152
    <string name="example_stencil">Stencil Buffer</string>
151 153
    <string name="example_stencil_subtitle">Implement the classic stencil example from https://open.gl/depthstencils</string>
152 154
    <string name="example_glow">Glowing Leaf</string>

Also available in: Unified diff