Project

General

Profile

« Previous | Next » 

Revision 62c869ad

Added by Leszek Koltunski over 4 years ago

Fix normals in case of MatrixEffectScale / Shear.
Fix displaying the normal vector.

View differences:

src/main/java/org/distorted/library/effect/MatrixEffect.java
37 37
 *
38 38
 * @y.exclude
39 39
 */
40
  public abstract void apply(float[] matrix, float[] uniforms, int index);
40
  public abstract void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index);
41 41

  
42 42
///////////////////////////////////////////////////////////////////////////////////////////////////
43 43
// empty function for completeness
src/main/java/org/distorted/library/effect/MatrixEffectMove.java
48 48
 *
49 49
 * @y.exclude
50 50
 */
51
  public void apply(float[] matrix, float[] uniforms, int index)
51
  public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index)
52 52
    {
53 53
    float sx = uniforms[NUM_UNIFORMS*index  ];
54 54
    float sy = uniforms[NUM_UNIFORMS*index+1];
55 55
    float sz = uniforms[NUM_UNIFORMS*index+2];
56 56

  
57
    Matrix.translateM(matrix, 0, sx, sy, sz);
57
    Matrix.translateM(matrixP, 0, sx, sy, sz);
58
    Matrix.translateM(matrixV, 0, sx, sy, sz);
58 59
    }
59 60

  
60 61
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/MatrixEffectQuaternion.java
54 54
 *
55 55
 * @y.exclude
56 56
 */
57
  public void apply(float[] matrix, float[] uniforms, int index)
57
  public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index)
58 58
    {
59 59
    float qX = uniforms[NUM_UNIFORMS*index  ];
60 60
    float qY = uniforms[NUM_UNIFORMS*index+1];
......
65 65
    float y = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1];
66 66
    float z = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2];
67 67

  
68
    Matrix.translateM(matrix, 0, x, y, z);
69
    multiplyByQuat( matrix, qX, qY, qZ, qW);
70
    Matrix.translateM(matrix, 0,-x,-y,-z);
68
    Matrix.translateM(matrixP, 0, x, y, z);
69
    multiplyByQuat   (matrixP, qX, qY, qZ, qW);
70
    Matrix.translateM(matrixP, 0,-x,-y,-z);
71

  
72
    Matrix.translateM(matrixV, 0, x, y, z);
73
    multiplyByQuat   (matrixV, qX, qY, qZ, qW);
74
    Matrix.translateM(matrixV, 0,-x,-y,-z);
71 75
    }
72 76

  
73 77
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/MatrixEffectRotate.java
52 52
 *
53 53
 * @y.exclude
54 54
 */
55
  public void apply(float[] matrix, float[] uniforms, int index)
55
  public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index)
56 56
    {
57 57
    float angle = uniforms[NUM_UNIFORMS*index  ];
58 58
    float axisX = uniforms[NUM_UNIFORMS*index+1];
......
63 63
    float y = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1];
64 64
    float z = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2];
65 65

  
66
    Matrix.translateM(matrix, 0, x, y, z);
67
    Matrix.rotateM( matrix, 0, angle, axisX, axisY, axisZ);
68
    Matrix.translateM(matrix, 0,-x,-y,-z);
66
    Matrix.translateM(matrixP, 0, x, y, z);
67
    Matrix.rotateM   (matrixP, 0, angle, axisX, axisY, axisZ);
68
    Matrix.translateM(matrixP, 0,-x,-y,-z);
69

  
70
    Matrix.translateM(matrixV, 0, x, y, z);
71
    Matrix.rotateM   (matrixV, 0, angle, axisX, axisY, axisZ);
72
    Matrix.translateM(matrixV, 0,-x,-y,-z);
69 73
    }
