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.library.effect;
|
21
|
|
22
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
23
|
/**
|
24
|
* Names of Effects one can add to the DistortedEffects queues.
|
25
|
* <p>
|
26
|
* Effect's 'Type' is one of the constants defined in {@link EffectType}.
|
27
|
* </p>
|
28
|
* <p>
|
29
|
* Effect's 'Uniforms' are a vector of 7 (matrix effects) 12 (vertex) or 8 (fragment) floats, which
|
30
|
* together form full information how to compute a given effect.
|
31
|
* Typically, some of those values will be Interpolated in CPU (by one of the 'EffectQueueX.compute()'
|
32
|
* methods) and the effect of such Interpolation sent to the Shaders.
|
33
|
* </p>
|
34
|
* <p>
|
35
|
* Effect's 'Unity' is such a particular vector of its 'interpolated values' which makes the
|
36
|
* effect NULL. For example, if the effect is 'MOVE' by a 3-dimensional vector, then a 'NULL
|
37
|
* MOVE' is a MOVE by vector (0,0,0), thus (0,0,0) is the unity of the MOVE effect.
|
38
|
* This is used by the EffectQueue classes to decide if the final form of the Effect is NULL - and
|
39
|
* thus if it can safely be removed from Effect Queues without affecting the visual in any way.
|
40
|
* </p>
|
41
|
*/
|
42
|
|
43
|
public enum EffectName
|
44
|
{
|
45
|
// EFFECT NAME /////// EFFECT TYPE ////////// EFFECT UNITY //////////// DIM REGION CENTER
|
46
|
ROTATE ( EffectType.MATRIX , new float[] {0.0f} , 4, false, true ),
|
47
|
QUATERNION ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 4, false, true ),
|
48
|
MOVE ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 3, false, false ),
|
49
|
SCALE ( EffectType.MATRIX , new float[] {1.0f,1.0f,1.0f} , 3, false, false ),
|
50
|
SHEAR ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 3, false, true ),
|
51
|
|
52
|
DISTORT ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, true , true ),
|
53
|
DEFORM ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, true , true ),
|
54
|
SINK ( EffectType.VERTEX , new float[] {1.0f} , 1, true , true ),
|
55
|
PINCH ( EffectType.VERTEX , new float[] {1.0f} , 2, true , true ),
|
56
|
SWIRL ( EffectType.VERTEX , new float[] {0.0f} , 1, true , true ),
|
57
|
WAVE ( EffectType.VERTEX , new float[] {0.0f} , 5, true , true ),
|
58
|
|
59
|
ALPHA ( EffectType.FRAGMENT, new float[] {1.0f} , 1, true , false ),
|
60
|
SMOOTH_ALPHA ( EffectType.FRAGMENT, new float[] {1.0f} , 1, true , false ),
|
61
|
CHROMA ( EffectType.FRAGMENT, new float[] {0.0f} , 4, true , false ),
|
62
|
SMOOTH_CHROMA ( EffectType.FRAGMENT, new float[] {0.0f} , 4, true , false ),
|
63
|
BRIGHTNESS ( EffectType.FRAGMENT, new float[] {1.0f} , 1, true , false ),
|
64
|
SMOOTH_BRIGHTNESS( EffectType.FRAGMENT, new float[] {1.0f} , 1, true , false ),
|
65
|
SATURATION ( EffectType.FRAGMENT, new float[] {1.0f} , 1, true , false ),
|
66
|
SMOOTH_SATURATION( EffectType.FRAGMENT, new float[] {1.0f} , 1, true , false ),
|
67
|
CONTRAST ( EffectType.FRAGMENT, new float[] {1.0f} , 1, true , false ),
|
68
|
SMOOTH_CONTRAST ( EffectType.FRAGMENT, new float[] {1.0f} , 1, true , false ),
|
69
|
|
70
|
BLUR ( EffectType.POSTPROCESS,new float[] {0.0f} , 1, false, false ),
|
71
|
GLOW ( EffectType.POSTPROCESS,new float[] {0.0f} , 4, false, false );
|
72
|
|
73
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74
|
|
75
|
private static final int MAXDIM = 4; // maximum supported dimension of effect's unity
|
76
|
public static final int LENGTH = values().length;
|
77
|
|
78
|
private final EffectType type;
|
79
|
private final float[] unity;
|
80
|
private final int dimension;
|
81
|
private final boolean supportsR;
|
82
|
private final boolean supportsC;
|
83
|
|
84
|
private static final float[] unities;
|
85
|
private static final int[] unityDimensions;
|
86
|
private static final int[] dimensions;
|
87
|
private static final boolean[] supportsRegion;
|
88
|
private static final boolean[] supportsCenter;
|
89
|
private static final EffectName[] names; // copy the values() to a local variable so that we
|
90
|
// don't have to keep recreating the array every time
|
91
|
static
|
92
|
{
|
93
|
int i=0;
|
94
|
|
95
|
unities = new float[MAXDIM*LENGTH];
|
96
|
unityDimensions = new int[LENGTH];
|
97
|
dimensions = new int[LENGTH];
|
98
|
supportsRegion = new boolean[LENGTH];
|
99
|
supportsCenter = new boolean[LENGTH];
|
100
|
names = new EffectName[LENGTH];
|
101
|
|
102
|
for(EffectName name: EffectName.values())
|
103
|
{
|
104
|
unityDimensions[i] = (name.unity==null ? 0 : name.unity.length);
|
105
|
dimensions[i] = name.dimension;
|
106
|
supportsRegion[i] = name.supportsR;
|
107
|
supportsCenter[i] = name.supportsC;
|
108
|
names[i] = name;
|
109
|
|
110
|
switch(unityDimensions[i])
|
111
|
{
|
112
|
case 4: unities[MAXDIM*i+3] = name.unity[3];
|
113
|
case 3: unities[MAXDIM*i+2] = name.unity[2];
|
114
|
case 2: unities[MAXDIM*i+1] = name.unity[1];
|
115
|
case 1: unities[MAXDIM*i ] = name.unity[0];
|
116
|
case 0: break;
|
117
|
}
|
118
|
|
119
|
i++;
|
120
|
}
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
float[] getUnity()
|
126
|
{
|
127
|
return unity;
|
128
|
}
|
129
|
|
130
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131
|
|
132
|
EffectName(EffectType type, float[] unity, int dimension, boolean supportsR, boolean supportsC)
|
133
|
{
|
134
|
this.type = type;
|
135
|
this.unity = unity;
|
136
|
this.dimension = dimension;
|
137
|
this.supportsR = supportsR;
|
138
|
this.supportsC = supportsC;
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
// PUBLIC API
|
143
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144
|
/**
|
145
|
* Returns the Type of an individual Effect. For example, EffectName.ROTATION.getType() will
|
146
|
* return EffectType.MATRIX.
|
147
|
* @return type of the effect.
|
148
|
*/
|
149
|
public EffectType getType()
|
150
|
{
|
151
|
return type;
|
152
|
}
|
153
|
|
154
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155
|
/**
|
156
|
* Returns the i-th EffectName.
|
157
|
* <p>
|
158
|
* If you want to loop over all possible Effects, you need this.
|
159
|
*/
|
160
|
public static EffectName getName(int ordinal)
|
161
|
{
|
162
|
return names[ordinal];
|
163
|
}
|
164
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166
|
/**
|
167
|
* Returns the dimension of an Effect (in other words, the number of interpolated values).
|
168
|
* @return dimension of the Effect.
|
169
|
*/
|
170
|
public int getDimension() { return dimensions[ordinal()]; }
|
171
|
|
172
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
173
|
/**
|
174
|
* Do we support being masked by a Region?
|
175
|
* @return true if the Effect supports being masked with a Region.
|
176
|
*/
|
177
|
public boolean supportsRegion() { return supportsRegion[ordinal()]; }
|
178
|
|
179
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180
|
/**
|
181
|
* Does this Effect have a center?
|
182
|
* @return true if the Effect has a center.
|
183
|
*/
|
184
|
public boolean supportsCenter() { return supportsCenter[ordinal()]; }
|
185
|
}
|
186
|
|