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
|
|
25 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26 |
faa3ff56
|
Leszek Koltunski
|
/**
|
27 |
|
|
* Blur the Framebuffer.
|
28 |
|
|
*/
|
29 |
d58407a8
|
Leszek Koltunski
|
public class PostprocessEffectBlur extends PostprocessEffectBlurred
|
30 |
125cee3d
|
Leszek Koltunski
|
{
|
31 |
d58407a8
|
Leszek Koltunski
|
private final Data2D mHaloAndRadius;
|
32 |
15aa7d94
|
Leszek Koltunski
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
faa3ff56
|
Leszek Koltunski
|
/**
|
35 |
|
|
* Only for use by the library itself.
|
36 |
|
|
*
|
37 |
|
|
* @y.exclude
|
38 |
|
|
*/
|
39 |
15aa7d94
|
Leszek Koltunski
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
40 |
|
|
{
|
41 |
d58407a8
|
Leszek Koltunski
|
return mHaloAndRadius.get(uniforms,index,currentDuration,step);
|
42 |
15aa7d94
|
Leszek Koltunski
|
}
|
43 |
1dfc9074
|
leszek
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
143095f7
|
Leszek Koltunski
|
/**
|
46 |
|
|
* Only for use by the library itself.
|
47 |
|
|
*
|
48 |
|
|
* @y.exclude
|
49 |
|
|
*/
|
50 |
d58407a8
|
Leszek Koltunski
|
public boolean getRenderDirectly()
|
51 |
9e771d06
|
Leszek Koltunski
|
{
|
52 |
|
|
return false;
|
53 |
|
|
}
|
54 |
86d322b5
|
Leszek Koltunski
|
|
55 |
1dfc9074
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
faa3ff56
|
Leszek Koltunski
|
// PUBLIC API
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
/**
|
59 |
7602a827
|
Leszek Koltunski
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
60 |
faa3ff56
|
Leszek Koltunski
|
*/
|
61 |
041b6dee
|
Leszek Koltunski
|
public static void enable()
|
62 |
|
|
{
|
63 |
d58407a8
|
Leszek Koltunski
|
PostprocessEffectBlurred.enable("BLUR1","BLUR2");
|
64 |
|
|
}
|
65 |
041b6dee
|
Leszek Koltunski
|
|
66 |
d58407a8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
// Clean up of static variables on exit. Called by reflection from super class.
|
68 |
1dfc9074
|
leszek
|
|
69 |
d58407a8
|
Leszek Koltunski
|
@SuppressWarnings("unused")
|
70 |
|
|
static void destroyStatics()
|
71 |
|
|
{
|
72 |
|
|
PostprocessEffectBlurred.destroyStatics();
|
73 |
1dfc9074
|
leszek
|
}
|
74 |
|
|
|
75 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
faa3ff56
|
Leszek Koltunski
|
/**
|
77 |
|
|
* Blur the Framebuffer.
|
78 |
|
|
*
|
79 |
d58407a8
|
Leszek Koltunski
|
* @param haloAndRadius First float: the halo.
|
80 |
|
|
* How far beyond the object does the effect stretch to? Unit: Percentage
|
81 |
|
|
* of the size of the original object, i.e. Halo=0 --> no halo around, this
|
82 |
|
|
* would mean sharp edges around the object; Halo=100 --> halo of the size
|
83 |
|
|
* of the object itself around (in case of blur, this would be - in vast
|
84 |
|
|
* majority of cases except an object rendered very closely to the near plane-
|
85 |
|
|
* an overkill).
|
86 |
|
|
* Second float: the radius.
|
87 |
|
|
* The 'strength' if the blur of the edges, in pixels. 0 = no blur, 10 =
|
88 |
|
|
* blur of roughly 10 pixels around the whole halo.
|
89 |
bb4755e2
|
Leszek Koltunski
|
|
90 |
faa3ff56
|
Leszek Koltunski
|
*/
|
91 |
d58407a8
|
Leszek Koltunski
|
public PostprocessEffectBlur(Data2D haloAndRadius)
|
92 |
1dfc9074
|
leszek
|
{
|
93 |
faa3ff56
|
Leszek Koltunski
|
super(EffectName.BLUR);
|
94 |
d58407a8
|
Leszek Koltunski
|
mHaloAndRadius = haloAndRadius;
|
95 |
1dfc9074
|
leszek
|
}
|
96 |
125cee3d
|
Leszek Koltunski
|
}
|