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.Data1D;
|
23
|
import org.distorted.library.type.Data3D;
|
24
|
import org.distorted.library.type.Static3D;
|
25
|
|
26
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27
|
/**
|
28
|
* Make a certain Region change its brightness level.
|
29
|
*/
|
30
|
public class FragmentEffectBrightness extends FragmentEffect
|
31
|
{
|
32
|
private Data1D mBrightness;
|
33
|
private Data3D mCenter;
|
34
|
private Data3D mRegion;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
/**
|
38
|
* Only for use by the library itself.
|
39
|
*
|
40
|
* @y.exclude
|
41
|
*/
|
42
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
43
|
{
|
44
|
mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step);
|
45
|
mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step);
|
46
|
return mBrightness.get(uniforms,index,currentDuration,step);
|
47
|
}
|
48
|
|
49
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50
|
// PUBLIC API
|
51
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52
|
/**
|
53
|
* Makes a certain sub-region of the Object smoothly change its brightness level.
|
54
|
*
|
55
|
* @param brightness level of brightness we want to have at any given moment. Valid range: <0,infinity)
|
56
|
* @param center center of the Effect (point in 3D).
|
57
|
* @param region Region this Effect is limited to (3 radii defining an ellipsoid).
|
58
|
* @param smooth If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
|
59
|
*/
|
60
|
public FragmentEffectBrightness(Data1D brightness, Data3D center, Data3D region, boolean smooth)
|
61
|
{
|
62
|
super(smooth?EffectName.SMOOTH_BRIGHTNESS:EffectName.BRIGHTNESS);
|
63
|
mBrightness = brightness;
|
64
|
mCenter = center;
|
65
|
mRegion = (region==null ? MAX_REGION : region);
|
66
|
}
|
67
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
/**
|
70
|
* Makes the whole Object smoothly change its brightness level.
|
71
|
*
|
72
|
* @param brightness level of brightness we want to have at any given moment. Valid range: <0,infinity)
|
73
|
*/
|
74
|
public FragmentEffectBrightness(Data1D brightness)
|
75
|
{
|
76
|
super(EffectName.BRIGHTNESS);
|
77
|
mBrightness = brightness;
|
78
|
mCenter = new Static3D(0,0,0);
|
79
|
mRegion = MAX_REGION;
|
80
|
}
|
81
|
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
/**
|
84
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
85
|
*/
|
86
|
public static void enable()
|
87
|
{
|
88
|
addEffect( EffectName.BRIGHTNESS,EffectName.SMOOTH_BRIGHTNESS,
|
89
|
"color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );" );
|
90
|
}
|
91
|
}
|