70 74

  
71 75
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/MatrixEffectScale.java
46 46
///////////////////////////////////////////////////////////////////////////////////////////////////
47 47
/**
48 48
 * Only for use by the library itself.
49
 * <p>
50
 * Here and in Shear we have the whole reason why there are two separate 'P' and 'V' (Point and
51
 * Vector) matrices - Scale and Shear have to manipulate Points and Normal Vectors differently.
52
 *
53
 * Points get multiplied by (sx,sy,sz) - and vectors by (1/sx,1/sy,1/sz) (think about it!) - or
54
 * better by sx*sy*sz*(1/sx,1/sy,1/sz) to avoid dividing my zero (vectors are normalized after)
49 55
 *
50 56
 * @y.exclude
51 57
 */
52
  public void apply(float[] matrix, float[] uniforms, int index)
58
  public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index)
53 59
    {
54 60
    float sx = uniforms[NUM_UNIFORMS*index  ];
55 61
    float sy = uniforms[NUM_UNIFORMS*index+1];
56 62
    float sz = uniforms[NUM_UNIFORMS*index+2];
57 63

  
58
    Matrix.scaleM(matrix, 0, sx, sy, sz);
64
    Matrix.scaleM(matrixP, 0, sx, sy, sz);
65
    Matrix.scaleM(matrixV, 0, sy*sz, sx*sz, sx*sy);
59 66
    }
60 67

  
61 68
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/MatrixEffectShear.java
46 46
///////////////////////////////////////////////////////////////////////////////////////////////////
47 47
/**
48 48
 * Only for use by the library itself.
49
 * <p>
50
 * Here and in Shear we have the whole reason why there are two separate 'P' and 'V' (Point and
51
 * Vector) matrices - Scale and Shear have to manipulate Points and Normal Vectors differently.
49 52
 *
50 53
 * @y.exclude
51 54
 */
52
  public void apply(float[] matrix, float[] uniforms, int index)
55
  public void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index)
53 56
    {
54 57
    float sx = uniforms[NUM_UNIFORMS*index  ];
55 58
    float sy = uniforms[NUM_UNIFORMS*index+1];
......
59 62
    float y  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1];
60 63
    float z  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2];
61 64

  
62
    Matrix.translateM(matrix, 0, x, y, z);
65
    Matrix.translateM(matrixP, 0, x, y, z);
63 66

  
64
    matrix[4] += sx*matrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
65
    matrix[5] += sx*matrix[1]; //                        0 1 0 0
66
    matrix[6] += sx*matrix[2]; //                        0 0 1 0
67
    matrix[7] += sx*matrix[3]; //                        0 0 0 1
