Project

General

Profile

« Previous | Next » 

Revision b24e4719

Added by Leszek Koltunski over 5 years ago

Make the Fragment effects truly 3D: change their 4D 'region' into a 3D 'center' (a point in 3D) and 3D 'region' (which is now a set of 3 radii defining an ellipsoid around the center)

Also corresponding changes to the applications.

View differences:

src/main/java/org/distorted/library/effect/Effect.java
32 32
  private final EffectType mType;
33 33
  private final EffectName mName;
34 34
  private final int mDimension;
35
  private final boolean mSupportsR;
36
  private final boolean mSupportsC;
35
  private final int mRegionDim;
36
  private final int mCenterDim;
37 37

  
38 38
  private static long mNextID = 0;
39 39

  
......
53 53
    {
54 54
    mName      = name;
55 55
    mType      = name.getType();
56
    mDimension = name.getDimension();
57
    mSupportsC = name.supportsCenter();
58
    mSupportsR = name.supportsRegion();
56
    mDimension = name.getEffectDimension();
57
    mCenterDim = name.getCenterDimension();
58
    mRegionDim = name.getRegionDimension();
59 59

  
60 60
    int n = name.ordinal();
61 61
    float[] u = name.getUnity();
......
167 167

  
168 168
///////////////////////////////////////////////////////////////////////////////////////////////////
169 169
/**
170
 * Does this effect have a Center?
170
 * Return the dimension of the Center supported by this effect (0- no center supported at all).
171 171
 */
172
  public boolean supportsCenter()
172
  public int getCenterDimension()
173 173
    {
174
    return mSupportsC;
174
    return mCenterDim;
175 175
    }
176 176

  
177 177
///////////////////////////////////////////////////////////////////////////////////////////////////
178 178
/**
179
 * Does this effect support being masked by a Region?
179
 * Return the dimension of the Region supported by this effect (0- no region supported at all).
180 180
 */
181
  public boolean supportsRegion()
181
  public int getRegionDimension()
182 182
    {
183
    return mSupportsR;
183
    return mRegionDim;
184 184
    }
185 185

  
186 186
///////////////////////////////////////////////////////////////////////////////////////////////////
187 187
/**
188 188
 * Return the number of Uniforms needed to describe this effect.
189 189
 */
190
  public int getDimension()
190
  public int getEffectDimension()
191 191
    {
192 192
    return mDimension;
193 193
    }
src/main/java/org/distorted/library/effect/EffectName.java
43 43
public enum EffectName
44 44
  {
45 45
  // EFFECT NAME /////// EFFECT TYPE ////////// EFFECT UNITY //////////// DIM REGION CENTER // CLASS
46
  ROTATE           ( EffectType.MATRIX  ,   new float[] {0.0f}           , 4, false, true  , MatrixEffectRotate.class       ),
47
  QUATERNION       ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 4, false, true  , MatrixEffectQuaternion.class   ),
48
  MOVE             ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 3, false, false , MatrixEffectMove.class         ),
49
  SCALE            ( EffectType.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} , 3, false, false , MatrixEffectScale.class        ),
50
  SHEAR            ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 3, false, true  , MatrixEffectShear.class        ),
51

  
52
  DISTORT          ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, true , true  , VertexEffectDistort.class      ),
53
  DEFORM           ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, true , true  , VertexEffectDeform.class       ),
54
  SINK             ( EffectType.VERTEX  ,   new float[] {1.0f}           , 1, true , true  , VertexEffectSink.class         ),
55
  PINCH            ( EffectType.VERTEX  ,   new float[] {1.0f}           , 2, true , true  , VertexEffectPinch.class        ),
56
  SWIRL            ( EffectType.VERTEX  ,   new float[] {0.0f}           , 1, true , true  , VertexEffectSwirl.class        ),
57
  WAVE             ( EffectType.VERTEX  ,   new float[] {0.0f}           , 5, true , true  , VertexEffectWave.class         ),
