Project

General

Profile

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

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

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 04fe7f80 Leszek Koltunski
  private Static4D aSkinColorRegion;
82 b3a555a7 Leszek Koltunski
  private Static3D aChromaSkin;
83
  private Static1D aChromaSkinFactor;
84
  private Dynamic1D aChromaSkinDyn;
85
  // b) darken both eyes (2 x SMOOTH_CHROMA)
86 04fe7f80 Leszek Koltunski
  private Static4D aLEyeColorRegion, aREyeColorRegion;
87 b3a555a7 Leszek Koltunski
  private Static3D aChromaEyes;
88
  private Static1D aChromaEyesFactor;
89
  private Dynamic1D aChromaEyesDyn;
90
91
  // BLACKNESS
92 04fe7f80 Leszek Koltunski
  // 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 287a5475 Leszek Koltunski
  // d) all those chroma effects have reduced contrast - bring it back
135
  private Static1D bContrastFactor;
136
  private Dynamic1D bContrastDyn;
137 4b34bb08 Leszek Koltunski
138 7ba38011 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
139
140 2f20ae3a Leszek Koltunski
  AroundTheWorldEffectsManager()
141 7ba38011 Leszek Koltunski
    {
142 b3a555a7 Leszek Koltunski
    mWhiteness = 1;
143 2f20ae3a Leszek Koltunski
    mBlackness = 0;
144
    mAsianness = 0;
145 7ba38011 Leszek Koltunski
146 b3a555a7 Leszek Koltunski
    // WHITENESS
147
    // Vertex Effects
148 9e7b6dbd Leszek Koltunski
    wLipsRegion = new Static4D(0,0,0,100);
149 04fe7f80 Leszek Koltunski
    wLipsCenter = new Static3D(300,500,0);
150 b3a555a7 Leszek Koltunski
    wLipsFactor = new Static1D(0.7f);
151
    wLipsDyn    = new Dynamic1D();
152
    wLipsDyn.add(wLipsFactor);
153
154
    // ASIANNESS
155
    // Vertex Effects
156 9e7b6dbd Leszek Koltunski
    aLipsNoseRegion    = new Static4D(0,0,0,267);
157 04fe7f80 Leszek Koltunski
    aLipsNoseCenter    = new Static3D(300,560,0);
158 b3a555a7 Leszek Koltunski
    aLipsNoseDyn       = new Dynamic3D();
159
    aLipsNoseFactor    = new Static3D(0,0,0);
160
    aLipsNoseDyn.add(aLipsNoseFactor);
161
162 9e7b6dbd Leszek Koltunski
    aNoseBroaderRegion = new Static4D(0,0,0,130);
163 04fe7f80 Leszek Koltunski
    aNoseBroaderCenter = new Static3D(300,307,0);
164 b3a555a7 Leszek Koltunski
    aNoseBroaderDyn    = new Dynamic2D();
165
    aNoseBroaderFactor = new Static2D(0,90);
166
    aNoseBroaderDyn.add(aNoseBroaderFactor);
167
168 9e7b6dbd Leszek Koltunski
    aNostrilsRegion    = new Static4D(0,0,0,60);
169 04fe7f80 Leszek Koltunski
    aNostrilsCenter    = new Static3D(300,336,0);
170 b3a555a7 Leszek Koltunski
    aNostrilsDyn       = new Dynamic3D();
171
    aNostrilsFactor    = new Static3D(0,0,0);
172
    aNostrilsDyn.add(aNostrilsFactor);
173
174 9e7b6dbd Leszek Koltunski
    aEyesRegion        = new Static4D(0,0,0,83);
175 04fe7f80 Leszek Koltunski
    aLEyeCenter        = new Static3D(176,230,0);
176
    aREyeCenter        = new Static3D(420,230,0);
177 b3a555a7 Leszek Koltunski
    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 9e7b6dbd Leszek Koltunski
    aEyebrowsRegion    = new Static4D(0,0,0,142);
185 04fe7f80 Leszek Koltunski
    aEyebrowsCenter    = new Static3D(300,100,0);
186 b3a555a7 Leszek Koltunski
    aEyebrowsDyn       = new Dynamic3D();
187
    aEyebrowsFactor    = new Static3D(0,0,0);
188
    aEyebrowsDyn.add(aEyebrowsFactor);
189
190
    // Fragment Effects
191 04fe7f80 Leszek Koltunski
    aSkinColorRegion   = new Static4D(300,300,600,600);
192
    aLEyeColorRegion   = new Static4D(172,230,29,25);
193
    aREyeColorRegion   = new Static4D(423,230,29,25);
194 b3a555a7 Leszek Koltunski
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 04fe7f80 Leszek Koltunski
205
    // BLACKNESS
206
    // Vertex Effects
207 9e7b6dbd Leszek Koltunski
    bFaceRegion        = new Static4D(0,0,0,600);
208 04fe7f80 Leszek Koltunski
    bFaceCenter        = new Static3D(300,300,0);
209
    bFaceFactor        = new Static2D(1.0f,90.0f);
210
    bFaceDyn           = new Dynamic2D();
211
    bFaceDyn.add(bFaceFactor);
212
213 9e7b6dbd Leszek Koltunski
    bTipLowerRegion    = new Static4D(0,0,0,41);
214 04fe7f80 Leszek Koltunski
    bTipLowerCenter    = new Static3D(300,393,0);
215
    bTipLowerFactor    = new Static3D(0,0,0);
216
    bTipLowerDyn       = new Dynamic3D();
217
    bTipLowerDyn.add(bTipLowerFactor);
218
219 9e7b6dbd Leszek Koltunski
    bWholeNoseRegion   = new Static4D(0,0,0,130);
220 04fe7f80 Leszek Koltunski
    bWholeNoseCenter   = new Static3D(300,357,0);
221
    bWholeNoseFactor   = new Static2D(1.0f,90.0f);
222
    bWholeNoseDyn      = new Dynamic2D();
223
    bWholeNoseDyn.add(bWholeNoseFactor);
224
225 9e7b6dbd Leszek Koltunski
    bNoseBroaderRegion = new Static4D(0,0,0,95);
226 04fe7f80 Leszek Koltunski
    bNoseBroaderCenter = new Static3D(300,408,0);
227
    bNoseBroaderFactor = new Static2D(1.0f,90.0f);
228
    bNoseBroaderDyn    = new Dynamic2D();
229
    bNoseBroaderDyn.add(bNoseBroaderFactor);
230
231 9e7b6dbd Leszek Koltunski
    bLipsRegion        = new Static4D(0,96,0,118);
232 04fe7f80 Leszek Koltunski
    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 287a5475 Leszek Koltunski
    bChromaSkin        = new Static3D(0.4f, 0.25f, 0.25f);
245 04fe7f80 Leszek Koltunski
    bChromaEyes        = new Static3D(1.0f, 1.0f, 1.0f);
246 287a5475 Leszek Koltunski
    bChromaPupil       = new Static3D(0.4f, 0.14f, 0.14f);
247 04fe7f80 Leszek Koltunski
    bChromaSkinFactor  = new Static1D(0.0f);
248
    bChromaPupilFactor = new Static1D(0.0f);
249
    bChromaEyesFactor  = new Static1D(0.0f);
250 287a5475 Leszek Koltunski
    bContrastFactor    = new Static1D(0.0f);
251 04fe7f80 Leszek Koltunski
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 287a5475 Leszek Koltunski
    bContrastDyn = new Dynamic1D();
259
    bContrastDyn.add(bContrastFactor);
260 7ba38011 Leszek Koltunski
    }
