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.

483 lines
24 KiB

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