58

  
59
  ALPHA            ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, true , false , FragmentEffectAlpha.class      ),
60
  SMOOTH_ALPHA     ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, true , false , FragmentEffectAlpha.class      ),
61
  CHROMA           ( EffectType.FRAGMENT,   new float[] {0.0f}           , 4, true , false , FragmentEffectChroma.class     ),
62
  SMOOTH_CHROMA    ( EffectType.FRAGMENT,   new float[] {0.0f}           , 4, true , false , FragmentEffectChroma.class     ),
63
  BRIGHTNESS       ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, true , false , FragmentEffectBrightness.class ),
64
  SMOOTH_BRIGHTNESS( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, true , false , FragmentEffectBrightness.class ),
65
  SATURATION       ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, true , false , FragmentEffectSaturation.class ),
66
  SMOOTH_SATURATION( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, true , false , FragmentEffectSaturation.class ),
67
  CONTRAST         ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, true , false , FragmentEffectContrast.class   ),
68
  SMOOTH_CONTRAST  ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, true , false , FragmentEffectContrast.class   ),
69

  
70
  BLUR             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 1, false, false , PostprocessEffectBlur.class    ),
71
  GLOW             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 5, false, false , PostprocessEffectGlow.class    );
46
  ROTATE           ( EffectType.MATRIX  ,   new float[] {0.0f}           , 4, 0,     3    , MatrixEffectRotate.class       ),
47
  QUATERNION       ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 4, 0,     3    , MatrixEffectQuaternion.class   ),
48
  MOVE             ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     0    , MatrixEffectMove.class         ),
49
  SCALE            ( EffectType.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} , 3, 0,     0    , MatrixEffectScale.class        ),
50
  SHEAR            ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     3    , MatrixEffectShear.class        ),
51

  
52
  DISTORT          ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 4 ,    3    , VertexEffectDistort.class      ),
53
  DEFORM           ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 4 ,    3    , VertexEffectDeform.class       ),
54
  SINK             ( EffectType.VERTEX  ,   new float[] {1.0f}           , 1, 4 ,    3    , VertexEffectSink.class         ),
55
  PINCH            ( EffectType.VERTEX  ,   new float[] {1.0f}           , 2, 4 ,    3    , VertexEffectPinch.class        ),
56
  SWIRL            ( EffectType.VERTEX  ,   new float[] {0.0f}           , 1, 4 ,    3    , VertexEffectSwirl.class        ),
57
  WAVE             ( EffectType.VERTEX  ,   new float[] {0.0f}           , 5, 4 ,    3    , VertexEffectWave.class         ),
58

  
59
  ALPHA            ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3 ,    3    , FragmentEffectAlpha.class      ),
60
  SMOOTH_ALPHA     ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3 ,    3    , FragmentEffectAlpha.class      ),
61
  CHROMA           ( EffectType.FRAGMENT,   new float[] {0.0f}           , 4, 3 ,    3    , FragmentEffectChroma.class     ),
62
  SMOOTH_CHROMA    ( EffectType.FRAGMENT,   new float[] {0.0f}           , 4, 3 ,    3    , FragmentEffectChroma.class     ),
63
  BRIGHTNESS       ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3 ,    3    , FragmentEffectBrightness.class ),
64
  SMOOTH_BRIGHTNESS( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3 ,    3    , FragmentEffectBrightness.class ),
65
  SATURATION       ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3 ,    3    , FragmentEffectSaturation.class ),
66
  SMOOTH_SATURATION( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3 ,    3    , FragmentEffectSaturation.class ),
67
  CONTRAST         ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3 ,    3    , FragmentEffectContrast.class   ),
68
  SMOOTH_CONTRAST  ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3 ,    3    , FragmentEffectContrast.class   ),
69

  
70
  BLUR             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 1, 0,     0    , PostprocessEffectBlur.class    ),
71
  GLOW             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 5, 0,     0    , PostprocessEffectGlow.class    );
