1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2017 Leszek Koltunski leszek@koltunski.pl //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// This library is free software; you can redistribute it and/or //
|
7
|
// modify it under the terms of the GNU Lesser General Public //
|
8
|
// License as published by the Free Software Foundation; either //
|
9
|
// version 2.1 of the License, or (at your option) any later version. //
|
10
|
// //
|
11
|
// This library 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 GNU //
|
14
|
// Lesser General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU Lesser General Public //
|
17
|
// License along with this library; if not, write to the Free Software //
|
18
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //
|
19
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20
|
|
21
|
package org.distorted.library.effect;
|
22
|
|
23
|
import org.distorted.library.type.Data1D;
|
24
|
import org.distorted.library.type.Data3D;
|
25
|
import org.distorted.library.type.Static3D;
|
26
|
|
27
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28
|
/**
|
29
|
* Make a certain Region change its transparency level.
|
30
|
*/
|
31
|
public class FragmentEffectAlpha extends FragmentEffect
|
32
|
{
|
33
|
private final Data1D mAlpha;
|
34
|
private final Data3D mCenter;
|
35
|
private final Data3D mRegion;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
/**
|
39
|
* Only for use by the library itself.
|
40
|
*
|
41
|
* @y.exclude
|
42
|
*/
|
43
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
44
|
{
|
45
|
mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step);
|
46
|
mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step);
|
47
|
return mAlpha.get(uniforms,index, currentDuration, step);
|
48
|
}
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
// PUBLIC API
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
/**
|
54
|
* Makes a certain sub-region of the Object smoothly change its transparency level.
|
55
|
*
|
56
|
* @param alpha level of transparency we want to have at any given moment: pixel.a *= alpha.
|
57
|
* Valid range: <0,1>
|
58
|
* @param center center of the Effect (point in 3D).
|
59
|
* @param region Region this Effect is limited to (3 radii defining an ellipsoid).
|
60
|
* @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
|
61
|
*/
|
62
|
public FragmentEffectAlpha(Data1D alpha, Data3D center, Data3D region, boolean smooth)
|
63
|
{
|
64
|
super(smooth? EffectName.SMOOTH_ALPHA:EffectName.ALPHA);
|
65
|
mAlpha = alpha;
|
66
|
mCenter = center;
|
67
|
mRegion = (region==null ? MAX_REGION : region);
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
/**
|
72
|
* Makes the whole Object smoothly change its transparency level.
|
73
|
*
|
74
|
* @param alpha level of transparency we want to have at any given moment: pixel.a *= alpha.
|
75
|
* Valid range: <0,1>
|
76
|
*/
|
77
|
public FragmentEffectAlpha(Data1D alpha)
|
78
|
{
|
79
|
super(EffectName.ALPHA);
|
80
|
mAlpha = alpha;
|
81
|
mCenter = new Static3D(0,0,0);
|
82
|
mRegion = MAX_REGION;
|
83
|
}
|
84
|
|
85
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86
|
/**
|
87
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
88
|
*/
|
89
|
public static void enable()
|
90
|
{
|
91
|
addEffect( EffectName.ALPHA,EffectName.SMOOTH_ALPHA,
|
92
|
"color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);" );
|
93
|
}
|
94
|
}
|