Project

General

Profile

« Previous | Next » 

Revision bfe2c61b

Added by Leszek Koltunski almost 8 years ago

Blurred image visible now!

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
159 159
      GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
160 160
      mBufferFBO.setAsInput();
161 161
      df.setAsOutput();
162
      mP.send(halfInputW,halfInputH);
162
      mP.send(df,halfInputW,halfInputH);
163 163

  
164 164
      GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
165 165
      GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mQuadTexture);
......
176 176
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
177 177
    EffectQueueVertex.sendZero();
178 178
    EffectQueueFragment.sendZero();
179
    EffectQueuePostprocess.sendZero(2*halfInputW,2*halfInputH);
179
    EffectQueuePostprocess.sendZero(df,2*halfInputW,2*halfInputH);
180 180

  
181 181
    mesh.draw();
182 182
    }
src/main/java/org/distorted/library/EffectQueuePostprocess.java
20 20
package org.distorted.library;
21 21

  
22 22
import android.opengl.GLES20;
23
import android.opengl.Matrix;
23 24

  
24 25
import org.distorted.library.message.EffectMessage;
25 26
import org.distorted.library.type.Data1D;
......
41 42
  private static int mTypeH;
42 43
  private static int mUniformsH;
43 44
  private static int mObjDH;
45
  private static int mMVPMatrixH;
46

  
47
  private static float[] mMVPMatrix = new float[16];
48
  private static float[] mTmpMatrix = new float[16];
44 49

  
45 50
///////////////////////////////////////////////////////////////////////////////////////////////////
46 51

  
......
57 62
    mTypeH      = GLES20.glGetUniformLocation( mProgramH, "pType");
58 63
    mUniformsH  = GLES20.glGetUniformLocation( mProgramH, "pUniforms");
59 64
    mObjDH      = GLES20.glGetUniformLocation( mProgramH, "u_objD");
65
    mMVPMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix");
60 66
    }
61 67

  
62 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
109 115

  
110 116
///////////////////////////////////////////////////////////////////////////////////////////////////
111 117

  
112
  synchronized void send(float halfX, float halfY)
118
  synchronized void send(DistortedFramebuffer df, float halfX, float halfY)
113 119
    {
120
    Matrix.setIdentityM(mTmpMatrix, 0);
121
    Matrix.translateM(mTmpMatrix, 0, halfX-df.mWidth/2, df.mHeight/2-halfY, -df.mDistance);
122
    Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
123

  
114 124
    GLES20.glUniform1i( mNumEffectsH, mNumEffects);
115 125
    GLES20.glUniform2f( mObjDH , halfX, halfY);
126
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
116 127

  
117 128
    if( mNumEffects>0 )
118 129
      {
......
123 134

  
124 135
///////////////////////////////////////////////////////////////////////////////////////////////////
125 136

  
126
  synchronized static void sendZero(float halfX, float halfY)
137
  synchronized static void sendZero(DistortedFramebuffer df, float halfX, float halfY)
127 138
    {
139
    Matrix.setIdentityM(mTmpMatrix, 0);
140
    Matrix.translateM(mTmpMatrix, 0, halfX-df.mWidth/2, df.mHeight/2-halfY, -df.mDistance);
141
    Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
142

  
128 143
    GLES20.glUniform1i( mNumEffectsH, 0);
129 144
    GLES20.glUniform2f( mObjDH , halfX, halfY);
145
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
130 146
    }
131 147

  
132 148
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/raw/main_vertex_shader.glsl
25 25
                                     // .far = f, .diff = f-n so maybe u_Depth is redundant
26 26
                                     // Update: this struct is only available in fragment shaders
27 27
                                
28
uniform mat4 u_MVPMatrix;            // A constant representing the combined model/view/projection matrix.
29
uniform mat4 u_MVMatrix;             // A constant representing the combined model/view matrix.
28
uniform mat4 u_MVPMatrix;            // the combined model/view/projection matrix.
29
uniform mat4 u_MVMatrix;             // the combined model/view matrix.
30 30
		 
31
attribute vec3 a_Position;           // Per-vertex position information we will pass in.
32
attribute vec3 a_Normal;             // Per-vertex normal information we will pass in.
33
attribute vec2 a_TexCoordinate;      // Per-vertex texture coordinate information we will pass in.
31
attribute vec3 a_Position;           // Per-vertex position.
32
attribute vec3 a_Normal;             // Per-vertex normal vector.
33
attribute vec2 a_TexCoordinate;      // Per-vertex texture coordinate.
34 34
		  
35 35
varying vec3 v_Position;             //
36 36
varying vec3 v_Normal;               //
src/main/res/raw/post_vertex_shader.glsl
19 19

  
20 20
uniform vec2 u_objD;             // half of object width x half of object height.
21 21
                                 // point (0,0) is the center of the object
22
uniform mat4 u_MVPMatrix;        // the combined model/view/projection matrix.
22 23

  
23 24
attribute vec2 a_Position;       // Per-vertex position information we will pass in.
24 25
attribute vec2 a_TexCoordinate;  // Per-vertex texture coordinate information we will pass in.
......
30 31
void main()
31 32
  {
32 33
  v_TexCoordinate = a_TexCoordinate;
33
  gl_Position = vec4( 2.0*u_objD*a_Position, 0.0, 1.0);
34
  gl_Position     = u_MVPMatrix*vec4( 2.0*u_objD*a_Position, 0.0, 1.0);
34 35
  }

Also available in: Unified diff