Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectSink.java @ 8fdeecd7

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

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
/**
28
 * Pull all points around the center of the Effect towards the center point (if degree>=1) or push them
29
 * away from it (degree<=1).
30
 */
31
public class VertexEffectSink extends VertexEffect
32
  {
33
  private Data1D mSink;
34
  private Data3D mCenter;
35
  private Data4D mRegion;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
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
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
46
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
47
    return mSink.get(uniforms,index,currentDuration,step);
48
    }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
// PUBLIC API
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
// Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P)
54
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P)
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
/**
57
 * Have to call this before the shaders get compiled (i.e before Distorted.onCreate()) for the Effect to work.
58
 */
59
  public static void enable()
60
    {
61
    addEffect(EffectName.SINK,
62

    
63
        "vec3 center = vUniforms[effect+1].yzw; \n"
64
      + "vec3 ps = center-v; \n"
65
      + "float h = vUniforms[effect].x; \n"
66
      + "float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h); \n"
67

    
68
      + "v += t*ps;"
69
      );
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
/**
74
 * Pull all points around the center of the Effect towards the center point (if degree>=1) or push them
75
 * away from it (degree<=1)
76
 *
77
 * @param sink   The current degree of the Effect.
78
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
79
 * @param region Region that masks the Effect.
80
 */
81
  public VertexEffectSink(Data1D sink, Data3D center, Data4D region)
82
    {
83
    super(EffectName.SINK);
84
    mSink   = sink;
85
    mCenter = center;
86
    mRegion = (region==null ? MAX_REGION : region);
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
/**
91
 * Pull all points around the center of the Effect towards the center point(if degree>=1) or push them
92
 * away from it (degree<=1)
93
 *
94
 * @param sink   The current degree of the Effect.
95
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
96
 */
97
  public VertexEffectSink(Data1D sink, Data3D center)
98
    {
99
    super(EffectName.SINK);
100
    mSink   = sink;
101
    mCenter = center;
102
    mRegion = MAX_REGION;
103
    }
104
  }
(24-24/26)