1 Shader "Hidden/MultipassHollywoodFlares" {
2     Properties {
3         _MainTex (
"Base (RGB)", 2D) = "" {}
4         _NonBlurredTex (
"Base (RGB)", 2D) = "" {}
5     }
6     
7     CGINCLUDE
8
9     #include
"UnityCG.cginc"
10     
11     
struct v2f {
12         half4 pos : SV_POSITION;
13         half2 uv : TEXCOORD0;
14     };
15
16     
struct v2f_opts {
17         half4 pos : SV_POSITION;
18         half2 uv[
7] : TEXCOORD0;
19     };
20     
21     half4 offsets;
22     half4 tintColor;
23     
24     half stretchWidth;
25     half2 _Threshhold;
26     
27     half4 _MainTex_TexelSize;
28     
29     sampler2D _MainTex;
30     sampler2D _NonBlurredTex;
31         
32     v2f vert (appdata_img v) {
33         v2f o;
34         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
35         o.uv = v.texcoord.xy;
36         
return o;
37     }
38
39     v2f_opts vertStretch (appdata_img v) {
40         v2f_opts o;
41         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
42         half b = stretchWidth;
43         o.uv[
0] = v.texcoord.xy;
44         o.uv[
1] = v.texcoord.xy + b * 2.0 * offsets.xy;
45         o.uv[
2] = v.texcoord.xy - b * 2.0 * offsets.xy;
46         o.uv[
3] = v.texcoord.xy + b * 4.0 * offsets.xy;
47         o.uv[
4] = v.texcoord.xy - b * 4.0 * offsets.xy;
48         o.uv[
5] = v.texcoord.xy + b * 6.0 * offsets.xy;
49         o.uv[
6] = v.texcoord.xy - b * 6.0 * offsets.xy;
50         
return o;
51     }
52     
53     v2f_opts vertVerticalCoords (appdata_img v) {
54         v2f_opts o;
55         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
56         o.uv[
0] = v.texcoord.xy;
57         o.uv[
1] = v.texcoord.xy + 0.5 * _MainTex_TexelSize.xy * half2(0,1);
58         o.uv[
2] = v.texcoord.xy - 0.5 * _MainTex_TexelSize.xy * half2(0,1);
59         o.uv[
3] = v.texcoord.xy + 1.5 * _MainTex_TexelSize.xy * half2(0,1);
60         o.uv[
4] = v.texcoord.xy - 1.5 * _MainTex_TexelSize.xy * half2(0,1);
61         o.uv[
5] = v.texcoord.xy + 2.5 * _MainTex_TexelSize.xy * half2(0,1);
62         o.uv[
6] = v.texcoord.xy - 2.5 * _MainTex_TexelSize.xy * half2(0,1);
63         
return o;
64     }
65         
66     
// deprecated
67     half4 fragPrepare (v2f i) : SV_Target {
68         half4 color = tex2D (_MainTex, i.uv);
69         half4 colorNb = tex2D (_NonBlurredTex, i.uv);
70         
return color * tintColor * 0.5 + colorNb * normalize (tintColor) * 0.5;
71     }
72
73
74     half4 fragPreAndCut (v2f_opts i) : SV_Target {
75         half4 color = tex2D (_MainTex, i.uv[
0]);
76         color += tex2D (_MainTex, i.uv[
1]);
77         color += tex2D (_MainTex, i.uv[
2]);
78         color += tex2D (_MainTex, i.uv[
3]);
79         color += tex2D (_MainTex, i.uv[
4]);
80         color += tex2D (_MainTex, i.uv[
5]);
81         color += tex2D (_MainTex, i.uv[
6]);
82         
return max(color / 7.0 - _Threshhold.x, 0.0) * _Threshhold.y * tintColor;
83     }
84
85     half4 fragStretch (v2f_opts i) : SV_Target {
86         half4 color = tex2D (_MainTex, i.uv[
0]);
87         color = max (color, tex2D (_MainTex, i.uv[
1]));
88         color = max (color, tex2D (_MainTex, i.uv[
2]));
89         color = max (color, tex2D (_MainTex, i.uv[
3]));
90         color = max (color, tex2D (_MainTex, i.uv[
4]));
91         color = max (color, tex2D (_MainTex, i.uv[
5]));
92         color = max (color, tex2D (_MainTex, i.uv[
6]));
93         
return color;
94     }
95     
96     half4 fragPost (v2f_opts i) : SV_Target {
97         half4 color = tex2D (_MainTex, i.uv[
0]);
98         color += tex2D (_MainTex, i.uv[
1]);
99         color += tex2D (_MainTex, i.uv[
2]);
100         color += tex2D (_MainTex, i.uv[
3]);
101         color += tex2D (_MainTex, i.uv[
4]);
102         color += tex2D (_MainTex, i.uv[
5]);
103         color += tex2D (_MainTex, i.uv[
6]);
104         
return color * 1.0/(7.0 + Luminance(color.rgb) + 0.5); // this also makes it a little noisy
105     }
106
107     ENDCG
108     
109 Subshader {
110       ZTest Always Cull Off ZWrite Off
111  Pass {
112
113       CGPROGRAM
114       
115       #pragma vertex vert
116       #pragma fragment fragPrepare
117       
118       ENDCG
119   }
120
121  Pass {
122
123       CGPROGRAM
124       
125       #pragma vertex vertStretch
126       #pragma fragment fragStretch
127       
128       ENDCG
129   }
130
131  Pass {
132
133       CGPROGRAM
134       
135       #pragma vertex vertVerticalCoords
136       #pragma fragment fragPreAndCut
137       
138       ENDCG
139   }
140
141  Pass {
142
143       CGPROGRAM
144       
145       #pragma vertex vertVerticalCoords
146       #pragma fragment fragPost
147       
148       ENDCG
149   }
150 }
151     
152 Fallback off
153     
154 }


Gõ tìm kiếm nhanh...