Why you should use "Advanced texture type" more - Unity3D
Welcome unity developers.
Let me start with our normal workflow in unity.
When we want to add a sprite into the game we just simply drag and drop it into the assets folder and we always remember to change the texture setting to sprite
Same if you are using texture or normal map or any other type, you always remember to change texture type to its corresponding one.
But let me ask you , how many times have you considered using advanced or actually though about what is its use ?!
Don't worry I barely thought about it, not until recently a friend of mine introduced me to series of blog posts ( check the reference below ) from which it came to my mind to apply them to unity and you will see lots of real magic xD.
Before we jump in let me clarify few points:
- This is kinda a very long subject so I will split it into series of blog posts .
- What is advanced texture type ?
When you choose a texture type what unity do is choose the best setting for your image when compressed/saved/used by the graphics card.
And to make it easy for users, it hides lots of details and try to make best choices for you on your texture type: image,texture..etc. But you can just choose advanced settings and pick the best setting that suits you.
- Why should I pick advanced texture type, if unity gives me both options and sometimes the best settings with specific types?
Simply because of the word "Sometimes". In many cases you will need a different setting. For example your images are taking too much memory for the mobile device that caused the frame rate to drop so you try and lower the max size ( will talk later more about it ) but that causes unwanted pixelated and lower quality art. However, with advanced settings you can get better quality and even smaller size.
One last thing, it will be hard and very long to explain every bit of advanced texture type but don't worry I will focus on the most important aspect which is texture compression.
For ease of use I will focus on using images only but the same can be applied to all other types ( textures,normal maps..etc).
Texture Compression:
In games, most of size and frame rate drop comes from images either for texture or different usages. Imagine AAA games with best quality images and on the highest resolution possible. Can your PC run it smoothly ? and why do these high quality images cause these problems ?
It came down to the idea of how much these high quality images take from the graphic card memory. As they take more memory, it gets harder to load all these textures and details and to preform different lighting and shading on them.
Note: The higher the quality, the bigger the size of the image gets, for example :
1920 x 1080 HD quality.
3840 x 2160 4K quality.
So graphic cards use texture compression, and actually almost all of them support different types or in some cases all compression types.
Before I just start telling you what are the available compression types let's start from the beginning and go step by step into the world of texture compression.
Computer pixel:
Back in the first days a pixel on the screen can either be white or black. That means one pixel in size takes 1 bit as 1 bit can either be true or false , or in this case white or black.
So to take 4 colors how much size it needs ?
Yup 2 bits gives us 4 colors and to turn it into an easier way: say 22 as in 1 bit can hold 2 values and now we have 2 bits so 2 ^ 2 .
24 bits is called true color that's similar to human eyes.
so if we considered 1024x1024 image
Regardless the fact that transparency (opacity) isn't included. Now, how many images does your game have ! xD
But this isn't its size on my PC ? Yup it's not, because what is saved on your disk is a compressed format so it reduces the size a lot. So why don't we compress the images in the memory as well ?
This is kinda what happens. What I've just explained is actually a type of texture compression.
It's called:
RGB 24bit : Means that the image with its true colors takes 24 bits per pixel from graphic card memory. These 24 bits are distributed evenly among colors. Each color channel takes 8 bits and no alpha is included.
Meaning the "R" (red channel) takes 8 bits, "G" (green channel) 8 bits and "B" (blue channel) 8 bits. That makes 24 bits. But there's no alpha which is responsible for transparency
For alpha channel we use RGBA which made 32bit. which is called RGBA 32bit
Let's give it a try in unity:
Get a 1024x1024 image (make sure it's a power of 2 image, if its not the size will be different as unity will automatically try to convert them to nearest power of 2)
Choose advanced texture type
make sure to uncheck "Generate Mip Maps" (and this is another topic for another day xD )
At the end you will find "Max Size" and "Format".
When opening the drop down list of "Format", you'll find a lot of options.
This very big list has all kinds of texture formats. All with different possibilities and powers that where hidden from you. Now is time to harness this power :D .
But for now let's try what we know.
RGB 24bit
RGBA 32bit
You might have noticed RGB 16bit and RGBA 16bit, remember when we said that RGB 24bit is distributed as 8 bits per channel ? What if we said that we will reduce it to 5 bits per channel ?
Yup it will make 15 bit not 16 bit xD
16 bits is a power of 2, and in actual life human eyes are better at seeing in the green spectrum, so the 1 extra bit is put in the green channel where it matters most. (Amazing, huh ? :D)
so the RGB 16bit becomes like this : R5G6B5
and the RGBA 16bit it will be : R4G4B4A4
But when there isn't much gradient as you can see there is hardly a noticeable difference.
And actually these 16 bits or Truecolor (32 bits) options are what you choose when you are not in advanced mode.
Another aspect to talk about is the Max Size.
It serves multiple purposes for example :
- When developing for different platforms or when targeting mobile with HD version and a normal version. In this case you want better quality (larger image size) for high end mobile devices, otherwise you can have small size images for low end ones. So should you ask your artist to have different version of each image,texture with different sizes ?
Actually No. Even if not targeting multi platforms it's better to ask the artist for the best size possible depending on your requirement then by simply changing the max size you can lower quality hence the size or increase quality when using different texture compression.
- One other trick is when working with image compression you can use for example RGB24 bit (larger size) and then lower the max size. This trick will be used a lot with other compression types.
So it's much better to have a little bit higher size from the artist (power of 2) and then you change it as you see fits.
Up till now I haven't talked about any new texture compression techniques, how they work or which ones work for which platforms (mobile devices or consoles) and which doesn't.
Well for now you can try different compression types in advanced mode and see how it goes, and in the next post I will talk about how they work, what is better and when and what types and better for each platform.
Let me know if you have any questions ;)
References :
This awesome blog :
http://joostdevblog.blogspot.com.eg/2015/11/texture-formats-for-2d-games-part-1.html
People's reference:
https://en.wikipedia.org/wiki/Pixel
Written and researched by :
Ahmed mohi
Revisited by my anonymous friend xD:
Ahmed Najeeb
Let me start with our normal workflow in unity.
When we want to add a sprite into the game we just simply drag and drop it into the assets folder and we always remember to change the texture setting to sprite
Same if you are using texture or normal map or any other type, you always remember to change texture type to its corresponding one.
But let me ask you , how many times have you considered using advanced or actually though about what is its use ?!
Don't worry I barely thought about it, not until recently a friend of mine introduced me to series of blog posts ( check the reference below ) from which it came to my mind to apply them to unity and you will see lots of real magic xD.
Before we jump in let me clarify few points:
- This is kinda a very long subject so I will split it into series of blog posts .
- What is advanced texture type ?
When you choose a texture type what unity do is choose the best setting for your image when compressed/saved/used by the graphics card.
And to make it easy for users, it hides lots of details and try to make best choices for you on your texture type: image,texture..etc. But you can just choose advanced settings and pick the best setting that suits you.
- Why should I pick advanced texture type, if unity gives me both options and sometimes the best settings with specific types?
Simply because of the word "Sometimes". In many cases you will need a different setting. For example your images are taking too much memory for the mobile device that caused the frame rate to drop so you try and lower the max size ( will talk later more about it ) but that causes unwanted pixelated and lower quality art. However, with advanced settings you can get better quality and even smaller size.
Click to enlarge |
One last thing, it will be hard and very long to explain every bit of advanced texture type but don't worry I will focus on the most important aspect which is texture compression.
For ease of use I will focus on using images only but the same can be applied to all other types ( textures,normal maps..etc).
Texture Compression:
In games, most of size and frame rate drop comes from images either for texture or different usages. Imagine AAA games with best quality images and on the highest resolution possible. Can your PC run it smoothly ? and why do these high quality images cause these problems ?
It came down to the idea of how much these high quality images take from the graphic card memory. As they take more memory, it gets harder to load all these textures and details and to preform different lighting and shading on them.
Note: The higher the quality, the bigger the size of the image gets, for example :
1920 x 1080 HD quality.
3840 x 2160 4K quality.
So graphic cards use texture compression, and actually almost all of them support different types or in some cases all compression types.
Before I just start telling you what are the available compression types let's start from the beginning and go step by step into the world of texture compression.
Computer pixel:
Back in the first days a pixel on the screen can either be white or black. That means one pixel in size takes 1 bit as 1 bit can either be true or false , or in this case white or black.
1 bit per pixel = 2 colors
So to take 4 colors how much size it needs ?
Yup 2 bits gives us 4 colors and to turn it into an easier way: say 22 as in 1 bit can hold 2 values and now we have 2 bits so 2 ^ 2 .
2 bits per pixel = 22 = 4 colors
3 bits per pixel = 23 = 8 colors
8 bits per pixel = 28 = 256 colors
16 bits per pixel = 216 = 65,536 colors
24 bits per pixel = 224 = 16,777,216 colors
so if we considered 1024x1024 image
1024 x 1024 x 24 = 1048576 bits = 3mb
Regardless the fact that transparency (opacity) isn't included. Now, how many images does your game have ! xD
But this isn't its size on my PC ? Yup it's not, because what is saved on your disk is a compressed format so it reduces the size a lot. So why don't we compress the images in the memory as well ?
This is kinda what happens. What I've just explained is actually a type of texture compression.
It's called:
RGB 24bit : Means that the image with its true colors takes 24 bits per pixel from graphic card memory. These 24 bits are distributed evenly among colors. Each color channel takes 8 bits and no alpha is included.
Meaning the "R" (red channel) takes 8 bits, "G" (green channel) 8 bits and "B" (blue channel) 8 bits. That makes 24 bits. But there's no alpha which is responsible for transparency
For alpha channel we use RGBA which made 32bit. which is called RGBA 32bit
Let's give it a try in unity:
Get a 1024x1024 image (make sure it's a power of 2 image, if its not the size will be different as unity will automatically try to convert them to nearest power of 2)
Choose advanced texture type
make sure to uncheck "Generate Mip Maps" (and this is another topic for another day xD )
At the end you will find "Max Size" and "Format".
When opening the drop down list of "Format", you'll find a lot of options.
This very big list has all kinds of texture formats. All with different possibilities and powers that where hidden from you. Now is time to harness this power :D .
But for now let's try what we know.
RGB 24bit
RGBA 32bit
You might have noticed RGB 16bit and RGBA 16bit, remember when we said that RGB 24bit is distributed as 8 bits per channel ? What if we said that we will reduce it to 5 bits per channel ?
Yup it will make 15 bit not 16 bit xD
16 bits is a power of 2, and in actual life human eyes are better at seeing in the green spectrum, so the 1 extra bit is put in the green channel where it matters most. (Amazing, huh ? :D)
so the RGB 16bit becomes like this : R5G6B5
and the RGBA 16bit it will be : R4G4B4A4
RGB 24bit gives highest quality but the largest images size
RGB 16bit lower quality for lower size
But let's think about it for moment. How much loss in image quality will happen if I changed from 24bit to 16bit ?
It comes down to the idea of what 24bit and 16bit is. 16bit means it will have less number/collection of colors than the actual true colors. Which means: for an image with gradient or smooth transition between a color and another one, it won't be that smooth. In 16bit the gradient will look sharp as some colors don't exist in this width (i.e. color can't be formed by only 16 bits) and are replaced with nearest available color. For example check the image below:
But when there isn't much gradient as you can see there is hardly a noticeable difference.
And actually these 16 bits or Truecolor (32 bits) options are what you choose when you are not in advanced mode.
Another aspect to talk about is the Max Size.
It serves multiple purposes for example :
- When developing for different platforms or when targeting mobile with HD version and a normal version. In this case you want better quality (larger image size) for high end mobile devices, otherwise you can have small size images for low end ones. So should you ask your artist to have different version of each image,texture with different sizes ?
Actually No. Even if not targeting multi platforms it's better to ask the artist for the best size possible depending on your requirement then by simply changing the max size you can lower quality hence the size or increase quality when using different texture compression.
- One other trick is when working with image compression you can use for example RGB24 bit (larger size) and then lower the max size. This trick will be used a lot with other compression types.
So it's much better to have a little bit higher size from the artist (power of 2) and then you change it as you see fits.
Up till now I haven't talked about any new texture compression techniques, how they work or which ones work for which platforms (mobile devices or consoles) and which doesn't.
Well for now you can try different compression types in advanced mode and see how it goes, and in the next post I will talk about how they work, what is better and when and what types and better for each platform.
Let me know if you have any questions ;)
References :
This awesome blog :
http://joostdevblog.blogspot.com.eg/2015/11/texture-formats-for-2d-games-part-1.html
People's reference:
https://en.wikipedia.org/wiki/Pixel
Written and researched by :
Ahmed mohi
Revisited by my anonymous friend xD:
Ahmed Najeeb
Comments
Post a Comment