Search code examples
androidopengl-esdepth-buffer

Dots on depth image


I'm trying to get the depth buffer on my Android device (nexus 7). Because I cannot attach the depth buffer (opengl ES), I've tried to use shaders in order to encode the depth values in the G and B components of the color buffer. The shaders :

static const char gVertexShader[] =
"varying vec2 texcoord;                                             \n"
"void main()                                                        \n"
"{                                                                  \n"
"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;        \n"
"    texcoord    = gl_MultiTexCoord0.xy/gl_MultiTexCoord0.w;        \n"
"}                                                                  \n";

static const char gFragmentShader[] =
#ifdef __ANDROID__
"precision highp float;                                       \n"
#endif
"uniform sampler2D modelTexture;                             \n"
"varying vec2 texcoord;                                      \n"
"void main()                                                 \n"
"{                                                           \n"
"  gl_FragColor.r = texture2D(modelTexture, texcoord).r;     \n"
"  float depth = gl_FragCoord.z;                             \n"
"  gl_FragColor.g = depth;                                   \n"
"  gl_FragColor.b = depth;                                   \n"
"  gl_FragColor.a =    1.0;                                  \n"
"}                                                           \n";

On the pc, the results are ok (it should be city buildings faces, same depth each), image is the G channel: pc

But on the Android, the results has a texture of "dots" on it, meaning closer pixels : Android

The Android Configuration is :

EGL_BUFFER_SIZE: 32
EGL_ALPHA_SIZE: 8
EGL_BLUE_SIZE: 8
EGL_GREEN_SIZE: 8
EGL_RED_SIZE: 8
EGL_DEPTH_SIZE: 16
EGL_STENCIL_SIZE: 0
EGL_CONFIG_CAVEAT: 12344
EGL_CONFIG_ID: 25
EGL_LEVEL: 0
EGL_MAX_PBUFFER_HEIGHT: 2048
EGL_MAX_PBUFFER_PIXELS: 4194304
EGL_MAX_PBUFFER_WIDTH: 2048
EGL_NATIVE_RENDERABLE: 0
EGL_NATIVE_VISUAL_ID: 1
EGL_NATIVE_VISUAL_TYPE: -1
EGL_SAMPLES: 0
EGL_SAMPLE_BUFFERS: 0
EGL_SURFACE_TYPE: 3175
EGL_TRANSPARENT_TYPE: 12344
EGL_TRANSPARENT_RED_VALUE: 0
EGL_TRANSPARENT_GREEN_VALUE: 0
EGL_TRANSPARENT_BLUE_VALUE: 0
EGL_BIND_TO_TEXTURE_RGB: 0
EGL_BIND_TO_TEXTURE_RGBA: 0
EGL_MIN_SWAP_INTERVAL: 1
EGL_MAX_SWAP_INTERVAL: 1
EGL_LUMINANCE_SIZE: 0
EGL_ALPHA_MASK_SIZE: 8
EGL_COLOR_BUFFER_TYPE: 12430
EGL_RENDERABLE_TYPE: 4
EGL_CONFORMANT: 4

What could cause this ? Is there another way to read the Depth buffer on Android device ?


Solution

  • Try disabling dithering:

    GLES20.glDisable(GLES20.GL_DITHER);