Hex Crown
Hex Crown

Reputation: 753

GLES2.0+ framebuffer fade artifacts

I'm writing a simple test program on android using GLES 2.0 or 3.0. (If the solution only works on one over the other, than that's what I'll go with.)

Problem:

Example:

Layout:

Render Code:

int i = 0;
@Override public void onDrawView() {
    setRenderTarget(mRenderTexture[i]);
    mTestShader.setTexture0(mRenderTexture[(i + 1) % 2].getTextureHandle());
    mTestShader.draw(mBlitQuad);
    setRenderTarget(null);
    mBlitShader.setTexture0(mRenderTexture[i].getTextureHandle());
    mBlitShader.draw(mBlitQuad);
    i = ++i % 2;
}

Shader Code:

precision highp float;

uniform float u_GlobalTime;
uniform vec3 u_Resolution;
uniform sampler2D u_Texture0;

varying vec2 v_TexCoord;

void main(void) {
    vec2 uv = v_TexCoord * 2.0 - 1.0;
    uv.x *= u_Resolution.z;
    vec2 pos = vec2(cos(u_GlobalTime), sin(u_GlobalTime)) * 0.5;
    vec4 circle = vec4(1.0 - smoothstep(0.09, 0.11, length(pos - uv)));
    vec4 px = max(texture2D(u_Texture0, v_TexCoord), circle) - 0.025;
    gl_FragColor = step(0.15, px) * px;
}

Any help on this issue?

EDIT:
After some googling on dither thanks to Jerem, I found GLES20.glDisable(GLES20.GL_DITHER). This helps alot with this problem and on newer devices it works perfect. On older devices I'm still running into artifacting as seen HERE.

EDIT2:
After some more testing, switching to a buffer format with even RGB colors seems to have done the trick GLES30.GL_UNSIGNED_SHORT_5_5_5_1. My guess is it had to do with how the GPU compresses the framebuffer as the green was more noticeable. (It would still be helpful to know the specific reason as to why it doesn't like the 5_6_5 format.)
Final result after both fixes applied: i.imgur.com/bQsG9YJ.png.

Upvotes: 1

Views: 307

Answers (1)

Hex Crown
Hex Crown

Reputation: 753

Its a multi-part solution, call GLES20.glDisable(GLES20.GL_DITHER), set render buffer format to GLES30.GL_UNSIGNED_SHORT_5_5_5_1, and as Jerem said, you also may be able to get even better results with alpha disabled, though experimentation with that on my device selection appeared to have no effect, possible on other devices it would.

Upvotes: 2

Related Questions