/
Building.shader
133 lines (112 loc) · 3.6 KB
/
Building.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
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
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Building" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Spec Color", Color) = (1,1,1,0)
_Emission ("Emissive Color", Color) = (0,0,0,0)
[PowerSlider(5.0)] _Shininess ("Shininess", Range (0.1, 1)) = 0.7
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
Pass {
ZWrite On
ColorMask 0
}
// Non-lightmapped
Pass {
ZTest LEqual
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGBA
Tags { "LightMode" = "Vertex" }
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeparateSpecular On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
// Lightmapped
Pass
{
Tags{ "LIGHTMODE" = "VertexLM" "QUEUE" = "Transparent" "IGNOREPROJECTOR" = "true" "RenderType" = "Transparent" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#pragma multi_compile_fog
#define USING_FOG (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
float4 unity_Lightmap_ST;
float4 _MainTex_ST;
struct appdata
{
float3 pos : POSITION;
half4 color : COLOR;
float3 uv1 : TEXCOORD1;
float3 uv0 : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
fixed4 color : COLOR0;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
#if USING_FOG
fixed fog : TEXCOORD3;
#endif
float4 pos : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
// vertex shader
v2f vert(appdata IN)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
half4 color = IN.color;
float3 eyePos = UnityObjectToViewPos(IN.pos);
half3 viewDir = 0.0;
o.color = saturate(color);
o.uv0 = IN.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
o.uv1 = IN.uv1.xy * unity_Lightmap_ST.xy + unity_Lightmap_ST.zw;
o.uv2 = IN.uv0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
#if USING_FOG
float fogCoord = length(eyePos.xyz);
UNITY_CALC_FOG_FACTOR_RAW(fogCoord);
o.fog = saturate(unityFogFactor);
#endif
o.pos = UnityObjectToClipPos(IN.pos);
return o;
}
sampler2D _MainTex;
fixed4 _Color;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 col, tex;
tex = UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.uv0.xy);
col = fixed4(DecodeLightmap(tex), 1);
col = col * _Color;
tex = tex2D(_MainTex, IN.uv2.xy);
col.rgb = tex * col;
col.a = _Color.a;
#if USING_FOG
col.rgb = lerp(unity_FogColor.rgb, col.rgb, IN.fog);
#endif
return col;
}
ENDCG
}
}
}