简体   繁体   English

openGL ES 2.0中3D精灵的混合功能

[英]Blending function for 3D sprites in openGL ES 2.0

I'm developing a 3D game for iOS with openGL ES2. 我正在使用openGL ES2开发适用于iOS的3D游戏。 the 3D sprites should be semi-transparent with an alpha channel of about 0.5 to show the background. 3D子画面应该是半透明的,具有约0.5的Alpha通道以显示背景。 The problem is that I want the back side of the 3D sprites to be completely not visible. 问题是我希望3D精灵的背面完全不可见。 In other words i want to see only the front side of the sprite (just like it would appear with an alpha channel = 1) but with the background visible through it. 换句话说,我只想看到子画面的正面(就像它在alpha通道= 1时出现的一样),但背景可以通过它看到。 Is there any blend function or some shader setting to obtain this effect? 是否有任何混合功能或某些着色器设置才能获得此效果?

Presumably your sprites are textured onto geometry (quads drawn using triangles or triangle strips)? 大概是您的精灵已在几何图形上纹理化了(使用三角形或三角形条纹绘制的四边形)? All you need to do is enable face culling: 您需要做的就是启用面部剔除:

glEnable(GL_CULL_FACE);

This will prevent drawing the "back" side of any polygon well before it gets to the blending stage of the graphics pipeline -- so you get a performance win in addition to the visual effect your after. 这样可以防止在多边形到达图形管道的融合阶段之前就对其进行“背面”绘制-这样,除了获得视觉效果之外,您还可以获得性能上的优势。

You do need to make sure that your "front" and "back" sides are defined consistently, though. 不过,您需要确保前后定义一致。 By default, OpenGL considers any polygon whose vertices are in counter-clockwise order to be front-facing (and vice versa). 默认情况下,OpenGL会将其顶点按逆时针顺序的任何多边形都视为朝前的多边形(反之亦然)。 If enabling face culling makes all your sprites disappear, it's because their vertices are in clockwise order. 如果启用面部剔除会使您所有的精灵消失,那是因为它们的顶点按顺时针顺序排列。 Either reorder your vertices, or tell OpenGL that they're all backwards with glFrontFace(GL_CW) . 可以对顶点重新排序,或者通过glFrontFace(GL_CW)告诉OpenGL它们都向后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM