richgel999 / bc7enc

Single source file BC1-5 and BC7 encoders and BC1-5/7 decoders with MIT or Public Domain licenses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Heavy blocking/opaque spots/sawtooth effect in translucent BC7 textures with gradients

Swyter opened this issue · comments

Hi, @richgel999. Thanks for the great compressor and your work along the years.

This issue isn't something new, because AMD Compressonator suffers from the exact same artifacts, and I know some kind of degradation is to be expected. There are format limitations and the RGB part may be eating all the bits.

I find it interesting that, while lower quality, using an older BC3 compressor produces a much more coherent image. Because I don't know if this is an isolated/edge case I figured bringing it up and posting actual samples would help. ¯\_(ツ)_/¯

Here's bc7enc's unpacked alpha:
imagen

Here's the result on a white background:
imagen


Here are the AMD Compressonator 4.0.4855 results, with their staircasing counterparts:
imagen

Or, who knows, maybe I'm using it wrong. The problem doesn't look that ugly on a gray or checkerboard background, but it's really apparent against bright and contrasty gradients.

Between the curve, the sudden color and alpha changes and all the noise these logos may be a tough case. On my end of the content pipeline I think they'll have to live uncompressed for now. They don't pass the quality check.

Here is the original sample in lossless PNG format, as well as both results: bc7enc-bc7-staircasing-sample.zip

I'll also paste the original command-line output in case looking at the PSNR is useful:

Click to expand!
[root@host bc7enc]# ./bc7enc "/mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png"
Source image: /mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Max mode 1 partitions: 64, uber level: 0, perceptual: 1
..
Total time: 0.406250 secs
BC7 mode histogram:
0: 0
1: 3840
2: 0
3: 0
4: 0
5: 5701
6: 118591
7: 2940
Source image had an alpha channel.
Wrote DDS file titleLogoKo.dds
Luma  Max error:  28 RMSE: 0.505616 PSNR 54.05 dB
RGB   Max error: 132 RMSE: 0.819654 PSNR 49.86 dB
RGBA  Max error: 132 RMSE: 0.877833 PSNR 49.26 dB
Red   Max error:  84 RMSE: 0.928404 PSNR 48.78 dB
Green Max error:  30 RMSE: 0.572683 PSNR 52.97 dB
Blue  Max error: 132 RMSE: 0.908624 PSNR 48.96 dB
Alpha Max error:  72 RMSE: 1.032893 PSNR 47.85 dB
Wrote PNG file titleLogoKo_unpacked.png
Wrote PNG file titleLogoKo_unpacked_alpha.png
[root@host bc7enc]# ./bc7enc -l "/mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png"
Source image: /mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Max mode 1 partitions: 64, uber level: 0, perceptual: 0
..
Total time: 0.281250 secs
BC7 mode histogram:
0: 0
1: 3930
2: 0
3: 0
4: 0
5: 5794
6: 118169
7: 3179
Source image had an alpha channel.
Wrote DDS file titleLogoKo.dds
Luma  Max error:  51 RMSE: 0.666306 PSNR 51.66 dB
RGB   Max error:  77 RMSE: 0.786523 PSNR 50.22 dB
RGBA  Max error:  77 RMSE: 0.770818 PSNR 50.39 dB
Red   Max error:  71 RMSE: 0.884945 PSNR 49.19 dB
Green Max error:  65 RMSE: 0.786624 PSNR 50.22 dB
Blue  Max error:  77 RMSE: 0.673759 PSNR 51.56 dB
Alpha Max error:  42 RMSE: 0.721656 PSNR 50.96 dB
Wrote PNG file titleLogoKo_unpacked.png
Wrote PNG file titleLogoKo_unpacked_alpha.png
[root@host bc7enc]# ./bc7enc -3 "/mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png"
Compressing to BC3
Source image: /mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Level: 2, use 3-color mode: 1, use 3-color mode for black: 0, bc1_mode: 0
..
Total time: 0.015625 secs
Source image had an alpha channel.
Wrote DDS file titleLogoKo.dds
Luma  Max error:  60 RMSE: 1.773811 PSNR 43.15 dB
RGB   Max error: 115 RMSE: 2.035485 PSNR 41.96 dB
RGBA  Max error: 115 RMSE: 1.782228 PSNR 43.11 dB
Red   Max error: 109 RMSE: 2.433953 PSNR 40.40 dB
Green Max error:  76 RMSE: 1.977903 PSNR 42.21 dB
Blue  Max error: 115 RMSE: 1.610395 PSNR 43.99 dB
Alpha Max error:  13 RMSE: 0.525112 PSNR 53.73 dB
Wrote PNG file titleLogoKo_unpacked.png
Wrote PNG file titleLogoKo_unpacked_alpha.png
[root@host bc7enc]# ./bc7enc -l "/mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png"
Source image: /mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Max mode 1 partitions: 64, uber level: 0, perceptual: 0
..
Total time: 0.281250 secs
BC7 mode histogram:
0: 0
1: 3930
2: 0
3: 0
4: 0
5: 5794
6: 118169
7: 3179
Source image had an alpha channel.
Wrote DDS file titleLogoKo.dds
Luma  Max error:  51 RMSE: 0.666306 PSNR 51.66 dB
RGB   Max error:  77 RMSE: 0.786523 PSNR 50.22 dB
RGBA  Max error:  77 RMSE: 0.770818 PSNR 50.39 dB
Red   Max error:  71 RMSE: 0.884945 PSNR 49.19 dB
Green Max error:  65 RMSE: 0.786624 PSNR 50.22 dB
Blue  Max error:  77 RMSE: 0.673759 PSNR 51.56 dB
Alpha Max error:  42 RMSE: 0.721656 PSNR 50.96 dB
Wrote PNG file titleLogoKo_unpacked.png
Wrote PNG file titleLogoKo_unpacked_alpha.png
[root@host bc7enc]# ./bc7enc -u4 -p64 "/mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png"
Source image: /mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Max mode 1 partitions: 64, uber level: 4, perceptual: 1
..
Total time: 1.484375 secs
BC7 mode histogram:
0: 0
1: 3862
2: 0
3: 0
4: 0
5: 4468
6: 119614
7: 3128
Source image had an alpha channel.
Wrote DDS file titleLogoKo.dds
Luma  Max error:  28 RMSE: 0.478694 PSNR 54.53 dB
RGB   Max error: 130 RMSE: 0.802323 PSNR 50.04 dB
RGBA  Max error: 130 RMSE: 0.860766 PSNR 49.43 dB
Red   Max error:  84 RMSE: 0.915708 PSNR 48.90 dB
Green Max error:  30 RMSE: 0.533199 PSNR 53.59 dB
Blue  Max error: 130 RMSE: 0.899079 PSNR 49.05 dB
Alpha Max error:  72 RMSE: 1.016124 PSNR 47.99 dB
Wrote PNG file titleLogoKo_unpacked.png
Wrote PNG file titleLogoKo_unpacked_alpha.png

