1 Shader "Hidden/Blend" {
2 Properties {
3 _MainTex ("Screen Blended", 2D) = "" {}
4 _ColorBuffer ("Color", 2D) = "" {}
5 }
6
7 CGINCLUDE
8
9 #include "UnityCG.cginc"
10
11 struct v2f {
12 float4 pos : SV_POSITION;
13 float2 uv[2] : TEXCOORD0;
14 };
15 struct v2f_mt {
16 float4 pos : SV_POSITION;
17 float2 uv[4] : TEXCOORD0;
18 };
19
20 sampler2D _ColorBuffer;
21 sampler2D _MainTex;
22
23 half _Intensity;
24 half4 _ColorBuffer_TexelSize;
25 half4 _MainTex_TexelSize;
26
27 v2f vert( appdata_img v ) {
28 v2f o;
29 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
30 o.uv[0] = v.texcoord.xy;
31 o.uv[1] = v.texcoord.xy;
32
33 #if UNITY_UV_STARTS_AT_TOP
34 if (_ColorBuffer_TexelSize.y < 0)
35 o.uv[1].y = 1-o.uv[1].y;
36 #endif
37
38 return o;
39 }
40
41 v2f_mt vertMultiTap( appdata_img v ) {
42 v2f_mt o;
43 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
44 o.uv[0] = v.texcoord.xy + _MainTex_TexelSize.xy * 0.5;
45 o.uv[1] = v.texcoord.xy - _MainTex_TexelSize.xy * 0.5;
46 o.uv[2] = v.texcoord.xy - _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
47 o.uv[3] = v.texcoord.xy + _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
48 return o;
49 }
50
51 half4 fragScreen (v2f i) : SV_Target {
52 half4 toBlend = saturate (tex2D(_MainTex, i.uv[0]) * _Intensity);
53 return 1-(1-toBlend)*(1-tex2D(_ColorBuffer, i.uv[1]));
54 }
55
56 half4 fragAdd (v2f i) : SV_Target {
57 return tex2D(_MainTex, i.uv[0].xy) * _Intensity + tex2D(_ColorBuffer, i.uv[1]);
58 }
59
60 half4 fragVignetteBlend (v2f i) : SV_Target {
61 return tex2D(_MainTex, i.uv[0].xy) * tex2D(_ColorBuffer, i.uv[0]);
62 }
63
64 half4 fragMultiTap (v2f_mt i) : SV_Target {
65 half4 outColor = tex2D(_MainTex, i.uv[0].xy);
66 outColor += tex2D(_MainTex, i.uv[1].xy);
67 outColor += tex2D(_MainTex, i.uv[2].xy);
68 outColor += tex2D(_MainTex, i.uv[3].xy);
69 return outColor * 0.25;
70 }
71
72 ENDCG
73
74 Subshader {
75 ZTest Always Cull Off ZWrite Off
76
77 // 0: nicer & softer "screen" blend mode
78 Pass {
79
80 CGPROGRAM
81 #pragma vertex vert
82 #pragma fragment fragScreen
83 ENDCG
84 }
85
86 // 1: simple "add" blend mode
87 Pass {
88
89 CGPROGRAM
90 #pragma vertex vert
91 #pragma fragment fragAdd
92 ENDCG
93 }
94 // 2: used for "stable" downsampling
95 Pass {
96
97 CGPROGRAM
98 #pragma vertex vertMultiTap
99 #pragma fragment fragMultiTap
100 ENDCG
101 }
102 // 3: vignette blending
103 Pass {
104
105 CGPROGRAM
106 #pragma vertex vert
107 #pragma fragment fragVignetteBlend
108 ENDCG
109 }
110 }
111
112 Fallback off
113
114 } // shader