Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

FuzzySprites - Sprite Slicing/Dicing support for Unity

Discussion in 'Assets and Asset Store' started by RobinBirdStudios, Nov 5, 2021.

  1. RobinBirdStudios

    RobinBirdStudios

    Joined:
    Sep 14, 2018
    Posts:
    9


    Sprite Slicing/Dicing support for Unity. Split up big textures into multiple parts to save Atlas space and improve memory usage. Non-destructive and easy!



    Asset Store Link: https://assetstore.unity.com/packages/slug/119171


    FuzzySprites is a plugin for Unity that makes it much easier and more performant when dealing with big textures in 2D. Have your artists ever given you a very big texture that doesn't compress well or does not fit on a reasonable size atlas? FuzzySprites is here to solve this automatically and maintainable.


    FuzzySprites uses a process called slicing or dicing. It basically cuts the texture into multiple pieces to optimize atlas packing and compression. It flawlessly reconstructs the pieces when rendering it in the game.


    Easy to use
    Just drag in a big texture up to 8K and use the automatic settings or fine tune the slicing to your needs. And you are done. FuzzySprites will make sure the texture is performant and looks great.


    Compatible
    Works with the Sprite Packer (Legacy) and the newer Sprite Atlas. FuzzySprites is tested and supported constantly against all major Unity versions.


    Advanced optimization
    If FuzzySprites detects rects that have the same color or are identical to other rects it does not duplicate this information on the atlas and thus save space. Imaging a texture with a lot of the same blue color (e.g. a sky background). FuzzySprites will only save the blue color once. If some parts of the texture are transparent they will be ignored as well.


    Compression correction
    One of the common problems with slicing is the compression artifacts at the edges of the dices. FuzzySprites looks at the connecting edges and corrects the compression so it looks nearly the same as if the texture has been compressed in one piece.


    Configurable
    FuzzySprites selects clever defaults based on the texture you want to slice/dice. There are also some presets to spread the texture across 1k atlasses or 2k depending what your game needs are.


    Flexible
    Normally the cut sprite is rendered with a custom mesh rendering component. But you can also use SpriteRenderer components to represent the sliced/diced graphic in case your game does some special processing or shader exclusive to SpriteRenderer's.


    Source code included
    Look under the hood and check how FuzzySprites works. Classes are designed to be extended for custom needs. All classes and complex code are well commented for easier understanding.


    Follow us for updates and news

    Website | Twitter | YouTube | Mail

    Feedback is always appreciated!
     
  2. frikic

    frikic

    Joined:
    Dec 22, 2011
    Posts:
    44
    Hello,
    Just bought your asset today and tried it out, It's working but i get some warnings and error messages, I'm using Unity 2021.3.26 LTS.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. FuzzySprites.FuzzySpriteRenderer.InitializeSortingOrder () (at Assets/FuzzySprites/Scripts/FuzzySpriteRenderer.cs:138)
    3. FuzzySprites.FuzzySpriteRenderer.SetupRenderer () (at Assets/FuzzySprites/Scripts/FuzzySpriteRenderer.cs:31)
    4. FuzzySprites.Editor.FuzzySpriteScriptableObjectEditor.OnInspectorGUI () (at Assets/FuzzySprites/Scripts/Editor/FuzzySpriteScriptableObjectEditor.cs:265)
    5. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/Inspector/InspectorElement.cs:636)
    6. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)
    And I get this warning every time i press apply after changing Fuzzy sprite
    Code (CSharp):
    1. mporter(NativeFormatImporter) generated inconsistent result for asset(guid:1e4f82574d4fa4bc39508d942b3ac0ff) "Assets/Graphics/Sprites/MushroomWorld/test/background1_1b.fuzzy.asset"
     
  3. RobinBirdStudios

    RobinBirdStudios

    Joined:
    Sep 14, 2018
    Posts:
    9
    Hi, thank you for your support and the report!

    Hmm, strange. I’ll look into it latest tomorrow!


    Cheers,

    Robin
     
  4. RobinBirdStudios

    RobinBirdStudios

    Joined:
    Sep 14, 2018
    Posts:
    9
    I found the issue. I am preparing a new version. This can unfortunately take a day until it is reviewed. Hang tight :)
     
  5. frikic

    frikic

    Joined:
    Dec 22, 2011
    Posts:
    44
    Oh great thanks for the quick fix!!!

    One question, do you know performance wise is it too much to have 100x100(or maybe even less) pixel squares for 2k atlas. So is it something to take into consideration when using 2d lit sprites or it does not affect the performance?

    Also one note and potential feature request if you plan to add more features in the future, I used 2DToolkit before with sprite dicing and missed this feature when I had to move from it because was not supported any more. So I was happy to find your asset and I remember that in 2DToolkit you could also have different shaders for transparent dices and another one for opaque. The explanation was that this way you would lessen overdraw and thus improve performance.
    Not sure if that is something that could improve performance with your asset and if it makes sense in this case?
     
  6. RobinBirdStudios

    RobinBirdStudios

    Joined:
    Sep 14, 2018
    Posts:
    9
    Fix is submitted. Can take some time. If you send me your Invoice Number to support*at*robinbird-studios.com I can also send you the package via Email.

    Regarding your question: FuzzySprites does all the processing in Editor/Offline. So at runtime you are rendering optimized meshes. The dicing/slicing is not performed at runtime/in-game. Having very small dices (100x100px should be fine!) can affect performance since the mesh of the objects gets more "complex". So a few more vertices are rendered. Still the texture hit (draw calls, memory) should stay the same and be even smaller if the diced image shows some repetition or transparency. It is always a trade of between texture memory and runtime vertex count. But usually 2D games have a lot of room in the vertex department so don't shy away to make small dices. 2D games are rather tight on texture memory/draw calls.

    Hmm, not exactly sure what you mean. For the visible pixels you can define a custom material that can have a custom shader for effects, etc. For the transparent dices they just don't exist anymore. They are not part of the mesh and also are not on the Sprite Atlas (if you use one). So they should have zero overdraw. If you have a sprite that has a lot of transparency the dices that are fully transparent are "culled offline" if you would want to call it this way. The renderer at runtime would not even know that there was an transparent dice/quad.

    I hope this helps :)

    Cheers
     
  7. frikic

    frikic

    Joined:
    Dec 22, 2011
    Posts:
    44
    Thanks for the answers, sounds good!

    "For the transparent dices they just don't exist anymore"
    Actually i explained it wrong and maybe was only relevant for the way 2dToolkit worked. So i was referring for the edge dices, that have transparency, like red square in image below, and yellow one that are opaque. So they way they solve it is that you would have different material for each with different shader, at least how I understood at that point. So only the red ones will be calculated for overdraw, rest of the sprite will count as opaque.
    Again not sure if that is relevant in case of your solution ;)

    thanks again for quick response, and I will send invoice no. to your email

    Screenshot 2023-06-08 at 12.35.33.png
     
  8. RobinBirdStudios

    RobinBirdStudios

    Joined:
    Sep 14, 2018
    Posts:
    9
    No problem, leave a review if you want ;)

    Ahh, now I understand. Sorry. I was focused too much on fully transparent quads. This is a good idea! But it would create another draw call I guess. That is ok, if the requirements of the game benefit more from the overdraw savings. I'll check if I can integrate something like this. Thank you for the input!

    Cheers
     
    frikic likes this.
  9. frikic

    frikic

    Joined:
    Dec 22, 2011
    Posts:
    44
    Hello glad you liked the idea!

    I got error when trying to make both IOS and Android build with Unity 2021.3.27 LTS.

    Code (CSharp):
    1. Could not setup build Properties
    2. UnityEngine.Debug:LogError (object)
    3. FuzzySprites.FuzzySprites.RobinBird.Logging.Unity.Provider.UnityLogProvider:ErrorFormat (object,string,object[],string) (at Assets/FuzzySprites/RobinBird/Logging/Unity/Provider/UnityLogProvider.cs:69)
    4. FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.Log:TranscodedLog (FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.Interfaces.ILogProvider,FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.LogLevel,object,string,object[],string,string&) (at Assets/FuzzySprites/RobinBird/Logging/Runtime/Log.cs:282)
    5. FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.Log:LogFormatContext (FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.LogLevel,string,object[],object,string) (at Assets/FuzzySprites/RobinBird/Logging/Runtime/Log.cs:228)
    6. FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.Log:Error (string,object,string) (at Assets/FuzzySprites/RobinBird/Logging/Runtime/Log.cs:181)
    7. FuzzySprites.FuzzySprites.RobinBird.Utilities.Unity.Editor.Build.BuildHelper:Build (string,UnityEditor.BuildTarget,UnityEditor.BuildOptions) (at Assets/FuzzySprites/RobinBird/Utilities/Unity/Editor/Build/BuildHelper.cs:240)
    8. FuzzySprites.FuzzySprites.RobinBird.Utilities.Unity.Editor.Build.BuildHelper:BuildPlayerHandler (UnityEditor.BuildPlayerOptions) (at Assets/FuzzySprites/RobinBird/Utilities/Unity/Editor/Build/BuildHelper.cs:153)
    9. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)
    And log entry before it

    Code (CSharp):
    1. Building for Android with Options: CompressTextures, StripDebugSymbols, ForceOptimizeScriptCompilation, Il2CPP, CompressWithLz4, CompressWithLz4HC, StrictMode. Path: /Users/frikic/Desktop/sustainions.apk
    2. UnityEngine.Debug:Log (object)
    3. FuzzySprites.FuzzySprites.RobinBird.Logging.Unity.Provider.UnityLogProvider:InfoFormat (object,string,object[],string) (at Assets/FuzzySprites/RobinBird/Logging/Unity/Provider/UnityLogProvider.cs:31)
    4. FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.Log:TranscodedLog (FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.Interfaces.ILogProvider,FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.LogLevel,object,string,object[],string,string&) (at Assets/FuzzySprites/RobinBird/Logging/Runtime/Log.cs:276)
    5. FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.Log:LogFormatContext (FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.LogLevel,string,object[],object,string) (at Assets/FuzzySprites/RobinBird/Logging/Runtime/Log.cs:228)
    6. FuzzySprites.FuzzySprites.RobinBird.Logging.Runtime.Log:Info (string,object,string) (at Assets/FuzzySprites/RobinBird/Logging/Runtime/Log.cs:101)
    7. FuzzySprites.FuzzySprites.RobinBird.Utilities.Unity.Editor.Build.BuildHelper:Build (string,UnityEditor.BuildTarget,UnityEditor.BuildOptions) (at Assets/FuzzySprites/RobinBird/Utilities/Unity/Editor/Build/BuildHelper.cs:214)
    8. FuzzySprites.FuzzySprites.RobinBird.Utilities.Unity.Editor.Build.BuildHelper:BuildPlayerHandler (UnityEditor.BuildPlayerOptions) (at Assets/FuzzySprites/RobinBird/Utilities/Unity/Editor/Build/BuildHelper.cs:153)
    9. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)
    Cheers
     
    Last edited: Jun 19, 2023
  10. RobinBirdStudios

    RobinBirdStudios

    Joined:
    Sep 14, 2018
    Posts:
    9
    Thank you for the report.
    New version is on the way!
    I also sent you the new version directly via E-Mail!

    Cheers
     
  11. frikic

    frikic

    Joined:
    Dec 22, 2011
    Posts:
    44
    Hello, now that Unity 2022 LTS is out, do you have a plan to support it, I get error when I try to switch to Unity 2022.3.8?
    Assets/FuzzySprites/Scripts/Editor/FuzzySpriteScriptableObjectEditor.cs(343,24): error CS0117: 'Packer' does not contain a definition for 'RebuildAtlasCacheIfNeeded'