Project

General

Profile

« Previous | Next » 

Revision 1b80a6e2

Added by Leszek Koltunski about 3 years ago

New postprocess effect 'Border' (not working yet) and adding it to the testing app 'Triblur'.

View differences:

src/main/java/org/distorted/examples/triblur/TriblurActivity.java
36 36

  
37 37
public class TriblurActivity extends Activity implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
38 38
{
39
    private static final int NONE0 = 0;
40
    private static final int NONE1 = 1;
41
    private static final int NONE2 = 2;
42
    private static final int BLUR0 = 3;
43
    private static final int BLUR1 = 4;
44
    private static final int BLUR2 = 5;
45
    private static final int GLOW0 = 6;
46
    private static final int GLOW1 = 7;
47
    private static final int GLOW2 = 8;
48

  
49 39
    private int mQuality;
50 40
    private int mBackground;
51 41

  
......
74 64

  
75 65
        privateQuality(1);
76 66
        privateBackgroundColor(1);
77
        privateEffect(BLUR0);
78
        privateEffect(BLUR1);
79
        privateEffect(BLUR2);
80 67
        }
81 68

  
82
      Spinner typeSpinner  = findViewById(R.id.triblur_spinnerQuality);
83
      typeSpinner.setOnItemSelectedListener(this);
84

  
85 69
      String[] objectType = new String[] {"Quality Highest", "Quality High", "Quality Medium", "Quality Low"};
70
      setUpSpinner(R.id.triblur_spinnerQuality, objectType);
71
      String[] renderType = new String[] {"Render: Normal", "Render: OIT" };
72
      setUpSpinner(R.id.triblur_spinnerMode, renderType);
73

  
74
      String[] effects = new String[] {"NONE", "BLUR", "GLOW", "BORDER" };
75
      setUpSpinner(R.id.triblur_effect0, effects);
76
      setUpSpinner(R.id.triblur_effect1, effects);
77
      setUpSpinner(R.id.triblur_effect2, effects);
78
      }
86 79

  
87
      ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
88
      adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
89
      typeSpinner.setAdapter(adapterType);
90

  
91
      Spinner bitmapSpinner  = findViewById(R.id.triblur_spinnerMode);
92
      bitmapSpinner.setOnItemSelectedListener(this);
80
///////////////////////////////////////////////////////////////////////////////////////////////////
93 81

  
94
      String[] objectBitmap = new String[] { "Render: Normal", "Render: OIT" };
82
    private void setUpSpinner(int spinnerID, String[] options)
83
      {
84
      Spinner typeSpinner  = findViewById(spinnerID);
85
      typeSpinner.setOnItemSelectedListener(this);
95 86

  
96
      ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
97
      adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
98
      bitmapSpinner.setAdapter(adapterBitmap);
87
      ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, options);
88
      adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
89
      typeSpinner.setAdapter(adapterType);
99 90
      }
100 91

  
101 92
///////////////////////////////////////////////////////////////////////////////////////////////////
......
110 101
                                          TriblurRenderer renderer = v.getRenderer();
111 102
                                          renderer.setRenderModeToOIT(pos==1);
112 103
                                          break;
104
        case R.id.triblur_effect0       : privateEffect(0,pos);
105
                                          break;
106
        case R.id.triblur_effect1       : privateEffect(1,pos);
107
                                          break;
108
        case R.id.triblur_effect2       : privateEffect(2,pos);
109
                                          break;
113 110
        }
114 111
      }
115 112

  
......
211 208

  
212 209
///////////////////////////////////////////////////////////////////////////////////////////////////
213 210

  
214
    public void onStartTrackingTouch(SeekBar bar) { }
211
  public void onStartTrackingTouch(SeekBar bar) { }
215 212

  
216 213
///////////////////////////////////////////////////////////////////////////////////////////////////
217 214

  
218
    public void onStopTrackingTouch(SeekBar bar)  { }
215
  public void onStopTrackingTouch(SeekBar bar)  { }
219 216

  
220 217
///////////////////////////////////////////////////////////////////////////////////////////////////
221 218

  
222
  public void effect(View v)
