Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ 291705f6

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 {@link EffectTypes}.
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
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
   * <p>
54
   * Unity: angle==0
55
   */
56
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           ),
57
 /**
58
   * Rotate the whole Object around a center point (in quaternion notation).
59
   * <p>
60
   * Uniforms: (quatX,quatY,quatZ,quatW,centerX,centerY,centerZ)
61
   * <p>
62
   * Unity: (quatX,quatY,quatZ) = (0,0,0)
63
   */
64
  QUATERNION       ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
65
 /**
66
   * Move the whole Object by a vector.
67
   * <p>
68
   * Uniforms: (vectorX,vectorY,vectorZ,UNUSED,UNUSED,UNUSED,UNUSED)
69
   * <p>
70
   * Unity: (vectorX,vectorY,vectorZ) = (0,0,0)
71
   */
72
  MOVE             ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
73
 /**
74
   * Scale the whole Object independently in all 3 dimensions.
75
   * <p>
76
   * Uniforms: (scaleX,scaleY,scaleZ,UNUSED,UNUSED,UNUSED,UNUSED)
77
   * <p>
78
   * Unity: (scaleX,scaleY,scaleZ) = (1,1,1)
79
   */
80
  SCALE            ( EffectTypes.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} ),
81
 /**
82
   * Shear the whole Object in 3 dimensions around a center point.
83
   * <p>
84
   * Uniforms: (shearX,shearY,shearZ,UNUSED,centerX,centerY,centerZ)
85
   * <p>
86
   * Unity:  (shearX,shearY,shearZ) = (0,0,0)
87
   */
88
  SHEAR            ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
89
  // add new Matrix effects here...
90

    
91
 /////////////////////////////////////////////////////////////////////////////////
92
 // VERTEX EFFECTS
93
 // Always 12 Uniforms: 6 per-effect interpolated values, 2-dimensional center of
94
 // the effect, 4-dimensional Region
95
 /**
96
   * Apply a 3D vector of force to area around a point on the surface of the Object.
97
   * <p>
98
   * Uniforms: (forceX ,forceY ,forceZ  ,UNUSED  ,
99
   *            UNUSED , UNUSED,centerX ,centerY ,
100
   *            regionX,regionY,regionRX,regionRY)
101
   * <p>
102
   * Unity: (forceX,forceY,forceZ) = (0,0,0)
103
   */
104
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),
105
 /**
106
   * Deform the whole Object by applying a 2D vector of force to a center point.
107
   * <p>
108
   * Uniforms: (forceX,forceY,UNUSED,UNUSED,
109
   *            UNUSED,UNUSED,centerX,centerY,
110
   *            UNUSED,UNUSED,UNUSED,UNUSED)
111
   * <p>
112
   * Unity: (forceX,forceY) = (0,0)
113
   */
114
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      ),
115
 /**
116
   * Pull (or push away) all points around a center point to (from) it.
117
   * <p>
118
   * Uniforms: (sinkFactor,UNUSED,UNUSED,UNUSED,
119
   *            UNUSED,UNUSED,centerX,centerY,
120
   *            regionX,regionY,regionRX,regionRY)
121
   * <p>
122
   * Unity: sinkFactor = 1
123
   */
124
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           ),
125
 /**
126
   * Smoothly rotate a limited area around a center point.
127
   * <p>
128
   * Uniforms: (swirlAngle,UNUSED,UNUSED,UNUSED,
129
   *            UNUSED, UNUSED,centerX,centerY,
130
   *            regionX,regionY,regionRX,regionRY)
131
   * <p>
132
   * Unity: swirlAngle = 0
133
   */
134
  SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
135
  /**
136
   * Directional sinusoidal wave effect. The direction of the wave is given by the 'angle'
137
   * parameters. Details: {@link DistortedObject#wave(Data5D,Data2D)}
138
   * <p>
139
   * Uniforms: (amplitude,length,phase,angleAlpha,
140
   *            angleBeta, UNUSED,centerX,centerY,
141
   *            regionX,regionY,regionRX,regionRY)
142
   * <p>
143
   * Unity: amplitude  = 0
144
   */
145
  WAVE             ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
146
  // add new Vertex Effects here...
147

    
148
 /////////////////////////////////////////////////////////////////////////////////
149
 // FRAGMENT EFFECTS
150
 // Always 8 Uniforms: 4-per effect interpolated values, 4 dimensional Region.
151
 /**
152
   * Make a given Region (partially) transparent.
153
   * <p>
154
   * Uniforms: (transparencyLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
155
   * <p>
156
   * Unity: transparencyLevel = 1
157
   */
158
  ALPHA            ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
159
 /**
160
   * Make a given Region (partially) transparent.
161
   * Effect smoothly fades towards the edges of the region.
162
   * <p>
163
   * Uniforms: (transparencyLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
164
   * Unity: transparencyLevel = 1
165
   */
166
  SMOOTH_ALPHA     ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
167
 /**
168
   * Blend current color in the texture with a given color.
169
   * <p>
170
   * Uniforms: (blendLevel,colorR,colorG,colorB, regionX, regionY, regionRX, regionRY)
171
   * <p>
172
   * Unity: blendLevel = 0
173
   */
