Project

General

Profile

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

examples / src / main / java / org / distorted / examples / aroundtheworld / AroundTheWorldEffectsManager.java @ 1585ba24

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 Static3D aSkinColorCenter;
82
  private Static3D aSkinColorRegion;
83
  private Static3D aChromaSkin;
84
  private Static1D aChromaSkinFactor;
85
  private Dynamic1D aChromaSkinDyn;
86
  // b) darken both eyes (2 x SMOOTH_CHROMA)
87
  private Static3D aLEyeColorCenter, aREyeColorCenter;
88
  private Static3D aLEyeColorRegion, aREyeColorRegion;
89
  private Static3D aChromaEyes;
90
  private Static1D aChromaEyesFactor;
91
  private Dynamic1D aChromaEyesDyn;
92

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

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  AroundTheWorldEffectsManager()
146
    {
147
    mWhiteness = 1;
148
    mBlackness = 0;
149
    mAsianness = 0;
150

    
151
    // WHITENESS
152
    // Vertex Effects
153
    wLipsRegion = new Static4D(0,0,0,100);
154
    wLipsCenter = new Static3D(300,500,0);
155
    wLipsFactor = new Static1D(0.7f);
156
    wLipsDyn    = new Dynamic1D();
157
    wLipsDyn.add(wLipsFactor);
158

    
159
    // ASIANNESS
160
    // Vertex Effects
161
    aLipsNoseRegion    = new Static4D(0,0,0,267);
162
    aLipsNoseCenter    = new Static3D(300,560,0);
163
    aLipsNoseDyn       = new Dynamic3D();
164
    aLipsNoseFactor    = new Static3D(0,0,0);
165
    aLipsNoseDyn.add(aLipsNoseFactor);
166

    
167
    aNoseBroaderRegion = new Static4D(0,0,0,130);
168
    aNoseBroaderCenter = new Static3D(300,307,0);
169
    aNoseBroaderDyn    = new Dynamic2D();
170
    aNoseBroaderFactor = new Static2D(0,90);
171
    aNoseBroaderDyn.add(aNoseBroaderFactor);
172

    
173
    aNostrilsRegion    = new Static4D(0,0,0,60);
174
    aNostrilsCenter    = new Static3D(300,336,0);
175
    aNostrilsDyn       = new Dynamic3D();
176
    aNostrilsFactor    = new Static3D(0,0,0);
177
    aNostrilsDyn.add(aNostrilsFactor);
178

    
179
    aEyesRegion        = new Static4D(0,0,0,83);
180
    aLEyeCenter        = new Static3D(176,230,0);
181
    aREyeCenter        = new Static3D(420,230,0);
182
    aLEyeDyn           = new Dynamic1D();
183
    aREyeDyn           = new Dynamic1D();
184
    aLEyeFactor        = new Static1D(0);
185
    aREyeFactor        = new Static1D(0);
186
    aLEyeDyn.add(aLEyeFactor);
187
    aREyeDyn.add(aREyeFactor);
188

    
189
    aEyebrowsRegion    = new Static4D(0,0,0,142);
190
    aEyebrowsCenter    = new Static3D(300,100,0);
191
    aEyebrowsDyn       = new Dynamic3D();
192
    aEyebrowsFactor    = new Static3D(0,0,0);
193
    aEyebrowsDyn.add(aEyebrowsFactor);
194

    
195
    // Fragment Effects
196
    aSkinColorCenter   = new Static3D(300,300,0);
197
    aSkinColorRegion   = new Static3D(600,600,600);
198
    aLEyeColorCenter   = new Static3D(172,230,0);
199
    aLEyeColorRegion   = new Static3D(29,25,25);
200
    aREyeColorCenter   = new Static3D(423,230,0);
201
    aREyeColorRegion   = new Static3D(29,25,25);
202

    
203
    aChromaSkin        = new Static3D(0.5f, 0.5f, 0.5f);
204
    aChromaEyes        = new Static3D(0.5f, 0.14f, 0.14f);
205
    aChromaSkinFactor  = new Static1D(0.0f);
206
    aChromaEyesFactor  = new Static1D(0.0f);
207

    
208
    aChromaSkinDyn = new Dynamic1D();
209
    aChromaSkinDyn.add(aChromaSkinFactor);
210
    aChromaEyesDyn = new Dynamic1D();
211
    aChromaEyesDyn.add(aChromaEyesFactor);
212

    
213
    // BLACKNESS
214
    // Vertex Effects
215
    bFaceRegion        = new Static4D(0,0,0,600);
216
    bFaceCenter        = new Static3D(300,300,0);
217
    bFaceFactor        = new Static2D(1.0f,90.0f);
218
    bFaceDyn           = new Dynamic2D();
219
    bFaceDyn.add(bFaceFactor);
220

    
221
    bTipLowerRegion    = new Static4D(0,0,0,41);
222
    bTipLowerCenter    = new Static3D(300,393,0);
223
    bTipLowerFactor    = new Static3D(0,0,0);
224
    bTipLowerDyn       = new Dynamic3D();
225
    bTipLowerDyn.add(bTipLowerFactor);
226

    
227
    bWholeNoseRegion   = new Static4D(0,0,0,130);
228
    bWholeNoseCenter   = new Static3D(300,357,0);
229
    bWholeNoseFactor   = new Static2D(1.0f,90.0f);
230
    bWholeNoseDyn      = new Dynamic2D();
231
    bWholeNoseDyn.add(bWholeNoseFactor);
232

    
233
    bNoseBroaderRegion = new Static4D(0,0,0,95);
234
    bNoseBroaderCenter = new Static3D(300,408,0);
235
    bNoseBroaderFactor = new Static2D(1.0f,90.0f);
236
    bNoseBroaderDyn    = new Dynamic2D();
237
    bNoseBroaderDyn.add(bNoseBroaderFactor);
238

    
239
    bLipsRegion        = new Static4D(0,96,0,118);
240
    bLipsCenter        = new Static3D(300,458,0);
241
    bLipsFactor        = new Static2D(1.0f,0.0f);
242
    bLipsDyn           = new Dynamic2D();
243
    bLipsDyn.add(bLipsFactor);
244

    
245
    // Fragment Effects
246
    bSkinColorCenter     = new Static3D(300,300,0);
247
    bSkinColorRegion     = new Static3D(600,600,600);
248
    bLEyeColorCenter     = new Static3D(158,241,0);
249
    bLEyeColorRegion     = new Static3D(55,24,50);
250
    bREyeColorCenter     = new Static3D(436,241,0);
251
    bREyeColorRegion     = new Static3D(55,24,50);
252
    bLPupilColorCenter   = new Static3D(166,230,0);
253
    bLPupilColorRegion   = new Static3D(28,23,25);
254
    bRPupilColorCenter   = new Static3D(431,230,0);
255
    bRPupilColorRegion   = new Static3D(28,23,25);
256

    
257
    bChromaSkin        = new Static3D(0.4f, 0.25f, 0.25f);
258
    bChromaEyes        = new Static3D(1.0f, 1.0f, 1.0f);
259
    bChromaPupil       = new Static3D(0.4f, 0.14f, 0.14f);
260
    bChromaSkinFactor  = new Static1D(0.0f);
261
    bChromaPupilFactor = new Static1D(0.0f);
262
    bChromaEyesFactor  = new Static1D(0.0f);
263
    bContrastFactor    = new Static1D(0.0f);
264

    
265
    bChromaSkinDyn = new Dynamic1D();
266
    bChromaSkinDyn.add(bChromaSkinFactor);
267
    bChromaEyesDyn = new Dynamic1D();
268
    bChromaEyesDyn.add(bChromaEyesFactor);
269
    bChromaPupilDyn = new Dynamic1D();
270
    bChromaPupilDyn.add(bChromaPupilFactor);
271
    bContrastDyn = new Dynamic1D();
272
    bContrastDyn.add(bContrastFactor);
273
    }
