Project

General

Profile

« Previous | Next » 

Revision 7a5e538a

Added by Leszek Koltunski over 5 years ago

Progress with Inflate (building block of postprocessing effects: the proper way of marking a halo around a Mesh)
'Inflate' app testing the machanism. MeshFlat appears to be working, now we only need to fill up the per-vertex Inflate vector in the MeshCubes.

View differences:

src/main/java/org/distorted/library/main/DistortedEffects.java
445 445

  
446 446
///////////////////////////////////////////////////////////////////////////////////////////////////
447 447

  
448
  void send(float halfW, float halfH, float halfZ, float margin, DistortedOutputSurface surface, int variant)
448
  void send(float halfW, float halfH, float halfZ, float inflate, DistortedOutputSurface surface, int variant)
449 449
    {
450
    mM.send(surface,halfW,halfH,halfZ,margin,variant);
451
    mV.send(variant);
450
    mM.send(surface,halfW,halfH,halfZ,variant);
451
    mV.send(inflate,variant);
452 452
    }
453 453

  
454 454
///////////////////////////////////////////////////////////////////////////////////////////////////
......
471 471

  
472 472
    mesh.bindVertexAttribs(mMainOITProgram);
473 473

  
474
    mM.send(surface,halfW,halfH,halfZ,0,1);
475
    mV.send(1);
474
    float inflate = mesh.getInflate();
475

  
476
    mM.send(surface,halfW,halfH,halfZ,1);
477
    mV.send(inflate,1);
476 478
    mF.send(1);
477 479

  
478 480
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
......
480 482
    if( mesh.getShowNormals() )
481 483
      {
482 484
      mMainProgram.useProgram();
483
      mM.send(surface,halfW,halfH,halfZ,0,0);
484
      mV.send(0);
485
      mM.send(surface,halfW,halfH,halfZ,0);
486
      mV.send(inflate,0);
485 487
      mF.send(0);
486 488
      displayNormals(mesh);
487 489
      }
......
505 507

  
506 508
    mesh.bindVertexAttribs(mMainProgram);
507 509

  
508
    mM.send(surface,halfW,halfH,halfZ,0,0);
509
    mV.send(0);
510
    mM.send(surface,halfW,halfH,halfZ,0);
511
    mV.send( mesh.getInflate(),0);
510 512
    mF.send(0);
511 513

  
512 514
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
src/main/java/org/distorted/library/main/DistortedNode.java
357 357
    }
358 358

  
359 359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
/**
361
 * Not part of the Public API.
362
 *
363
 * @y.exclude
364
 */
365
  public EffectQueuePostprocess getPostprocessQueue()
360

  
361
  EffectQueuePostprocess getPostprocessQueue()
366 362
    {
367 363
    return mEffects.getPostprocess();
368 364
    }
src/main/java/org/distorted/library/main/EffectQueueMatrix.java
36 36

  
37 37
  private static float[] mMVPMatrix = new float[16];
38 38
  private static float[] mViewMatrix= new float[16];
39
  private static float[] mTmpMatrix = new float[16];
40
  private static float[] mTmpResult = new float[4];
41
  private static float[] mTmpPoint  = new float[4];
42
  private static float mMinx;
43
  private static float mMaxx;
44
  private static float mMiny;
45
  private static float mMaxy;
46 39

  
47 40
  private static int[] mObjDH      = new int[Distorted.MAIN_VARIANTS];
48 41
  private static int[] mMVPMatrixH = new int[Distorted.MAIN_VARIANTS];
......
55 48
    super(id,NUM_UNIFORMS,INDEX );
56 49
    }
57 50

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

  
60
  private void magnifyDir()
