Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import org.distorted.library.type.Dynamic1D;
26
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.Dynamic4D;
28
import org.distorted.library.type.Static1D;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
public class FragmentEffectChroma extends FragmentEffect
35
  {
36
  private static final float[] UNITIES         = new float[] {0.0f};
37
  private static final int DIMENSION           = 4;
38
  private static final boolean SUPPORTS_CENTER = false;
39
  private static final boolean SUPPORTS_REGION = true;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
/**
43
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
44
 *
45
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
46
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
47
 *               Valid range: <0,1>
48
 * @param color  Color to mix. (1,0,0) is RED.
49
 * @param region Region this Effect is limited to.
50
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
51
 */
52
  public FragmentEffectChroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
53
    {
54
    super(smooth?EffectName.SMOOTH_CHROMA:EffectName.CHROMA,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,UNITIES);
55

    
56
    if( blend instanceof Dynamic1D )
57
      {
58
      mDynamic0 = (Dynamic1D)blend;
59
      }
60
    else if ( blend instanceof Static1D )
61
      {
62
      mStatic0 = (Static1D)blend;
63
      }
64

    
65
    if( color instanceof Dynamic3D )
66
      {
67
      mDynamic1 = (Dynamic3D)color;
68
      }
69
    else if ( color instanceof Static3D)
70
      {
71
      mStatic1 = (Static3D)color;
72
      }
73

    
74
    if( region instanceof Static4D)
75
      {
76
      mStaticRegion = (Static4D)region;
77
      }
78
    else if( region instanceof Dynamic4D)
79
      {
80
      mDynamicRegion = (Dynamic4D)region;
81
      }
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
/**
86
 * Makes the whole Object smoothly change all three of its RGB components.
87
 *
88
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
89
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
90
 *               Valid range: <0,1>
91
 * @param color  Color to mix. (1,0,0) is RED.
92
 */
93
  public FragmentEffectChroma(Data1D blend, Data3D color)
94
    {
95
    super(EffectName.CHROMA,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,UNITIES);
96

    
97
    if( blend instanceof Dynamic1D )
98
      {
99
      mDynamic0 = (Dynamic1D)blend;
100
      }
101
    else if ( blend instanceof Static1D )
102
      {
103
      mStatic0 = (Static1D)blend;
104
      }
105

    
106
    if( color instanceof Dynamic3D )
107
      {
108
      mDynamic1 = (Dynamic3D)color;
109
      }
110
    else if ( color instanceof Static3D)
111
      {
112
      mStatic1 = (Static3D)color;
113
      }
114

    
115
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
121
    {
122
    if( mDynamicRegion!=null )
123
      {
124
      mDynamicRegion.interpolateMain(uniforms,index+4,currentDuration,step);
125
      }
126
    else
127
      {
128
      uniforms[index+4] = mStaticRegion.getX();
129
      uniforms[index+5] = mStaticRegion.getY();
130
      uniforms[index+6] = mStaticRegion.getZ();
131
      uniforms[index+7] = mStaticRegion.getW();
132
      }
133

    
134
    if( mDynamic1!=null )
135
      {
136
      mDynamic1.interpolateMain(uniforms,index+1,currentDuration,step);
137
      }
138
    else
139
      {
140
      uniforms[index+1] = ((Static3D)mStatic1).getX();
141
      uniforms[index+2] = ((Static3D)mStatic1).getY();
142
      uniforms[index+3] = ((Static3D)mStatic1).getZ();
143
      }
144

    
145
    if( mDynamic0!=null )
146
      {
147
      return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
148
      }
149
    else
150
      {
151
      uniforms[index  ] = ((Static1D)mStatic0).getX();
152
      return false;
153
      }
154
    }
155
  }
(7-7/25)