Subversion Repository Public Repository

Nextrek

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
Shader "Transparent/Refractive"
{
	Properties
	{
		_MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
		_BumpMap ("Normal Map (RGB)", 2D) = "bump" {}
		_Mask ("Specularity (R), Shininess (G), Refraction (B)", 2D) = "black" {}
		_Color ("Color Tint", Color) = (1,1,1,1)
		_Specular ("Specular Color", Color) = (0,0,0,0)
		_Focus ("Focus", Range(-100.0, 100.0)) = -100.0
		_Shininess ("Shininess", Range(0.01, 1.0)) = 0.2
	}

	Category
	{
		Tags
		{
			"Queue" = "Transparent+1"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
		}

		SubShader
		{
			LOD 500

			GrabPass
			{
				Name "BASE"
				Tags { "LightMode" = "Always" }
			}

			Cull Off
			ZWrite Off
			ZTest LEqual
			Blend SrcAlpha OneMinusSrcAlpha
			AlphaTest Greater 0

			CGPROGRAM
			#pragma exclude_renderers gles
			#pragma vertex vert
			#pragma surface surf PPL alpha
			#include "UnityCG.cginc"

			sampler2D _GrabTexture;
			sampler2D _MainTex;
			sampler2D _BumpMap;
			sampler2D _Mask;

			fixed4 _Color;
			fixed4 _Specular;
			half4 _GrabTexture_TexelSize;
			half _Focus;
			half _Shininess;

			struct Input
			{
				float4 position : POSITION;
				float2 uv_MainTex : TEXCOORD0;
				float4 color : COLOR;
				float4 proj : TEXCOORD1;
			};

			void vert (inout appdata_full v, out Input o)
			{
#if SHADER_API_D3D11
				UNITY_INITIALIZE_OUTPUT(Input, o);
#endif
				o.position = mul(UNITY_MATRIX_MVP, v.vertex);
				
				#if UNITY_UV_STARTS_AT_TOP
					float scale = -1.0;
				#else
					float scale = 1.0;
				#endif
				o.proj.xy = (float2(o.position.x, o.position.y * scale) + o.position.w) * 0.5;
				o.proj.zw = o.position.zw;
			}

			void surf (Input IN, inout SurfaceOutput o)
			{
				half4 tex	= tex2D(_MainTex, IN.uv_MainTex);
				half3 nm	= UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
				half3 mask	= tex2D(_Mask, IN.uv_MainTex);

				float2 offset = nm.xy * _GrabTexture_TexelSize.xy * _Focus;
				IN.proj.xy = offset * IN.proj.z + IN.proj.xy;
				half4 ref = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(IN.proj));
				
				half4 col;
				col.rgb = lerp(IN.color.rgb * tex.rgb, _Color.rgb * ref.rgb, mask.b);
				col.a = IN.color.a * _Color.a * tex.a;

				o.Albedo = col.rgb;
				o.Normal = nm;
				o.Specular = mask.r;
				o.Gloss = _Shininess * mask.g;
				o.Alpha = col.a;
			}

			// Forward lighting
			half4 LightingPPL (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
			{
				half3 nNormal = normalize(s.Normal);
				half shininess = s.Gloss * 250.0 + 4.0;

			#ifndef USING_DIRECTIONAL_LIGHT
				lightDir = normalize(lightDir);
			#endif

				// Phong shading model
				half reflectiveFactor = max(0.0, dot(-viewDir, reflect(lightDir, nNormal)));

				// Blinn-Phong shading model
				//half reflectiveFactor = max(0.0, dot(nNormal, normalize(lightDir + viewDir)));
				
				half diffuseFactor = max(0.0, dot(nNormal, lightDir));
				half specularFactor = pow(reflectiveFactor, shininess) * s.Specular;

				half4 c;
				c.rgb = (s.Albedo * diffuseFactor + _Specular.rgb * specularFactor) * _LightColor0.rgb;
				c.rgb *= (atten * 2.0);
				c.a = s.Alpha;
				return c;
			}

			ENDCG
		}
		
		SubShader
		{
			LOD 400

			Cull Off
			ZWrite Off
			ZTest LEqual
			Blend SrcAlpha OneMinusSrcAlpha
			AlphaTest Greater 0

			CGPROGRAM
			#pragma surface surf PPL alpha
			#include "UnityCG.cginc"

			sampler2D _MainTex;
			sampler2D _BumpMap;
			sampler2D _Mask;

			float4 _Color;
			float4 _Specular;
			float _Shininess;

			struct Input
			{
				float4 position : POSITION;
				float2 uv_MainTex : TEXCOORD0;
				float4 color : COLOR;
			};

			void surf (Input IN, inout SurfaceOutput o)
			{
				half4 tex	= tex2D(_MainTex, IN.uv_MainTex);
				half3 nm	= UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
				half3 mask	= tex2D(_Mask, IN.uv_MainTex);

				half4 col;
				col.rgb = IN.color.rgb * tex.rgb;
				col.rgb = lerp(col.rgb, _Color.rgb, mask.b * 0.5);
				col.a = IN.color.a * _Color.a * tex.a;

				o.Albedo = col.rgb;
				o.Normal = nm;
				o.Specular = mask.r;
				o.Gloss = _Shininess * mask.g;
				o.Alpha = col.a;
			}

			// Forward lighting
			half4 LightingPPL (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
			{
				half3 nNormal = normalize(s.Normal);
				half shininess = s.Gloss * 250.0 + 4.0;

			#ifndef USING_DIRECTIONAL_LIGHT
				lightDir = normalize(lightDir);
			#endif

				// Phong shading model
				half reflectiveFactor = max(0.0, dot(-viewDir, reflect(lightDir, nNormal)));

				// Blinn-Phong shading model
				//half reflectiveFactor = max(0.0, dot(nNormal, normalize(lightDir + viewDir)));
				
				half diffuseFactor = max(0.0, dot(nNormal, lightDir));
				half specularFactor = pow(reflectiveFactor, shininess) * s.Specular;

				half4 c;
				c.rgb = (s.Albedo * diffuseFactor + _Specular.rgb * specularFactor) * _LightColor0.rgb;
				c.rgb *= (atten * 2.0);
				c.a = s.Alpha;
				return c;
			}
			ENDCG
		}
		
		SubShader
		{
			LOD 300

			Cull Off
			ZWrite Off
			ZTest LEqual
			Blend SrcAlpha OneMinusSrcAlpha
			AlphaTest Greater 0

			CGPROGRAM
			#pragma surface surf BlinnPhong alpha
			#include "UnityCG.cginc"

			sampler2D _MainTex;
			sampler2D _Mask;

			float4 _Color;

			struct Input
			{
				float4 position : POSITION;
				float2 uv_MainTex : TEXCOORD0;
				float4 color : COLOR;
			};

			void surf (Input IN, inout SurfaceOutput o)
			{
				half4 tex	= tex2D(_MainTex, IN.uv_MainTex);
				half3 mask	= tex2D(_Mask, IN.uv_MainTex);

				half4 col;
				col.rgb = IN.color.rgb * tex.rgb;
				col.rgb = lerp(col.rgb, _Color.rgb, mask.b * 0.5);
				col.a = IN.color.a * _Color.a * tex.a;

				o.Albedo = col.rgb;
				o.Alpha = col.a;
			}
			ENDCG
		}
		
		SubShader
		{
			LOD 100
			Cull Off
			Lighting Off
			ZWrite Off
			Fog { Mode Off }
			ColorMask RGB
			AlphaTest Greater .01
			Blend SrcAlpha OneMinusSrcAlpha
			
			Pass
			{
				ColorMaterial AmbientAndDiffuse
				
				SetTexture [_MainTex]
				{
					Combine Texture * Primary
				}
			}
		}
	}
	Fallback Off
}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/NGUI/Examples/Shaders/Refractive.shader

Diff revisions: vs.
Revision Author Commited Message
83 FMMortaroli picture FMMortaroli Tue 13 May, 2014 11:32:51 +0000