Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Sprite Atlas Custom Outline for Pixel Art

Discussion in '2D' started by AllanSmithZ3, Mar 21, 2020.

  1. AllanSmithZ3

    AllanSmithZ3

    Joined:
    May 21, 2019
    Posts:
    23
    Hey,

    So, I am working on a game where for many reasons it would be extremely useful if there was a tool that would generate TIGHT custom outlines for sprites in an atlas. By tight I mean pixel perfect tight, like this: Screenshot 2020-03-21 at 00.34.29.png

    I understand this does generate a mesh with more triangles but honestly, I am not concerned about triangles in a 2d pixel art game regardless of how pixely it is, I am concerned about overdraw though, and tons of transparencies literally everywhere on screen. I use currently a shader on sprite renderers that is not transparent, and being able to cut sprites like this (which are also in an atlas), would be great. I did this example by hand cause its fine for this moment but... obviously does not scale as a solution.

    Is there a way to automate this? A tool that already exists? I couldnt even find a way to do this by scripting, searched documentation on TextureImporter, TextureImporterSettings... it seemed like this is inaccessible through code?

    At any rate any help would be greatly appreciated!

    Best,
    Allan
     
    Raial likes this.
  2. cossacksman

    cossacksman

    Joined:
    Dec 2, 2017
    Posts:
    10
    Bump, this is absolutely necessary for pixel art.. The alternative takes far too long.
     
  3. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    unclear what you are trying to do from that image.

    You can use texture2d.setpixels to draw outlines on sprites
     
  4. AllanSmithZ3

    AllanSmithZ3

    Joined:
    May 21, 2019
    Posts:
    23
    The image shows the very manual process of creating a custom outline in the Sprite Editor tool. The custom outline is used in game to generate the mesh in which the sprite is applied. If the custom outline is pixel perfect like the one in the image, the mesh no longer needs a transparent shader, since the object in-game doesnt need transparency to have holes in it, as is the case with a lot of pixel art games. I am surprised this doesn't easily exist yet (from what I can gather), and to this day lol, a long time after posting this originally, I am still doing this by hand... I have been focusing a lot on coding though so haven't wasted all that much time yet, but I am getting concerned this will take me days of work (and sanity lol)
     
    LilGames likes this.
  5. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    did you try sprite mask
     
  6. AllanSmithZ3

    AllanSmithZ3

    Joined:
    May 21, 2019
    Posts:
    23
    What sprite mask? Is it a plugin or something?
     
  7. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    its a component
     
  8. AllanSmithZ3

    AllanSmithZ3

    Joined:
    May 21, 2019
    Posts:
    23
    Ah... then it would be even slower... the issue is trying to avoid transparent shaders by making the trade off with higher poly meshes. For pixel art specifically, most models wouldn't even be that high poly and could avoid entirely being transparent... its a performance consideration above anything else.
     
    LilGames likes this.
  9. Raial

    Raial

    Joined:
    May 2, 2017
    Posts:
    24
    Interesting question, but I believe you don't explain yourself well. Try formulating better the question to see if somebody knows.
    Anyway, if the change in performance would be significant, some native tool would already exist.
     
  10. AllanSmithZ3

    AllanSmithZ3

    Joined:
    May 21, 2019
    Posts:
    23
    I'm not sure how to be clearer on my intent.

    Regular flow is: sprites get turned into meshes by unity, using a transparent shader. You can create a "custom outline" in the sprite import settings and that defines the shape of the mesh unity will generate for your sprite. Doing that, your mesh will have less surface, less transparent area, therefore, less pixels will need to be drawn multiple times since there will likely be a bunch of transparent sprites one on top of the other.

    What I want to achieve: Use the "custom outline" tool in the sprite import settings for pixel-perfect outline, which for pixel art is very doable since shapes are simpler. This results in a mesh created by Unity which has more triangles, but, since all pixels have color and are not transparent, I use a material that doesn't even support transparency, making the rendering faster by not having transparency, less overdraw, in exchange for higher poly count.

    The issue: there is no tool that automatically generates pixel perfect outlines in the "custom outline" tool, and the API doesn't seem to support the creation of such a tool either.

    The question: is there a tool that I dont know about? Does the API support it and I couldn't find it? Only way I could think of to implement this is very brute force changing the sprite asset by hand... so basically do it all outside of Unity, which is doable but I didn't take that step yet lol
     
  11. Raial

    Raial

    Joined:
    May 2, 2017
    Posts:
    24
    I found what you are searching for in the docs: link

    Unity has a built-in system for doing what you were doing manually. Refer to the section Automatically Generating a Mesh Outline.

    It would be nice to have a performance comparison to see how much improves having a tight outline vs rendering also transparency (less vertices).
     
  12. AllanSmithZ3

    AllanSmithZ3

    Joined:
    May 21, 2019
    Posts:
    23
    Thanks, unfortunately, that doesn't do what I'm doing manually, it is not nearly "tight" enough to stop using transparencies. Its not made thinking of pixel art, but regular 2d art. My sprites can be 16x16, in which case the highest granularity of this tool still creates a square lol, the padding it considers is probably around 5-10 pixels... which is a lot for pixel art.
     
  13. RoxyPloxy

    RoxyPloxy

    Joined:
    Jul 2, 2021
    Posts:
    2
    It's almost a year later and I am still doing the same thing. It's really slow and boring, and the generate feature, unfortunately doesn't help. I hope you didn't give up on your project because of this, AllanSmithZ3 XD. If you're still trying, good luck.
     
  14. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,511
    Indeed, we need option to generate mesh with 0 extrusion.
     
    LilGames likes this.