Project

General

Profile

« Previous | Next » 

Revision 277eddbb

Added by Leszek Koltunski over 4 years ago

Remove the MeshBase.{set/get}Stretch API altogether.

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
37 37
  private static float[] mMVPMatrix       = new float[16];
38 38
  private static float[] mModelViewMatrix = new float[16];
39 39

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

  
......
52 51

  
53 52
  static void uniforms(int mProgramH, int variant)
54 53
    {
55
    mStretchH[variant]  = GLES30.glGetUniformLocation(mProgramH, "u_Stretch");
56 54
    mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix");
57 55
    mMVMatrixH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_MVMatrix");
58 56
    }
......
101 99
    // combined Model-View-Projection matrix
102 100
    Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrix, 0);
103 101

  
104
    GLES30.glUniform3f( mStretchH[variant]  , mesh.getStretchX() , mesh.getStretchY() , mesh.getStretchZ() );
105 102
    GLES30.glUniformMatrix4fv(mMVMatrixH[variant] , 1, false, mModelViewMatrix, 0);
106 103
    GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix      , 0);
107 104
    }
src/main/java/org/distorted/library/mesh/MeshBase.java
514 514
     {
515 515
     return (component>=0 && component<mComponent.size()) ? mComponent.get(component).mTextureMap : null;
516 516
     }
517

  
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519
/**
520
 * Sometimes we want to display a Mesh on a rectangular screen. Then we need to stretch it by
521
 * different factors in x and y (or z) directions. If we also wanted do display some vertex effects
522
 * done on this mesh, let's say a bulge done by a Distort effect, and wanted the bulge to be round,
523
 * (i.e the same in x and y directions) then doing so without this method would be impossible.
524
 *
525
 * This sets 'stretch' factors in each 3 dimensions. All vertices of this Mesh will be premultiplied
526
 * by those factors in the very first line of the Vertex Shader, before any Effects are done on it.
527
 * Using this we can thus pre-stretch the mesh to aspect ratio equal to the surface we eventually
528
 * want to display the Mesh on, and this way we can achieve a round Distort bulge!
529
 *
530
 * This could also be used to pre-stretch a Rectangles Mesh to a size equal (in pixels) to the bitmap
531
 * this mesh is textured with - and this lets us work with all Effects in natural, pixel units.
532
 *
533
 * @param sx stretch factor in x.
534
 * @param sy stretch factor in y.
535
 * @param sz stretch factor in z.
536
 */
537
   public void setStretch(float sx, float sy, float sz)
538
     {
539
     mStretchX = sx;
540
     mStretchY = sy;
541
     mStretchZ = sz;
542
     }
543

  
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545
/**
546
 * Returns the x-factor set by setStretch().
547
 */
548
   public float getStretchX()
549
     {
550
     return mStretchX;
551
     }
552

  
553
///////////////////////////////////////////////////////////////////////////////////////////////////
554
/**
555
 * Returns the y-factor set by setStretch().
556
 */
557
   public float getStretchY()
558
     {
559
     return mStretchY;
560
     }
561

  
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563
/**
564
 * Returns the z-factor set by setStretch().
565
 */
566
   public float getStretchZ()
567
     {
568
     return mStretchZ;
569
     }
570 517
   }
571 518

  
572 519

  
src/main/res/raw/main_vertex_shader.glsl
31 31
out vec3 v_Normal;                   //
32 32
out vec2 v_TexCoordinate;            //
33 33

  
34
uniform vec3 u_Stretch;              // MeshBase.mStretch{X,Y,Z}
35 34
uniform mat4 u_MVPMatrix;            // the combined model/view/projection matrix.
36 35
uniform mat4 u_MVMatrix;             // the combined model/view matrix.
37 36
uniform float u_Inflate;             // how much should we inflate (>0.0) or deflate (<0.0) the mesh.
......
93 92

  
94 93
void main()
95 94
  {
96
  vec3 v = u_Stretch*a_Position;
95
  vec3 v = a_Position + u_Inflate*a_Inflate;
97 96
  vec3 n = a_Normal;
98 97

  
99
  v += u_Inflate*u_Stretch*a_Inflate;
100

  
101 98
#if NUM_VERTEX>0
102 99
  int effect=0;
103 100

  
......
110 107
#endif
111 108
   
112 109
  v_Position      = v;
113
  v_endPosition   = v + (0.2*u_Stretch.x)*n;
110
  v_endPosition   = v + 0.4*n;
114 111
  v_TexCoordinate = a_TexCoordinate;
115 112
  v_Normal        = normalize(vec3(u_MVMatrix*vec4(n,0.0)));
116 113
  gl_Position     = u_MVPMatrix*vec4(v,1.0);

Also available in: Unified diff