274

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

    
277
  synchronized void apply(DistortedEffects effects)
278
    {
279
    setRace(mBlackness, mAsianness);
280

    
281
    // WHITENESS
282
    effects.apply( new VertexEffectSink(wLipsDyn, wLipsCenter, wLipsRegion) );
283

    
284
    // ASIANNESS
285
    effects.apply( new VertexEffectDistort(aLipsNoseDyn   , aLipsNoseCenter   , aLipsNoseRegion   ) );
286
    effects.apply( new VertexEffectPinch  (aNoseBroaderDyn, aNoseBroaderCenter, aNoseBroaderRegion) );
287
    effects.apply( new VertexEffectDistort( aNostrilsDyn  , aNostrilsCenter   , aNostrilsRegion   ) );
288
    effects.apply( new VertexEffectSwirl  ( aLEyeDyn      , aLEyeCenter       , aEyesRegion       ) );
289
    effects.apply( new VertexEffectSwirl  ( aREyeDyn      , aREyeCenter       , aEyesRegion       ) );
290
    effects.apply( new VertexEffectDistort( aEyebrowsDyn  , aEyebrowsCenter   , aEyebrowsRegion   ) );
291

    
292
    effects.apply( new FragmentEffectChroma( aChromaSkinDyn, aChromaSkin, aSkinColorCenter, aSkinColorRegion, false) );
293
    effects.apply( new FragmentEffectChroma( aChromaEyesDyn, aChromaEyes, aLEyeColorCenter, aLEyeColorRegion, true ) );
294
    effects.apply( new FragmentEffectChroma( aChromaEyesDyn, aChromaEyes, aREyeColorCenter, aREyeColorRegion, true ) );
295

    
296
    // BLACKNESS
297
    effects.apply( new VertexEffectPinch  ( bFaceDyn       , bFaceCenter       , bFaceRegion        ) );
298
    effects.apply( new VertexEffectDistort( bTipLowerDyn   , bTipLowerCenter   , bTipLowerRegion    ) );
299
    effects.apply( new VertexEffectPinch  ( bWholeNoseDyn  , bWholeNoseCenter  , bWholeNoseRegion   ) );
300
    effects.apply( new VertexEffectPinch  ( bNoseBroaderDyn, bNoseBroaderCenter, bNoseBroaderRegion ) );
301
    effects.apply( new VertexEffectPinch  ( bLipsDyn       , bLipsCenter       , bLipsRegion        ) );
302

    
303
    effects.apply( new FragmentEffectChroma( bChromaSkinDyn , bChromaSkin , bSkinColorCenter  , bSkinColorRegion  , false ) );
304
    effects.apply( new FragmentEffectChroma( bChromaEyesDyn , bChromaEyes , bLEyeColorCenter  , bLEyeColorRegion  , true  ) );
305
    effects.apply( new FragmentEffectChroma( bChromaEyesDyn , bChromaEyes , bREyeColorCenter  , bREyeColorRegion  , true  ) );
306
    effects.apply( new FragmentEffectChroma( bChromaPupilDyn, bChromaPupil, bLPupilColorCenter, bLPupilColorRegion, true  ) );
307
    effects.apply( new FragmentEffectChroma( bChromaPupilDyn, bChromaPupil, bRPupilColorCenter, bRPupilColorRegion, true  ) );
308

    
309
    effects.apply( new FragmentEffectContrast(bContrastDyn) );
310
    }
