Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ 35bece36

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 6a06a912 Leszek Koltunski
package org.distorted.library;
21
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23 476bbc81 Leszek Koltunski
/**
24
 * Names of Effects one can apply to DistortedObjects.
25 0df17fad Leszek Koltunski
 * <p>
26 e25d0dde Leszek Koltunski
 * 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 476bbc81 Leszek Koltunski
 */
42
public enum EffectNames
43 6a06a912 Leszek Koltunski
  {
44
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////////////////
45 0df17fad Leszek Koltunski
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 e25d0dde Leszek Koltunski
   * Uniforms: (angle,axisX,axisY,axisZ,centerX,centerY,centerZ)
53 0df17fad Leszek Koltunski
   * Unity: angle==0
54
   */
55 1e438fc7 Leszek Koltunski
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           ),
56 0df17fad Leszek Koltunski
 /**
57
   * Rotate the whole Object around a center point (in quaternion notation).
58
   * <p>
59 e25d0dde Leszek Koltunski
   * Uniforms: (quatX,quatY,quatZ,quatW,centerX,centerY,centerZ)
60 0df17fad Leszek Koltunski
   * 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 e25d0dde Leszek Koltunski
   * Uniforms: (vectorX,vectorY,vectorZ,UNUSED,UNUSED,UNUSED,UNUSED)
67 0df17fad Leszek Koltunski
   * Unity: (vectorX,vectorY,vectorZ) = (0,0,0)
68
   */
69 1e438fc7 Leszek Koltunski
  MOVE             ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
70 0df17fad Leszek Koltunski
 /**
71
   * Scale the whole Object independently in all 3 dimensions.
72
   * <p>
73 e25d0dde Leszek Koltunski
   * Uniforms: (scaleX,scaleY,scaleZ,UNUSED,UNUSED,UNUSED,UNUSED)
74 0df17fad Leszek Koltunski
   * Unity: (scaleX,scaleY,scaleZ) = (1,1,1)
75
   */
76 1e438fc7 Leszek Koltunski
  SCALE            ( EffectTypes.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} ),
77 0df17fad Leszek Koltunski
 /**
78
   * Shear the whole Object in 3 dimensions around a center point.
79
   * <p>
80 e25d0dde Leszek Koltunski
   * Uniforms: (shearX,shearY,shearZ,UNUSED,centerX,centerY,centerZ)
81 0df17fad Leszek Koltunski
   * Unity:  (shearX,shearY,shearZ) = (0,0,0)
82
   */
83 1e438fc7 Leszek Koltunski
  SHEAR            ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
84
  // add new Matrix effects here...
85 0df17fad Leszek Koltunski
86
 /////////////////////////////////////////////////////////////////////////////////
87
 // VERTEX EFFECTS
88 02ef26bc Leszek Koltunski
 // Always 12 Uniforms: 4 per-effect interpolated values, 2 caches, 2-dimensional
89
 // center of the effect, 4-dimensional Region
90 0df17fad Leszek Koltunski
 /**
91
   * Apply a 3D vector of force to area around a point on the surface of the Object.
92
   * <p>
93 02ef26bc Leszek Koltunski
   * Uniforms: (forceX ,forceY ,forceZ  ,UNUSED  ,
94
  *             UNUSED , UNUSED,centerX ,centerY ,
95
  *             regionX,regionY,regionRX,regionRY)
96 0df17fad Leszek Koltunski
   * Unity: (forceX,forceY,forceZ) = (0,0,0)
97
   */
98 e8c81a8e Leszek Koltunski
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),
99 0df17fad Leszek Koltunski
 /**
100
   * Deform the whole Object by applying a 2D vector of force to a center point.
101
   * <p>
102 02ef26bc Leszek Koltunski
   * Uniforms: (forceX,forceY,UNUSED,UNUSED,
103
   *            UNUSED,UNUSED,centerX,centerY,
104
   *            UNUSED,UNUSED,UNUSED,UNUSED)
105 0df17fad Leszek Koltunski
   * Unity: (forceX,forceY) = (0,0)
106
   */
107 1e438fc7 Leszek Koltunski
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      ),
108 0df17fad Leszek Koltunski
 /**
109
   * Pull (or push away) all points around a center point to (from) it.
110
   * <p>
111 02ef26bc Leszek Koltunski
   * Uniforms: (sinkFactor,UNUSED,UNUSED,UNUSED,
112
   *            UNUSED,UNUSED,centerX,centerY,
113
   *            regionX,regionY,regionRX,regionRY)
114 0df17fad Leszek Koltunski
   * Unity: sinkFactor = 1
115
   */
116 1e438fc7 Leszek Koltunski
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           ),
117 0df17fad Leszek Koltunski
 /**
118
   * Smoothly rotate a limited area around a center point.
119
   * <p>
120 02ef26bc Leszek Koltunski
   * Uniforms: (swirlAngle,UNUSED,UNUSED,UNUSED,
121 35bece36 Leszek Koltunski
   *            UNUSED, UNUSED,centerX,centerY,
122 02ef26bc Leszek Koltunski
   *            regionX,regionY,regionRX,regionRY)
123 0df17fad Leszek Koltunski
   * Unity: swirlAngle = 0
124
   */
