Project

General

Profile

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

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

1 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 cc62b34a Leszek Koltunski
// Copyright 2017 Leszek Koltunski  leszek@koltunski.pl                                          //
3 125cee3d Leszek Koltunski
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 125cee3d Leszek Koltunski
//                                                                                               //
6 cc62b34a Leszek Koltunski
// 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 125cee3d Leszek Koltunski
//                                                                                               //
11 cc62b34a Leszek Koltunski
// This library is distributed in the hope that it will be useful,                               //
12 125cee3d Leszek Koltunski
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13 cc62b34a Leszek Koltunski
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
14
// Lesser General Public License for more details.                                               //
15 125cee3d Leszek Koltunski
//                                                                                               //
16 cc62b34a Leszek Koltunski
// 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 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
20
21
package org.distorted.library.effect;
22
23
import org.distorted.library.type.Data1D;
24 b24e4719 Leszek Koltunski
import org.distorted.library.type.Data3D;
25
import org.distorted.library.type.Static3D;
26 125cee3d Leszek Koltunski
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28 faa3ff56 Leszek Koltunski
/**
29
 * Make a certain Region change its contrast level.
30
 */
31 125cee3d Leszek Koltunski
public class FragmentEffectContrast extends FragmentEffect
32
  {
33 0e1d3d2e Leszek Koltunski
  private final Data1D mContrast;
34
  private final Data3D mCenter;
35
  private final Data3D mRegion;
36 a1d92a36 leszek
37 faa3ff56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 b24e4719 Leszek Koltunski
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
46
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
47 faa3ff56 Leszek Koltunski
    return mContrast.get(uniforms,index,currentDuration,step);
48
    }
49
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
// PUBLIC API
52 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
53 6bb59aad Leszek Koltunski
/**
54
 * Makes a certain sub-region of the Object smoothly change its contrast level.
55
 *
56 e2e92a29 Leszek Koltunski
 * @param contrast level of contrast we want to have at any given moment. Valid range: <0,infinity)
57 b24e4719 Leszek Koltunski
 * @param center center of the Effect (point in 3D).
58
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
59 6bb59aad Leszek Koltunski
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
60
 */
61 b24e4719 Leszek Koltunski
  public FragmentEffectContrast(Data1D contrast, Data3D center, Data3D region, boolean smooth)
62 125cee3d Leszek Koltunski
    {
63 9d0d8530 leszek
    super(smooth?EffectName.SMOOTH_CONTRAST:EffectName.CONTRAST);
64 a1d92a36 leszek
    mContrast = contrast;
65 b24e4719 Leszek Koltunski
    mCenter = center;
66 dd89c7f4 Leszek Koltunski
    mRegion = (region==null ? MAX_REGION : region);
67 125cee3d Leszek Koltunski
    }
68
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70 6bb59aad Leszek Koltunski
/**
71
 * Makes the whole Object smoothly change its contrast level.
72
 *
73 e2e92a29 Leszek Koltunski
 * @param contrast level of contrast we want to have at any given moment. Valid range: <0,infinity)
74 6bb59aad Leszek Koltunski
 */
75 125cee3d Leszek Koltunski
  public FragmentEffectContrast(Data1D contrast)
76
    {
77 9d0d8530 leszek
    super(EffectName.CONTRAST);
78 a1d92a36 leszek
    mContrast = contrast;
79 b24e4719 Leszek Koltunski
    mCenter = new Static3D(0,0,0);
80 dd89c7f4 Leszek Koltunski
    mRegion = MAX_REGION;
81 125cee3d Leszek Koltunski
    }
82 15aa7d94 Leszek Koltunski
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84 faa3ff56 Leszek Koltunski
/**
85 7602a827 Leszek Koltunski
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
86 faa3ff56 Leszek Koltunski
 */
87 7cd24173 leszek
  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 125cee3d Leszek Koltunski
  }