Texture 2D
Unity Manual > User Guide > Working with Assets > Texture 2D

Texture 2D

Текстуры — это изображения или видеофайлы, которые проецируются на поверхность объекта.

The shaders you use for your objects put specific requirements on which textures you need, but the basic principle is that you can put any image file inside your project. If it meets the size requirements (specified below), it will get imported and optimized for game use. This extends to multi-layer Photoshop or TIFF files - they are flattened on import, so there is no size penalty for your game.

Properties

Inspector текстур выглядит следующим образом:

Верхняя секция содержит настройки, а нижняя показывает предпросмотр текстуры.

Filtering ModeSelects how the Texture is filtered when it gets stretched by 3D transformations:
No FilteringThe Texture becomes blocky up close
BilinearThe Texture becomes blurry up close
TrilinearLike Bilinear, but the Texture also blurs between the different mip levels
AnisotropyIncreases texture quality when viewing the texture at a steep angle. Good for floor and ground textures, see below.
Edge modeОпределяет, как тайлится структура:
RepeatThe Texture repeats (tiles) itself
ClampThe Texture's edges get stretched
Show AlphaВключает отображения альфа-канала текстуры
Mip LevelThe current Mip Level that is displayed

Import Settings

Текстыр берутся из файлов в папке проекта. Выбираете файл текстуры, задаёте настройки импорта в Inspector и готово.


Настройки импорта текстуры.
Max. Texture SizeМаксимальный размер импортируемой текстуры. Скажем, ваш художник работает с текстурой размером 100000х100000 пикселей. Вы можете уменьшить её размер при импорте, чтобы не терять производительность.
Texture FormatWhat internal representation is used for the texture. This is a tradeoff between size and quality. In the examples below we show the final size of a in-game texture of 256 by 256 pixels:
RGB Compressed DXT1Compressed RGB texture. This is the most common format for diffuse textures. 4 bits per pixel (32 KB for a 256x256 texture).
RGBA Compressed DXT5Compressed RGBA texture. This is the main format used for diffuse & specular control textures. 1 byte/pixel (64 KB for a 256x256 texture).
RGB 16 bit65 thousand colors with no alpha. Compressed DXT formats use less memory and usually look better. 128 KB for a 256x256 texture.
RGB 24 bitTruecolor but without alpha. 192 KB for a 256x256 texture.
Alpha 8 bitHigh quality alpha channel but without any color. 64 KB for a 256x256 texture.
RGBA 16 bitLow-quality truecolor. Has 16 levels of red, green, blue and alpha. Compressed DXT5 format use less memory and usually look better. 128 KB for a 256x256 texture.
RGBA 32 bitTruecolor with alpha - this is the highest quality. At 256 KB for a 256x256 texture, this one is expensive. Most of the time, DXT5 offers sufficient quality at a much smaller size. The main place this is used is for bump maps, as DXT compression there often carries a visible quality loss.
Build Alpha From Grayscale Если включено, то альфа-канал прозрачности будет сегенрирован из значений светлого/тёмного в изображении. То есть, тёмные области будут менее прозрачными, светлые — более прозрачными.
Scale NonPower2 Sizes UpIf enabled on textures that have non-power-of-two sizes, this will scale texture up to the nearest power-of-two size at import time. For more info see Texture Sizes section below.
Generate Cube MapGenerates a cubemap from the texture using different generation methods.
Generate Mip MapsSelect this to enable mip-map generation. Mip maps are smaller versions of the texture that gets used when the texture is very small on screen. For more info, see Mip Maps below.
Correct GammaSelect this to enable per-mip-level gamma correction.
Border Mip MapsSelect this to avoid colors seeping out to the edge of the lower Mip levels. Used for light cookies (see below).
Mip Map FilteringTwo ways of mip map filtering is available to optimize image quality:
BoxThe simplest way to fade out the mipmaps - the mip levels become smoother and smoother as they go down in size.
KaiserA sharpening Kaiser algorithm is run on the mip maps as they go down in size. If your textures are too blurry in the distance, try this option.
Fade Out MipsEnable this to make the mipmaps fade to gray the mip levels progress. This is used for detail maps.
Fade Out startThe first mip level to begin fading out at.
Fade Out EndThe mip level where the texture is completely grayed out.
Generate Bump MapEnable this to turn the color channels into a format suitable for real-time bumpmapping. For more info, see Bump Maps, below.
BumpinessControl the amount of bumpyness.
FilteringDetermine how the bumpyness is calculated:
StandardThis generates normal maps that are quite smooth.
SobelThe Sobel filter generates normal maps that are sharper than Standard.

