opengl z-sorting transparency

梦想与她 提交于 2019-11-28 13:05:36

Your title is essentially the answer to your question!

Generally transparency is done by first rendering all opaque objects in the scene (letting the z-buffer figure out what's visible), then rendering all transparent objects from back to front.

user346443

Figured it out. You can discard in the fragment shader

mediump vec4 basecolor = texture2D(sTexture, TexCoord);

if (basecolor.a == 0.0){
    discard;
}

gl_FragColor = basecolor;

Drew Hall gave you a good answer but another option is to set glEnable(GL_ALPHA_TEST) with glAlphaFunc(GL_GREATER, 0.1f). This will prevent transparent pixels (in this case, ones with alpha < 0.1f) from being rendered at all. That way they do not write into the Z buffer and other things can "show through". However, this only works on fully transparent objects. It also has rough edges wherever the 0.1 alpha edge is and this can look bad for distant features where the pixels are large compared to the object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!