Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ 43fbf0dd

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 4 Uniforms: 4 per-effect interpolated values.
245
 /**
246
   * Blur the area around the center.
247
   * <p>
248
   * Uniforms: (radius,UNUSED,UNUSED,UNUSED)
249
   * <p>
250
   * Unity: radius = 0
251
   */
252
  BLUR             ( EffectTypes.POSTPROCESS,new float[] {0.0f}          , 1, false, false );
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255
  
256
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
257
  
258
  private final EffectTypes type;
259
  private final float[] unity;
260
  private final int dimension;
261
  private final boolean supportsR;
262
  private final boolean supportsC;
263

    
264
  private static final float[] unities;
265
  private static final int[] unityDimensions;
266
  private static final int[] dimensions;
267
  private static final boolean[] supportsRegion;
268
  private static final boolean[] supportsCenter;
269
  private static final EffectNames[] names;
270

    
271
  static
272
    {
273
    int len = values().length;
274
    int i=0;
275
    
276
    unityDimensions = new int[len];
277
    dimensions      = new int[len];
278
    supportsRegion  = new boolean[len];
279
    supportsCenter  = new boolean[len];
280
    unities         = new float[MAXDIM*len];
281
    names           = new EffectNames[len];
282

    
283
    for(EffectNames name: EffectNames.values())
284
      {
285
      unityDimensions[i] = (name.unity==null ? 0 : name.unity.length);
286
      dimensions[i]      = name.dimension;
287
      supportsRegion[i]  = name.supportsR;
288
      supportsCenter[i]  = name.supportsC;
289
      names[i]           = name;
290

    
291
      switch(unityDimensions[i])
292
        {
293
        case 4: unities[MAXDIM*i+3] = name.unity[3];
294
        case 3: unities[MAXDIM*i+2] = name.unity[2];
295
        case 2: unities[MAXDIM*i+1] = name.unity[1];
296
        case 1: unities[MAXDIM*i  ] = name.unity[0];
297
        case 0: break;
298
        }
299
      
300
      i++;  
301
      }
302
    }
303
  
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305
  
306
  EffectNames(EffectTypes type, float[] unity, int dimension, boolean supportsR, boolean supportsC)
307
    {
308
    this.type      = type;
309
    this.unity     = unity;
310
    this.dimension = dimension;
311
    this.supportsR = supportsR;
312
    this.supportsC = supportsC;
313
    }
314

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

    
317
  static EffectTypes getType(int ordinal)
318
    {
319
    return names[ordinal].type;
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  static EffectNames getName(int ordinal)
325
    {
326
    return names[ordinal];
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

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

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376
// PUBLIC API
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378
/**
379
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
380
 * return EffectTypes.MATRIX.
381
 * @return type of the effect.
382
 */
383
  public EffectTypes getType()
384
    {
385
    return type;
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
/**
391
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
392
 * @return dimension of the Effect.
393
 */
394
  public int getDimension() { return dimensions[ordinal()]; }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397

    
398
/**
399
 * Do we support being masked by a Region?
400
 * @return true if the Effect supports being masked with a Region.
401
 */
402
  public boolean supportsRegion() { return supportsRegion[ordinal()]; }
403

    
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

    
406
/**
407
 * Does this Effect have a center?
408
 * @return true if the Effect has a center.
409
 */
410
  public boolean supportsCenter() { return supportsCenter[ordinal()]; }
411

    
412
  }
(13-13/22)