Revision c2c08950
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedEffects.java | ||
---|---|---|
72 | 72 |
/// BLIT PROGRAM /// |
73 | 73 |
private static DistortedProgram mBlitProgram; |
74 | 74 |
private static int mBlitTextureH; |
75 |
private static int mBlitObjDH; |
|
76 |
private static int mBlitMVPMatrixH; |
|
75 |
private static int mBlitDepthH; |
|
77 | 76 |
private static final FloatBuffer mQuadPositions; |
78 | 77 |
|
79 | 78 |
static |
... | ... | |
166 | 165 |
|
167 | 166 |
int blitProgramH = mBlitProgram.getProgramHandle(); |
168 | 167 |
mBlitTextureH = GLES30.glGetUniformLocation( blitProgramH, "u_Texture"); |
169 |
mBlitObjDH = GLES30.glGetUniformLocation( blitProgramH, "u_objD"); |
|
170 |
mBlitMVPMatrixH= GLES30.glGetUniformLocation( blitProgramH, "u_MVPMatrix"); |
|
168 |
mBlitDepthH = GLES30.glGetUniformLocation( blitProgramH, "u_Depth"); |
|
171 | 169 |
|
172 | 170 |
// DEBUG ONLY ////////////////////////////////////// |
173 | 171 |
final InputStream debugVertexStream = resources.openRawResource(R.raw.test_vertex_shader); |
... | ... | |
349 | 347 |
|
350 | 348 |
static void blitPriv(DistortedOutputSurface projection) |
351 | 349 |
{ |
352 |
GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight); |
|
353 |
|
|
354 | 350 |
mBlitProgram.useProgram(); |
355 | 351 |
|
356 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
357 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -projection.mDistance); |
|
358 |
Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mTmpMatrix, 0); |
|
359 |
|
|
352 |
GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight); |
|
360 | 353 |
GLES30.glUniform1i(mBlitTextureH, 0); |
361 |
GLES30.glUniform2f( mBlitObjDH , projection.mWidth/2, projection.mHeight/2); |
|
362 |
GLES30.glUniformMatrix4fv(mBlitMVPMatrixH, 1, false, mMVPMatrix, 0); |
|
354 |
GLES30.glUniform1f( mBlitDepthH , 1.0f-projection.mNear); |
|
363 | 355 |
GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
364 | 356 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
365 | 357 |
} |
src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
---|---|---|
32 | 32 |
private ArrayList<DistortedNode> mChildren; |
33 | 33 |
private int mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added |
34 | 34 |
|
35 |
private float mNear, mFOV;
|
|
35 |
private float mFOV; |
|
36 | 36 |
int mWidth,mHeight,mDepth; |
37 |
float mDistance; |
|
37 |
float mDistance, mNear;
|
|
38 | 38 |
float[] mProjectionMatrix; |
39 | 39 |
|
40 | 40 |
int mDepthCreated; |
... | ... | |
71 | 71 |
if( mFOV>0.0f ) // perspective projection |
72 | 72 |
{ |
73 | 73 |
float a = 2.0f*(float)Math.tan(mFOV*Math.PI/360); |
74 |
float q = (float)mWidth/mHeight;
|
|
74 |
float q = mWidth*mNear;
|
|
75 | 75 |
float c = mHeight*mNear; |
76 | 76 |
|
77 |
float left = -q*c/2;
|
|
78 |
float right = +q*c/2;
|
|
79 |
float bottom = -c/2;
|
|
80 |
float top = +c/2;
|
|
81 |
float near = c/a;
|
|
77 |
float left = -q/2; |
|
78 |
float right = +q/2; |
|
79 |
float bottom = -c/2; |
|
80 |
float top = +c/2; |
|
81 |
float near = c/a; |
|
82 | 82 |
|
83 | 83 |
mDistance = mHeight/a; |
84 | 84 |
float far = 2*mDistance-near; |
src/main/java/org/distorted/library/EffectQueueFragment.java | ||
---|---|---|
132 | 132 |
} |
133 | 133 |
} |
134 | 134 |
|
135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
|
137 |
synchronized static void sendZero() |
|
138 |
{ |
|
139 |
GLES30.glUniform1i( mNumEffectsH, 0); |
|
140 |
} |
|
141 |
|
|
142 | 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
143 | 136 |
// alpha, brightness, contrast, saturation |
144 | 137 |
|
src/main/java/org/distorted/library/EffectQueueMatrix.java | ||
---|---|---|
294 | 294 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
295 | 295 |
} |
296 | 296 |
|
297 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
298 |
// here construct the ModelView Matrix, but without any effects |
|
299 |
|
|
300 |
synchronized static void sendZero(DistortedOutputSurface projection, float halfX, float halfY, float halfZ) |
|
301 |
{ |
|
302 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
303 |
Matrix.translateM(mTmpMatrix, 0, halfX-projection.mWidth/2, projection.mHeight/2-halfY, -projection.mDistance); |
|
304 |
Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mTmpMatrix, 0); |
|
305 |
|
|
306 |
GLES30.glUniform3f( mObjDH , halfX, halfY, halfZ); |
|
307 |
GLES30.glUniform1f( mDepthH, projection.mDepth); |
|
308 |
GLES30.glUniformMatrix4fv(mMVMatrixH , 1, false, mTmpMatrix, 0); |
|
309 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0); |
|
310 |
} |
|
311 |
|
|
312 | 297 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
313 | 298 |
// move, scale |
314 | 299 |
|
src/main/java/org/distorted/library/EffectQueueVertex.java | ||
---|---|---|
151 | 151 |
} |
152 | 152 |
} |
153 | 153 |
|
154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 |
|
|
156 |
synchronized static void sendZero() |
|
157 |
{ |
|
158 |
GLES30.glUniform1i( mNumEffectsH, 0); |
|
159 |
} |
|
160 |
|
|
161 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
162 | 155 |
// Do various post-processing on already computed effects. |
163 | 156 |
// 1) here unlike in the fragment queue, we don't have to multiply the points by ModelView matrix because that gets done in the shader. |
src/main/res/raw/blit_vertex_shader.glsl | ||
---|---|---|
19 | 19 |
|
20 | 20 |
precision lowp float; |
21 | 21 |
|
22 |
uniform vec2 u_objD; // half of object width x half of object height |
|
23 |
uniform mat4 u_MVPMatrix; // the combined model/view/projection matrix. |
|
22 |
uniform float u_Depth; // distance from the near plane to render plane, in clip coords |
|
24 | 23 |
attribute vec2 a_Position; // Per-vertex position. |
25 | 24 |
varying vec2 v_TexCoordinate; // |
26 | 25 |
|
... | ... | |
29 | 28 |
void main() |
30 | 29 |
{ |
31 | 30 |
v_TexCoordinate = a_Position + 0.5; |
32 |
//gl_Position = vec4(2.0*a_Position,0.0,1.0); |
|
33 |
gl_Position = u_MVPMatrix*vec4(2.0*u_objD*a_Position,0.0,1.0); |
|
34 |
} |
|
31 |
gl_Position = vec4(2.0*a_Position,u_Depth,1.0); |
|
32 |
} |
Also available in: Unified diff
simplify blitPriv()