1 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2017 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.effect;
|
21 |
|
|
|
22 |
|
|
import org.distorted.library.type.Data1D;
|
23 |
|
|
import org.distorted.library.type.Data4D;
|
24 |
|
|
import org.distorted.library.type.Dynamic1D;
|
25 |
6bb59aad
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic4D;
|
26 |
125cee3d
|
Leszek Koltunski
|
import org.distorted.library.type.Static1D;
|
27 |
6bb59aad
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
28 |
125cee3d
|
Leszek Koltunski
|
|
29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
|
31 |
|
|
public class FragmentEffectAlpha extends FragmentEffect
|
32 |
|
|
{
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
6bb59aad
|
Leszek Koltunski
|
/**
|
35 |
|
|
* Makes a certain sub-region of the Object smoothly change its transparency level.
|
36 |
|
|
*
|
37 |
|
|
* @param alpha 1-dimensional Data that returns the level of transparency we want to have at any given
|
38 |
|
|
* moment: pixel.a *= alpha.
|
39 |
|
|
* Valid range: <0,1>
|
40 |
|
|
* @param region Region this Effect is limited to.
|
41 |
|
|
* @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
|
42 |
|
|
*/
|
43 |
125cee3d
|
Leszek Koltunski
|
public FragmentEffectAlpha(Data1D alpha, Data4D region, boolean smooth)
|
44 |
|
|
{
|
45 |
9d0d8530
|
leszek
|
super(smooth? EffectName.SMOOTH_ALPHA:EffectName.ALPHA);
|
46 |
125cee3d
|
Leszek Koltunski
|
|
47 |
|
|
if( alpha instanceof Dynamic1D )
|
48 |
|
|
{
|
49 |
|
|
mDynamic0 = (Dynamic1D)alpha;
|
50 |
|
|
}
|
51 |
|
|
else if ( alpha instanceof Static1D )
|
52 |
|
|
{
|
53 |
|
|
mStatic0 = (Static1D)alpha;
|
54 |
|
|
}
|
55 |
|
|
|
56 |
7625e47e
|
leszek
|
if( region == null )
|
57 |
6bb59aad
|
Leszek Koltunski
|
{
|
58 |
7625e47e
|
leszek
|
mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
|
59 |
6bb59aad
|
Leszek Koltunski
|
}
|
60 |
7625e47e
|
leszek
|
else
|
61 |
6bb59aad
|
Leszek Koltunski
|
{
|
62 |
7625e47e
|
leszek
|
if (region instanceof Static4D)
|
63 |
|
|
{
|
64 |
|
|
mStaticRegion = (Static4D) region;
|
65 |
|
|
}
|
66 |
|
|
else if (region instanceof Dynamic4D)
|
67 |
|
|
{
|
68 |
|
|
mDynamicRegion = (Dynamic4D) region;
|
69 |
|
|
}
|
70 |
6bb59aad
|
Leszek Koltunski
|
}
|
71 |
125cee3d
|
Leszek Koltunski
|
}
|
72 |
|
|
|
73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
6bb59aad
|
Leszek Koltunski
|
/**
|
75 |
|
|
* Makes the whole Object smoothly change its transparency level.
|
76 |
|
|
*
|
77 |
|
|
* @param alpha 1-dimensional Data that returns the level of transparency we want to have at any
|
78 |
|
|
* given moment: pixel.a *= alpha.
|
79 |
|
|
* Valid range: <0,1>
|
80 |
|
|
*/
|
81 |
125cee3d
|
Leszek Koltunski
|
public FragmentEffectAlpha(Data1D alpha)
|
82 |
|
|
{
|
83 |
9d0d8530
|
leszek
|
super(EffectName.ALPHA);
|
84 |
125cee3d
|
Leszek Koltunski
|
|
85 |
|
|
if( alpha instanceof Dynamic1D )
|
86 |
|
|
{
|
87 |
|
|
mDynamic0 = (Dynamic1D)alpha;
|
88 |
|
|
}
|
89 |
|
|
else if ( alpha instanceof Static1D )
|
90 |
|
|
{
|
91 |
|
|
mStatic0 = (Static1D)alpha;
|
92 |
|
|
}
|
93 |
6bb59aad
|
Leszek Koltunski
|
|
94 |
|
|
mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
|
95 |
125cee3d
|
Leszek Koltunski
|
}
|
96 |
15aa7d94
|
Leszek Koltunski
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
100 |
|
|
{
|
101 |
6bb59aad
|
Leszek Koltunski
|
if( mDynamicRegion!=null )
|
102 |
|
|
{
|
103 |
|
|
mDynamicRegion.interpolateMain(uniforms,index+4,currentDuration,step);
|
104 |
|
|
}
|
105 |
|
|
else
|
106 |
|
|
{
|
107 |
|
|
uniforms[index+4] = mStaticRegion.getX();
|
108 |
|
|
uniforms[index+5] = mStaticRegion.getY();
|
109 |
|
|
uniforms[index+6] = mStaticRegion.getZ();
|
110 |
|
|
uniforms[index+7] = mStaticRegion.getW();
|
111 |
|
|
}
|
112 |
|
|
|
113 |
15aa7d94
|
Leszek Koltunski
|
if( mDynamic0!=null )
|
114 |
|
|
{
|
115 |
|
|
return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
|
116 |
|
|
}
|
117 |
|
|
else
|
118 |
|
|
{
|
119 |
|
|
uniforms[index] = ((Static1D)mStatic0).getX();
|
120 |
|
|
return false;
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
125cee3d
|
Leszek Koltunski
|
}
|