67
    matrixP[4] += sx*matrixP[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
68
    matrixP[5] += sx*matrixP[1]; //                        0 1 0 0
69
    matrixP[6] += sx*matrixP[2]; //                        0 0 1 0
70
    matrixP[7] += sx*matrixP[3]; //                        0 0 0 1
68 71

  
69
    matrix[0] += sy*matrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear.
70
    matrix[1] += sy*matrix[5]; //                        y 1 0 0
71
    matrix[2] += sy*matrix[6]; //                        0 0 1 0
72
    matrix[3] += sy*matrix[7]; //                        0 0 0 1
72
    matrixP[0] += sy*matrixP[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear.
73
    matrixP[1] += sy*matrixP[5]; //                        y 1 0 0
74
    matrixP[2] += sy*matrixP[6]; //                        0 0 1 0
75
    matrixP[3] += sy*matrixP[7]; //                        0 0 0 1
73 76

  
74
    matrix[4] += sz*matrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear.
75
    matrix[5] += sz*matrix[9]; //                        0 1 0 0
76
    matrix[6] += sz*matrix[10];//                        0 z 1 0
77
    matrix[7] += sz*matrix[11];//                        0 0 0 1
77
    matrixP[4] += sz*matrixP[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear.
78
    matrixP[5] += sz*matrixP[9]; //                        0 1 0 0
79
    matrixP[6] += sz*matrixP[10];//                        0 z 1 0
80
    matrixP[7] += sz*matrixP[11];//                        0 0 0 1
78 81

  
79
    Matrix.translateM(matrix, 0,-x,-y,-z);
82
    Matrix.translateM(matrixP, 0,-x,-y,-z);
83

  
84
    Matrix.translateM(matrixV, 0, x, y, z);
85

  
86
    matrixV[0] -= sx*matrixV[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. vector X-shear.
87
    matrixV[1] -= sx*matrixV[5]; //                       -x 1 0 0
88
    matrixV[2] -= sx*matrixV[6]; //                        0 0 1 0
89
    matrixV[3] -= sx*matrixV[7]; //                        0 0 0 1
90

  
91
    matrixV[4] -= sy*matrixV[0]; // Multiply viewMatrix by 1-y 0 0 , i.e. vector Y-shear.
92
    matrixV[5] -= sy*matrixV[1]; //                        0 1 0 0
93
    matrixV[6] -= sy*matrixV[2]; //                        0 0 1 0
94
    matrixV[7] -= sy*matrixV[3]; //                        0 0 0 1
95

  
96
    matrixV[8] -= sz*matrixV[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. vector Z-shear.
97
    matrixV[9] -= sz*matrixV[5]; //                        0 1-z 0
98
    matrixV[10]-= sz*matrixV[6]; //                        0 0 1 0
99
    matrixV[11]-= sz*matrixV[7]; //                        0 0 0 1
100

  
101
    Matrix.translateM(matrixV, 0,-x,-y,-z);
80 102
    }
81 103

  
82 104
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effectqueue/EffectQueue.java
179 179
///////////////////////////////////////////////////////////////////////////////////////////////////
180 180

  
181 181
  public static void send(EffectQueue[] queues, float distance, float mipmap,
182
                          float[] projection, float inflate, MeshBase mesh, int variant )
182
                          float[] projection, float inflate, int variant )
183 183
    {
184
    ((EffectQueueMatrix  )queues[0]).send(distance, mipmap, projection, mesh, variant);
184
    ((EffectQueueMatrix  )queues[0]).send(distance, mipmap, projection, variant);
185 185
    ((EffectQueueVertex  )queues[1]).send(inflate, variant);
186 186
    ((EffectQueueFragment)queues[2]).send(variant);
187 187
    }
188 188

  
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

  
191
  public static float[] getMVP(EffectQueue[] queues)
192
    {
193
    return ((EffectQueueMatrix)queues[0]).getMVP();
194
    }
195

  
196 189
///////////////////////////////////////////////////////////////////////////////////////////////////
197 190
// variant: 0 --> MAIN  1 --> OIT  2 --> prePOST  3 --> FULL
198 191

  
src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
24 24

  
25 25
import org.distorted.library.effect.EffectType;
26 26
import org.distorted.library.effect.MatrixEffect;
27
import org.distorted.library.mesh.MeshBase;
28 27
import org.distorted.library.message.EffectMessageSender;
29 28

  
30 29
///////////////////////////////////////////////////////////////////////////////////////////////////
......
35 34
  private static final int INDEX = EffectType.MATRIX.ordinal();
36 35

  
37 36
  private static float[] mMVPMatrix       = new float[16];
38
  private static float[] mModelViewMatrix = new float[16];
37
  private static float[] mModelViewMatrixP= new float[16];
38
  private static float[] mModelViewMatrixV= new float[16];
39 39

  
40 40
  private static int[] mMVPMatrixH = new int[MAIN_VARIANTS];
41
  private static int[] mMVMatrixH  = new int[MAIN_VARIANTS];
41
  private static int[] mMVMatrixPH = new int[MAIN_VARIANTS];
42
  private static int[] mMVMatrixVH = new int[MAIN_VARIANTS];
42 43

  
43 44
///////////////////////////////////////////////////////////////////////////////////////////////////
44 45
   
......
59 60
  static void uniforms(int mProgramH, int variant)
60 61
    {
61 62
    mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
62
    mMVMatrixH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_MVMatrix");
63
    mMVMatrixPH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixP");
64
    mMVMatrixVH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixV");
63 65
    }
64 66

  
65 67
///////////////////////////////////////////////////////////////////////////////////////////////////
......
83 85

  
84 86
///////////////////////////////////////////////////////////////////////////////////////////////////
85 87

  
86
  float[] getMVP()
88
  void send(float distance, float mipmap, float[] projection, int variant)
87 89
    {
88
    return mMVPMatrix;
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
90
    Matrix.setIdentityM(mModelViewMatrixP, 0);
91
    Matrix.translateM(mModelViewMatrixP, 0, 0,0, -distance);
92 92

  
93
  void send(float distance, float mipmap, float[] projection, MeshBase mesh, int variant)
94
    {
95
    Matrix.setIdentityM(mModelViewMatrix, 0);
93
    if( mipmap!=1 )
94
      {
95
      Matrix.scaleM(mModelViewMatrixP, 0, mipmap, mipmap, mipmap);
96
      }
96 97

  
97
    // The 'View' part of the MV matrix
98
    Matrix.translateM(mModelViewMatrix, 0, 0,0, -distance);
99
    if( mipmap!=1 ) Matrix.scaleM(mModelViewMatrix, 0, mipmap, mipmap, mipmap);
98
    mModelViewMatrixV[ 0] = mModelViewMatrixP[ 0];
99
    mModelViewMatrixV[ 1] = mModelViewMatrixP[ 1];
100
    mModelViewMatrixV[ 2] = mModelViewMatrixP[ 2];
101
    mModelViewMatrixV[ 3] = mModelViewMatrixP[ 3];
102
    mModelViewMatrixV[ 4] = mModelViewMatrixP[ 4];
103
    mModelViewMatrixV[ 5] = mModelViewMatrixP[ 5];
104
    mModelViewMatrixV[ 6] = mModelViewMatrixP[ 6];
105
    mModelViewMatrixV[ 7] = mModelViewMatrixP[ 7];
106
    mModelViewMatrixV[ 8] = mModelViewMatrixP[ 8];
107
    mModelViewMatrixV[ 9] = mModelViewMatrixP[ 9];
108
    mModelViewMatrixV[10] = mModelViewMatrixP[10];
109
    mModelViewMatrixV[11] = mModelViewMatrixP[11];
110
    mModelViewMatrixV[12] = mModelViewMatrixP[12];
111
    mModelViewMatrixV[13] = mModelViewMatrixP[13];
112
    mModelViewMatrixV[14] = mModelViewMatrixP[14];
113
    mModelViewMatrixV[15] = mModelViewMatrixP[15];
100 114

  
101 115
    // the 'Model' part of the MV matrix
102
    for(int i=mNumEffects-1; i>=0; i--) ((MatrixEffect)mEffects[i]).apply(mModelViewMatrix,mUniforms,i);
116
    for(int i=mNumEffects-1; i>=0; i--)
117
      {
118
      ((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,mUniforms,i);
119
      }
103 120

  
104 121
    // combined Model-View-Projection matrix
105
    Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrix, 0);
122
    Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrixP, 0);
106 123

  
107
    GLES30.glUniformMatrix4fv(mMVMatrixH[variant] , 1, false, mModelViewMatrix, 0);
108
    GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix      , 0);
124
    GLES30.glUniformMatrix4fv(mMVMatrixVH[variant], 1, false, mModelViewMatrixV, 0);
125
    GLES30.glUniformMatrix4fv(mMVMatrixPH[variant], 1, false, mModelViewMatrixP, 0);
126
    GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix       , 0);
109 127
    }
110 128
  }