Let me know if I can help, and thanks again.

By the way, I almost forgot. But here's what (for example) Compressonator outputs with the highest quality BC3:
imagen

From what remember they are comparable to what bc7enc outputs in that mode. In this case the slight blurriness is almost beneficial. I wonder if the alpha being uncorrelated in BC3 helps a bit. Or maybe it's just due to the years of compressor fine-tuning for these older (and more common) formats.

titleLogoKo_PNG_BC3_2.dds.zip

Here are the bc7enc results at the highest quality mode, maybe there's some extra ringing, which is to be expected, but in any case it's surprising that the perceptive BC3 result is still leaps and bounds ahead of BC7:
imagen

Click to expand!
[root@host bc7enc]# ./bc7enc -3 -u5 "/mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png" out_bc3.dds out_bc3.png
Compressing to BC3
Source image: /mnt/c/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Level: 2, use 3-color mode: 1, use 3-color mode for black: 0, bc1_mode: 0
..
Total time: 0.015625 secs
Source image had an alpha channel.
Wrote DDS file out_bc3.dds
Luma  Max error:  60 RMSE: 1.773811 PSNR 43.15 dB
RGB   Max error: 115 RMSE: 2.035485 PSNR 41.96 dB
RGBA  Max error: 115 RMSE: 1.782228 PSNR 43.11 dB
Red   Max error: 109 RMSE: 2.433953 PSNR 40.40 dB
Green Max error:  76 RMSE: 1.977903 PSNR 42.21 dB
Blue  Max error: 115 RMSE: 1.610395 PSNR 43.99 dB
Alpha Max error:  13 RMSE: 0.525112 PSNR 53.73 dB
Wrote PNG file out_bc3.png
Wrote PNG file out_bc3_alpha.png

Resulting file: bc7enc-bc3-looks-okay.zip

Same thing, white background:
imagen

Yes - you have identified BC7's key weakness. All encoders I've tried will suffer from this problem with alpha channels. BC3 won't because it always separately encodes alpha.

There is a feature in BC7E that you can try that may help:
uint32_t m_mode67_error_weight_mul[4];

See the info in the README file. I will expose these options to the command line tool when I work on it again.

To use this feature, after you call one of the profile selection functions
(bc7e_compress_block_params_init_basic() etc.), you can optionally set the
values in the "m_alpha_settings.m_mode67_error_weight_mul[]" array.

