- Home /
Sprite Renderer Boundaries
Hi,
Unity newbie here.
I am trying to add a white outline to a sprite I have dragged and dropped to my scene.
I am using a shader for the outline.
When I increase the shader outline width property, The outline get's clipped because it doesn't go beyond the sprite renderer boundaries.
How can I fix the issue so that the the outline is visible?
I don't know how to increase the bounds of the sprite and add padding to it so that the outline fits properly.
Answer by SojaBird · Jun 30, 2016 at 02:29 PM
Hey @alvaromartinlop,
I have the same issue and have not yet been able to find a solution. So far it seems to me that sprite renderers are limited to only draw anything inside the boundaries of the sprite. A solution (though not perfect) would be to add a padding to your sprite so that there is extra space in the renderer where the outline can exist. You can do this in any graphicsrogram (such as Photoshop or Gimp). Just load up the image and increase the canvas/field size. In case you are using a multiple-sprite Atlas, you can increase the bounding box of your sprite in the sprite-editor. Just increase the boundaries box of the sprite by dragging the sides or using the inspector.
An other option would be to, instead of an outset line, make it an inset line. This will change the look as it will sacrafice the outer pixels but you will be sure that it will all show.
Good luck, keep searching.
Answer by tanoshimi · Jun 30, 2016 at 05:05 PM
It's not really a limitation of the sprite renderer - a sprite is a mesh just like any other object placed in your scene. When it looks like you're "expanding" the sprite with a white outline, all you're really doing is replacing some transparent pixels on the texture assigned to that mesh with some opaque pixels instead. But when this object is sent to the graphics card, it wont's affect pixels outside the boundary of the mesh.
To add more transparent pixels around the border of the sprite, try setting the sprite border on the texture importer; https://docs.unity3d.com/ScriptReference/TextureImporter-spriteBorder.html