Search Unity

SVGAssets - SVG Rendering Engine for Unity.

Discussion in 'Assets and Asset Store' started by turbo3d, Jul 18, 2014.

  1. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    Are you using Unity's built in atlas generator or some other method for 1.3?
     
  2. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    You can have a look at this guide: http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Paths-Combining.html
    It seems that under Inkscape it is possible to clip paths using an intersection operation.

    The rendering performance are perfectly suitable for init/offline rendering. Of course, in order to not run out of texture memory, it would be better to split rendering operations and load/generate one game level at once. Your idea to cache generated bitmaps on the device could be feasable in future, but it will require (at least) the permission to write on the device filesystem (SD card).

    No, we have implemented an efficient 2D bin packer by ourself. In order to optimize the packing results, you can pre-process your SVG files using SVGO tool (https://github.com/svg/svgo)
    This tool can be executed from command line too, so the integration in a custom building system is possible.
     
  3. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    On the iPhone this could be done to the /tmp or caches directory (No SDCard available)
     
  4. Yokil

    Yokil

    Joined:
    Sep 9, 2012
    Posts:
    26
    I wonder if you have plans to use this technology with Ngui
     
  5. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    We will surely investigate the possible integration of SVGAssets with GUI plugins available on the asset store and with the Unity 4.6 UI native solution in the future!
     
  6. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    Just discovered this new plugin, which I'm very happy to see. I can't justify the expense right this moment, but if I ever get close to shipping I may revisit. One thing I'd suggest is providing an SVG cached material — i.e. a material that renders once and saves the bitmap — for mobile distribution. (Obviously, this may not make sense if rendering the image is faster/more power economical than loading it from storage, but I suspect that will seldom be the case.)

    I downloaded your evaluation package. One thing I'd recommend is supporting Mac standard keyboard settings (command-o for open, for example) and putting several example files in one place, rather than the same example in lots of places. Not burying the executables five levels deep in folders wouldn't hurt.

    It would be nice if the player also allowed you to render the file at different scales experimentally.

    I see you don't have any reviews yet. I hope you're making some money off this! (I can easily see this plugin making the difference between a huge game being downloadable via cellular connection and not, which makes a big difference in downloads.)
     
  7. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    You're not the first to suggest a "cache to bitmap / svg" material, so we'll definitively plan the development of such feature, for the future SVGAssets releases!
     
  8. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    Thanks for your suggestions, they seem really interesting!
     
  9. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    Hi,
    your asset looks interesting. I watched the video and saw that in your example you make the SVG to Texture2D conversion at start. Do you see any problems if i want a more dynamic solution? I want a Texture2D placeholder that renders on the fly a different SVG file depending on my current app logic.(I don't want to have a pool of SVG files in the background/memory).
     
  10. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    There aren't problems to generate textures (from SVG) at runtime.
    The simple generation code below can be called at any time in your Unity application.
    Code (csharp):
    1.  
    2. private Texture2D DrawSVG(string svgXml, uint texWidth, uint texHeight, Color clearColor, bool makeNoLongerReadable)
    3. {
    4.     SVGDocument document;
    5.     SVGSurface surface;
    6.  
    7.   // create a 2D texture (no mipmaps)
    8.   Texture2D texture = new Texture2D((int)texWidth, (int)texHeight, TextureFormat.ARGB32, false);
    9.   texture.filterMode = FilterMode.Bilinear;
    10.   // create a drawing surface, with the same texture dimensions
    11.   surface = SVGAssets.CreateSurface(texWidth, texHeight);
    12.   if (surface == null)
    13.       return null;
    14.   // create the SVG document
    15.   document = SVGAssets.CreateDocument(svgXml);
    16.   if (document == null)
    17.   {
    18.       surface.Dispose();
    19.       return null;
    20.   }
    21.   // draw the SVG document onto the surface
    22.   surface.Draw(document, new SVGColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a), SVGRenderingQuality.Better);
    23.   // copy the surface content inside the texture; NB: we set the delateEdgesFix flag because we are using bilinear texture filtering
    24.   surface.Copy(texture, true);
    25.   // call Apply() so it's actually uploaded to the GPU
    26.   texture.Apply(true, makeNoLongerReadable);
    27.   // destroy SVG surface and document
    28.   surface.Dispose();
    29.   document.Dispose();
    30.   // return the created texture
    31.   return texture;
    32. }
    33.  
    Please note that SVGAssets is not intended for realtime usage (i.e. at each frame generate and update textures), please see post number #46: the slowness is not due to the pure SVG rendering, but because the combination of Texture2D.SetPixels32 (the function that copies pixels produced by SVGAssets) + Texture2D.Apply (the function that actually loads texture pixels into GPU memory).
     
  11. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    Many thanks for the info!
    I don't plan to update the texture every frame so i have no performance concerns. :)
     
  12. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    Good to know!
    By the way, if you decide to purchase SVGAssets 1.2 and you are interested in receiving / testing the new 1.3 version (still in beta), don't forget to contact me in private: I'll be glad to share with you (as well as for other SVGAssets 1.2 customers) the beta builds.
     
    ibyte likes this.
  13. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    SVGAssets 1.3 is out!
     
  14. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    Finally...
     
  15. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    Automatic Sprite-from-SVG generation with optimized texture atlasing. Unity Player filesize reduction: no bitmaps, just SVGs deployment. All the graphics generated at the right resolution on the target device.
     
  16. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    Now working on WP8 support.
     
  17. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    The way I see it, svg has two benefits.... scalable graphics require much less storage space and can be generated at runtime... you're doing that, to a fixed resolution. Second benefit is being able to scale the graphics in realtime in the game... you're not. I would focus on making that a possibility.
     
  18. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    SVGassets rendering isn't performed at a "fixed resolution" but instead at the right (native) resolution on the target device. The benefit to deploy SVGs instead of bitmaps, and the relative storage space saving, is there.

    Surely we'll work on a vector graphic engine for the realtime purpose, but this is a completely different task: it will be OpenGL based, and, probably, not a simple SVG renderer.
     
  19. Saxy_Guy

    Saxy_Guy

    Joined:
    Nov 27, 2013
    Posts:
    34
    What are your plans with the current engine once you ship the new (realtime) one? Continued commercial development parallel to the new one, open-sourcing (unlikely but would be the best thing in the world for uGUI developers) etc...?
     
  20. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    As Mazatech, our plan is to support both our engines: AmanithVG SRE and GLE exists since 2008 as crossplatform native libraries. SVGAssets Plugin (the current one) for Unity is based on AmanithVG SRE rendering engine, and it's aimed to manage the SVG-to-Texture2D process at initialization time. The new one will be based on AmanithVG GLE and it will have a different purpose: the realtime 2D vector graphic rendering.

    Internally, we are discussing the opportunity to open-source the editor plugin components, but it's highly unlikely that AmanithVG and other low-level libraries will be released under opensource licences.
     
  21. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    To be more precise: editor scripts, workflow scripts and C# interfaces to the low level native library.
     
  22. Saxy_Guy

    Saxy_Guy

    Joined:
    Nov 27, 2013
    Posts:
    34
    Cool, that's good to know. I may end up getting SVGAssets in the near future, as it's no doubt the best SVG -> texture solution for Unity. Thanks for the info!
     
    turbo3d and Ska0s like this.
  23. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    Enhanced the SVGLoadBehaviour script, now Atlas and Sprite reference fields can be visually selected by a comfortable editor! (see the screenshot)

    Added the support for Windows Phone 8 and Windows Phone 8.1

    Working an a new tutorial (the classic couples cards game!), showing how it is simple to write a game that supports whatever resolution you want...automatically! (see the screenshot)

     
    Last edited: Aug 28, 2018
    ibyte likes this.
  24. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    Hi Looking good!! - what is the projected time line for

    1) Clipping
    2) uGUI?
    3) U5
     
    Last edited: Feb 27, 2015
  25. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    We are working on all these aspects for the next release. We'll keep you updated ;)
     
  26. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    Hi Thanks for the update - really appreciate your support!

    iByte
     
  27. reykjavik72

    reykjavik72

    Joined:
    Mar 17, 2013
    Posts:
    2
    If I buy a copy of 1.3 which the store lists with date=2015-Jan-30, will that version work with Unity 5?
    Or maybe I should wait until your team is done testing on Unity 5?
     
  28. Ska0s

    Ska0s

    Joined:
    Feb 4, 2014
    Posts:
    32
    Hello reykjavik72, SVGAssets 1.3 is working on Unity 4.5 and Unity 4.6 only. We are working on the porting on Unity5 (it seems that Unity5 has some problems with native plugins for different architectures but same OS; in the detail we got some errors on Android operating system if we include all ARM, MIPSand x86 platforms).
     
  29. seastar

    seastar

    Joined:
    May 3, 2015
    Posts:
    6
    I have a few questions related to SVGAssets.
    Is it currently compatible with Unity 5? If not yet, what time can it be compatible?
    Is it possible to usie SVGAssets on open source projects? I will have 3 open source game projects (currently 1 of them is on development).
    Do you have a plan to support different kinds of licenses? For example, any discount for open source projects? I am asking it because SVGAssets is a little expensive asset.
     
  30. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    Hello seastar, at the moment SVGAssets 1.3 is working on Unity 4.5 and Unity 4.6 only. We are working on the porting on Unity5 (it seems that Unity5 has some problems with native plugins for different architectures but same OS; in the detail we got some errors on Android operating system if we include all ARM, MIPS and x86 platforms).

    For what regarding licensing, SVGAssets is a closed source project; by purchasing it, you won't have the right to obtain nor to redistribute its (native) source code (SVGAssets C# scripts, of course, are available and you can redistribute it!).

    Out of it, this does not imply that you cannot use SVGAssets within opensource projects, if the chosen opensource license allows it.

     
  31. seastar

    seastar

    Joined:
    May 3, 2015
    Posts:
    6
    So, if I buy SVG Assets, I can import it to my project and I can distribute my whole project as a Unity project legally, right? Or should I remove SVG Assets' all resources (scripts, libs, etc) from the project before checking in the project to the version control system?
    By the way, does SVG Assets have problems just on Android/iOS or as you said, on all the different platforms? For example, can I build the project for Mac OS X (Universal) on my 64 Bit Windows system? If no, can I use SVG Assets for only 64 Bit Windows until the next version is released?
     
  32. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    You just need to remove SVGAssets native libraries (i.e. all libraries present in Assets/Plugins directory) in order to distribute it as Unity project; you can include SVGAssets C# scripts.
    Of course, you can distribute the Unity player built with SVGAssets libraries inside (i.e. the executables).

    For the other technical question, I will send you a private message.

     
  33. seastar

    seastar

    Joined:
    May 3, 2015
    Posts:
    6
    thanks turbo3d
     
  34. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    SVGAssets 1.3.5 (Unity5 support + Windows Phone 8/8.1 support + card game example + editor enhancements) is waiting for approval...cross the fingers!
     
    ibyte likes this.
  35. Lord_Pall

    Lord_Pall

    Joined:
    Sep 25, 2009
    Posts:
    52
    I'm seeing 2-4 second increase in load times when using a few svgassets on Android.
    I see
    D/dalvikvm(17825): Trying to load lib /data/app-lib/<appidhere>/libAmanithSVG.so 0x42343668
    D/dalvikvm(17825): Shared lib '/data/app-lib/<appidhere>/libAmanithSVG.so' already loaded in same CL 0x42343668
    D/dalvikvm(17825): Trying to load lib /data/app-lib/<appidhere>/libAmanithSVG.so 0x42343668
    D/dalvikvm(17825): Shared lib '/data/app-lib/<appidhere>/libAmanithSVG.so' already loaded in same CL 0x42343668
    D/dalvikvm(17825): Trying to load lib /data/app-lib/<appidhere>/libAmanithSVG.so 0x42343668
    (Continues ~10 times)

    every time I transition scenes.

    Any idea what's trying to load that .so file so many times? As it stands i can't use this because it's such a big hit to load times.
     
  36. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    Hello Lord_Pall, I will contact you privately in order to investigate the issue.

     
  37. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    Hi so the package is now Unity 5.0 only? That is not a problem for me . Just checking
     
  38. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    Hi ibyte, SVGAssets 1.3.5 example scenes are created using Unity 5.0.1 editor, but the plugin itself, as well as scripts, are compatible with Unity 4.5+
     
  39. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    Hi, FYI I was unable to import that package in 4.6.5.
     
  40. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    I do apologize Glen, actually the package was submitted with Unity5, that's why you cannot import it directly in Unity 4.5.x. Anyway, if you copy script files and plugin banaries by hand in a Unity 4.5.x project, I confirm that it will work.

    When we'll release the next version, we will surely fix this inconvenience.

    Thanks for your patience ;)
     
  41. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,047
    No worries just wanted to give you a heads up and thanks for posting a work around for now.

    I haven't checked was clipping support included in 1.3.5?
     
  42. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    No Glen, SVG clipPaths are not yet supported ;)
     
  43. Mistale

    Mistale

    Joined:
    Apr 18, 2012
    Posts:
    173
    @turbo3d How would this asset perform on, say, an iPad Air given that all svg files have to be converted to retina textures? Do you have any metrics? I understand that the performance is as as good as it can get, but since memory is limited on mobile, and since creating textures, setting pixels etc all take extra time regardless of your optimizations, what can a developer realistically expect on mobile platforms?
    I'm looking at this as well as other solutions, both texture- and mesh-based, but its hard to know if this asset will fit my needs without actually buying it, and the cost is a bit prohibitive if it turns out to be too slow or use too much memory to be used as a one stop solution for mobile games.
     
  44. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    Hello @Mistale, unfortunately at the moment we don't have precise metrics about timings to share with you.
    We have uploaded a small video showing a game example in which all the SVG graphics is rendered on textures at initialization time, and on device rotation events:


    Maybe it could give you an idea of achievable performance on two different devices (Android: LG Nexus4, iOS: iPad Air). About memory concernings, during a texture rendering you'll need an amount of memory sufficient to temporarely store the textures pixels; after the texture.Apply() such memory is freed.
     
  45. Mistale

    Mistale

    Joined:
    Apr 18, 2012
    Posts:
    173
    @turbo3d That looks very fast, but Im still concerned about memory usage when dealing with larger projects. Mostly because modern tablets and phones have such a high resolution that a 2048 texture would be needed for a single fullscreen background.
    Are you still planning on creating a GLE version for Unity? In an ideal world I would really like the opportunity to choose per svg file if it should be treated as a texture or imported as a mesh (GLE). Then you could really save memory on having large 'simple' geometry as meshes, and more intricate shapes with lots of details as textures.
     
  46. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    WARNING: the use of IL2CPP technology with SVGAssets plugin on iOS devices seems to generate wrong code in the automatic IL2CPP conversion.

    We have seen that using IL2CPP, a function (svgtSurfaceCopy) in the produced native wrapper file (Bulk_Assembly-CSharp_0.cpp) is subjected to a bad conversion of arguments (bad marshaling).
    At the moment, the only workaround is to modify it by hand, then it seems to work. In the detail the generated svgtSurfaceCopy function (Bulk_Assembly-CSharp_0.cpp) must be substituted with the following one by hand:
    Code (CSharp):
    1. // System.Int32 AmanithSVG::svgtSurfaceCopy(System.UInt32,UnityEngine.Color32[],System.Int32)
    2. extern Il2CppType Color32U5BU5D_t25_0_0_0;
    3. extern "C" {int32_t DEFAULT_CALL svgtSurfaceCopy(uint32_t, Color32_t26 *, int32_t);}
    4. extern Il2CppType Color32U5BU5D_t25_0_0_0;
    5. extern MethodInfo AmanithSVG_svgtSurfaceCopy_m66_MethodInfo;
    6. extern "C" int32_t AmanithSVG_svgtSurfaceCopy_m66 (Object_t * __this /* static, unused */, uint32_t ___surface, Color32U5BU5D_t25* ___dstPixels32, int32_t ___dilateEdgesFix, MethodInfo* method) {
    7.     typedef int32_t (DEFAULT_CALL *PInvokeFunc) (uint32_t, Color32_t26 *, int32_t);
    8.     static PInvokeFunc _il2cpp_pinvoke_func;
    9.     if (!_il2cpp_pinvoke_func) {
    10.         _il2cpp_pinvoke_func = (PInvokeFunc)svgtSurfaceCopy;
    11.         if (_il2cpp_pinvoke_func == NULL) {
    12.             il2cpp_codegen_raise_exception(il2cpp_codegen_get_not_supported_exception("Unable to find method for p/invoke: 'svgtSurfaceCopy'"));
    13.         }
    14.     }
    15.  
    16.     // Marshaling of parameter '___surface' to native representation
    17.  
    18.     // Marshaling of parameter '___dstPixels32' to native representation
    19.     Color32_t26 * ____dstPixels32_marshaled = { 0 };
    20.     ____dstPixels32_marshaled = il2cpp_codegen_marshal_array<Color32_t26>((Il2CppCodeGenArray*)___dstPixels32);
    21.  
    22.  
    23.     // Marshaling of parameter '___dilateEdgesFix' to native representation
    24.  
    25.     // Native function invocation and marshaling of return value back from native representation
    26.     int32_t _return_value = _il2cpp_pinvoke_func(___surface, ____dstPixels32_marshaled, ___dilateEdgesFix);
    27.     return _return_value;
    28. }
     
    Last edited: Sep 16, 2015
  47. mysteryDate

    mysteryDate

    Joined:
    Feb 2, 2015
    Posts:
    11
    I apologize if I've missed something obvious, but will SVGAssets in Unity zoom like SVG elements in the browser. I.e. will they not pixel-late?
     
  48. Arganoid

    Arganoid

    Joined:
    Oct 12, 2013
    Posts:
    24
    Is support for clip paths coming soon?

    And are there any plans to support Windows Store apps?
     
  49. turbo3d

    turbo3d

    Joined:
    Apr 28, 2014
    Posts:
    50
    Unfortunately the development of clip paths feature cannot start before the end of the year 2015, due to resources allocation (we have to work on an automotive project until that date). Windows Store apps is not in the current plans...
     
  50. Maraudor

    Maraudor

    Joined:
    Mar 9, 2013
    Posts:
    10
    Hello,

    I just recently learned about SVGAssets, and I think it'll fit perfectly for a game we're planning. However, I had a quick question: Does it support XBox One and PS4?

    Thanks!