开发者

AlphaFunctions in WebGL?

Is it possible to achieve an transparency effect where fragments with alpha lower than 0.5 are discarded and fragments with alpha higher than 0.5 are rendered rendered opaque? From what I've read,

glEnable(GL_ALPHA_TEST);
glAlphaFu开发者_如何学运维nc(GL_GREATER, 0.5); 

would be what I'm looking for but unfortunately, AlphaFunction is not defined in WebGL. Is there a workaround?

My problem is, that transparent fragments write into the depth buffer and thus prevent farther fragments from beeing rendered: alpha_error http://gebackene-ente.at/nudelsalat/sonstiges/pointcloud_alphaerror.jpg

Sorting is not an option because there are way too much points.


Use your shader to do it. At the bottom of your fragment shader, after setting the output color:

if(gl_FragColor.a < 0.5)
  discard;


You can completely discard fragments in the fragment shader using the discard statement. So just look up there alpha from the texture (or somewhere else) and then just call

if(alpha < 0.5)
    discard;

So you don't even need to propagate the alpha to the color or you can make the test dependent on something else. That is the modern way of doing alpha test, as it's also deprecated in desktop GL 3+.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