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/VertexEffectWave.java
33 33
 */
34 34
public class VertexEffectWave extends VertexEffect
35 35
  {
36
  private static final EffectName NAME = EffectName.WAVE;
37

  
36 38
  private Data5D mWave;
37 39
  private Data3D mCenter;
38 40
  private Data4D mRegion;
......
47 49
    {
48 50
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
49 51
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
50
    boolean ret = mWave.get(uniforms,index,currentDuration,step);
52
    boolean ret = mWave.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
51 53

  
52
    uniforms[index+2] = (float)(Math.PI*uniforms[index+2]/180);
53
    uniforms[index+3] = (float)(Math.PI*uniforms[index+3]/180);
54
    uniforms[index+4] = (float)(Math.PI*uniforms[index+4]/180);
54
    uniforms[index+VALUES_OFFSET+2] = (float)(Math.PI*uniforms[index+2]/180);
55
    uniforms[index+VALUES_OFFSET+3] = (float)(Math.PI*uniforms[index+3]/180);
56
    uniforms[index+VALUES_OFFSET+4] = (float)(Math.PI*uniforms[index+4]/180);
55 57

  
56 58
    return ret;
57 59
    }
58 60

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
// PUBLIC API
61
///////////////////////////////////////////////////////////////////////////////////////////////////
61
//////////////////////////////////////////////////////////////////////////////////////////////
62 62
// Directional sinusoidal wave effect.
63 63
//
64 64
// This is an effect from a (hopefully!) generic family of effects of the form (vec3 V: |V|=1 , f(x,y) )  (*)
......
122 122
//
123 123
// Generally speaking I'd keep to amplitude < length, as the opposite case has some other problems as well.
124 124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
/**
126
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
127
 */
128
  public static void enable()
125

  
126
  static String code()
129 127
    {
130
    addEffect(EffectName.WAVE,
128
    return
131 129

  
132 130
        "vec3 center     = vUniforms[effect+1].yzw;                   \n"
133 131
      + "float amplitude = vUniforms[effect  ].x;                     \n"
......
184 182
      +     "n.y = (n.y*normal.z + n.z*normal.y);                     \n"   // ? Because if we do the above, my Nexus4 crashes
185 183
      +     "n.z = (n.z*normal.z);                                    \n"   // during shader compilation!
186 184
      +     "}                                                        \n"
187
      +   "}"
188
      );
185
      +   "}";
186
    }
187

  
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
// PUBLIC API
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
/**
192
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
193
 */
194
  public static void enable()
195
    {
196
    addEffect( NAME, code() );
189 197
    }
190 198

  
191 199
///////////////////////////////////////////////////////////////////////////////////////////////////
......
219 227
 */
220 228
  public VertexEffectWave(Data5D wave, Data3D center, Data4D region)
221 229
    {
222
    super(EffectName.WAVE);
230
    super(NAME);
223 231
    mWave   = wave;
224 232
    mCenter = center;
225 233
    mRegion = (region==null ? MAX_REGION : region);
......
229 237
/**
230 238
 * Directional, sinusoidal wave effect.
231 239
 *
232
 * @param wave   see {@link #VertexEffectWave(Data5D,Data3D)}
240
 * @param wave   see {@link #VertexEffectWave(Data5D,Data3D,Data4D)}
233 241
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
234 242
 */
235 243
  public VertexEffectWave(Data5D wave, Data3D center)
236 244
    {
237
    super(EffectName.WAVE);
245
    super(NAME);
238 246
    mWave   = wave;
239 247
    mCenter = center;
240 248
    mRegion = MAX_REGION;

Also available in: Unified diff