Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ 0df17fad

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 apply to DistortedObjects.
25
 * <p>
26
 * Effect's 'unity' is a set of values which
27
 */
28
public enum EffectNames
29
  {
30
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////////////////
31

    
32
  /////////////////////////////////////////////////////////////////////////////////
33
  // MATRIX EFFECTS.
34
  // Always 7 Uniforms: 4 per-effect interpolated values + 3 dimensional center.
35
 /**
36
   * Rotate the whole Object around a center point (in angle-axis notation).
37
   * <p>
38
   * 7 Uniforms: (angle,axisX,axisY,axisZ,centerX,centerY,centerZ)
39
   * Unity: angle==0
40
   */
41
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           ),
42
 /**
43
   * Rotate the whole Object around a center point (in quaternion notation).
44
   * <p>
45
   * 7 Uniforms: (quatX,quatY,quatZ,quatW,centerX,centerY,centerZ)
46
   * Unity: (quatX,quatY,quatZ) = (0,0,0)
47
   */
48
  QUATERNION       ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
49
 /**
50
   * Move the whole Object by a vector.
51
   * <p>
52
   * 7 Uniforms: (vectorX,vectorY,vectorZ,UNUSED,UNUSED,UNUSED,UNUSED)
53
   * Unity: (vectorX,vectorY,vectorZ) = (0,0,0)
54
   */
55
  MOVE             ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
56
 /**
57
   * Scale the whole Object independently in all 3 dimensions.
58
   * <p>
59
   * 7 Uniforms: (scaleX,scaleY,scaleZ,UNUSED,UNUSED,UNUSED,UNUSED)
60
   * Unity: (scaleX,scaleY,scaleZ) = (1,1,1)
61
   */
62
  SCALE            ( EffectTypes.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} ),
63
 /**
64
   * Shear the whole Object in 3 dimensions around a center point.
65
   * <p>
66
   * 7 Uniforms: (shearX,shearY,shearZ,UNUSED,centerX,centerY,centerZ)
67
   * Unity:  (shearX,shearY,shearZ) = (0,0,0)
68
   */
69
  SHEAR            ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
70
  // add new Matrix effects here...
71

    
72
 /////////////////////////////////////////////////////////////////////////////////
73
 // VERTEX EFFECTS
74
 // Always 9 Uniforms: 3 per-effect interpolated values, 4-dimensional Region,
75
 // 2-dimensional center of the effect.
76
 /**
77
   * Apply a 3D vector of force to area around a point on the surface of the Object.
78
   * <p>
79
   * 9 Uniforms: (forceX,forceY,forceZ,regionX,regionY,regionRX,regionRY,centerX,centerY)
80
   * Unity: (forceX,forceY,forceZ) = (0,0,0)
81
   */
82
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),      // keep this the first VERT effect (reason: getType)
83
 /**
84
   * Deform the whole Object by applying a 2D vector of force to a center point.
85
   * <p>
86
   * 9 Uniforms: (forceX,forceY,UNUSED,UNUSED,UNUSED,UNUSED,UNUSED,centerX,centerY)
87
   * Unity: (forceX,forceY) = (0,0)
88
   */
89
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      ),
90
 /**
91
   * Pull (or push away) all points around a center point to (from) it.
92
   * <p>
93
   * 9 Uniforms: (sinkFactor,UNUSED,UNUSED,regionX,regionY,regionRX,regionRY,centerX,centerY)
94
   * Unity: sinkFactor = 1
95
   */
96
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           ),
97
 /**
98
   * Smoothly rotate a limited area around a center point.
99
   * <p>
100
   * 9 Uniforms: (swirlAngle,UNUSED,UNUSED,regionX,regionY,regionRX,regionRY,centerX,centerY)
101
   * Unity: swirlAngle = 0
102
   */
103
  SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
104
  // add new Vertex Effects here...
105

    
106
 /////////////////////////////////////////////////////////////////////////////////
107
 // FRAGMENT EFFECTS
108
 // Always 8 Uniforms: 4-per effect interpolated values, 4 dimensional Region.
109
 /**
110
   * Create square-shaped macroblocks.
111
   * <p>
112
   * 8 Uniforms: (macroblockSize,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
113
   * Unity: macroblockSize = 1
114
   */
115
  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),      // keep this the first FRAG effect (reason: getType)
116
 /**
117
   * Make a given Region (partially) transparent.
118
   * <p>
119
   * 8 Uniforms: (transparencyLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
120
   * Unity: transparencyLevel = 1
121
   */
122
  ALPHA            ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
123
 /**
124
   * Make a given Region (partially) transparent.
125
   * Effect smoothly fades towards the edges of the region.
126
   * <p>
127
   * 8 Uniforms: (transparencyLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
128
   * Unity: transparencyLevel = 1
129
   */
130
  SMOOTH_ALPHA     ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
131
 /**
132
   * Blend current color in the texture with a given color.
133
   * <p>
134
   * 8 Uniforms: (blendLevel,colorR,colorG,colorB, regionX, regionY, regionRX, regionRY)
135
   * Unity: blendLevel = 0
136
   */
