Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ 3695d6fa

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