Sprite Atlas Custom Outline for Pixel Art

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:

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

1 Like

Bump, this is absolutely necessary for pixel art… The alternative takes far too long.

unclear what you are trying to do from that image.

You can use texture2d.setpixels to draw outlines on sprites

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)

1 Like

did you try sprite mask

What sprite mask? Is it a plugin or something?

its a component

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.

1 Like

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.

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

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).

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.

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.

Indeed, we need option to generate mesh with 0 extrusion.

1 Like