Skip to main content
GameDev.net gamedev.net
🔒 Locked

What resulutuion should textures for games have?

Started by David_212211 Jun 22, 2015 at 7:26 PM 3 replies 6.3k views
Original Post
David_212211
David_212211

Hello,

I have 2 questions:

1st I just created a 20k : 20k picture in Gimp and realized that this used about 4GB RAM. I know, exporting this as a .png will be a lot less big and gameenginethingys compress it even more, but I wonder whats the "perfect" resulution for my textures tongue.png

Because I made a arrow and a bow model for a game and when pulling the bow, the arrow will be right in the camera and I don't want the player to see the pixels, neither I want to have 128GB RAM to play the game..

2nd: Why are textures width and height always at a size of: 2x like 2, 4, 8, 16,...

Thanks in advance,

Sorry for my horrible english tongue.png

Hodgman
Hodgman

I know, exporting this as a .png will be a lot less big and gameenginethingys compress it even more

When game engines load textures, there's only two options:
* Uncompressed (4GB!!!)
* Using DXT (also called "Block Compression"), which you can read about here and here.
PNG will be much smaller than these options, but it's not usable at runtime. A game engine will have to decompress the PNG file (and then optionally DXT/BC compress it)...

Uncompressed or DXT-compressed data will usually be much larger than PNG-compressed data!

I wonder whats the "perfect" resulution for my textures

It depends how big they are in your game world, and how close you can get to them.
If you get so close to a wall that one brick fills your entire screen, then that brick should have a maximum resolution of 1920*1080 (or whatever maximum screen resolution you want to support). Having a texture that's higher resolution than that will be wasted, as no one will ever get close enough to see the details.

Usually game artists will create their textures at a higher resolution than what is required, and will shrink them when exporting to the game -- this allows them to increase the resolution later if required.

Another thing that's usually done when building game worlds is to stick to a memory budget. For example, the lead game programmer might tell you that you can have 1GB of textures in your level. You can decide to allocate that budget however you like (512MB for walls, 256MB for props, 256MB for other...) as long as you stick within the 1GB that's been given to you.
These budgets will depend on the hardware that your game is designed to run on, and the technology requirements of the rest of the engine/game.
Also, the sizes you should be counting here are not the PNG sizes -- as this is just the on-disk size!
You should count the size of your textures when uncompressed (.BMP / .TGA without RLE enabled / etc), or when compressed using DXT/BC (.DDS/etc) -- this is the in-RAM size.

2nd: Why are textures width and height always at a size of: 2x like 2, 4, 8, 16,...

It's slightly more efficient for GPUs to fetch pixels from textures when the width/height are a power of two.
Decades ago, it used to be required (non power-of-two textures simply didn't work at all!).

Avilius
Avilius

1st I just created a 20k : 20k picture in Gimp and realized that this used about 4GB RAM. I know, exporting this as a .png will be a lot less big and gameenginethingys compress it even more, but I wonder whats the "perfect" resulution for my textures tongue.png

I don't know, you tell me.

This question depends on your target hardware.

What's the complexity of the scene? When there isn't much going on you can probably up the resolution on the fewer objects, so instead of having a 512x512 texture for a rock maybe when you zoom in during a cutscene you can bump that texture up to 1024x1024.

How much memory do you have? Can you afford to store several large textures?

What's the maximum texture resolution that your GPU can support? You can't pass this limit no matter what you do.

How large is your storage medium? If you can't fit your collection of 4k rock textures on a blu-ray disc then they are too large.

I could go on all day. We need more information.

Because I made a arrow and a bow model for a game and when pulling the bow, the arrow will be right in the camera and I don't want the player to see the pixels, neither I want to have 128GB RAM to play the game..

Try using linear filtering then.

2nd: Why are textures width and height always at a size of: 2x like 2, 4, 8, 16,...

Textures with dimensions that are a power of 2 are much faster to use than one without. It's easier for your CPU and GPU to handle numbers like this. Not only that, but a texture with dimensions that are a power of 2 also meet the requirements for compression.

EDIT: Damn, Hodgman posted right before I did and did a better job at explaining...

Krypt0n
Krypt0n

2nd: Why are textures width and height always at a size of: 2x like 2, 4, 8, 16,...

The original GPUs were designed to do tons of stupid/simple graphics work and therefor work was saved wherever possible, texture coordinate calculations are no difference and using just power of 2 textures saved an insane amount of transistors.

1. you have to map a float coordinate to the integer texel position. converting float to int was quite an expensive operation back in the days, in languages like c++ that could happen by implicit casts and could cause a noticeable performance decrease. but if the texture resolution is of power of two, you can use a trick. floats are stored as an exponent and a fraction. to get the integer power of two coordinate, you just need to shift the fraction part.

2. Clamping textures would usually be a comparison instruction, on processors that is solved by subtracting both values, and if the bit flips, the 2nd value is bigger. in code something like
if( TextureCoordinate - TextureResolution < 0)
  TextureCoordinate = TextureResolution-1;
but with power of two textures, that's just a one bit test and in hardware, it's a simple transistor instead of an expensive operation.

3. wrapping/repeating texture coordinates would be defined as
TextureCoordinate = TextureCoordinate%TextureResolution;
which is essentially a division. integer division is one of the most expensive operation up to today. some CPU architectures, like ARM, don't provide it is emulated in software. shaders also emulated that for integer. No way you wanted to have tons of those division-units on a GPU back then. yet again, for power of two, this operation is just a simple bitmasking operation.
TextureCoordinate = TextureCoordinate&(TextureResolution-1);//works just with power of two
Hodgman explained why it's still preferred nowadays, so i'll save some ink smile.png
Stainless
Stainless

The "perfect" texture size depends on who you talk to.

Graphics artist.

As large as possible, huge baby, give me detail. I want detail.

Programmer.

As small as possible. Why do you need a texture? Can't I just use a solid colour?

I have this fight most days. In one case I found a 4K texture (4096 by 4096 32 bit = 67,108,864 bytes) on a shoe. I looked closer and the shoe had 5 4K textures attached.

Diffuse, specular, normal, reflectance, and self illumination. (don't ask me why)

I went to the game and found the scene where the character was wearing the shoes. The MAXIMUM screen pixels the shoes could ever occupy was a 16 by 16 area.

Total overkill, total waste of resources.

On this game our texture budget is about 3 GIG, so obviously this was not acceptable and the textures were shrunk to a sensible size.

It the general case, IMHO anything over 4K needs to be justified. You have to have a really good reason for having it in the game. Doesn't mean that it is banned, just that you really need to think about it.

One trick I use a lot is to record the highest mipmap ever used on a texture. It's complicated to get the detection to work, but it can be done. Then I can generate a report and flag any large textures that are never used at full resolution.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.