Part Tools Import
[VesselSimulator.git] / Assets / PartTools / Shaders / InternalBumpedSpecular.shader
cybutek 1 Shader "KSP/InternalSpace/Bumped Specular"
2 {
3 Properties
4 {
5 [Header(Texture Maps)]
6 _MainTex("_MainTex (RGB spec(A))", 2D) = "white" {}
7 _BumpMap("_BumpMap", 2D) = "bump" {}
8 _LightMap ("_LightMap", 2D) = "gray" {}
9
10 [Header(Specular)]
11 _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
12 _Shininess ("Shininess", Range (0.03, 1)) = 0.4
13
14 [Header(Lightmaps and Occlusion)]
15 [Toggle(LMTOGGLE)] _LMTOGGLE("Enable Lightmap", Float) = 0
16 [KeywordEnum(Single Colored, Multi Grayscale)] _LM_Mode("Mode", Float) = 0
17 _LightColor1 ("Internal Light Color 1", Color) = (1,1,1,1)
18 _LightColor2 ("Internal Light Color 2", Color) = (1,1,1,1)
19 _LightAmbient("Ambient Boost", Range(0, 3)) = 1
20
21 _Occlusion("Occlusion Tightness", Range(0, 3)) = 1
22 [Space] //Im in Spaaaaaaaace
23
24 [Header(Fog)]
25 [Toggle(FOGTOGGLE)] _FOGTOGGLE("Enable Fog", Float) = 0
26 _FogColor("Color (RGB) Density (A)", Color) = (0.3, 0.4, 0.7, 0.5)
27 _FogStart("Start", Float) = 1
28 _FogEnd("End", Float) = 10
29
30 }
31
32 SubShader
33 {
34 Tags{ "RenderType" = "Opaque" }
35 LOD 200
36 //ZWrite On
37 //ZTest LEqual
38 //Blend SrcAlpha OneMinusSrcAlpha
39
40 CGPROGRAM
41
42 #include "LightingKSP.cginc"
43
44 #pragma surface surf BlinnPhongSmooth vertex:fogVertex finalcolor:fogColor
45 #pragma shader_feature LMTOGGLE
46 #pragma shader_feature FOGTOGGLE
47 #pragma multi_compile _LM_MODE_MULTI_GREYSCALE _LM_MODE_SINGLE_COLORED
48
49 #pragma target 3.0
50
51
52
53 sampler2D _MainTex;
54 sampler2D _BumpMap;
55 #if LMTOGGLE
56 sampler2D _LightMap;
57 #endif
58
59
60
61 uniform float _Shininess;
62 uniform float4 _SpecularColor;
63
64 #if LMTOGGLE
65 uniform float4 _LightColor1;
66 uniform float4 _LightColor2;
67 uniform float _LightAmbient;
68 uniform float _Occlusion;
69 #endif
70
71 #if FOGTOGGLE
72 uniform float4 _FogColor;
73 uniform float _FogStart;
74 uniform float _FogEnd;
75 #endif
76
77 struct Input
78 {
79 float2 uv_MainTex;
80 float2 uv_BumpMap;
81 float4 color : COLOR; //vertex color
82
83 #if LMTOGGLE
84 float2 uv2_LightMap;
85 #endif
86
87 #if FOGTOGGLE
88 half fogFactor;
89 #endif
90 };
91
92 void fogVertex(inout appdata_full v, out Input data)
93 {
94 UNITY_INITIALIZE_OUTPUT(Input, data);
95 #if FOGTOGGLE
96 float cameraVertDist = length(mul(UNITY_MATRIX_MV, v.vertex).xyz);
97 data.fogFactor = lerp(saturate((_FogEnd.x - cameraVertDist) / (_FogEnd.x - _FogStart.x)), 1, 1 - _FogColor.a);
98 #endif
99 }
100
101 void fogColor(Input IN, SurfaceOutput o, inout fixed4 c)
102 {
103 #if FOGTOGGLE
104 c.rgb = lerp(_FogColor.rgb, c.rgb, IN.fogFactor);
105 #endif
106 }
107
108 void surf (Input IN, inout SurfaceOutput o)
109 {
110 float4 c = tex2D(_MainTex,(IN.uv_MainTex));
111 float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
112
113 #if LMTOGGLE
114
115 float4 lightmap = tex2D(_LightMap, IN.uv2_LightMap);
116
117 #if _LM_MODE_SINGLE_COLORED
118 float3 light = lightmap.rgb * _LightColor1 + UNITY_LIGHTMODEL_AMBIENT * _LightAmbient * lightmap.rgb;
119 float3 AO = pow(lightmap.a, _Occlusion);
120 float3 finalLight = light * c.rgb * AO;
121 #endif
122
123 #if _LM_MODE_MULTI_GREYSCALE
124 float3 light1 = lightmap.r * _LightColor1;
125 float3 light2 = lightmap.g * _LightColor2;
126 float3 light3 = lightmap.b * UNITY_LIGHTMODEL_AMBIENT * _LightAmbient;
127 float3 AO = lerp(pow(lightmap.a, _Occlusion), 1, light1 + light2);
128 float3 finalLight = (light1 + light2 + light3) * c.rgb * AO;
129 #endif
130
131 #endif
132
133 o.Albedo = c.rgb * step(0.5,IN.color.rgb);
134 o.Gloss = c.a;
135 o.Specular = _Shininess;
136 o.Normal = normal;
137 o.Alpha = 1;
138
139 #if LMTOGGLE
140 o.Albedo *= AO;
141 o.Emission = finalLight;
142 #endif
143 }
144 ENDCG
145 }
146 Fallback "Diffuse"
147 }