带 DXT5 压缩纹理的 Alpha 通道

发布于 2025-01-01 07:58:29 字数 898 浏览 2 评论 0原文

我在 OS X 上使用 OpenGL 编写了一个测试程序,该程序加载 PNG,使用 libsquish (http://code.google.com/p/libsquish/) 将其在内存中压缩为 DXT5,并为平面提供纹理。

当我上传包含 Alpha 通道的图像,但没有像素具有除完全不透明以外的 Alpha 值时,它会正确显示: https://i.sstatic.net/WlRcD.png

给定相同的图像,但黑色部分被透明替换,这是我得到的输出:https://i.sstatic.net/wOPqA.png

代码不漂亮,它是一个抛出的错误概念证明:

  1. C++ 源代码:http://pastebin.com/m0RqpgUS
  2. 顶点着色器:http://pastebin.com/QyaWCaTk
  3. 片段着色器:http://pastebin.com/KEuFJ83C
  4. 测试图像:http://dl.dropbox.com/u/4597377/images.zip

任何想法?

I've written a test program using OpenGL on OS X that loads a PNG, compresses it in memory to DXT5 using libsquish (http://code.google.com/p/libsquish/), and textures a plane.

When I upload an image that contains an alpha channel, but no pixels have alpha values other than fully opaque, it displays correctly: https://i.sstatic.net/WlRcD.png

Given the same image but the black part is replaced with transparency, this is the output I get: https://i.sstatic.net/wOPqA.png

The code is not pretty, it is a thrown together proof of concept:

  1. The C++ source: http://pastebin.com/m0RqpgUS
  2. The vertex shader: http://pastebin.com/QyaWCaTk
  3. The fragment shader: http://pastebin.com/KEuFJ83C
  4. The test images: http://dl.dropbox.com/u/4597377/images.zip

Any thoughts?

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

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

发布评论

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

评论(1

千柳 2025-01-08 07:58:29

原来我忘记了这一点:

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

Turns out I forgot this:

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