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