Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

479 lines
24 KiB

4 years ago
  1. Shader "Ciconia Studio/Double Sided/Transparent/Diffuse Bump2" {
  2. Properties {
  3. _Color ("Diffuse Color", Color) = (1,1,1,1)
  4. _MainTex ("Diffuse map (Trans A)", 2D) = "white" {}
  5. _BumpMap ("Normal map", 2D) = "bump" {}
  6. _NormalIntensity ("Normal Intensity", Range(0, 2)) = 1
  7. _SpecGlossMap ("Specular map", 2D) = "white" {}
  8. _SpecColor ("Specular Color", Color) = (1,1,1,1)
  9. _SpecularIntensity ("Specular Intensity", Range(0, 2)) = 0.2
  10. _Glossiness ("Glossiness", Range(0, 1)) = 0.5
  11. _Transparency ("Transparency", Range(0, 1)) = 0.5
  12. [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  13. }
  14. SubShader {
  15. Tags {
  16. "Queue"="Transparent"
  17. "RenderType"="Transparent"
  18. }
  19. Pass {
  20. Name "FORWARD"
  21. Tags {
  22. "LightMode"="ForwardBase"
  23. }
  24. Blend SrcAlpha OneMinusSrcAlpha
  25. Cull Off
  26. CGPROGRAM
  27. #pragma vertex vert
  28. #pragma fragment frag
  29. #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
  30. #define _GLOSSYENV 1
  31. #include "UnityCG.cginc"
  32. #include "AutoLight.cginc"
  33. #include "Lighting.cginc"
  34. #include "UnityPBSLighting.cginc"
  35. #include "UnityStandardBRDF.cginc"
  36. #pragma multi_compile_fwdbase_fullshadows
  37. #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
  38. #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
  39. #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
  40. #pragma multi_compile_fog
  41. #pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
  42. #pragma target 3.0
  43. uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
  44. uniform float4 _Color;
  45. uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
  46. uniform float _NormalIntensity;
  47. uniform sampler2D _SpecGlossMap; uniform float4 _SpecGlossMap_ST;
  48. uniform float _SpecularIntensity;
  49. uniform float _Glossiness;
  50. uniform float _Transparency;
  51. struct VertexInput {
  52. float4 vertex : POSITION;
  53. float3 normal : NORMAL;
  54. float4 tangent : TANGENT;
  55. float2 texcoord0 : TEXCOORD0;
  56. float2 texcoord1 : TEXCOORD1;
  57. float2 texcoord2 : TEXCOORD2;
  58. };
  59. struct VertexOutput {
  60. float4 pos : SV_POSITION;
  61. float2 uv0 : TEXCOORD0;
  62. float2 uv1 : TEXCOORD1;
  63. float2 uv2 : TEXCOORD2;
  64. float4 posWorld : TEXCOORD3;
  65. float3 normalDir : TEXCOORD4;
  66. float3 tangentDir : TEXCOORD5;
  67. float3 bitangentDir : TEXCOORD6;
  68. LIGHTING_COORDS(7,8)
  69. UNITY_FOG_COORDS(9)
  70. #if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH)
  71. float4 ambientOrLightmapUV : TEXCOORD10;
  72. #endif
  73. };
  74. VertexOutput vert (VertexInput v) {
  75. VertexOutput o = (VertexOutput)0;
  76. o.uv0 = v.texcoord0;
  77. o.uv1 = v.texcoord1;
  78. o.uv2 = v.texcoord2;
  79. #ifdef LIGHTMAP_ON
  80. o.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  81. o.ambientOrLightmapUV.zw = 0;
  82. #endif
  83. #ifdef DYNAMICLIGHTMAP_ON
  84. o.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  85. #endif
  86. o.normalDir = UnityObjectToWorldNormal(v.normal);
  87. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  88. o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  89. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  90. float3 lightColor = _LightColor0.rgb;
  91. o.pos = UnityObjectToClipPos( v.vertex );
  92. UNITY_TRANSFER_FOG(o,o.pos);
  93. TRANSFER_VERTEX_TO_FRAGMENT(o)
  94. return o;
  95. }
  96. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  97. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  98. float faceSign = ( facing >= 0 ? 1 : -1 );
  99. i.normalDir = normalize(i.normalDir);
  100. i.normalDir *= faceSign;
  101. float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
  102. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  103. float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(i.uv0, _BumpMap)));
  104. float3 normalLocal = lerp(float3(0,0,1),_BumpMap_var.rgb,_NormalIntensity);
  105. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  106. float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
  107. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  108. float3 lightColor = _LightColor0.rgb;
  109. float3 halfDirection = normalize(viewDirection+lightDirection);
  110. ////// Lighting:
  111. UNITY_LIGHT_ATTENUATION(attenuation,i, i.posWorld.xyz);
  112. float3 attenColor = attenuation * _LightColor0.xyz;
  113. float Pi = 3.141592654;
  114. float InvPi = 0.31830988618;
  115. ///////// Gloss:
  116. float gloss = _Glossiness;
  117. float perceptualRoughness = 1.0 - _Glossiness;
  118. float roughness = perceptualRoughness * perceptualRoughness;
  119. float specPow = exp2( gloss * 10.0 + 1.0 );
  120. /////// GI Data:
  121. UnityLight light;
  122. #ifdef LIGHTMAP_OFF
  123. light.color = lightColor;
  124. light.dir = lightDirection;
  125. light.ndotl = LambertTerm (normalDirection, light.dir);
  126. #else
  127. light.color = half3(0.f, 0.f, 0.f);
  128. light.ndotl = 0.0f;
  129. light.dir = half3(0.f, 0.f, 0.f);
  130. #endif
  131. UnityGIInput d;
  132. d.light = light;
  133. d.worldPos = i.posWorld.xyz;
  134. d.worldViewDir = viewDirection;
  135. d.atten = attenuation;
  136. #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
  137. d.ambient = 0;
  138. d.lightmapUV = i.ambientOrLightmapUV;
  139. #else
  140. d.ambient = i.ambientOrLightmapUV;
  141. #endif
  142. #if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION
  143. d.boxMin[0] = unity_SpecCube0_BoxMin;
  144. d.boxMin[1] = unity_SpecCube1_BoxMin;
  145. #endif
  146. #if UNITY_SPECCUBE_BOX_PROJECTION
  147. d.boxMax[0] = unity_SpecCube0_BoxMax;
  148. d.boxMax[1] = unity_SpecCube1_BoxMax;
  149. d.probePosition[0] = unity_SpecCube0_ProbePosition;
  150. d.probePosition[1] = unity_SpecCube1_ProbePosition;
  151. #endif
  152. d.probeHDR[0] = unity_SpecCube0_HDR;
  153. d.probeHDR[1] = unity_SpecCube1_HDR;
  154. Unity_GlossyEnvironmentData ugls_en_data;
  155. ugls_en_data.roughness = 1.0 - gloss;
  156. ugls_en_data.reflUVW = viewReflectDirection;
  157. UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );
  158. lightDirection = gi.light.dir;
  159. lightColor = gi.light.color;
  160. ////// Specular:
  161. float NdotL = saturate(dot( normalDirection, lightDirection ));
  162. float LdotH = saturate(dot(lightDirection, halfDirection));
  163. float4 _SpecGlossMap_var = tex2D(_SpecGlossMap,TRANSFORM_TEX(i.uv0, _SpecGlossMap));
  164. float3 specularColor = ((_SpecGlossMap_var.rgb*_SpecularIntensity)*_SpecColor.rgb);
  165. float specularMonochrome;
  166. float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
  167. float3 diffuseColor = (_MainTex_var.rgb*_Color.rgb); // Need this for specular when using metallic
  168. diffuseColor = EnergyConservationBetweenDiffuseAndSpecular(diffuseColor, specularColor, specularMonochrome);
  169. specularMonochrome = 1.0-specularMonochrome;
  170. float NdotV = abs(dot( normalDirection, viewDirection ));
  171. float NdotH = saturate(dot( normalDirection, halfDirection ));
  172. float VdotH = saturate(dot( viewDirection, halfDirection ));
  173. float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );
  174. float normTerm = GGXTerm(NdotH, roughness);
  175. float specularPBL = (visTerm*normTerm) * UNITY_PI;
  176. #ifdef UNITY_COLORSPACE_GAMMA
  177. specularPBL = sqrt(max(1e-4h, specularPBL));
  178. #endif
  179. specularPBL = max(0, specularPBL * NdotL);
  180. #if defined(_SPECULARHIGHLIGHTS_OFF)
  181. specularPBL = 0.0;
  182. #endif
  183. half surfaceReduction;
  184. #ifdef UNITY_COLORSPACE_GAMMA
  185. surfaceReduction = 1.0-0.28*roughness*perceptualRoughness;
  186. #else
  187. surfaceReduction = 1.0/(roughness*roughness + 1.0);
  188. #endif
  189. specularPBL *= any(specularColor) ? 1.0 : 0.0;
  190. float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
  191. half grazingTerm = saturate( gloss + specularMonochrome );
  192. float3 indirectSpecular = (gi.indirect.specular);
  193. indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV);
  194. indirectSpecular *= surfaceReduction;
  195. float3 specular = (directSpecular + indirectSpecular);
  196. /////// Diffuse:
  197. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  198. half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
  199. float nlPow5 = Pow5(1-NdotL);
  200. float nvPow5 = Pow5(1-NdotV);
  201. float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;
  202. float3 indirectDiffuse = float3(0,0,0);
  203. indirectDiffuse += gi.indirect.diffuse;
  204. diffuseColor *= 1-specularMonochrome;
  205. float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
  206. /// Final Color:
  207. float3 finalColor = diffuse + specular;
  208. fixed4 finalRGBA = fixed4(finalColor,(_MainTex_var.a*(1.0 - _Transparency)));
  209. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  210. return finalRGBA;
  211. }
  212. ENDCG
  213. }
  214. Pass {
  215. Name "FORWARD_DELTA"
  216. Tags {
  217. "LightMode"="ForwardAdd"
  218. }
  219. Blend One One
  220. Cull Off
  221. CGPROGRAM
  222. #pragma vertex vert
  223. #pragma fragment frag
  224. #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
  225. #define _GLOSSYENV 1
  226. #include "UnityCG.cginc"
  227. #include "AutoLight.cginc"
  228. #include "Lighting.cginc"
  229. #include "UnityPBSLighting.cginc"
  230. #include "UnityStandardBRDF.cginc"
  231. #pragma multi_compile_fwdadd_fullshadows
  232. #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
  233. #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
  234. #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
  235. #pragma multi_compile_fog
  236. #pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
  237. #pragma target 3.0
  238. uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
  239. uniform float4 _Color;
  240. uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
  241. uniform float _NormalIntensity;
  242. uniform sampler2D _SpecGlossMap; uniform float4 _SpecGlossMap_ST;
  243. uniform float _SpecularIntensity;
  244. uniform float _Glossiness;
  245. uniform float _Transparency;
  246. struct VertexInput {
  247. float4 vertex : POSITION;
  248. float3 normal : NORMAL;
  249. float4 tangent : TANGENT;
  250. float2 texcoord0 : TEXCOORD0;
  251. float2 texcoord1 : TEXCOORD1;
  252. float2 texcoord2 : TEXCOORD2;
  253. };
  254. struct VertexOutput {
  255. float4 pos : SV_POSITION;
  256. float2 uv0 : TEXCOORD0;
  257. float2 uv1 : TEXCOORD1;
  258. float2 uv2 : TEXCOORD2;
  259. float4 posWorld : TEXCOORD3;
  260. float3 normalDir : TEXCOORD4;
  261. float3 tangentDir : TEXCOORD5;
  262. float3 bitangentDir : TEXCOORD6;
  263. LIGHTING_COORDS(7,8)
  264. UNITY_FOG_COORDS(9)
  265. };
  266. VertexOutput vert (VertexInput v) {
  267. VertexOutput o = (VertexOutput)0;
  268. o.uv0 = v.texcoord0;
  269. o.uv1 = v.texcoord1;
  270. o.uv2 = v.texcoord2;
  271. o.normalDir = UnityObjectToWorldNormal(v.normal);
  272. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  273. o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  274. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  275. float3 lightColor = _LightColor0.rgb;
  276. o.pos = UnityObjectToClipPos( v.vertex );
  277. UNITY_TRANSFER_FOG(o,o.pos);
  278. TRANSFER_VERTEX_TO_FRAGMENT(o)
  279. return o;
  280. }
  281. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  282. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  283. float faceSign = ( facing >= 0 ? 1 : -1 );
  284. i.normalDir = normalize(i.normalDir);
  285. i.normalDir *= faceSign;
  286. float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
  287. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  288. float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(i.uv0, _BumpMap)));
  289. float3 normalLocal = lerp(float3(0,0,1),_BumpMap_var.rgb,_NormalIntensity);
  290. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  291. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
  292. float3 lightColor = _LightColor0.rgb;
  293. float3 halfDirection = normalize(viewDirection+lightDirection);
  294. ////// Lighting:
  295. UNITY_LIGHT_ATTENUATION(attenuation,i, i.posWorld.xyz);
  296. float3 attenColor = attenuation * _LightColor0.xyz;
  297. float Pi = 3.141592654;
  298. float InvPi = 0.31830988618;
  299. ///////// Gloss:
  300. float gloss = _Glossiness;
  301. float perceptualRoughness = 1.0 - _Glossiness;
  302. float roughness = perceptualRoughness * perceptualRoughness;
  303. float specPow = exp2( gloss * 10.0 + 1.0 );
  304. ////// Specular:
  305. float NdotL = saturate(dot( normalDirection, lightDirection ));
  306. float LdotH = saturate(dot(lightDirection, halfDirection));
  307. float4 _SpecGlossMap_var = tex2D(_SpecGlossMap,TRANSFORM_TEX(i.uv0, _SpecGlossMap));
  308. float3 specularColor = ((_SpecGlossMap_var.rgb*_SpecularIntensity)*_SpecColor.rgb);
  309. float specularMonochrome;
  310. float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
  311. float3 diffuseColor = (_MainTex_var.rgb*_Color.rgb); // Need this for specular when using metallic
  312. diffuseColor = EnergyConservationBetweenDiffuseAndSpecular(diffuseColor, specularColor, specularMonochrome);
  313. specularMonochrome = 1.0-specularMonochrome;
  314. float NdotV = abs(dot( normalDirection, viewDirection ));
  315. float NdotH = saturate(dot( normalDirection, halfDirection ));
  316. float VdotH = saturate(dot( viewDirection, halfDirection ));
  317. float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );
  318. float normTerm = GGXTerm(NdotH, roughness);
  319. float specularPBL = (visTerm*normTerm) * UNITY_PI;
  320. #ifdef UNITY_COLORSPACE_GAMMA
  321. specularPBL = sqrt(max(1e-4h, specularPBL));
  322. #endif
  323. specularPBL = max(0, specularPBL * NdotL);
  324. #if defined(_SPECULARHIGHLIGHTS_OFF)
  325. specularPBL = 0.0;
  326. #endif
  327. specularPBL *= any(specularColor) ? 1.0 : 0.0;
  328. float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
  329. float3 specular = directSpecular;
  330. /////// Diffuse:
  331. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  332. half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
  333. float nlPow5 = Pow5(1-NdotL);
  334. float nvPow5 = Pow5(1-NdotV);
  335. float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;
  336. diffuseColor *= 1-specularMonochrome;
  337. float3 diffuse = directDiffuse * diffuseColor;
  338. /// Final Color:
  339. float3 finalColor = diffuse + specular;
  340. fixed4 finalRGBA = fixed4(finalColor * (_MainTex_var.a*(1.0 - _Transparency)),0);
  341. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  342. return finalRGBA;
  343. }
  344. ENDCG
  345. }
  346. Pass {
  347. Name "ShadowCaster"
  348. Tags {
  349. "LightMode"="ShadowCaster"
  350. }
  351. Offset 1, 1
  352. Cull Off
  353. CGPROGRAM
  354. #pragma vertex vert
  355. #pragma fragment frag
  356. #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
  357. #define _GLOSSYENV 1
  358. #include "UnityCG.cginc"
  359. #include "Lighting.cginc"
  360. #include "UnityPBSLighting.cginc"
  361. #include "UnityStandardBRDF.cginc"
  362. #pragma fragmentoption ARB_precision_hint_fastest
  363. #pragma multi_compile_shadowcaster
  364. #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
  365. #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
  366. #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
  367. #pragma multi_compile_fog
  368. #pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
  369. #pragma target 3.0
  370. struct VertexInput {
  371. float4 vertex : POSITION;
  372. float2 texcoord1 : TEXCOORD1;
  373. float2 texcoord2 : TEXCOORD2;
  374. };
  375. struct VertexOutput {
  376. V2F_SHADOW_CASTER;
  377. float2 uv1 : TEXCOORD1;
  378. float2 uv2 : TEXCOORD2;
  379. float4 posWorld : TEXCOORD3;
  380. };
  381. VertexOutput vert (VertexInput v) {
  382. VertexOutput o = (VertexOutput)0;
  383. o.uv1 = v.texcoord1;
  384. o.uv2 = v.texcoord2;
  385. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  386. o.pos = UnityObjectToClipPos( v.vertex );
  387. TRANSFER_SHADOW_CASTER(o)
  388. return o;
  389. }
  390. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  391. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  392. float faceSign = ( facing >= 0 ? 1 : -1 );
  393. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  394. SHADOW_CASTER_FRAGMENT(i)
  395. }
  396. ENDCG
  397. }
  398. Pass {
  399. Name "Meta"
  400. Tags {
  401. "LightMode"="Meta"
  402. }
  403. Cull Off
  404. CGPROGRAM
  405. #pragma vertex vert
  406. #pragma fragment frag
  407. #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
  408. #define _GLOSSYENV 1
  409. #include "UnityCG.cginc"
  410. #include "Lighting.cginc"
  411. #include "UnityPBSLighting.cginc"
  412. #include "UnityStandardBRDF.cginc"
  413. #include "UnityMetaPass.cginc"
  414. #pragma fragmentoption ARB_precision_hint_fastest
  415. #pragma multi_compile_shadowcaster
  416. #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
  417. #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
  418. #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
  419. #pragma multi_compile_fog
  420. #pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
  421. #pragma target 3.0
  422. uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
  423. uniform float4 _Color;
  424. uniform sampler2D _SpecGlossMap; uniform float4 _SpecGlossMap_ST;
  425. uniform float _SpecularIntensity;
  426. uniform float _Glossiness;
  427. struct VertexInput {
  428. float4 vertex : POSITION;
  429. float2 texcoord0 : TEXCOORD0;
  430. float2 texcoord1 : TEXCOORD1;
  431. float2 texcoord2 : TEXCOORD2;
  432. };
  433. struct VertexOutput {
  434. float4 pos : SV_POSITION;
  435. float2 uv0 : TEXCOORD0;
  436. float2 uv1 : TEXCOORD1;
  437. float2 uv2 : TEXCOORD2;
  438. float4 posWorld : TEXCOORD3;
  439. };
  440. VertexOutput vert (VertexInput v) {
  441. VertexOutput o = (VertexOutput)0;
  442. o.uv0 = v.texcoord0;
  443. o.uv1 = v.texcoord1;
  444. o.uv2 = v.texcoord2;
  445. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  446. o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST );
  447. return o;
  448. }
  449. float4 frag(VertexOutput i, float facing : VFACE) : SV_Target {
  450. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  451. float faceSign = ( facing >= 0 ? 1 : -1 );
  452. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  453. UnityMetaInput o;
  454. UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );
  455. o.Emission = 0;
  456. float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
  457. float3 diffColor = (_MainTex_var.rgb*_Color.rgb);
  458. float4 _SpecGlossMap_var = tex2D(_SpecGlossMap,TRANSFORM_TEX(i.uv0, _SpecGlossMap));
  459. float3 specColor = ((_SpecGlossMap_var.rgb*_SpecularIntensity)*_SpecColor.rgb);
  460. float specularMonochrome = max(max(specColor.r, specColor.g),specColor.b);
  461. diffColor *= (1.0-specularMonochrome);
  462. float roughness = 1.0 - _Glossiness;
  463. o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
  464. return UnityMetaFragment( o );
  465. }
  466. ENDCG
  467. }
  468. }
  469. FallBack "Diffuse"
  470. }