我启用Alpha Blending:
GLES20.glEnable(GLES20.GL_BLEND);@H_301_14@然后我设置了功能:
GLES20.glBlendFunc(GLES20.GL_SRC_Alpha,GLES20.GL_ONE_MINUS_SRC_Alpha);@H_301_14@要么
GLES20.glBlendFunc(GLES20.GL_ONE,GLES20.GL_ONE_MINUS_SRC_Alpha);@H_301_14@效果还是一样的.我使用带Alpha通道的48位png文件.
我的片段着色器看起来像这样:
final String fragmentShader = "precision mediump float; \n" +"uniform vec3 u_lightPos; \n" +"uniform sampler2D u_Texture; \n" +"varying vec3 v_position; \n" +"varying vec4 v_color; \n" +"varying vec3 v_normal; \n" +"varying vec2 v_TexCoordinate; \n" +"voID main() \n" +"{ \n" +"float distance = length(u_lightPos - v_position); \n" +"vec3 lightVector = normalize(u_lightPos - v_position); \n" +"float diffuse = max(dot(v_normal,lightVector),0.0); \n" +"diffuse = diffuse * (" + float.toString((float)Brightness) +" / (1.0 + (0.08 * distance))); \n" +"diffuse = diffuse; \n" //+3 +"gl_Fragcolor = (v_color * diffuse * texture2D(u_Texture,v_TexCoordinate)); \n" +"} \n";@H_301_14@和顶点着色器:
uniform mat4 u_MVPMatrix; uniform mat4 u_MVMatrix; attribute vec4 a_position; attribute vec3 a_normal; attribute vec2 a_TexCoordinate; varying vec3 v_position; varying vec4 v_color; varying vec3 v_normal; varying vec2 v_TexCoordinate; voID main() { v_position = vec3(u_MVMatrix * a_position); v_color = a_color; v_TexCoordinate = a_TexCoordinate; v_normal = vec3(u_MVMatrix * vec4(a_normal,0.0)); gl_position = u_MVPMatrix * a_position; } Thx for any suggestions:)@H_301_14@解决方法 片段着色器将纹理颜色的所有4(RGBA)分量与漫反射因子相乘.当漫反射光消失时,这会使你的Alpha分量趋向于零,使你的精灵几乎看不见.要修复代码,请将其更改为以下内容:
gl_Fragcolor = v_color * texture2D(u_Texture,v_TexCoordinate);gl_Fragcolor.rgb *= diffuse;@H_301_14@ 总结以上是内存溢出为你收集整理的Android Opengl 2.0 Alpha混合问题 – 半透明纹理全部内容,希望文章能够帮你解决Android Opengl 2.0 Alpha混合问题 – 半透明纹理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)