Revision bed13bea
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/effect/PostprocessEffect.java | ||
|---|---|---|
| 139 | 139 |
* |
| 140 | 140 |
* @y.exclude |
| 141 | 141 |
*/ |
| 142 |
public abstract int apply(float[] uniforms, int index, int quality, DistortedFramebuffer[] buffers);
|
|
| 142 |
public abstract int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers); |
|
| 143 | 143 |
|
| 144 | 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 145 | 145 |
/** |
| src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java | ||
|---|---|---|
| 138 | 138 |
* |
| 139 | 139 |
* @y.exclude |
| 140 | 140 |
*/ |
| 141 |
public int apply(float[] uniforms, int index, int quality, DistortedFramebuffer[] buffers)
|
|
| 141 |
public int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers) |
|
| 142 | 142 |
{
|
| 143 | 143 |
if( mProgram1 ==null) |
| 144 | 144 |
{
|
| ... | ... | |
| 146 | 146 |
mProgram2 = mPrograms.get(mIndex2); |
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 |
DistortedFramebuffer buffer = buffers[quality];
|
|
| 149 |
DistortedFramebuffer buffer = buffers[mQualityLevel];
|
|
| 150 | 150 |
|
| 151 | 151 |
buffer.setAsOutput(); |
| 152 | 152 |
|
| ... | ... | |
| 198 | 198 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
| 199 | 199 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
| 200 | 200 |
|
| 201 |
return quality;
|
|
| 201 |
return 2;
|
|
| 202 | 202 |
} |
| 203 | 203 |
|
| 204 | 204 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java | ||
|---|---|---|
| 141 | 141 |
* |
| 142 | 142 |
* @y.exclude |
| 143 | 143 |
*/ |
| 144 |
public int apply(float[] uniforms, int index, int quality, DistortedFramebuffer[] buffers)
|
|
| 144 |
public int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers) |
|
| 145 | 145 |
{
|
| 146 | 146 |
if( mProgram1 ==null) |
| 147 | 147 |
{
|
| ... | ... | |
| 149 | 149 |
mProgram2 = mPrograms.get(mIndex2); |
| 150 | 150 |
} |
| 151 | 151 |
|
| 152 |
int outQuality = (quality<mQualityLevel ? mQualityLevel:quality); |
|
| 153 |
|
|
| 154 |
DistortedFramebuffer inBuffer = buffers[quality]; |
|
| 155 |
DistortedFramebuffer outBuffer = buffers[outQuality]; |
|
| 156 |
|
|
| 157 |
outBuffer.setAsOutput(); |
|
| 152 |
DistortedFramebuffer inBuffer = buffers[0]; |
|
| 153 |
DistortedFramebuffer outBuffer = buffers[mQualityLevel]; |
|
| 158 | 154 |
|
| 159 | 155 |
float w1 = outBuffer.getWidth(); |
| 160 | 156 |
float h1 = outBuffer.getHeight(); |
| ... | ... | |
| 172 | 168 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w1; |
| 173 | 169 |
|
| 174 | 170 |
mProgram1.useProgram(); |
| 171 |
outBuffer.setAsOutput(); |
|
| 175 | 172 |
outBuffer.bindForOutput(1); |
| 176 | 173 |
inBuffer.setAsInput(0); |
| 177 | 174 |
|
| ... | ... | |
| 189 | 186 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h1; |
| 190 | 187 |
|
| 191 | 188 |
mProgram2.useProgram(); |
| 192 |
outBuffer.bindForOutput(0); |
|
| 189 |
inBuffer.setAsOutput(); |
|
| 190 |
inBuffer.bindForOutput(0); |
|
| 193 | 191 |
outBuffer.setAsInput(1); |
| 194 |
/* |
|
| 195 |
GLES30.glColorMask(true,true,true,true); |
|
| 196 |
GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f); |
|
| 197 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT); |
|
| 198 |
*/ |
|
| 192 |
|
|
| 199 | 193 |
GLES30.glUniform1f ( mProgram2.mUniform[0] , near); |
| 200 | 194 |
GLES30.glUniform1i ( mProgram2.mUniform[1] , 0 ); |
| 201 | 195 |
GLES30.glUniform1fv( mProgram2.mUniform[2] , radius+1, mOffsets,0); |
| ... | ... | |
| 206 | 200 |
GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
| 207 | 201 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
| 208 | 202 |
|
| 209 |
return outQuality;
|
|
| 203 |
return 2;
|
|
| 210 | 204 |
} |
| 211 | 205 |
|
| 212 | 206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 253 | 247 |
" pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x+u_Offsets[i],v_TexCoord.y)) + \n"+ |
| 254 | 248 |
" texture(u_ColorTexture,vec2(v_TexCoord.x-u_Offsets[i],v_TexCoord.y)) ) * u_Weights[i]; \n"+ |
| 255 | 249 |
" } \n"+ |
| 256 |
" fragColor = vec4( 0.5*(pixel.rgb+u_Color.rgb), sign(pixel.a)*u_Color.a); \n"+
|
|
| 250 |
" fragColor = vec4( 0.5*(pixel.rgb+u_Color.rgb), sqrt(pixel.a*u_Color.a)); \n"+
|
|
| 257 | 251 |
" }"; |
| 258 | 252 |
|
| 259 | 253 |
final String glowFragment2 = |
| ... | ... | |
| 277 | 271 |
" pixel += ( texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y+u_Offsets[i])) + \n"+ |
| 278 | 272 |
" texture(u_ColorTexture,vec2(v_TexCoord.x,v_TexCoord.y-u_Offsets[i])) ) * u_Weights[i]; \n"+ |
| 279 | 273 |
" } \n"+ |
| 280 |
" fragColor = vec4( 0.5*(pixel.rgb+u_Color.rgb), sign(pixel.a)*u_Color.a); \n"+
|
|
| 274 |
" fragColor = vec4( 0.5*(pixel.rgb+u_Color.rgb), sqrt(pixel.a*u_Color.a)); \n"+
|
|
| 281 | 275 |
" }"; |
| 282 | 276 |
|
| 283 | 277 |
mIndex1 = PostprocessEffect.register("GLOW1", glowVertex,glowFragment1);
|
| src/main/java/org/distorted/library/main/DistortedEffects.java | ||
|---|---|---|
| 231 | 231 |
|
| 232 | 232 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 233 | 233 |
|
| 234 |
int postprocess(DistortedOutputSurface surface,int quality)
|
|
| 234 |
int postprocess(DistortedOutputSurface surface) |
|
| 235 | 235 |
{
|
| 236 |
return mP.postprocess(surface,quality);
|
|
| 236 |
return mP.postprocess(surface); |
|
| 237 | 237 |
} |
| 238 | 238 |
|
| 239 | 239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
|---|---|---|
| 251 | 251 |
|
| 252 | 252 |
int renderChildren(long time, int numChildren, ArrayList<DistortedNode> children) |
| 253 | 253 |
{
|
| 254 |
int inQuality=0, outQuality, numRenders = 0, bucketChange = 0;
|
|
| 254 |
int quality=0, numRenders = 0, bucketChange = 0;
|
|
| 255 | 255 |
DistortedNode child1, child2; |
| 256 | 256 |
DistortedEffects lastEffects=null, currEffects; |
| 257 | 257 |
long lastBucket=0, currBucket; |
| ... | ... | |
| 278 | 278 |
for(int j=bucketChange; j<i; j++) |
| 279 | 279 |
{
|
| 280 | 280 |
child2 = children.get(j); |
| 281 |
numRenders += child2.markStencilAndDepth(time,mBuffer[inQuality],lastEffects);
|
|
| 281 |
numRenders += child2.markStencilAndDepth(time,mBuffer[quality],lastEffects);
|
|
| 282 | 282 |
} |
| 283 | 283 |
|
| 284 |
outQuality = lastEffects.postprocess(this,inQuality); |
|
| 285 |
numRenders += lastEffects.getNumRenders(); |
|
| 286 |
numRenders += blitWithDepth(time, mBuffer[outQuality]); |
|
| 284 |
numRenders += lastEffects.postprocess(this); |
|
| 285 |
numRenders += blitWithDepth(time, mBuffer[quality]); |
|
| 287 | 286 |
} |
| 288 | 287 |
|
| 289 |
inQuality = currEffects.getQuality();
|
|
| 288 |
quality = currEffects.getQuality();
|
|
| 290 | 289 |
bucketChange = i; |
| 291 | 290 |
} |
| 292 | 291 |
|
| 293 |
numRenders += child1.draw(time,mBuffer[inQuality]);
|
|
| 292 |
numRenders += child1.draw(time,mBuffer[quality]);
|
|
| 294 | 293 |
|
| 295 | 294 |
if( i==numChildren-1 ) |
| 296 | 295 |
{
|
| 297 | 296 |
for(int j=bucketChange; j<numChildren; j++) |
| 298 | 297 |
{
|
| 299 | 298 |
child2 = children.get(j); |
| 300 |
numRenders += child2.markStencilAndDepth(time,mBuffer[inQuality],currEffects);
|
|
| 299 |
numRenders += child2.markStencilAndDepth(time,mBuffer[quality],currEffects);
|
|
| 301 | 300 |
} |
| 302 | 301 |
|
| 303 |
outQuality = currEffects.postprocess(this,inQuality); |
|
| 304 |
numRenders += currEffects.getNumRenders(); |
|
| 305 |
numRenders += blitWithDepth(time, mBuffer[outQuality]); |
|
| 302 |
numRenders += currEffects.postprocess(this); |
|
| 303 |
numRenders += blitWithDepth(time, mBuffer[quality]); |
|
| 306 | 304 |
} |
| 307 | 305 |
} |
| 308 | 306 |
|
| src/main/java/org/distorted/library/main/EffectQueueMatrix.java | ||
|---|---|---|
| 46 | 46 |
private static int mObjDH; // This is a handle to half a Object dimensions |
| 47 | 47 |
private static int mMVPMatrixH; // the transformation matrix |
| 48 | 48 |
private static int mMVMatrixH; // the modelview matrix. |
| 49 |
|
|
| 49 |
|
|
| 50 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 51 | 51 |
|
| 52 | 52 |
EffectQueueMatrix(long id) |
| ... | ... | |
| 70 | 70 |
|
| 71 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 72 | 72 |
// modify the ModelView matrix so that the object drawn appears to be (about) 'marginInPixels' pixels |
| 73 |
// larger in each direction when rendered. Used in BLUR.
|
|
| 73 |
// larger in each direction when rendered. Used in Postprocessing.
|
|
| 74 | 74 |
|
| 75 | 75 |
private void magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels) |
| 76 | 76 |
{
|
| ... | ... | |
| 94 | 94 |
|
| 95 | 95 |
float xlen = projection.mWidth *(mMaxx-mMinx)/2; |
| 96 | 96 |
float ylen = projection.mHeight*(mMaxy-mMiny)/2; |
| 97 |
float scale = 1.0f + marginInPixels/( xlen>ylen ? ylen:xlen ); |
|
| 98 |
|
|
| 99 |
android.util.Log.d("scale", ""+marginInPixels+" scale= "+scale+" xlen="+xlen+" ylen="+ylen+" meshW="+(2*halfX)+" meshY="+(2*halfY));
|
|
| 97 |
float scale = 1.0f + 2*marginInPixels/( xlen>ylen ? ylen:xlen ); |
|
| 100 | 98 |
|
| 101 | 99 |
Matrix.scaleM(mViewMatrix, 0, scale, scale, scale); |
| 102 | 100 |
} |
| src/main/java/org/distorted/library/main/EffectQueuePostprocess.java | ||
|---|---|---|
| 101 | 101 |
|
| 102 | 102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 103 | 103 |
|
| 104 |
int postprocess(DistortedOutputSurface surface, int quality)
|
|
| 104 |
int postprocess(DistortedOutputSurface surface) |
|
| 105 | 105 |
{
|
| 106 |
int numRenders = 0; |
|
| 107 |
|
|
| 106 | 108 |
DistortedRenderState.useStencilMark(); |
| 107 | 109 |
|
| 108 | 110 |
for(int i=0; i<mNumEffects; i++) |
| 109 | 111 |
{
|
| 110 |
quality = ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, quality, surface.mBuffer);
|
|
| 112 |
numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, surface.mBuffer);
|
|
| 111 | 113 |
} |
| 112 | 114 |
|
| 113 | 115 |
DistortedRenderState.unuseStencilMark(); |
| 114 | 116 |
|
| 115 |
return quality;
|
|
| 117 |
return numRenders;
|
|
| 116 | 118 |
} |
| 117 | 119 |
} |
Also available in: Unified diff
Progress with Glow.