1 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
cc62b34a
|
Leszek Koltunski
|
// Copyright 2017 Leszek Koltunski leszek@koltunski.pl //
|
3 |
125cee3d
|
Leszek Koltunski
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
125cee3d
|
Leszek Koltunski
|
// //
|
6 |
cc62b34a
|
Leszek Koltunski
|
// 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 |
125cee3d
|
Leszek Koltunski
|
// //
|
11 |
cc62b34a
|
Leszek Koltunski
|
// This library is distributed in the hope that it will be useful, //
|
12 |
125cee3d
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
cc62b34a
|
Leszek Koltunski
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
|
14 |
|
|
// Lesser General Public License for more details. //
|
15 |
125cee3d
|
Leszek Koltunski
|
// //
|
16 |
cc62b34a
|
Leszek Koltunski
|
// 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 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20 |
|
|
|
21 |
|
|
package org.distorted.library.effect;
|
22 |
|
|
|
23 |
bb4755e2
|
Leszek Koltunski
|
import org.distorted.library.type.Data2D;
|
24 |
125cee3d
|
Leszek Koltunski
|
import org.distorted.library.type.Data4D;
|
25 |
|
|
|
26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27 |
6b816678
|
Leszek Koltunski
|
/**
|
28 |
ca4521e3
|
Leszek Koltunski
|
* Add a (colored) glow around an object.
|
29 |
6b816678
|
Leszek Koltunski
|
*/
|
30 |
d58407a8
|
Leszek Koltunski
|
public class PostprocessEffectGlow extends PostprocessEffectBlurred
|
31 |
125cee3d
|
Leszek Koltunski
|
{
|
32 |
d58407a8
|
Leszek Koltunski
|
private final Data2D mHaloAndRadius;
|
33 |
7958d843
|
Leszek Koltunski
|
private final Data4D mColor;
|
34 |
0dd98279
|
Leszek Koltunski
|
|
35 |
15aa7d94
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
faa3ff56
|
Leszek Koltunski
|
/**
|
37 |
|
|
* Only for use by the library itself.
|
38 |
|
|
*
|
39 |
|
|
* @y.exclude
|
40 |
|
|
*/
|
41 |
15aa7d94
|
Leszek Koltunski
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
42 |
|
|
{
|
43 |
bb4755e2
|
Leszek Koltunski
|
mColor.get(uniforms,index+2,currentDuration,step);
|
44 |
d58407a8
|
Leszek Koltunski
|
return mHaloAndRadius.get(uniforms,index,currentDuration,step);
|
45 |
15aa7d94
|
Leszek Koltunski
|
}
|
46 |
1dfc9074
|
leszek
|
|
47 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
143095f7
|
Leszek Koltunski
|
/**
|
49 |
|
|
* Only for use by the library itself.
|
50 |
|
|
*
|
51 |
|
|
* @y.exclude
|
52 |
|
|
*/
|
53 |
d58407a8
|
Leszek Koltunski
|
public boolean getRenderDirectly()
|
54 |
9e771d06
|
Leszek Koltunski
|
{
|
55 |
|
|
return true;
|
56 |
|
|
}
|
57 |
86d322b5
|
Leszek Koltunski
|
|
58 |
1149be8f
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
faa3ff56
|
Leszek Koltunski
|
// PUBLIC API
|
60 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61 |
|
|
/**
|
62 |
7602a827
|
Leszek Koltunski
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
63 |
faa3ff56
|
Leszek Koltunski
|
*/
|
64 |
1149be8f
|
leszek
|
public static void enable()
|
65 |
|
|
{
|
66 |
d58407a8
|
Leszek Koltunski
|
PostprocessEffectBlurred.enable("GLOW1","GLOW2");
|
67 |
|
|
}
|
68 |
9e771d06
|
Leszek Koltunski
|
|
69 |
d58407a8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
// Clean up of static variables on exit. Called by reflection from super class.
|
71 |
1149be8f
|
leszek
|
|
72 |
d58407a8
|
Leszek Koltunski
|
@SuppressWarnings("unused")
|
73 |
|
|
static void destroyStatics()
|
74 |
|
|
{
|
75 |
|
|
PostprocessEffectBlurred.destroyStatics();
|
76 |
1149be8f
|
leszek
|
}
|
77 |
|
|
|
78 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
faa3ff56
|
Leszek Koltunski
|
/**
|
80 |
|
|
* Make the object glow with a specific color and a halo of specific radius.
|
81 |
|
|
*
|
82 |
d58407a8
|
Leszek Koltunski
|
* @param haloAndRadius First float: the halo.
|
83 |
|
|
* How far beyond the object does the effect stretch to? Unit: Percentage
|
84 |
|
|
* of the size of the original object, i.e. Halo=0 --> no halo around, this
|
85 |
|
|
* would mean sharp edges around the object; Halo=100 --> halo of the size
|
86 |
|
|
* of the object itself around.
|
87 |
|
|
* Second float: the radius.
|
88 |
|
|
* The 'strength' of the blur of the edges, in pixels. 0 = no blur, 10 =
|
89 |
|
|
* blur of roughly 10 pixels around the whole halo.
|
90 |
|
|
* @param color RGBA of the color with which to draw the glow; example: (1.0f,0.0f,0.0f,0.5f) -
|
91 |
|
|
* half transparent red.
|
92 |
faa3ff56
|
Leszek Koltunski
|
*/
|
93 |
d58407a8
|
Leszek Koltunski
|
public PostprocessEffectGlow(Data2D haloAndRadius, Data4D color)
|
94 |
1149be8f
|
leszek
|
{
|
95 |
faa3ff56
|
Leszek Koltunski
|
super(EffectName.GLOW);
|
96 |
bb4755e2
|
Leszek Koltunski
|
|
97 |
d58407a8
|
Leszek Koltunski
|
mHaloAndRadius = haloAndRadius;
|
98 |
|
|
mColor = color;
|
99 |
1dfc9074
|
leszek
|
}
|
100 |
125cee3d
|
Leszek Koltunski
|
}
|