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/VertexEffectDistort.java
28 28
 */
29 29
public class VertexEffectDistort extends VertexEffect
30 30
  {
31
  private static final EffectName NAME = EffectName.DISTORT;
32

  
31 33
  private Data3D mVector, mCenter;
32 34
  private Data4D mRegion;
33 35

  
......
41 43
    {
42 44
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
43 45
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
44
    return mVector.get(uniforms,index,currentDuration,step);
46

  
47
    return mVector.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
45 48
    }
46 49

  
47 50
///////////////////////////////////////////////////////////////////////////////////////////////////
......
118 121
// which makes Vrot = (a+n.y*c , b-n.y*c , v*n) where
119 122
// a = vx*nz-vz*nx , b = vy*nz-vz*ny , c = (vx*ny-vy*nx)/(1+nz)    (unless n=(0,0,-1))
120 123
///////////////////////////////////////////////////////////////////////////////////////////////////
121
/**
122
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
123
 */
124
  public static void enable()
124

  
125
  static String code()
125 126
    {
126
    addEffect(EffectName.DISTORT,
127
    return
127 128

  
128 129
        "vec3 ps = vUniforms[effect+1].yzw - v;                        \n"
129 130
      + "vec3 force = vUniforms[effect].xyz;                           \n"
......
152 153
      + "  n = vec3( an+n.y*cn , bn-n.x*cn , -N.x*n.x-N.y*n.y+N.z*n.z);\n"   // notice 4 signs change!
153 154

  
154 155
      + "  n = normalize(n);                                           \n"
155
      + "  }                                                           \n"
156
      );
156
      + "  }                                                           \n";
157
    }
158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
/**
161
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
162
 */
163
  public static void enable()
164
    {
165
    addEffect( NAME, code() );
157 166
    }
158 167

  
159 168
///////////////////////////////////////////////////////////////////////////////////////////////////
......
166 175
 */
167 176
  public VertexEffectDistort(Data3D vector, Data3D center, Data4D region)
168 177
    {
169
    super(EffectName.DISTORT);
178
    super(NAME);
170 179
    mVector = vector;
171 180
    mCenter = center;
172 181
    mRegion = (region==null ? MAX_REGION : region);
......
181 190
 */
182 191
  public VertexEffectDistort(Data3D vector, Data3D center)
183 192
    {
184
    super(EffectName.DISTORT);
193
    super(NAME);
185 194
    mVector = vector;
186 195
    mCenter = center;
187 196
    mRegion = MAX_REGION;

Also available in: Unified diff