| 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 |
6bb59aad
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
| 25 |
125cee3d
|
Leszek Koltunski
|
|
| 26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 27 |
|
|
|
| 28 |
|
|
public class FragmentEffectAlpha extends FragmentEffect
|
| 29 |
|
|
{
|
| 30 |
a1d92a36
|
leszek
|
private Data1D mAlpha;
|
| 31 |
|
|
private Data4D mRegion;
|
| 32 |
|
|
|
| 33 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 34 |
6bb59aad
|
Leszek Koltunski
|
/**
|
| 35 |
|
|
* Makes a certain sub-region of the Object smoothly change its transparency level.
|
| 36 |
|
|
*
|
| 37 |
e2e92a29
|
Leszek Koltunski
|
* @param alpha level of transparency we want to have at any given moment: pixel.a *= alpha.
|
| 38 |
6bb59aad
|
Leszek Koltunski
|
* Valid range: <0,1>
|
| 39 |
|
|
* @param region Region this Effect is limited to.
|
| 40 |
|
|
* @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
|
| 41 |
|
|
*/
|
| 42 |
125cee3d
|
Leszek Koltunski
|
public FragmentEffectAlpha(Data1D alpha, Data4D region, boolean smooth)
|
| 43 |
|
|
{
|
| 44 |
9d0d8530
|
leszek
|
super(smooth? EffectName.SMOOTH_ALPHA:EffectName.ALPHA);
|
| 45 |
a1d92a36
|
leszek
|
mAlpha = alpha;
|
| 46 |
|
|
mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
|
| 47 |
125cee3d
|
Leszek Koltunski
|
}
|
| 48 |
|
|
|
| 49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 50 |
6bb59aad
|
Leszek Koltunski
|
/**
|
| 51 |
|
|
* Makes the whole Object smoothly change its transparency level.
|
| 52 |
|
|
*
|
| 53 |
e2e92a29
|
Leszek Koltunski
|
* @param alpha level of transparency we want to have at any given moment: pixel.a *= alpha.
|
| 54 |
6bb59aad
|
Leszek Koltunski
|
* Valid range: <0,1>
|
| 55 |
|
|
*/
|
| 56 |
125cee3d
|
Leszek Koltunski
|
public FragmentEffectAlpha(Data1D alpha)
|
| 57 |
|
|
{
|
| 58 |
9d0d8530
|
leszek
|
super(EffectName.ALPHA);
|
| 59 |
a1d92a36
|
leszek
|
mAlpha = alpha;
|
| 60 |
|
|
mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
|
| 61 |
125cee3d
|
Leszek Koltunski
|
}
|
| 62 |
15aa7d94
|
Leszek Koltunski
|
|
| 63 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 64 |
|
|
|
| 65 |
|
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
| 66 |
|
|
{
|
| 67 |
a1d92a36
|
leszek
|
mRegion.get(uniforms, index+4, currentDuration, step);
|
| 68 |
|
|
return mAlpha.get(uniforms,index, currentDuration, step);
|
| 69 |
15aa7d94
|
Leszek Koltunski
|
}
|
| 70 |
7cd24173
|
leszek
|
|
| 71 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 72 |
|
|
|
| 73 |
|
|
public static void enable()
|
| 74 |
|
|
{
|
| 75 |
|
|
addEffect( EffectName.ALPHA,EffectName.SMOOTH_ALPHA,
|
| 76 |
|
|
"color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);" );
|
| 77 |
|
|
}
|
| 78 |
125cee3d
|
Leszek Koltunski
|
}
|