Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectChroma.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
import org.distorted.library.type.Data3D;
25 b24e4719 Leszek Koltunski
import org.distorted.library.type.Static3D;
26 125cee3d Leszek Koltunski
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28 faa3ff56 Leszek Koltunski
/**
29
 * Make a certain Region change its color.
30
 */
31 125cee3d Leszek Koltunski
public class FragmentEffectChroma extends FragmentEffect
32
  {
33 0e1d3d2e Leszek Koltunski
  private final Data1D mBlend;
34
  private final Data3D mColor;
35
  private final Data3D mCenter;
36
  private final Data3D mRegion;
37 a1d92a36 leszek
38 faa3ff56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
39
/**
40
 * Only for use by the library itself.
41
 *
42
 * @y.exclude
43
 */
44
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
45
    {
46
    mColor.get(uniforms,index+1,currentDuration,step);
47 b24e4719 Leszek Koltunski
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
48
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
49 faa3ff56 Leszek Koltunski
    return mBlend.get(uniforms,index,currentDuration,step);
50
    }
51
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
// PUBLIC API
54 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
55 6bb59aad Leszek Koltunski
/**
56
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
57
 *
58 e2e92a29 Leszek Koltunski
 * @param blend  level of blend a given pixel will be mixed with the next parameter 'color':
59
 *               pixel = (1-level)*pixel + level*color.
60 6bb59aad Leszek Koltunski
 *               Valid range: <0,1>
61
 * @param color  Color to mix. (1,0,0) is RED.
62 b24e4719 Leszek Koltunski
 * @param center center of the Effect (point in 3D).
63
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
64 6bb59aad Leszek Koltunski
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
65
 */
66 b24e4719 Leszek Koltunski
  public FragmentEffectChroma(Data1D blend, Data3D color, Data3D center, Data3D region, boolean smooth)
67 125cee3d Leszek Koltunski
    {
68 9d0d8530 leszek
    super(smooth?EffectName.SMOOTH_CHROMA:EffectName.CHROMA);
69 b24e4719 Leszek Koltunski
    mBlend  = blend;
70
    mColor  = color;
71
    mCenter = center;
72 dd89c7f4 Leszek Koltunski
    mRegion = (region==null ? MAX_REGION : region);
73 125cee3d Leszek Koltunski
    }
74
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76 6bb59aad Leszek Koltunski
/**
77
 * Makes the whole Object smoothly change all three of its RGB components.
78
 *
79 e2e92a29 Leszek Koltunski
 * @param blend  level of blend a given pixel will be mixed with the next parameter 'color':
80
 *               pixel = (1-level)*pixel + level*color.
81 6bb59aad Leszek Koltunski
 *               Valid range: <0,1>
82
 * @param color  Color to mix. (1,0,0) is RED.
83
 */
84 125cee3d Leszek Koltunski
  public FragmentEffectChroma(Data1D blend, Data3D color)
85
    {
86 9d0d8530 leszek
    super(EffectName.CHROMA);
87 a1d92a36 leszek
    mBlend = blend;
88
    mColor = color;
89 b24e4719 Leszek Koltunski
    mCenter = new Static3D(0,0,0);
90 dd89c7f4 Leszek Koltunski
    mRegion = MAX_REGION;
91 125cee3d Leszek Koltunski
    }
92 15aa7d94 Leszek Koltunski
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94 faa3ff56 Leszek Koltunski
/**
95 7602a827 Leszek Koltunski
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
96 faa3ff56 Leszek Koltunski
 */
97 7cd24173 leszek
  public static void enable()
98
    {
99
    addEffect( EffectName.CHROMA,EffectName.SMOOTH_CHROMA,
100
               "color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);" );
101
    }
102 125cee3d Leszek Koltunski
  }