Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectContrast.java @ 6770ef46

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.Static4D;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
/**
28
 * Make a certain Region change its contrast level.
29
 */
30
public class FragmentEffectContrast extends FragmentEffect
31
  {
32
  private Data1D mContrast;
33
  private Data4D mRegion;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
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 mContrast.get(uniforms,index,currentDuration,step);
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
// PUBLIC API
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
/**
51
 * Makes a certain sub-region of the Object smoothly change its contrast level.
52
 *
53
 * @param contrast level of contrast we want to have at any given moment. Valid range: <0,infinity)
54
 * @param region   Region this Effect is limited to.
55
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
56
 */
57
  public FragmentEffectContrast(Data1D contrast, Data4D region, boolean smooth)
58
    {
59
    super(smooth?EffectName.SMOOTH_CONTRAST:EffectName.CONTRAST);
60
    mContrast = contrast;
61
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
/**
66
 * Makes the whole Object smoothly change its contrast level.
67
 *
68
 * @param contrast level of contrast we want to have at any given moment. Valid range: <0,infinity)
69
 */
70
  public FragmentEffectContrast(Data1D contrast)
71
    {
72
    super(EffectName.CONTRAST);
73
    mContrast = contrast;
74
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
/**
79
 * Have to call this before the shaders get compiled (i.e before Distorted.onCreate()) for the Effect to work.
80
 */
81
  public static void enable()
82
    {
83
    addEffect( EffectName.CONTRAST,EffectName.SMOOTH_CONTRAST,
84
               "color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );" );
85
    }
86
  }
(9-9/26)