Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectChroma.java @ 6bb59aad

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 String NAME = "CHROMA";
37
  private static final float[] UNITIES = new float[] {0.0f};
38
  private static final int DIMENSION = 4;
39
  private static final boolean SUPPORTS_CENTER = false;
40
  private static final boolean SUPPORTS_REGION = true;
41

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

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

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

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

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

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

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

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

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

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

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

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