Project

General

Profile

Download (4.72 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / effect / FragmentEffectSaturation.java @ c0255951

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 saturation.
30
 */
31
public class FragmentEffectSaturation extends FragmentEffect
32
  {
33
  private final Data1D mSaturation;
34
  private final Data3D mCenter;
35
  private final Data3D mRegion;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
/**
39
 * Only for use by the library itself.
40
 *
41
 * @y.exclude
42
 */
43
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
44
    {
45
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
46
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
47
    return mSaturation.get(uniforms,index,currentDuration,step);
48
    }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
// PUBLIC API
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
/**
54
 * Makes a certain sub-region of the Object smoothly change its saturation level.
55
 *
56
 * @param saturation level of saturation we want to have at any given moment. Valid range: <0,infinity)
57
 * @param center center of the Effect (point in 3D).
58
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
59
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
60
 */
61
  public FragmentEffectSaturation(Data1D saturation, Data3D center, Data3D region, boolean smooth)
62
    {
63
    super(smooth?EffectName.SMOOTH_SATURATION:EffectName.SATURATION);
64

    
65
    mSaturation = saturation;
66
    mCenter = center;
67
    mRegion = (region==null ? MAX_REGION : region);
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
/**
72
 * Makes the whole Object smoothly change its saturation level.
73
 *
74
 * @param saturation level of saturation we want to have at any given moment. Valid range: <0,infinity)
75
 */
76
  public FragmentEffectSaturation(Data1D saturation)
77
    {
78
    super(EffectName.SATURATION);
79

    
80
    mSaturation = saturation;
81
    mCenter = new Static3D(0,0,0);
82
    mRegion = MAX_REGION;
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
/**
87
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
88
 */
89
  public static void enable()
90
    {
91
    addEffect( EffectName.SATURATION,EffectName.SMOOTH_SATURATION,
92
               "float luminance = dot(vec3( 0.2125, 0.7154, 0.0721 ),color.rgb);\n" +
93
               "color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); " );
94
    }
95
  }
(10-10/34)