Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
279
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2.  
  3. // Shader created with Shader Forge v1.28
  4. // Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
  5. // Note: Manually altering this data may prevent you from opening it in Shader Forge
  6. /*SF_DATA;ver:1.28;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,lico:1,lgpr:1,limd:3,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:True,hqlp:True,rprd:True,enco:False,rmgx:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:0,bdst:1,dpts:2,wrdp:True,dith:0,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False;n:type:ShaderForge.SFN_Final,id:2865,x:32871,y:32883,varname:node_2865,prsc:2|diff-7887-OUT,spec-158-OUT,gloss-1397-OUT,normal-5720-OUT;n:type:ShaderForge.SFN_Multiply,id:6343,x:32240,y:32681,varname:node_6343,prsc:2|A-7736-RGB,B-6665-RGB;n:type:ShaderForge.SFN_Color,id:6665,x:31922,y:32725,ptovrint:False,ptlb:Color,ptin:_Color,varname:_Color,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,c1:0.5019608,c2:0.5019608,c3:0.5019608,c4:1;n:type:ShaderForge.SFN_Tex2d,id:7736,x:31922,y:32539,ptovrint:True,ptlb:Base Color,ptin:_MainTex,varname:_MainTex,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:5964,x:31922,y:33776,ptovrint:True,ptlb:Normal Map,ptin:_BumpMap,varname:_BumpMap,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:3,isnm:True;n:type:ShaderForge.SFN_Slider,id:358,x:31765,y:33038,ptovrint:False,ptlb:Metallic,ptin:_Metallic,varname:node_358,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.08627867,max:1;n:type:ShaderForge.SFN_Slider,id:1813,x:31765,y:33658,ptovrint:False,ptlb:Gloss,ptin:_Gloss,varname:_Metallic_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_NormalVector,id:6875,x:31118,y:32495,prsc:2,pt:True;n:type:ShaderForge.SFN_Vector4Property,id:3520,x:30925,y:32328,ptovrint:False,ptlb:Snow Direction,ptin:_SnowDirection,varname:node_3520,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:0,v2:1,v3:0.2,v4:0;n:type:ShaderForge.SFN_Dot,id:5213,x:31466,y:32174,varname:node_5213,prsc:2,dt:0|A-4454-OUT,B-6875-OUT;n:type:ShaderForge.SFN_If,id:6795,x:31922,y:32378,varname:node_6795,prsc:2|A-8464-OUT,B-8464-OUT,GT-8464-OUT,EQ-8464-OUT,LT-8464-OUT;n:type:ShaderForge.SFN_Slider,id:511,x:30961,y:32769,ptovrint:False,ptlb:Snowiness,ptin:_Snowiness,varname:node_511,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.6050279,max:1;n:type:ShaderForge.SFN_Vector1,id:7778,x:31466,y:32696,varname:node_7778,prsc:2,v1:1;n:type:ShaderForge.SFN_Vector1,id:2068,x:31466,y:32770,varname:node_2068,prsc:2,v1:0;n:type:ShaderForge.SFN_OneMinus,id:9087,x:31466,y:32544,varname:node_9087,prsc:2|IN-511-OUT;n:type:ShaderForge.SFN_Dot,id:4177,x:31466,y:32323,varname:node_4177,prsc:2,dt:3|A-4454-OUT,B-6875-OUT;n:type:ShaderForge.SFN_Lerp,id:1344,x:31712,y:32307,varname:node_1344,prsc:2|A-5213-OUT,B-4177-OUT,T-5478-OUT;n:type:ShaderForge.SFN_Slider,id:3651,x:30961,y:32672,ptovrint:False,ptlb:Cakiness,ptin:_Cakiness,varname:node_3651,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:1,max:1;n:type:ShaderForge.SFN_Relay,id:5478,x:31466,y:32479,varname:node_5478,prsc:2|IN-3651-OUT;n:type:ShaderForge.SFN_Add,id:7887,x:32559,y:32731,varname:node_7887,prsc:2|A-6343-OUT,B-6795-OUT,C-5955-OUT;n:type:ShaderForge.SFN_Tex2d,id:3705,x:31922,y:33453,ptovrint:False,ptlb:Gloss Map,ptin:_GlossMap,varname:node_3705,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Multiply,id:5703,x:32129,y:33358,varname:node_5703,prsc:2|A-3705-R,B-1813-OUT,C-7397-OUT;n:type:ShaderForge.SFN_OneMinus,id:7397,x:31922,y:33298,varname:node_7397,prsc:2|IN-6795-OUT;n:type:ShaderForge.SFN_Multiply,id:158,x:32559,y:32888,varname:node_158,prsc:2|A-358-OUT,B-7316-R,C-7397-OUT;n:type:ShaderForge.SFN_Tex2d,id:7316,x:31922,y:33136,ptovrint:False,ptlb:Metal Map,ptin:_MetalMap,varname:node_7316,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Noise,id:3377,x:31118,y:32876,varname:node_3377,prsc:2|XY-3977-UVOUT;n:type:ShaderForge.SFN_TexCoord,id:3977,x:30946,y:32876,varname:node_3977,prsc:2,uv:0;n:type:ShaderForge.SFN_Multiply,id:7475,x:31702,y:32876,varname:node_7475,prsc:2|A-5436-OUT,B-6795-OUT,C-2541-OUT;n:type:ShaderForge.SFN_RemapRange,id:2784,x:31302,y:32876,varname:node_2784,prsc:2,frmn:0,frmx:1,tomn:-1,tomx:0.01|IN-3377-OUT;n:type:ShaderForge.SFN_Normalize,id:5436,x:31469,y:32876,varname:node_5436,prsc:2|IN-2784-OUT;n:type:ShaderForge.SFN_Add,id:1397,x:32559,y:33036,varname:node_1397,prsc:2|A-5703-OUT,B-5955-OUT;n:type:ShaderForge.SFN_Normalize,id:4454,x:31118,y:32328,varname:node_4454,prsc:2|IN-3520-XYZ;n:type:ShaderForge.SFN_Vector3,id:1623,x:32175,y:33953,varname:node_1623,prsc:2,v1:0,v2:0,v3:1;n:type:ShaderForge.SFN_Lerp,id:5720,x:32559,y:33192,varname:node_5720,prsc:2|A-9052-OUT,B-1623-OUT,T-9591-OUT;n:type:ShaderForge.SFN_NormalVector,id:9849,x:31470,y:33776,prsc:2,pt:False;n:type:ShaderForge.SFN_Dot,id:9792,x:31705,y:33776,varname:node_9792,prsc:2,dt:0|A-4454-OUT,B-9849-OUT;n:type:ShaderForge.SFN_Multiply,id:9591,x:32175,y:34068,varname:node_9591,prsc:2|A-9792-OUT,B-2472-OUT,C-1640-OUT;n:type:ShaderForge.SFN_Tex2d,id:7,x:31922,y:33993,ptovrint:False,ptlb:Detail Normal,ptin:_DetailNormal,varname:node_7,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:bbab0a6f7bae9cf42bf057d8ee2755f6,ntxv:3,isnm:True|UVIN-6846-OUT;n:type:ShaderForge.SFN_TexCoord,id:6929,x:31470,y:33954,varname:node_6929,prsc:2,uv:0;n:type:ShaderForge.SFN_Multiply,id:6846,x:31705,y:33954,varname:node_6846,prsc:2|A-6929-UVOUT,B-553-OUT;n:type:ShaderForge.SFN_Slider,id:553,x:31313,y:34160,ptovrint:False,ptlb:Detail Scale,ptin:_DetailScale,varname:node_553,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:1.218944,max:50;n:type:ShaderForge.SFN_Blend,id:9052,x:32175,y:33776,varname:node_9052,prsc:2,blmd:8,clmp:False|SRC-5964-RGB,DST-7-RGB;n:type:ShaderForge.SFN_Clamp01,id:2472,x:31705,y:34111,varname:node_2472,prsc:2|IN-7831-OUT;n:type:ShaderForge.SFN_Add,id:7831,x:31470,y:34258,varname:node_7831,prsc:2|A-511-OUT,B-511-OUT;n:type:ShaderForge.SFN_Clamp01,id:5955,x:31922,y:32876,varname:node_5955,prsc:2|IN-7475-OUT;n:type:ShaderForge.SFN_Slider,id:2541,x:31312,y:33108,ptovrint:False,ptlb:Sparkle,ptin:_Sparkle,varname:node_2541,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:1,max:1;n:type:ShaderForge.SFN_Slider,id:1640,x:31891,y:34326,ptovrint:False,ptlb:Smoothness,ptin:_Smoothness,varname:node_1640,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_Vector1,id:8464,x:31685,y:32494,varname:node_8464,prsc:2,v1:0;proporder:6665-7736-5964-358-7316-1813-3705-3520-511-3651-7-553-2541-1640;pass:END;sub:END;*/
  7.  
  8. Shader "Shader Forge/Sno" {
  9. Properties {
  10. _Color ("Color", Color) = (0.5019608,0.5019608,0.5019608,1)
  11. _MainTex ("Base Color", 2D) = "white" {}
  12. _BumpMap ("Normal Map", 2D) = "bump" {}
  13. _Metallic ("Metallic", Range(0, 1)) = 0.08627867
  14. _MetalMap ("Metal Map", 2D) = "white" {}
  15. _Gloss ("Gloss", Range(0, 1)) = 0
  16. _GlossMap ("Gloss Map", 2D) = "white" {}
  17. _SnowDirection ("Snow Direction", Vector) = (0,1,0.2,0)
  18. _Snowiness ("Snowiness", Range(0, 1)) = 0.6050279
  19. _Cakiness ("Cakiness", Range(0, 1)) = 1
  20. _DetailNormal ("Detail Normal", 2D) = "bump" {}
  21. _DetailScale ("Detail Scale", Range(0, 50)) = 1.218944
  22. _Sparkle ("Sparkle", Range(0, 1)) = 1
  23. _Smoothness ("Smoothness", Range(0, 1)) = 0
  24. }
  25. SubShader {
  26. Tags {
  27. "RenderType"="Opaque"
  28. }
  29. LOD 100
  30. Pass {
  31. Name "FORWARD"
  32. Tags {
  33. "LightMode"="ForwardBase"
  34. }
  35.  
  36.  
  37. CGPROGRAM
  38. #pragma vertex vert
  39. #pragma fragment frag
  40. #define UNITY_PASS_FORWARDBASE
  41. #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
  42. #define _GLOSSYENV 1
  43. #include "UnityCG.cginc"
  44. #include "AutoLight.cginc"
  45. #include "Lighting.cginc"
  46. #include "UnityPBSLighting.cginc"
  47. #include "UnityStandardBRDF.cginc"
  48. #pragma multi_compile_fwdbase_fullshadows
  49. #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
  50. #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
  51. #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
  52. #pragma multi_compile_fog
  53. #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
  54. #pragma target 3.0
  55. uniform float4 _Color;
  56. uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
  57. uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
  58. uniform float _Metallic;
  59. uniform float _Gloss;
  60. uniform float4 _SnowDirection;
  61. uniform float _Snowiness;
  62. uniform sampler2D _GlossMap; uniform float4 _GlossMap_ST;
  63. uniform sampler2D _MetalMap; uniform float4 _MetalMap_ST;
  64. uniform sampler2D _DetailNormal; uniform float4 _DetailNormal_ST;
  65. uniform float _DetailScale;
  66. uniform float _Sparkle;
  67. uniform float _Smoothness;
  68. struct VertexInput {
  69. float4 vertex : POSITION;
  70. float3 normal : NORMAL;
  71. float4 tangent : TANGENT;
  72. float2 texcoord0 : TEXCOORD0;
  73. float2 texcoord1 : TEXCOORD1;
  74. float2 texcoord2 : TEXCOORD2;
  75. };
  76. struct VertexOutput {
  77. float4 pos : SV_POSITION;
  78. float2 uv0 : TEXCOORD0;
  79. float2 uv1 : TEXCOORD1;
  80. float2 uv2 : TEXCOORD2;
  81. float4 posWorld : TEXCOORD3;
  82. float3 normalDir : TEXCOORD4;
  83. float3 tangentDir : TEXCOORD5;
  84. float3 bitangentDir : TEXCOORD6;
  85. LIGHTING_COORDS(7,8)
  86. UNITY_FOG_COORDS(9)
  87. #if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH)
  88. float4 ambientOrLightmapUV : TEXCOORD10;
  89. #endif
  90. };
  91. VertexOutput vert (VertexInput v) {
  92. VertexOutput o = (VertexOutput)0;
  93. o.uv0 = v.texcoord0;
  94. o.uv1 = v.texcoord1;
  95. o.uv2 = v.texcoord2;
  96. #ifdef LIGHTMAP_ON
  97. o.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  98. o.ambientOrLightmapUV.zw = 0;
  99. #endif
  100. #ifdef DYNAMICLIGHTMAP_ON
  101. o.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  102. #endif
  103. o.normalDir = UnityObjectToWorldNormal(v.normal);
  104. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  105. o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  106. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  107. float3 lightColor = _LightColor0.rgb;
  108. o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
  109. UNITY_TRANSFER_FOG(o,o.pos);
  110. TRANSFER_VERTEX_TO_FRAGMENT(o)
  111. return o;
  112. }
  113. float4 frag(VertexOutput i) : COLOR {
  114. i.normalDir = normalize(i.normalDir);
  115. float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
  116. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  117. float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(i.uv0, _BumpMap)));
  118. float2 node_6846 = (i.uv0*_DetailScale);
  119. float3 _DetailNormal_var = UnpackNormal(tex2D(_DetailNormal,TRANSFORM_TEX(node_6846, _DetailNormal)));
  120. float3 node_4454 = normalize(_SnowDirection.rgb);
  121. float3 normalLocal = lerp((_BumpMap_var.rgb+_DetailNormal_var.rgb),float3(0,0,1),(dot(node_4454,i.normalDir)*saturate((_Snowiness+_Snowiness))*_Smoothness));
  122. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  123. float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
  124. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  125. float3 lightColor = _LightColor0.rgb;
  126. float3 halfDirection = normalize(viewDirection+lightDirection);
  127. ////// Lighting:
  128. float attenuation = LIGHT_ATTENUATION(i);
  129. float3 attenColor = attenuation * _LightColor0.xyz;
  130. float Pi = 3.141592654;
  131. float InvPi = 0.31830988618;
  132. ///////// Gloss:
  133. float4 _GlossMap_var = tex2D(_GlossMap,TRANSFORM_TEX(i.uv0, _GlossMap));
  134. float node_8464 = 0.0;
  135. float node_6795_if_leA = step(node_8464,node_8464);
  136. float node_6795_if_leB = step(node_8464,node_8464);
  137. float node_6795 = lerp((node_6795_if_leA*node_8464)+(node_6795_if_leB*node_8464),node_8464,node_6795_if_leA*node_6795_if_leB);
  138. float node_7397 = (1.0 - node_6795);
  139. float2 node_3377_skew = i.uv0 + 0.2127+i.uv0.x*0.3713*i.uv0.y;
  140. float2 node_3377_rnd = 4.789*sin(489.123*(node_3377_skew));
  141. float node_3377 = frac(node_3377_rnd.x*node_3377_rnd.y*(1+node_3377_skew.x));
  142. float node_5955 = saturate((normalize((node_3377*1.01+-1.0))*node_6795*_Sparkle));
  143. float gloss = ((_GlossMap_var.r*_Gloss*node_7397)+node_5955);
  144. float specPow = exp2( gloss * 10.0+1.0);
  145. /////// GI Data:
  146. UnityLight light;
  147. #ifdef LIGHTMAP_OFF
  148. light.color = lightColor;
  149. light.dir = lightDirection;
  150. light.ndotl = LambertTerm (normalDirection, light.dir);
  151. #else
  152. light.color = half3(0.f, 0.f, 0.f);
  153. light.ndotl = 0.0f;
  154. light.dir = half3(0.f, 0.f, 0.f);
  155. #endif
  156. UnityGIInput d;
  157. d.light = light;
  158. d.worldPos = i.posWorld.xyz;
  159. d.worldViewDir = viewDirection;
  160. d.atten = attenuation;
  161. #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
  162. d.ambient = 0;
  163. d.lightmapUV = i.ambientOrLightmapUV;
  164. #else
  165. d.ambient = i.ambientOrLightmapUV;
  166. #endif
  167. d.boxMax[0] = unity_SpecCube0_BoxMax;
  168. d.boxMin[0] = unity_SpecCube0_BoxMin;
  169. d.probePosition[0] = unity_SpecCube0_ProbePosition;
  170. d.probeHDR[0] = unity_SpecCube0_HDR;
  171. d.boxMax[1] = unity_SpecCube1_BoxMax;
  172. d.boxMin[1] = unity_SpecCube1_BoxMin;
  173. d.probePosition[1] = unity_SpecCube1_ProbePosition;
  174. d.probeHDR[1] = unity_SpecCube1_HDR;
  175. Unity_GlossyEnvironmentData ugls_en_data;
  176. ugls_en_data.roughness = 1.0 - gloss;
  177. ugls_en_data.reflUVW = viewReflectDirection;
  178. UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );
  179. lightDirection = gi.light.dir;
  180. lightColor = gi.light.color;
  181. ////// Specular:
  182. float NdotL = max(0, dot( normalDirection, lightDirection ));
  183. float LdotH = max(0.0,dot(lightDirection, halfDirection));
  184. float4 _MetalMap_var = tex2D(_MetalMap,TRANSFORM_TEX(i.uv0, _MetalMap));
  185. float3 specularColor = (_Metallic*_MetalMap_var.r*node_7397);
  186. float specularMonochrome;
  187. float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
  188. float3 diffuseColor = ((_MainTex_var.rgb*_Color.rgb)+node_6795+node_5955); // Need this for specular when using metallic
  189. diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );
  190. specularMonochrome = 1.0-specularMonochrome;
  191. float NdotV = max(0.0,dot( normalDirection, viewDirection ));
  192. float NdotH = max(0.0,dot( normalDirection, halfDirection ));
  193. float VdotH = max(0.0,dot( viewDirection, halfDirection ));
  194. float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, 1.0-gloss );
  195. float normTerm = max(0.0, GGXTerm(NdotH, 1.0-gloss));
  196. float specularPBL = (NdotL*visTerm*normTerm) * (UNITY_PI / 4);
  197. if (IsGammaSpace())
  198. specularPBL = sqrt(max(1e-4h, specularPBL));
  199. specularPBL = max(0, specularPBL * NdotL);
  200. float3 directSpecular = (floor(attenuation) * _LightColor0.xyz)*specularPBL*FresnelTerm(specularColor, LdotH);
  201. half grazingTerm = saturate( gloss + specularMonochrome );
  202. float3 indirectSpecular = (gi.indirect.specular);
  203. indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV);
  204. float3 specular = (directSpecular + indirectSpecular);
  205. /////// Diffuse:
  206. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  207. half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
  208. float nlPow5 = Pow5(1-NdotL);
  209. float nvPow5 = Pow5(1-NdotV);
  210. float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;
  211. float3 indirectDiffuse = float3(0,0,0);
  212. indirectDiffuse += gi.indirect.diffuse;
  213. float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
  214. /// Final Color:
  215. float3 finalColor = diffuse + specular;
  216. fixed4 finalRGBA = fixed4(finalColor,1);
  217. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  218. return finalRGBA;
  219. }
  220. ENDCG
  221. }
  222. Pass {
  223. Name "FORWARD_DELTA"
  224. Tags {
  225. "LightMode"="ForwardAdd"
  226. }
  227. Blend One One
  228.  
  229.  
  230. CGPROGRAM
  231. #pragma vertex vert
  232. #pragma fragment frag
  233. #define UNITY_PASS_FORWARDADD
  234. #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
  235. #define _GLOSSYENV 1
  236. #include "UnityCG.cginc"
  237. #include "AutoLight.cginc"
  238. #include "Lighting.cginc"
  239. #include "UnityPBSLighting.cginc"
  240. #include "UnityStandardBRDF.cginc"
  241. #pragma multi_compile_fwdadd_fullshadows
  242. #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
  243. #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
  244. #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
  245. #pragma multi_compile_fog
  246. #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
  247. #pragma target 3.0
  248. uniform float4 _Color;
  249. uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
  250. uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
  251. uniform float _Metallic;
  252. uniform float _Gloss;
  253. uniform float4 _SnowDirection;
  254. uniform float _Snowiness;
  255. uniform sampler2D _GlossMap; uniform float4 _GlossMap_ST;
  256. uniform sampler2D _MetalMap; uniform float4 _MetalMap_ST;
  257. uniform sampler2D _DetailNormal; uniform float4 _DetailNormal_ST;
  258. uniform float _DetailScale;
  259. uniform float _Sparkle;
  260. uniform float _Smoothness;
  261. struct VertexInput {
  262. float4 vertex : POSITION;
  263. float3 normal : NORMAL;
  264. float4 tangent : TANGENT;
  265. float2 texcoord0 : TEXCOORD0;
  266. float2 texcoord1 : TEXCOORD1;
  267. float2 texcoord2 : TEXCOORD2;
  268. };
  269. struct VertexOutput {
  270. float4 pos : SV_POSITION;
  271. float2 uv0 : TEXCOORD0;
  272. float2 uv1 : TEXCOORD1;
  273. float2 uv2 : TEXCOORD2;
  274. float4 posWorld : TEXCOORD3;
  275. float3 normalDir : TEXCOORD4;
  276. float3 tangentDir : TEXCOORD5;
  277. float3 bitangentDir : TEXCOORD6;
  278. LIGHTING_COORDS(7,8)
  279. UNITY_FOG_COORDS(9)
  280. };
  281. VertexOutput vert (VertexInput v) {
  282. VertexOutput o = (VertexOutput)0;
  283. o.uv0 = v.texcoord0;
  284. o.uv1 = v.texcoord1;
  285. o.uv2 = v.texcoord2;
  286. o.normalDir = UnityObjectToWorldNormal(v.normal);
  287. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  288. o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  289. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  290. float3 lightColor = _LightColor0.rgb;
  291. o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
  292. UNITY_TRANSFER_FOG(o,o.pos);
  293. TRANSFER_VERTEX_TO_FRAGMENT(o)
  294. return o;
  295. }
  296. float4 frag(VertexOutput i) : COLOR {
  297. i.normalDir = normalize(i.normalDir);
  298. float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
  299. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  300. float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(i.uv0, _BumpMap)));
  301. float2 node_6846 = (i.uv0*_DetailScale);
  302. float3 _DetailNormal_var = UnpackNormal(tex2D(_DetailNormal,TRANSFORM_TEX(node_6846, _DetailNormal)));
  303. float3 node_4454 = normalize(_SnowDirection.rgb);
  304. float3 normalLocal = lerp((_BumpMap_var.rgb+_DetailNormal_var.rgb),float3(0,0,1),(dot(node_4454,i.normalDir)*saturate((_Snowiness+_Snowiness))*_Smoothness));
  305. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  306. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
  307. float3 lightColor = _LightColor0.rgb;
  308. float3 halfDirection = normalize(viewDirection+lightDirection);
  309. ////// Lighting:
  310. float attenuation = LIGHT_ATTENUATION(i);
  311. float3 attenColor = attenuation * _LightColor0.xyz;
  312. float Pi = 3.141592654;
  313. float InvPi = 0.31830988618;
  314. ///////// Gloss:
  315. float4 _GlossMap_var = tex2D(_GlossMap,TRANSFORM_TEX(i.uv0, _GlossMap));
  316. float node_8464 = 0.0;
  317. float node_6795_if_leA = step(node_8464,node_8464);
  318. float node_6795_if_leB = step(node_8464,node_8464);
  319. float node_6795 = lerp((node_6795_if_leA*node_8464)+(node_6795_if_leB*node_8464),node_8464,node_6795_if_leA*node_6795_if_leB);
  320. float node_7397 = (1.0 - node_6795);
  321. float2 node_3377_skew = i.uv0 + 0.2127+i.uv0.x*0.3713*i.uv0.y;
  322. float2 node_3377_rnd = 4.789*sin(489.123*(node_3377_skew));
  323. float node_3377 = frac(node_3377_rnd.x*node_3377_rnd.y*(1+node_3377_skew.x));
  324. float node_5955 = saturate((normalize((node_3377*1.01+-1.0))*node_6795*_Sparkle));
  325. float gloss = ((_GlossMap_var.r*_Gloss*node_7397)+node_5955);
  326. float specPow = exp2( gloss * 10.0+1.0);
  327. ////// Specular:
  328. float NdotL = max(0, dot( normalDirection, lightDirection ));
  329. float LdotH = max(0.0,dot(lightDirection, halfDirection));
  330. float4 _MetalMap_var = tex2D(_MetalMap,TRANSFORM_TEX(i.uv0, _MetalMap));
  331. float3 specularColor = (_Metallic*_MetalMap_var.r*node_7397);
  332. float specularMonochrome;
  333. float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
  334. float3 diffuseColor = ((_MainTex_var.rgb*_Color.rgb)+node_6795+node_5955); // Need this for specular when using metallic
  335. diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );
  336. specularMonochrome = 1.0-specularMonochrome;
  337. float NdotV = max(0.0,dot( normalDirection, viewDirection ));
  338. float NdotH = max(0.0,dot( normalDirection, halfDirection ));
  339. float VdotH = max(0.0,dot( viewDirection, halfDirection ));
  340. float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, 1.0-gloss );
  341. float normTerm = max(0.0, GGXTerm(NdotH, 1.0-gloss));
  342. float specularPBL = (NdotL*visTerm*normTerm) * (UNITY_PI / 4);
  343. if (IsGammaSpace())
  344. specularPBL = sqrt(max(1e-4h, specularPBL));
  345. specularPBL = max(0, specularPBL * NdotL);
  346. float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
  347. float3 specular = directSpecular;
  348. /////// Diffuse:
  349. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  350. half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
  351. float nlPow5 = Pow5(1-NdotL);
  352. float nvPow5 = Pow5(1-NdotV);
  353. float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;
  354. float3 diffuse = directDiffuse * diffuseColor;
  355. /// Final Color:
  356. float3 finalColor = diffuse + specular;
  357. fixed4 finalRGBA = fixed4(finalColor * 1,0);
  358. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  359. return finalRGBA;
  360. }
  361. ENDCG
  362. }
  363. Pass {
  364. Name "Meta"
  365. Tags {
  366. "LightMode"="Meta"
  367. }
  368. Cull Off
  369.  
  370. CGPROGRAM
  371. #pragma vertex vert
  372. #pragma fragment frag
  373. #define UNITY_PASS_META 1
  374. #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
  375. #define _GLOSSYENV 1
  376. #include "UnityCG.cginc"
  377. #include "Lighting.cginc"
  378. #include "UnityPBSLighting.cginc"
  379. #include "UnityStandardBRDF.cginc"
  380. #include "UnityMetaPass.cginc"
  381. #pragma fragmentoption ARB_precision_hint_fastest
  382. #pragma multi_compile_shadowcaster
  383. #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
  384. #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
  385. #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
  386. #pragma multi_compile_fog
  387. #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
  388. #pragma target 3.0
  389. uniform float4 _Color;
  390. uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
  391. uniform float _Metallic;
  392. uniform float _Gloss;
  393. uniform sampler2D _GlossMap; uniform float4 _GlossMap_ST;
  394. uniform sampler2D _MetalMap; uniform float4 _MetalMap_ST;
  395. uniform float _Sparkle;
  396. struct VertexInput {
  397. float4 vertex : POSITION;
  398. float2 texcoord0 : TEXCOORD0;
  399. float2 texcoord1 : TEXCOORD1;
  400. float2 texcoord2 : TEXCOORD2;
  401. };
  402. struct VertexOutput {
  403. float4 pos : SV_POSITION;
  404. float2 uv0 : TEXCOORD0;
  405. float2 uv1 : TEXCOORD1;
  406. float2 uv2 : TEXCOORD2;
  407. float4 posWorld : TEXCOORD3;
  408. };
  409. VertexOutput vert (VertexInput v) {
  410. VertexOutput o = (VertexOutput)0;
  411. o.uv0 = v.texcoord0;
  412. o.uv1 = v.texcoord1;
  413. o.uv2 = v.texcoord2;
  414. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  415. o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST );
  416. return o;
  417. }
  418. float4 frag(VertexOutput i) : SV_Target {
  419. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  420. UnityMetaInput o;
  421. UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );
  422.  
  423. o.Emission = 0;
  424.  
  425. float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
  426. float node_8464 = 0.0;
  427. float node_6795_if_leA = step(node_8464,node_8464);
  428. float node_6795_if_leB = step(node_8464,node_8464);
  429. float node_6795 = lerp((node_6795_if_leA*node_8464)+(node_6795_if_leB*node_8464),node_8464,node_6795_if_leA*node_6795_if_leB);
  430. float2 node_3377_skew = i.uv0 + 0.2127+i.uv0.x*0.3713*i.uv0.y;
  431. float2 node_3377_rnd = 4.789*sin(489.123*(node_3377_skew));
  432. float node_3377 = frac(node_3377_rnd.x*node_3377_rnd.y*(1+node_3377_skew.x));
  433. float node_5955 = saturate((normalize((node_3377*1.01+-1.0))*node_6795*_Sparkle));
  434. float3 diffColor = ((_MainTex_var.rgb*_Color.rgb)+node_6795+node_5955);
  435. float specularMonochrome;
  436. float3 specColor;
  437. float4 _MetalMap_var = tex2D(_MetalMap,TRANSFORM_TEX(i.uv0, _MetalMap));
  438. float node_7397 = (1.0 - node_6795);
  439. diffColor = DiffuseAndSpecularFromMetallic( diffColor, (_Metallic*_MetalMap_var.r*node_7397), specColor, specularMonochrome );
  440. float4 _GlossMap_var = tex2D(_GlossMap,TRANSFORM_TEX(i.uv0, _GlossMap));
  441. float roughness = 1.0 - ((_GlossMap_var.r*_Gloss*node_7397)+node_5955);
  442. o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
  443.  
  444. return UnityMetaFragment( o );
  445. }
  446. ENDCG
  447. }
  448. }
  449. FallBack "Diffuse"
  450. CustomEditor "ShaderForgeMaterialInspector"
  451. }
Advertisement
RAW Paste Data Copied
Advertisement