Author Topic: Generate Square Textures  (Read 13294 times)

Anathorn

  • Guest
Generate Square Textures
« on: November 05, 2012, 11:38:30 AM »
I need NGUI to always generate square textures, there is any way to do that? because sometimes it create a 512x256 or 1024x512 textures and in iOS i need to use square textures, any ideas of how to force that?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Generate Square Textures
« Reply #1 on: November 05, 2012, 11:41:46 AM »
That's actually done by Unity, not NGUI (assuming you are talking about the atlas textures). Have you tried using the non-Unity packing? (checkbox on the atlas maker)

Anathorn

  • Guest
Re: Generate Square Textures
« Reply #2 on: November 05, 2012, 12:18:32 PM »
i just tried that and works the same way, i still cant create the square atlas texture

im going to attach the image of the texture, check it

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Generate Square Textures
« Reply #3 on: November 05, 2012, 01:57:57 PM »
You can take those sprites and split them up. Left side (looking glass), right side (round edge), and middle is just a square piece that you can repeat using a tiled texture. This will save you texture space, and will allow you to fit everything into 256x256 or less. Likely even 128x128.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Generate Square Textures
« Reply #4 on: November 09, 2012, 04:14:58 AM »
In fact, the algorithms used by NGUI can't make a square textures each time, they just pack sprites and it will result in a particular size, not necessarily square.
You can either do as ArenMook told you, that is, optimize your sprites, or add some others so that the atlas is square :)

Game Whiz

  • Guest
Re: Generate Square Textures
« Reply #5 on: December 29, 2012, 09:51:16 AM »
Aren, could you please add a "Force Square" field that forces the atlas to be square? NGUI could add a bogus texture to force this (empty white rectangle or whatever). Manually adding a texture to achieve squareness sucks if you're constantly redesigning the GUI and ending up with a non square PVRTC atlas sucks even more, because Unity will convert it internally to RGBA32 without informing you (http://docs.unity3d.com/Documentation/Components/class-Texture2D.html). A "Force Square" field that takes into account current sprites and automagically generates the necessary sprites for the smallest possible square texture would be a good feature in my opinion.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Generate Square Textures
« Reply #6 on: December 29, 2012, 09:54:36 AM »
You only need this if you want to PVR compress it. I would add a dummy texture myself, but I see the merit in a feature like this.

Game Whiz

  • Guest
Re: Generate Square Textures
« Reply #7 on: December 29, 2012, 10:23:29 AM »
You only need this if you want to PVR compress it. I would add a dummy texture myself, but I see the merit in a feature like this.
I want PVR to compress it :) In iPad3 it's crazy not to compress, particularly because with proper padding you really can't tell the difference between PVRTC and RGBA32 in a 10 inch screen (gradients are still an issue).

Just tested compressing a texture in Unity 4.0, and Unity automatically stretches it in iOS (I guess no more auto conversion to RGBA32). The problem is that NGUI doesn't know how to handle this, and all sprites get chopped. A "Force Square" field would really be handy in these cases.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Generate Square Textures
« Reply #8 on: December 29, 2012, 03:44:10 PM »
You want to double the texture size so that you can reduce its quality using PVRTC (which looks terrible around edges of the font characters in particular)? PVRTC compression is for game textures, it shouldn't be used for UI. You'll get better quality by using smaller UI textures than using larger textures that you then PVRTC-compress.

Game Whiz

  • Guest
Re: Generate Square Textures
« Reply #9 on: December 29, 2012, 04:15:10 PM »
You want to double the texture size so that you can reduce its quality using PVRTC (which looks terrible around edges of the font characters in particular)? PVRTC compression is for game textures, it shouldn't be used for UI. You'll get better quality by using smaller UI textures than using larger textures that you then PVRTC-compress.

As with everything, there are no absolutes, but I guess you're younger than I am ;)

PVRTC compression is suitable for much more than game textures, particularly now with the advances in its compression algorithms. If you couple that with retina resolution graphics (which makes compression artefacts much less visible due to the crazy density), you get sharp enough UIs with PVRTC, provided you use it where it makes sense (and I get away with it in some fonts).

In my game I use it mainly for glows behind non PVRTC buttons. It works fine and it greatly reduces game size (8Mb for a 4096x4096 PVRTC texture vs 64Mb for the same texture in RGBA32). When compared to a 16 bit Floyd Steinberg dithered image, PVRTC wins in 50% of the cases (gradients are better handled by Floyd-Steinberg, since there's some pretty obvious banding when using PVRTC).

Even if I double a PVRTC texture size I still gain a lot in space/memory usage when compared to a RGBA32, and in many instances I can even live with PVRTC 2 bit which reduces things even further.

Of course if I'm the only one thinking this is a good idea, then perhaps it's not really cost effective for you to implement it ;)

Game Whiz

  • Guest
Re: Generate Square Textures
« Reply #10 on: December 29, 2012, 04:24:05 PM »
Here's an example of where PVRTC is used in my GUI:

http://www.facebook.com/photo.php?fbid=370601166365038&set=a.370601156365039.88637.370593203032501&type=1&theater

The glow behind the direction wheel as well as the glows behind the attack/jump buttons are PVRTC. They're large textures and using RGBA32 on them is totally overkill and doesn't bring any extra visible quality. For animated textures PVRTC is also very useful and in this case even PVRTC works very well (I have one animated texture in the upper left weapon indicator. It's visible in the lower half of the indicator and it's PVRTC 2 bit).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Generate Square Textures
« Reply #11 on: December 29, 2012, 07:41:04 PM »
So... why not have a small texture for the glow and just enlarge the sprite? I mean -- it's glow. It doesn't have sharp edges. You can easily reduce the size of the glow itself significantly.

Game Whiz

  • Guest
Re: Generate Square Textures
« Reply #12 on: December 30, 2012, 01:01:26 AM »
Sure, I could use smaller textures but I'd have to be careful about their size (to be sure to get a square texture). There are always ways to keep the texture square, but the point is that in these cases where squared textures are needed, it's much more productive to check a box and forget about it, rather than trying to come up with strategies to keep the texture square.

andrew

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Generate Square Textures
« Reply #13 on: February 10, 2013, 06:26:07 PM »
I would request the "Force Square" option as well as nothing draws properly in our game if the NGUI atlas goes non-square.. and yes it's an iOS/Android game.  2D Toolkit used to do this and it saved a lot of frustration. (Well, the frustration was in other places :) )

Game Whiz

  • Guest
Re: Generate Square Textures
« Reply #14 on: February 10, 2013, 06:51:27 PM »
...2D Toolkit used to do this...

tk2d still does this. It's one sensible solution to solve this issue, but I guess this isn't on NGUI's roadmap. For now I merely add the same sprite multiple times until the texture is square. It's a workaround that's hacky and inelegant and it doesn't fit at all with the elegance of NGUI.