125 1e438fc7 Leszek Koltunski
  SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
126 4fde55a0 Leszek Koltunski
  /**
127
   * Directional sinusoidal wave effect. The direction of the wave is given by the 'angle'
128
   * parameter, which is the angle (in degrees) the direction forms with the X-axis.
129
   * <p>
130 35bece36 Leszek Koltunski
   * Uniforms: (amplitude,length,angleAlpha,angleBeta,
131
   *            UNUSED, UNUSED,centerX,centerY,
132 02ef26bc Leszek Koltunski
   *            regionX,regionY,regionRX,regionRY)
133 4fde55a0 Leszek Koltunski
   * Unity: amplitude  = 0
134
   */
135
  WAVE             ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
136 6a06a912 Leszek Koltunski
  // add new Vertex Effects here...
137 0df17fad Leszek Koltunski
138
 /////////////////////////////////////////////////////////////////////////////////
139
 // FRAGMENT EFFECTS
140
 // Always 8 Uniforms: 4-per effect interpolated values, 4 dimensional Region.
141
 /**
142
   * Make a given Region (partially) transparent.
143
   * <p>
144 e25d0dde Leszek Koltunski
   * Uniforms: (transparencyLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
145 0df17fad Leszek Koltunski
   * Unity: transparencyLevel = 1
146
   */
147 1e438fc7 Leszek Koltunski
  ALPHA            ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
148 0df17fad Leszek Koltunski
 /**
149
   * Make a given Region (partially) transparent.
150
   * Effect smoothly fades towards the edges of the region.
151
   * <p>
152 e25d0dde Leszek Koltunski
   * Uniforms: (transparencyLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
153 0df17fad Leszek Koltunski
   * Unity: transparencyLevel = 1
154
   */
155 1e438fc7 Leszek Koltunski
  SMOOTH_ALPHA     ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
156 0df17fad Leszek Koltunski
 /**
157
   * Blend current color in the texture with a given color.
158
   * <p>
159 e25d0dde Leszek Koltunski
   * Uniforms: (blendLevel,colorR,colorG,colorB, regionX, regionY, regionRX, regionRY)
160 0df17fad Leszek Koltunski
   * Unity: blendLevel = 0
161
   */
162 1e438fc7 Leszek Koltunski
  CHROMA           ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
163 0df17fad Leszek Koltunski
 /**
164
   * Smoothly blend current color in the texture with a given color.
165
   * <p>
166 e25d0dde Leszek Koltunski
   * Uniforms: (blendLevel,colorR,colorG,colorB, regionX, regionY, regionRX, regionRY)
167 0df17fad Leszek Koltunski
   * Unity: blendLevel = 0
168
   */
169 1e438fc7 Leszek Koltunski
  SMOOTH_CHROMA    ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
170 0df17fad Leszek Koltunski
 /**
171
   * Change brightness level of a given Region.
172
   * <p>
173 e25d0dde Leszek Koltunski
   * Uniforms: (brightnessLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
174 0df17fad Leszek Koltunski
   * Unity: brightnessLevel = 1
175
   */
176 1e438fc7 Leszek Koltunski
  BRIGHTNESS       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
177 0df17fad Leszek Koltunski
 /**
178
   * Smoothly change brightness level of a given Region.
179
   * <p>
180 e25d0dde Leszek Koltunski
   * Uniforms: (brightnessLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
181 0df17fad Leszek Koltunski
   * Unity: brightnessLevel = 1
182
   */
