Revision 95c441a2
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedEffects.java | ||
---|---|---|
230 | 230 |
// DEBUG ONLY |
231 | 231 |
|
232 | 232 |
@SuppressWarnings("unused") |
233 |
private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedOutputSurface surface, float[] mvp, float[] vertices) |
|
233 |
private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedOutputSurface surface, float[] mvp, float[] vertices, long currTime)
|
|
234 | 234 |
{ |
235 | 235 |
int len = vertices.length/3; |
236 | 236 |
int minx = Integer.MAX_VALUE; |
... | ... | |
264 | 264 |
} |
265 | 265 |
|
266 | 266 |
mDebugProgram.useProgram(); |
267 |
surface.setAsOutput(); |
|
267 |
surface.setAsOutput(currTime);
|
|
268 | 268 |
|
269 | 269 |
Matrix.setIdentityM( mTmpMatrix, 0); |
270 | 270 |
Matrix.translateM ( mTmpMatrix, 0, minx-surface.mWidth/2, maxy-surface.mHeight/2, -surface.mDistance); |
... | ... | |
286 | 286 |
return mP.mNumEffects==0 ? null : mP.mMainBuffer; |
287 | 287 |
} |
288 | 288 |
|
289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
290 |
|
|
291 |
int postprocessPriv(long currTime, DistortedOutputSurface surface) |
|
292 |
{ |
|
293 |
return mP.postprocess(currTime,surface); |
|
294 |
} |
|
295 |
|
|
289 | 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
290 | 297 |
|
291 | 298 |
void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime) |
... | ... | |
293 | 300 |
mM.compute(currTime); |
294 | 301 |
mV.compute(currTime); |
295 | 302 |
mF.compute(currTime); |
296 |
mP.compute(currTime); |
|
297 | 303 |
|
298 | 304 |
float halfZ = halfW*mesh.zFactor; |
299 | 305 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight); |
300 | 306 |
|
301 | 307 |
mMainProgram.useProgram(); |
302 | 308 |
GLES30.glUniform1i(mMainTextureH, 0); |
303 |
surface.setAsOutput(); |
|
309 |
surface.setAsOutput(currTime);
|
|
304 | 310 |
mM.send(surface,halfW,halfH,halfZ); |
305 | 311 |
mV.send(halfW,halfH,halfZ); |
306 | 312 |
mF.send(halfW,halfH); |
src/main/java/org/distorted/library/DistortedNode.java | ||
---|---|---|
211 | 211 |
return 0; |
212 | 212 |
} |
213 | 213 |
|
214 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
215 |
|
|
216 |
int postprocess(long currTime, DistortedOutputSurface surface) |
|
217 |
{ |
|
218 |
return mEffects.postprocessPriv(currTime,surface); |
|
219 |
} |
|
220 |
|
|
214 | 221 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
215 | 222 |
|
216 | 223 |
DistortedFramebuffer getPostprocessingBuffer() |
... | ... | |
234 | 241 |
numRenders += mChildren.get(i).renderRecursive(currTime); |
235 | 242 |
} |
236 | 243 |
|
237 |
mData.mFBO.setAsOutput(); |
|
238 |
|
|
239 |
DistortedRenderState.colorDepthOn(); |
|
240 |
|
|
241 |
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
|
242 |
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT); |
|
244 |
mData.mFBO.setAsOutput(currTime); |
|
243 | 245 |
|
244 | 246 |
if( mSurface.setAsInput() ) |
245 | 247 |
{ |
src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
---|---|---|
30 | 30 |
private ArrayList<DistortedNode> mChildren; |
31 | 31 |
private int mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added |
32 | 32 |
|
33 |
private long mTime; |
|
33 | 34 |
private float mFOV; |
34 | 35 |
int mWidth,mHeight,mDepth; |
35 | 36 |
float mDistance, mNear; |
... | ... | |
61 | 62 |
mFBOH[0] = fbo; |
62 | 63 |
mDepthH[0] = 0; |
63 | 64 |
|
65 |
mTime = 0; |
|
66 |
|
|
64 | 67 |
createProjection(); |
65 | 68 |
} |
66 | 69 |
|
... | ... | |
111 | 114 |
int numRenders = 0; |
112 | 115 |
DistortedNode child; |
113 | 116 |
DistortedFramebuffer fbo; |
114 |
DistortedOutputSurface buffer;
|
|
117 |
DistortedOutputSurface surface;
|
|
115 | 118 |
|
116 | 119 |
// 1. Render all children that have postprocessing effects to their own buffer FBOs |
117 | 120 |
|
... | ... | |
130 | 133 |
// 2. If we have rendered anything so far, and we are a Screen, then render to an |
131 | 134 |
// intermediate FBO instead. |
132 | 135 |
|
133 |
buffer = numRenders>0 ? getBuffer() : this;
|
|
136 |
surface = this;//numRenders>0 ? getBuffer() : this;
|
|
134 | 137 |
|
135 | 138 |
// 3. Render all children without postprocessing effects to buffer |
136 | 139 |
|
... | ... | |
141 | 144 |
|
142 | 145 |
if( fbo==null ) |
143 | 146 |
{ |
144 |
numRenders += child.draw(time,buffer);
|
|
147 |
numRenders += child.draw(time,surface);
|
|
145 | 148 |
} |
146 | 149 |
} |
147 | 150 |
|
... | ... | |
149 | 152 |
// postprocess fbo |
150 | 153 |
// merge to buffer |
151 | 154 |
|
152 |
// TODO |
|
155 |
for(int i=0; i<num; i++) |
|
156 |
{ |
|
157 |
numRenders += children.get(i).postprocess(time,surface); |
|
158 |
} |
|
153 | 159 |
|
154 | 160 |
// 5. finally blit to this if we have to |
155 | 161 |
|
156 |
if( buffer!=this && ((DistortedFramebuffer)buffer).setAsInput() )
|
|
162 |
if( surface!=this && ((DistortedFramebuffer)surface).setAsInput() )
|
|
157 | 163 |
{ |
158 | 164 |
numRenders++; |
159 | 165 |
DistortedEffects.blitPriv(this); |
... | ... | |
215 | 221 |
numRenders += mChildren.get(i).renderRecursive(time); |
216 | 222 |
} |
217 | 223 |
|
218 |
setAsOutput(); |
|
224 |
setAsOutput(time);
|
|
219 | 225 |
numRenders += renderChildren(time,mNumChildren,mChildren); |
220 | 226 |
|
221 | 227 |
return numRenders; |
... | ... | |
225 | 231 |
/** |
226 | 232 |
* Bind this Surface as a Framebuffer we can render to. |
227 | 233 |
*/ |
228 |
public void setAsOutput() |
|
234 |
public void setAsOutput(long time)
|
|
229 | 235 |
{ |
230 | 236 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFBOH[0]); |
237 |
|
|
238 |
if( mTime!=time ) |
|
239 |
{ |
|
240 |
mTime = time; |
|
241 |
DistortedRenderState.colorDepthOn(); |
|
242 |
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
|
243 |
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT); |
|
244 |
} |
|
231 | 245 |
} |
232 | 246 |
|
233 | 247 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
---|---|---|
137 | 137 |
|
138 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
139 | 139 |
|
140 |
synchronized void compute(long currTime)
|
|
140 |
synchronized boolean compute(long currTime)
|
|
141 | 141 |
{ |
142 |
if( currTime==mTime ) return; |
|
142 |
if( currTime==mTime ) return false;
|
|
143 | 143 |
if( mTime==0 ) mTime = currTime; |
144 | 144 |
long step = (currTime-mTime); |
145 | 145 |
|
... | ... | |
166 | 166 |
} |
167 | 167 |
} |
168 | 168 |
|
169 |
mTime = currTime; |
|
169 |
mTime = currTime; |
|
170 |
|
|
171 |
return true; |
|
170 | 172 |
} |
171 | 173 |
|
172 | 174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
227 | 229 |
} |
228 | 230 |
|
229 | 231 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
230 |
// w,h - width and height of the input texture. MVP - Model-View-Projection matrix to apply to the |
|
231 |
// texture; df - output FBO. |
|
232 | 232 |
|
233 |
synchronized void render(float w, float h, float[] mvp, DistortedOutputSurface surface)
|
|
233 |
int postprocess(long time, DistortedOutputSurface surface)
|
|
234 | 234 |
{ |
235 |
mBlurProgram.useProgram(); |
|
236 |
|
|
237 |
int radius = (int)mUniforms[0]; |
|
238 |
if( radius>=MAX_BLUR ) radius = MAX_BLUR-1; |
|
239 |
computeGaussianKernel(radius); |
|
235 |
if( mNumEffects>0 && compute(time) ) |
|
236 |
{ |
|
237 |
mMainBuffer.setAsInput(); |
|
238 |
|
|
239 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
240 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -surface.mDistance); |
|
241 |
Matrix.multiplyMM(mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0); |
|
242 |
|
|
243 |
float w = surface.mWidth; |
|
244 |
float h = surface.mHeight; |
|
245 |
|
|
246 |
mBlurProgram.useProgram(); |
|
247 |
|
|
248 |
int radius = (int)mUniforms[0]; |
|
249 |
if( radius>=MAX_BLUR ) radius = MAX_BLUR-1; |
|
250 |
computeGaussianKernel(radius); |
|
251 |
|
|
252 |
int offset = radius + radius*radius/4; |
|
253 |
radius = (radius+1)/2; |
|
254 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h; |
|
255 |
|
|
256 |
GLES30.glUniform1fv( mWeightsH, radius+1, weightsCache,offset); |
|
257 |
GLES30.glUniform1i( mRadiusH, radius); |
|
258 |
GLES30.glUniform2f( mObjDH , w, h ); |
|
259 |
|
|
260 |
mPostBuffer.resizeFast( (int)w, (int)h); |
|
261 |
mPostBuffer.setAsOutput(time); |
|
262 |
GLES30.glViewport(0, 0, (int)w, (int)h); |
|
263 |
|
|
264 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
265 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -mPostBuffer.mDistance); |
|
266 |
Matrix.multiplyMM(mMVPMatrix, 0, mPostBuffer.mProjectionMatrix, 0, mTmpMatrix, 0); |
|
267 |
|
|
268 |
// horizontal blur |
|
269 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
270 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
|
271 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
272 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
273 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
|
274 |
|
|
275 |
// vertical blur |
|
276 |
mPostBuffer.setAsInput(); |
|
277 |
surface.setAsOutput(time); |
|
278 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w; |
|
279 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
280 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
|
281 |
} |
|
240 | 282 |
|
241 |
int offset = radius + radius*radius/4; |
|
242 |
radius = (radius+1)/2; |
|
243 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h; |
|
244 |
|
|
245 |
GLES30.glUniform1fv( mWeightsH, radius+1, weightsCache,offset); |
|
246 |
GLES30.glUniform1i( mRadiusH, radius); |
|
247 |
GLES30.glUniform2f( mObjDH , w, h ); |
|
248 |
|
|
249 |
mPostBuffer.resizeFast( (int)w, (int)h); |
|
250 |
mPostBuffer.setAsOutput(); |
|
251 |
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
|
252 |
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT); |
|
253 |
GLES30.glViewport(0, 0, (int)w, (int)h); |
|
254 |
|
|
255 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
256 |
Matrix.translateM(mTmpMatrix, 0, 0, 0, -mPostBuffer.mDistance); |
|
257 |
Matrix.multiplyMM(mMVPMatrix, 0, mPostBuffer.mProjectionMatrix, 0, mTmpMatrix, 0); |
|
258 |
|
|
259 |
// horizontal blur |
|
260 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
261 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
|
262 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
263 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
264 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
|
265 |
|
|
266 |
mPostBuffer.setAsInput(); |
|
267 |
surface.setAsOutput(); |
|
268 |
|
|
269 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight); |
|
270 |
|
|
271 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w; |
|
272 |
|
|
273 |
// vertical blur |
|
274 |
GLES30.glUniform1fv( mOffsetsH ,radius+1, mOffsets,0); |
|
275 |
GLES30.glUniformMatrix4fv(mMVPMatrixH, 1, false, mvp , 0); |
|
276 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
|
277 |
GLES30.glVertexAttribPointer(mBlurProgram.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTextureInv); |
|
278 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
|
283 |
return mNumEffects; |
|
279 | 284 |
} |
280 | 285 |
|
281 | 286 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Progress with Multiblur.
This introduces some regressions with transparency (see: 'Different Bitmaps' and 'Around the world' )