223
    {
224
    switch(v.getId())
225
      {
226
      case R.id.triblurRadioNone0: privateEffect(NONE0); break;
227
      case R.id.triblurRadioNone1: privateEffect(NONE1); break;
228
      case R.id.triblurRadioNone2: privateEffect(NONE2); break;
229
      case R.id.triblurRadioBlur0: privateEffect(BLUR0); break;
230
      case R.id.triblurRadioBlur1: privateEffect(BLUR1); break;
231
      case R.id.triblurRadioBlur2: privateEffect(BLUR2); break;
232
      case R.id.triblurRadioGlow0: privateEffect(GLOW0); break;
233
      case R.id.triblurRadioGlow1: privateEffect(GLOW1); break;
234
      case R.id.triblurRadioGlow2: privateEffect(GLOW2); break;
235
      }
236
    }
237

  
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

  
240
  private void privateEffect(int index)
219
  private void privateEffect(int object, int effect)
241 220
    {
242 221
    TriblurSurfaceView view = findViewById(R.id.triblurSurfaceView);
243 222
    TriblurRenderer renderer = view.getRenderer();
244 223

  
245
    switch(index)
246
      {
247
      case NONE0: renderer.setEffects(0,0); break;
248
      case NONE1: renderer.setEffects(1,0); break;
249
      case NONE2: renderer.setEffects(2,0); break;
250
      case BLUR0: renderer.setEffects(0,1); break;
251
      case BLUR1: renderer.setEffects(1,1); break;
252
      case BLUR2: renderer.setEffects(2,1); break;
253
      case GLOW0: renderer.setEffects(0,2); break;
254
      case GLOW1: renderer.setEffects(1,2); break;
255
      case GLOW2: renderer.setEffects(2,2); break;
256
      }
224
    renderer.setEffects(object,effect);
257 225
    }
258 226

  
259 227
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/triblur/TriblurRenderer.java
31 31
import org.distorted.library.effect.MatrixEffectQuaternion;
32 32
import org.distorted.library.effect.MatrixEffectScale;
33 33
import org.distorted.library.effect.PostprocessEffectBlur;
34
import org.distorted.library.effect.PostprocessEffectBorder;
34 35
import org.distorted.library.effect.PostprocessEffectGlow;
35 36
import org.distorted.library.effect.VertexEffectScale;
36 37
import org.distorted.library.main.DistortedLibrary;
......
66 67
    private static final int NUM_OBJECTS = OBJECTS.length/NUM;
67 68
    private static final int OBJ_SIZE    = 100;
68 69

  
69
    private GLSurfaceView mView;
70
    private DistortedTexture mTex;
71
    private DistortedNode[] mNode;
72
    private Static2D[] mEffectHaloRadius;
73
    private DistortedScreen mScreen;
74
    private PostprocessEffectBlur[] mBlur;
75
    private PostprocessEffectGlow[] mGlow;
76
    private int[] mEffectStatus;
77
    private Static3D mScale1, mScale2;
70
    private final GLSurfaceView mView;
71
    private final DistortedTexture mTex;
72
    private final DistortedNode[] mNode;
73
    private final Static2D[] mEffectHaloRadius;
74
    private final Static1D[] mEffectHalo;
75
    private final DistortedScreen mScreen;
76
    private final PostprocessEffectBlur[] mBlur;
77
    private final PostprocessEffectGlow[] mGlow;
78
    private final PostprocessEffectBorder[] mBord;
79
    private final int[] mEffectStatus;
80
    private final Static3D mScale1, mScale2;
78 81

  
79 82
    Static4D mQuat1, mQuat2;
80 83
    int mScreenMin;
......
97 100

  
98 101
      mEffectStatus    = new int[NUM_OBJECTS];
99 102
      mEffectHaloRadius= new Static2D[NUM_OBJECTS];
103
      mEffectHalo      = new Static1D[NUM_OBJECTS];
100 104
      mNode            = new DistortedNode[NUM_OBJECTS];
101 105
      mBlur            = new PostprocessEffectBlur[NUM_OBJECTS];
102 106
      mGlow            = new PostprocessEffectGlow[NUM_OBJECTS];
107
      mBord            = new PostprocessEffectBorder[NUM_OBJECTS];
103 108

  
104 109
      FragmentEffectChroma[] chroma= new FragmentEffectChroma[NUM_OBJECTS];
