Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectChroma.java @ c1fa9e3c

1 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2017 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 125cee3d Leszek Koltunski
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 125cee3d Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// Distorted 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
// 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 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.library.effect;
21
22
import org.distorted.library.type.Data1D;
23
import org.distorted.library.type.Data3D;
24 b24e4719 Leszek Koltunski
import org.distorted.library.type.Static3D;
25 125cee3d Leszek Koltunski
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 faa3ff56 Leszek Koltunski
/**
28
 * Make a certain Region change its color.
29
 */
30 125cee3d Leszek Koltunski
public class FragmentEffectChroma extends FragmentEffect
31
  {
32 a1d92a36 leszek
  private Data1D mBlend;
33
  private Data3D mColor;
34 b24e4719 Leszek Koltunski
  private Data3D mCenter;
35
  private 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
    mColor.get(uniforms,index+1,currentDuration,step);
46 b24e4719 Leszek Koltunski
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
47
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
48 faa3ff56 Leszek Koltunski
    return mBlend.get(uniforms,index,currentDuration,step);
49
    }
50
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
// PUBLIC API
53 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
54 6bb59aad Leszek Koltunski
/**
55
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
56
 *
57 e2e92a29 Leszek Koltunski
 * @param blend  level of blend a given pixel will be mixed with the next parameter 'color':
58
 *               pixel = (1-level)*pixel + level*color.
59 6bb59aad Leszek Koltunski
 *               Valid range: <0,1>
60
 * @param color  Color to mix. (1,0,0) is RED.
61 b24e4719 Leszek Koltunski
 * @param center center of the Effect (point in 3D).
62
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
63 6bb59aad Leszek Koltunski
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
64
 */
65 b24e4719 Leszek Koltunski
  public FragmentEffectChroma(Data1D blend, Data3D color, Data3D center, Data3D region, boolean smooth)
66 125cee3d Leszek Koltunski
    {
67 9d0d8530 leszek
    super(smooth?EffectName.SMOOTH_CHROMA:EffectName.CHROMA);
68 b24e4719 Leszek Koltunski
    mBlend  = blend;
69
    mColor  = color;
70
    mCenter = center;
71 dd89c7f4 Leszek Koltunski
    mRegion = (region==null ? MAX_REGION : region);
72 125cee3d Leszek Koltunski
    }
73
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75 6bb59aad Leszek Koltunski
/**
76
 * Makes the whole Object smoothly change all three of its RGB components.
77
 *
78 e2e92a29 Leszek Koltunski
 * @param blend  level of blend a given pixel will be mixed with the next parameter 'color':
79
 *               pixel = (1-level)*pixel + level*color.
80 6bb59aad Leszek Koltunski
 *               Valid range: <0,1>
81
 * @param color  Color to mix. (1,0,0) is RED.
82
 */
83 125cee3d Leszek Koltunski
  public FragmentEffectChroma(Data1D blend, Data3D color)
84
    {
85 9d0d8530 leszek
    super(EffectName.CHROMA);
86 a1d92a36 leszek
    mBlend = blend;
87
    mColor = color;
88 b24e4719 Leszek Koltunski
    mCenter = new Static3D(0,0,0);
89 dd89c7f4 Leszek Koltunski
    mRegion = MAX_REGION;
90 125cee3d Leszek Koltunski
    }
91 15aa7d94 Leszek Koltunski
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93 faa3ff56 Leszek Koltunski
/**
94 7602a827 Leszek Koltunski
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
95 faa3ff56 Leszek Koltunski
 */
96 7cd24173 leszek
  public static void enable()
97
    {
98
    addEffect( EffectName.CHROMA,EffectName.SMOOTH_CHROMA,
99
               "color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);" );
100
    }
101 125cee3d Leszek Koltunski
  }