Project

General

Profile

« Previous | Next » 

Revision f046b159

Added by Leszek Koltunski almost 4 years ago

First attempt at the MeshBase.apply(VertexEffect) API.

View differences:

src/main/java/org/distorted/library/effect/VertexEffectDeform.java
29 29
 */
30 30
public class VertexEffectDeform extends VertexEffect
31 31
  {
32
  private static final EffectName NAME = EffectName.DEFORM;
33

  
32 34
  private Data3D mVector, mCenter;
33 35
  private Data1D mRadius;
34 36
  private Data4D mRegion;
......
41 43
 */
42 44
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
43 45
    {
44
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
45
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
46
    mRadius.get(uniforms,index+3,currentDuration,step);
47
    return mVector.get(uniforms,index,currentDuration,step);
46
    mCenter.get(uniforms,index+CENTER_OFFSET  ,currentDuration,step);
47
    mRegion.get(uniforms,index+REGION_OFFSET  ,currentDuration,step);
48
    mRadius.get(uniforms,index+VALUES_OFFSET+3,currentDuration,step);
49

  
50
    return mVector.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
48 51
    }
49 52

  
50 53
///////////////////////////////////////////////////////////////////////////////////////////////////
......
103 106
///////////////////////////////////////////////////////////////////////////////////////////////////
104 107
// 2020-05-03: replaced vec3 'u_Bounding' with a uniform 'vUniforms[effect].w' (i.e. mRadius)
105 108
///////////////////////////////////////////////////////////////////////////////////////////////////
106
/**
107
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
108
 */
109
  public static void enable()
109

  
110
  static String code()
110 111
    {
111
    addEffect( EffectName.DEFORM,
112
    return
112 113

  
113 114
        "const vec3 ONE = vec3(1.0,1.0,1.0);                                 \n"
114 115
      + "const float A = 0.5;                                                \n"
......
144 145
      + "v.z += force.z*d*d*(3.0*d*d -8.0*d +6.0);                           \n"  // thick bubble
145 146
      + "float b = -(12.0*force.z*d*(1.0-d)*(1.0-d)*(1.0-d))*one_over_denom; \n"
146 147

  
147
      + "n.xy += n.z*b*ps.xy;"
148
      );
148
      + "n.xy += n.z*b*ps.xy;";
149
    }
150

  
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152
/**
153
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
154
 */
155
  public static void enable()
156
    {
157
    addEffect( NAME, code() );
149 158
    }
150 159

  
151 160
///////////////////////////////////////////////////////////////////////////////////////////////////
......
161 170
 */
162 171
  public VertexEffectDeform(Data3D vector, Data1D radius, Data3D center, Data4D region)
163 172
    {
164
    super(EffectName.DEFORM);
173
    super(NAME);
165 174
    mVector = vector;
166 175
    mRadius = radius;
167 176
    mCenter = center;
......
180 189
 */
181 190
  public VertexEffectDeform(Data3D vector, Data1D radius, Data3D center)
182 191
    {
183
    super(EffectName.DEFORM);
192
    super(NAME);
184 193
    mVector = vector;
185 194
    mRadius = radius;
186 195
    mCenter = center;

Also available in: Unified diff