72 72

  
73 73
///////////////////////////////////////////////////////////////////////////////////////////////////
74 74

  
......
77 77
  private final EffectType type;
78 78
  private final float[] unity;
79 79
  private final int dimension;
80
  private final boolean supportsR;
81
  private final boolean supportsC;
80
  private final int regionDim;
81
  private final int centerDim;
82 82
  private final Class<? extends Effect> effectClass;
83 83

  
84 84
  private static final int[] dimensions;
85
  private static final boolean[] supportsRegion;
86
  private static final boolean[] supportsCenter;
85
  private static final int[] regionDimension;
86
  private static final int[] centerDimension;
87 87
  private static final EffectName[] names;  // copy the values() to a local variable so that we
88 88
                                            // don't have to keep recreating the array every time
89 89
  static
......
91 91
    int i=0;
92 92

  
93 93
    dimensions      = new int[LENGTH];
94
    supportsRegion  = new boolean[LENGTH];
95
    supportsCenter  = new boolean[LENGTH];
94
    regionDimension = new int[LENGTH];
95
    centerDimension = new int[LENGTH];
96 96
    names           = new EffectName[LENGTH];
97 97

  
98 98
    for(EffectName name: EffectName.values())
99 99
      {
100 100
      dimensions[i]      = name.dimension;
101
      supportsRegion[i]  = name.supportsR;
102
      supportsCenter[i]  = name.supportsC;
101
      regionDimension[i] = name.regionDim;
102
      centerDimension[i] = name.centerDim;
103 103
      names[i]           = name;
104 104

  
105 105
      i++;
......
115 115

  
116 116
///////////////////////////////////////////////////////////////////////////////////////////////////
117 117

  
118
  EffectName(EffectType type, float[] unity, int dimension, boolean supportsR,
119
             boolean supportsC, Class<? extends Effect> effectClass )
118
  EffectName(EffectType type, float[] unity, int dimension, int regionDim,
119
             int centerDim, Class<? extends Effect> effectClass )
120 120
    {
121 121
    this.type        = type;
122 122
    this.unity       = unity;
123 123
    this.dimension   = dimension;
124
    this.supportsR   = supportsR;
125
    this.supportsC   = supportsC;
124
    this.regionDim   = regionDim;
125
    this.centerDim   = centerDim;
126 126
    this.effectClass = effectClass;
127 127
    }
128 128

  
......
166 166
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
167 167
 * @return dimension of the Effect.
168 168
 */
169
  public int getDimension() { return dimensions[ordinal()]; }
169
  public int getEffectDimension() { return dimensions[ordinal()]; }
170 170

  
171 171
///////////////////////////////////////////////////////////////////////////////////////////////////
172 172
/**
173
 * Do we support being masked by a Region?
174
 * @return true if the Effect supports being masked with a Region.
173
 * What is the dimension of the Region supported by this effect?
174
 * @return Dimension of the Region supported (0-region not supported at all).
175 175
 */
176
  public boolean supportsRegion() { return supportsRegion[ordinal()]; }
176
  public int getRegionDimension() { return regionDimension[ordinal()]; }
177 177

  
178 178
///////////////////////////////////////////////////////////////////////////////////////////////////
179 179
/**
180
 * Does this Effect have a center?
181
 * @return true if the Effect has a center.
180
 * What is the dimension of the Center supported by this effect?
181
 * @return Dimension of the Center supported (0-center not supported at all).
182 182
 */
183
  public boolean supportsCenter() { return supportsCenter[ordinal()]; }
183
  public int getCenterDimension() { return centerDimension[ordinal()]; }
184 184
  }
