Project

General

Profile

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

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

1 7ba38011 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 fa9b6494 Leszek Koltunski
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 01782e85 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
31 4b34bb08 Leszek Koltunski
import org.distorted.library.type.Dynamic1D;
32
import org.distorted.library.type.Dynamic2D;
33 7ba38011 Leszek Koltunski
import org.distorted.library.type.Dynamic3D;
34 4b34bb08 Leszek Koltunski
import org.distorted.library.type.Static1D;
35
import org.distorted.library.type.Static2D;
36 7ba38011 Leszek Koltunski
import org.distorted.library.type.Static3D;
37
import org.distorted.library.type.Static4D;
38
39
class AroundTheWorldEffectsManager
40
  {
41 b3a555a7 Leszek Koltunski
  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 04fe7f80 Leszek Koltunski
  private Static4D wLipsRegion;
47
  private Static3D wLipsCenter;
48 b3a555a7 Leszek Koltunski
  private Static1D wLipsFactor;
49
  private Dynamic1D wLipsDyn;
50
51
  // ASIANNESS
52
  // Vertex Effects:
53
  // a) move lips & nose higher (DISTORT)
54 04fe7f80 Leszek Koltunski
  private Static4D aLipsNoseRegion;
55
  private Static3D aLipsNoseCenter;
56 b3a555a7 Leszek Koltunski
  private Static3D aLipsNoseFactor;
57
  private Dynamic3D aLipsNoseDyn;
58
  // b) make the nose broader (PINCH)
59 04fe7f80 Leszek Koltunski
  private Static4D aNoseBroaderRegion;
60
  private Static3D aNoseBroaderCenter;
61 b3a555a7 Leszek Koltunski
  private Static2D aNoseBroaderFactor;
62
  private Dynamic2D aNoseBroaderDyn;
63
  // c) make the nostrils more visible (DISTORT)
64 04fe7f80 Leszek Koltunski
  private Static4D aNostrilsRegion;
65
  private Static3D aNostrilsCenter;
66 b3a555a7 Leszek Koltunski
  private Static3D aNostrilsFactor;
67
  private Dynamic3D aNostrilsDyn;
68
  // d) rotate eyes (2 x SWIRL)
69 04fe7f80 Leszek Koltunski
  private Static4D aEyesRegion;
70
  private Static3D aLEyeCenter, aREyeCenter;
71 b3a555a7 Leszek Koltunski
  private Static1D aLEyeFactor, aREyeFactor;
72
  private Dynamic1D aLEyeDyn, aREyeDyn;
73
  // e) move eyebrow higher (DISTORT)
74 04fe7f80 Leszek Koltunski
  private Static4D aEyebrowsRegion;
75
  private Static3D aEyebrowsCenter;
76 b3a555a7 Leszek Koltunski
  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 1585ba24 Leszek Koltunski
  private Static3D aSkinColorCenter;
82
  private Static3D aSkinColorRegion;
83 b3a555a7 Leszek Koltunski
  private Static3D aChromaSkin;
84
  private Static1D aChromaSkinFactor;
85
  private Dynamic1D aChromaSkinDyn;
86
  // b) darken both eyes (2 x SMOOTH_CHROMA)
87 1585ba24 Leszek Koltunski
  private Static3D aLEyeColorCenter, aREyeColorCenter;
88
  private Static3D aLEyeColorRegion, aREyeColorRegion;
89 b3a555a7 Leszek Koltunski
  private Static3D aChromaEyes;
90
  private Static1D aChromaEyesFactor;
91
  private Dynamic1D aChromaEyesDyn;
92
93
  // BLACKNESS
94 04fe7f80 Leszek Koltunski
  // 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 1585ba24 Leszek Koltunski
  private Static3D bSkinColorCenter;
123
  private Static3D bSkinColorRegion;
124 04fe7f80 Leszek Koltunski
  private Static3D bChromaSkin;
125
  private Static1D bChromaSkinFactor;
126
  private Dynamic1D bChromaSkinDyn;
127
  // b) move both eyes back to whiteness (2 x SMOOTH CHROMA)
128 1585ba24 Leszek Koltunski
  private Static3D bLEyeColorCenter, bREyeColorCenter;
129
  private Static3D bLEyeColorRegion, bREyeColorRegion;
130 04fe7f80 Leszek Koltunski
  private Static3D bChromaEyes;
131
  private Static1D bChromaEyesFactor;
132
  private Dynamic1D bChromaEyesDyn;
133
  // c) darken both pupils (2 x SMOOTH_CHROMA)
134 1585ba24 Leszek Koltunski
  private Static3D bLPupilColorCenter, bRPupilColorCenter;
135
  private Static3D bLPupilColorRegion, bRPupilColorRegion;
136 04fe7f80 Leszek Koltunski
  private Static3D bChromaPupil;
137
  private Static1D bChromaPupilFactor;
138
  private Dynamic1D bChromaPupilDyn;
139 287a5475 Leszek Koltunski
  // d) all those chroma effects have reduced contrast - bring it back
140
  private Static1D bContrastFactor;
141
  private Dynamic1D bContrastDyn;
142 4b34bb08 Leszek Koltunski
143 7ba38011 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
144
145 2f20ae3a Leszek Koltunski
  AroundTheWorldEffectsManager()
146 7ba38011 Leszek Koltunski
    {
147 b3a555a7 Leszek Koltunski
    mWhiteness = 1;
148 2f20ae3a Leszek Koltunski
    mBlackness = 0;
149
    mAsianness = 0;
150 7ba38011 Leszek Koltunski
151 b3a555a7 Leszek Koltunski
    // WHITENESS
152
    // Vertex Effects
153 9e7b6dbd Leszek Koltunski
    wLipsRegion = new Static4D(0,0,0,100);
154 04fe7f80 Leszek Koltunski
    wLipsCenter = new Static3D(300,500,0);
155 b3a555a7 Leszek Koltunski
    wLipsFactor = new Static1D(0.7f);
156
    wLipsDyn    = new Dynamic1D();
157
    wLipsDyn.add(wLipsFactor);
158
159
    // ASIANNESS
160
    // Vertex Effects
161 9e7b6dbd Leszek Koltunski
    aLipsNoseRegion    = new Static4D(0,0,0,267);
162 04fe7f80 Leszek Koltunski
    aLipsNoseCenter    = new Static3D(300,560,0);
163 b3a555a7 Leszek Koltunski
    aLipsNoseDyn       = new Dynamic3D();
164
    aLipsNoseFactor    = new Static3D(0,0,0);
165
    aLipsNoseDyn.add(aLipsNoseFactor);
166
167 9e7b6dbd Leszek Koltunski
    aNoseBroaderRegion = new Static4D(0,0,0,130);
168 04fe7f80 Leszek Koltunski
    aNoseBroaderCenter = new Static3D(300,307,0);
169 b3a555a7 Leszek Koltunski
    aNoseBroaderDyn    = new Dynamic2D();
170
    aNoseBroaderFactor = new Static2D(0,90);
171
    aNoseBroaderDyn.add(aNoseBroaderFactor);
172
173 9e7b6dbd Leszek Koltunski
    aNostrilsRegion    = new Static4D(0,0,0,60);
174 04fe7f80 Leszek Koltunski
    aNostrilsCenter    = new Static3D(300,336,0);
175 b3a555a7 Leszek Koltunski
    aNostrilsDyn       = new Dynamic3D();
176
    aNostrilsFactor    = new Static3D(0,0,0);
177
    aNostrilsDyn.add(aNostrilsFactor);
178
179 9e7b6dbd Leszek Koltunski
    aEyesRegion        = new Static4D(0,0,0,83);
180 04fe7f80 Leszek Koltunski
    aLEyeCenter        = new Static3D(176,230,0);
181
    aREyeCenter        = new Static3D(420,230,0);
182 b3a555a7 Leszek Koltunski
    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 9e7b6dbd Leszek Koltunski
    aEyebrowsRegion    = new Static4D(0,0,0,142);
190 04fe7f80 Leszek Koltunski
    aEyebrowsCenter    = new Static3D(300,100,0);
191 b3a555a7 Leszek Koltunski
    aEyebrowsDyn       = new Dynamic3D();
192
    aEyebrowsFactor    = new Static3D(0,0,0);
193
    aEyebrowsDyn.add(aEyebrowsFactor);
194
195
    // Fragment Effects
196 1585ba24 Leszek Koltunski
    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 b3a555a7 Leszek Koltunski
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 04fe7f80 Leszek Koltunski
213
    // BLACKNESS
214
    // Vertex Effects
215 9e7b6dbd Leszek Koltunski
    bFaceRegion        = new Static4D(0,0,0,600);
216 04fe7f80 Leszek Koltunski
    bFaceCenter        = new Static3D(300,300,0);
217
    bFaceFactor        = new Static2D(1.0f,90.0f);
218
    bFaceDyn           = new Dynamic2D();
219
    bFaceDyn.add(bFaceFactor);
220
221 9e7b6dbd Leszek Koltunski
    bTipLowerRegion    = new Static4D(0,0,0,41);
222 04fe7f80 Leszek Koltunski
    bTipLowerCenter    = new Static3D(300,393,0);
223
    bTipLowerFactor    = new Static3D(0,0,0);
224
    bTipLowerDyn       = new Dynamic3D();
225
    bTipLowerDyn.add(bTipLowerFactor);
226
227 9e7b6dbd Leszek Koltunski
    bWholeNoseRegion   = new Static4D(0,0,0,130);
228 04fe7f80 Leszek Koltunski
    bWholeNoseCenter   = new Static3D(300,357,0);
229
    bWholeNoseFactor   = new Static2D(1.0f,90.0f);
230
    bWholeNoseDyn      = new Dynamic2D();
231
    bWholeNoseDyn.add(bWholeNoseFactor);
232
233 9e7b6dbd Leszek Koltunski
    bNoseBroaderRegion = new Static4D(0,0,0,95);
234 04fe7f80 Leszek Koltunski
    bNoseBroaderCenter = new Static3D(300,408,0);
235
    bNoseBroaderFactor = new Static2D(1.0f,90.0f);
236
    bNoseBroaderDyn    = new Dynamic2D();
237
    bNoseBroaderDyn.add(bNoseBroaderFactor);
238
239 9e7b6dbd Leszek Koltunski
    bLipsRegion        = new Static4D(0,96,0,118);
240 04fe7f80 Leszek Koltunski
    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 1585ba24 Leszek Koltunski
    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 04fe7f80 Leszek Koltunski
257 287a5475 Leszek Koltunski
    bChromaSkin        = new Static3D(0.4f, 0.25f, 0.25f);
258 04fe7f80 Leszek Koltunski
    bChromaEyes        = new Static3D(1.0f, 1.0f, 1.0f);
259 287a5475 Leszek Koltunski
    bChromaPupil       = new Static3D(0.4f, 0.14f, 0.14f);
260 04fe7f80 Leszek Koltunski
    bChromaSkinFactor  = new Static1D(0.0f);
261
    bChromaPupilFactor = new Static1D(0.0f);
262
    bChromaEyesFactor  = new Static1D(0.0f);
263 287a5475 Leszek Koltunski
    bContrastFactor    = new Static1D(0.0f);
264 04fe7f80 Leszek Koltunski
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 287a5475 Leszek Koltunski
    bContrastDyn = new Dynamic1D();
272
    bContrastDyn.add(bContrastFactor);
273 7ba38011 Leszek Koltunski
    }
274
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276
277 d04a4886 Leszek Koltunski
  synchronized void apply(DistortedEffects effects)
278 7ba38011 Leszek Koltunski
    {
279 2f20ae3a Leszek Koltunski
    setRace(mBlackness, mAsianness);
280 7ba38011 Leszek Koltunski
281 b3a555a7 Leszek Koltunski
    // WHITENESS
282 fa9b6494 Leszek Koltunski
    effects.apply( new VertexEffectSink(wLipsDyn, wLipsCenter, wLipsRegion) );
283 b3a555a7 Leszek Koltunski
284
    // ASIANNESS
285 1585ba24 Leszek Koltunski
    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 4b34bb08 Leszek Koltunski
292 1585ba24 Leszek Koltunski
    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 b3a555a7 Leszek Koltunski
296
    // BLACKNESS
297 1585ba24 Leszek Koltunski
    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 fa9b6494 Leszek Koltunski
309
    effects.apply( new FragmentEffectContrast(bContrastDyn) );
310 7ba38011 Leszek Koltunski
    }
311
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313
314 2f20ae3a Leszek Koltunski
  synchronized void setRace(float blackness, float asianness)
315 7ba38011 Leszek Koltunski
    {
316 b3a555a7 Leszek Koltunski
    mWhiteness = 1 - blackness - asianness;
317 2f20ae3a Leszek Koltunski
    mAsianness = asianness;
318 04fe7f80 Leszek Koltunski
    mBlackness = blackness;
319 7ba38011 Leszek Koltunski
320 4b34bb08 Leszek Koltunski
    //android.util.Log.e("manager", "blackness="+blackness+" asianness="+asianness);
321
322 b3a555a7 Leszek Koltunski
    // WHITENESS
323
    wLipsFactor.set(1.0f-0.3f*mWhiteness);
324
325
    // ASIANNESS
326
    aLipsNoseFactor.set2(-23.0f*mAsianness);
327 287a5475 Leszek Koltunski
    aNoseBroaderFactor.set1(1.0f+0.85f*mAsianness);
328 b3a555a7 Leszek Koltunski
    aNostrilsFactor.set2(-12.0f*mAsianness);
329 287a5475 Leszek Koltunski
    aLEyeFactor.set(+10.0f*mAsianness);
330
    aREyeFactor.set(-10.0f*mAsianness);
331 b3a555a7 Leszek Koltunski
    aEyebrowsFactor.set2(-40.0f*mAsianness);
332
333
    aChromaSkinFactor.set(0.2f*mAsianness);
334
    aChromaEyesFactor.set(0.7f*mAsianness);
335
336
    // BLACKNESS
337 04fe7f80 Leszek Koltunski
    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 287a5475 Leszek Koltunski
    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 7ba38011 Leszek Koltunski
    }
349
  }