Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectContrast.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 contrast level.
30
 */
31
public class FragmentEffectContrast extends FragmentEffect
32
  {
33
  private final Data1D mContrast;
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 mContrast.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 contrast level.
55
 *
56
 * @param contrast level of contrast 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 'contrast' will smoothly fade out towards the edges of the region.
60
 */
61
  public FragmentEffectContrast(Data1D contrast, Data3D center, Data3D region, boolean smooth)
62
    {
63
    super(smooth?EffectName.SMOOTH_CONTRAST:EffectName.CONTRAST);
64
    mContrast = contrast;
65
    mCenter = center;
66
    mRegion = (region==null ? MAX_REGION : region);
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
/**
71
 * Makes the whole Object smoothly change its contrast level.
72
 *
73
 * @param contrast level of contrast we want to have at any given moment. Valid range: <0,infinity)
74
 */
75
  public FragmentEffectContrast(Data1D contrast)
76
    {
77
    super(EffectName.CONTRAST);
78
    mContrast = contrast;
79
    mCenter = new Static3D(0,0,0);
80
    mRegion = MAX_REGION;
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
/**
85
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
86
 */
87
  public static void enable()
88
    {
89
    addEffect( EffectName.CONTRAST,EffectName.SMOOTH_CONTRAST,
90
               "color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );" );
91
    }
92
  }
(9-9/34)