在 DDS 文件中,您可以检测具有 0/1 alpha 位的纹理吗?
在我的引擎中,我需要能够检测具有 0 alpha 纹理像素的 DXT1 纹理(例如窗框的切口)。 这对于我自己压缩的纹理来说很容易,但我不确定已经压缩的纹理。
有没有一种简单的方法可以从标题中判断 DDS 图像是否包含 alpha?
In my engine I have a need to be able to detect DXT1 textures that have texels with 0 alpha (e.g. a cutout for a window frame). This is easy for textures I compress myself, but I'm not sure about textures that are already compressed.
Is there an easy way to tell from the header whether a DDS image contains alpha?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我同意已接受的答案。 通过使用“squish”库为您解压缩块,您的工作可能会变得更容易一些。
http://www.sjbrown.co.uk/?code=squish
I agree with the accepted answer. Your job may be made a bit easier by using the "squish" library to decompress the blocks for you.
http://www.sjbrown.co.uk/?code=squish
DDS 是一个非常差的 DXT(或 BTC)数据包装器。 标题不会帮助你。
普通原始 DXT1 没有任何 alpha。 我相信现在 d3d 实际上确实可以用 alpha 解码 DXT1。 每个 DXT1 块如下所示:颜色 1(16 位)颜色 2(16 位)索引(32 位)。 如果 16 位 color1 值小于 color2(只是 uint16 比较,没什么花哨的!)该块没有 alpha。 否则就是这样。 所以回答你的问题:跳过标题,读取16位a,读取16位b,如果a>b则有alpha。 否则跳过 32 位并重复直到 eof。 其他 DXT 格式(例如 DXT5)始终具有 Alpha。 人们很少依赖 DXT1 alpha 技巧,因为某些硬件(英特尔..)不可靠地支持它。
DDS is a very poor wrapper for DXT (or BTC) data. The header will not help you.
Plain original DXT1 did not have any alpha. I believe d3d nowadays does actually decode DXT1 with alpha though. Every DXT1 block looks like this: color1(16 bits) color2(16 bits) indices(32 bits). If the 16 bit color1 value is less than color2 (just a uint16 comparison, nothing fancy!) the block has no alpha. Otherwise it does. So to answer you question: Skip the header, read 16 bits a, read 16 bits b, if a>b there is alpha. otherwise skip 32 bits and repeat until eof. Other DXT formats like DXT5 always have alpha. It is very rare that people rely on the DXT1 alpha trick because some hw (intel..) does not support it reliably.
据我所知,从标题中无法判断。 有一个 DDPF_ALPHAPIXELS 标志,但我认为它不会根据像素数据中的内容进行设置。 您需要解析 DXT1 块,并查找其中 alpha 为 0 的颜色(我想,请务必检查块中实际使用的颜色)。
As far as I know, there's no way to tell from the header. There's a DDPF_ALPHAPIXELS flag, but I don't think that will get set based on what's in the pixel data. You'd need to parse the DXT1 blocks, and look for colours that have 0 alpha in them (making sure to check that the colour is actually used in the block, too, I suppose).
不,DDS 标头仅对未压缩图像使用 alpha 标志。 我也有类似的需求来确定 DXT1 图像是否使用 1 位 alpha,经过长时间的搜索,我在这里发现了此参考: https://msdn.microsoft.com/en-us/library/windows/desktop/bb147243(v=vs.85 ).aspx
基本上,如果 color_0 <= color_1 则纹理有可能具有 1 位 Alpha。 为了进一步验证它,您需要检查 2 位对中的下一个 32 位是否为 11。如果没有找到,则对每个块继续此操作。
No, the DDS header only uses alpha flags for uncompressed images. I had a similar need to figure out if a DXT1 image was using 1-bit alpha and after a long search I came across this reference here: https://msdn.microsoft.com/en-us/library/windows/desktop/bb147243(v=vs.85).aspx
Basically if color_0 <= color_1 then there is a possibility the texture has 1-Bit alpha. To further verify it, you need to check the next 32-bits in 2-bit pairs if they are 11. Then continue this for every block if not found.