我正在尝试在Android设备上获取深度缓冲区(nexus 7)。 因为我无法附加深度缓冲区(opengl ES),所以我尝试使用着色器来编码颜色缓冲区的G和B组件中的深度值。 着色器:
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";
在电脑上,结果还可以(它应该是城市建筑物的面孔,每个都是相同的深度),图像是G通道:
但在Android上,结果上有一个“点”纹理,意味着更接近像素:
Android配置是:
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
是什么导致这个? 还有其他方法可以在Android设备上读取深度缓冲区吗?
答案 0 :(得分:1)
尝试禁用抖动:
GLES20.glDisable(GLES20.GL_DITHER);