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.Dynamic3D;
|
33
|
import org.distorted.library.type.Static1D;
|
34
|
import org.distorted.library.type.Static3D;
|
35
|
import org.distorted.library.type.Static4D;
|
36
|
|
37
|
class AroundTheWorldEffectsManager
|
38
|
{
|
39
|
private float mWhiteness, mBlackness, mAsianness; // those always sum up to 1
|
40
|
|
41
|
// WHITENESS
|
42
|
// Vertex effects:
|
43
|
// a) make the lips smaller (SINK)
|
44
|
private final Static4D wLipsRegion;
|
45
|
private final Static3D wLipsCenter;
|
46
|
private final Static1D wLipsFactor;
|
47
|
private final Dynamic1D wLipsDyn;
|
48
|
|
49
|
// ASIANNESS
|
50
|
// Vertex Effects:
|
51
|
// a) move lips & nose higher (DISTORT)
|
52
|
private final Static4D aLipsNoseRegion;
|
53
|
private final Static3D aLipsNoseCenter;
|
54
|
private final Static3D aLipsNoseFactor;
|
55
|
private final Dynamic3D aLipsNoseDyn;
|
56
|
// b) make the nose broader (PINCH)
|
57
|
private final Static4D aNoseBroaderRegion;
|
58
|
private final Static3D aNoseBroaderCenter;
|
59
|
private final Static3D aNoseBroaderFactor;
|
60
|
private final Dynamic3D aNoseBroaderDyn;
|
61
|
// c) make the nostrils more visible (DISTORT)
|
62
|
private final Static4D aNostrilsRegion;
|
63
|
private final Static3D aNostrilsCenter;
|
64
|
private final Static3D aNostrilsFactor;
|
65
|
private final Dynamic3D aNostrilsDyn;
|
66
|
// d) rotate eyes (2 x SWIRL)
|
67
|
private final Static4D aEyesRegion;
|
68
|
private final Static3D aLEyeCenter, aREyeCenter;
|
69
|
private final Static1D aLEyeFactor, aREyeFactor;
|
70
|
private final Dynamic1D aLEyeDyn, aREyeDyn;
|
71
|
// e) move eyebrow higher (DISTORT)
|
72
|
private final Static4D aEyebrowsRegion;
|
73
|
private final Static3D aEyebrowsCenter;
|
74
|
private final Static3D aEyebrowsFactor;
|
75
|
private final Dynamic3D aEyebrowsDyn;
|
76
|
|
77
|
// Fragment effects:
|
78
|
// a) change color of the skin to more brown and less red (CHROMA)
|
79
|
private final Static3D aSkinColorCenter;
|
80
|
private final Static3D aSkinColorRegion;
|
81
|
private final Static3D aChromaSkin;
|
82
|
private final Static1D aChromaSkinFactor;
|
83
|
private final Dynamic1D aChromaSkinDyn;
|
84
|
// b) darken both eyes (2 x SMOOTH_CHROMA)
|
85
|
private final Static3D aLEyeColorCenter, aREyeColorCenter;
|
86
|
private final Static3D aLEyeColorRegion, aREyeColorRegion;
|
87
|
private final Static3D aChromaEyes;
|
88
|
private final Static1D aChromaEyesFactor;
|
89
|
private final Dynamic1D aChromaEyesDyn;
|
90
|
|
91
|
// BLACKNESS
|
92
|
// Vertex Effects
|
93
|
// a) make the whole face broader (PINCH)
|
94
|
private final Static4D bFaceRegion;
|
95
|
private final Static3D bFaceCenter;
|
96
|
private final Static3D bFaceFactor;
|
97
|
private final Dynamic3D bFaceDyn;
|
98
|
// b) tip of the nose lower (DISTORT)
|
99
|
private final Static4D bTipLowerRegion;
|
100
|
private final Static3D bTipLowerCenter;
|
101
|
private final Static3D bTipLowerFactor;
|
102
|
private final Dynamic3D bTipLowerDyn;
|
103
|
// c) broaden the whole nose: (PINCH)
|
104
|
private final Static4D bWholeNoseRegion;
|
105
|
private final Static3D bWholeNoseCenter;
|
106
|
private final Static3D bWholeNoseFactor;
|
107
|
private final Dynamic3D bWholeNoseDyn;
|
108
|
// d) broaden the tip of the nose some more: (PINCH)
|
109
|
private final Static4D bNoseBroaderRegion;
|
110
|
private final Static3D bNoseBroaderCenter;
|
111
|
private final Static3D bNoseBroaderFactor;
|
112
|
private final Dynamic3D bNoseBroaderDyn;
|
113
|
// 3) make lips higher: (PINCH)
|
114
|
private final Static4D bLipsRegion;
|
115
|
private final Static3D bLipsCenter;
|
116
|
private final Static3D bLipsFactor;
|
117
|
private final Dynamic3D bLipsDyn;
|
118
|
// Fragment effects
|
119
|
// a) make the whole face darker (CHROMA)
|
120
|
private final Static3D bSkinColorCenter;
|
121
|
private final Static3D bSkinColorRegion;
|
122
|
private final Static3D bChromaSkin;
|
123
|
private final Static1D bChromaSkinFactor;
|
124
|
private final Dynamic1D bChromaSkinDyn;
|
125
|
// b) move both eyes back to whiteness (2 x SMOOTH CHROMA)
|
126
|
private final Static3D bLEyeColorCenter, bREyeColorCenter;
|
127
|
private final Static3D bLEyeColorRegion, bREyeColorRegion;
|
128
|
private final Static3D bChromaEyes;
|
129
|
private final Static1D bChromaEyesFactor;
|
130
|
private final Dynamic1D bChromaEyesDyn;
|
131
|
// c) darken both pupils (2 x SMOOTH_CHROMA)
|
132
|
private final Static3D bLPupilColorCenter, bRPupilColorCenter;
|
133
|
private final Static3D bLPupilColorRegion, bRPupilColorRegion;
|
134
|
private final Static3D bChromaPupil;
|
135
|
private final Static1D bChromaPupilFactor;
|
136
|
private final Dynamic1D bChromaPupilDyn;
|
137
|
// d) all those chroma effects have reduced contrast - bring it back
|
138
|
private final Static1D bContrastFactor;
|
139
|
private final Dynamic1D bContrastDyn;
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
|
143
|
AroundTheWorldEffectsManager()
|
144
|
{
|
145
|
mWhiteness = 1;
|
146
|
mBlackness = 0;
|
147
|
mAsianness = 0;
|
148
|
|
149
|
// WHITENESS
|
150
|
// Vertex Effects
|
151
|
wLipsRegion = new Static4D(0,0,0,100);
|
152
|
wLipsCenter = new Static3D(3,-200,0);
|
153
|
wLipsFactor = new Static1D(0.7f);
|
154
|
wLipsDyn = new Dynamic1D();
|
155
|
wLipsDyn.add(wLipsFactor);
|
156
|
|
157
|
// ASIANNESS
|
158
|
// Vertex Effects
|
159
|
aLipsNoseRegion = new Static4D(0,0,0,267);
|
160
|
aLipsNoseCenter = new Static3D(3,260,0);
|
161
|
aLipsNoseDyn = new Dynamic3D();
|
162
|
aLipsNoseFactor = new Static3D(0,0,0);
|
163
|
aLipsNoseDyn.add(aLipsNoseFactor);
|
164
|
|
165
|
aNoseBroaderRegion = new Static4D(0,0,0,130);
|
166
|
aNoseBroaderCenter = new Static3D(3,-7,0);
|
167
|
aNoseBroaderDyn = new Dynamic3D();
|
168
|
aNoseBroaderFactor = new Static3D(0,0,90);
|
169
|
aNoseBroaderDyn.add(aNoseBroaderFactor);
|
170
|
|
171
|
aNostrilsRegion = new Static4D(0,0,0,60);
|
172
|
aNostrilsCenter = new Static3D(3,-36,0);
|
173
|
aNostrilsDyn = new Dynamic3D();
|
174
|
aNostrilsFactor = new Static3D(0,0,0);
|
175
|
aNostrilsDyn.add(aNostrilsFactor);
|
176
|
|
177
|
aEyesRegion = new Static4D(0,0,0,83);
|
178
|
aLEyeCenter = new Static3D(-121,70,0);
|
179
|
aREyeCenter = new Static3D( 123,70,0);
|
180
|
aLEyeDyn = new Dynamic1D();
|
181
|
aREyeDyn = new Dynamic1D();
|
182
|
aLEyeFactor = new Static1D(0);
|
183
|
aREyeFactor = new Static1D(0);
|
184
|
aLEyeDyn.add(aLEyeFactor);
|
185
|
aREyeDyn.add(aREyeFactor);
|
186
|
|
187
|
aEyebrowsRegion = new Static4D(0,0,0,142);
|
188
|
aEyebrowsCenter = new Static3D(3,200,0);
|
189
|
aEyebrowsDyn = new Dynamic3D();
|
190
|
aEyebrowsFactor = new Static3D(0,0,0);
|
191
|
aEyebrowsDyn.add(aEyebrowsFactor);
|
192
|
|
193
|
// Fragment Effects
|
194
|
aSkinColorCenter = new Static3D(3,0,0);
|
195
|
aSkinColorRegion = new Static3D(600,600,600);
|
196
|
aLEyeColorCenter = new Static3D(-125,70,0);
|
197
|
aLEyeColorRegion = new Static3D(29,25,25);
|
198
|
aREyeColorCenter = new Static3D(126,70,0);
|
199
|
aREyeColorRegion = new Static3D(29,25,25);
|
200
|
|
201
|
aChromaSkin = new Static3D(0.5f, 0.5f, 0.5f);
|
202
|
aChromaEyes = new Static3D(0.5f, 0.14f, 0.14f);
|
203
|
aChromaSkinFactor = new Static1D(0.0f);
|
204
|
aChromaEyesFactor = new Static1D(0.0f);
|
205
|
|
206
|
aChromaSkinDyn = new Dynamic1D();
|
207
|
aChromaSkinDyn.add(aChromaSkinFactor);
|
208
|
aChromaEyesDyn = new Dynamic1D();
|
209
|
aChromaEyesDyn.add(aChromaEyesFactor);
|
210
|
|
211
|
// BLACKNESS
|
212
|
// Vertex Effects
|
213
|
bFaceRegion = new Static4D(0,0,0,600);
|
214
|
bFaceCenter = new Static3D(3,0,0);
|
215
|
bFaceFactor = new Static3D(1.0f,0.0f,90.0f);
|
216
|
bFaceDyn = new Dynamic3D();
|
217
|
bFaceDyn.add(bFaceFactor);
|
218
|
|
219
|
bTipLowerRegion = new Static4D(0,0,0,41);
|
220
|
bTipLowerCenter = new Static3D(3,-93,0);
|
221
|
bTipLowerFactor = new Static3D(0,0,0);
|
222
|
bTipLowerDyn = new Dynamic3D();
|
223
|
bTipLowerDyn.add(bTipLowerFactor);
|
224
|
|
225
|
bWholeNoseRegion = new Static4D(0,0,0,130);
|
226
|
bWholeNoseCenter = new Static3D(3,-57,0);
|
227
|
bWholeNoseFactor = new Static3D(1.0f,0.0f,90.0f);
|
228
|
bWholeNoseDyn = new Dynamic3D();
|
229
|
bWholeNoseDyn.add(bWholeNoseFactor);
|
230
|
|
231
|
bNoseBroaderRegion = new Static4D(0,0,0,95);
|
232
|
bNoseBroaderCenter = new Static3D(3,-108,0);
|
233
|
bNoseBroaderFactor = new Static3D(1.0f,0.0f,90.0f);
|
234
|
bNoseBroaderDyn = new Dynamic3D();
|
235
|
bNoseBroaderDyn.add(bNoseBroaderFactor);
|
236
|
|
237
|
bLipsRegion = new Static4D(0,-96,0,118);
|
238
|
bLipsCenter = new Static3D(3,-158,0);
|
239
|
bLipsFactor = new Static3D(1.0f,90.0f,0.0f);
|
240
|
bLipsDyn = new Dynamic3D();
|
241
|
bLipsDyn.add(bLipsFactor);
|
242
|
|
243
|
// 594 x 600
|
244
|
|
245
|
// Fragment Effects
|
246
|
bSkinColorCenter = new Static3D(3,0,0);
|
247
|
bSkinColorRegion = new Static3D(600,600,600);
|
248
|
bLEyeColorCenter = new Static3D(-139,59,0);
|
249
|
bLEyeColorRegion = new Static3D(55,24,50);
|
250
|
bREyeColorCenter = new Static3D(139,59,0);
|
251
|
bREyeColorRegion = new Static3D(55,24,50);
|
252
|
bLPupilColorCenter = new Static3D(-131,70,0);
|
253
|
bLPupilColorRegion = new Static3D(28,23,25);
|
254
|
bRPupilColorCenter = new Static3D(134,70,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
|
// WHITENESS
|
321
|
wLipsFactor.set(1.0f-0.3f*mWhiteness);
|
322
|
|
323
|
// ASIANNESS
|
324
|
aLipsNoseFactor.set1(23.0f*mAsianness);
|
325
|
aNoseBroaderFactor.set0(1.0f+0.85f*mAsianness);
|
326
|
aNostrilsFactor.set1(12.0f*mAsianness);
|
327
|
aLEyeFactor.set(+10.0f*mAsianness);
|
328
|
aREyeFactor.set(-10.0f*mAsianness);
|
329
|
aEyebrowsFactor.set1(40.0f*mAsianness);
|
330
|
|
331
|
aChromaSkinFactor.set(0.2f*mAsianness);
|
332
|
aChromaEyesFactor.set(0.7f*mAsianness);
|
333
|
|
334
|
// BLACKNESS
|
335
|
bFaceFactor.set0(1.0f + 0.1f*mBlackness);
|
336
|
bTipLowerFactor.set1(-23.0f*mBlackness);
|
337
|
bWholeNoseFactor.set0(1.0f+0.5f*mBlackness);
|
338
|
bNoseBroaderFactor.set0(1.0f+0.38f*mBlackness);
|
339
|
bLipsFactor.set0(1.0f+1.0f*mBlackness);
|
340
|
|
341
|
bChromaSkinFactor.set(0.75f*mBlackness);
|
342
|
bChromaEyesFactor.set(0.2f*mBlackness);
|
343
|
bChromaPupilFactor.set(0.6f*mBlackness);
|
344
|
|
345
|
bContrastFactor.set(1.0f+1.5f*mBlackness);
|
346
|
}
|
347
|
}
|