iPhone OpenGL ES:对 2D 游戏具有透明像素的纹理应用深度测试

发布于 2024-08-02 21:24:23 字数 164 浏览 5 评论 0原文

目前,我为 2D 游戏启用了混合和深度测试。当我绘制纹理时,“上部”纹理会删除下部纹理的某些部分(如果它们相交)。显然,深度测试考虑了纹理的透明像素,并且如果它们相交,它就会清除绘制的较低纹理的所有颜色。此外,Alpha 混合渲染不正确。是否有任何类型的函数可以告诉 OpenGL 不要将透明像素包含在深度测试中?

Currently, I have blending and depth testing turn on for a 2D game. When I draw my textures, the "upper" texture remove some portion of the lower textures if they intersect. Clearly, transparent pixels of the textures are taken into account of the depth test, and it clear out all the colors of the drawn lower textures if they intersect. Moreover, alpha blendings are incorrectly rendered. Are there any sort of functions that can tell OpenGL to not include transparent pixels into depth testing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

童话里做英雄 2024-08-09 21:24:24
glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_EQUAL, 1.0f );

这将丢弃所有具有非完全不透明 Alpha 值的像素。这些像素将不会被渲染到 Z 缓冲区。然而,这确实会影响各种 Z 缓冲区管道优化,因此可能会导致严重的速度减慢。仅当您确实也有时才使用它。

glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_EQUAL, 1.0f );

This will discard all pixels with an alpha of anything other than fully opaque. These pixels will, then, not be rendered to the Z-Buffer. This does, however, affect various Z-Buffer pipeline optimisations so it may cause some serious slowdowns. Only use it if you really have too.

野侃 2024-08-09 21:24:24

不,这是不可能的。所有硬件深度测试都是如此。

GL(完整或 ES——以及 D3D)都具有相同的模型——它们按照您指定的多边形的顺序进行绘制。如果在多边形 B 之前绘制多边形 A,并且逻辑上多边形 A 应该在多边形 B 的前面,则不会绘制多边形 B(由深度测试提供)。

解决方案是按照从当前视图原点最远到最近的顺序绘制多边形。令人高兴的是,在 2D 游戏中,这应该只是一种简单的排序(您可能甚至不需要经常这样做)。

在 3D 游戏中,BSP 是这个问题的基本解决方案。

No it's not possible. This is true of all hardware depth testing.

GL (full or ES -- and D3D) all have the same model -- they paint in the order you specify polygons. If you draw polygon A in before polygon B, and logically polygon A should be in front on polygon B, polygon B won't be painted (courtesy of the depth test).

The solution is to draw you polygons in order from farthest to nearest the current view origin. Happily in a 2D game this should just be a simple sort (one you probably won't even need to do very often).

In 3D games BSPs are the basic solution to this issue.

逆夏时光 2024-08-09 21:24:24

如果您使用着色器,可以尝试禁用混合并丢弃 alpha 0 的像素

if(texColor.w == 0.0)
    discard;

if you're using shaders, can try disabling blending and discard the pixels with alpha 0

if(texColor.w == 0.0)
    discard;
习ぎ惯性依靠 2024-08-09 21:24:24

您使用什么类型的混合?

glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

应防止 alpha 为 0 的任何片段写入深度缓冲区。

What type of blending are you using?

glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Should prevent any fragments with alpha of 0 from writing to the depth buffer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文