Search Unity

Help for mobile shader equal to Blending mode Darken

Discussion in 'Shaders' started by Rokkrage, Feb 12, 2016.

  1. Rokkrage

    Rokkrage

    Joined:
    Dec 29, 2015
    Posts:
    3
    Hey all,

    So I'm working on a game and assets like that one are supposed to be mountains in a level: http://i.imgur.com/MFVsiP4.png

    We want to use a shader which makes the black color visible and the white color transparent, while also achieving best performance on mobile.

    When imported in Unity however, some grey border appears on all black colored elements' edges. Like this: http://i.imgur.com/F7zop8d.png

    That's the code used:
    Code (CSharp):
    1. Shader "Somian/Darken Texture"
    2. {
    3. Properties
    4. {
    5.   _Color ("Main Color", Color) = (1,1,1,1)
    6.   _MainTex ("Texture", 2D) = ""
    7. }
    8.  
    9. SubShader
    10. {
    11.   Tags { Queue = Transparent }
    12.   Blend OneMinusSrcColor SrcColor
    13.   ZWrite Off
    14.   Cull Off
    15.   Lighting Off
    16.   Fog { Mode Off }
    17.   Pass
    18.   {
    19.   SetTexture[_MainTex] { Combine texture }
    20.   }
    21. }
    22. }
    Any idea what is causing it and how to fix it?

    Thanks in advance for any help on it!
     
    Last edited: Feb 17, 2016
    NeatWolf likes this.
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    My wild guess would be that this can be due to texture filtering around transparency edges. If you select "alpha is transparency" option in the texture import settings, does this fix it?
     
    NeatWolf likes this.
  3. Rokkrage

    Rokkrage

    Joined:
    Dec 29, 2015
    Posts:
    3
    Heya,

    Thanks for the response! Now, these are the settings we are using to achieve the best compression:

    Screen Shot 2016-02-17 at 22.25.36.png

    Texture has no alpha.
     
    NeatWolf likes this.
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    Try
    Blend DstColor Zero
    Or
    BlendOp Min
     
    NeatWolf and Rokkrage like this.
  5. Rokkrage

    Rokkrage

    Joined:
    Dec 29, 2015
    Posts:
    3
    It worked! You are awesome!

    shot_160218_210823.png shot_160218_210823.png

    Thank you both for your help, especially to @bgolus for providing us with a solution. Well, even two working solutions.

    If you ever come to Bulgaria, you must know that you've earned yourself a few drinks. :)

    Have a nice day!

    P.S.: By the way, if you know even a better way to optimize for mobile, please feel free to share. :)
     

    Attached Files:

    NeatWolf likes this.
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    They are different btw. Blend DstColor Zero is the same as Photoshop multiply. BlendOp Min is the same as darken.
     
    NeatWolf likes this.