Revision f89f791a
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
---|---|---|
93 | 93 |
private static float[] offsetsCache = new float[MAX_BLUR + MAX_BLUR*MAX_BLUR/4]; |
94 | 94 |
|
95 | 95 |
private static DistortedProgram mBlur1Program, mBlur2Program; |
96 |
private static int mRadius1H,mOffsets1H,mWeights1H,mDepth1H, mColorTexture1H; |
|
97 |
private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mColorTexture2H, mDepthTexture2H; |
|
96 |
private static int mRadius1H,mOffsets1H,mWeights1H,mDepth1H, mScale1H, mColorTexture1H;
|
|
97 |
private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mScale2H, mColorTexture2H, mDepthTexture2H;
|
|
98 | 98 |
private static float[] mWeights = new float[MAX_BLUR]; |
99 | 99 |
private static float[] mOffsets = new float[MAX_BLUR]; |
100 | 100 |
// another effect .... |
... | ... | |
131 | 131 |
mOffsets1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Offsets"); |
132 | 132 |
mWeights1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Weights"); |
133 | 133 |
mDepth1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Depth"); |
134 |
mScale1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Scale"); |
|
134 | 135 |
mColorTexture1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_ColorTexture"); |
135 | 136 |
|
136 | 137 |
final InputStream blur2VertexStream = resources.openRawResource(R.raw.blur_vertex_shader); |
... | ... | |
154 | 155 |
mOffsets2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Offsets"); |
155 | 156 |
mWeights2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Weights"); |
156 | 157 |
mDepth2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Depth"); |
158 |
mScale2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Scale"); |
|
157 | 159 |
mColorTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_ColorTexture"); |
158 | 160 |
mDepthTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_DepthTexture"); |
159 | 161 |
} |
... | ... | |
259 | 261 |
{ |
260 | 262 |
compute(time); |
261 | 263 |
|
262 |
surface.mBuffer1.setAsInput(); |
|
263 |
float w = surface.mWidth; |
|
264 |
float h = surface.mHeight; |
|
264 |
surface.mBuffer1[DistortedOutputSurface.CUR_MIPMAP].setAsInput();
|
|
265 |
float w = surface.mBuffer1[DistortedOutputSurface.CUR_MIPMAP].mWidth;
|
|
266 |
float h = surface.mBuffer1[DistortedOutputSurface.CUR_MIPMAP].mHeight;
|
|
265 | 267 |
|
266 | 268 |
int radius = (int)mUniforms[0]; |
267 | 269 |
if( radius>=MAX_BLUR ) radius = MAX_BLUR-1; |
... | ... | |
274 | 276 |
|
275 | 277 |
// horizontal blur |
276 | 278 |
mBlur1Program.useProgram(); |
277 |
surface.mBuffer2.setAsOutput(time); |
|
279 |
surface.mBuffer2[DistortedOutputSurface.CUR_MIPMAP].setAsOutput(time);
|
|
278 | 280 |
|
279 | 281 |
GLES30.glUniform1fv( mWeights1H, radius+1, weightsCache,offset); |
280 | 282 |
GLES30.glUniform1i( mRadius1H, radius); |
281 | 283 |
GLES30.glUniform1f( mDepth1H , 1.0f-surface.mNear); |
284 |
GLES30.glUniform1f( mScale1H , 1.0f); |
|
282 | 285 |
GLES30.glUniform1i( mColorTexture1H , 0 ); |
283 | 286 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h; |
284 | 287 |
GLES30.glUniform1fv( mOffsets1H ,radius+1, mOffsets,0); |
... | ... | |
288 | 291 |
|
289 | 292 |
// vertical blur |
290 | 293 |
mBlur2Program.useProgram(); |
291 |
surface.mBuffer2.setAsInput(); |
|
292 |
surface.mBuffer1.setAsDepth(); |
|
294 |
surface.mBuffer2[DistortedOutputSurface.CUR_MIPMAP].setAsInput();
|
|
295 |
surface.mBuffer1[DistortedOutputSurface.CUR_MIPMAP].setAsDepth();
|
|
293 | 296 |
surface.setAsOutput(time); |
294 | 297 |
|
295 | 298 |
GLES30.glUniform1fv( mWeights2H, radius+1, weightsCache,offset); |
296 | 299 |
GLES30.glUniform1i( mRadius2H, radius); |
297 | 300 |
GLES30.glUniform1f( mDepth2H , 1.0f-surface.mNear); |
301 |
GLES30.glUniform1f( mScale2H , 0.9f); |
|
298 | 302 |
GLES30.glUniform1i( mColorTexture2H , 0 ); |
299 | 303 |
GLES30.glUniform1i( mDepthTexture2H , 1 ); |
300 | 304 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w; |
Also available in: Unified diff
Preliminary support for MIPMAP levels of the postprocessing buffers. (doesn't work yet)