Unity Texture 讲解 翻译自官方文档
支持的格式
Unity can read the following file formats:
- BMP
- EXR
- GIF
- HDR
- IFF
- JPG
- PICT
- PNG
- PSD
- TGA
- TIFF
HDR Textures
When importing from an EXR or HDR file containing HDR information, the Texture Importer automatically chooses the right HDR format for the output Texture. This format changes automatically depending on which platform you are building for.
- 当从包含HDR信息的EXR或HDR文件导入时,纹理导入器自动为输出纹理选择正确的HDR格式。这种格式会根据您为哪个平台构建而自动更改。
Texture dimension sizes
Ideally, Texture dimension sizes should be powers of two on each side (that is, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 pixels (px), and so on). The Textures do not have to be square; that is the width can be different from height. Note that specific platforms may impose maximum Texture dimension sizes. For DirectX, the maximum Texture sizes for different feature levels are as follows:
- 理想情况下,纹理尺寸应该是每边2的幂(即,2、4、8、16、32、64、128、256、512、1024、2048像素,等等)。纹理不必是方形的;也就是说宽度可以和高度不同。注意,特定的平台可能会有最大的纹理尺寸限制。对于DirectX,不同特征层的最大纹理大小如下:
Graphics APIs / Feature levels |
Maximum 2D and Cubemap texture dimension size (px) |
DX9 Shader Model 2 (PC GPUs before 2004) / OpenGL ES 2.0 |
2048 |
DX9 Shader Model 3 (PC GPUs before 2006) / Windows Phone DX11 9.3 level / OpenGL ES 3.0 |
4096 |
DX10 Shader Model 4 / GL3 (PC GPUs before 2007) / OpenGL ES 3.1 |
8192 |
DX11 Shader Model 5 / GL4 (PC GPUs since 2008) |
16384 |
Notes:
The Texture Importer only allows you to choose dimension sizes up to 8K (that is 8192 x 8192 px).
- Texture Importer只允许选择尺寸不超过8K的尺寸(即8192 x 8192 px)
Mali-Txxx GPUs (See Wikipedia) and OpenGL ES 3.1 (www.opengl.org) only support up to 4096px Texture dimension size for cubemaps.
- 对于cubemaps, Mali-Txxx gpu(参见Wikipedia)和OpenGL ES 3.1 (www.opengl.org)只支持高达4096px的纹理尺寸
It is possible to use NPOT (non-power of two) Texture sizes with Unity; however, NPOT Texture sizes generally take slightly more memory and might be slower for the GPU to sample, so it’s better for performance to use power of two sizes whenever you can. If the platform or GPU does not support NPOT Texture sizes, Unity scales and pads the Texture up to the next power of two size. This process uses more memory and makes loading slower (especially on older mobile devices). In general, you should only use NPOT sizes for GUI purposes.
You can scale up NPOT Texture Assets at import time using the Non Power of 2 option in the Advanced section of the Texture Importer.
- 简述:应该尽量用POT(2的次幂),NPOT会占用更大的内存,GPU读取速度也更慢。如果是在一些老旧的不支持NPOT的设备上,Unity还会把它扩大到最接近的2的次幂上,这一行为会浪费更多内存。Unity的Non Power of 2选项可以在编辑器里提前完成修改为2的次幂的行为,但是测试来看不支持Sprite
UV mapping
When mapping a 2D Texture onto a 3D model, your 3D modelling application does a type of wrapping called UV mapping. Inside Unity, you can scale and move the Texture using Materials
. Scaling normal and detail maps is especially useful.
- 2D图片映射到3D模型上,这种图片称为UV mapping
Mip maps
Mip maps are lists of progressively smaller versions of an image, used to optimise performance on real-time 3D engines. Objects that are far away from the Camera use smaller Texture versions. Using mip maps uses 33% more memory, but not using them can result in a huge performance loss. You should always use mip maps for in-game Textures; the only exceptions are Textures that are made smaller (for example, GUI textures, Skybox
, Cursors and Cookies). Mip maps are also essential for avoiding many forms of Texture aliasing and shimmering.
- mipmaps是一个图像的不断缩小的版本列表,用于优化实时3D引擎的性能。远离相机的物体使用更小的纹理版本。使用mipmaps会多占用33%的内存,但是不使用它们会导致巨大的性能损失。在游戏中应该始终使用mipmaps;唯一的例外是纹理变得更小(例如,GUI纹理、Skybox、游标和cookie)。mipmaps对于避免多种形式的纹理混叠和闪烁也是必不可少的。
Normal maps
Normal maps are used by normal map Shaders to make low-polygon models look as if they contain more detail. Unity uses normal maps encoded as RGB images. You also have the option to generate a normal map from a grayscale height map image.
- 法线贴图着色器使用法线贴图使低多边形模型看起来像是包含了更多的细节。Unity使用编码为RGB图像的法线贴图。您还可以选择从灰度高度映射图像生成法线映射
Detail maps
If you want to make a Terrain, you normally use your main Texture to show areas of terrain such as grass, rocks and sand. If your terrain is large, it may end up very blurry. Detail Textures hide this fact by fading in small details as your main Texture gets closer.
When drawing Detail Textures, a neutral gray is invisible, white makes the main Texture twice as bright, and black makes the main Texture completely black.
See documentation on Secondary Maps (Detail Maps) for more information.
- 如果你想创建一个地形,你通常使用你的主要纹理来显示地形的区域,比如草,岩石和沙子。如果你的地形很大,它可能会非常模糊。Detail Textures 用于解决这一问题,原理我看不懂,以后看。。
Reflections (cubemaps)
To use a Texture for reflection maps (for example, in Reflection Probes
or a cubemapped Skybox, set the Texture Shape to Cube. See documentation on Cubemap Textures for more information.
- Reflections和天空和以后看。。
Anisotropic filtering
Anisotropic filtering increases Texture quality when viewed from a grazing angle. This rendering
is resource-intensive on the graphics card. Increasing the level of Anisotropy is usually a good idea for ground and floor Textures. Use Quality settings to force anisotropic filtering for all Textures or disable it completely.
- 从掠入射角度看(就是贴着看),Anisotropic filtering提高了纹理质量。这种渲染在显卡上是资源密集型的(大量消耗性能)。增加Anisotropic filtering的水平通常对于地面纹理有好处。可以在Quality settings中设置Anisotropic filtering
Texture compression formats for platform-specific overrides
The following table shows the default formats used for each platform.
- 下表是Unity默认情况下选择的压缩格式
Platform |
Color model |
None |
Normal quality (Default) |
High quality |
Low quality (higher performance) |
Windows, Linux, macOS, PS4, XBox One |
RGB |
RGB 24 bit |
RGB Compressed DXT1 |
RGB(A) Compressed BC7 |
RGB Compressed DXT1 |
RGBA |
RGBA 32 bit |
RGBA Compressed DXT5 |
RGB(A) Compressed BC7 |
RGBA Compressed DXT5 |
|
HDR |
RGBA Half |
RGB Compressed BC6H |
RGB Compressed BC6H |
RGB Compressed BC6H |
|
WebGL |
RGB |
RGB 24 bit |
RGB Compressed DXT1 |
RGB Compressed DXT1 |
RGB Compressed DXT1 |
RGBA |
RGBA 32 bit |
RGBA Compressed DXT5 |
RGBA Compressed DXT5 |
RGBA Compressed DXT5 |
|
Android (default subTarget) |
RGB |
RGB 24 bit |
RGB Compressed ETC |
RGB Compressed ETC |
RGB Compressed ETC |
RGBA |
RGBA 32 bit |
RGBA Compressed ETC2 |
RGBA Compressed ETC2 |
RGBA Compressed ETC2 |
|
iOS |
RGB |
RGB 24 bit |
RGB Compressed PVRTC 4 bits |
RGB Compressed PVRTC 4 bits |
RGB Compressed PVRTC 2 bits |
RGBA |
RGBA 32 bit |
RGBA Compressed PVRTC 4 bits |
RGBA Compressed PVRTC 4 bits |
RGBA Compressed PVRTC 2 bits |
|
tvOS |
RGB |
RGB 24 bit |
RGB Compressed ASTC 6x6 block |
RGB Compressed ASTC 4x4 block |
RGB Compressed ASTC 8x8 block |
RGBA |
RGBA 32 bit |
RGBA Compressed ASTC 6x6 block |
RGBA Compressed ASTC 4x4 block |
RGBA Compressed ASTC 8x8 block |
|
RGBA |
RGBA 32 bit |
RGBA 16 bit |
RGBA 16 bit |
RGBA 16 bit |
When you use a Texture compression format that is not supported on the target platform, the Textures are decompressed to RGBA 32 and stored in memory alongside the compressed Textures. When this happens, time is lost decompressing Textures, and memory is lost because you are storing them twice. In addition, all platforms have different hardware, and are optimised to work most efficiently with specific compression formats; choosing non-compatible formats can impact your game’s performance. The table below shows supported platforms for each compression format.
- 当一个图片被压缩成目标平台不支持的格式,那么在使用时会被解压缩成RGBA 32和不被支持的原图一起放在内存里,这会消耗更多的加载时间和内存,因为图片被存放了两次。每个平台有不同的硬件,每个硬件都对自己支持的格式做了优化。选择了不合适的平台会导致游戏性能下降。
All supported Texture compression formats
- 下表是Unity里面所有支持的格式和对应的平台
Notes on the table below:
- RGB is a color model in which red, green and blue are added together in various ways to reproduce a broad array of colors.
- RGBA is a version of RGB with an alpha channel, which supports blending and opacity alteration.
- Crunch compression is a lossy compression format (meaning that parts of the data are lost during compression) on top of DXT or ETC Texture compression. Textures are decompressed to DXT or ETC on the CPU, and then uploaded to the GPU at run time. Crunch compression helps the Texture use the lowest possible amount of space on disk and for downloads. Crunch Textures can take a long time to compress, but decompression at run time is very fast.
- Crunch compression 是一种优于DTX或是ETC的有损压缩。DTX或是ETC是在CPU上解压缩,然后再发给GPU使用。Crunch compression可以让图片压缩的更小,便于节省磁盘空间和下载。Crunch 算法在压缩过程中比较慢,但是解压缩的速度非常快。
Texture compression format |
Description |
Size for a 256x256 pixel Texture |
Platform Support |
RGB Compressed DXT1 |
Compressed unsigned normalised integer RGB Texture. |
32KB (4 bits per pixel) |
Windows, Linux, macOS, PS4, XBox One, Android (Nvidia Tegra and Intel Bay Trail), WebGL
Note: With linear rendering on web browser that doesn’t support sRGB DXT, textures are uncompressed at run time to RGBA32. |
RGB Crunched DXT1 |
Similar to RGB Compressed DXT1, but compressed using Crunch compression. See Notes, above, for more on crunch compression. |
Variable, depending on the complexity of the content in the texture. |
Windows, Linux, macOS, PS4, XBox One, Android (Nvidia Tegra and Intel Bay Trail), WebGL
Note: With linear rendering on a web browser that doesn’t support sRGB DXT, textures are uncompressed at run time to RGBA32. |
RGBA Compressed DXT5 |
Compressed unsigned normalised integer RGBA Texture. 8 bits per pixel. |
64KB (8 bits per pixel) |
Windows, Linux, macOS, PS4, XBox One, Android (Nvidia Tegra and Intel Bay Trail), WebGL
Note: With linear rendering on a web browser that doesn’t support sRGB DXT, textures are uncompressed at run time to RGBA32. |
RGBA Crunched DXT5 |
Similar to RGBA Compressed DXT5, but compressed using Crunch compression. See Notes, above, for more on crunch compression. |
Variable, depending on the complexity of the content in the texture. |
Windows, Linux, macOS, PS4, XBox One, Android (Nvidia Tegra and Intel Bay Trail), WebGL
Note: With linear rendering on a web browser that doesn’t support sRGB DXT, textures are uncompressed at run time to RGBA32. |
RGB Compressed BC6H |
Compressed unsigned float/High Dynamic Range (HDR) RGB Texture. |
64KB (8 bits per pixel) |
Windows Direct3D 11: OpenGL 4, Linux.
Note: BC6H Textures are uncompressed at run time to RGBA half on the following platform configurations: - macOS with OpenGL - Platforms with Direct3D 10 Shader Model 4 or OpenGL 3 GPUs. |
RGB(A) Compressed BC7 |
High-quality compressed unsigned normalised integer RGB or RGBA Texture. |
64KB (8 bits per pixel) |
Windows Direct3D 11: OpenGL 4, Linux
Note: BC7 Textures are uncompressed at run time to RGBA 32bits on the following platform configurations: - macOS with OpenGL - Platforms with Direct3D 10 Shader Model 4 Platforms with OpenGL 3 GPUs. |
RGB Compressed ETC |
Compressed RGB Texture. This is the default texture compression format for textures without an alpha channel for Android projects. |
32KB (4 bits per pixel) |
Android, iOS, tvOS. Note: ETC1 is supported by all OpenGL ES 2.0 GPUs. It does not support alpha. |
RGB Crunched ETC |
Similar to RGB Compressed ETC, but compressed using Crunch compression. See Notes above for more on crunch compression. |
Variable, depending on the complexity of the content in the texture. |
Android, iOS, tvOS. |
RGB Compressed ETC2 |
Compressed RGB Texture. |
32KB (4 bits per pixel) |
Android (OpenGL ES 3.0) Note: On Android platforms that don’t support ETC2, the texture is uncompressed at run time to the format specified by ETC2 fallback in the Build Settings. |
RGBA Compressed ETC2 |
Compressed RGBA Texture. This is the default Texture compression format for textures with alpha channel for Android projects. |
64KB (8 bits per pixel) |
Android (OpenGL ES 3.0), iOS (OpenGL ES 3.0), tvOS (OpenGL ES 3.0)
Note: On iOS and tvOS devices that don’t support ETC2, the texture is uncompressed at run time to RGBA32. On Android platforms that don’t support ETC2, the texture is uncompressed at run time to the format specified by ETC2 fallback in the Build Settings. |
RGBA Crunched ETC2 |
Similar to RGBA Compressed ETC2, but compressed using Crunch compression. See Notes above for more on crunch compression. |
Variable, depending on the complexity of the content in the texture. |
Android (OpenGL ES 3.0), iOS (OpenGL ES 3.0), tvOS (OpenGL ES 3.0)
Note: On iOS and tvOS devices that don’t support ETC2, the texture is uncompressed at run time to RGBA32. On Android platforms that don’t support ETC2, the texture is uncompressed at run time to the format specified by ETC2 fallback in the Build Settings. |
RGB(A) Compressed ASTC |
Variable block size compressed RGB or RGBA Texture. |
12x12: 0.89 bits per pixel (7.56KB for a 256x256 Texture) 10x10: 1.28 bits per pixel (10.56KB for a 256x256 Textures) 8x8: 2 bits per pixel (16KB for a 256x256 Texture); 6x6: 3.56 bits per pixel (28.89KB for a 256x256 Texture) 5x5: 5.12 bits per pixel (42.25KB for a 256x256 Texture) 4x4: 8 bits per pixel (64KB for a 256x256 Texture) |
tvOS (all), iOS (A8), Android (PowerVR 6XT, Mali T600 series, Adreno 400 series, Tegra K1). |
RGB(A) Compressed ASTC HDR |
Variable block size compressed unsigned float/High Dynamic Range (HDR) RGB or RGBA Texture. |
12x12: 0.89 bits per pixel (7744 bytes for a 256x256 Texture) 10x10: 1.28 bits per pixel (10816 bytes for a 256x256 Textures) 8x8: 2 bits per pixel (16KB for a 256x256 Texture); 6x6: 3.56 bits per pixel (29584 bytes for a 256x256 Texture) 5x5: 5.12 bits per pixel (43264 bytes for a 256x256 Texture) 4x4: 8 bits per pixel (64KB for a 256x256 Texture) |
Android (Mali T700 series, Adreno 500 series).
Note: On devices that don’t support ASTC HDR, the texture is uncompressed at run time to RGB9e5, losing the alpha channel. |
RGB Compressed PVRTC 2 bits |
High-compression RGB Texture. Low quality, but lower size, resulting in higher performance. |
16KB (2 bits per pixel) |
Android (PowerVR), iOS, tvOS. |
RGBA Compressed PVRTC 2 bits |
High-compression RGBA Texture. Low quality, but lower size, resulting in higher performance. |
16KB (2 bits per pixel) |
Android (PowerVR), iOS, tvOS. |
RGB Compressed PVRTC 4 bits |
Compressed RGB Texture. High-quality Textures, particularly on color data, but can take a long time to compress. |
32KB (4 bits per pixel) |
Android (PowerVR), iOS, tvOS. |
RGBA Compressed PVRTC 4 bits |
Compressed RGB Texture. High-quality Textures, particularly on color data, but can take a long time to compress. |
32KB (4 bits per pixel) |
Android (PowerVR), iOS, tvOS. |
RGB Compressed ATC |
Compressed RGB Texture. |
32KB (4 bits per pixel) |
Android (Qualcomm - Adreno), iOS, tvOS. |
RGBA Compressed ATC |
Compressed RGBA Texture. |
64KB (8 bits per pixel) |
Android (Qualcomm - Adreno), iOS, tvOS. |
RGB 16 bit |
65 thousand colors with no alpha. Uses more memory than the compressed formats, but could be more suitable for UI or crisp Textures without gradients. |
128KB (16 bits per pixel) |
All platforms. |
RGB 24 bit |
True color, but without alpha. |
192KB (24 bits per pixel) |
All platforms |
Alpha 8 |
High-quality alpha channel, but without any color. |
64KB (8 bits per pixel) |
All platforms. |
RGBA 16 bit |
Low-quality true color. This is the default compression for Textures that have an alpha channel. |
128KB (16 bits per pixel) |
All platforms. |
RGBA 32 bit |
True color with alpha. This is the highest quality compression for Textures that have an alpha channel. |
256KB (32 bits per pixel) |
All platforms. |
Notes on Android
Unless you’re targeting specific hardware (such as Tegra), ETC2 compression is the most efficient option for Android, offering the best balance of quality and file size (with associated memory size requirements). If you need an alpha channel, you could store it externally and still benefit from a lower Texture file size.
You can use ETC1 for Textures that have an alpha channel, but only if the build is for Android and the Textures are placed on an atlas (by specifying the packing tag). To enable this, tick the Compress using ETC1 checkbox for the Texture. Unity splits the resulting atlas into two Textures, each without an alpha channel, and then combines them in the final parts of the render pipeline.
To store an alpha channel in a Texture, use RGBA16 bit compression, which is supported by all hardware vendors.
- 对于安卓来说,除了一些特殊平台,ETC2是效果最好的选择。ETC2是支持alpha通道的。
对于安卓平台的图集,也可以使用ETC1来压缩,Unity会将图集拆成两张不包含alpha的图片,在渲染时合并。(拆分成两张图的选项split alpha channel,旧版图集在每张图片上选择。新版图集直接在图集上选择即可)