Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

[FREE] Shapes2D - Procedural 2D shapes for Sprites and UI

Discussion in 'Assets and Asset Store' started by all_iver, May 21, 2016.

  1. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    You can interpolate via scripting with polygon shapes by setting vertices via code, but please read the performance and other notes in the documentation first. You would not be able to interpolate from a circle because of number-of-vertex limitations. It sounds like a mesh-based solution might be more what you're looking for?
     
  2. ElTotoro

    ElTotoro

    Joined:
    Dec 14, 2013
    Posts:
    3
    Hi! I just bought "Shapes2D" on AssetStore and now I stuck with a problem of building on Windows Standalone platform. In the editor everything works just fine, but if start to build an application, I get about 27 erros like this one:
    "Shader error in 'Shapes2D/Shape': maximum temp register index exceeded at Assets/Shapes2D/Shaders/Common.cginc(25) (on d3d9)"
    Could you help me with it? How can I build an application with this asset imported?

    My unity version is 2017.1.1f1 (64-bit)
    Thanks in advance!
     
  3. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    ElTotoro, this is from the documentation:

    For d3d9 the poly and path shaders are too complex. Your options are to remove the Direct3D9 graphics API from your player settings (Unity seems to be deprecating it anyway) or convert your shapes to sprites (which you should anyway unless you really need to use them procedurally). If neither of those options work for you then please feel free to email me about a refund!
     
  4. ElTotoro

    ElTotoro

    Joined:
    Dec 14, 2013
    Posts:
    3
    Thanks! This really work:)
     
  5. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Hey all, Shapes2D v1.12 is out - just a few quick changes from a user request:
    • Polygon and Path shape types now have a button to read their points from a PolygonCollider2D (points outside the shape's bounding rect will be clamped, though)
    • Polygon shape type now has a button to create a PolygonCollider2D
    • Arrow polygon preset now points to the right
    Also, Shapes2D is on sale for Cyber Monday for $6.99 right now!
     
  6. alelepd

    alelepd

    Joined:
    Feb 18, 2015
    Posts:
    7
    Hi, @lemon-tree I noticed that the antialiasing is not good on short angles (when rotating the objects in 3d). Is it possible to use antialiasing on these scenarios? I am currently working with 2d shapes in a 3d environment and the shapes need to rotate, but when they do–perpendicular to camera–, the edges look aliased.
     
  7. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Yes you're right, the antialiasing is only "correct" in 2d. The antialiasing is just a thin blurred padding around the edges of the shape. When using a perspective camera the thickness of the blur is based on calculating the size of a pixel in world units at the current z depth, but if the shape isn't billboarded/facing the camera exactly then it doesn't really work. Unfortunately I'm not sure how to fix this problem.

    You could try switching back to an older method of antialiasing. It might give better (still not "correct") results but I stopped using it because it isn't supported on some mobile platforms.

    In Shapes2D/Shaders/Common.cginc, find the lines that say this (line 80):

    Code (CSharp):
    1. // float2 aa = fwidth(pos);
    2. // _Blur = length(aa);
    3. _Blur = sqrt(_PixelSize * _PixelSize * 2);
    And change them to say this:

    Code (CSharp):
    1. float2 aa = fwidth(pos);
    2. _Blur = length(aa);
    3. // _Blur = sqrt(_PixelSize * _PixelSize * 2);
    Sorry I don't really have a fix for this.
     
  8. Ramphic

    Ramphic

    Joined:
    Jun 21, 2017
    Posts:
    57
    Hi, is it possible to provide more than 2 colors in gradient in your asset?
    Thankyou.
     
  9. Ramphic

    Ramphic

    Joined:
    Jun 21, 2017
    Posts:
    57
    Hi, is it possible to provide inner shadow option for your asset? as in attached picture:
     

    Attached Files:

  10. Ramphic

    Ramphic

    Joined:
    Jun 21, 2017
    Posts:
    57
    Hi, I'm getting this error while building for android and standalone, and shapes2D shader isn't getting loaded. It's getting as pink color.

    Can anyone tell me why please? It's very much needed for us.

    Thankyou.

    D/Unity: WARNING: Shader
    05-24 10:34:33.109 12031-12060 D/Unity: Unsupported: 'Shapes2D/Shape' - Pass '' has no vertex shader
    05-24 10:34:33.109 12031-12060 D/Unity: ERROR: Shader
    05-24 10:34:33.109 12031-12060 D/Unity: Shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    05-24 10:34:33.121 12031-12060 D/Unity: WARNING: Shader
    05-24 10:34:33.121 12031-12060 D/Unity: Unsupported: 'Shapes2D/Shape' - Setting to default shader.
     
  11. Ramphic

    Ramphic

    Joined:
    Jun 21, 2017
    Posts:
    57
    Hi,
    The issue got resolved - by reimporting the shapes2D asset after switching the platform in Unity.
     
    Seraphic572 likes this.
  12. Seraphic572

    Seraphic572

    Joined:
    Mar 11, 2016
    Posts:
    21
    Roundedness For Rectangular Shape Should be Visually Same For all Mobile Resoultions . How to Acheive it
     
  13. Seraphic572

    Seraphic572

    Joined:
    Mar 11, 2016
    Posts:
    21
    Will Shapes 2D Asset Work with Multiple Resoultions Properly ?
     
  14. Seraphic572

    Seraphic572

    Joined:
    Mar 11, 2016
    Posts:
    21
    Its not Working in my case See the Attachments below . How to Sort this Case
     

    Attached Files:

  15. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    FYI all, I have put the Shapes2D source up on GitHub. I don't have anything else I really want to add to Shapes2D so I'm spending my time elsewhere, but I wanted to make the source available so others can help make improvements or fixes as new Unity versions break things.

    Sorry @Seraphic572, I think we had other conversations in private chat but I can't remember if we addressed your last problem here. I'm guessing you've figured something out by now, but if not send me a PM and tell me your configuration (UI or Sprite shapes, and if UI then what kind of Canvas/CanvasScaler you have going on).
     
  16. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    883
    D'oh, bought the asset 2 years ago, and right now when I'm actually going to use it it went free and with no roadmap :(

    I was about to ask if runtime drawing would be possible (e.g.: drawing during play mode, with the same controls used in edit mode), at least in a sort of limited way, but I believe it's quite of a stretch to ask now that it's free :(

    I'd consider it as one of the possible features it could have, greatly expanding its initial purpose (runtime customization of... stuff :p)

    I know it's not the initial purpose of the plugin, but I can see stylized games taking advantage of it. :)
     
  17. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Hey @NeatWolf, it should be possible to do what you're talking about, just that you'd have to implement all the runtime editor controls. However I'd say a mesh-based tool (or some other approach) would be more robust and scalable for runtime purposes. Shapes2D is shader-based which means it has some arbitrary limitations and performance issues, so for me it's really best for in-editor use where you can convert to a sprite before runtime.
     
  18. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    155
    Such a great asset, not supported anymore?
     
  19. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Hey, thanks for the kind words! I don't have time to support Shapes2D anymore and I don't have any plans to continue working on it. But I can answer simple questions, or feel free to add an issue to the github (https://github.com/all-iver/shapes2d) and maybe somebody else could take a look at it too. As far as I know everything is still working in the latest versions of Unity.
     
  20. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Having said that, Shapes2D v1.13 is out containing some fixes for using canvases with Screen Space Camera!
     
    slimshader likes this.
  21. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    155
    Thanks! Another question tho: I've noticed that when Converting to Sprite, transparent areas are not transparent in the resulting sprite,making rounded corners and inner cutouts just white areas. Could something be done for that?
     
  22. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    That doesn't happen for me...does that happen with shapes in the included demo scenes too? Can you tell me more about what you're doing?
     
  23. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    155
    Yes, te same with demo assets, for example "Moon" when converted, becomes just white square (Unity 2018.4 and 2019.1)
     
  24. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    155
    I found the reason: it only works the way I reported when build not set to "Standalone". I am on mobile game so my build was set to Android, didn't try in iOS build yet tho. Anyways, on Standalone it works perfectly, question tho: how can I set resolution / size of rendered sprite?
     
  25. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Ah, okay. Thanks for letting me know about that. You can set the pixels per unit used during sprite conversion in Assets/Shapes2D/Preferences, but that only applies to sprite shapes, and UI shapes if the canvas render mode is World Space. Other than that you can just resize the object before conversion.
     
    slimshader likes this.
  26. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    75
    Fantastic work lemon-tree! I'm really excited to try this out.

    A question: Is it possible to create a shape and then programatically change the size or positions of the vertices dynamically via script?
     
  27. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Thank you! Yes, you can programmatically change polygon vertices or path segments by getting the Shape component and using settings.polyVertices or settings.pathSegments. Check the documentation for details (see also the warnings about using shapes at runtime). The Shape component also has methods for Get/SetPolygonWorldVertices() and Get/SetPathWorldSegments() that might be useful to you depending on what you're doing. Those are helpers for working in world units whereas using settings.polyVertices/pathSegments work in normalized coordinates.
     
  28. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    75
    Excellent and thank you for following up lemon-tree! I should expand on what I would like to do first.

    I would like to be able to change the width and height of a 2D rectangle programmatically. Is this doable without using scale as everything is in Unity?

    For example:

    I have a rectangle that is 100 width x 100 height.

    I would like to be able to change it to 220 width via script.

    Is this possible and would you have ideas on how to approach this using your asset?
     
  29. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Hmm, why don't you want to use scale? In Shapes2D you would rescale the object to do that, though if you used a polygon shape and have its scale be your max desired scale (say 220), then you could programmatically change the vertices to be smaller than that without changing the scale again. However, it seems overly complicated and would draw a lot of wasted pixels. A shape's scale is its drawable boundary so you can't move the vertices outside of that area. Maybe you could try a mesh approach instead, i.e. make a rectangle mesh on the fly.

    If you don't want to scale it because you want an outline to stay the same size, then Shapes2D handles that automatically by resizing the outline as you scale, or you could use a 9-slice image (if you're working with Unity GUI). Hope that makes sense!
     
  30. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    84
    Hello and thanks for great asset! I want to ask about Path segments. It is made with Bezier curves and I wish to change t value for start and end points in runtime (to make path "grow" along time).
    Something like Shape.settings.pathSegments.p0.t = 0....1.0f
    Where 0 is start point of curve and 1 is end.
    But seems it can't be done in current implementation. Any suggestion about how to do that?
     
  31. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    84
  32. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    33
    Thank you very much, an excellent asset, hopefully it continues to grow.
     
  33. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    JuanJSAR likes this.
  34. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    33
    Hi, I ask you is there any way to reduce the size of one side?
    upload_2019-11-26_9-4-32.png

    But I have this difficulty:
    upload_2019-11-26_9-14-56.png

    I think that with an internal scale option this problem could be solved.
     
  35. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Hi, sorry but I'm not sure exactly what you're trying to do. It looks like you have a normal Sprite on top of a Shape and you want them to match? Currently there's no way to adjust the corners inward like that, if that's what you mean... Maybe you could get closer with a path shape because then you can adjust the curves manually? It depends on what you want to do though.
     
  36. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    33
    Is there any way to make the "Original"? that is not a "Path"?
    Sin título.png
     
  37. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Currently the path shape would be the only option. You could overlay multiple shapes (like an arc and a rectangle), but it might not look nice.

    I hacked in something quickly that might do what you want, but no guarantees. Replace your
    Shapes2D/Shaders/Rectangle.cginc
    file with this: https://gist.github.com/all-iver/59423ee929475d0792f5dcd004a05254. To use it, change your roundness per corner settings to 0,0,1,1 (bottom left and bottom right are 1, otherwise 0). Then it will use different code to draw something like your picture (example below). I hope this helps! But if not, then Shapes2D probably can't do what you want.

    upload_2019-12-2_11-23-50.png
     
    Last edited: Dec 2, 2019
  38. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    33
    Thanks that was what I wanted, could you explain to me how I add it as a new rectangle without deleting the previous one?
     
  39. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    It should not affect your existing shapes unless they have the 0, 0, >0, >0 roundness settings. If you need it to be a totally separate shape that's possible but a little more involved and I don't have time to do it right now. Can you work around that?
     
  40. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    33
    It would be excellent if there was some way to move the central node to alter the shape, where 0 in X and Y is the square by default.
    Sin nombre.png
    If this function could be added, the versatility of what can be achieved is greatly increased.
     
  41. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    That's a cool idea! Offhand it might not be feasible to do in the shader, but you could probably implement something like that in user code with the Path shape and modifying the path segments in a script.
     
  42. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    33
    I'm glad you liked the idea, I would be the most excited and I would like to see it as soon as it is available.
    I've been trying for a while, but I can't do it.
     
  43. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Just so I don't lead you on, I don't have time to work on Shapes2D right now other than to help people out with bugfixes or advice when I can. But if you give it a shot and you want help with something specific to Shapes2D, feel free to post here and I'll try and help out!
     
  44. nastajus

    nastajus

    Joined:
    Apr 16, 2014
    Posts:
    3
    Hi Oliver! What a great library. Question, is it just me or are Shapes not serializable? At a glance it looks like it should be since I see lots of [SerializeField] attributes used, but when I reopen a scene with GameObject created `CreatePrefab` and have my own custom component run upon waking/starting/validating, it fails to retrieve previously-stored Shape in a field, which otherwise worked (during a single scene session, no reloads). I tried searching for this in this thread and in the documentation, but no luck. I should mention I'm still learning how to make Unity's Serialization obey my will, and that I invoked your MenuItems.CreatePrefab directly via reflection. Though I suspect if anything's wrong, it's that I'm not following Unity's Serialization Rules correctly, in some way that eludes me. What I know is my field loads null, and I don't expect it to be. Any ideas?

    Thanks in advance, and again what an amazingly useful library! I'll use this for a long time!
     
  45. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    Hey @nastajus, thanks for the kind words! From your description I'm not exactly sure what you're doing. I don't think you'd need to use `CreatePrefab()` for anything - it's just a helper utility for my editor scripts. Can you give me a step-by-step rundown of exactly what you're doing? If you take Shapes2D out of the equation and try to use a normal GameObject in the same way, does that work? That might help identify if you're not understanding Unity's serialization correctly, or if there's some problem specific to Shapes2D.
     
  46. nastajus

    nastajus

    Joined:
    Apr 16, 2014
    Posts:
    3
    So I've spent 2 hours trying to isolate my issue into a reproducible example to post here, without all the extra fluff of my own project. So naturally serialization of the shape field / path segments array works in all my test examples just now, regardless of switching scenes or restarting Unity :rolleyes:. But not in my real project for the shape reference.o_O Bit by bit I make the simple test look closer and closer to my real code with the issue. For now I'll save you the hassle of posting actual code just yet, because I'm dealing with 5 different unity life cycle hooks across 3 different levels component dependencies, and having it execute from a Custom Editor. Perhaps I'm a mad man doing it all this way, but I am intending it to be clean code. I will post back when I have better grasp of where the issue is. Thanks for the prompt reply!
     
    all_iver likes this.
  47. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    166
    Hi, is it possible to have subtractive blending for layers? I.e. I want to create a shape masked by a child layer.
     
  48. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    102
    You should be able to use Unity's Mask or RectMask2D for that (I don't think SpriteMask works but haven't had time to look into it).
     
  49. pixelsage

    pixelsage

    Joined:
    Jan 28, 2014
    Posts:
    8
    Shapes2D has been working like a charm for me, just until yesterday when I switched to Linear color space (away from Gamma). The colors look different now, kind of washed out. Anyone else run into this issue?
     
  50. rutkoski

    rutkoski

    Joined:
    Jan 9, 2015
    Posts:
    5
    The problem is not with Shapes2D, it's just the nature of Linear Color Space, RGB colors are just look diferent that way. Had the same problem, had to switch to Gamme color space to fix it.
     
unityunity