185 185

  
src/main/java/org/distorted/library/effect/FragmentEffect.java
26 26
public abstract class FragmentEffect extends Effect
27 27
  {
28 28
/**
29
 * 8: 4-per effect interpolated values, 4 dimensional Region.
29
 * 12: 4-per effect interpolated values, 3 dimensional Center (+padding), 3 dimensional Region (+padding).
30 30
 */
31
  public static final int NUM_UNIFORMS = 8;
31
  public static final int NUM_UNIFORMS = 12;
32
  static final int VALUES_OFFSET = 0;
33
  static final int CENTER_OFFSET = 5;
34
  static final int REGION_OFFSET = 8;
32 35
  private static String mGLSL = "";
33 36
  private static int mNumEnabled = 0;
34 37

  
src/main/java/org/distorted/library/effect/FragmentEffectAlpha.java
20 20
package org.distorted.library.effect;
21 21

  
22 22
import org.distorted.library.type.Data1D;
23
import org.distorted.library.type.Data4D;
24
import org.distorted.library.type.Static4D;
23
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Static3D;
25 25

  
26 26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 27
/**
......
30 30
public class FragmentEffectAlpha extends FragmentEffect
31 31
  {
32 32
  private Data1D mAlpha;
33
  private Data4D mRegion;
33
  private Data3D mCenter;
34
  private Data3D mRegion;
34 35

  
35 36
///////////////////////////////////////////////////////////////////////////////////////////////////
36 37
/**
......
40 41
 */
41 42
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
42 43
    {
43
    mRegion.get(uniforms, index+4, currentDuration, step);
44
    mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step);
45
    mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step);
44 46
    return mAlpha.get(uniforms,index, currentDuration, step);
45 47
    }
46 48

  
......
52 54
 *
53 55
 * @param alpha  level of transparency we want to have at any given moment: pixel.a *= alpha.
54 56
 *               Valid range: <0,1>
55
 * @param region Region this Effect is limited to.
57
 * @param center center of the Effect (point in 3D).
58
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
56 59
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
57 60
 */
58
  public FragmentEffectAlpha(Data1D alpha, Data4D region, boolean smooth)
61
  public FragmentEffectAlpha(Data1D alpha, Data3D center, Data3D region, boolean smooth)
59 62
    {
60 63
    super(smooth? EffectName.SMOOTH_ALPHA:EffectName.ALPHA);
61
    mAlpha = alpha;
62
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
64
    mAlpha  = alpha;
65
    mCenter = center;
66
    mRegion = (region==null ? new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE) : region);
63 67
    }
64 68

  
65 69
///////////////////////////////////////////////////////////////////////////////////////////////////
......
72 76
  public FragmentEffectAlpha(Data1D alpha)
73 77
    {
74 78
    super(EffectName.ALPHA);
75
    mAlpha = alpha;
76
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
79
    mAlpha  = alpha;
80
    mCenter = new Static3D(0,0,0);
81
    mRegion = new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE);
77 82
    }
78 83

  
79 84
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/FragmentEffectBrightness.java
20 20
package org.distorted.library.effect;
21 21

  
22 22
import org.distorted.library.type.Data1D;
23
import org.distorted.library.type.Data4D;
24
import org.distorted.library.type.Static4D;
23
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Static3D;
25 25

  
26 26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 27
/**
......
30 30
public class FragmentEffectBrightness extends FragmentEffect
31 31
  {
32 32
  private Data1D mBrightness;
33
  private Data4D mRegion;
34

  
33
  private Data3D mCenter;
34
  private Data3D mRegion;
35 35

  
36 36
///////////////////////////////////////////////////////////////////////////////////////////////////
37 37
/**
......
41 41
 */
42 42
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
43 43
    {
44
    mRegion.get(uniforms,index+4,currentDuration,step);
44
    mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step);
45
    mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step);
45 46
    return mBrightness.get(uniforms,index,currentDuration,step);
46 47
    }
47 48

  
......
52 53
 * Makes a certain sub-region of the Object smoothly change its brightness level.
53 54
 *
54 55
 * @param brightness level of brightness we want to have at any given moment. Valid range: <0,infinity)
