Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / FragmentEffectAlpha.java @ c0255951

1 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 cc62b34a Leszek Koltunski
// Copyright 2017 Leszek Koltunski  leszek@koltunski.pl                                          //
3 125cee3d Leszek Koltunski
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 125cee3d Leszek Koltunski
//                                                                                               //
6 cc62b34a Leszek Koltunski
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10 125cee3d Leszek Koltunski
//                                                                                               //
11 cc62b34a Leszek Koltunski
// This library is distributed in the hope that it will be useful,                               //
12 125cee3d Leszek Koltunski
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13 cc62b34a Leszek Koltunski
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
14
// Lesser General Public License for more details.                                               //
15 125cee3d Leszek Koltunski
//                                                                                               //
16 cc62b34a Leszek Koltunski
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
20
21
package org.distorted.library.effect;
22
23
import org.distorted.library.type.Data1D;
24 b24e4719 Leszek Koltunski
import org.distorted.library.type.Data3D;
25
import org.distorted.library.type.Static3D;
26 125cee3d Leszek Koltunski
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28 faa3ff56 Leszek Koltunski
/**
29
 * Make a certain Region change its transparency level.
30
 */
31 125cee3d Leszek Koltunski
public class FragmentEffectAlpha extends FragmentEffect
32
  {
33 0e1d3d2e Leszek Koltunski
  private final Data1D mAlpha;
34
  private final Data3D mCenter;
35
  private final Data3D mRegion;
36 a1d92a36 leszek
37 faa3ff56 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
38
/**
39
 * Only for use by the library itself.
40
 *
41
 * @y.exclude
42
 */
43
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
44
    {
45 b24e4719 Leszek Koltunski
    mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step);
46
    mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step);
47 faa3ff56 Leszek Koltunski
    return mAlpha.get(uniforms,index, currentDuration, step);
48
    }
49
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
// PUBLIC API
52 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
53 6bb59aad Leszek Koltunski
/**
54
 * Makes a certain sub-region of the Object smoothly change its transparency level.
55
 *
56 e2e92a29 Leszek Koltunski
 * @param alpha  level of transparency we want to have at any given moment: pixel.a *= alpha.
57 6bb59aad Leszek Koltunski
 *               Valid range: <0,1>
58 b24e4719 Leszek Koltunski
 * @param center center of the Effect (point in 3D).
59
 * @param region Region this Effect is limited to (3 radii defining an ellipsoid).
60 6bb59aad Leszek Koltunski
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
61
 */
62 b24e4719 Leszek Koltunski
  public FragmentEffectAlpha(Data1D alpha, Data3D center, Data3D region, boolean smooth)
63 125cee3d Leszek Koltunski
    {
64 9d0d8530 leszek
    super(smooth? EffectName.SMOOTH_ALPHA:EffectName.ALPHA);
65 b24e4719 Leszek Koltunski
    mAlpha  = alpha;
66
    mCenter = center;
67 dd89c7f4 Leszek Koltunski
    mRegion = (region==null ? MAX_REGION : region);
68 125cee3d Leszek Koltunski
    }
69
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71 6bb59aad Leszek Koltunski
/**
72
 * Makes the whole Object smoothly change its transparency level.
73
 *
74 e2e92a29 Leszek Koltunski
 * @param alpha  level of transparency we want to have at any given moment: pixel.a *= alpha.
75 6bb59aad Leszek Koltunski
 *               Valid range: <0,1>
76
 */
77 125cee3d Leszek Koltunski
  public FragmentEffectAlpha(Data1D alpha)
78
    {
79 9d0d8530 leszek
    super(EffectName.ALPHA);
80 b24e4719 Leszek Koltunski
    mAlpha  = alpha;
81
    mCenter = new Static3D(0,0,0);
82 dd89c7f4 Leszek Koltunski
    mRegion = MAX_REGION;
83 125cee3d Leszek Koltunski
    }
84 15aa7d94 Leszek Koltunski
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86 faa3ff56 Leszek Koltunski
/**
87 7602a827 Leszek Koltunski
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
88 faa3ff56 Leszek Koltunski
 */
89 7cd24173 leszek
  public static void enable()
90
    {
91
    addEffect( EffectName.ALPHA,EffectName.SMOOTH_ALPHA,
92
               "color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);" );
93
    }
94 125cee3d Leszek Koltunski
  }