Revision 2b942cd0
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/DistortedEffects.java | ||
---|---|---|
146 | 146 |
} |
147 | 147 |
else |
148 | 148 |
{ |
149 |
mBufferFBO.resizeFast(df.mWidth, df.mHeight); |
|
150 |
mBufferFBO.setAsOutput(); |
|
151 |
|
|
152 |
mM.send(mBufferFBO,halfInputW,halfInputH,halfZ); |
|
153 |
mV.send(halfInputW,halfInputH,halfZ); |
|
154 |
mF.send(halfInputW,halfInputH); |
|
155 |
|
|
156 |
mesh.draw(); |
|
157 |
|
|
158 |
GLES20.glUseProgram(Distorted.postProgramH); |
|
159 |
GLES20.glViewport(0, 0, df.mWidth, df.mHeight); |
|
160 |
mBufferFBO.setAsInput(); |
|
161 |
df.setAsOutput(); |
|
162 |
mP.send(df,halfInputW,halfInputH); |
|
163 |
|
|
164 |
GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions); |
|
165 |
GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mQuadTexture); |
|
166 |
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); |
|
149 |
if( mV.mNumEffects>0 || mP.mNumEffects>0 ) |
|
150 |
{ |
|
151 |
mBufferFBO.resizeFast(df.mWidth, df.mHeight); |
|
152 |
mBufferFBO.setAsOutput(); |
|
153 |
|
|
154 |
mM.send(mBufferFBO,halfInputW,halfInputH,halfZ); |
|
155 |
mV.send(halfInputW,halfInputH,halfZ); |
|
156 |
mF.send(halfInputW,halfInputH); |
|
157 |
|
|
158 |
mesh.draw(); |
|
159 |
|
|
160 |
GLES20.glUseProgram(Distorted.postProgramH); |
|
161 |
GLES20.glViewport(0, 0, df.mWidth, df.mHeight); |
|
162 |
mBufferFBO.setAsInput(); |
|
163 |
df.setAsOutput(); |
|
164 |
mP.send(df); |
|
165 |
|
|
166 |
GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions); |
|
167 |
GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mQuadTexture); |
|
168 |
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); |
|
169 |
} |
|
170 |
else |
|
171 |
{ |
|
172 |
GLES20.glUseProgram(Distorted.postProgramH); |
|
173 |
GLES20.glViewport(0, 0, df.mWidth, df.mHeight); |
|
174 |
mP.send(df); |
|
175 |
|
|
176 |
GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions); |
|
177 |
GLES20.glVertexAttribPointer(Distorted.mPostProgramAttributes[1], TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mQuadTexture); |
|
178 |
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); |
|
179 |
} |
|
167 | 180 |
} |
168 | 181 |
} |
169 | 182 |
|
... | ... | |
176 | 189 |
EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor); |
177 | 190 |
EffectQueueVertex.sendZero(); |
178 | 191 |
EffectQueueFragment.sendZero(); |
179 |
EffectQueuePostprocess.sendZero(df,2*halfInputW,2*halfInputH);
|
|
192 |
EffectQueuePostprocess.sendZero(df); |
|
180 | 193 |
|
181 | 194 |
mesh.draw(); |
182 | 195 |
} |
src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
---|---|---|
115 | 115 |
|
116 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
117 | 117 |
|
118 |
synchronized void send(DistortedFramebuffer df, float halfX, float halfY)
|
|
118 |
synchronized void send(DistortedFramebuffer df) |
|
119 | 119 |
{ |
120 | 120 |
Matrix.setIdentityM(mTmpMatrix, 0); |
121 |
Matrix.translateM(mTmpMatrix, 0, halfX-df.mWidth/2, df.mHeight/2-halfY, -df.mDistance);
|
|
121 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
|
|
122 | 122 |
Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0); |
123 | 123 |
|
124 | 124 |
GLES20.glUniform1i( mNumEffectsH, mNumEffects); |
125 |
GLES20.glUniform2f( mObjDH , halfX, halfY);
|
|
125 |
GLES20.glUniform2f( mObjDH , df.mWidth, df.mHeight);
|
|
126 | 126 |
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
127 | 127 |
|
128 | 128 |
if( mNumEffects>0 ) |
... | ... | |
134 | 134 |
|
135 | 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
136 | 136 |
|
137 |
synchronized static void sendZero(DistortedFramebuffer df, float halfX, float halfY)
|
|
137 |
synchronized static void sendZero(DistortedFramebuffer df) |
|
138 | 138 |
{ |
139 | 139 |
Matrix.setIdentityM(mTmpMatrix, 0); |
140 |
Matrix.translateM(mTmpMatrix, 0, halfX-df.mWidth/2, df.mHeight/2-halfY, -df.mDistance);
|
|
140 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
|
|
141 | 141 |
Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0); |
142 | 142 |
|
143 | 143 |
GLES20.glUniform1i( mNumEffectsH, 0); |
144 |
GLES20.glUniform2f( mObjDH , halfX, halfY);
|
|
144 |
GLES20.glUniform2f( mObjDH , df.mWidth, df.mHeight);
|
|
145 | 145 |
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
146 | 146 |
} |
147 | 147 |
|
src/main/res/raw/post_vertex_shader.glsl | ||
---|---|---|
17 | 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
18 | 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
19 | 19 |
|
20 |
uniform vec2 u_objD; // half of object width x half of object height.
|
|
20 |
uniform vec2 u_objD; // object width X object height.
|
|
21 | 21 |
// point (0,0) is the center of the object |
22 | 22 |
uniform mat4 u_MVPMatrix; // the combined model/view/projection matrix. |
23 | 23 |
|
... | ... | |
31 | 31 |
void main() |
32 | 32 |
{ |
33 | 33 |
v_TexCoordinate = a_TexCoordinate; |
34 |
gl_Position = u_MVPMatrix*vec4( 2.0*u_objD*a_Position, 0.0, 1.0);
|
|
34 |
gl_Position = u_MVPMatrix*vec4( u_objD*a_Position, 0.0, 1.0); |
|
35 | 35 |
} |
Also available in: Unified diff
Naive implementation of blur works now!