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.Data2D;
|
24
|
import org.distorted.library.type.Data4D;
|
25
|
|
26
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27
|
/**
|
28
|
* Add a (colored) glow around an object.
|
29
|
*/
|
30
|
public class PostprocessEffectGlow extends PostprocessEffectBlurred
|
31
|
{
|
32
|
private final Data2D mHaloAndRadius;
|
33
|
private final Data4D mColor;
|
34
|
|
35
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36
|
/**
|
37
|
* Only for use by the library itself.
|
38
|
*
|
39
|
* @y.exclude
|
40
|
*/
|
41
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
42
|
{
|
43
|
mColor.get(uniforms,index+2,currentDuration,step);
|
44
|
return mHaloAndRadius.get(uniforms,index,currentDuration,step);
|
45
|
}
|
46
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
/**
|
49
|
* Only for use by the library itself.
|
50
|
*
|
51
|
* @y.exclude
|
52
|
*/
|
53
|
public boolean getRenderDirectly()
|
54
|
{
|
55
|
return true;
|
56
|
}
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
// PUBLIC API
|
60
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61
|
/**
|
62
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
63
|
*/
|
64
|
public static void enable()
|
65
|
{
|
66
|
PostprocessEffectBlurred.enable("GLOW1","GLOW2");
|
67
|
}
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
// Clean up of static variables on exit. Called by reflection from super class.
|
71
|
|
72
|
@SuppressWarnings("unused")
|
73
|
static void destroyStatics()
|
74
|
{
|
75
|
PostprocessEffectBlurred.destroyStatics();
|
76
|
}
|
77
|
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
/**
|
80
|
* Make the object glow with a specific color and a halo of specific radius.
|
81
|
*
|
82
|
* @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
|
*/
|
93
|
public PostprocessEffectGlow(Data2D haloAndRadius, Data4D color)
|
94
|
{
|
95
|
super(EffectName.GLOW);
|
96
|
|
97
|
mHaloAndRadius = haloAndRadius;
|
98
|
mColor = color;
|
99
|
}
|
100
|
}
|