137
  CHROMA           ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
138
 /**
139
   * Smoothly blend current color in the texture with a given color.
140
   * <p>
141
   * 8 Uniforms: (blendLevel,colorR,colorG,colorB, regionX, regionY, regionRX, regionRY)
142
   * Unity: blendLevel = 0
143
   */
144
  SMOOTH_CHROMA    ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
145
 /**
146
   * Change brightness level of a given Region.
147
   * <p>
148
   * 8 Uniforms: (brightnessLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
149
   * Unity: brightnessLevel = 1
150
   */
151
  BRIGHTNESS       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
152
 /**
153
   * Smoothly change brightness level of a given Region.
154
   * <p>
155
   * 8 Uniforms: (brightnessLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
156
   * Unity: brightnessLevel = 1
157
   */
158
  SMOOTH_BRIGHTNESS( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
159
 /**
160
   * Change saturation level of a given Region.
161
   * <p>
162
   * 8 Uniforms: (saturationLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
163
   * Unity: saturationLevel = 1
164
   */
165
  SATURATION       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
166
 /**
167
   * Smoothly change saturation level of a given Region.
168
   * <p>
169
   * 8 Uniforms: (saturationLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
170
   * Unity: saturationLevel = 1
171
   */
172
  SMOOTH_SATURATION( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
173
 /**
174
   * Change contrast level of a given Region.
175
   * <p>
176
   * 8 Uniforms: (contrastLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
177
   * Unity: contrastLevel = 1
178
   */
179
  CONTRAST         ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
180
 /**
181
   * Smoothly change contrast level of a given Region.
182
   * <p>
183
   * 8 Uniforms: (contrastLevel,UNUSED,UNUSED,UNUSED, regionX, regionY, regionRX, regionRY)
184
   * Unity: contrastLevel = 1
185
   */
186
  SMOOTH_CONTRAST  ( EffectTypes.FRAGMENT,   new float[] {1.0f}           );
187
  // add new Fragment effects here...
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190
  
191
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
192
  
193
  private EffectTypes type;
194
  private float[] unity;
195
  
196
  static private float[] unities;
197
  static private int[] dimensions;
198
  
199
  static
200
    {
201
    int len = values().length;
202
    int i=0;
203
    
204
    dimensions = new int[len];
205
    unities    = new float[MAXDIM*len];
206
    
207
    for(EffectNames name: EffectNames.values())
208
      {
209
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
210
      
211
      switch(dimensions[i])
212
        {
213
        case 4: unities[MAXDIM*i+3] = name.unity[3];
214
        case 3: unities[MAXDIM*i+2] = name.unity[2];
215
        case 2: unities[MAXDIM*i+1] = name.unity[1];
216
        case 1: unities[MAXDIM*i+0] = name.unity[0];
217
        case 0: break;
218
        }
219
      
220
      i++;  
221
      }
222
    }
223
  
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225
  
226
  EffectNames(EffectTypes type, float[] unity)
227
    {
228
    this.type = type;  
229
    this.unity= unity;
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233
// yes, I know we could have used values(i) but that allocates a new copy each time!
234

    
235
  static EffectTypes getType(int ordinal)
236
    {
237
    if( ordinal<DISTORT.ordinal()     ) return EffectTypes.MATRIX;
238
    if( ordinal<MACROBLOCK.ordinal()  ) return EffectTypes.VERTEX;
239

    
240
    return EffectTypes.FRAGMENT;
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
  static void fillWithUnities(int ordinal, float[] buffer, int index)
246
    {
247
    switch(dimensions[ordinal])
248
      {
249
      case 0: break;
250
      case 1: buffer[index+0]=unities[MAXDIM*ordinal+0];
251
              break;
252
      case 2: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
253
              buffer[index+1]=unities[MAXDIM*ordinal+1];
254
              break;
255
      case 3: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
256
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
257
              buffer[index+2]=unities[MAXDIM*ordinal+2];
258
              break;
259
      case 4: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
260
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
261
              buffer[index+2]=unities[MAXDIM*ordinal+2];
262
              buffer[index+3]=unities[MAXDIM*ordinal+3];
263
              break;
264
      }  
265
    }
266
  
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268
  
269
  static boolean isUnity(int ordinal, float[] buffer, int index)
270
    {
271
    switch(dimensions[ordinal])
272
      {
273
      case 0: return true;
274
      case 1: return buffer[index+0]==unities[MAXDIM*ordinal+0];
275
      case 2: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
276
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
277
      case 3: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
278
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
279
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
280
      case 4: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
281
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
282
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
283
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
284
      }
285
   
286
    return false;
287
    }
288

    
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290
// PUBLIC API
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292
/**
293
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
294
 * return EffectTypes.MATRIX.
295
 * @return type of the effect.
296
 */
297
  public EffectTypes getType()
298
    {
299
    return type;
300
    }
301
  }
(12-12/17)