Details

Supported Formats

Поддерживаемые форматы
Unity может читать следующие форматы: PSD, TIFF, JPG, TGA, PNG, GIF, BMP, IFF, PICT. Unity прекрасно работает с многослойными изображениями PSD и TIFF. При импорте слои не теряются. Это позволяет использовать один файл для работы в PS, Unity и 3D-пакете.

Texture Sizes

Идеальный размер текстуры должен быть кратен двум (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, … пикселей).
Текстуры не обязаны быть квадратными. Пусть будут прямоугольными — не страшно.

It is possible to use other (non power of two) texture sizes with Unity. Non power of two texture sizes work best when used on GUI Textures, however if used on anything else they will be converted to an uncompressed RGBA 32 bit format. That means they will take up more video memory (compared to DXT compressed textures) and will be slightly slower to load. In general you'll use non power of two sizes only for making GUI.

Non power of two texture assets can be scaled up at import time using a Scale NonPower2 Sizes Up option in the import settings. Then Unity will scale texture contents up to the next power of two, and in the game they will behave just like any other texture. So they can still be compressed and very fast to load.

UV Mapping

When mapping a 2D texture on to a 3D model, some sort of wrapping is done. This is called UV mapping and is done in your 3D modelling app. Inside Unity, you can scale and move the texture using Materials. Scaling bump & detail maps is especially useful.

Mip Maps

Mip Maps are a list 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 the smaller texture versions. Using mip maps uses 33% more memory, but not using them can be a huge performance loss. You should always you mipmaps for in-game textures; the only exceptions are textures that will never be minified (e.g. GUI textures).

Bump Maps

Bump maps are used by bump 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.

Detail Maps

If you want to do a terrain, you normally use your main texture to show where there are grass, rocks sand, etc... If your terrain has a decent size, you will end up with a very blurry terrain. Detail textures hide this fact by fading in small details as your main texture get up close.

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.

Cube Maps

If you want to use texture for reflection maps (e.g. use Reflective builtin shaders), you need to use Cubemap Textures.

Anisotropic filtering

Anisotropic filtering increases texture quality when viewed from a grazing angle, at some expense of rendering cost (the cost is entirely on the graphics card). Increasing anisotropy level is usually a good idea for ground and floor textures. In Quality Settings anisotropic filtering can be forced for all textures or disabled completely.


No anisotropy used on the ground texture

Maximum anisotropy used on the ground texture

Light Cookies

An interesting way to add a lot of visual detail to your scenes is to use Cookies - greyscale textures you use to control the precise look of in-game lighting. This is fantastic for making moving clouds and giving an impression of dense foilage. The Light page has more info on all this, but the main thing is that for textures to be usable for cookies, the following properties need to be set:

For Spotlight Cookies, use the following settings:

Texture FormatAny setting that has an alpha channel: Alpha 8 bit (recommended), DXT5 RGBA, RGBA 16 bit or RGBA 32 bit.
Build Alpha from RGB GrayscaleEnabled
Generate Mip MapsEnabled
Border Mip MapsEnabled

You should keep the edges of you cookie texture solid black in order to get the proper effect. In the Texture Inspector, set the Edge Mode to Clamp.

For Directional Lights, use the following settings:

Texture FormatAny setting that has an alpha channel: Alpha 8 bit (recommended), DXT5 RGBA, RGBA 16 bit or RGBA 32 bit.
Build Alpha from RGB GrayscaleEnabled
Generate Mip MapsEnabled
Border Mip MapsDisabled

This texture will tile, so in the texture inspector, you must set the Edge Mode to Repeat.

For Point Lights, you need to use Cube Maps. To generate one, either make six textures and assign them as described in Cubemap Textures or generate one with the following settings:

Texture FormatAny setting that has an alpha channel: Alpha 8 bit (recommended), DXT5 RGBA, RGBA 16 bit or RGBA 32 bit.
Generate Cube MapAny other setting than None.
Build Alpha from RGB GrayscaleEnabled
Generate Mip MapsEnabled
Border Mip MapsDisabled