105 110
      Static3D[] chromaVector      = new Static3D[NUM_OBJECTS];
......
122 127
        moveVector[i]       = new Static3D(OBJECTS[NUM*i  ], OBJECTS[NUM*i+1], OBJECTS[NUM*i+2]);
123 128
        chromaVector[i]     = new Static3D(OBJECTS[NUM*i+3], OBJECTS[NUM*i+4], OBJECTS[NUM*i+5]);
124 129
        mEffectHaloRadius[i]= new Static2D(10,10);
130
        mEffectHalo[i]      = new Static1D(10);
125 131
        mBlur[i]            = new PostprocessEffectBlur(mEffectHaloRadius[i] );
126 132
        mGlow[i]            = new PostprocessEffectGlow(mEffectHaloRadius[i], new Static4D(1.0f,1.0f,1.0f,0.5f) );
133
        mBord[i]            = new PostprocessEffectBorder(mEffectHalo[i], new Static4D(0.0f,0.0f,0.0f,0.5f) );
127 134
        chroma[i]           = new FragmentEffectChroma( new Static1D(0.3f), chromaVector[i]);
128 135
        effects[i]          = new DistortedEffects();
129
        effects[i].apply(mBlur[i]);
130 136
        effects[i].apply(chroma[i]);
131 137
        effects[i].apply(scaleEffectV);
132 138
        effects[i].apply(new MatrixEffectMove(moveVector[i]));
......
134 140
        effects[i].apply(quatEffect1);
135 141
        effects[i].apply( (i==0||i==NUM_OBJECTS-1) ? scaleEffect1 : scaleEffect2 );
136 142

  
137
        mEffectStatus[i] = 1;
143
        mEffectStatus[i] = 0;
138 144
        mNode[i] = new DistortedNode(mTex, effects[i], mesh );
139 145
        mScreen.attach(mNode[i]);
140 146
        }
......
228 234
      if( object>=0 && object<NUM_OBJECTS )
229 235
        {
230 236
        mEffectHaloRadius[object].set(range*0.5f,range*0.5f);
237
        mEffectHalo[object].set(range*0.5f);
231 238
        }
232 239
      }
233 240

  
......
251 258

  
252 259
          if( effect==1 ) mNode[object].getEffects().apply(mBlur[object]);
253 260
          if( effect==2 ) mNode[object].getEffects().apply(mGlow[object]);
261
          if( effect==3 ) mNode[object].getEffects().apply(mBord[object]);
254 262
          }
255 263
        }
256 264
      else
src/main/res/layout/triblurlayout.xml
40 40
        android:orientation="horizontal"
41 41
        android:paddingTop="5dp">
42 42

  
43
        <RadioGroup
44
            android:id="@+id/triblurRadio0"
43
        <Spinner
45 44
            android:layout_width="0dp"
46
            android:layout_height="wrap_content"
47
            android:layout_weight="0.6"
48
            android:orientation="horizontal">
49

  
50
            <RadioButton
51
                android:id="@+id/triblurRadioNone0"
52
                android:layout_width="match_parent"
53
                android:layout_height="wrap_content"
54
                android:layout_weight="1"
55
                android:onClick="effect"
56
                android:text="@string/none"
57
                android:textSize="14sp" />
58

  
59
            <RadioButton
60
                android:id="@+id/triblurRadioBlur0"
61
                android:layout_width="match_parent"
62
                android:layout_height="wrap_content"
63
                android:layout_weight="1"
64
                android:checked="true"
65
                android:onClick="effect"
66
                android:text="@string/blur"
67
                android:textSize="14sp" />
68

  
69
            <RadioButton
70
                android:id="@+id/triblurRadioGlow0"
71
                android:layout_width="match_parent"
72
                android:layout_height="wrap_content"
73
                android:layout_weight="1"
74
                android:onClick="effect"
75
                android:text="@string/glow"
76
                android:textSize="14sp" />
77

  
78
        </RadioGroup>
79

  
45
            android:layout_height="50dp"
46
            android:layout_weight="0.5"
47
            android:id="@+id/triblur_effect0" />
80 48
        <SeekBar
81 49
            android:id="@+id/triblurSeek0"
