Revision 6bb59aad
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/library/effect/FragmentEffectAlpha.java | ||
---|---|---|
22 | 22 |
import org.distorted.library.type.Data1D; |
23 | 23 |
import org.distorted.library.type.Data4D; |
24 | 24 |
import org.distorted.library.type.Dynamic1D; |
25 |
import org.distorted.library.type.Dynamic4D; |
|
25 | 26 |
import org.distorted.library.type.Static1D; |
27 |
import org.distorted.library.type.Static4D; |
|
26 | 28 |
|
27 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
28 | 30 |
|
29 | 31 |
public class FragmentEffectAlpha extends FragmentEffect |
30 | 32 |
{ |
33 |
private static final String NAME = "ALPHA"; |
|
31 | 34 |
private static final float[] UNITIES = new float[] {1.0f}; |
32 | 35 |
private static final int DIMENSION = 1; |
33 | 36 |
private static final boolean SUPPORTS_CENTER = false; |
34 | 37 |
private static final boolean SUPPORTS_REGION = true; |
35 | 38 |
|
36 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
37 |
|
|
40 |
/** |
|
41 |
* Makes a certain sub-region of the Object smoothly change its transparency level. |
|
42 |
* |
|
43 |
* @param alpha 1-dimensional Data that returns the level of transparency we want to have at any given |
|
44 |
* moment: pixel.a *= alpha. |
|
45 |
* Valid range: <0,1> |
|
46 |
* @param region Region this Effect is limited to. |
|
47 |
* @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region. |
|
48 |
*/ |
|
38 | 49 |
public FragmentEffectAlpha(Data1D alpha, Data4D region, boolean smooth) |
39 | 50 |
{ |
40 |
super(smooth?SMOOTH_ALPHA:ALPHA ,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION); |
|
51 |
super(smooth?SMOOTH_ALPHA:ALPHA ,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
|
|
41 | 52 |
|
42 | 53 |
if( alpha instanceof Dynamic1D ) |
43 | 54 |
{ |
... | ... | |
48 | 59 |
mStatic0 = (Static1D)alpha; |
49 | 60 |
} |
50 | 61 |
|
51 |
mRegion = region; |
|
62 |
if( region instanceof Static4D) |
|
63 |
{ |
|
64 |
mStaticRegion = (Static4D)region; |
|
65 |
} |
|
66 |
else if( region instanceof Dynamic4D) |
|
67 |
{ |
|
68 |
mDynamicRegion = (Dynamic4D)region; |
|
69 |
} |
|
52 | 70 |
} |
53 | 71 |
|
54 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 |
|
|
73 |
/** |
|
74 |
* Makes the whole Object smoothly change its transparency level. |
|
75 |
* |
|
76 |
* @param alpha 1-dimensional Data that returns the level of transparency we want to have at any |
|
77 |
* given moment: pixel.a *= alpha. |
|
78 |
* Valid range: <0,1> |
|
79 |
*/ |
|
56 | 80 |
public FragmentEffectAlpha(Data1D alpha) |
57 | 81 |
{ |
58 |
super(ALPHA,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION); |
|
82 |
super(ALPHA,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
|
|
59 | 83 |
|
60 | 84 |
if( alpha instanceof Dynamic1D ) |
61 | 85 |
{ |
... | ... | |
65 | 89 |
{ |
66 | 90 |
mStatic0 = (Static1D)alpha; |
67 | 91 |
} |
92 |
|
|
93 |
mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE); |
|
68 | 94 |
} |
69 | 95 |
|
70 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
71 | 97 |
|
72 | 98 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
73 | 99 |
{ |
100 |
if( mDynamicRegion!=null ) |
|
101 |
{ |
|
102 |
mDynamicRegion.interpolateMain(uniforms,index+4,currentDuration,step); |
|
103 |
} |
|
104 |
else |
|
105 |
{ |
|
106 |
uniforms[index+4] = mStaticRegion.getX(); |
|
107 |
uniforms[index+5] = mStaticRegion.getY(); |
|
108 |
uniforms[index+6] = mStaticRegion.getZ(); |
|
109 |
uniforms[index+7] = mStaticRegion.getW(); |
|
110 |
} |
|
111 |
|
|
74 | 112 |
if( mDynamic0!=null ) |
75 | 113 |
{ |
76 | 114 |
return mDynamic0.interpolateMain(uniforms,index,currentDuration,step); |
Also available in: Unified diff
Progress with support for Effect classes.