183 1e438fc7 Leszek Koltunski
  SMOOTH_BRIGHTNESS( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
184 0df17fad Leszek Koltunski
 /**
185
   * Change saturation level of a given Region.
186
   * <p>
187 e25d0dde Leszek Koltunski
   * Uniforms: (saturationLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
188 0df17fad Leszek Koltunski
   * Unity: saturationLevel = 1
189
   */
190 1e438fc7 Leszek Koltunski
  SATURATION       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
191 0df17fad Leszek Koltunski
 /**
192
   * Smoothly change saturation level of a given Region.
193
   * <p>
194 e25d0dde Leszek Koltunski
   * Uniforms: (saturationLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
195 0df17fad Leszek Koltunski
   * Unity: saturationLevel = 1
196
   */
197 1e438fc7 Leszek Koltunski
  SMOOTH_SATURATION( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
198 0df17fad Leszek Koltunski
 /**
199
   * Change contrast level of a given Region.
200
   * <p>
201 e25d0dde Leszek Koltunski
   * Uniforms: (contrastLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
202 0df17fad Leszek Koltunski
   * Unity: contrastLevel = 1
203
   */
204 1e438fc7 Leszek Koltunski
  CONTRAST         ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
205 0df17fad Leszek Koltunski
 /**
206
   * Smoothly change contrast level of a given Region.
207
   * <p>
208 e25d0dde Leszek Koltunski
   * Uniforms: (contrastLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
209 0df17fad Leszek Koltunski
   * Unity: contrastLevel = 1
210
   */
211
  SMOOTH_CONTRAST  ( EffectTypes.FRAGMENT,   new float[] {1.0f}           );
212 6a06a912 Leszek Koltunski
  // add new Fragment effects here...
213
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215
  
216
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
217
  
218 e8c81a8e Leszek Koltunski
  private final EffectTypes type;
219
  private final float[] unity;
220 6a06a912 Leszek Koltunski
  
221 e8c81a8e Leszek Koltunski
  private static final float[] unities;
222
  private static final int[] dimensions;
223
  private static final EffectNames[] names;
224
225 6a06a912 Leszek Koltunski
  static
226
    {
227
    int len = values().length;
228
    int i=0;
229
    
230
    dimensions = new int[len];
231
    unities    = new float[MAXDIM*len];
232 e8c81a8e Leszek Koltunski
    names      = new EffectNames[len];
233
234 6a06a912 Leszek Koltunski
    for(EffectNames name: EffectNames.values())
235
      {
236 b3618cb5 Leszek Koltunski
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
237 e8c81a8e Leszek Koltunski
      names[i]      = name;
238
239 6a06a912 Leszek Koltunski
      switch(dimensions[i])
240
        {
241
        case 4: unities[MAXDIM*i+3] = name.unity[3];
242
        case 3: unities[MAXDIM*i+2] = name.unity[2];
243
        case 2: unities[MAXDIM*i+1] = name.unity[1];
244 0318e7e3 Leszek Koltunski
        case 1: unities[MAXDIM*i  ] = name.unity[0];
245 6a06a912 Leszek Koltunski
        case 0: break;
246
        }
247
      
248
      i++;  
249
      }
250
    }
251
  
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253
  
254 1e438fc7 Leszek Koltunski
  EffectNames(EffectTypes type, float[] unity)
255 6a06a912 Leszek Koltunski
    {
256
    this.type = type;  
257
    this.unity= unity;
258
    }
259
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261 c6e1c219 Leszek Koltunski
262 1e438fc7 Leszek Koltunski
  static EffectTypes getType(int ordinal)
263 6a06a912 Leszek Koltunski
    {
264 e8c81a8e Leszek Koltunski
    return names[ordinal].type;
265
    }
266 b3618cb5 Leszek Koltunski
267 e8c81a8e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
268
269
  static EffectNames getName(int ordinal)
270
    {
271
    return names[ordinal];
272 6a06a912 Leszek Koltunski
    }
273
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275
276
  static void fillWithUnities(int ordinal, float[] buffer, int index)
277
    {
278
    switch(dimensions[ordinal])
279
      {
280
      case 0: break;
281 0318e7e3 Leszek Koltunski
      case 1: buffer[index  ]=unities[MAXDIM*ordinal  ];
282 6a06a912 Leszek Koltunski
              break;
283 0318e7e3 Leszek Koltunski
      case 2: buffer[index  ]=unities[MAXDIM*ordinal  ];
284 6a06a912 Leszek Koltunski
              buffer[index+1]=unities[MAXDIM*ordinal+1];
285
              break;
286 0318e7e3 Leszek Koltunski
      case 3: buffer[index  ]=unities[MAXDIM*ordinal  ];
287 6a06a912 Leszek Koltunski
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
288
              buffer[index+2]=unities[MAXDIM*ordinal+2];
289
              break;
290 0318e7e3 Leszek Koltunski
      case 4: buffer[index  ]=unities[MAXDIM*ordinal  ];
291 6a06a912 Leszek Koltunski
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
292
              buffer[index+2]=unities[MAXDIM*ordinal+2];
293
              buffer[index+3]=unities[MAXDIM*ordinal+3];
294
              break;
295
      }  
296
    }
297
  
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299
  
300
  static boolean isUnity(int ordinal, float[] buffer, int index)
301
    {
302
    switch(dimensions[ordinal])
303
      {
304
      case 0: return true;
305 0318e7e3 Leszek Koltunski
      case 1: return buffer[index  ]==unities[MAXDIM*ordinal  ];
306
      case 2: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
307 6a06a912 Leszek Koltunski
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
308 0318e7e3 Leszek Koltunski
      case 3: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
309 6a06a912 Leszek Koltunski
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
310
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
311 0318e7e3 Leszek Koltunski
      case 4: return buffer[index  ]==unities[MAXDIM*ordinal  ] &&
312 6a06a912 Leszek Koltunski
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
313
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
314
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
315
      }
316
   
317
    return false;
318
    }
319
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321 476bbc81 Leszek Koltunski
// PUBLIC API
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323
/**
324
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
325
 * return EffectTypes.MATRIX.
326
 * @return type of the effect.
327
 */
328
  public EffectTypes getType()
329
    {
330
    return type;
331
    }
332 ac094579 Leszek Koltunski
333
/**
334
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
335
 * @return dimension of the Effect.
336
 */
337
  public int getDimension() { return dimensions[ordinal()]; }
338 d333eb6b Leszek Koltunski
  }