Search Unity

Deleted

Discussion in 'UGUI & TextMesh Pro' started by qiankanglai, Mar 6, 2016.

  1. qiankanglai

    qiankanglai

    Joined:
    Jun 8, 2013
    Posts:
    22
    Deleted
     
    Last edited: Jan 19, 2018
  2. Tef

    Tef

    Joined:
    Apr 6, 2013
    Posts:
    18
    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?
     
    wccrawford likes this.
  3. Andreas Loew

    Andreas Loew

    Joined:
    Feb 27, 2013
    Posts:
    17
    @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.

    @qklxtlx
    This is awesome!
     
    wccrawford likes this.
  4. Tef

    Tef

    Joined:
    Apr 6, 2013
    Posts:
    18
    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.
     
  5. Tef

    Tef

    Joined:
    Apr 6, 2013
    Posts:
    18
    Thanks for the information!
     
  6. Andreas Loew

    Andreas Loew

    Joined:
    Feb 27, 2013
    Posts:
    17
    @Tef
    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:


    polygon-tracer-tolerance-2.png

    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.
     
  7. Tef

    Tef

    Joined:
    Apr 6, 2013
    Posts:
    18
    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!
     
    Andreas Loew likes this.
  8. Tef

    Tef

    Joined:
    Apr 6, 2013
    Posts:
    18

    Does this also work for old flash games in Starling? That would be very interesting for our old game.
     
  9. chenxr

    chenxr

    Joined:
    Aug 9, 2016
    Posts:
    1
    How about the slice model ,I have studied for a long time, but it's so complex
     
  10. guzzo

    guzzo

    Joined:
    Feb 20, 2014
    Posts:
    79
    This looks amazing!

    Thank you!
     
  11. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    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).
     
  12. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    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
     

    Attached Files:

  13. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
    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?
     
    Last edited: Oct 3, 2016
  14. -Aymeric-

    -Aymeric-

    Joined:
    Oct 21, 2014
    Posts:
    110
    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 ;)
     
  15. Deankovitch

    Deankovitch

    Joined:
    Sep 28, 2012
    Posts:
    31
    Hi all,

    I'd like to share with you my plugin to create 2D Primitives.
    You can create these primitives
    • Circle
    • Star
    • Rounded square
    • Arrow
    • Spiral
    • N-Sides Polygon
    • Gradient Quad
    • 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;
    • Fully animable;
    • Lightweight;
    • Fully configurable;
    • 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
    2D Primitives
     
  16. dookeybre

    dookeybre

    Joined:
    Nov 10, 2012
    Posts:
    6
    @qklxtlx Thank you so much for this code! It works well!!
     
  17. anthony_q

    anthony_q

    Joined:
    Oct 28, 2017
    Posts:
    6
    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
     
    qiankanglai likes this.