Project

General

Profile

« Previous | Next » 

Revision ae2802b1

Added by Leszek Koltunski about 6 years ago

Postprocessing buffers mBuffer[] are now shared among all postprocessing operations. This saves a lot of memory, but also means that when doing each particular postprocessing, the textures backing up the mBuffer might be too large. We need to fix two things here: when outputting to those too large textures, we need to adjust the Viewport, and when binding those too large textures as input - we need to adjust the TexCoords to compensate.

This commit does just that. Verified as working by the 'PostprocessTree' app.

View differences:

src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
158 158
    float h= buffer.getHeight();
159 159
    float n= 1.0f - buffer.getNear();
160 160

  
161
    float corrW = buffer.getWidthCorrection();
162
    float corrH = buffer.getHeightCorrection();
163
    float offsetCorrW = corrW/w;
164
    float offsetCorrH = corrH/h;
165

  
161 166
    int radius = (int)(uniforms[index]*mQualityScale);
162 167
    if( radius>=MAX_HALO ) radius = MAX_HALO-1;
163 168
    computeGaussianKernel(radius);
......
167 172
    GLES31.glViewport(0, 0, (int)w, (int)h);
168 173

  
169 174
    // horizontal blur
170
    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w;
175
    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrW;
171 176

  
172 177
    mProgram1.useProgram();
173 178
    buffer.bindForOutput(1);
174 179
    buffer.setAsInput(0);
175 180

  
176 181
    GLES31.glUniform1f ( mProgram1.mUniform[0] , n );
177
    GLES31.glUniform1i ( mProgram1.mUniform[1] , 0 );
178
    GLES31.glUniform1fv( mProgram1.mUniform[2] , radius+1, mOffsets,0);
179
    GLES31.glUniform1fv( mProgram1.mUniform[3] , radius+1, weightsCache,offset);
180
    GLES31.glUniform1i ( mProgram1.mUniform[4] , radius);
182
    GLES31.glUniform2f ( mProgram1.mUniform[1] , corrW, corrH );
183
    GLES31.glUniform1i ( mProgram1.mUniform[2] , 0 );
184
    GLES31.glUniform1fv( mProgram1.mUniform[3] , radius+1, mOffsets,0);
185
    GLES31.glUniform1fv( mProgram1.mUniform[4] , radius+1, weightsCache,offset);
186
    GLES31.glUniform1i ( mProgram1.mUniform[5] , radius);
181 187
    GLES31.glVertexAttribPointer(mProgram1.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadPositions);
182 188
    GLES31.glVertexAttribPointer(mProgram1.mAttribute[1], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadTexture);
183 189
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
184 190

  
185 191
    // vertical blur
186
    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h;
192
    for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]*offsetCorrH;
187 193

  
188 194
    mProgram2.useProgram();
189 195
    buffer.bindForOutput(0);
......
194 200
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
195 201

  
196 202
    GLES31.glUniform1f ( mProgram2.mUniform[0] , n );
197
    GLES31.glUniform1i ( mProgram2.mUniform[1] , 0 );
198
    GLES31.glUniform1fv( mProgram2.mUniform[2] , radius+1, mOffsets,0);
199
    GLES31.glUniform1fv( mProgram2.mUniform[3] , radius+1, weightsCache,offset);
200
    GLES31.glUniform1i ( mProgram2.mUniform[4] , radius);
203
    GLES31.glUniform2f ( mProgram2.mUniform[1] , corrW, corrH );
204
    GLES31.glUniform1i ( mProgram2.mUniform[2] , 0 );
205
    GLES31.glUniform1fv( mProgram2.mUniform[3] , radius+1, mOffsets,0);
206
    GLES31.glUniform1fv( mProgram2.mUniform[4] , radius+1, weightsCache,offset);
207
    GLES31.glUniform1i ( mProgram2.mUniform[5] , radius);
201 208
    GLES31.glVertexAttribPointer(mProgram2.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadPositions);
202 209
    GLES31.glVertexAttribPointer(mProgram2.mAttribute[1], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, 0, mQuadTexture);
203 210
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
......
223 230
      "in vec2 a_TexCoord;    \n"+
224 231
      "out vec2 v_TexCoord;   \n"+
225 232
      "uniform float u_Depth; \n"+
233
      "uniform vec2 u_TexCorr;\n"+
226 234

  
227 235
      "void main()                                      \n"+
228 236
      "  {                                              \n"+
229
      "  v_TexCoord = a_TexCoord;                       \n"+
237
      "  v_TexCoord = a_TexCoord * u_TexCorr;           \n"+
230 238
      "  gl_Position= vec4(2.0*a_Position,u_Depth,1.0); \n"+
231 239
      "  }";
232 240

  

Also available in: Unified diff