82 50
            android:layout_width="wrap_content"
83 51
            android:layout_height="fill_parent"
84
            android:layout_weight="0.4"
52
            android:layout_weight="0.5"
85 53
            android:paddingLeft="5dp"
86 54
            android:paddingRight="5dp" />
87 55
    </LinearLayout>
......
93 61
        android:orientation="horizontal"
94 62
        android:paddingTop="5dp">
95 63

  
96
        <RadioGroup
97
            android:id="@+id/triblurRadio1"
64
        <Spinner
98 65
            android:layout_width="0dp"
99
            android:layout_height="wrap_content"
100
            android:layout_weight="0.6"
101
            android:orientation="horizontal">
102

  
103
            <RadioButton
104
                android:id="@+id/triblurRadioNone1"
105
                android:layout_width="match_parent"
106
                android:layout_height="wrap_content"
107
                android:layout_weight="1"
108
                android:onClick="effect"
109
                android:text="@string/none"
110
                android:textSize="14sp" />
111

  
112
            <RadioButton
113
                android:id="@+id/triblurRadioBlur1"
114
                android:layout_width="match_parent"
115
                android:layout_height="wrap_content"
116
                android:layout_weight="1"
117
                android:checked="true"
118
                android:onClick="effect"
119
                android:text="@string/blur"
120
                android:textSize="14sp" />
121

  
122
            <RadioButton
123
                android:id="@+id/triblurRadioGlow1"
124
                android:layout_width="match_parent"
125
                android:layout_height="wrap_content"
126
                android:layout_weight="1"
127
                android:onClick="effect"
128
                android:text="@string/glow"
129
                android:textSize="14sp" />
130

  
131
        </RadioGroup>
132

  
66
            android:layout_height="50dp"
67
            android:layout_weight="0.5"
68
            android:id="@+id/triblur_effect1" />
133 69
        <SeekBar
134 70
            android:id="@+id/triblurSeek1"
135 71
            android:layout_width="wrap_content"
136 72
            android:layout_height="fill_parent"
137
            android:layout_weight="0.4"
73
            android:layout_weight="0.5"
138 74
            android:paddingLeft="5dp"
139 75
            android:paddingRight="5dp" />
140 76
    </LinearLayout>
......
146 82
        android:orientation="horizontal"
147 83
        android:paddingTop="5dp">
148 84

  
149
        <RadioGroup
150
            android:id="@+id/triblurRadio2"
85
        <Spinner
151 86
            android:layout_width="0dp"
152
            android:layout_height="wrap_content"
153
            android:layout_weight="0.6"
154
            android:orientation="horizontal">
155

  
156
            <RadioButton
157
                android:id="@+id/triblurRadioNone2"
158
                android:layout_width="match_parent"
159
                android:layout_height="wrap_content"
160
                android:layout_weight="1"
161
                android:onClick="effect"
162
                android:text="@string/none"
163
                android:textSize="14sp" />
164

  
165
            <RadioButton
166
                android:id="@+id/triblurRadioBlur2"
167
                android:layout_width="match_parent"
168
                android:layout_height="wrap_content"
169
                android:layout_weight="1"
170
                android:checked="true"
171
                android:onClick="effect"
172
                android:text="@string/blur"
173
                android:textSize="14sp" />
174

  
175
            <RadioButton
176
                android:id="@+id/triblurRadioGlow2"
177
                android:layout_width="match_parent"
178
                android:layout_height="wrap_content"
179
                android:layout_weight="1"
180
                android:onClick="effect"
181
                android:text="@string/glow"
182
                android:textSize="14sp" />
183

  
184
        </RadioGroup>
185

  
87
            android:layout_height="50dp"
88
            android:layout_weight="0.5"
89
            android:id="@+id/triblur_effect2" />
186 90
        <SeekBar
187 91
            android:id="@+id/triblurSeek2"
188 92
            android:layout_width="wrap_content"
189 93
            android:layout_height="fill_parent"
190
            android:layout_weight="0.4"
94
            android:layout_weight="0.5"
191 95
            android:paddingLeft="5dp"
192 96
            android:paddingRight="5dp" />
193 97
    </LinearLayout>

Also available in: Unified diff