src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
187 187
    EffectQueueMatrix matrix = (EffectQueueMatrix)queues[0];
188 188
    EffectQueueVertex vertex = (EffectQueueVertex)queues[1];
189 189

  
190
    matrix.send(distance, mipmap, projection, mesh, 2);
190
    matrix.send(distance, mipmap, projection, 2);
191 191
    vertex.send(mHalo*0.01f,2);
192 192

  
193 193
    if( mA!=0.0f )
src/main/java/org/distorted/library/main/DistortedLibrary.java
123 123
  /// MAIN PROGRAM ///
124 124
  private static DistortedProgram mMainProgram;
125 125
  private static int mMainTextureH;
126
  private static int mTransformFeedbackH;
126 127

  
127 128
  /// NORMAL PROGRAM /////
128 129
  private static DistortedProgram mNormalProgram;
129
  private static int mNormalMVPMatrixH;
130
  private static int mNormalProjectionH;
130 131

  
131 132
  /// MAIN OIT PROGRAM ///
132 133
  private static DistortedProgram mMainOITProgram;
......
262 263
    EffectQueue.getUniforms(mainProgramH,0);
263 264
    MeshBase.getUniforms(mainProgramH,0);
264 265
    mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
266
    mTransformFeedbackH= GLES30.glGetUniformLocation( mainProgramH, "u_TransformFeedback");
