1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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.Data2D;
|
23
|
import org.distorted.library.type.Data4D;
|
24
|
|
25
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26
|
/**
|
27
|
* Add a (colored) glow around an object.
|
28
|
*/
|
29
|
public class PostprocessEffectGlow extends PostprocessEffectBlurred
|
30
|
{
|
31
|
private final Data2D mHaloAndRadius;
|
32
|
private final Data4D mColor;
|
33
|
|
34
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35
|
/**
|
36
|
* Only for use by the library itself.
|
37
|
*
|
38
|
* @y.exclude
|
39
|
*/
|
40
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
41
|
{
|
42
|
mColor.get(uniforms,index+2,currentDuration,step);
|
43
|
return mHaloAndRadius.get(uniforms,index,currentDuration,step);
|
44
|
}
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
/**
|
48
|
* Only for use by the library itself.
|
49
|
*
|
50
|
* @y.exclude
|
51
|
*/
|
52
|
public boolean getRenderDirectly()
|
53
|
{
|
54
|
return true;
|
55
|
}
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
// PUBLIC API
|
59
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60
|
/**
|
61
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
62
|
*/
|
63
|
public static void enable()
|
64
|
{
|
65
|
PostprocessEffectBlurred.enable("GLOW1","GLOW2");
|
66
|
}
|
67
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
// Clean up of static variables on exit. Called by reflection from super class.
|
70
|
|
71
|
@SuppressWarnings("unused")
|
72
|
static void destroyStatics()
|
73
|
{
|
74
|
PostprocessEffectBlurred.destroyStatics();
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
/**
|
79
|
* Make the object glow with a specific color and a halo of specific radius.
|
80
|
*
|
81
|
* @param haloAndRadius First float: the halo.
|
82
|
* How far beyond the object does the effect stretch to? Unit: Percentage
|
83
|
* of the size of the original object, i.e. Halo=0 --> no halo around, this
|
84
|
* would mean sharp edges around the object; Halo=100 --> halo of the size
|
85
|
* of the object itself around.
|
86
|
* Second float: the radius.
|
87
|
* The 'strength' of the blur of the edges, in pixels. 0 = no blur, 10 =
|
88
|
* blur of roughly 10 pixels around the whole halo.
|
89
|
* @param color RGBA of the color with which to draw the glow; example: (1.0f,0.0f,0.0f,0.5f) -
|
90
|
* half transparent red.
|
91
|
*/
|
92
|
public PostprocessEffectGlow(Data2D haloAndRadius, Data4D color)
|
93
|
{
|
94
|
super(EffectName.GLOW);
|
95
|
|
96
|
mHaloAndRadius = haloAndRadius;
|
97
|
mColor = color;
|
98
|
}
|
99
|
}
|