This array contains a per-component error weight multiplier that's
only used in modes 6/7. This allows you to deemphasize the usage of the
correlated alpha modes (6/7). These modes can cause blockiness in either RGB or
A on highly uncorrelated textures containing complex alpha channels. To use
this, I would first start with setting the RGB (first 3 array values) to 3,3,3
or 5,5,5 and test the results.

Setting these values higher than 1 will cause the encoder to use modes 4/5 more
often on alpha blocks. This will result in higher overall PSNR/SSIM error, but
hopefully less blockiness.

Thanks for the detailed response, @richgel999. Makes a lot of sense.

Looks like even vanilla bc7e reduces blocking vs. bc7enc, tried both modes and while there's still some visible acne going on and the blocks are still sort of visible this is much more bearable for an important asset like these logos, even with the RGB degradation.

imagen
imagen
imagen

Here's the command-line and output with the various stats:

Click to expand!
C:\Users\Usuario\Documents\github\bc7e\bin>bc7enc -u6 "c:/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png" test_bc7enc.dds test_bc7enc.png
Source image: c:/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Level: 6, Perceptual: 1
....
Total time: 0.236000 secs
Wrote DDS file test_bc7enc.dds
Luma  Max error:  41 RMSE: 0.598126 PSNR 52.59 dB
RGB   Max error: 132 RMSE: 0.894573 PSNR 49.10 dB
RGBA  Max error: 132 RMSE: 0.803197 PSNR 50.03 dB
Alpha Max error:  34 RMSE: 0.423931 PSNR 55.58 dB
Wrote PNG file test_bc7enc.png
Wrote PNG file test_bc7enc_alpha.png

C:\Users\Usuario\Documents\github\bc7e\bin>bc7enc -u6 -l "c:/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png" test_bc7enc_l.dds test_bc7enc_l.png
Source image: c:/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Level: 6, Perceptual: 0
....
Total time: 0.359000 secs
Wrote DDS file test_bc7enc_l.dds
Luma  Max error:  38 RMSE: 0.567324 PSNR 53.05 dB
RGB   Max error:  70 RMSE: 0.664130 PSNR 51.69 dB
RGBA  Max error:  70 RMSE: 0.654958 PSNR 51.81 dB
Alpha Max error:  38 RMSE: 0.626635 PSNR 52.19 dB
Wrote PNG file test_bc7enc_l.png
Wrote PNG file test_bc7enc_l_alpha.png

C:\Users\Usuario\Documents\github\bc7e\bin>bc7enc-333 -u6 "c:/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png" test_bc7enc_333.dds test_bc7enc_333.png
Source image: c:/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Level: 6, Perceptual: 1
....
Total time: 0.228000 secs
Wrote DDS file test_bc7enc_333.dds
Luma  Max error:  38 RMSE: 0.625938 PSNR 52.20 dB
RGB   Max error: 132 RMSE: 1.002251 PSNR 48.11 dB
RGBA  Max error: 132 RMSE: 0.898084 PSNR 49.06 dB
Alpha Max error:  25 RMSE: 0.461187 PSNR 54.85 dB
Wrote PNG file test_bc7enc_333.png
Wrote PNG file test_bc7enc_333_alpha.png

C:\Users\Usuario\Documents\github\bc7e\bin>bc7enc-555 -u6 "c:/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png" test_bc7enc_555.dds test_bc7enc_555.png
Source image: c:/Users/Usuario/Documents/Sphinx/trunk/Sphinx/Binary/_bin_PC___mixed_up_64_and_32_bits/texoverrides/titleLogoKo.png 2048x1024
Level: 6, Perceptual: 1
....
Total time: 0.238000 secs
Wrote DDS file test_bc7enc_555.dds
Luma  Max error:  38 RMSE: 0.663446 PSNR 51.69 dB
RGB   Max error: 132 RMSE: 1.067595 PSNR 47.56 dB
RGBA  Max error: 132 RMSE: 0.954905 PSNR 48.53 dB
Alpha Max error:  24 RMSE: 0.477598 PSNR 54.55 dB
Wrote PNG file test_bc7enc_555.png
Wrote PNG file test_bc7enc_555_alpha.png

Here are the resulting test files, for completeness: bc7e-vanilla-and-weighted-333-555-results.zip

imagen
imagen

I'll think for a bit about these artifacts, maybe I'll try steeper weights. In the worst case I'll pay the price and store the alpha separately, or something. In any case I have learnt a thing or two today, that's for sure. It's been instructive.

Sorry, my comment was for BC7E:
https://github.com/BinomialLLC/bc7e

This is my best BC7 encoder.

Yeah, and even vanilla bc7e is a big improvement. That's what I used in the examples above. :)

The Windows executable is still called bc6enc, though. Maybe it's worth clarifying the relationship between both projects now that the full-featured one is public, the demo and the nifty ISPC one. ¯\_(ツ)_/¯