etc2 纹理压缩_ETC纹理的紧缩压缩

etc2 纹理压缩

This blog post describes the basics of Crunch compression and explains in details how the original Crunch algorithm was modified in order to be able to compress ETC1 and ETC2 textures.

这篇博客文章描述了Crunch压缩的基础知识,并详细说明了如何修改原始的Crunch算法以能够压缩ETC1和ETC2纹理。

紧缩简介:压缩DXT纹理。 (Introduction to Crunch: Compressing DXT textures.)

Crunch is an open source texture compression library © Richard Geldreich, Jr. and Binomial LLC, available on GitHub. The library was originally designed for compression of DXT textures. The following section describes the main ideas used in the original algorithm.

Crunch是一个开源纹理压缩库©Richard Geldreich,Jr.和Binomial LLC, 可在GitHub上找到 。 该库最初是为DXT纹理压缩而设计的。 以下部分描述了原始算法中使用的主要思想。

DXT编码 (DXT Encoding)

DXT is a block-based texture compression format. The image is split up into 4×4 blocks, and each block is encoded using a fixed number of bits. In case of DXT1 format (used for compression of RGB images), each block is encoded using 64 bits. Information about each block is stored using two 16-bit color endpoint values (color0 and color1), and 16 2-bit selector values (one selector value per pixel) which determine how the color of each pixel is computed (it can be either one of the two endpoint colors or a blend between them). According to the DXT1 compression format, there are two different ways to blend the endpoint colors, depending on which endpoint color has higher value. However, Crunch algorithm uses a subset of DXT1 encoding (endpoint colors are always ordered in such a way that color0 >= color1). Therefore, when using Crunch compression, endpoint colors are always blended in the following way:

DXT是基于块的纹理压缩格式。 图像被分成4×4的块,并且每个块使用固定数量的位进行编码。 在DXT1格式(用于RGB图像压缩)的情况下,每个块使用64位编码。 使用两个16位颜色端点值( color0color1 )和16个2位选择器值(每个像素一个选择器值)存储有关每个块的信息,这些值确定如何计算每个像素的颜色(可以是一个两种端点颜色或它们之间的混合)。 根据DXT1压缩格式,有两种不同的方法可以混合端点颜色,具体取决于哪种端点颜色具有更高的值。 但是,Crunch算法使用DXT1编码的子集(端点颜色始终以color0> = color1的方式排序 )。 因此,在使用Crunch压缩时,端点颜色始终以以下方式混合:

selector value pixel color
0 color0
1 color1
2 (2 * color0 + color1) / 3
3 (color0 + 2 * color1) / 3
选择器值 像素颜色
0 颜色0
1个 颜色1
2 (2 * color0 + color1)/ 3
3 (color0 + 2 * color1)/ 3

DXT encoding can therefore be visually represented in the following way:

DXT编码因此可以通过以下方式直观地表示:

color0 (RGB565)
16 bits/block
color1 (RGB565)
16 bits/block
selectors
2 bits/pixel
decoded DXT
4 bits/pixel
color0(RGB565)
16位/块
color1(RGB565)
16位/块
选择器
2位/像素
解码DXT
4位/像素

Each pixel can be decoded by merging together color0 and color1 values according to the selector value.

可以通过根据选择器值将color0color1值合并在一起来解码每个像素。

For simplicity, information about color0 and color1 can be displayed on the same image (with the upper part of every 4×4 block filled with color0 and the lower part filled with color1). Then all the information necessary for decoding the final texture can be represented in a form of the following 2 images (4×4 blocks are displayed slightly separated from each other):

为简单起见,有关color0color1的信息可以显示在同一图像上(每4×4块的上部填充有color0 ,下部填充有color1 )。 然后,可以用以下2个图像的形式表示解码最终纹理所需的所有信息(显示4×4块,彼此之间稍微分开):

color endpoints
32 bits/block
color selectors
32 bits/block
颜色端点
32位/块
颜色选择器
32位/块

平铺 (Tiling)

For an average texture it is quite common that neighbor blocks have similar endpoints. This property can be used to improve the compression ratio. In order to achieve this, Crunch introduces the concept of “chunks”. All the texture blocks are split into “chunks” of 2×2 blocks (the size of each chunk is 8×8 pixels), and each chunk is associated with one of the following 8 chunk types:

对于平均纹理,邻居块具有相似的端点是很常见的。 此属性可用于提高压缩率。 为了实现这一目标,Crunch引入了“块”的概念。 所有纹理块均被分为2×2块的“块”(每个块的大小为8×8像素),并且每个块与以下8个块类型之一相关联:

Of course, the described chunk types don’t cover all the possible combinations of matching endpoints, but at the same time, this way the information about the matching endpoints can be encoded very efficiently. Specifically, encoding of the chunk type requires 3 bits per 4 blocks (0.75 bits per block, uncompressed).

当然,所描述的块类型并不能涵盖匹配端点的所有可能组合,但是与此同时,通过这种方式,可以非常高效地编码有关匹配端点的信息。 具体来说,块类型的编码需要每4块3位(每块0.75位,未压缩)。

Crunch algorithm can enforce the neighbor blocks within a chunk to have identical endpoints in cases when extra accuracy of the encoded colors isn’t worth spending extra bits for encoding of additional endpoints. This is achieved in the following way. First, each chunk is encoded in 8 different ways, corresponding to the described 8 chunk types (instead of using DXT1 optimization for each block, the algorithm is using DXT1 optimization for each tile). The quality of each encoding is then evaluated as the PSNR multiplied by a coefficient associated with the used chunk type, and the optimal encoding is selected. The trick here is that chunk types with higher number of matching endpoints also have higher quality coefficients. In other words, if using the same endpoint for two neighbor blocks within a chunk doesn’t reduce the PSNR much, then the algorithm will most likely select the chunk type where those neighbor blocks belong to the same tile. The described process can be referenced as “tiling”.

