A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'UGUI & TextMesh Pro' started by qiankanglai, Mar 6, 2016.
Sorry for this stupid question. But what is the general application for this? The only think I can think of is to get a more compact texture atlas. Is that the thing?
@Tef : Using polygon meshes instead of quads has 2 advantages:
1) You can pack the sprite much tighter => reduced memory usage for the textures
2) Reducing overdraw => increases the performance of your game
The reason for 2) is that transparent pixels are not "nothing". The GPU processes them as it does with every other pixel. Using polygon meshes decreases the number of pixels. In the example above I would estimate that the polygon mesh uses only about 70% GPU compared to the rectangular image.
This is awesome!
Cool, but doesn’t a polygon mesh lead to more triangles compared to the 2 triangles used by a rectangle? Maybe that doesn’t lead to any performance loss, I remember when games had a limit of 100 tris on a character ;-) But then GPU’s weren’t as good as they are today either.
Thanks for the information!
The transformation of the vertices is usually done by CPU. Adding more vertices adds to the CPU time - that's right. But the mesh reduces the number of pixels drawn. So what you get is a way to control the distribution of the workload between GPU and CPU.
TexturePacker has a slider called Tracer Tolerance (default is 200) - it's the amount of pixels that are accepted for adding a new vertex. If TexturePacker decides to add a new vertex it checks if it will gain more pixels. E.g. if it's possible to add a vertex and reduce the area by 200px it's done.
Here's an example what you get from different settings:
The right most frame uses +3 vertices while reducing the number of pixels by 52% compared to the rectangle. This is really improving things.
You also see that if you take it to the extreme (left example) you add more and more vertices, with only small reductions in size.
As @qklxtlx : You now have the control over the optimization.
I forgot you’re the creator of TexturePacker, we actually use that for our old mmo, Astroflux. http://www.astroflux.net
Thanks again for explaining, this is actually really awesome!
Does this also work for old flash games in Starling? That would be very interesting for our old game.
How about the slice model ，I have studied for a long time， but it's so complex
This looks amazing!
I've been using this and notice that the generated vertex positions are incorrect if the source image has transparent padding along the borders. I guess it's assuming the original Image mesh is going from UV (0,0) to UV (1,1).
Just put this image in a scene, set it to native size and then add the PolygonImage Component to see the issue. In the meantime I've solved it (with clues from your comments) by using "GetDrawingDimensions" rather than vertex positions and slightly modify the method to ignore the Sprite Padding
Hey @qklxtlx, thanks for the code!
I spotted an issue: using a texture Compressed it works fine, but with a Truecolor it seems the script doesn't work... any ideas?
My bad, I changed again and it works fine in fact. From the script I don't see any reasons why the texture format would change its behavior. So I suppose that Unity had an issue when I changed my sprites
I'd like to share with you my plugin to create 2D Primitives.
You can create these primitives
4 Corner Gradient Quad
All primitives types are inherited from default Graphic class so it's behave as any canvas element.
The main pros to use those primitives are:
They are resolution independent;
Source code included;
You can use the shapes included in the pack (as a static class Shape2DHelper) for many implementations: spawn objects, emit particles, draw, animation etc.
Fast and easy to prototype or create UI / UX;
To next version I'm adding support to create 2D Sprite Primitives as well.
Here is the link to the plugin on Asset Store
@qklxtlx Thank you so much for this code! It works well!!
Hi! Thank you for your great work of the code. We use this tool for UI part and we've implemented a PolyImage to add support Image in UGUI. This helps a lot with both memory and performance.
If you are interested, you can find more info here PolyImage - Support Polygon Sprite in UGUI Image