Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectChroma.java @ 7625e47e

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

    
51
    if( blend instanceof Dynamic1D )
52
      {
53
      mDynamic0 = (Dynamic1D)blend;
54
      }
55
    else if ( blend instanceof Static1D )
56
      {
57
      mStatic0 = (Static1D)blend;
58
      }
59

    
60
    if( color instanceof Dynamic3D )
61
      {
62
      mDynamic1 = (Dynamic3D)color;
63
      }
64
    else if ( color instanceof Static3D)
65
      {
66
      mStatic1 = (Static3D)color;
67
      }
68

    
69
    if( region == null )
70
      {
71
      mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
72
      }
73
    else
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
/**
88
 * Makes the whole Object smoothly change all three of its RGB components.
89
 *
90
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
91
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
92
 *               Valid range: <0,1>
93
 * @param color  Color to mix. (1,0,0) is RED.
94
 */
95
  public FragmentEffectChroma(Data1D blend, Data3D color)
96
    {
97
    super(EffectName.CHROMA);
98

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

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

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

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

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

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

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