forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunlit_see_through.shader
104 lines (90 loc) · 2.18 KB
/
unlit_see_through.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//Code has written by Przemyslaw Zaworski, 07.01.2018
Shader "Unlit See Through"
{
Properties
{
surface("Color Map", 2D) = "white" {}
mask("Mask", 2D) = "white" {}
[KeywordEnum(Desaturation,Grain,NoName)] filters("Filters", Float) = 0
}
Subshader
{
Pass
{
CGPROGRAM
#pragma vertex vertex_shader
#pragma fragment pixel_shader
#pragma target 3.0
struct structure
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D surface,mask;
structure vertex_shader (float4 vertex:POSITION, float2 uv:TEXCOORD0)
{
structure vs;
vs.vertex = UnityObjectToClipPos (vertex);
vs.uv = uv;
return vs;
}
float4 pixel_shader (structure ps) : COLOR
{
float2 mask_uv = ps.vertex.xy / _ScreenParams.xy;
float4 color = tex2D(mask,mask_uv);
if (color.x>0.1)
discard;
return tex2D(surface,ps.uv.xy);
}
ENDCG
}
GrabPass { "image" }
Pass
{
CGPROGRAM
#pragma vertex vertex_shader
#pragma fragment pixel_shader
#pragma target 3.0
sampler2D mask, image;
float filters;
float4 vertex_shader (float4 vertex:position) : SV_POSITION
{
return UnityObjectToClipPos(vertex);
}
float4 desaturation (float4 x)
{
float c = dot(x.rgb, float3(0.2126, 0.7152, 0.0722));
return float4(c,c,c,1.0);
}
float4 grain (float4 color, float2 uv)
{
float strength = 16.0;
float x = (uv.x + 4.0 ) * (uv.y + 4.0 ) * (_Time.g * 10.0);
float t = fmod((fmod(x, 17.0) + 1.0) * (fmod(x, 117.0) + 1.0), 0.01)-0.005;
float4 grain = float4(t,t,t,1) * strength;
return color + grain;
}
float4 noname (float4 c)
{
return float4(c.r*c.r,sqrt(c.g),1.0-c.b,1.0);
}
float4 pixel_shader (float4 vertex:SV_POSITION) : SV_TARGET
{
float2 mask_uv = vertex.xy / _ScreenParams.xy;
float4 color = tex2D(mask,mask_uv);
if (color.x>0.1)
{
if (filters==0)
return desaturation(tex2D(image,mask_uv));
else if (filters==1)
return grain(tex2D(image,mask_uv),mask_uv);
else
return noname(tex2D(image,mask_uv));
}
else
return tex2D(image,mask_uv);
}
ENDCG
}
}
}