Revision 4b9fe2e9
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, DistortedFramebuffer[] buffers); | |
| 142 |   public abstract int apply(float[] uniforms, int index, int quality, 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, DistortedFramebuffer[] buffers) | |
| 141 |   public int apply(float[] uniforms, int index, int quality, 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[mQualityLevel];
 | |
| 149 |     DistortedFramebuffer buffer = buffers[quality];
 | |
| 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 2;
 | |
| 201 |     return quality;
 | |
| 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, DistortedFramebuffer[] buffers) | |
| 144 |   public int apply(float[] uniforms, int index, int quality, DistortedFramebuffer[] buffers)
 | |
| 145 | 145 |     {
 | 
| 146 | 146 | if( mProgram1 ==null) | 
| 147 | 147 |       {
 | 
| ... | ... | |
| 149 | 149 | mProgram2 = mPrograms.get(mIndex2); | 
| 150 | 150 | } | 
| 151 | 151 |  | 
| 152 |     DistortedFramebuffer buffer = buffers[mQualityLevel];
 | |
| 152 |     int outQuality = (quality<mQualityLevel ? mQualityLevel:quality);
 | |
| 153 | 153 |  | 
| 154 | buffer.setAsOutput(); | |
| 154 | DistortedFramebuffer inBuffer = buffers[quality]; | |
| 155 | DistortedFramebuffer outBuffer = buffers[outQuality]; | |
| 155 | 156 |  | 
| 156 | float w1 = buffer.getWidth(); | |
| 157 | float h1 = buffer.getHeight(); | |
| 158 | float near= 1.0f - buffer.getNear(); | |
| 157 | outBuffer.setAsOutput(); | |
| 158 |  | |
| 159 | float w1 = outBuffer.getWidth(); | |
| 160 | float h1 = outBuffer.getHeight(); | |
| 161 | float near= 1.0f - outBuffer.getNear(); | |
| 159 | 162 |  | 
| 160 | 163 | int radius = (int)(uniforms[index]*mQualityScale); | 
| 161 | 164 | if( radius>=MAX_HALO ) radius = MAX_HALO-1; | 
| ... | ... | |
| 165 | 168 | radius = (radius+1)/2; | 
| 166 | 169 | GLES30.glViewport(0, 0, (int)w1, (int)h1); | 
| 167 | 170 |  | 
| 168 |     // horizontal blur
 | |
| 171 |     // horizontal glow
 | |
| 169 | 172 | for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h1; | 
| 170 | 173 |  | 
| 171 | 174 | mProgram1.useProgram(); | 
| 172 |     buffer.bindForOutput(1);
 | |
| 173 |     buffer.setAsInput(0);
 | |
| 175 |     outBuffer.bindForOutput(1);
 | |
| 176 |     inBuffer.setAsInput(0);
 | |
| 174 | 177 |  | 
| 175 | 178 | GLES30.glUniform1f ( mProgram1.mUniform[0] , near); | 
| 176 | 179 | GLES30.glUniform1i ( mProgram1.mUniform[1] , 0 ); | 
| ... | ... | |
| 181 | 184 | GLES30.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); | 
| 182 | 185 | GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); | 
| 183 | 186 |  | 
| 184 |     // vertical blur
 | |
| 187 |     // vertical glow
 | |
| 185 | 188 | for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w1; | 
| 186 | 189 |  | 
| 187 | 190 | mProgram2.useProgram(); | 
| 188 |     buffer.bindForOutput(0);
 | |
| 189 |     buffer.setAsInput(1);
 | |
| 191 |     outBuffer.bindForOutput(0);
 | |
| 192 |     outBuffer.setAsInput(1);
 | |
| 190 | 193 |  | 
| 191 | 194 | GLES30.glColorMask(true,true,true,true); | 
| 192 | 195 | GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f); | 
| ... | ... | |
| 201 | 204 | GLES30.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); | 
| 202 | 205 | GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); | 
| 203 | 206 |  | 
| 204 |     return 2;
 | |
| 207 |     return outQuality;
 | |
| 205 | 208 | } | 
| 206 | 209 |  | 
| 207 | 210 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| src/main/java/org/distorted/library/main/DistortedEffects.java | ||
|---|---|---|
| 231 | 231 |  | 
| 232 | 232 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 233 | 233 |  | 
| 234 | int postprocess(DistortedOutputSurface surface) | |
| 234 |   int postprocess(DistortedOutputSurface surface,int quality)
 | |
