Project

General

Profile

Download (13.8 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / aroundtheworld / AroundTheWorldEffectsManager.java @ 9e7b6dbd

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.aroundtheworld;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

    
24
import org.distorted.library.effect.FragmentEffectChroma;
25
import org.distorted.library.effect.FragmentEffectContrast;
26
import org.distorted.library.effect.VertexEffectDistort;
27
import org.distorted.library.effect.VertexEffectPinch;
28
import org.distorted.library.effect.VertexEffectSink;
29
import org.distorted.library.effect.VertexEffectSwirl;
30
import org.distorted.library.main.DistortedEffects;
31
import org.distorted.library.type.Dynamic1D;
32
import org.distorted.library.type.Dynamic2D;
33
import org.distorted.library.type.Dynamic3D;
34
import org.distorted.library.type.Static1D;
35
import org.distorted.library.type.Static2D;
36
import org.distorted.library.type.Static3D;
37
import org.distorted.library.type.Static4D;
38

    
39
class AroundTheWorldEffectsManager
40
  {
41
  private float mWhiteness, mBlackness, mAsianness;  // those always sum up to 1
42

    
43
  // WHITENESS
44
  // Vertex effects:
45
  // a) make the lips smaller (SINK)
46
  private Static4D wLipsRegion;
47
  private Static3D wLipsCenter;
48
  private Static1D wLipsFactor;
49
  private Dynamic1D wLipsDyn;
50

    
51
  // ASIANNESS
52
  // Vertex Effects:
53
  // a) move lips & nose higher (DISTORT)
54
  private Static4D aLipsNoseRegion;
55
  private Static3D aLipsNoseCenter;
56
  private Static3D aLipsNoseFactor;
57
  private Dynamic3D aLipsNoseDyn;
58
  // b) make the nose broader (PINCH)
59
  private Static4D aNoseBroaderRegion;
60
  private Static3D aNoseBroaderCenter;
61
  private Static2D aNoseBroaderFactor;
62
  private Dynamic2D aNoseBroaderDyn;
63
  // c) make the nostrils more visible (DISTORT)
64
  private Static4D aNostrilsRegion;
65
  private Static3D aNostrilsCenter;
66
  private Static3D aNostrilsFactor;
67
  private Dynamic3D aNostrilsDyn;
68
  // d) rotate eyes (2 x SWIRL)
69
  private Static4D aEyesRegion;
70
  private Static3D aLEyeCenter, aREyeCenter;
71
  private Static1D aLEyeFactor, aREyeFactor;
72
  private Dynamic1D aLEyeDyn, aREyeDyn;
73
  // e) move eyebrow higher (DISTORT)
74
  private Static4D aEyebrowsRegion;
75
  private Static3D aEyebrowsCenter;
76
  private Static3D aEyebrowsFactor;
77
  private Dynamic3D aEyebrowsDyn;
78

    
79
  // Fragment effects:
80
  // a) change color of the skin to more brown and less red (CHROMA)
81
  private Static4D aSkinColorRegion;
82
  private Static3D aChromaSkin;
83
  private Static1D aChromaSkinFactor;
84
  private Dynamic1D aChromaSkinDyn;
85
  // b) darken both eyes (2 x SMOOTH_CHROMA)
86
  private Static4D aLEyeColorRegion, aREyeColorRegion;
87
  private Static3D aChromaEyes;
88
  private Static1D aChromaEyesFactor;
89
  private Dynamic1D aChromaEyesDyn;
90

    
91
  // BLACKNESS
92
  // Vertex Effects
93
  // a) make the whole face broader (PINCH)
94
  private Static4D bFaceRegion;
95
  private Static3D bFaceCenter;
96
  private Static2D bFaceFactor;
97
  private Dynamic2D bFaceDyn;
98
  // b) tip of the nose lower (DISTORT)
99
  private Static4D bTipLowerRegion;
100
  private Static3D bTipLowerCenter;
101
  private Static3D bTipLowerFactor;
102
  private Dynamic3D bTipLowerDyn;
103
  // c) broaden the whole nose: (PINCH)
104
  private Static4D bWholeNoseRegion;
105
  private Static3D bWholeNoseCenter;
106
  private Static2D bWholeNoseFactor;
107
  private Dynamic2D bWholeNoseDyn;
108
  // d) broaden the tip of the nose some more: (PINCH)
109
  private Static4D bNoseBroaderRegion;
110
  private Static3D bNoseBroaderCenter;
111
  private Static2D bNoseBroaderFactor;
112
  private Dynamic2D bNoseBroaderDyn;
113
  // 3) make lips higher: (PINCH)
114
  private Static4D bLipsRegion;
115
  private Static3D bLipsCenter;
116
  private Static2D bLipsFactor;
117
  private Dynamic2D bLipsDyn;
118
  // Fragment effects
119
  // a) make the whole face darker (CHROMA)
120
  private Static4D bSkinColorRegion;
121
  private Static3D bChromaSkin;
122
  private Static1D bChromaSkinFactor;
123
  private Dynamic1D bChromaSkinDyn;
124
  // b) move both eyes back to whiteness (2 x SMOOTH CHROMA)
125
  private Static4D bLEyeColorRegion, bREyeColorRegion;
126
  private Static3D bChromaEyes;
127
  private Static1D bChromaEyesFactor;
128
  private Dynamic1D bChromaEyesDyn;
129
  // c) darken both pupils (2 x SMOOTH_CHROMA)
130
  private Static4D bLPupilColorRegion, bRPupilColorRegion;
131
  private Static3D bChromaPupil;
132
  private Static1D bChromaPupilFactor;
133
  private Dynamic1D bChromaPupilDyn;
134
  // d) all those chroma effects have reduced contrast - bring it back
135
  private Static1D bContrastFactor;
136
  private Dynamic1D bContrastDyn;
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  AroundTheWorldEffectsManager()
141
    {
142
    mWhiteness = 1;
143
    mBlackness = 0;
144
    mAsianness = 0;
145

    
146
    // WHITENESS
147
    // Vertex Effects
148
    wLipsRegion = new Static4D(0,0,0,100);
149
    wLipsCenter = new Static3D(300,500,0);
150
    wLipsFactor = new Static1D(0.7f);
151
    wLipsDyn    = new Dynamic1D();
152
    wLipsDyn.add(wLipsFactor);
153

    
154
    // ASIANNESS
155
    // Vertex Effects
156
    aLipsNoseRegion    = new Static4D(0,0,0,267);
157
    aLipsNoseCenter    = new Static3D(300,560,0);
158
    aLipsNoseDyn       = new Dynamic3D();
159
    aLipsNoseFactor    = new Static3D(0,0,0);
160
    aLipsNoseDyn.add(aLipsNoseFactor);
161

    
162
    aNoseBroaderRegion = new Static4D(0,0,0,130);
163
    aNoseBroaderCenter = new Static3D(300,307,0);
164
    aNoseBroaderDyn    = new Dynamic2D();
165
    aNoseBroaderFactor = new Static2D(0,90);
166
    aNoseBroaderDyn.add(aNoseBroaderFactor);
167

    
168
    aNostrilsRegion    = new Static4D(0,0,0,60);
169
    aNostrilsCenter    = new Static3D(300,336,0);
170
    aNostrilsDyn       = new Dynamic3D();
171
    aNostrilsFactor    = new Static3D(0,0,0);
172
    aNostrilsDyn.add(aNostrilsFactor);
173

    
174
    aEyesRegion        = new Static4D(0,0,0,83);
175
    aLEyeCenter        = new Static3D(176,230,0);
176
    aREyeCenter        = new Static3D(420,230,0);
177
    aLEyeDyn           = new Dynamic1D();
178
    aREyeDyn           = new Dynamic1D();
179
    aLEyeFactor        = new Static1D(0);
180
    aREyeFactor        = new Static1D(0);
181
    aLEyeDyn.add(aLEyeFactor);
182
    aREyeDyn.add(aREyeFactor);
183

    
184
    aEyebrowsRegion    = new Static4D(0,0,0,142);
185
    aEyebrowsCenter    = new Static3D(300,100,0);
186
    aEyebrowsDyn       = new Dynamic3D();
187
    aEyebrowsFactor    = new Static3D(0,0,0);
188
    aEyebrowsDyn.add(aEyebrowsFactor);
189

    
190
    // Fragment Effects
191
    aSkinColorRegion   = new Static4D(300,300,600,600);
192
    aLEyeColorRegion   = new Static4D(172,230,29,25);
193
    aREyeColorRegion   = new Static4D(423,230,29,25);
194

    
195
    aChromaSkin        = new Static3D(0.5f, 0.5f, 0.5f);
196
    aChromaEyes        = new Static3D(0.5f, 0.14f, 0.14f);
197
    aChromaSkinFactor  = new Static1D(0.0f);
198
    aChromaEyesFactor  = new Static1D(0.0f);
199

    
200
    aChromaSkinDyn = new Dynamic1D();
201
    aChromaSkinDyn.add(aChromaSkinFactor);
202
    aChromaEyesDyn = new Dynamic1D();
203
    aChromaEyesDyn.add(aChromaEyesFactor);
204

    
205
    // BLACKNESS
206
    // Vertex Effects
207
    bFaceRegion        = new Static4D(0,0,0,600);
208
    bFaceCenter        = new Static3D(300,300,0);
209
    bFaceFactor        = new Static2D(1.0f,90.0f);
210
    bFaceDyn           = new Dynamic2D();
211
    bFaceDyn.add(bFaceFactor);
212

    
213
    bTipLowerRegion    = new Static4D(0,0,0,41);
214
    bTipLowerCenter    = new Static3D(300,393,0);
215
    bTipLowerFactor    = new Static3D(0,0,0);
216
    bTipLowerDyn       = new Dynamic3D();
217
    bTipLowerDyn.add(bTipLowerFactor);
218

    
219
    bWholeNoseRegion   = new Static4D(0,0,0,130);
220
    bWholeNoseCenter   = new Static3D(300,357,0);
221
    bWholeNoseFactor   = new Static2D(1.0f,90.0f);
222
    bWholeNoseDyn      = new Dynamic2D();
223
    bWholeNoseDyn.add(bWholeNoseFactor);
224

    
225
    bNoseBroaderRegion = new Static4D(0,0,0,95);
226
    bNoseBroaderCenter = new Static3D(300,408,0);
227
    bNoseBroaderFactor = new Static2D(1.0f,90.0f);
228
    bNoseBroaderDyn    = new Dynamic2D();
229
    bNoseBroaderDyn.add(bNoseBroaderFactor);
230

    
231
    bLipsRegion        = new Static4D(0,96,0,118);
232
    bLipsCenter        = new Static3D(300,458,0);
233
    bLipsFactor        = new Static2D(1.0f,0.0f);
234
    bLipsDyn           = new Dynamic2D();
235
    bLipsDyn.add(bLipsFactor);
236

    
237
    // Fragment Effects
238
    bSkinColorRegion   = new Static4D(300,300,600,600);
239
    bLEyeColorRegion = new Static4D(158,241,55,24);
240
    bREyeColorRegion = new Static4D(436,241,55,24);
241
    bLPupilColorRegion   = new Static4D(166,230,28,23);
242
    bRPupilColorRegion   = new Static4D(431,230,28,23);
243

    
244
    bChromaSkin        = new Static3D(0.4f, 0.25f, 0.25f);
245
    bChromaEyes        = new Static3D(1.0f, 1.0f, 1.0f);
246
    bChromaPupil       = new Static3D(0.4f, 0.14f, 0.14f);
247
    bChromaSkinFactor  = new Static1D(0.0f);
248
    bChromaPupilFactor = new Static1D(0.0f);
249
    bChromaEyesFactor  = new Static1D(0.0f);
250
    bContrastFactor    = new Static1D(0.0f);
251

    
252
    bChromaSkinDyn = new Dynamic1D();
253
    bChromaSkinDyn.add(bChromaSkinFactor);
254
    bChromaEyesDyn = new Dynamic1D();
255
    bChromaEyesDyn.add(bChromaEyesFactor);
256
    bChromaPupilDyn = new Dynamic1D();
257
    bChromaPupilDyn.add(bChromaPupilFactor);
258
    bContrastDyn = new Dynamic1D();
259
    bContrastDyn.add(bContrastFactor);
260
    }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
  synchronized void apply(DistortedEffects effects)
265
    {
266
    setRace(mBlackness, mAsianness);
267

    
268
    // WHITENESS
269
    effects.apply( new VertexEffectSink(wLipsDyn, wLipsCenter, wLipsRegion) );
270

    
271
    // ASIANNESS
272
    effects.apply( new VertexEffectDistort(aLipsNoseDyn, aLipsNoseCenter, aLipsNoseRegion) );
273
    effects.apply( new VertexEffectPinch(aNoseBroaderDyn, aNoseBroaderCenter, aNoseBroaderRegion) );
274
    effects.apply( new VertexEffectDistort( aNostrilsDyn, aNostrilsCenter, aNostrilsRegion) );
275
    effects.apply( new VertexEffectSwirl( aLEyeDyn, aLEyeCenter, aEyesRegion) );
276
    effects.apply( new VertexEffectSwirl( aREyeDyn, aREyeCenter, aEyesRegion) );
277
    effects.apply( new VertexEffectDistort( aEyebrowsDyn, aEyebrowsCenter, aEyebrowsRegion) );
278

    
279
    effects.apply( new FragmentEffectChroma( aChromaSkinDyn, aChromaSkin, aSkinColorRegion, false) );
280
    effects.apply( new FragmentEffectChroma( aChromaEyesDyn, aChromaEyes, aLEyeColorRegion, true ) );
281
    effects.apply( new FragmentEffectChroma( aChromaEyesDyn, aChromaEyes, aREyeColorRegion, true ) );
282

    
283
    // BLACKNESS
284
    effects.apply( new VertexEffectPinch( bFaceDyn, bFaceCenter, bFaceRegion ) );
285
    effects.apply( new VertexEffectDistort( bTipLowerDyn, bTipLowerCenter, bTipLowerRegion ) );
286
    effects.apply( new VertexEffectPinch( bWholeNoseDyn, bWholeNoseCenter, bWholeNoseRegion ) );
287
    effects.apply( new VertexEffectPinch( bNoseBroaderDyn, bNoseBroaderCenter, bNoseBroaderRegion ) );
288
    effects.apply( new VertexEffectPinch( bLipsDyn, bLipsCenter, bLipsRegion ) );
289

    
290
    effects.apply( new FragmentEffectChroma( bChromaSkinDyn, bChromaSkin, bSkinColorRegion, false ) );
291
    effects.apply( new FragmentEffectChroma( bChromaEyesDyn, bChromaEyes, bLEyeColorRegion, true  ) );
292
    effects.apply( new FragmentEffectChroma( bChromaEyesDyn, bChromaEyes, bREyeColorRegion, true  ) );
293
    effects.apply( new FragmentEffectChroma( bChromaPupilDyn, bChromaPupil, bLPupilColorRegion, true) );
294
    effects.apply( new FragmentEffectChroma( bChromaPupilDyn, bChromaPupil, bRPupilColorRegion, true) );
295

    
296
    effects.apply( new FragmentEffectContrast(bContrastDyn) );
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
  synchronized void setRace(float blackness, float asianness)
302
    {
303
    mWhiteness = 1 - blackness - asianness;
304
    mAsianness = asianness;
305
    mBlackness = blackness;
306

    
307
    //android.util.Log.e("manager", "blackness="+blackness+" asianness="+asianness);
308

    
309
    // WHITENESS
310
    wLipsFactor.set(1.0f-0.3f*mWhiteness);
311

    
312
    // ASIANNESS
313
    aLipsNoseFactor.set2(-23.0f*mAsianness);
314
    aNoseBroaderFactor.set1(1.0f+0.85f*mAsianness);
315
    aNostrilsFactor.set2(-12.0f*mAsianness);
316
    aLEyeFactor.set(+10.0f*mAsianness);
317
    aREyeFactor.set(-10.0f*mAsianness);
318
    aEyebrowsFactor.set2(-40.0f*mAsianness);
319

    
320
    aChromaSkinFactor.set(0.2f*mAsianness);
321
    aChromaEyesFactor.set(0.7f*mAsianness);
322

    
323
    // BLACKNESS
324
    bFaceFactor.set1(1.0f + 0.1f*mBlackness);
325
    bTipLowerFactor.set2(23.0f*mBlackness);
326
    bWholeNoseFactor.set1(1.0f+0.5f*mBlackness);
327
    bNoseBroaderFactor.set1(1.0f+0.38f*mBlackness);
328
    bLipsFactor.set1(1.0f+1.0f*mBlackness);
329

    
330
    bChromaSkinFactor.set(0.75f*mBlackness);
331
    bChromaEyesFactor.set(0.2f*mBlackness);
332
    bChromaPupilFactor.set(0.6f*mBlackness);
333

    
334
    bContrastFactor.set(1.0f+1.5f*mBlackness);
335
    }
336
  }
(2-2/6)