265 267

  
266 268
    // BLIT PROGRAM ////////////////////////////////////
267 269
    final InputStream blitVertStream = mResources.openRawResource(R.raw.blit_vertex_shader);
......
321 323
      }
322 324

  
323 325
    int normalProgramH = mNormalProgram.getProgramHandle();
324
    mNormalMVPMatrixH  = GLES30.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
326
    mNormalProjectionH = GLES30.glGetUniformLocation( normalProgramH, "u_Projection");
325 327
    }
326 328

  
327 329
///////////////////////////////////////////////////////////////////////////////////////////////////
......
481 483

  
482 484
///////////////////////////////////////////////////////////////////////////////////////////////////
483 485

  
484
  private static void displayNormals(EffectQueue[] queues, MeshBase mesh)
486
  private static void displayNormals(float[] projection, MeshBase mesh)
485 487
    {
486 488
    if( mNormalProgram==null )
487 489
      {
......
499 501
    int num = mesh.getNumVertices();
500 502
    int tfo = mesh.getTFO();
501 503

  
504
    GLES30.glUniform1i(DistortedLibrary.mTransformFeedbackH, 1);
502 505
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo );
503 506
    GLES30.glBeginTransformFeedback( GLES30.GL_POINTS);
504 507
    InternalRenderState.switchOffDrawing();
......
508 511
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
509 512

  
510 513
    mNormalProgram.useProgram();
511
    GLES30.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, EffectQueue.getMVP(queues) , 0);
514
    GLES30.glUniformMatrix4fv(mNormalProjectionH, 1, false, projection, 0);
512 515
    mesh.bindTransformAttribs(mNormalProgram);
513 516
    GLES30.glLineWidth(8.0f);
514 517
    GLES30.glDrawArrays(GLES30.GL_LINES, 0, 2*num);
......
574 577
      float mipmap      = surface.mMipmap;
575 578
      float[] projection= surface.mProjectionMatrix;
576 579

  
577
      EffectQueue.send(queues, distance, mipmap, projection, inflate, mesh, 1 );
580
      EffectQueue.send(queues, distance, mipmap, projection, inflate, 1 );
578 581
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
579 582

  
580 583
      if( mesh.getShowNormals() )
581 584
        {
582 585
        mMainProgram.useProgram();
583 586
        mesh.send(0);
584
        EffectQueue.send(queues, distance, mipmap, projection, inflate, mesh, 0 );
585
        displayNormals(queues,mesh);
587
        EffectQueue.send(queues, distance, mipmap, projection, inflate, 0 );
588
        displayNormals(projection,mesh);
586 589
        }
587 590
      }
588 591
    }
......
608 611
      float mipmap      = surface.mMipmap;
609 612
      float[] projection= surface.mProjectionMatrix;
610 613

  
611
      EffectQueue.send(queues, distance, mipmap, projection, inflate, mesh, 0 );
614
      EffectQueue.send(queues, distance, mipmap, projection, inflate, 0 );
612 615
      GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
613 616

  
614
      if( mesh.getShowNormals() ) displayNormals(queues,mesh);
617
      if( mesh.getShowNormals() ) displayNormals(projection,mesh);
615 618
      }
616 619
    }
617 620

  
src/main/java/org/distorted/library/mesh/MeshBase.java
255 255

  
256 256
   void applyMatrix(MatrixEffect effect, int andAssoc, int equAssoc)