| 235 | 235 |     {
 | 
| 236 | return mP.postprocess(surface); | |
| 236 | return mP.postprocess(surface,quality); | |
| 237 | } | |
| 238 |  | |
| 239 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 240 |  | |
| 241 | int getNumRenders() | |
| 242 |     {
 | |
| 243 | return mP.getNumRenders(); | |
| 237 | 244 | } | 
| 238 | 245 |  | 
| 239 | 246 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
|---|---|---|
| 250 | 250 |  | 
| 251 | 251 | int renderChildren(long time, int numChildren, ArrayList<DistortedNode> children) | 
| 252 | 252 |     {
 | 
| 253 |     int quality=0, numRenders = 0, bucketChange = 0;
 | |
| 253 |     int inQuality=0, outQuality, numRenders = 0, bucketChange = 0;
 | |
| 254 | 254 | DistortedNode child1, child2; | 
| 255 | 255 | DistortedEffects lastEffects=null, currEffects; | 
| 256 | 256 | long lastBucket=0, currBucket; | 
| ... | ... | |
| 277 | 277 | for(int j=bucketChange; j<i; j++) | 
| 278 | 278 |               {
 | 
| 279 | 279 | child2 = children.get(j); | 
| 280 |               numRenders += child2.markStencilAndDepth(time,mBuffer[quality],lastEffects);
 | |
| 280 |               numRenders += child2.markStencilAndDepth(time,mBuffer[inQuality],lastEffects);
 | |
| 281 | 281 | } | 
| 282 | 282 |  | 
| 283 | numRenders += lastEffects.postprocess(this); | |
| 284 | numRenders += blitWithDepth(time, mBuffer[quality]); | |
| 283 | outQuality = lastEffects.postprocess(this,inQuality); | |
| 284 | numRenders += lastEffects.getNumRenders(); | |
| 285 | numRenders += blitWithDepth(time, mBuffer[outQuality]); | |
| 285 | 286 | } | 
| 286 | 287 |  | 
| 287 |           quality = currEffects.getQuality();
 | |
| 288 |           inQuality = currEffects.getQuality();
 | |
| 288 | 289 | bucketChange = i; | 
| 289 | 290 | } | 
| 290 | 291 |  | 
| 291 |         numRenders += child1.draw(time,mBuffer[quality]);
 | |
| 292 |         numRenders += child1.draw(time,mBuffer[inQuality]);
 | |
| 292 | 293 |  | 
| 293 | 294 | if( i==numChildren-1 ) | 
| 294 | 295 |           {
 | 
| 295 | 296 | for(int j=bucketChange; j<numChildren; j++) | 
| 296 | 297 |             {
 | 
| 297 | 298 | child2 = children.get(j); | 
| 298 |             numRenders += child2.markStencilAndDepth(time,mBuffer[quality],currEffects);
 | |
| 299 |             numRenders += child2.markStencilAndDepth(time,mBuffer[inQuality],currEffects);
 | |
| 299 | 300 | } | 
| 300 | 301 |  | 
| 301 | numRenders += currEffects.postprocess(this); | |
| 302 | numRenders += blitWithDepth(time,mBuffer[quality]); | |
| 302 | outQuality = currEffects.postprocess(this,inQuality); | |
| 303 | numRenders += currEffects.getNumRenders(); | |
| 304 | numRenders += blitWithDepth(time, mBuffer[outQuality]); | |
| 303 | 305 | } | 
| 304 | 306 | } | 
| 305 | 307 |  | 
| src/main/java/org/distorted/library/main/EffectQueuePostprocess.java | ||
|---|---|---|
| 91 | 91 | } | 
| 92 | 92 |  | 
| 93 | 93 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 94 | // TODO: for now, we assume each postprocessing effect issues 2 drawing calls (this is for statistical | |
| 95 | // purposes only anyway) | |
| 94 | 96 |  | 
| 95 |   int postprocess(DistortedOutputSurface surface)
 | |
| 97 |   int getNumRenders()
 | |
| 96 | 98 |     {
 | 
| 97 | int numRenders = 0; | |
| 99 | return 2*mNumEffects; | |
| 100 | } | |
| 101 |  | |
| 102 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 98 | 103 |  | 
| 104 | int postprocess(DistortedOutputSurface surface, int quality) | |
| 105 |     {
 | |
| 99 | 106 | DistortedRenderState.useStencilMark(); | 
| 100 | 107 |  | 
| 101 | 108 | for(int i=0; i<mNumEffects; i++) | 
| 102 | 109 |       {
 | 
| 103 |       numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, surface.mBuffer);
 | |
| 110 |       quality = ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, quality, surface.mBuffer);
 | |
| 104 | 111 | } | 
| 112 |  | |
| 105 | 113 | DistortedRenderState.unuseStencilMark(); | 
| 106 | 114 |  | 
| 107 |     return numRenders;
 | |
| 115 |     return quality;
 | |
| 108 | 116 | } | 
| 109 | 117 | } | 
Also available in: Unified diff
Introduce concepts of 'in' and 'out' postprocessing qualities.