Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ cacc63de

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 add to the DistortedEffects queues.
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 /////////////// DIM // REGION // CENTER
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}           , 4, false, true ),
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} , 4, false, true ),
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} , 3, false, false ),
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} , 3, false, false ),
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} , 3, false, true ),
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 , centerX ,centerY , centerZ,
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} , 3, true, true ),
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,centerX,centerY,centerZ,
110
   *            UNUSED,UNUSED,UNUSED,UNUSED)
111
   * <p>
112
   * Unity: (forceX,forceY) = (0,0)
113
   */
114
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      , 3, true, true ),
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,centerX,centerY,centerZ,
120
   *            regionX,regionY,regionRX,regionRY)
121
   * <p>
122
   * Unity: sinkFactor = 1
123
   */
124
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           , 1, true, true ),
125
  /**
126
   * Pull (or push away) all points around a line to (from) it.
127
   * <p>
128
   * Uniforms: (pinchFactor,lineAngle,UNUSED,UNUSED,
129
   *            UNUSED,centerX,centerY,centerZ,
130
   *            regionX,regionY,regionRX,regionRY)
131
   * <p>
132
   * Unity: sinkFactor = 1
133
   */
134
  PINCH            ( EffectTypes.VERTEX  ,   new float[] {1.0f}           , 2, true, true ),
135
 /**
136
   * Smoothly rotate a limited area around a center point.
137
   * <p>
138
   * Uniforms: (swirlAngle,UNUSED,UNUSED,UNUSED,
139
   *            UNUSED, centerX,centerY,centerZ,
140
   *            regionX,regionY,regionRX,regionRY)
141
   * <p>
142
   * Unity: swirlAngle = 0
143
   */
144
  SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           , 1, true, true ),
145
  /**
146
   * Directional sinusoidal wave effect. The direction of the wave is given by the 'angle'
147
   * parameters. Details: {@link DistortedEffects#wave(org.distorted.library.type.Data5D,org.distorted.library.type.Data3D)}
148
   * <p>
149
   * Uniforms: (amplitude,length,phase,angleAlpha,
150
   *            angleBeta, centerX,centerY,centerZ,
151
   *            regionX,regionY,regionRX,regionRY)
152
   * <p>
153
   * Unity: amplitude  = 0
154
   */
155
  WAVE             ( EffectTypes.VERTEX  ,   new float[] {0.0f}           , 5, true, true ),
156
  // add new Vertex Effects here...
157

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

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
  
244
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
245
  
246
  private final EffectTypes type;
247
  private final float[] unity;
248
  private final int dimension;
249
  private final boolean supportsR;
250
  private final boolean supportsC;
251

    
252
  private static final float[] unities;
253
  private static final int[] unityDimensions;
254
  private static final int[] dimensions;
255
  private static final boolean[] supportsRegion;
256
  private static final boolean[] supportsCenter;
257
  private static final EffectNames[] names;
258

    
259
  static
260
    {
261
    int len = values().length;
262
    int i=0;
263
    
264
    unityDimensions = new int[len];
265
    dimensions      = new int[len];
266
    supportsRegion  = new boolean[len];
267
    supportsCenter  = new boolean[len];
268
    unities         = new float[MAXDIM*len];
269
    names           = new EffectNames[len];
270

    
271
    for(EffectNames name: EffectNames.values())
272
      {
273
      unityDimensions[i] = (name.unity==null ? 0 : name.unity.length);
274
      dimensions[i]      = name.dimension;
275
      supportsRegion[i]  = name.supportsR;
276
      supportsCenter[i]  = name.supportsC;
277
      names[i]           = name;
278

    
279
      switch(unityDimensions[i])
280
        {
281
        case 4: unities[MAXDIM*i+3] = name.unity[3];
282
        case 3: unities[MAXDIM*i+2] = name.unity[2];
283
        case 2: unities[MAXDIM*i+1] = name.unity[1];
284
        case 1: unities[MAXDIM*i  ] = name.unity[0];
285
        case 0: break;
286
        }
287
      
288
      i++;  
289
      }
290
    }
291
  
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293
  
294
  EffectNames(EffectTypes type, float[] unity, int dimension, boolean supportsR, boolean supportsC)
295
    {
296
    this.type      = type;
297
    this.unity     = unity;
298
    this.dimension = dimension;
299
    this.supportsR = supportsR;
300
    this.supportsC = supportsC;
301
    }
302

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

    
305
  static EffectTypes getType(int ordinal)
306
    {
307
    return names[ordinal].type;
308
    }
309

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

    
312
  static EffectNames getName(int ordinal)
313
    {
314
    return names[ordinal];
315
    }
316

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

    
319
  static void fillWithUnities(int ordinal, float[] buffer, int index)
320
    {
321
    switch(unityDimensions[ordinal])
322
      {
323
      case 0: break;
324
      case 1: buffer[index  ]=unities[MAXDIM*ordinal  ];
325
              break;
326
      case 2: buffer[index  ]=unities[MAXDIM*ordinal  ];
327
              buffer[index+1]=unities[MAXDIM*ordinal+1];
328
              break;
329
      case 3: buffer[index  ]=unities[MAXDIM*ordinal  ];
330
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
331
              buffer[index+2]=unities[MAXDIM*ordinal+2];
332
              break;
333
      case 4: buffer[index  ]=unities[MAXDIM*ordinal  ];
334
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
335
              buffer[index+2]=unities[MAXDIM*ordinal+2];
336
              buffer[index+3]=unities[MAXDIM*ordinal+3];
337
              break;
338
      }  
339
    }
340
  
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
  
343
  static boolean isUnity(int ordinal, float[] buffer, int index)
344
    {
345
    switch(unityDimensions[ordinal])
346
      {
347
      case 0: return true;
348
      case 1: return buffer[index  ]==unities[MAXDIM*ordinal  ];
349
      case 2: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
350
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
351
      case 3: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
352
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
353
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
354
      case 4: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
355
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
356
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
357
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
358
      }
359
   
360
    return false;
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364
// PUBLIC API
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366
/**
367
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
368
 * return EffectTypes.MATRIX.
369
 * @return type of the effect.
370
 */
371
  public EffectTypes getType()
372
    {
373
    return type;
374
    }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
/**
379
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
380
 * @return dimension of the Effect.
381
 */
382
  public int getDimension() { return dimensions[ordinal()]; }
383

    
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

    
386
/**
387
 * Do we support being masked by a Region?
388
 * @return true if the Effect supports being masked with a Region.
389
 */
390
  public boolean supportsRegion() { return supportsRegion[ordinal()]; }
391

    
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

    
394
/**
395
 * Does this Effect have a center?
396
 * @return true if the Effect has a center.
397
 */
398
  public boolean supportsCenter() { return supportsCenter[ordinal()]; }
399

    
400
  }
(7-7/15)