257 257
     {
258
     float[] matrix   = new float[16];
258
     float[] matrixP  = new float[16];
259
     float[] matrixV  = new float[16];
259 260
     float[] uniforms = new float[7];
260 261
     int start, end=-1, numComp = mEffComponent.size();
261 262

  
262
     Matrix.setIdentityM(matrix,0);
263
     Matrix.setIdentityM(matrixP,0);
264
     Matrix.setIdentityM(matrixV,0);
263 265
     effect.compute(uniforms,0,0,0);
264
     effect.apply(matrix, uniforms, 0);
266
     effect.apply(matrixP, matrixV, uniforms, 0);
265 267

  
266 268
     for(int i=0; i<numComp; i++)
267 269
       {
......
270 272

  
271 273
       if( (andAssoc & mAndAssociation[i]) != 0 || (equAssoc == mEquAssociation[i]) )
272 274
         {
273
         applyMatrixToComponent(matrix,start,end);
275
         applyMatrixToComponent(matrixP, matrixV, start, end);
274 276
         }
275 277
       }
276 278

  
......
279 281

  
280 282
///////////////////////////////////////////////////////////////////////////////////////////////////
281 283

  
282
   private void applyMatrixToComponent(float[] matrix, int start, int end)
284
   private void applyMatrixToComponent(float[] matrixP, float[] matrixV, int start, int end)
283 285
     {
284 286
     float x,y,z;
285 287

  
......
289 291
       y = mVertAttribs1[index+POS_ATTRIB+1];
290 292
       z = mVertAttribs1[index+POS_ATTRIB+2];
291 293

  
292
       mVertAttribs1[index+POS_ATTRIB  ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z + matrix[12];
293
       mVertAttribs1[index+POS_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z + matrix[13];
294
       mVertAttribs1[index+POS_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z + matrix[14];
294
       mVertAttribs1[index+POS_ATTRIB  ] = matrixP[0]*x + matrixP[4]*y + matrixP[ 8]*z + matrixP[12];
295
       mVertAttribs1[index+POS_ATTRIB+1] = matrixP[1]*x + matrixP[5]*y + matrixP[ 9]*z + matrixP[13];
296
       mVertAttribs1[index+POS_ATTRIB+2] = matrixP[2]*x + matrixP[6]*y + matrixP[10]*z + matrixP[14];
295 297

  
296 298
       x = mVertAttribs1[index+NOR_ATTRIB  ];
297 299
       y = mVertAttribs1[index+NOR_ATTRIB+1];
298 300
       z = mVertAttribs1[index+NOR_ATTRIB+2];
299 301

  
300
       mVertAttribs1[index+NOR_ATTRIB  ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z;
301
       mVertAttribs1[index+NOR_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z;
302
       mVertAttribs1[index+NOR_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z;
302
       mVertAttribs1[index+NOR_ATTRIB  ] = matrixV[0]*x + matrixV[4]*y + matrixV[ 8]*z;
303
       mVertAttribs1[index+NOR_ATTRIB+1] = matrixV[1]*x + matrixV[5]*y + matrixV[ 9]*z;
304
       mVertAttribs1[index+NOR_ATTRIB+2] = matrixV[2]*x + matrixV[6]*y + matrixV[10]*z;
305

  
306
       x = mVertAttribs1[index+NOR_ATTRIB  ];
307
       y = mVertAttribs1[index+NOR_ATTRIB+1];
308
       z = mVertAttribs1[index+NOR_ATTRIB+2];
309

  
310
       float len1 = (float)Math.sqrt(x*x + y*y + z*z);
311

  
312
       if( len1>0.0f )
313
         {
314
         mVertAttribs1[index+NOR_ATTRIB  ] /= len1;
315
         mVertAttribs1[index+NOR_ATTRIB+1] /= len1;
316
         mVertAttribs1[index+NOR_ATTRIB+2] /= len1;
317
         }
303 318

  
304 319
       x = mVertAttribs1[index+INF_ATTRIB  ];
305 320
       y = mVertAttribs1[index+INF_ATTRIB+1];
306 321
       z = mVertAttribs1[index+INF_ATTRIB+2];
307 322

  
308
       mVertAttribs1[index+INF_ATTRIB  ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z;
309
       mVertAttribs1[index+INF_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z;
310
       mVertAttribs1[index+INF_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z;
323
       mVertAttribs1[index+INF_ATTRIB  ] = matrixV[0]*x + matrixV[4]*y + matrixV[ 8]*z;
324
       mVertAttribs1[index+INF_ATTRIB+1] = matrixV[1]*x + matrixV[5]*y + matrixV[ 9]*z;
325
       mVertAttribs1[index+INF_ATTRIB+2] = matrixV[2]*x + matrixV[6]*y + matrixV[10]*z;
326

  
327
       x = mVertAttribs1[index+INF_ATTRIB  ];
328
       y = mVertAttribs1[index+INF_ATTRIB+1];
329
       z = mVertAttribs1[index+INF_ATTRIB+2];
330

  
331
       float len2 = (float)Math.sqrt(x*x + y*y + z*z);
332

  
333
       if( len2>0.0f )
334
         {
335
         mVertAttribs1[index+INF_ATTRIB  ] /= len2;
336
         mVertAttribs1[index+INF_ATTRIB+1] /= len2;
337
         mVertAttribs1[index+INF_ATTRIB+2] /= len2;
338
         }
311 339
       }
312 340
     }
313 341

  
src/main/res/raw/main_vertex_shader.glsl
40 40
out vec2 v_TexCoordinate;            //
41 41

  
42 42
uniform mat4 u_MVPMatrix;            // the combined model/view/projection matrix.
43
uniform mat4 u_MVMatrix;             // the combined model/view matrix.
43
uniform mat4 u_MVMatrixP;            // the combined model/view matrix. (for points)
44
uniform mat4 u_MVMatrixV;            // the combined model/view matrix. (for vectors)
45
                                     // which need to work differently on points and vectors
44 46
uniform float u_Inflate;             // how much should we inflate (>0.0) or deflate (<0.0) the mesh.
47
uniform int u_TransformFeedback;     // are we doing the transform feedback now?
45 48

  
46 49
#if NUM_VERTEX>0
47 50
uniform int vNumEffects;             // total number of vertex effects
......
119 122
    effect+=3;
120 123
    }
121 124
#endif
122
   
123
  v_Position      = v;
124 125

  
125 126
#ifdef PREAPPLY
126
  v_endPosition   = n;
127
  v_Inflate       = inf;
127
  v_Position   = v;
128
  v_endPosition= n;
129
  v_Inflate    = inf;
128 130
#else
129
  v_endPosition   = v + 0.5*n;
131
  if( u_TransformFeedback == 1 )
132
    {
133
    vec4 tmp1 =  u_MVMatrixP * vec4(v,1.0);
134
    vec4 tmp2 =  normalize(u_MVMatrixV * vec4(n,0.0));
135

  
136
    v_Position    = vec3(tmp1);
137
    v_endPosition = vec3(tmp1+100.0*tmp2);
138
    }
130 139
#endif
131 140

  
132 141
  v_TexCoordinate = a_TexCoordinate;
133
  v_Normal        = normalize(vec3(u_MVMatrix*vec4(n,0.0)));
142
  v_Normal        = normalize(vec3(u_MVMatrixV*vec4(n,0.0)));
134 143
  gl_Position     = u_MVPMatrix*vec4(v,1.0);
135 144
  }                               
src/main/res/raw/normal_vertex_shader.glsl
20 20
precision lowp float;
21 21

  
22 22
in vec3 a_Position;
23
uniform mat4 u_MVPMatrix;
23
uniform mat4 u_Projection;
24 24

  
25 25
//////////////////////////////////////////////////////////////////////////////////////////////
26 26

  
27 27
void main()
28 28
  {
29
  gl_Position = u_MVPMatrix * vec4(a_Position, 1.0);
29
  gl_Position = u_Projection * vec4(a_Position, 1.0);
30 30
  }

Also available in: Unified diff