Search Unity

black borders around colorized sprite

Discussion in 'Shaders' started by fwehrmaker, Aug 9, 2019.

  1. fwehrmaker

    fwehrmaker

    Joined:
    Apr 23, 2019
    Posts:
    10
    does anybody know why this shader is drawing black lines when i colorize it? i basically want a shader that is able to put the whole sprite white without borders + it has to be lit and when the alpha is zero it should be the normal texture. Which is exactly what this shader i found does except the black outline. thanks in advance for any help :)
    Unbenannt1.png
    Unbenannt.png
     
  2. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    127
    I have a suspicion that the shader multiplies alpha with the color, that's why it goes darker on the edges till alpha fades to zero making anything beyond just transparent.

    What you would need to do is not multiply alpha with the color in the shader code.
     
  3. fwehrmaker

    fwehrmaker

    Joined:
    Apr 23, 2019
    Posts:
    10
    okay i will look into that. but im a complete noob with shaders. if you can add some lines of code that would be extremely helpful for me. this is the github i got this shaders from: https://github.com/traggett/UnitySpriteShaders and SpritesPixelLitDissolve is the one i use.
     
    Last edited: Aug 9, 2019
  4. fwehrmaker

    fwehrmaker

    Joined:
    Apr 23, 2019
    Posts:
    10
    well for anyone who has the same problem i just created a second material with the blendmode changed to additive and swapped that in. dirty solution but works ^^
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,000
    What happens if you use the PremultipliedAlpha option?

    The problem is probably because your Sprite textures have a black background and you're using the StandardAlpha blend mode which expects the background color to match the color of the Sprite in the areas around the alpha.

    You could also try selecting "alpha is transparency" in the texture / Sprite asset settings. That does a dilate pass on the texture to remove the black background.
     
    iSinner likes this.
  6. fwehrmaker

    fwehrmaker

    Joined:
    Apr 23, 2019
    Posts:
    10
    thanks for your reply :) sadly the premultiplied alpha option gives a white 10% alpha rectangle and alpha is transparency is already activated :/
     
  7. fwehrmaker

    fwehrmaker

    Joined:
    Apr 23, 2019
    Posts:
    10
    i have those borders on every 2nd shader i use and i dont know why ><. its either those or black smudges. damn i wish i wouldnt be such a noob in this. but i will sit here and understand shaders somehow even if its the last thing i do lol
     

    Attached Files:

  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,000
    Oh ... You have Write to Depth enabled. That's going to lead to a bad time. You can either have alpha blending or depth write, not both. Both leads to what you're seeing.

    The "dark edge" is just the background color being visible because the depth write is causing the next sprite to be depth occluded.
     
  9. fwehrmaker

    fwehrmaker

    Joined:
    Apr 23, 2019
    Posts:
    10
    you mean this:
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha?
    idk i tried turning it on off. i even bought shader weaver today hoping it wouldnt come up there.. but i chose the simplest shader and there's always occlusion on the edge :(

    it only shows up when i make the shader lit though. it must have something to do with that
     
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,000
    I mean really, it’s some kind of bug with those shaders. The fact that when you set the blend mode to premultiplied shows additional color outside the intended alpha edge means your content is properly setup to do standard alpha blending. But something in the shader isn’t handling alpha blending properly (like @iSinner mentioned), or isn’t disabling ZWrite properly.

    I would try contacting the author of those shaders.
     
  11. fwehrmaker

    fwehrmaker

    Joined:
    Apr 23, 2019
    Posts:
    10
    ok i changed
    Blend SrcAlpha OneMinusSrcAlpha
    to
    Blend One OneMinusSrcAlpha
    i hope this helps someone it took me days xD