Wednesday, May 30, 2018

xmen_1024 encoded to .basis at various bitrates

Here's xmen_1024 compressed at various bitrates to .basis. I show the output of two transcodes: ETC1 (which is the highest quality format in baseline .basis) and PVRTC (with clamp addressing).

Original:

Optimal ETC1 is 38.896 Y PSNR

Q 16: .717 bits/texel, ETC1 28.473 Y PSNR

ETC1:
PVRTC:

Q 64: .905 bits/texel, ETC1: 30.361 Y PSNR

ETC1:

PVRTC:

Q 128: 1.064 bits/texel, ETC1: 32.026 Y PSNR

ETC1:

PVRTC:

Q 192: 1.208 bits/texel, ETC1: 30.379 Y PSNR

ETC1:

 PVRTC:

Q 255: 1.362 bits/texel, ETC1: 34.630 Y PSNR

ETC1:
 PVRTC:

Basis universal GPU texture format examples

The .basis format is a lossy texture compression format roughly comparable to JPEG in size but designed specifically for GPU texture data. The format's main feature is that it can be efficiently transcoded to any other GPU texture format. We've written transcoders for BC1-5, ETC1, PVRTC, and BC7 so far. ASTC, ETC2 are coming. Transcoding complexity is similar to crunch's (my older open source texture compression tech for BC1-5). This is the first system to support a universal GPU texture format that is usable on the Web.

Excluding PVRTC, there are no complex pixel-level operations needed during transcoding. The transcoder's inner loop works at the block level (or 2x2 macroblock level) and involves simple operations (Huffman decoding, table lookups, endpoint/selector translation using small precomputed lookup tables). The PVRTC transcoder requires two passes and a temporary buffer to hold block endpoints. The PVRTC transcoder in this system is faster and simpler than any real-time PVRTC encoder I'm aware of.

I resized the kodim images to 512x512 (using a gamma correct windowed sinc filter) so they can be transcoded to PVRTC which only supports power of 2 texture dimensions. Resizing these textures to 512 actually makes these images more difficult to compress because the details are more dense spatially and artifacts stand out more.

The current single-threaded transcode times (for kodim01) on my 3.3GHz Xeon were:

ETC1 transcode time: 1.199494 ms
DXT1 transcode time: 2.198336 ms
BC7 transcode time: 2.801654 ms
DXT5A transcode time: 2.361919 ms
PVRTC1_4 transcode time: 2.756762 ms

These timings will get better as I optimize the transcoders. crunch's transcoding speed is roughly similar to .basis ETC1. The transcoder is usable on Web by cross compiling it to Javascript or WebAssembly.

For transparency support we internally store two texture slices, one for RGB and another for alpha. For ETC1 with alpha the user can either transcode to a texture twice as wide or high or use two separate textures. We support BC3-5 directly. For BC7, we currently only support opaque mode 6, but mode 4 or 5 is coming. For PVRTC we only support opaque 4bpp, but we know how to add alpha. PVRTC 2bpp opaque/alpha is also doable. ETC2 alpha block support will be easy.

These images are at quality level 255, around 1.5-2 bits/texel. The biggest quality constraint right now is the ETC1S format that these "baseline" .basis files use internally. Our plan is to add some optional extra texture data to the files to upgrade the quality for BC7/ASTC.

Some notable properties of this system:
  • This system is intended for Web use. It's a delicate balance between transcode times, quality, GPU format support, and encoder complexity. The transcoder step must be much faster than just using JPEG (or WebP, etc.) followed by a real-time GPU texture encoder, or it's not valuable. This system is basically existence proof that it's possible to build a universal GPU texture compression system. Long term, much higher quality solutions are possible.
  • This format trade offs quality to gain access to all GPU's and API's without having to store/distribute multiple files or encode multiple times. Quality isn't that great but it's very usable on photos, satellite photography, and rasterized map images. For some games it may not be acceptable, which is fine. The largest users of crunch aren't games at all.
  • The internal baseline format uses a subset of ETC1 (ETC1S), so transcoding to ETC1 is fastest. ETC1 is highest quality, followed by BC7, BC1, then PVRTC. The difference between ETC1 and BC1 is .1-.4 dB Y PSNR (slightly better for BC7). 
  • This system isn't full ETC1 quality because it disables 2x4/4x2 subblocks. We loose a few dB vs. optimal ETC1 due to this limitation, but we gain the ability to easily transcode to any other 4x4 block-based format. In a rate distortion sense using PSNR or SSIM full ETC1 support rarely makes sense in our testing anyway (i.e. there are almost always better uses of those bits vs. supporting flips or 4:4:4 individual mode colors).
  • Using ETC1S as an internal format allowed us to reuse our existing ETC1 encoder. It also allows others to easily build their own universal format encoders by re-purposing their existing ETC1 solutions. There's a large amount of value in a system that will work on any GPU or API, and we can improve the quality over time by extending it.
  • The PVRTC endpoint interpolation actually smooths out the ETC1 artifacts in a "nice" looking way. The PVRTC artifacts are definitely worse than any other format. The .basis->PVRTC transcoder favors speed and reliable behavior, not PSNR/SSIM. There are noticeable banding and low-pass artifacts. (Honestly, PVRTC is an unforgiving format and I'm surprised it looks as good as it does!) It should be possible to add dithering or smarter endpoint selection, but that would substantially slow transcoding down.
  • We have a customer using .basis ETC1 with normal maps on mobile, so I know they are usable. I doubt PVRTC would work well with normal maps, but the other formats should be usable.
  • Grayscale conversion is easy: we just convert the G channel. For DXT5/BC3 or BC7 we call the transcoder twice (once for RGB then again for alpha).
  • Newer iOS devices support ETC1 in hardware, but WebGL on iOS doesn't expose this format on these devices so we must support PVRTC. We weren't originally going to support PVRTC, but we had to due to this issue.
  • The PVRTC transcoder and decoder assumes wrap addressing is enabled, for compatibility with PVRTexTool. This can be disabled (and you can use clamp addressing when fetching from the shader). This can sometimes cause issues on the very edges of the texture (see the bottom of the xmen image, or the bottom of the hramp at the end).
  • Look at these images on your phone or tablet before making any quality judgments. On a iPhone even really low .basis quality levels can look surprisingly good. Vector quantization+GPU block compression artifacts are just different from JPEG's artifacts. 
Original:
 BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:

Original:
 BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:

Original:
 BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:


BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:

BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
 BC7:
 DXT1:
 DXT5A:
 ETC1:
 PVRTC:
BC7:
 DXT1:
 DXT5A:
 ETC1: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