WebGL(关于混合)

试了很久,发现效果都不满意。后来,看到了:

When using depth buffering in an application, you need to be careful about the order in which you render primitives. Fully opaque primitives need to be rendered first, followed by partially opaque primitives in back-to-front order. If you don't render primitives in this order, the primitives, which would otherwise be visible through a partially opaque primitive, might lose the depth test entirely.

结论:

先画不透明,再画半透明。都是半透明,那么由远及近的画(z轴)。

补充:

This is a quick solution, but it’s not very satisfactory because, as we’ve seen in Chapter 7 , hidden surface removal is often needed to correctly draw a 3D scene.

You can overcome this problem by drawing objects while turning the hidden surface removal function on and off.

  1. Enable the hidden surface removal function.
    gl.enable(gl.DEPTH_TEST);
  1. Draw all the opaque objects (whose alpha values are 1.0).
  1. Make the depth buffer ( Chapter 7 ), which is used in the hidden surface removal, read-only.
    gl.depthMask(false);
  1. Draw all the transparent objects (whose alpha values are smaller than 1.0). Note, they should be sorted by the depth order and drawn back to front.
  1. Make the depth buffer readable and writable.
    gl.depthMask(true);

If you completely disable the hidden surface removal function, when there are transpar-ent objects behind opaque objects, the transparent object will not be hidden behind the opaque objects. So you need to control that with gl.depthMask() . gl.depthMask() has the following specification.

参考

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,425评论 0 23
  • 好久没有写东西,最近的日子忙碌而艰难,年底对于机关单位而言真的是噩耗,今年偏偏事情特别多,不同部门的考核,人大代表...
    mqingl阅读 1,131评论 0 0
  • 或许这个世界上就是有人与众不同。他们不会因为自己的目的像这个世界索取,而是拿出自己奉献世界。他们从来不会隐藏,他们...
    袹悠阅读 1,105评论 0 0
  • :你们开公众号主要收入是什么?接广告?我:起步没有那么厉害,不过公号也就两种收入,我:赞赏和广告:感觉也是竞争激烈...
    邝鉴萍阅读 1,326评论 0 3
  • 静听春雨拍冷窗,倍感寒风添凄凉。 默叹落花入春泥,更觉年岁嵌忧伤。 细枝嫩芽不经晃,犹盼天晴多艳阳。 虚身弱体勿逞...
    平心如我阅读 1,482评论 0 0