Search Unity

Shapes - a real-time vector graphics library

Discussion in 'Assets and Asset Store' started by Acegikmo, Jul 3, 2020.

  1. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    398
    Unfortunately instancing is already disabled :(

    Any other ideas?
     
  2. dimib

    dimib

    Joined:
    Apr 16, 2017
    Posts:
    50
    Does this asset work with the standard built-in render pipeline?
     
  3. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    upload_2021-8-17_14-20-33.png

    Line in volumetric 3d with dashes looks bugged, it's hollow and noisy at the caps (also if 'End' is set to the same as 'Start', it unexplicably becomes a sphere shape with the secondary color)

    Also is there a way to have endpoints/caps of polylines also have rounding?
    Or Rectangle/Polyline be Volumetric 3D (rounded or cubic)?
    Or Torus/Arc have a radial completion amount with cap rounding (for progress feedback elements)?

    In the docs Draw.Command mentions in a separate bullet point that 'ImmediateModeShapeDrawer does this for you', but there's no Draw.Command inside it, it's likely a typo and just a continuation of the bulletpoint before it; but i think it should be corrected as it's tempting to think you don't have to use Draw.Command anymore.
     
  4. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Also Setting Draw.LineGeometry to Flat2D seems to force the z position of drawn lines to 0, which is not expected and not what the same option in the Line component does (it aligns the line with xy, but keeps the z position, which is expected).
    Or is there maybe something else needed to be set to make it work the same?
     
  5. ryanzec

    ryanzec

    Joined:
    Jun 10, 2008
    Posts:
    696
    I did try regen and clean install, should this package work with the 2D URP renderer as I am using that?
     
  6. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Is this asset still supported?
     
  7. firepad9

    firepad9

    Joined:
    May 20, 2016
    Posts:
    8
    I enabled hdr color in config ,it work when i create a shape by editor, but not work with code .:(
    Code (CSharp):
    1. ... ...
    2.     [ColorUsage(true, true)]
    3.     public Color InnerStartColor;
    4.     [ColorUsage(true, true)]
    5.     public Color InnerEndColor;
    6.     [ColorUsage(true, true)]
    7.     public Color OuterStartColor;
    8.     [ColorUsage(true, true)]
    9.     public Color OuterEndColor;
    10. ... ...
    11.  
    12.     private DiscColors _discColors;
    13.  
    14.     public override void DrawShapes(Camera cam)
    15.     {
    16.         using (Draw.Command(cam))
    17.         {
    18.             ShapesConfig.Instance.useHdrColorPickers = true;
    19.             _discColors.innerStart = InnerStartColor;
    20.             _discColors.innerEnd = InnerEndColor;
    21.             _discColors.outerStart = OuterStartColor;
    22.             _discColors.outerStart = OuterEndColor;
    23.   ... ...
    24.          
    25.             switch (DiscType)
    26.             {
    27.                 case DiscType.Disc:
    28.                     Draw.Disc(_discColors);
     
  8. danBourquin

    danBourquin

    Joined:
    Nov 16, 2016
    Posts:
    34
    I could have some help on the PolygonPath and the usage of ArcTo.
    I don't understand how it work. It takes the last point and ask for a corner point and the next point. If I want to make an half circle, how do I do ? Could someone explain me what's expected as corner and next point?

    Thank you all !
     
  9. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Has the author vanished, or is support just not included anymore?
     
  10. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    since 4.0.0 all weird flickering should be resolved!

    Yes, works across all three (built-in, URP and HDRP)

    dashed 3D lines are generally a complicated thing to solve, but I can probably look into solving the noisy ends, though an easier solution for now is to use square end caps or make sure the dashes don't perfectly align to where the mesh cuts off

    as for the end = start case, generally this is an invalid shape, and so any behavior there will kinda by definition be a little unpredictable and weird~ there's not really one canonical expected shape, because the line doesn't have orientation anymore

    not at the moment, feature request thread here

    currently there are no plans to add volumetric 3D rectangles, though you can construct it using multiple 3D lines

    as for 3D polylines, it's a complicated one, feature request here

    Rounded caps are already supported in 2D arcs, as for the torus, there's no support for a partial torus/volumetric arc at the moment

    I've updated the docs to clarify this now!

    Flat2D should behave the same way for both lines and polylines - Flat2D means Z = 0 for all points, and the line/polyline will be restricted to the local XY plane. The Billboard option allows you to set a Z position, but the line/polyline itself is still using flat geometry.

    if you want to use a different plane, you can rotate the transform, or in the case of immediate mode, you can set Draw.Matrix to some other space

    I have not vanished! I just have more than one projects at any one moment, and this thread is the one I check the least regularly, even when working on Shapes exclusively.
    The feedback forum is the best place to report bugs, ask questions or request features.

    I'm also available in my discord in the Shapes channel for quick questions

    It will add points in the arc fit into the corner between the previous point, and the corner, and the next point, with the given radius. There's no way to do a half circle with a single ArcTo, but you can do it with two corners, one after the other

    upload_2021-9-5_14-10-39.png
     
  11. danBourquin

    danBourquin

    Joined:
    Nov 16, 2016
    Posts:
    34
    Thanks you for your reply. Is it possible that if we have a lot of point on the arc, very close it detect an intersection ? I have tried to make my own "Arc" method (with positionStart, positionEnd, centerPosition and radius parameters). And I'm facing some trouble when I add too much point on my arc. For example it draw with 24 partition of the arc, but not more.
    It's not important so if you don't know yet don't take time to search !
     
  12. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    some of the geometry breaks down if you have points in the same location, yeah, (if that's what you're asking) and it might apply to points very close to each other too depending on which type of polyline joins you are using

    for smooth paths with many points I always recommend using the Simple joins, they are the cheapest and the least error prone, because of their simplicity

    all other join types have various edge cases that might break in extreme circumstances
     
  13. danBourquin

    danBourquin

    Joined:
    Nov 16, 2016
    Posts:
    34
    I was drawing small object (~0.05 unity unit) that's maybe the reason. I'll check it. Thanks for your answer!
     
  14. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    69
    Is it possible to use this asset to draw shapes to a Texture2D? If so, how is this done?

    I'm trying to draw to a Texture which is in turn being fed into a shader input.

    thanks,
     
    Last edited: Sep 16, 2021
  15. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    yes! you first render to a render target, and then save it to a Texture2D
     
  16. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    160
    Hi! could you please help me with some strange bugs? I have errors in some browsers in webgl:

    -------- GLSL link error: Fragment shader active uniforms exceed GL_MAX_FRAGMENT_UNIFORM_VECTORS (261)

    is there any way to handle it when using shapes? maybe you can tell what can be the reason and I will try to fix it
     
    Last edited: Sep 21, 2021
  17. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    69
  18. mGMM

    mGMM

    Joined:
    Apr 3, 2017
    Posts:
    6
    Are there any plans to support the 2D Renderer?
     
  19. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    yes, although shapes is moving slowly right now, as I'm dealing with near-burnout symptoms unfortunately :(
     
    Last edited: Oct 7, 2021
    mGMM likes this.
  20. Bivens32

    Bivens32

    Joined:
    Jul 8, 2013
    Posts:
    36
    Can I use Shapes in a custom editor window? If so, can it somehow be embedded in my tool so I can share it without sharing Shapes itself? I'm trying to draw some animated dashed lines in my tool and don't know of any way to do it myself using Unity's Gizmos/Handles. Any thoughts anybody?
     
  21. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    69
    Is it possible to interactively draw and edit (say) a Polygon shape at runtime?

    If not directly supported, any tips?

    I guess if one were to implement it from scratch then presumably one would do some sort of hit testing against (say) a flat surface (I want users to be able to draw 2D polygons) and then draw each line in immediate mode until the next point and lay down another "point" shape. And repeat until the polygon is closed.

    Presumably one would have to detect self-intersections and abort the draw. Does Shapes care whether (say) a polygon is drawn clockwise or counterclockwise?

    For editing, presumably the "point" markers would be selectable (I assume all shapes are meshes and can have colliders?).

    What I am trying to achieve is to allow a user to take an image and trace out a polygon around the foreground and use that to separate the background from the foreground.

    thanks,
     
  22. ejoissa

    ejoissa

    Joined:
    Mar 12, 2021
    Posts:
    1
    Hello. I want to draw a Bezier curve between two points on my transform matrix(local Points , I don't know how do they say it). is there any class I can use to draw it for me?

    essentially I want to draw some spheres (points) in Bezier or circular shape like the picture below.
     

    Attached Files:

  23. Hoyar

    Hoyar

    Joined:
    Apr 17, 2020
    Posts:
    1
    upload_2021-12-7_17-26-8.png
    [pic: 2020.3.24f1 LTS (Build-In), 4.1.1]

    I build on pc, it rendering successful.
    Target to android, not rendering after build, but gameview is correctly.
    I also try URP, add ShapesRenderFeature done, same problom occured.

    Can I try other way to fix?

    - ShapesVersion: 3.1.1 & 4.1.1
    - UnityEngineVersion: 2020.3.24f1 LTS (Build-In), 2021.1.22f1 (URP)
     
    Polyfemos likes this.
  24. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    677
    Shapes looks very good to me. From the Asset Store info, it seems you are including all source code. Is that correct?
     
  25. Saturday afternoon play with
    ImmediateModeShapeDrawer
    . (Original PNG and generated shape from code). I still have some learning to do to make proper beziers and arcs and whatnot.

    sidebyside.png zoom.png
     
    Last edited by a moderator: Dec 18, 2021
  26. Xaron

    Xaron

    Joined:
    Nov 15, 2012
    Posts:
    379
    This looks great, bought it. As a vectrosity user, what would be the differences or to rephrase, what would be better to use for drawing 2d stuff (e.g. HUD, lines, shapes)?
     
  27. warp23

    warp23

    Joined:
    Apr 12, 2017
    Posts:
    2
    Hi. When I installed the asset, it was not working at all when using URP. Just the default 3D pipeline. It was adding commands to the bufffer, but not rendering them at all. I noticed after some serious brain damage, that I get warning that my ForwardRenderererData was not found in Assets/. So after some time I found that you have to add a renderer feature in the Forward Renderer Data in order to make IM mode drawing actually rendered and so visible.
    Renderer features is empty by default. This is not mentioned in the tutorial. Maybe add it there?
    Using Unity 20.3.11f1 and Shapes 4.1.1.
    upload_2022-1-7_14-3-37.png
     
    hqvist likes this.
  28. Polyfemos

    Polyfemos

    Joined:
    Nov 13, 2020
    Posts:
    25
    Hi! I saw the comment above about Shapes not working on Android, and can confirm it doesn't work on iOS either.

    See screenshot. This is the FPS HUD Immediate Mode test scene running in Unity and on an iPhone.
     

    Attached Files:

  29. unity_CDVKxN7snkcptA

    unity_CDVKxN7snkcptA

    Joined:
    Mar 24, 2020
    Posts:
    13
    Hi there.
    We had Shapes in our project recently and now I'm looking for using it to optimise some runtime draws.
    So one thing is we have a room editor in game, which may need a grid view on the floor(just looks like the Unity Editor one).
    Does Shapes can draw the grid lines directly or need some tricks to do this?
     
  30. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It's possible to draw in editor windows, but not officially supported! And right now there's unfortunately no way to include Shapes in other that you sell, since it would include Shapes itself unfortunately.

    Drawing at runtime is definitely supported! However, Shapes does not support self-intersecting polygons, but it does support both clockwise and counterclockwise ones. As for colliders, Shapes doesn't have built-in colliders, it's a rendering-only library. You might be able to use the polygon mesh in a mesh collider though, or just pass the data to Unity's 2D polygon collider

    For a case like this it would be easiest to use the ring shape, as well as a ring with dashes for those round dots arranged in a circle. So yeah, definitely possible! I wouldn't recommend beziers for this shape, since it's all circular arcs, but there are bezier helpers in PolylinePath that you can use (path.BezierTo)

    Unfortunately I don't know why this keeps happening for some. There seems to be some cases where GPU instancing doesn't work, even though I've set everything up correctly on my end (as far as I know), and the platforms you test on, should support GPU instancing.

    I would start by testing a few things:
    1. If you are using immediate mode rendering in Shapes, try disabling immediate mode GPU instancing in the Shapes settings window, and then see if it works. If it works after this, we know that it's related to GPU instancing.
    2. Unity has a way to check if your current platform actually supports GPU instancing, I would run that on your target platform to double check that it should be supported.

    other than that I'm at as much of a loss as you are - I've implemented instancing support the way you should, it works just fine on many platforms, including iOS and Android for many, so I don't know why it seems to fail in some specific cases. There might be some hidden setting somewhere that disables GPU instancing elsewhere, though that's something I wouldn't know of!

    Source code is included, yes!

    I've never used vectrosity, so I wouldn't know I'm afraid!

    Right now the first-time setup is very clunky due to a but that was introduced in later versions of Unity, that causes the whole setup process to get a nullref and not execute properly.

    On first time setup, you *should* get a window that pops up that tells you that you need to assign the ForwardRenderererData, however, this doesn't happen right now unless you restart Unity (or recompile scripts). Sorry about the mess, hopefully it will be cleaner in the next update.

    you can! though make sure you don't overdo the grid and make it extremely fine-detailed, if so then you might run into some performance issues with 500+ lines. Ideally you'd use a single quad with a special grid shader, though of course it would be entirely flat, and would require a technical artist on your team!
     
  31. Polyfemos

    Polyfemos

    Joined:
    Nov 13, 2020
    Posts:
    25
    I think it's fair to assume that an emtpy URP project running the Shapes-included test scene should work properly on the latest iphones - there's not much room for hidden switches and settings.
    Let me know if there's anything I can provide to help.
     
  32. travlake

    travlake

    Joined:
    Oct 4, 2019
    Posts:
    50
    Is there an example or documentation anywhere of how to use the Stencil Buffer? My application is (I think) fairly simple, and was definitely mentioned above by @Amplify_RnD_Rick: I have some Shapes in the content of a ScrollView UI element, and I want to add another shape that hides the shapes when the content goes out of view.

    I've tried messing with the parameters in the StencilBuffer (Compare, Pass, Ref, ReadMask, WriteMask) but for can't make even a simple one-shape-masks-another shape example work. Sorry I'm an idiot when it comes to this stuff.

    Edit: Never mind, figured it out. The StencilBuffer properties match the ones Unity uses here: Unity - Manual: ShaderLab: Stencil (unity3d.com). In short: 1) Draw a new Shape where you want the existing Shapes to show. Everything outside this should be hidden. 2) Set new shape Stencil params to: Pass: Replace, Ref: 2. 3) Set all the existing items you want masked Compare: Less, Ref: 2.
     
    Last edited: Jan 21, 2022
  33. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    well, exactly, that's what I would expect! Unity shouldn't struggle here, they should have cross platform support, which is why I'm confused as for why it doesn't work in some cases

    I've been trying to collect information on this in this support forum thread, I'd appreciate any contribution!
     
  34. jreinjr

    jreinjr

    Joined:
    Nov 13, 2017
    Posts:
    2
    Hello! I'm sure this is more an issue with my lack of understanding of .asmdef files and assemblies, but I'm having a really hard time getting Visual Studio to recognize any of the classes for immediate mode drawing. I've attached a screenshot of what I mean - all samples run fine in Unity without errors, but inside Visual Studio it's as though none of the assemblies are loaded (or something). I've tried this with and without the rest of my code inside its own assembly referencing the Shapes asmdef files. Would be very glad if you have any ideas!
     

    Attached Files:

  35. laurienash

    laurienash

    Joined:
    Mar 15, 2013
    Posts:
    61
    Hi - love this asset!

    I was just wondering - is it possible to set up the Polygon material to render after post processing?

    Im using Unity HDRP 2021. I have 1 sprite with a material set to render after post processing, and am then placing Polygon shapes in front of it to highlight areas of text.

    I'd like to set the material to Transparent, but then render after post processing so it displays on top of the text as a highlight. Is this an option?

    Thanks!
    Laurien

    upload_2022-2-11_15-19-30.png
     
  36. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    Can Shapes handle thick lines?

    I have been trying to create this with Unity's LineRenderer (red ones in the screenshot) but they just can't handle it well. The images overlaid are the ones I'm trying to recreate.

    I realized I'd have to use something like signed distance fields just to get this right, but I was hoping an existing plugin already does this.



    UPDATE: Ok, no worries. I've ended up working on the SDF curve shader myself.

     
    Last edited: Feb 19, 2022
  37. Bambivalent

    Bambivalent

    Joined:
    Jan 25, 2017
    Posts:
    16
    Hi, I have a question: I'd like to move some points of my Shapes polygon. Apprently this is not working unless I update a point in the inspector by hand:
    Code (CSharp):
    1.  
    2. DOTween.To(() => polygon.points[i], x => polygon.points[i] = x, PointsListEnd[i], duration);
    3.  
    Is it a limitation or do I do something wrong?
    Best regards, Max
     
  38. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    I'm not entirely sure if it's possible to render after post processing in HDRP without using immediate mode drawing. If you do use immediate mode, you can set the draw timing as the second parameter in Draw.Command, but other than that I'm not sure I'm afraid!

    when directly modifying the array of polygons, you'll have to mark the mesh as out of date, as the inline docs state:
    upload_2022-3-6_16-17-26.png

    I believe you can do this in the OnUpdate callback in the tween
     
  39. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    hi there and thanks for putting this out!

    When I override DrawShapes I only see my shape for the length of that frame and then it disappears. Any ideas?

    Also I'd like to be able to reference whatever shape I draw and when I see a tutorial I dont see anything being added in the hierarchy.

    Thanks!
     
  40. Hukha

    Hukha

    Joined:
    Aug 12, 2013
    Posts:
    61
    Hello!
    This asset looks awesome!
    But I have a small question that I can't find;
    My idea is to use it to create a procedural scroll game with colors (With different shapes I suppose) and to do that I need some type of "collision" detection, how it is handled in the asset? I can see a lot of examples that have some kind of collision but cannot see a hint in the docs nor the store.

    Thanks!
     
  41. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    398
    The Polyline class has a few variants of the SetPoints and AddPoints methods which accept IEnumerable and IReadOnlyCollection arguments - would it be possible to add another overload which accepts NativeSlice?
     
  42. Kruemelkatze

    Kruemelkatze

    Joined:
    Sep 5, 2014
    Posts:
    10
    I struggled with the same thing this week and ended up creating the appropriate 2D colliders myself using the same parameters I use for drawing. BoxCollider2D for a Rect, PolygonCollider2D for a Polygon, etc. For polylines (I ended up using only those for now), I use following code (posted by Freya on the feedback page) to create and feed points into an EdgeCollider2D:


    Code (CSharp):
    1. static Vector3 GetBezierPt(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float t)
    2.         {
    3.             float omt = 1f - t;
    4.             float omt2 = omt * omt;
    5.             return a * (omt2 * omt) + b * (3f * omt2 * t) + c * (3f * omt * t * t) + d * (t * t * t);
    6.         }
    Don't know if it's the best or recommended solution, but as of now it works for me. :)
     
    Hukha likes this.
  43. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    Hi, I'm getting a shader warning whenever I recompile my code in Unity 2021.3.4 (Shapes 4.1.3).

    Code (CSharp):
    1. Failed to load material Assets/_Asset Store/Asset Store Graphics/Shapes/Shaders/Generated Materials/Polyline 2D ColorBurn [JOIN_BEVEL].mat
    2. UnityEngine.Debug:LogWarning (object)
    3. Shapes.ShapesMaterials:InitMaterial (string,string,string[]) (at Assets/_Asset Store/Asset Store Graphics/Shapes/Scripts/Runtime/Utils/ShapesMaterials.cs:57)
    4. Shapes.ShapesMaterials:.ctor (string,string[]) (at Assets/_Asset Store/Asset Store Graphics/Shapes/Scripts/Runtime/Utils/ShapesMaterials.cs:23)
    5. Shapes.ShapesMaterialUtils:.cctor () (at Assets/_Asset Store/Asset Store Graphics/Shapes/Scripts/Runtime/Utils/ShapesMaterialUtils.cs:102)
    6. Shapes.ShapeRenderer:OnValidate () (at Assets/_Asset Store/Asset Store Graphics/Shapes/Scripts/Runtime/Components/ShapeRenderer.cs:195)
     
  44. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    Okay, interesting. I think I fixed this. Deleting the .mat + .meta and re-importing the package did not work, fwiw. But then I tried right click -> Reimport on the corrupted .mat and that did work.
     
  45. Pourya-MDP

    Pourya-MDP

    Joined:
    May 18, 2017
    Posts:
    145
    hello @Acegikmo first thanks for such a great plugin
    second i have some problems getting it work in my case
    as you can see the code i just want to draw lines alongside all the bones but thats not working using shapes , but debug.drawline works perfectly in my case ,
    if i simply change the endPos to a single game object its working perfectly but when i attach this script to my character and trying to visualize multiple bones it only renders a ball in the right hand (shown in picture)
    i would appreciate for a working script to just visualize bones in runtime using shapes!
    thanks in advance
     

    Attached Files:

  46. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    it sounds like GPU instancing is broken. you can test this by turning off GPU instancing in the Shapes settings window.

    I'm not sure why this happens! but usually it will fix itself if you do a clean reinstall
     
  47. arvzg

    arvzg

    Joined:
    Jun 28, 2009
    Posts:
    619
    Hello! is there any way to get Unity to be able to generate Asset Preview of prefabs that are using Shapes?
    The prefabs I have that use Shapes have asset preview that's just blank.
     
  48. helloroy

    helloroy

    Joined:
    Jun 23, 2016
    Posts:
    42
    Hello, is it possible to set the polyline to dashed?
     
  49. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    it should generate them if you're using component based Shapes, but with immediate mode preview cameras are excluded in the ImmediateModeShapeDrawer to prevent your scene objects from drawing in asset preview cameras

    not yet, but it is something I've been wanting to do! it's surprisingly complicated, unfortunately

    more info here: https://shapes.userecho.com/en/communities/1/topics/19-dashed-polylines
     
  50. charles-everyrealm

    charles-everyrealm

    Joined:
    Jun 30, 2022
    Posts:
    11
    @Acegikmo Hey Freya - can you do rounded corners as a line (e.g. a 90 degree angle rounded)? I assume so just want to make sure before purchasing.

    EDIT: I see that I can draw a straight line, then an arc, then another straight line. However, this line needs to be in an isometric format, meaning it needs to appear on an isometric tilemap so for that use case I don't think that will work.
     
    Last edited: Aug 25, 2022