55
 * @param region     Region this Effect is limited to.
56
 * @param center center of the Effect (point in 3D).
57
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
56 58
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
57 59
 */
58
  public FragmentEffectBrightness(Data1D brightness, Data4D region, boolean smooth)
60
  public FragmentEffectBrightness(Data1D brightness, Data3D center, Data3D region, boolean smooth)
59 61
    {
60 62
    super(smooth?EffectName.SMOOTH_BRIGHTNESS:EffectName.BRIGHTNESS);
61 63
    mBrightness = brightness;
62
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
64
    mCenter = center;
65
    mRegion = (region==null ? new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE) : region);
63 66
    }
64 67

  
65 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
72 75
    {
73 76
    super(EffectName.BRIGHTNESS);
74 77
    mBrightness = brightness;
75
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
78
    mCenter = new Static3D(0,0,0);
79
    mRegion = new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE);
76 80
    }
77 81

  
78 82
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/FragmentEffectChroma.java
21 21

  
22 22
import org.distorted.library.type.Data1D;
23 23
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Data4D;
25
import org.distorted.library.type.Static4D;
24
import org.distorted.library.type.Static3D;
26 25

  
27 26
///////////////////////////////////////////////////////////////////////////////////////////////////
28 27
/**
......
32 31
  {
33 32
  private Data1D mBlend;
34 33
  private Data3D mColor;
35
  private Data4D mRegion;
34
  private Data3D mCenter;
35
  private Data3D mRegion;
36 36

  
37 37
///////////////////////////////////////////////////////////////////////////////////////////////////
38 38
/**
......
42 42
 */
43 43
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
44 44
    {
45
    mRegion.get(uniforms,index+4,currentDuration,step);
46 45
    mColor.get(uniforms,index+1,currentDuration,step);
46
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
47
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
47 48
    return mBlend.get(uniforms,index,currentDuration,step);
48 49
    }
49 50

  
......
57 58
 *               pixel = (1-level)*pixel + level*color.
58 59
 *               Valid range: <0,1>
59 60
 * @param color  Color to mix. (1,0,0) is RED.
60
 * @param region Region this Effect is limited to.
61
 * @param center center of the Effect (point in 3D).
62
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
61 63
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
62 64
 */
63
  public FragmentEffectChroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
65
  public FragmentEffectChroma(Data1D blend, Data3D color, Data3D center, Data3D region, boolean smooth)
64 66
    {
65 67
    super(smooth?EffectName.SMOOTH_CHROMA:EffectName.CHROMA);
66
    mBlend = blend;
67
    mColor = color;
68
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
68
    mBlend  = blend;
69
    mColor  = color;
70
    mCenter = center;
71
    mRegion = (region==null ? new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE) : region);
69 72
    }
70 73

  
71 74
///////////////////////////////////////////////////////////////////////////////////////////////////
......
82 85
    super(EffectName.CHROMA);
83 86
    mBlend = blend;
84 87
    mColor = color;
85
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
88
    mCenter = new Static3D(0,0,0);
89
    mRegion = new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE);
86 90
    }
87 91

  
88 92
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/FragmentEffectContrast.java
20 20
package org.distorted.library.effect;
21 21

  
22 22
import org.distorted.library.type.Data1D;
23
import org.distorted.library.type.Data4D;
24
import org.distorted.library.type.Static4D;
23
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Static3D;
25 25

  
26 26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 27
/**
......
30 30
public class FragmentEffectContrast extends FragmentEffect
31 31
  {
32 32
  private Data1D mContrast;
33
  private Data4D mRegion;
33
  private Data3D mCenter;
34
  private Data3D mRegion;
34 35

  
35 36
///////////////////////////////////////////////////////////////////////////////////////////////////
36 37
/**
......
40 41
 */
41 42
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
42 43
    {
43
    mRegion.get(uniforms,index+4,currentDuration,step);
44
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
45
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
44 46
    return mContrast.get(uniforms,index,currentDuration,step);
45 47
    }