311

    
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

    
314
  synchronized void setRace(float blackness, float asianness)
315
    {
316
    mWhiteness = 1 - blackness - asianness;
317
    mAsianness = asianness;
318
    mBlackness = blackness;
319

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

    
322
    // WHITENESS
323
    wLipsFactor.set(1.0f-0.3f*mWhiteness);
324

    
325
    // ASIANNESS
326
    aLipsNoseFactor.set2(-23.0f*mAsianness);
327
    aNoseBroaderFactor.set1(1.0f+0.85f*mAsianness);
328
    aNostrilsFactor.set2(-12.0f*mAsianness);
329
    aLEyeFactor.set(+10.0f*mAsianness);
330
    aREyeFactor.set(-10.0f*mAsianness);
331
    aEyebrowsFactor.set2(-40.0f*mAsianness);
332

    
333
    aChromaSkinFactor.set(0.2f*mAsianness);
334
    aChromaEyesFactor.set(0.7f*mAsianness);
335

    
336
    // BLACKNESS
337
    bFaceFactor.set1(1.0f + 0.1f*mBlackness);
338
    bTipLowerFactor.set2(23.0f*mBlackness);
339
    bWholeNoseFactor.set1(1.0f+0.5f*mBlackness);
340
    bNoseBroaderFactor.set1(1.0f+0.38f*mBlackness);
341
    bLipsFactor.set1(1.0f+1.0f*mBlackness);
342

    
343
    bChromaSkinFactor.set(0.75f*mBlackness);
344
    bChromaEyesFactor.set(0.2f*mBlackness);
345
    bChromaPupilFactor.set(0.6f*mBlackness);
346

    
347
    bContrastFactor.set(1.0f+1.5f*mBlackness);
348
    }
349
  }
(2-2/6)