Search Unity

Applying shader to a sprite leads to strange things

Discussion in 'Shaders' started by unity_9CAW-4zn_c979Q, May 28, 2019.

  1. unity_9CAW-4zn_c979Q

    unity_9CAW-4zn_c979Q

    Joined:
    Jan 25, 2019
    Posts:
    1
    In my game I have multiple sprites and I want to apply my shader to them. I do things by this sequence: Create Shader -> Create Material -> Add the shader to the Material -> Add the material to my sprite(s). But when I add my shader to the material, images get started looking like below. What I do wrong and which way is right?

    P.S.
    I create Unlit shader and do not change nothing inside it.


    Before applying shader.


    After applying shader.
     
  2. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
    If you don't clip by alpha (alpha test) - you will take result like on screenshots
    i.e. you have alpha = 0 (or near 0) in specific positions, to get smooth contours on rounded square
    p.s. approach with alpha test is not universal due to artifacts on threshhold, probably your shader already has alpha test, and you have this artifacts

    you can use alpha-blended shader to properly blend any alpha value with background

    as a base you can use "UI/Default"
    https://github.com/TwoTailsGames/Un...er/DefaultResourcesExtra/UI/UI-Default.shader
    or "UI/Unlit/Transparent"
    https://github.com/TwoTailsGames/Un...ResourcesExtra/UI/UI-Unlit-Transparent.shader

    the core blending option is
    Blend SrcAlpha OneMinusSrcAlpha
     
    Last edited: May 31, 2019