Android GLES20.glBlendEquation not working?

2019-02-22 10:39发布

Ive been trying to make a 2.5D engine with depth and normal map textures for a few weeks now, not unlike whats used here Linky. After thinking the drawing of a depth map in the fragment shader from a texture was impossible due to ES 2.0 missing the gl_fragDepth variable I found a tutorial for iOS where they used glBlendEquation with the mode GL_MIN/GL_MAX to "fake" depth buffering of the fragment to a framebuffer-texture Linky. Unfortunely GLES20.glBlendEquation makes the application crash on both my phones (SGS 1/2) with UnsupportedOperationException. So Im wondering if anyone has used this function to any success? GL_MIN/GL_MAX also seems to be missing from the Android Opengl ES 2.0 spec so Im probably out of luck here... Any ideas?

BTW It does seem to work in GL11Ext but since Im using the fragment shader for normal mapping this wont work from me.

1条回答
来,给爷笑一个
2楼-- · 2019-02-22 10:56

i was experimenting on my Vega tablet (Tegra) and this worked for me:

fragment shader:

#extension GL_NV_shader_framebuffer_fetch : require 
// makes gl_LastFragColor accessible

precision highp float;

varying vec2 v_texcoord;

uniform sampler2D n_sampler;

void main()
{
    vec4 v_tex = texture2D(n_sampler, v_texcoord);
    gl_FragColor = min(gl_LastFragColor, v_tex); // MIN blending
}

Pretty easy, huh? But i'm afraid this will be NV-only.

查看更多
登录 后发表回答