当编码颜色的额外精度不值得花费额外的比特来编码其他端点时,Crunch算法可以强制块内的相邻块具有相同的端点。 这可以通过以下方式实现。 首先,以与所描述的8种块类型相对应的8种不同方式对每个块进行编码(算法不是对每个块使用DXT1优化,而是对每个图块使用DXT1优化)。 然后,将每种编码的质量评估为PSNR乘以与所使用的块类型相关联的系数,然后选择最佳编码。 这里的技巧是,具有更高数量的匹配端点的块类型也具有更高的质量系数。 换句话说,如果对块内的两个相邻块使用相同的端点不会大大降低PSNR,则算法将最有可能选择那些相邻块属于同一图块的块类型。 所描述的过程可以称为“平铺”。

量化 (Quantization)

The basic idea of Crunch compression is to perform quantization of the determined endpoints and selectors blocks, in order to encode them more efficiently. This is achieved using vector quantization. The idea is similar to color quantization, when a color image is represented using a color palette and palette indices defined for each pixel.

紧缩压缩的基本思想是对确定的端点和选择器块执行量化,以便更有效地对其进行编码。 这是使用矢量量化实现的。 当使用调色板和为每个像素定义的调色板索引表示彩色图像时,该想法类似于颜色量化。

In order to perform vector quantization, each endpoint pair should be represented with a vector. For example, it is possible represent a tile endpoint pair with a vector (color0.r, color0.g, color0.b, color1.r, color1.g, color1.b), where color0 and color1 are obtained from DXT1 optimization. However, such representation doesn’t reflect the continuity properties of the source texture very well (for example, in case of a solid block, a small change of the block color might result in significant change of the optimal color0 and color1, which are used to encode this color). Instead, Crunch algorithm is using a different representation. Source pixels of each tile, which are represented by their (r, g, b) vectors, are split into 2 clusters using vector quantization, providing two centroids for each tile: low_color and high_color. Then the endpoints of each tile are represented with a (low_color.r, low_color.g, low_color.b, high_color.r, high_color.g, high_color.b) vector. Such representation of the tile endpoints doesn’t depend on the DXT1 optimization result, but at the same time performs quite well.

为了执行矢量量化,每个端点对应该用一个矢量表示。 例如,可能用矢量(color0.r,color0.g,color0.b,color1.r,color1.g,color1.b)表示图块端点对,其中color0color1是从DXT1优化获得的。 但是,这种表示不能很好地反映源纹理的连续性(例如,在实心块的情况下,块颜色的微小变化可能会导致所使用的最佳color0color1发生重大变化。编码这种颜色)。 相反,Crunch算法使用其他表示形式。 使用矢量量化将每个图块的源像素(由其(r,g,b)矢量表示)分成两个簇,为每个图块提供两个质心: low_colorhigh_color 。 然后,用(low_color.r,low_color.g,low_color.b,high_color.r,high_color.g,high_color.b)向量表示每个图块的端点。 瓦片端点的这种表示方式不依赖于DXT1优化结果,但同时表现得很好。

Note that after quantization all the blocks within a tile will be associated with the same endpoint codebook element, so they will get assigned the same endpoint index. This means that initially determined chunk types will be still valid after endpoint quantization.

请注意,量化后,图块中的所有块将与相同的端点码本元素相关联,因此将为它们分配相同的端点索引。 这意味着在端点量化之后,最初确定的块类型将仍然有效。

Selectors of each 4×4 block can be represented with a vector of 16 components, corresponding to the selector values of each block pixel. In order to improve the result of the quantization, selector values are reordered in the following way, in order to better reflect the continuity of the selected color values:

每个4×4块的选择器可以用16个分量的向量表示,与每个块像素的选择器值相对应。 为了改善量化结果,选择器值以以下方式重新排序,以便更好地反映所选颜色值的连续性:

linear selector value pixel color
0 color0
1 (2 * color0 + color1) / 3
2 (color0 + 2 * color1) / 3
3 color1
线性选择器值 像素颜色
0 颜色0
1个 (2 * color0 + color1)/ 3
2 (color0 + 2 * color1)/ 3
3 颜色1

Vector quantization algorithm splits all the input vectors into separate groups (clusters) in such a way so that vectors in each group appear to be more or less similar. Each group is represented by its centroid, which is computed as an average of all the vectors in the group according to the selected metric. The computed centroid vectors are then used to generate the codebook (centroid vector components are clipped and rounded to integers in order to represent valid endpoints or selectors). The original texture elements are then replaced with the elements of the computed codebooks (endpoints for each source 4×4 block are replaced with the closest endpoint pair from the generated endpoint codebook, selectors for each source 4×4 block are replaced with the selector values of the closest selector codebook element).

向量量化算法将所有输入向量分成不同的组(簇),以使每组中的向量看起来或多或少相似。 每个组由其质心表示,质心根据所选度量计算为该组中所有矢量的平均值。 然后,将计算出的质心向量用于生成码本(质心向量分量被裁剪并舍入为整数,以表示有效的端点或选择器)。 然后,将原始纹理元素替换为计算后的代码簿的元素(将每个源4×4块的端点替换为生成的端点代码本中最接近的端点对,将每个源4×4块的选择器替换为选择器值最接近的选择器代码簿元素的元素)。

The result of vector quantization performed for both endpoints and selectors can be represented in the following way:

对端点和选择器执行的矢量量化的结果可以用以下方式表示:


endpoint codebook:

selector codebook:
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值