0

I have a shader for highlights and outlines that works just fine, except in one small but hugely annoying way:

https://i.stack.imgur.com/vfsNx.png

https://i.stack.imgur.com/N3mG6.png

My sprite is divided into separate Gameobjects for 'player', 'hair', 'outfit' and 'weapons' which are all swappable and animated. The outline/fill material is also on its own Gameobject, and the shader uses the 'player' Sprite Renderer as its _mainTex and to set the Sprite on it own Sprite Renderer.

The shader is currently using the 'hair' (and eventually 'outfit' and 'weapons') Sprite Renderer texture as a secondary texture in shader graph with the name _Hair to create a composite highlighted/outlined image of both hair and body.

It works great... except for the fact that the top line, and always exactly the the top line of pixels is cut off.

I know it's not the sprite sheet or any import setting problems, because other shaders are working fine on the individual parts, and I'm not using a sprite atlas or anything. I think it must be a problem with the way I've set up shader graph...

https://i.stack.imgur.com/5LZHZ.png

...the way I'm accessing the texture from the 'hair' sprite renderer or the way I'm setting the texture:

public class PlayerOutline : EntityOutline
{ 
public SpriteRenderer outlineRend;

public SpriteRenderer hairRend;

public override void SetSprite()
{
    if (hairRend.sprite)
    {
        outlineRend.material.SetTexture("_Hair",hairRend.sprite.texture);
    }

    base.SetSprite();
}

}

I've been stuck on this for two days, so I'd be very grateful for any ideas, and I'm still very much a beginner with shaders; I haven't used them for much more than things like this before. This was also quite a hard problem to title, so any advice on a better title is also welcome!

  • If you feed a 1 into your Clamp node instead of feeding the result of Add into it, is the top row of sprites still not green? – Ben Rubin Feb 21 '21 at 00:36
  • Also, in your screenshot that shows the outline on our character, how are you expanding the outline outside the boundaries of your original sprite? – Ben Rubin Feb 21 '21 at 00:43
  • If I bypass everything entirely and just feed the secondary texture straight to the multiply node I get this result: only the hair highlighted, except for the top row of pixels. I'm fairly certain the problem has nothing to do with the outlining itself because it works fine on individual sprites. I've got two shaders here, one for outlining and and one for highlighting. I've only shown the highlight shader graph here because they both produce the same result, leaving me to think its a problem with the texture itself. – Charlie Lashmar Feb 21 '21 at 08:59

1 Answers1

0

Okay so I worked out that the shader can't be applied to secondary textures that are outside the bounds of the main texture. Changing the mesh type from 'tight' to 'full rect' on my sprite sheet import settings fixed the problem for me, though I could foresee situations where you would need to physically resize sprites to get this to work. Thanks Ben for taking an interest!

  • I had a similar problem because some of my sprites had no extra transparent pixels on one of the edges. In my case I solved it by making sure my sprites all had a few extra pixels around the perimeter. – Ben Rubin Feb 21 '21 at 14:15