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.

466 lines
22 KiB

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