1 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
6bb59aad
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
25 |
125cee3d
|
Leszek Koltunski
|
|
26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27 |
faa3ff56
|
Leszek Koltunski
|
/**
|
28 |
|
|
* Make a certain Region change its color saturation.
|
29 |
|
|
*/
|
30 |
125cee3d
|
Leszek Koltunski
|
public class FragmentEffectSaturation extends FragmentEffect
|
31 |
|
|
{
|
32 |
a1d92a36
|
leszek
|
private Data1D mSaturation;
|
33 |
|
|
private Data4D mRegion;
|
34 |
|
|
|
35 |
faa3ff56
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
|
|
mRegion.get(uniforms,index+4,currentDuration,step);
|
44 |
|
|
return mSaturation.get(uniforms,index,currentDuration,step);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
|
|
// PUBLIC API
|
49 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
6bb59aad
|
Leszek Koltunski
|
/**
|
51 |
|
|
* Makes a certain sub-region of the Object smoothly change its saturation level.
|
52 |
|
|
*
|
53 |
e2e92a29
|
Leszek Koltunski
|
* @param saturation level of saturation we want to have at any given moment. Valid range: <0,infinity)
|
54 |
6bb59aad
|
Leszek Koltunski
|
* @param region Region this Effect is limited to.
|
55 |
|
|
* @param smooth If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
|
56 |
|
|
*/
|
57 |
125cee3d
|
Leszek Koltunski
|
public FragmentEffectSaturation(Data1D saturation, Data4D region, boolean smooth)
|
58 |
|
|
{
|
59 |
9d0d8530
|
leszek
|
super(smooth?EffectName.SMOOTH_SATURATION:EffectName.SATURATION);
|
60 |
125cee3d
|
Leszek Koltunski
|
|
61 |
a1d92a36
|
leszek
|
mSaturation = saturation;
|
62 |
|
|
mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
|
63 |
125cee3d
|
Leszek Koltunski
|
}
|
64 |
|
|
|
65 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66 |
6bb59aad
|
Leszek Koltunski
|
/**
|
67 |
|
|
* Makes the whole Object smoothly change its saturation level.
|
68 |
|
|
*
|
69 |
e2e92a29
|
Leszek Koltunski
|
* @param saturation level of saturation we want to have at any given moment. Valid range: <0,infinity)
|
70 |
6bb59aad
|
Leszek Koltunski
|
*/
|
71 |
125cee3d
|
Leszek Koltunski
|
public FragmentEffectSaturation(Data1D saturation)
|
72 |
|
|
{
|
73 |
9d0d8530
|
leszek
|
super(EffectName.SATURATION);
|
74 |
125cee3d
|
Leszek Koltunski
|
|
75 |
a1d92a36
|
leszek
|
mSaturation = saturation;
|
76 |
|
|
mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
|
77 |
125cee3d
|
Leszek Koltunski
|
}
|
78 |
15aa7d94
|
Leszek Koltunski
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
faa3ff56
|
Leszek Koltunski
|
/**
|
81 |
|
|
* Have to call this before the shaders get compiled (i.e before Distorted.onCreate()) for the Effect to work.
|
82 |
|
|
*/
|
83 |
7cd24173
|
leszek
|
public static void enable()
|
84 |
|
|
{
|
85 |
|
|
addEffect( EffectName.SATURATION,EffectName.SMOOTH_SATURATION,
|
86 |
|
|
"float luminance = dot(vec3( 0.2125, 0.7154, 0.0721 ),color.rgb);\n" +
|
87 |
|
|
"color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); " );
|
88 |
|
|
}
|
89 |
125cee3d
|
Leszek Koltunski
|
}
|