Project

General

Profile

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

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

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 3D vector of force to a center point.
107
   * <p>
108
   * Uniforms: (forceX,forceY,forceZ,UNUSED,
109
   *            UNUSED,centerX,centerY,centerZ,
110
   *            regionX,regionY,regionRX,regionRY)
111
   * <p>
112
   * Unity: (forceX,forceY,forceZ) = (0,0,0)
113
   */
114
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,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
  // POSTPROCESSING EFFECTS.
244
  // Always 5 Uniforms: 5 per-effect interpolated values.
245
 /**
246
   * Blur the area around the center.
247
   * <p>
248
   * Uniforms: (radius,UNUSED,UNUSED,UNUSED,UNUSED)
249
   * <p>
250
   * Unity: radius = 0
251
   */
252
  BLUR             ( EffectTypes.POSTPROCESS,new float[] {0.0f}          , 1, false, false ),
253
/**
254
   * Make the object Glow with a certain color and configurable radius of the halo around it.
255
   * <p>
256
   * Uniforms: (A,R,G,B,radius)
257
   * <p>
258
   * Unity: radius = 0
259
   */
260
  GLOW             ( EffectTypes.POSTPROCESS,new float[] {0.0f}          , 5, false, false );
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263
  
264
  private static final int MAXDIM = 4;  // maximum supported dimension of the Unity of an Effect
265
                                        // (not to be confused with dimension of the Effect itself!)
266
  private final EffectTypes type;
267
  private final float[] unity;
268
  private final int dimension;
269
  private final boolean supportsR;
270
  private final boolean supportsC;
271

    
272
  private static final float[] unities;
273
  private static final int[] unityDimensions;
274
  private static final int[] dimensions;
275
  private static final boolean[] supportsRegion;
276
  private static final boolean[] supportsCenter;
277
  private static final EffectNames[] names;
278

    
279
  static
280
    {
281
    int len = values().length;
282
    int i=0;
283
    
284
    unityDimensions = new int[len];
285
    dimensions      = new int[len];
286
    supportsRegion  = new boolean[len];
287
    supportsCenter  = new boolean[len];
288
    unities         = new float[MAXDIM*len];
289
    names           = new EffectNames[len];
290

    
291
    for(EffectNames name: EffectNames.values())
292
      {
293
      unityDimensions[i] = (name.unity==null ? 0 : name.unity.length);
294
      dimensions[i]      = name.dimension;
295
      supportsRegion[i]  = name.supportsR;
296
      supportsCenter[i]  = name.supportsC;
297
      names[i]           = name;
298

    
299
      switch(unityDimensions[i])
300
        {
301
        case 4: unities[MAXDIM*i+3] = name.unity[3];
302
        case 3: unities[MAXDIM*i+2] = name.unity[2];
303
        case 2: unities[MAXDIM*i+1] = name.unity[1];
304
        case 1: unities[MAXDIM*i  ] = name.unity[0];
305
        case 0: break;
306
        }
307
      
308
      i++;  
309
      }
310
    }
311
  
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313
  
314
  EffectNames(EffectTypes type, float[] unity, int dimension, boolean supportsR, boolean supportsC)
315
    {
316
    this.type      = type;
317
    this.unity     = unity;
318
    this.dimension = dimension;
319
    this.supportsR = supportsR;
320
    this.supportsC = supportsC;
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

    
325
  static EffectTypes getType(int ordinal)
326
    {
327
    return names[ordinal].type;
328
    }
329

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

    
332
  static EffectNames getName(int ordinal)
333
    {
334
    return names[ordinal];
335
    }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
  static void fillWithUnities(int ordinal, float[] buffer, int index)
340
    {
341
    switch(unityDimensions[ordinal])
342
      {
343
      case 0: break;
344
      case 1: buffer[index  ]=unities[MAXDIM*ordinal  ];
345
              break;
346
      case 2: buffer[index  ]=unities[MAXDIM*ordinal  ];
347
              buffer[index+1]=unities[MAXDIM*ordinal+1];
348
              break;
349
      case 3: buffer[index  ]=unities[MAXDIM*ordinal  ];
350
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
351
              buffer[index+2]=unities[MAXDIM*ordinal+2];
352
              break;
353
      case 4: buffer[index  ]=unities[MAXDIM*ordinal  ];
354
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
355
              buffer[index+2]=unities[MAXDIM*ordinal+2];
356
              buffer[index+3]=unities[MAXDIM*ordinal+3];
357
              break;
358
      }  
359
    }
360
  
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362
  
363
  static boolean isUnity(int ordinal, float[] buffer, int index)
364
    {
365
    switch(unityDimensions[ordinal])
366
      {
367
      case 0: return true;
368
      case 1: return buffer[index  ]==unities[MAXDIM*ordinal  ];
369
      case 2: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
370
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
371
      case 3: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
372
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
373
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
374
      case 4: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
375
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
376
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
377
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
378
      }
379
   
380
    return false;
381
    }
382

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

    
385
  static int size()
386
    {
387
    return values().length;
388
    }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
// PUBLIC API
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393
/**
394
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
395
 * return EffectTypes.MATRIX.
396
 * @return type of the effect.
397
 */
398
  public EffectTypes getType()
399
    {
400
    return type;
401
    }
402

    
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404

    
405
/**
406
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
407
 * @return dimension of the Effect.
408
 */
409
  public int getDimension() { return dimensions[ordinal()]; }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
/**
414
 * Do we support being masked by a Region?
415
 * @return true if the Effect supports being masked with a Region.
416
 */
417
  public boolean supportsRegion() { return supportsRegion[ordinal()]; }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

    
421
/**
422
 * Does this Effect have a center?
423
 * @return true if the Effect has a center.
424
 */
425
  public boolean supportsCenter() { return supportsCenter[ordinal()]; }
426

    
427
  }
(16-16/26)