Unity Shader for a Scanlines Effect

in #tutorial7 years ago (edited)

Here’s a great shader I found for giving a material scanlines. It creates a very cool retro tv effect. Forgive me I don’t have a source link, I couldn’t find it again. So a special thanks to whoever did write it, if you’re out there, leave a comment or if anyone finds the original link, it was part of a Unity Answers thread, post a comment. Anyway, here’s the shader, use it, enjoy!

Shader "Custom/Scanlines" { 
Properties { 
    _Color("Color", Color) = (0,0,0,1) 
    _LinesSize("LinesSize", Range(1,10)) = 1 
} 
SubShader { 
    Tags {"IgnoreProjector" = "True" "Queue" = "Overlay"} 
    Fog { Mode Off } 
    Pass { 
        ZTest Always 
        ZWrite Off 
        Blend SrcAlpha OneMinusSrcAlpha

CGPROGRAM
 
#pragma vertex vert 
#pragma fragment frag
#include "UnityCG.cginc"

        fixed4 _Color; half _LinesSize;

        struct v2f { 
            half4 pos:POSITION; 
            fixed4 sPos:TEXCOORD; 
        };

        v2f vert(appdata_base v) {
            v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 
            o.sPos = ComputeScreenPos(o.pos); 
            return o; 
        }

        fixed4 frag(v2f i) : COLOR {
            fixed p = i.sPos.y / i.sPos.w;

            if((int)(p*_ScreenParams.y/floor(_LinesSize))%2==0) discard;

               return _Color; 
         }
 
ENDCG
       }

} 

}
Sort:  

@chrs944
Beautiful writeup!Thanks for sharing.

You're welcome, god you like it.

Coin Marketplace

STEEM 0.16
TRX 0.16
JST 0.030
BTC 59488.68
ETH 2538.17
USDT 1.00
SBD 2.52