Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectChroma.java @ 8e28b6ff

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
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Data4D;
25 6bb59aad Leszek Koltunski
import org.distorted.library.type.Static4D;
26 125cee3d Leszek Koltunski
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28
29
public class FragmentEffectChroma extends FragmentEffect
30
  {
31 a1d92a36 leszek
  private Data1D mBlend;
32
  private Data3D mColor;
33
  private Data4D mRegion;
34
35 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
36 6bb59aad Leszek Koltunski
/**
37
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
38
 *
39 e2e92a29 Leszek Koltunski
 * @param blend  level of blend a given pixel will be mixed with the next parameter 'color':
40
 *               pixel = (1-level)*pixel + level*color.
41 6bb59aad Leszek Koltunski
 *               Valid range: <0,1>
42
 * @param color  Color to mix. (1,0,0) is RED.
43
 * @param region Region this Effect is limited to.
44
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
45
 */
46 125cee3d Leszek Koltunski
  public FragmentEffectChroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
47
    {
48 9d0d8530 leszek
    super(smooth?EffectName.SMOOTH_CHROMA:EffectName.CHROMA);
49 a1d92a36 leszek
    mBlend = blend;
50
    mColor = color;
51
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
52 125cee3d Leszek Koltunski
    }
53
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55 6bb59aad Leszek Koltunski
/**
56
 * Makes the whole 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
 */
63 125cee3d Leszek Koltunski
  public FragmentEffectChroma(Data1D blend, Data3D color)
64
    {
65 9d0d8530 leszek
    super(EffectName.CHROMA);
66 a1d92a36 leszek
    mBlend = blend;
67
    mColor = color;
68
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
69 125cee3d Leszek Koltunski
    }
70 15aa7d94 Leszek Koltunski
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
74
    {
75 a1d92a36 leszek
    mRegion.get(uniforms,index+4,currentDuration,step);
76
    mColor.get(uniforms,index+1,currentDuration,step);
77
    return mBlend.get(uniforms,index,currentDuration,step);
78 15aa7d94 Leszek Koltunski
    }
79 7cd24173 leszek
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
82
  public static void enable()
83
    {
84
    addEffect( EffectName.CHROMA,EffectName.SMOOTH_CHROMA,
85
               "color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);" );
86
    }
87 125cee3d Leszek Koltunski
  }