Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectAlpha.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.Data4D;
24
import org.distorted.library.type.Dynamic1D;
25
import org.distorted.library.type.Dynamic4D;
26
import org.distorted.library.type.Static1D;
27
import org.distorted.library.type.Static4D;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class FragmentEffectAlpha extends FragmentEffect
32
  {
33
  private static final String NAME = "ALPHA";
34
  private static final float[] UNITIES = new float[] {1.0f};
35
  private static final int DIMENSION = 1;
36
  private static final boolean SUPPORTS_CENTER = false;
37
  private static final boolean SUPPORTS_REGION = true;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
/**
41
 * Makes a certain sub-region of the Object smoothly change its transparency level.
42
 *
43
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
44
 *               moment: pixel.a *= alpha.
45
 *               Valid range: <0,1>
46
 * @param region Region this Effect is limited to.
47
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
48
 */
49
  public FragmentEffectAlpha(Data1D alpha, Data4D region, boolean smooth)
50
    {
51
    super(smooth?SMOOTH_ALPHA:ALPHA ,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
52

    
53
    if( alpha instanceof Dynamic1D )
54
      {
55
      mDynamic0 = (Dynamic1D)alpha;
56
      }
57
    else if ( alpha instanceof Static1D )
58
      {
59
      mStatic0 = (Static1D)alpha;
60
      }
61

    
62
    if( region instanceof Static4D)
63
      {
64
      mStaticRegion = (Static4D)region;
65
      }
66
    else if( region instanceof Dynamic4D)
67
      {
68
      mDynamicRegion = (Dynamic4D)region;
69
      }
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
/**
74
 * Makes the whole Object smoothly change its transparency level.
75
 *
76
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
77
 *               given moment: pixel.a *= alpha.
78
 *               Valid range: <0,1>
79
 */
80
  public FragmentEffectAlpha(Data1D alpha)
81
    {
82
    super(ALPHA,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
83

    
84
    if( alpha instanceof Dynamic1D )
85
      {
86
      mDynamic0 = (Dynamic1D)alpha;
87
      }
88
    else if ( alpha instanceof Static1D )
89
      {
90
      mStatic0 = (Static1D)alpha;
91
      }
92

    
93
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
99
    {
100
    if( mDynamicRegion!=null )
101
      {
102
      mDynamicRegion.interpolateMain(uniforms,index+4,currentDuration,step);
103
      }
104
    else
105
      {
106
      uniforms[index+4] = mStaticRegion.getX();
107
      uniforms[index+5] = mStaticRegion.getY();
108
      uniforms[index+6] = mStaticRegion.getZ();
109
      uniforms[index+7] = mStaticRegion.getW();
110
      }
111

    
112
    if( mDynamic0!=null )
113
      {
114
      return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
115
      }
116
    else
117
      {
118
      uniforms[index] = ((Static1D)mStatic0).getX();
119
      return false;
120
      }
121
    }
122
  }
(3-3/23)