简体   繁体   中英

Blending function for 3D sprites in openGL ES 2.0

I'm developing a 3D game for iOS with openGL ES2. the 3D sprites should be semi-transparent with an alpha channel of about 0.5 to show the background. The problem is that I want the back side of the 3D sprites to be completely not visible. 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. 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). 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) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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