Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ 4fde55a0

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;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * Names of Effects one can apply to DistortedObjects.
25
 * <p>
26
 * Effect's 'Type' is one of the constants defined in {@see EffectTypes}.
27
 * </p>
28
 * <p>
29
 * Effect's 'Uniforms' are a vector of 7 (matrix effects) 9 (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
public enum EffectNames
43
  {
44
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////////////////
45

    
46
  /////////////////////////////////////////////////////////////////////////////////
47
  // MATRIX EFFECTS.
48
  // Always 7 Uniforms: 4 per-effect interpolated values + 3 dimensional center.
49
 /**
50
   * Rotate the whole Object around a center point (in angle-axis notation).
51
   * <p>
52
   * Uniforms: (angle,axisX,axisY,axisZ,centerX,centerY,centerZ)
53
   * Unity: angle==0
54
   */
55
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           ),
56
 /**
57
   * Rotate the whole Object around a center point (in quaternion notation).
58
   * <p>
59
   * Uniforms: (quatX,quatY,quatZ,quatW,centerX,centerY,centerZ)
60
   * Unity: (quatX,quatY,quatZ) = (0,0,0)
61
   */
62
  QUATERNION       ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
63
 /**
64
   * Move the whole Object by a vector.
65
   * <p>
66
   * Uniforms: (vectorX,vectorY,vectorZ,UNUSED,UNUSED,UNUSED,UNUSED)
67
   * Unity: (vectorX,vectorY,vectorZ) = (0,0,0)
68
   */
69
  MOVE             ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
70
 /**
71
   * Scale the whole Object independently in all 3 dimensions.
72
   * <p>
73
   * Uniforms: (scaleX,scaleY,scaleZ,UNUSED,UNUSED,UNUSED,UNUSED)
74
   * Unity: (scaleX,scaleY,scaleZ) = (1,1,1)
75
   */
76
  SCALE            ( EffectTypes.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} ),
77
 /**
78
   * Shear the whole Object in 3 dimensions around a center point.
79
   * <p>
80
   * Uniforms: (shearX,shearY,shearZ,UNUSED,centerX,centerY,centerZ)
81
   * Unity:  (shearX,shearY,shearZ) = (0,0,0)
82
   */
83
  SHEAR            ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
84
  // add new Matrix effects here...
85

    
86
 /////////////////////////////////////////////////////////////////////////////////
87
 // VERTEX EFFECTS
88
 // Always 9 Uniforms: 3 per-effect interpolated values, 4-dimensional Region,
89
 // 2-dimensional center of the effect.
90
 /**
91
   * Apply a 3D vector of force to area around a point on the surface of the Object.
92
   * <p>
93
   * Uniforms: (forceX,forceY,forceZ,regionX,regionY,regionRX,regionRY,centerX,centerY)
94
   * Unity: (forceX,forceY,forceZ) = (0,0,0)
95
   */
96
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),
97
 /**
98
   * Deform the whole Object by applying a 2D vector of force to a center point.
99
   * <p>
100
   * Uniforms: (forceX,forceY,UNUSED,UNUSED,UNUSED,UNUSED,UNUSED,centerX,centerY)
101
   * Unity: (forceX,forceY) = (0,0)
102
   */
103
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      ),
104
 /**
105
   * Pull (or push away) all points around a center point to (from) it.
106
   * <p>
107
   * Uniforms: (sinkFactor,UNUSED,UNUSED,regionX,regionY,regionRX,regionRY,centerX,centerY)
108
   * Unity: sinkFactor = 1
109
   */
110
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           ),
111
 /**
112
   * Smoothly rotate a limited area around a center point.
113
   * <p>
114
   * Uniforms: (swirlAngle,UNUSED,UNUSED,regionX,regionY,regionRX,regionRY,centerX,centerY)
115
   * Unity: swirlAngle = 0
116
   */
117
  SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
118
  /**
119
   * Directional sinusoidal wave effect. The direction of the wave is given by the 'angle'
120
   * parameter, which is the angle (in degrees) the direction forms with the X-axis.
121
   * <p>
122
   * Uniforms: (amplitude,angle,length,regionX,regionY,regionRX,regionRY,centerX,centerY)
123
   * Unity: amplitude  = 0
124
   */
125
  WAVE             ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
126
  // add new Vertex Effects here...
127

    
128
 /////////////////////////////////////////////////////////////////////////////////
129
 // FRAGMENT EFFECTS
130
 // Always 8 Uniforms: 4-per effect interpolated values, 4 dimensional Region.
131
 /**
132
   * Make a given Region (partially) transparent.
133
   * <p>
134
   * Uniforms: (transparencyLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
135
   * Unity: transparencyLevel = 1
136
   */
137
  ALPHA            ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
138
 /**
139
   * Make a given Region (partially) transparent.
140
   * Effect smoothly fades towards the edges of the region.
141
   * <p>
142
   * Uniforms: (transparencyLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
143
   * Unity: transparencyLevel = 1
144
   */
145
  SMOOTH_ALPHA     ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
146
 /**
147
   * Blend current color in the texture with a given color.
148
   * <p>
149
   * Uniforms: (blendLevel,colorR,colorG,colorB, regionX, regionY, regionRX, regionRY)
150
   * Unity: blendLevel = 0
151
   */
152
  CHROMA           ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
153
 /**
154
   * Smoothly blend current color in the texture with a given color.
155
   * <p>
156
   * Uniforms: (blendLevel,colorR,colorG,colorB, regionX, regionY, regionRX, regionRY)
157
   * Unity: blendLevel = 0
158
   */
159
  SMOOTH_CHROMA    ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
160
 /**
161
   * Change brightness level of a given Region.
162
   * <p>
163
   * Uniforms: (brightnessLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
164
   * Unity: brightnessLevel = 1
165
   */
166
  BRIGHTNESS       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
167
 /**
168
   * Smoothly change brightness level of a given Region.
169
   * <p>
170
   * Uniforms: (brightnessLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
171
   * Unity: brightnessLevel = 1
172
   */
173
  SMOOTH_BRIGHTNESS( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
174
 /**
175
   * Change saturation level of a given Region.
176
   * <p>
177
   * Uniforms: (saturationLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
178
   * Unity: saturationLevel = 1
179
   */
180
  SATURATION       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
181
 /**
182
   * Smoothly change saturation level of a given Region.
183
   * <p>
184
   * Uniforms: (saturationLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
185
   * Unity: saturationLevel = 1
186
   */
187
  SMOOTH_SATURATION( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
188
 /**
189
   * Change contrast level of a given Region.
190
   * <p>
191
   * Uniforms: (contrastLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
192
   * Unity: contrastLevel = 1
193
   */
194
  CONTRAST         ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
195
 /**
196
   * Smoothly change contrast level of a given Region.
197
   * <p>
198
   * Uniforms: (contrastLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
199
   * Unity: contrastLevel = 1
200
   */
201
  SMOOTH_CONTRAST  ( EffectTypes.FRAGMENT,   new float[] {1.0f}           );
202
  // add new Fragment effects here...
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205
  
206
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
207
  
208
  private final EffectTypes type;
209
  private final float[] unity;
210
  
211
  private static final float[] unities;
212
  private static final int[] dimensions;
213
  private static final EffectNames[] names;
214

    
215
  static
216
    {
217
    int len = values().length;
218
    int i=0;
219
    
220
    dimensions = new int[len];
221
    unities    = new float[MAXDIM*len];
222
    names      = new EffectNames[len];
223

    
224
    for(EffectNames name: EffectNames.values())
225
      {
226
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
227
      names[i]      = name;
228

    
229
      switch(dimensions[i])
230
        {
231
        case 4: unities[MAXDIM*i+3] = name.unity[3];
232
        case 3: unities[MAXDIM*i+2] = name.unity[2];
233
        case 2: unities[MAXDIM*i+1] = name.unity[1];
234
        case 1: unities[MAXDIM*i  ] = name.unity[0];
235
        case 0: break;
236
        }
237
      
238
      i++;  
239
      }
240
    }
241
  
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
  
244
  EffectNames(EffectTypes type, float[] unity)
245
    {
246
    this.type = type;  
247
    this.unity= unity;
248
    }
249

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

    
252
  static EffectTypes getType(int ordinal)
253
    {
254
    return names[ordinal].type;
255
    }
256

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

    
259
  static EffectNames getName(int ordinal)
260
    {
261
    return names[ordinal];
262
    }
263

    
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

    
266
  static void fillWithUnities(int ordinal, float[] buffer, int index)
267
    {
268
    switch(dimensions[ordinal])
269
      {
270
      case 0: break;
271
      case 1: buffer[index  ]=unities[MAXDIM*ordinal  ];
272
              break;
273
      case 2: buffer[index  ]=unities[MAXDIM*ordinal  ];
274
              buffer[index+1]=unities[MAXDIM*ordinal+1];
275
              break;
276
      case 3: buffer[index  ]=unities[MAXDIM*ordinal  ];
277
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
278
              buffer[index+2]=unities[MAXDIM*ordinal+2];
279
              break;
280
      case 4: buffer[index  ]=unities[MAXDIM*ordinal  ];
281
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
282
              buffer[index+2]=unities[MAXDIM*ordinal+2];
283
              buffer[index+3]=unities[MAXDIM*ordinal+3];
284
              break;
285
      }  
286
    }
287
  
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
  
290
  static boolean isUnity(int ordinal, float[] buffer, int index)
291
    {
292
    switch(dimensions[ordinal])
293
      {
294
      case 0: return true;
295
      case 1: return buffer[index  ]==unities[MAXDIM*ordinal  ];
296
      case 2: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
297
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
298
      case 3: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
299
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
300
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
301
      case 4: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
302
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
303
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
304
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
305
      }
306
   
307
    return false;
308
    }
309

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311
// PUBLIC API
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313
/**
314
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
315
 * return EffectTypes.MATRIX.
316
 * @return type of the effect.
317
 */
318
  public EffectTypes getType()
319
    {
320
    return type;
321
    }
322

    
323
/**
324
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
325
 * @return dimension of the Effect.
326
 */
327
  public int getDimension() { return dimensions[ordinal()]; }
328
  }
(13-13/18)