Unity Shader for a Scanlines Effect
Category : Full Script , Shader , Unity
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!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
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 } } } |
Latest posts by Justin Fletcher (see all)
- UITableView scroll to new row only when at the end of table. - December 7, 2015
- Unity Shader for a Scanlines Effect - August 16, 2015
- Unity Shader Alpha Blended With Color - August 16, 2015
1 Comment
x2l2
October 4, 2016 at 7:41 amit give me an error in line 36 on unity 5.4
if((int)(p*_ScreenParams.y/floor(_LinesSize))%2==0) discard;
its works if i change it to this:
if( ( (int)(p*_ScreenParams.y/floor(_LinesSize)) )%2 ==0 ) discard;
😕