1
\$\begingroup\$

I have a texture that is 1024x900. Should I resize it in Photoshop to be 1024x1024 or leave it as it is?

What about a texture sized 1000x900?

\$\endgroup\$
  • 1
    \$\begingroup\$ It depends what effect you want / what problem you want to solve. As you've probably noticed, Unity can handle non-power-of-two textures just fine in many cases. Have you observed a specific issue in your current case that you're hoping to solve by changing the texture size? \$\endgroup\$ – DMGregory Feb 10 at 17:12
  • \$\begingroup\$ I have not noticed any problems. I am currently just sorting all my textures. \$\endgroup\$ – AzulShiva Feb 11 at 7:58
  • \$\begingroup\$ If you haven't noticed any problems, then it's probably fine for your needs as-is \$\endgroup\$ – DMGregory Feb 11 at 10:31
1
\$\begingroup\$

Making you textures a power of two is very useful for many reasons:

  • When it comes to rendering or the computation and usage of mipmaps, making your texture's dimensions powers of two can avoid some gpu headaches, since it could do some optimization internally;

  • You (or the software you use) are going to have custom extensions made by your gpu's drivers manufacturer if you want them to work consistently on your machine. Using special gpu extensions decreases the game's compatibility since not every machine it's going to run on is probably going to implement what it needs to run on. if you stick with powers of 2 then you are guaranteed multi-platform support and good performance, otherwise you may have problems when you try and work with a different machine other than the one you started on;

Let's make a simple example:

Let's say we have two textures, one is 64x64 and the other is 60x60 pixels big; We want to find a given texel in the texture:

64x64:

Texel = 64 * s + t

60x60:

Texel = 60 * s + t

But wait, 64 is a power of two isn't it? That means we can do:

64x64:

Texel = (s<<6) +t //64 is equal to 2 to the power of 6

In the case of 60, we can't quite simplify this calculation as easily;

Shifting bytes is always going to be faster that multiplying by powers of 2, no matter how fast and clever the calculations we make are.

Other than all this performance-related stuff, power of two textures are also easier to maintain overtime.

Nowdays game engines like Unity can totally handle non power of two textures without much trouble, which is why this is not such a huge issue;

In my experience power of two textures are the best way to make 2D art, since that's exactly what your gpu wants (and expects); also, in terms of maintainability and efficency it's probably the best option in 99% of the cases.

\$\endgroup\$
  • 2
    \$\begingroup\$ Your answer doesn't seem to take Unity into account. How does it deal with non-power of 2 textures? Do they affect performance or portability? Maybe Unity is applying some workaround internally? BTW, the the bit-shifting you've shown is an example of optimisation that you shouldn't apply. Compiler would figure it out by itself and writing it explicitly hurts readability. \$\endgroup\$ – gronostaj Feb 11 at 6:03
  • \$\begingroup\$ @gronostaj I can't speak for Unity since i cannot (an don't) read the source code. As I explained in my answer, non power of 2 textures are more computationally expensive and are generally less portable. Unity takes care of most of this stuff internally, but it's still important to know its limitations. The example shows how the compiler could have handled both cases, not the most efficient way ;) \$\endgroup\$ – Gabriele Vierti Feb 11 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.