Dry: Unity Game development Image Texture Compression scheme

Source: Internet
Author: User
Tags python script

Original: HTTP://WWW.JIANSHU.COM/P/F7C3741F22AF

The Unity3d engine handles textures intelligently: Whether you put in png,psd or TGA, they are automatically converted into Unity's own texture2d format .

In the texture2d settings option, you can set different compression formats for different platforms, such as iOS set to Pvrtc4,android platform set to RGBA16, etc.

Well, it's very smart.

However, in some advanced use, some situations are difficult to meet.

For example, we ngui the atlas texture, on the Android platform, using the ETC1 texture +alpha channel graph, the iOS platform, using PVRTC4 textures.

Individual picture texture, require high definition, use RGBA16, but the use of RGBA16 gradient display picture is miserable;

Some require high fidelity, you need to use the highest quality RGBA32 format directly.

Most of the time, with the complex requirements of the project, simple unity texture management has not been able to meet our needs. At this time, we often need to do some extra work.

To summarize my own texture compression scheme:

Policy for texture compression

Hand-Tour development (Android/ios), I will use 3 levels of compression: high-definition uncompressed, medium clear compression, low-definition high compression, 4 methods of compression: RGBA32, RGBA16+DITHERING,ETC1+ALPHA,PVRTC4. Generally enough to cope with most of the demand.

High Definition uncompressed-RGBA32

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/1835687-93cd7864ce9b9f2d.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" Border:0px;vertical-align:middle;height:auto; "alt=" 1240 "/>

Unity RGBA32-High definition uncompressed. png

RGBA32 is equivalent to the original image, the advantages are clear, consistent with the original, the disadvantage is that the memory is very large, for some art requires the best clarity of the picture, is preferred.

Note that some PNG images, which take up a few kilobytes of hard disk, are displayed in unity and become larger. Since unity shows the size of the texture, which is the size of the actual run-time memory, PNG is a compressed display format, so to understand that PNG is similar to the ZIP format, is a compressed file, but at run time will be automatically decompression parsing.

Medium clear in compression-RGBA16 + DitheringRGBA16 + dithering

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/1835687-aa2ad9c3f0e07ded.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" Border:0px;vertical-align:middle;height:auto; "alt=" 1240 "/>

Unity RGBA16, non-dithering gradient picture miserable

Since it is called RGBA16, Nature is the castrated version of RGBA32.
For some of the use of gradient images, from RGBA32 to RGBA16, can clearly see the color cascade changes, such as.

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/1835687-de31189408370f5e.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" Border:0px;vertical-align:middle;height:auto; "alt=" 1240 "/>

Using Floyd Steinberg jitter processing, unless magnified, the naked eye basically see no difference

RGBA16 Advantage, memory consumption is RGBA32 1/2, with the dithering jitter, in the original size of the same definition;

Disadvantage, unity native does not support dithering jitter, need to do their own tools to do the image processing, for the need to enlarge, stretch the picture, dithering jitter support is not good, there will be a very clear sense of grain.

How to perform dithering jitter?

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/1835687-81e518c83fda9b90.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" Border:0px;vertical-align:middle;height:auto; "alt=" 1240 "/>

Texture Packer tool in the image format select Rgba4444,dithering Select Floydsteinberg

In my project, Texturepacker has a very important role, like the UI of the Atlas generation, pre-generated a good square of the iOS PVRTC4 Atlas and non-square Android ETC1 Atlas, scaling the original 50% and so the work is done by Texturepacker.

Similarly, jitter processing of images is also pre-texturepacker using the Floydsteinberg algorithm for image jitter, which is then imported into unity.

Texturepacker provides command-line tools that can be made into automated tools. Concrete methods are not detailed here.

RGB16

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/1835687-2aff61ed971cb8eb.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" Border:0px;vertical-align:middle;height:auto; "alt=" 1240 "/>

Unity RGB16

And RGB16, is mainly aimed at some, without transparent channel, at the same time the width is not 2 of the second side of the picture; For these pictures, using RGB16 can reduce the memory by half, but the effect will be slightly less than RGB32.

Of course, RGB16 can be combined with jitter, but also to improve the display effect, but the same dithering jitter is not friendly to stretch amplification.

Low clear high compression-ETC1+ALPHA/PVRTC4

Many beginners will wonder why the game is often seen in the development of some pictures, need to be set to 2 of the second party? Because such as ETC1, PVRTC4 and so on in memory without decompression, directly supported by the GPU format, memory is very low, and performance efficiency is also the best.

However, relative RGBA32, it can be seen that the quality has decreased.

ETC1

Etc1+alpha is generally used in the Android version of the UI set, ETC1 without transparent channels, so you need to plug in a similarly ETC1 format of the alpha channel diagram. The method is to extract RGB from the original RGBA32 to generate the first ETC1, then extract a channel, fill another ETC1 R channel; When the game runs, shader mixes two ETC1 images.

http://blog.csdn.net/ u010153703/article/details/45502895

later, Because I don't want to generate transparent graphs based on the Unity API, I generate an alpha channel graph method. I use a Python png.py library, which is handled with a Python script:

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_ images/1835687-d8b4991fa9a0ec5b.png?imagemogr2/auto-orient/strip%7cimageview2/2/w/1240 "style=" border:0px; Vertical-align:middle;height:auto; "alt=" 1240 "/>

png.py generate Alpha Chart

To cooperate with Etc1+alpha, you also need shader support, which is referred to directly modify the Ngui unlit/transparent with colored shader.

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/1835687-8185f356b0bd62ea.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" Border:0px;vertical-align:middle;height:auto; "alt=" 1240 "/>

PVRTC4

PVRTC4 is directly supported in unity, but it is important to note that it must be two square squares, which means that the length and width of the two-time side must be equal.

Comparison of several texture formats
format memory consumption mass transparent Two dimensions We recommend the use of the occasion
RGBA32 1 ★★★★★ Yes Without Very High definition requirements
Rgba16+dithering 1/2 ★★★★ Yes Without UI, Avatar, card, no stretch amplification
RGBA16 1/2 ¡ï ★ Yes Without UI, avatar, card, without gradients, color is not rich, need to stretch to enlarge
Rgb16+dithering 1/2 ★★★★ No Without UI, avatar, card, opaque, no stretch amplification
RGB16 1/2 ¡ï ★ No Without UI, avatar, card, opacity, no gradient, no stretch magnification
RGB (ETC1) + Alpha (ETC1) 1/4 ¡ï ★ Yes Need two times, the length of the width is not the same Use as default as possible, and consider using the top format when the quality is not satisfied
RGB (ETC1) 1/8 ¡ï ★ No Need two times, the length of the width is not the same Use as default as possible, and consider using the top format when the quality is not satisfied
PVRTC4 1/8 No Requires two square squares, the same length and width Use as default as possible, and consider using the top format when the quality is not satisfied
  • Memory consumption, compared to RGBA32

  • Quality Star, more is I feel, for reference only

A business project, mixing a variety of texture formats is an unavoidable thing. The project texture is divided into high, medium and low three kinds of quality requirements, is the goal of this scheme.

In the project, it is possible to use graphics formats that are directly supported by GPUs such as ETC1 and PVRTV4, not only for low memory consumption, but also for better performance, and to progressively increase the compression format to meet the needs when quality fails.


Dry: Unity Game development Image Texture Compression scheme

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.