61
    {
62
    Matrix.multiplyMV(mTmpResult,0,mTmpMatrix,0,mTmpPoint,0);
63
    float nx = mTmpResult[0]/mTmpResult[3];
64
    float ny = mTmpResult[1]/mTmpResult[3];
65

  
66
    if( nx<mMinx ) mMinx = nx;
67
    if( nx>mMaxx ) mMaxx = nx;
68
    if( ny<mMiny ) mMiny = ny;
69
    if( ny>mMaxy ) mMaxy = ny;
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
// modify the ModelView matrix so that the object drawn appears to be (about) 'marginInPixels' pixels
74
// larger in each direction when rendered. Used in Postprocessing.
75

  
76
  private void magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
77
    {
78
    mMinx = Integer.MAX_VALUE;
79
    mMaxx = Integer.MIN_VALUE;
80
    mMiny = Integer.MAX_VALUE;
81
    mMaxy = Integer.MIN_VALUE;
82

  
83
    mTmpPoint[3] = 1.0f;
84

  
85
    Matrix.multiplyMM(mTmpMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
86

  
87
    mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir();
88
    mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir();
89
    mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir();
90
    mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir();
91
    mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir();
92
    mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir();
93
    mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir();
94
    mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir();
95

  
96
    float xlen = projection.mWidth *(mMaxx-mMinx)/2;
97
    float ylen = projection.mHeight*(mMaxy-mMiny)/2;
98
    float scale = 1.0f + 2*marginInPixels/( xlen>ylen ? ylen:xlen );
99

  
100
    Matrix.scaleM(mViewMatrix, 0, scale, scale, scale);
101
    }
102

  
103 51
///////////////////////////////////////////////////////////////////////////////////////////////////
104 52

  
105 53
  static void getUniforms(int mProgramH, int variant)
......
146 94

  
147 95
///////////////////////////////////////////////////////////////////////////////////////////////////
148 96

  
149
  void send(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels, int variant)
97
  void send(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, int variant)
150 98
    {
151 99
    Matrix.setIdentityM(mViewMatrix, 0);
152 100
    Matrix.translateM(mViewMatrix, 0, -projection.mWidth/2, projection.mHeight/2, -projection.mDistance);
......
156 104
    for(int i=0; i<mNumEffects; i++) ((MatrixEffect)mEffects[i]).apply(mViewMatrix,mUniforms,i);
157 105

  
158 106
    Matrix.translateM(mViewMatrix, 0, halfX,-halfY,-halfZ);
159
    if( marginInPixels!=0 ) magnify(projection,halfX,halfY,halfZ, marginInPixels);
160 107
    Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
161 108

  
162 109
    GLES31.glUniform3f( mObjDH[variant] , halfX, halfY, halfZ);
src/main/java/org/distorted/library/main/EffectQueuePostprocess.java
159 159
    if( input.setAsInput() )
160 160
      {
161 161
      MeshBase mesh = node.getMesh();
162
      float    margin = mHalo*buffer.mMipmap;
163 162

  
164 163
      float halfW = input.getWidth() / 2.0f;
165 164
      float halfH = input.getHeight()/ 2.0f;
......
173 172

  
174 173
      mesh.bindVertexAttribs(mPreProgram);
175 174

  
176
      node.getEffects().send(halfW, halfH, halfZ, margin, buffer, 2);
175
      node.getEffects().send(halfW, halfH, halfZ, mHalo, buffer, 2);
177 176

  
178 177
      if( mA!=0.0f )
179 178
        {
src/main/java/org/distorted/library/main/EffectQueueVertex.java
36 36
  private static int[] mNumEffectsH = new int[Distorted.MAIN_VARIANTS];
37 37
  private static int[] mNameH       = new int[Distorted.MAIN_VARIANTS];
38 38
  private static int[] mUniformsH   = new int[Distorted.MAIN_VARIANTS];
39
  private static int[] mInflateH    = new int[Distorted.MAIN_VARIANTS];
39 40

  
40 41
///////////////////////////////////////////////////////////////////////////////////////////////////
41 42
   
......
51 52
    mNumEffectsH[variant]= GLES31.glGetUniformLocation( mProgramH, "vNumEffects");
52 53
    mNameH[variant]      = GLES31.glGetUniformLocation( mProgramH, "vName");
53 54
    mUniformsH[variant]  = GLES31.glGetUniformLocation( mProgramH, "vUniforms");
55
    mInflateH[variant]   = GLES31.glGetUniformLocation( mProgramH, "u_Inflate");
54 56
    }
55 57

  
56 58
///////////////////////////////////////////////////////////////////////////////////////////////////
......
88 90

  
89 91
///////////////////////////////////////////////////////////////////////////////////////////////////
90 92

  
91
  void send(int variant)
93
  void send(float inflate, int variant)
92 94
    {
93 95
    GLES31.glUniform1i( mNumEffectsH[variant], mNumEffects);
94
      
96
    GLES31.glUniform1f( mInflateH[variant]   , inflate    );
97

  
95 98
    if( mNumEffects>0 )
96 99
      {
97 100
      GLES31.glUniform1iv( mNameH[variant]    ,                 mNumEffects, mName    ,0);
src/main/java/org/distorted/library/mesh/MeshBase.java
34 34
 * Abstract class which represents a Mesh, i.e. an array of vertices (rendered as a TRIANGLE_STRIP)
35 35
 * <p>
36 36
 * If you want to render to a particular shape, extend from here, construct a float array
37
 * containing per-vertex attributes, and call back setData().
37
 * containing per-vertex attributes, and call back setAttribs().
38 38
 */
39 39
public abstract class MeshBase
40 40
   {
......
42 42
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
43 43
   private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
44 44
   private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z
45
   private static final int TEX_DATA_SIZE= 2; // texture coordinates
45
   private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t
46 46

  
47 47
   static final int POS_ATTRIB   = 0;
48 48
   static final int NOR_ATTRIB   = POS_DATA_SIZE;
......
66 66
                                       // of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
67 67
   private int mNumVertices;
68 68
   private FloatBuffer mVertAttribs;   // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ, TexS,TexT
69
   private float mInflate;
69 70

  
70 71
///////////////////////////////////////////////////////////////////////////////////////////////////
71 72

  
......
154 155
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
155 156
     }
156 157

  
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
/**
160
 * Not part of public API, do not document (public only because has to be used from the main package)
161
 *
162
 * @y.exclude
163
 */
164
   public void setInflate(float inflate)
165
     {
166
     mInflate = inflate;
167
     }
168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170
/**
171
 * Not part of public API, do not document (public only because has to be used from the main package)
172
 *
173
 * @y.exclude
174
 */
175
   public float getInflate()
176
     {
177
     return mInflate;
178
     }
179

  
157 180
///////////////////////////////////////////////////////////////////////////////////////////////////
158 181
// PUBLIC API
159 182
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/mesh/MeshFlat.java
64 64

  
65 65
     attribs[VERT_ATTRIBS*vertex + POS_ATTRIB  ] = x-0.5f;
66 66
     attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f-y;
67
     attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0;
67
     attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.0f;
68 68

  
69 69
     attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB  ] = 0.0f;
70 70
     attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
71 71
     attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
72 72

  
73
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB  ] = 1.0f;  //
74
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = 0.0f;  // TODO
75
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.0f;  //
73
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB  ] = x-0.5f;
74
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = 0.5f-y;
75
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.0f;
76 76

  
77 77
     attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB  ] = x;
78 78
     attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f-y;
src/main/res/raw/main_vertex_shader.glsl
36 36

  
37 37
uniform mat4 u_MVPMatrix;            // the combined model/view/projection matrix.
38 38
uniform mat4 u_MVMatrix;             // the combined model/view matrix.
39
uniform float u_Inflate;             // how much should we inflate (>0.0) or deflate (<0.0) the mesh.
39 40

  
40 41
#if NUM_VERTEX>0
41 42
uniform int vNumEffects;             // total number of vertex effects
......
144 145

  
145 146
void main()
146 147
  {
147
  vec3 v = 2.0*u_objD*a_Position;
148
  vec3 v = 2.0*u_objD*(a_Position + u_Inflate*a_Inflate);
148 149
  vec3 n = a_Normal;
149 150

  
150 151
#if NUM_VERTEX>0

Also available in: Unified diff