261
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263
264 d04a4886 Leszek Koltunski
  synchronized void apply(DistortedEffects effects)
265 7ba38011 Leszek Koltunski
    {
266 2f20ae3a Leszek Koltunski
    setRace(mBlackness, mAsianness);
267 7ba38011 Leszek Koltunski
268 b3a555a7 Leszek Koltunski
    // WHITENESS
269 fa9b6494 Leszek Koltunski
    effects.apply( new VertexEffectSink(wLipsDyn, wLipsCenter, wLipsRegion) );
270 b3a555a7 Leszek Koltunski
271
    // ASIANNESS
272 fa9b6494 Leszek Koltunski
    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 4b34bb08 Leszek Koltunski
279 fa9b6494 Leszek Koltunski
    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 b3a555a7 Leszek Koltunski
283
    // BLACKNESS
284 fa9b6494 Leszek Koltunski
    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 7ba38011 Leszek Koltunski
    }
298
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
301 2f20ae3a Leszek Koltunski
  synchronized void setRace(float blackness, float asianness)
302 7ba38011 Leszek Koltunski
    {
303 b3a555a7 Leszek Koltunski
    mWhiteness = 1 - blackness - asianness;
304 2f20ae3a Leszek Koltunski
    mAsianness = asianness;
305 04fe7f80 Leszek Koltunski
    mBlackness = blackness;
306 7ba38011 Leszek Koltunski
307 4b34bb08 Leszek Koltunski
    //android.util.Log.e("manager", "blackness="+blackness+" asianness="+asianness);
308
309 b3a555a7 Leszek Koltunski
    // WHITENESS
310
    wLipsFactor.set(1.0f-0.3f*mWhiteness);
311
312
    // ASIANNESS
313
    aLipsNoseFactor.set2(-23.0f*mAsianness);
314 287a5475 Leszek Koltunski
    aNoseBroaderFactor.set1(1.0f+0.85f*mAsianness);
315 b3a555a7 Leszek Koltunski
    aNostrilsFactor.set2(-12.0f*mAsianness);
316 287a5475 Leszek Koltunski
    aLEyeFactor.set(+10.0f*mAsianness);
317
    aREyeFactor.set(-10.0f*mAsianness);
318 b3a555a7 Leszek Koltunski
    aEyebrowsFactor.set2(-40.0f*mAsianness);
319
320
    aChromaSkinFactor.set(0.2f*mAsianness);
321
    aChromaEyesFactor.set(0.7f*mAsianness);
322
323
    // BLACKNESS
324 04fe7f80 Leszek Koltunski
    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 287a5475 Leszek Koltunski
    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 7ba38011 Leszek Koltunski
    }
336
  }