46 48

  
......
51 53
 * Makes a certain sub-region of the Object smoothly change its contrast level.
52 54
 *
53 55
 * @param contrast level of contrast we want to have at any given moment. Valid range: <0,infinity)
54
 * @param region   Region this Effect is limited to.
56
 * @param center center of the Effect (point in 3D).
57
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
55 58
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
56 59
 */
57
  public FragmentEffectContrast(Data1D contrast, Data4D region, boolean smooth)
60
  public FragmentEffectContrast(Data1D contrast, Data3D center, Data3D region, boolean smooth)
58 61
    {
59 62
    super(smooth?EffectName.SMOOTH_CONTRAST:EffectName.CONTRAST);
60 63
    mContrast = contrast;
61
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
64
    mCenter = center;
65
    mRegion = (region==null ? new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE) : region);
62 66
    }
63 67

  
64 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
71 75
    {
72 76
    super(EffectName.CONTRAST);
73 77
    mContrast = contrast;
74
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
78
    mCenter = new Static3D(0,0,0);
79
    mRegion = new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE);
75 80
    }
76 81

  
77 82
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/FragmentEffectSaturation.java
20 20
package org.distorted.library.effect;
21 21

  
22 22
import org.distorted.library.type.Data1D;
23
import org.distorted.library.type.Data4D;
24
import org.distorted.library.type.Static4D;
23
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Static3D;
25 25

  
26 26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 27
/**
......
30 30
public class FragmentEffectSaturation extends FragmentEffect
31 31
  {
32 32
  private Data1D mSaturation;
33
  private Data4D mRegion;
33
  private Data3D mCenter;
34
  private Data3D mRegion;
34 35

  
35 36
///////////////////////////////////////////////////////////////////////////////////////////////////
36 37
/**
......
40 41
 */
41 42
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
42 43
    {
43
    mRegion.get(uniforms,index+4,currentDuration,step);
44
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
45
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
44 46
    return mSaturation.get(uniforms,index,currentDuration,step);
45 47
    }
46 48

  
......
51 53
 * Makes a certain sub-region of the Object smoothly change its saturation level.
52 54
 *
53 55
 * @param saturation level of saturation we want to have at any given moment. Valid range: <0,infinity)
54
 * @param region     Region this Effect is limited to.
56
 * @param center center of the Effect (point in 3D).
57
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
55 58
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
56 59
 */
57
  public FragmentEffectSaturation(Data1D saturation, Data4D region, boolean smooth)
60
  public FragmentEffectSaturation(Data1D saturation, Data3D center, Data3D region, boolean smooth)
58 61
    {
59 62
    super(smooth?EffectName.SMOOTH_SATURATION:EffectName.SATURATION);
60 63

  
61 64
    mSaturation = saturation;
62
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
65
    mCenter = center;
66
    mRegion = (region==null ? new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE) : region);
63 67
    }
64 68

  
65 69
///////////////////////////////////////////////////////////////////////////////////////////////////
......
73 77
    super(EffectName.SATURATION);
74 78

  
75 79
    mSaturation = saturation;
76
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
80
    mCenter = new Static3D(0,0,0);
81
    mRegion = new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE);
77 82
    }
78 83

  
79 84
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/VertexEffect.java
29 29
 * 12: 5 per-effect interpolated values, 3-dimensional center, 4-dimensional Region
30 30
 */
31 31
  public static final int NUM_UNIFORMS = 12;
32
  static final int VALUES_OFFSET = 0;
33
  static final int CENTER_OFFSET = 5;
34
  static final int REGION_OFFSET = 8;
32 35
  private static String mGLSL = "";
33 36
  private static int mNumEnabled = 0;
34 37

  
src/main/java/org/distorted/library/effect/VertexEffectDeform.java
40 40
 */
