30 |
30 |
import org.distorted.library.program.VertexCompilationException;
|
31 |
31 |
import org.distorted.library.program.VertexUniformsException;
|
32 |
32 |
import org.distorted.library.type.Data1D;
|
|
33 |
import org.distorted.library.type.Data4D;
|
33 |
34 |
import org.distorted.library.type.Dynamic1D;
|
|
35 |
import org.distorted.library.type.Dynamic4D;
|
34 |
36 |
import org.distorted.library.type.Static1D;
|
|
37 |
import org.distorted.library.type.Static4D;
|
35 |
38 |
|
36 |
39 |
import java.io.InputStream;
|
37 |
40 |
import java.nio.ByteBuffer;
|
... | ... | |
42 |
45 |
|
43 |
46 |
class EffectQueuePostprocess extends EffectQueue
|
44 |
47 |
{
|
|
48 |
private static final int MAX_HALO = 50; // Support effects creating up to MAX_HALO pixels wide 'halo' around the object.
|
|
49 |
|
45 |
50 |
private static final int POS_DATA_SIZE= 2; // Post Program: size of the position data in elements
|
46 |
51 |
private static final int TEX_DATA_SIZE= 2; // Post Program: size of the texture coordinate data in elements.
|
47 |
52 |
|
48 |
|
private static final int NUM_UNIFORMS = 4;
|
|
53 |
private static final int NUM_UNIFORMS = 5;
|
49 |
54 |
private static final int NUM_CACHE = 0;
|
50 |
55 |
private static final int INDEX = EffectTypes.POSTPROCESS.ordinal();
|
51 |
56 |
|
... | ... | |
68 |
73 |
mQuadTextureInv.put(textureInv).position(0);
|
69 |
74 |
}
|
70 |
75 |
|
|
76 |
int mQualityLevel;
|
|
77 |
float mQualityScale;
|
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////
|
71 |
80 |
// BLUR effect
|
72 |
81 |
private static final float GAUSSIAN[] = // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
|
73 |
82 |
{ // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates.
|
... | ... | |
85 |
94 |
};
|
86 |
95 |
private static final int NUM_GAUSSIAN = GAUSSIAN.length-2;
|
87 |
96 |
|
88 |
|
// Support blurs consisting of the present pixel and up to MAX_BLUR pixels in each direction
|
89 |
|
static final int MAX_BLUR = 50;
|
90 |
|
|
91 |
97 |
// The (fixed-function-sampled) Gaussian Blur kernels are of the size k0=1, k1=2, k2=2, k3=3, k4=3, k5=4, k6=4,...
|
92 |
98 |
// i.e. k(i)=floor((i+3)/2). (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
|
93 |
99 |
// in all 4 directions)
|
94 |
100 |
// We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
|
95 |
|
private static float[] weightsCache = new float[MAX_BLUR + MAX_BLUR*MAX_BLUR/4];
|
96 |
|
private static float[] offsetsCache = new float[MAX_BLUR + MAX_BLUR*MAX_BLUR/4];
|
|
101 |
private static float[] weightsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
|
|
102 |
private static float[] offsetsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
|
97 |
103 |
|
98 |
104 |
private static DistortedProgram mBlur1Program, mBlur2Program;
|
99 |
105 |
private static int mRadius1H,mOffsets1H,mWeights1H,mDepth1H, mColorTexture1H;
|
100 |
106 |
private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mColorTexture2H;
|
101 |
|
private static float[] mWeights = new float[MAX_BLUR];
|
102 |
|
private static float[] mOffsets = new float[MAX_BLUR];
|
103 |
|
// another effect ....
|
|
107 |
private static float[] mWeights = new float[MAX_HALO];
|
|
108 |
private static float[] mOffsets = new float[MAX_HALO];
|
|
109 |
/////////////////////////////////////////////////////////////////////////////////
|
|
110 |
// GLOW effect
|
104 |
111 |
|
105 |
|
int mQualityLevel;
|
106 |
|
float mQualityScale;
|
107 |
112 |
|
108 |
113 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
114 |
|
... | ... | |
127 |
132 |
{
|
128 |
133 |
mBlur1Program = new DistortedProgram(blur1VertexStream,blur1FragmentStream,
|
129 |
134 |
Distorted.GLSL_VERSION,
|
130 |
|
Distorted.GLSL_VERSION + "#define MAX_BLUR "+MAX_BLUR, Distorted.GLSL);
|
|
135 |
Distorted.GLSL_VERSION + "#define MAX_BLUR "+MAX_HALO, Distorted.GLSL);
|
131 |
136 |
}
|
132 |
137 |
catch(Exception e)
|
133 |
138 |
{
|
... | ... | |
149 |
154 |
{
|
150 |
155 |
mBlur2Program = new DistortedProgram(blur2VertexStream,blur2FragmentStream,
|
151 |
156 |
Distorted.GLSL_VERSION,
|
152 |
|
Distorted.GLSL_VERSION + "#define MAX_BLUR "+MAX_BLUR, Distorted.GLSL);
|
|
157 |
Distorted.GLSL_VERSION + "#define MAX_BLUR "+MAX_HALO, Distorted.GLSL);
|
153 |
158 |
}
|
154 |
159 |
catch(Exception e)
|
155 |
160 |
{
|
... | ... | |
168 |
173 |
|
169 |
174 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
170 |
175 |
|
171 |
|
synchronized boolean compute(long currTime)
|
|
176 |
private boolean compute(long currTime)
|
172 |
177 |
{
|
173 |
178 |
if( currTime==mTime ) return false;
|
174 |
179 |
if( mTime==0 ) mTime = currTime;
|
... | ... | |
195 |
200 |
}
|
196 |
201 |
else mInter[0][i] = null;
|
197 |
202 |
}
|
|
203 |
|
|
204 |
if( mInter[1][i]!=null ) mInter[1][i].interpolateMain( mUniforms, NUM_UNIFORMS*i+1, mCurrentDuration[i], step);
|
198 |
205 |
}
|
199 |
206 |
|
200 |
207 |
mTime = currTime;
|
... | ... | |
210 |
217 |
mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
|
211 |
218 |
mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
|
212 |
219 |
mUniforms[NUM_UNIFORMS*index+3] = mUniforms[NUM_UNIFORMS*(index+1)+3];
|
|
220 |
mUniforms[NUM_UNIFORMS*index+4] = mUniforms[NUM_UNIFORMS*(index+1)+4];
|
213 |
221 |
}
|
214 |
222 |
|
215 |
223 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
280 |
288 |
{
|
281 |
289 |
if (mName[i] == EffectNames.BLUR.ordinal() )
|
282 |
290 |
{
|
283 |
|
blur(mUniforms[i],surface);
|
|
291 |
blur(NUM_UNIFORMS*i,surface);
|
|
292 |
numRenders += 2;
|
|
293 |
}
|
|
294 |
else if (mName[i] == EffectNames.GLOW.ordinal() )
|
|
295 |
{
|
|
296 |
glow(NUM_UNIFORMS*i,surface);
|
284 |
297 |
numRenders += 2;
|
285 |
298 |
}
|
286 |
299 |
}
|
... | ... | |
291 |
304 |
|
292 |
305 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
293 |
306 |
|
294 |
|
private void blur(float degree, DistortedOutputSurface surface)
|
|
307 |
private void blur(int index, DistortedOutputSurface surface)
|
295 |
308 |
{
|
296 |
309 |
DistortedFramebuffer buffer = surface.mBuffer[mQualityLevel];
|
297 |
310 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, buffer.mFBOH[0]);
|
... | ... | |
299 |
312 |
float w1 = buffer.mWidth;
|
300 |
313 |
float h1 = buffer.mHeight;
|
301 |
314 |
|
302 |
|
int radius = (int)(degree*mQualityScale);
|
303 |
|
if( radius>=MAX_BLUR ) radius = MAX_BLUR-1;
|
|
315 |
int radius = (int)(mUniforms[index]*mQualityScale);
|
|
316 |
if( radius>=MAX_HALO ) radius = MAX_HALO-1;
|
304 |
317 |
computeGaussianKernel(radius);
|
305 |
318 |
|
306 |
319 |
int offset = radius + radius*radius/4;
|
... | ... | |
354 |
367 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
|
355 |
368 |
}
|
356 |
369 |
|
|
370 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
371 |
|
|
372 |
private void glow(int index, DistortedOutputSurface surface)
|
|
373 |
{
|
|
374 |
|
|
375 |
}
|
|
376 |
|
357 |
377 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
358 |
378 |
// blur
|
359 |
379 |
|
... | ... | |
380 |
400 |
|
381 |
401 |
return -1;
|
382 |
402 |
}
|
|
403 |
|
|
404 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
405 |
// glow
|
|
406 |
|
|
407 |
synchronized long add(EffectNames eln, Data1D degree, Data4D color)
|
|
408 |
{
|
|
409 |
if( mMax[INDEX]>mNumEffects )
|
|
410 |
{
|
|
411 |
if( degree instanceof Dynamic1D)
|
|
412 |
{
|
|
413 |
mInter[0][mNumEffects] = (Dynamic1D)degree;
|
|
414 |
}
|
|
415 |
else if( degree instanceof Static1D)
|
|
416 |
{
|
|
417 |
mInter[0][mNumEffects] = null;
|
|
418 |
mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)degree).getX();
|
|
419 |
}
|
|
420 |
else return -1;
|
|
421 |
|
|
422 |
if( color instanceof Dynamic4D)
|
|
423 |
{
|
|
424 |
mInter[1][mNumEffects] = (Dynamic4D)color;
|
|
425 |
}
|
|
426 |
else if( color instanceof Static4D)
|
|
427 |
{
|
|
428 |
mInter[1][mNumEffects] = null;
|
|
429 |
Static4D tmp = (Static4D)color;
|
|
430 |
mUniforms[NUM_UNIFORMS*mNumEffects+1] = tmp.getW(); //
|
|
431 |
mUniforms[NUM_UNIFORMS*mNumEffects+2] = tmp.getX(); // Invert: RGBA sent
|
|
432 |
mUniforms[NUM_UNIFORMS*mNumEffects+3] = tmp.getY(); // in, ARGB inside
|
|
433 |
mUniforms[NUM_UNIFORMS*mNumEffects+4] = tmp.getZ(); //
|
|
434 |
}
|
|
435 |
else return -1;
|
|
436 |
|
|
437 |
mInter[2][mNumEffects] = null;
|
|
438 |
|
|
439 |
return addBase(eln);
|
|
440 |
}
|
|
441 |
|
|
442 |
return -1;
|
|
443 |
}
|
383 |
444 |
}
|
Beginnings of support for the GLOW effect.