-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathFogColor.shader
70 lines (58 loc) · 1.95 KB
/
FogColor.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
Shader "Custom/FogColor"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_FogColor ("Fog Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_FogTex ("Fog Tex (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 screenPos;
fixed3 color : COLOR0;
UNITY_FOG_COORDS(1)
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.color = v.normal * 0.5 + 0.5;
o.screenPos = ComputeScreenPos(o.pos);
o.uv = float4( v.texcoord.xy, 0, 0 );
UNITY_TRANSFER_FOG(o, o.pos);
return o;
}
fixed4 _FogColor;
sampler2D _MainTex;
sampler2D _FogTex;
fixed4 frag (v2f i) : SV_Target
{
// Surface color before fog:
//float4 c = float4( i.color, 1 ); // this shows surface normal
float4 c = tex2D( _MainTex, i.uv); //this shows texture
// float4 c = float4( 1, 1, 1, 1 ); // this shows white
// Fog Color
//float4 fogColor = tex2D(_FogTex, i.screenPos.xy/i.screenPos.w); // fades to a screenspace texture
float4 fogColor = tex2D(_FogTex, i.uv); // fades to a different model texture
//float4 fogColor = _FogColor; //switch to this for a color specified on this material
UNITY_APPLY_FOG_COLOR(i.fogCoord, c, fogColor);
return c;
}
ENDCG
}
}
FallBack "Diffuse"
}