41 41
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
42 42
    {
43
    mCenter.get(uniforms,index+5,currentDuration,step);
44
    mRegion.get(uniforms,index+8,currentDuration,step);
43
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
44
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
45 45
    boolean ret = mVector.get(uniforms,index,currentDuration,step);
46 46

  
47
    uniforms[index+9] =-uniforms[index+9];
47
    uniforms[index+REGION_OFFSET+1] =-uniforms[index+REGION_OFFSET+1];  // region's y
48 48

  
49 49
    return ret;
50 50
    }
src/main/java/org/distorted/library/effect/VertexEffectDistort.java
40 40
 */
41 41
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
42 42
    {
43
    mCenter.get(uniforms,index+5,currentDuration,step);
44
    mRegion.get(uniforms,index+8,currentDuration,step);
43
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
44
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
45 45
    boolean ret = mVector.get(uniforms,index,currentDuration,step);
46 46

  
47 47
    uniforms[index+1] =-uniforms[index+1];
48
    uniforms[index+9] =-uniforms[index+9];
48
    uniforms[index+REGION_OFFSET+1] =-uniforms[index+REGION_OFFSET+1];  // region's y
49 49

  
50 50
    return ret;
51 51
    }
src/main/java/org/distorted/library/effect/VertexEffectPinch.java
43 43
 */
44 44
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
45 45
    {
46
    mCenter.get(uniforms,index+5,currentDuration,step);
47
    mRegion.get(uniforms,index+8,currentDuration,step);
46
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
47
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
48 48
    boolean ret = mPinch.get(uniforms,index,currentDuration,step);
49 49

  
50 50
    uniforms[index+1] = (float)(Math.PI*uniforms[index+1]/180);
51
    uniforms[index+9] =-uniforms[index+9];
51
    uniforms[index+REGION_OFFSET+1] =-uniforms[index+REGION_OFFSET+1];  // region's y
52 52

  
53 53
    return ret;
54 54
    }
src/main/java/org/distorted/library/effect/VertexEffectSink.java
43 43
 */
44 44
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
45 45
    {
46
    mCenter.get(uniforms,index+5,currentDuration,step);
47
    mRegion.get(uniforms,index+8,currentDuration,step);
46
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
47
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
48 48
    boolean ret = mSink.get(uniforms,index,currentDuration,step);
49 49

  
50
    uniforms[index+9] =-uniforms[index+9];
50
    uniforms[index+REGION_OFFSET+1] =-uniforms[index+REGION_OFFSET+1];  // region's y
51 51

  
52 52
    return ret;
53 53
    }
src/main/java/org/distorted/library/effect/VertexEffectSwirl.java
42 42
 */
43 43
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
44 44
    {
45
    mCenter.get(uniforms,index+5,currentDuration,step);
46
    mRegion.get(uniforms,index+8,currentDuration,step);
45
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
46
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
47 47
    boolean ret = mSwirl.get(uniforms,index,currentDuration,step);
48 48

  
49 49
    uniforms[index  ] = (float)(Math.PI*uniforms[index]/180);
50
    uniforms[index+9] =-uniforms[index+9];
50
    uniforms[index+REGION_OFFSET+1] =-uniforms[index+REGION_OFFSET+1];  // region's y
51 51

  
52 52
    return ret;
53 53
    }
src/main/java/org/distorted/library/effect/VertexEffectWave.java
42 42
 */
43 43
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
44 44
    {
45
    mCenter.get(uniforms,index+5,currentDuration,step);
46
    mRegion.get(uniforms,index+8,currentDuration,step);
45
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
46
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
47 47
    boolean ret = mWave.get(uniforms,index,currentDuration,step);
48 48

  
49 49
    uniforms[index+2] = (float)(Math.PI*uniforms[index+2]/180);
50 50
    uniforms[index+3] = (float)(Math.PI*uniforms[index+3]/180);
51 51
    uniforms[index+4] = (float)(Math.PI*uniforms[index+4]/180);
52
    uniforms[index+9] =-uniforms[index+9];
52

  
53
    uniforms[index+REGION_OFFSET+1] =-uniforms[index+REGION_OFFSET+1];  // region's y
53 54

  
54 55
    return ret;
55 56
    }
