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.Data4D;
|
24
|
import org.distorted.library.type.Dynamic1D;
|
25
|
import org.distorted.library.type.Dynamic4D;
|
26
|
import org.distorted.library.type.Static1D;
|
27
|
import org.distorted.library.type.Static4D;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public class FragmentEffectSaturation extends FragmentEffect
|
32
|
{
|
33
|
private static final String NAME = "SATURATION";
|
34
|
private static final float[] UNITIES = new float[] {1.0f};
|
35
|
private static final int DIMENSION = 1;
|
36
|
private static final boolean SUPPORTS_CENTER = false;
|
37
|
private static final boolean SUPPORTS_REGION = true;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
/**
|
41
|
* Makes a certain sub-region of the Object smoothly change its saturation level.
|
42
|
*
|
43
|
* @param saturation 1-dimensional Data that returns the level of saturation we want to have
|
44
|
* at any given moment. Valid range: <0,infinity)
|
45
|
* @param region Region this Effect is limited to.
|
46
|
* @param smooth If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
|
47
|
*/
|
48
|
public FragmentEffectSaturation(Data1D saturation, Data4D region, boolean smooth)
|
49
|
{
|
50
|
super(smooth?SMOOTH_SATURATION:SATURATION ,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
|
51
|
|
52
|
if( saturation instanceof Dynamic1D )
|
53
|
{
|
54
|
mDynamic0 = (Dynamic1D)saturation;
|
55
|
}
|
56
|
else if ( saturation instanceof Static1D )
|
57
|
{
|
58
|
mStatic0 = (Static1D)saturation;
|
59
|
}
|
60
|
|
61
|
if( region instanceof Static4D)
|
62
|
{
|
63
|
mStaticRegion = (Static4D)region;
|
64
|
}
|
65
|
else if( region instanceof Dynamic4D)
|
66
|
{
|
67
|
mDynamicRegion = (Dynamic4D)region;
|
68
|
}
|
69
|
}
|
70
|
|
71
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72
|
/**
|
73
|
* Makes the whole Object smoothly change its saturation level.
|
74
|
*
|
75
|
* @param saturation 1-dimensional Data that returns the level of saturation we want to have
|
76
|
* at any given moment. Valid range: <0,infinity)
|
77
|
*/
|
78
|
public FragmentEffectSaturation(Data1D saturation)
|
79
|
{
|
80
|
super(SATURATION,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
|
81
|
|
82
|
if( saturation instanceof Dynamic1D )
|
83
|
{
|
84
|
mDynamic0 = (Dynamic1D)saturation;
|
85
|
}
|
86
|
else if ( saturation instanceof Static1D )
|
87
|
{
|
88
|
mStatic0 = (Static1D)saturation;
|
89
|
}
|
90
|
|
91
|
mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
97
|
{
|
98
|
if( mDynamicRegion!=null )
|
99
|
{
|
100
|
mDynamicRegion.interpolateMain(uniforms,index+4,currentDuration,step);
|
101
|
}
|
102
|
else
|
103
|
{
|
104
|
uniforms[index+4] = mStaticRegion.getX();
|
105
|
uniforms[index+5] = mStaticRegion.getY();
|
106
|
uniforms[index+6] = mStaticRegion.getZ();
|
107
|
uniforms[index+7] = mStaticRegion.getW();
|
108
|
}
|
109
|
|
110
|
if( mDynamic0!=null )
|
111
|
{
|
112
|
return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
|
113
|
}
|
114
|
else
|
115
|
{
|
116
|
uniforms[index] = ((Static1D)mStatic0).getX();
|
117
|
return false;
|
118
|
}
|
119
|
}
|
120
|
}
|