-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathScanlinesEffect.shader
62 lines (48 loc) · 1.58 KB
/
ScanlinesEffect.shader
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Shader "Custom/Scanlines" {
Properties {
_MainTex("_Color", 2D) = "white" {}
_LineWidth("Line Width", Float) = 4
_Hardness("Hardness", Float) = 0.9
_Speed("Displacement Speed", Range(0,1)) = 0.1
}
SubShader {
Tags {"IgnoreProjector" = "True" "Queue" = "Overlay"}
Pass {
ZTest Always
Cull Off
ZWrite Off
Fog{ Mode off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#pragma target 3.0
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float4 scr_pos : TEXCOORD1;
};
uniform sampler2D _MainTex;
uniform float _LineWidth;
uniform float _Hardness;
uniform float _Speed;
v2f vert(appdata_img v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = MultiplyUV(UNITY_MATRIX_TEXTURE0, v.texcoord);
o.scr_pos = ComputeScreenPos(o.pos);
return o;
}
half4 frag(v2f i) : COLOR {
half4 color = tex2D(_MainTex, i.uv);
fixed lineSize = _ScreenParams.y*0.005;
float displacement = ((_Time.y*1000)*_Speed)%_ScreenParams.y;
float ps = displacement+(i.scr_pos.y * _ScreenParams.y / i.scr_pos.w);
return ((int)(ps / floor(_LineWidth*lineSize)) % 2 == 0) ? color : color * float4(_Hardness,_Hardness,_Hardness,1);
}
ENDCG
}
}
FallBack "Diffuse"
}