src/main/java/org/distorted/library/main/DistortedEffects.java
467 467

  
468 468
    mM.compute(currTime);
469 469
    mV.compute(currTime,halfW,halfH,halfZ);
470
    mF.compute(currTime,halfW,halfH);
470
    mF.compute(currTime,halfW,halfH,halfZ);
471 471
    mP.compute(currTime);
472 472

  
473 473
    GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
......
505 505

  
506 506
    mM.compute(currTime);
507 507
    mV.compute(currTime,halfW,halfH,halfZ);
508
    mF.compute(currTime,halfW,halfH);
508
    mF.compute(currTime,halfW,halfH,halfZ);
509 509
    mP.compute(currTime);
510 510

  
511 511
    GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
src/main/java/org/distorted/library/main/EffectQueueFragment.java
55 55

  
56 56
///////////////////////////////////////////////////////////////////////////////////////////////////
57 57
  
58
  void compute(long currTime,float halfX, float halfY)
58
  void compute(long currTime,float halfX, float halfY, float halfZ)
59 59
    { 
60 60
    if( currTime==mTime ) return;
61 61
    if( mTime==0 ) mTime = currTime;
......
78 78
          }
79 79
        }
80 80

  
81
      mUniforms[NUM_UNIFORMS*i+4] = mUniforms[NUM_UNIFORMS*i+4]-halfX;
82
      mUniforms[NUM_UNIFORMS*i+5] =-mUniforms[NUM_UNIFORMS*i+5]+halfY;
81
      mUniforms[NUM_UNIFORMS*i+5] = mUniforms[NUM_UNIFORMS*i+5]-halfX;
82
      mUniforms[NUM_UNIFORMS*i+6] =-mUniforms[NUM_UNIFORMS*i+6]+halfY;
83
      mUniforms[NUM_UNIFORMS*i+7] =-mUniforms[NUM_UNIFORMS*i+7]+halfZ;
83 84
      }
84 85

  
85 86
    mTime = currTime;  
src/main/res/raw/main_fragment_shader.glsl
47 47
#if NUM_FRAGMENT>0
48 48
uniform int fNumEffects;                // total number of fragment effects
49 49
uniform int fName[NUM_FRAGMENT];        // their namess.
50
uniform vec4 fUniforms[2*NUM_FRAGMENT]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1]. First vec4 is the Interpolated values,
51
                                        // next describes the Region, i.e. area over which the effect is active.
50
uniform vec4 fUniforms[3*NUM_FRAGMENT]; // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
51
                                        // The first vec4 is the Interpolated values,
52
                                        // second vec4: first float - cache, next 3: Center, the third - the Region.
52 53
#endif    // NUM_FRAGMENT>0
53 54

  
54 55
#ifdef OIT
......
110 111
  vec4 color = texture(u_Texture,v_TexCoordinate);
111 112

  
112 113
#if NUM_FRAGMENT>0
113
  vec2 diff;
114
  vec3 diff;
114 115
  float degree;
115 116
  int effect=0;
116 117

  
117 118
  for(int i=0; i<fNumEffects; i++)
118 119
    {
119
    diff   = (v_Position.xy - fUniforms[effect+1].xy)/fUniforms[effect+1].zw;
120
    diff   = (v_Position - fUniforms[effect+1].yzw)/fUniforms[effect+2].xyz;
120 121
    degree = max(0.0,1.0-dot(diff,diff));
121 122

  
122 123
    // ENABLED EFFECTS WILL BE INSERTED HERE
123 124

  
124
    effect+=2;
125
    effect+=3;
125 126
    }
126 127
#endif
127 128

  

Also available in: Unified diff