Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectContrast.java @ b24e4719

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 b24e4719 Leszek Koltunski
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Static3D;
25 125cee3d Leszek Koltunski
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 faa3ff56 Leszek Koltunski
/**
28
 * Make a certain Region change its contrast level.
29
 */
30 125cee3d Leszek Koltunski
public class FragmentEffectContrast extends FragmentEffect
31
  {
32 a1d92a36 leszek
  private Data1D mContrast;
33 b24e4719 Leszek Koltunski
  private Data3D mCenter;
34
  private Data3D mRegion;
35 a1d92a36 leszek
36 faa3ff56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
37
/**
38
 * Only for use by the library itself.
39
 *
40
 * @y.exclude
41
 */
42
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
43
    {
44 b24e4719 Leszek Koltunski
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
45
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
46 faa3ff56 Leszek Koltunski
    return mContrast.get(uniforms,index,currentDuration,step);
47
    }
48
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
// PUBLIC API
51 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
52 6bb59aad Leszek Koltunski
/**
53
 * Makes a certain sub-region of the Object smoothly change its contrast level.
54
 *
55 e2e92a29 Leszek Koltunski
 * @param contrast level of contrast we want to have at any given moment. Valid range: <0,infinity)
56 b24e4719 Leszek Koltunski
 * @param center center of the Effect (point in 3D).
57
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
58 6bb59aad Leszek Koltunski
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
59
 */
60 b24e4719 Leszek Koltunski
  public FragmentEffectContrast(Data1D contrast, Data3D center, Data3D region, boolean smooth)
61 125cee3d Leszek Koltunski
    {
62 9d0d8530 leszek
    super(smooth?EffectName.SMOOTH_CONTRAST:EffectName.CONTRAST);
63 a1d92a36 leszek
    mContrast = contrast;
64 b24e4719 Leszek Koltunski
    mCenter = center;
65
    mRegion = (region==null ? new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE) : region);
66 125cee3d Leszek Koltunski
    }
67
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69 6bb59aad Leszek Koltunski
/**
70
 * Makes the whole Object smoothly change its contrast level.
71
 *
72 e2e92a29 Leszek Koltunski
 * @param contrast level of contrast we want to have at any given moment. Valid range: <0,infinity)
73 6bb59aad Leszek Koltunski
 */
74 125cee3d Leszek Koltunski
  public FragmentEffectContrast(Data1D contrast)
75
    {
76 9d0d8530 leszek
    super(EffectName.CONTRAST);
77 a1d92a36 leszek
    mContrast = contrast;
78 b24e4719 Leszek Koltunski
    mCenter = new Static3D(0,0,0);
79
    mRegion = new Static3D(Float.MAX_VALUE,Float.MAX_VALUE, Float.MAX_VALUE);
80 125cee3d Leszek Koltunski
    }
81 15aa7d94 Leszek Koltunski
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83 faa3ff56 Leszek Koltunski
/**
84
 * Have to call this before the shaders get compiled (i.e before Distorted.onCreate()) for the Effect to work.
85
 */
86 7cd24173 leszek
  public static void enable()
87
    {
88
    addEffect( EffectName.CONTRAST,EffectName.SMOOTH_CONTRAST,
89
               "color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );" );
90
    }
91 125cee3d Leszek Koltunski
  }