174
  CHROMA           ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
175
 /**
176
   * Smoothly blend current color in the texture with a given color.
177
   * <p>
178
   * Uniforms: (blendLevel,colorR,colorG,colorB, regionX, regionY, regionRX, regionRY)
179
   * Unity: blendLevel = 0
180
   */
181
  SMOOTH_CHROMA    ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
182
 /**
183
   * Change brightness level of a given Region.
184
   * <p>
185
   * Uniforms: (brightnessLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
186
   * <p>
187
   * Unity: brightnessLevel = 1
188
   */
189
  BRIGHTNESS       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
190
 /**
191
   * Smoothly change brightness level of a given Region.
192
   * <p>
193
   * Uniforms: (brightnessLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
194
   * <p>
195
   * Unity: brightnessLevel = 1
196
   */
197
  SMOOTH_BRIGHTNESS( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
198
 /**
199
   * Change saturation level of a given Region.
200
   * <p>
201
   * Uniforms: (saturationLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
202
   * <p>
203
   * Unity: saturationLevel = 1
204
   */
205
  SATURATION       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
206
 /**
207
   * Smoothly change saturation level of a given Region.
208
   * <p>
209
   * Uniforms: (saturationLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
210
   * <p>
211
   * Unity: saturationLevel = 1
212
   */
213
  SMOOTH_SATURATION( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
214
 /**
215
   * Change contrast level of a given Region.
216
   * <p>
217
   * Uniforms: (contrastLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
218
   * <p>
219
   * Unity: contrastLevel = 1
220
   */
221
  CONTRAST         ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
222
 /**
223
   * Smoothly change contrast level of a given Region.
224
   * <p>
225
   * Uniforms: (contrastLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
226
   * <p>
227
   * Unity: contrastLevel = 1
228
   */
229
  SMOOTH_CONTRAST  ( EffectTypes.FRAGMENT,   new float[] {1.0f}           );
230
  // add new Fragment effects here...
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233
  
234
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
235
  
236
  private final EffectTypes type;
237
  private final float[] unity;
238
  
239
  private static final float[] unities;
240
  private static final int[] dimensions;
241
  private static final EffectNames[] names;
242

    
243
  static
244
    {
245
    int len = values().length;
246
    int i=0;
247
    
248
    dimensions = new int[len];
249
    unities    = new float[MAXDIM*len];
250
    names      = new EffectNames[len];
251

    
252
    for(EffectNames name: EffectNames.values())
253
      {
254
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
255
      names[i]      = name;
256

    
257
      switch(dimensions[i])
258
        {
259
        case 4: unities[MAXDIM*i+3] = name.unity[3];
260
        case 3: unities[MAXDIM*i+2] = name.unity[2];
261
        case 2: unities[MAXDIM*i+1] = name.unity[1];
262
        case 1: unities[MAXDIM*i  ] = name.unity[0];
263
        case 0: break;
264
        }
265
      
266
      i++;  
267
      }
268
    }
269
  
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271
  
272
  EffectNames(EffectTypes type, float[] unity)
273
    {
274
    this.type = type;  
275
    this.unity= unity;
276
    }
277

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

    
280
  static EffectTypes getType(int ordinal)
281
    {
282
    return names[ordinal].type;
283
    }
284

    
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286

    
287
  static EffectNames getName(int ordinal)
288
    {
289
    return names[ordinal];
290
    }
291

    
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

    
294
  static void fillWithUnities(int ordinal, float[] buffer, int index)
295
    {
296
    switch(dimensions[ordinal])
297
      {
298
      case 0: break;
299
      case 1: buffer[index  ]=unities[MAXDIM*ordinal  ];
300
              break;
301
      case 2: buffer[index  ]=unities[MAXDIM*ordinal  ];
302
              buffer[index+1]=unities[MAXDIM*ordinal+1];
303
              break;
304
      case 3: buffer[index  ]=unities[MAXDIM*ordinal  ];
305
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
306
              buffer[index+2]=unities[MAXDIM*ordinal+2];
307
              break;
308
      case 4: buffer[index  ]=unities[MAXDIM*ordinal  ];
309
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
310
              buffer[index+2]=unities[MAXDIM*ordinal+2];
311
              buffer[index+3]=unities[MAXDIM*ordinal+3];
312
              break;
313
      }  
314
    }
315
  
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317
  
318
  static boolean isUnity(int ordinal, float[] buffer, int index)
319
    {
320
    switch(dimensions[ordinal])
321
      {
322
      case 0: return true;
323
      case 1: return buffer[index  ]==unities[MAXDIM*ordinal  ];
324
      case 2: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
325
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
326
      case 3: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
327
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
328
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
329
      case 4: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
330
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
331
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
332
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
333
      }
334
   
335
    return false;
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339
// PUBLIC API
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341
/**
342
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
343
 * return EffectTypes.MATRIX.
344
 * @return type of the effect.
345
 */
346
  public EffectTypes getType()
347
    {
348
    return type;
349
    }
350

    
351
/**
352
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
353
 * @return dimension of the Effect.
354
 */
355
  public int getDimension() { return dimensions[ordinal()]; }
356
  }
(13-13/18)