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/VertexEffectShear.java
27 27
 */
28 28
public class VertexEffectShear extends VertexEffect
29 29
  {
30
  private Data3D mShear, mCenter;
30
  private static final EffectName NAME = EffectName.VERTEX_SHEAR;
31

  
32
  private Data3D mShear;
33
  private Data3D mCenter;
31 34

  
32 35
///////////////////////////////////////////////////////////////////////////////////////////////////
33 36
/**
......
38 41
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
39 42
    {
40 43
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
41
    return mShear.get(uniforms,index,currentDuration,step);
44
    return mShear.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
42 45
    }
43 46

  
44 47
///////////////////////////////////////////////////////////////////////////////////////////////////
45
// PUBLIC API
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
/*
48
  float sx = uniforms[NUM_UNIFORMS*index  ];
49
    float sy = uniforms[NUM_UNIFORMS*index+1];
50
    float sz = uniforms[NUM_UNIFORMS*index+2];
51 48

  
52
    float x  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET  ];
53
    float y  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1];
54
    float z  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2];
49
  static String code()
50
    {
51
    return
52

  
53
      "float sx = vUniforms[effect].x;               \n"
54
    + "float sy = vUniforms[effect].y;               \n"
55
    + "float sz = vUniforms[effect].z;               \n"
56
    + "vec3 center = vUniforms[effect+1].yzw;        \n"
55 57

  
56
    Matrix.translateM(matrix, 0, x, y, z);
58
    + "v -= center;                                  \n"
57 59

  
58
    matrix[4] += sx*matrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
59
    matrix[5] += sx*matrix[1]; //                        0 1 0 0
60
    matrix[6] += sx*matrix[2]; //                        0 0 1 0
61
    matrix[7] += sx*matrix[3]; //                        0 0 0 1
60
    + "float new_vx = (1.0+sx*sy)*v.x + sx*v.y;      \n"
61
    + "float new_vy = sy*v.x + v.y;                  \n"
62
    + "float new_vz = sz*v.y + v.z;                  \n"
62 63

  
63
    matrix[0] += sy*matrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear.
64
    matrix[1] += sy*matrix[5]; //                        y 1 0 0
65
    matrix[2] += sy*matrix[6]; //                        0 0 1 0
66
    matrix[3] += sy*matrix[7]; //                        0 0 0 1
64
    + "v.x = new_vx;                                 \n"
65
    + "v.y = new_vy;                                 \n"
66
    + "v.z = new_vz;                                 \n"
67 67

  
68
    matrix[4] += sz*matrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear.
69
    matrix[5] += sz*matrix[9]; //                        0 1 0 0
70
    matrix[6] += sz*matrix[10];//                        0 z 1 0
71
    matrix[7] += sz*matrix[11];//                        0 0 0 1
68
    + "v += center;                                  \n"
72 69

  
73
    Matrix.translateM(matrix, 0,-x,-y,-z);
74
*/
70
    + "float new_nx = (1.0+sx*sy)*n.x + sx*n.y;      \n"
71
    + "float new_ny = sy*n.x + n.y;                  \n"
72
    + "float new_nz = sz*n.y + n.z;                  \n"
75 73

  
74
    + "n.x = new_nx;                                 \n"
75
    + "n.y = new_ny;                                 \n"
76
    + "n.z = new_nz;                                 \n";
77
    }
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
// PUBLIC API
81
///////////////////////////////////////////////////////////////////////////////////////////////////
76 82
/**
77 83
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
78 84
 */
79 85
  public static void enable()
80 86
    {
81
    addEffect( EffectName.VERTEX_SHEAR,
82

  
83
               "float sx = vUniforms[effect].x;               \n"
84
             + "float sy = vUniforms[effect].y;               \n"
85
             + "float sz = vUniforms[effect].z;               \n"
86
             + "vec3 center = vUniforms[effect+1].yzw;        \n"
87

  
88
             + "v -= center;                                  \n"
89

  
90
             + "float new_vx = (1.0+sx*sy)*v.x + sx*v.y;      \n"
91
             + "float new_vy = sy*v.x + v.y;                  \n"
92
             + "float new_vz = sz*v.y + v.z;                  \n"
93

  
94
             + "v.x = new_vx;                                 \n"
95
             + "v.y = new_vy;                                 \n"
96
             + "v.z = new_vz;                                 \n"
97

  
98
             + "v += center;                                  \n"
99

  
100
             + "float new_nx = (1.0+sx*sy)*n.x + sx*n.y;      \n"
101
             + "float new_ny = sy*n.x + n.y;                  \n"
102
             + "float new_nz = sz*n.y + n.z;                  \n"
103

  
104
             + "n.x = new_nx;                                 \n"
105
             + "n.y = new_ny;                                 \n"
106
             + "n.z = new_nz;                                 \n"
107
             );
87
    addEffect( NAME, code() );
108 88
    }
109 89

  
110 90
///////////////////////////////////////////////////////////////////////////////////////////////////
......
119 99
 */
120 100
  public VertexEffectShear(Data3D shear, Data3D center)
121 101
    {
122
    super(EffectName.VERTEX_SHEAR);
102
    super(NAME);
123 103
    mShear = shear;
124 104
    mCenter = center;
125 105
    }

Also available in: Unified diff