Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.49 KB | None | 0 0
  1. Shader "StylizedWater/Desktop" {
  2. Properties {
  3. _WaterColor ("Water Color", Color) = (0,0.503546,1,1)
  4. _RimColor ("Rim Color", Color) = (1,1,1,1)
  5. _FresnelColor ("Fresnel Color", Color) = (1,1,1,0.5019608)
  6. _Wavetint ("Wave tint", Range(-1, 1)) = 0
  7. _Fresnelexponent ("Fresnel exponent", Float ) = 4
  8. _NormalStrength ("Normal Strength", Range(0, 1)) = 1
  9. _Transparency ("Transparency", Range(0, 1)) = 0.75
  10. _Glossiness ("Glossiness", Range(0, 3)) = 1
  11. _SurfaceHighlight ("Surface Highlight", Range(0, 1)) = 0.05
  12. _Surfacehightlightsize ("Surface hightlight size", Range(0, 1)) = 0
  13. _SurfaceHightlighttiling ("Surface Hightlight tiling", Float ) = 0.25
  14. _UseIntersectionHighlight ("UseIntersectionHighlight", Range(0, 1)) = 0
  15. [MaterialToggle] _HighlightPanning ("HighlightPanning", Float ) = 0
  16. _Depth ("Depth", Range(0, 30)) = 30
  17. _Depthdarkness ("Depth darkness", Range(0, 1)) = 0.5
  18. _RimSize ("Rim Size", Range(0, 4)) = 2
  19. _Rimfalloff ("Rim falloff", Range(0, 5)) = 0.25
  20. _RimDistance ("Rim Distance", Range(0, 1)) = 0.1
  21. [MaterialToggle] _Worldspacetiling ("Worldspace tiling", Float ) = 0
  22. _Tiling ("Tiling", Range(0.1, 1)) = 0.9
  23. _Rimtiling ("Rim tiling", Float ) = 2
  24. _RefractionAmount ("Refraction Amount", Range(0, 0.2)) = 0.1
  25. _Wavesspeed ("Waves speed", Range(0, 10)) = 0.75
  26. _Wavesstrength ("Waves strength", Range(0, 1)) = 0
  27. _WaveSize ("WaveSize", Float ) = 0.1
  28. [NoScaleOffset][Normal]_Normals ("Normals", 2D) = "bump" {}
  29. [NoScaleOffset]_Shadermap ("Shadermap", 2D) = "black" {}
  30. _Reflection ("Reflection", Cube) = "_Skybox" {}
  31. [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  32. }
  33. SubShader {
  34. Tags {
  35. "IgnoreProjector"="True"
  36. "Queue"="Transparent"
  37. "RenderType"="Transparent"
  38. }
  39. GrabPass{ }
  40. Pass {
  41. Name "FORWARD"
  42. Tags {
  43. "LightMode"="ForwardBase"
  44. }
  45. Blend SrcAlpha OneMinusSrcAlpha
  46. ZWrite Off
  47.  
  48. CGPROGRAM
  49. #pragma vertex vert
  50. #pragma fragment frag
  51. #define UNITY_PASS_FORWARDBASE
  52. #include "UnityCG.cginc"
  53. #include "UnityPBSLighting.cginc"
  54. #include "UnityStandardBRDF.cginc"
  55. #pragma multi_compile_fwdbase
  56. #pragma multi_compile_fog
  57. #pragma exclude_renderers d3d11_9x xbox360 ps3 psp2
  58. #pragma target 3.0
  59. #pragma glsl
  60. uniform sampler2D _GrabTexture;
  61. uniform sampler2D _CameraDepthTexture;
  62. uniform float4 _TimeEditor;
  63. uniform fixed _RimSize;
  64. uniform fixed4 _WaterColor;
  65. uniform fixed4 _RimColor;
  66. uniform sampler2D _Shadermap;
  67. uniform fixed _Tiling;
  68. uniform float _RefractionAmount;
  69. uniform float _Transparency;
  70. uniform sampler2D _Normals;
  71. uniform fixed _Wavesspeed;
  72. uniform float _Glossiness;
  73. uniform float _Wavesstrength;
  74. uniform fixed _Depth;
  75. uniform fixed _Depthdarkness;
  76. uniform fixed _Rimtiling;
  77. uniform fixed _Worldspacetiling;
  78. uniform fixed _Rimfalloff;
  79. uniform float _SurfaceHighlight;
  80. uniform float _Surfacehightlightsize;
  81. uniform float _SurfaceHightlighttiling;
  82. uniform float _Fresnelexponent;
  83. uniform float4 _FresnelColor;
  84. uniform float _RimDistance;
  85. uniform fixed _HighlightPanning;
  86. uniform samplerCUBE _Reflection;
  87. uniform float _Wavetint;
  88. uniform float _WaveSize;
  89. uniform float _NormalStrength;
  90. uniform float _UseIntersectionHighlight;
  91. struct VertexInput {
  92. float4 vertex : POSITION;
  93. float3 normal : NORMAL;
  94. float4 tangent : TANGENT;
  95. float2 texcoord0 : TEXCOORD0;
  96. };
  97. struct VertexOutput {
  98. float4 pos : SV_POSITION;
  99. float2 uv0 : TEXCOORD0;
  100. float4 posWorld : TEXCOORD1;
  101. float3 normalDir : TEXCOORD2;
  102. float3 tangentDir : TEXCOORD3;
  103. float3 bitangentDir : TEXCOORD4;
  104. float4 screenPos : TEXCOORD5;
  105. float4 projPos : TEXCOORD6;
  106. UNITY_FOG_COORDS(7)
  107. };
  108. VertexOutput vert (VertexInput v) {
  109. VertexOutput o = (VertexOutput)0;
  110. o.uv0 = v.texcoord0;
  111. o.normalDir = UnityObjectToWorldNormal(v.normal);
  112. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  113. o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  114. float4 Time = _Time + _TimeEditor;
  115. float WaveSpeed = (Time.g*(_Wavesspeed*0.1));
  116. fixed2 Tiling = (lerp( ((-20.0)*o.uv0), mul(unity_ObjectToWorld, v.vertex).rgb.rb, _Worldspacetiling )*(1.0 - _Tiling));
  117. float2 node_5626 = ((Tiling*_WaveSize)+(WaveSpeed*0.5)*float2(0,1));
  118. float4 HeightmapTex = tex2Dlod(_Shadermap,float4(node_5626,0.0,0));
  119. float DisplacementDirection = (HeightmapTex.g*_Wavesstrength);
  120. float3 Displacement = (v.normal*DisplacementDirection);
  121. float3 node_933 = Displacement;
  122. v.vertex.xyz += node_933;
  123. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  124. float3 lightColor = _LightColor0.rgb;
  125. o.pos = UnityObjectToClipPos(v.vertex );
  126. UNITY_TRANSFER_FOG(o,o.pos);
  127. o.projPos = ComputeScreenPos (o.pos);
  128. COMPUTE_EYEDEPTH(o.projPos.z);
  129. o.screenPos = o.pos;
  130. return o;
  131. }
  132. float4 frag(VertexOutput i) : COLOR {
  133. #if UNITY_UV_STARTS_AT_TOP
  134. float grabSign = -_ProjectionParams.x;
  135. #else
  136. float grabSign = _ProjectionParams.x;
  137. #endif
  138. i.normalDir = normalize(i.normalDir);
  139. i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
  140. i.screenPos.y *= _ProjectionParams.x;
  141. float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
  142. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  143. float4 Time = _Time + _TimeEditor;
  144. float WaveSpeed = (Time.g*(_Wavesspeed*0.1));
  145. fixed mWaveSpeed = WaveSpeed;
  146. fixed2 Tiling = (lerp( ((-20.0)*i.uv0), i.posWorld.rgb.rb, _Worldspacetiling )*(1.0 - _Tiling));
  147. fixed2 mTiling = Tiling;
  148. fixed2 WavePanningV = (mTiling+mWaveSpeed*float2(0,1));
  149. fixed3 WavePanningV_Tex = UnpackNormal(tex2D(_Normals,WavePanningV));
  150. fixed2 WavePanningU = (mTiling+mWaveSpeed*float2(0.1,0));
  151. fixed3 WavePanningU_Tex = UnpackNormal(tex2D(_Normals,WavePanningU));
  152. float3 WaveNormalBlend_nrm_base = WavePanningV_Tex.rgb + float3(0,0,1);
  153. float3 WaveNormalBlend_nrm_detail = WavePanningU_Tex.rgb * float3(-1,-1,1);
  154. float3 WaveNormalBlend_nrm_combined = WaveNormalBlend_nrm_base*dot(WaveNormalBlend_nrm_base, WaveNormalBlend_nrm_detail)/WaveNormalBlend_nrm_base.z - WaveNormalBlend_nrm_detail;
  155. float3 WaveNormalBlend = WaveNormalBlend_nrm_combined;
  156. float2 HighlightPanningV = (WavePanningV*_SurfaceHightlighttiling);
  157. float4 HighlightPanningV_Tex = tex2D(_Shadermap,HighlightPanningV);
  158. float node_8200 = lerp(HighlightPanningV_Tex.r,HighlightPanningV_Tex.b,_UseIntersectionHighlight);
  159. float2 HightlightPanningU = (WavePanningU*_SurfaceHightlighttiling);
  160. float4 HightlightPanningU_Tex = tex2D(_Shadermap,HightlightPanningU);
  161. float node_5823 = lerp(HightlightPanningU_Tex.r,HightlightPanningU_Tex.b,_UseIntersectionHighlight);
  162. float SurfaceHighlights = saturate((_SurfaceHighlight*lerp(step(_Surfacehightlightsize,(node_8200-node_5823)),(1.0 - lerp( node_5823, (node_8200*node_5823), _HighlightPanning )),_UseIntersectionHighlight)));
  163. float3 Normals = lerp(i.normalDir,lerp(WaveNormalBlend,float3(0,0,1),SurfaceHighlights),_NormalStrength);
  164. float3 normalLocal = Normals;
  165. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  166. float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
  167. float sceneZ = max(0,LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)))) - _ProjectionParams.g);
  168. float partZ = max(0,i.projPos.z - _ProjectionParams.g);
  169. float2 Refraction = (_RefractionAmount*float2(WavePanningV_Tex.r,WavePanningU_Tex.g));
  170. float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + Refraction;
  171. float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
  172. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  173. float3 lightColor = _LightColor0.rgb;
  174. float3 halfDirection = normalize(viewDirection+lightDirection);
  175. ////// Lighting:
  176. float attenuation = 1;
  177. float3 attenColor = attenuation * _LightColor0.xyz;
  178. float Pi = 3.141592654;
  179. float InvPi = 0.31830988618;
  180. ///////// Gloss:
  181. float Roughness = (saturate((1.0-(1.0-WavePanningV_Tex.r)*(1.0-WavePanningU_Tex.g)))*_Glossiness);
  182. float gloss = 1.0 - Roughness; // Convert roughness to gloss
  183. float specPow = exp2( gloss * 10.0+1.0);
  184. /////// GI Data:
  185. UnityLight light;
  186. #ifdef LIGHTMAP_OFF
  187. light.color = lightColor;
  188. light.dir = lightDirection;
  189. light.ndotl = LambertTerm (normalDirection, light.dir);
  190. #else
  191. light.color = half3(0.f, 0.f, 0.f);
  192. light.ndotl = 0.0f;
  193. light.dir = half3(0.f, 0.f, 0.f);
  194. #endif
  195. UnityGIInput d;
  196. d.light = light;
  197. d.worldPos = i.posWorld.xyz;
  198. d.worldViewDir = viewDirection;
  199. d.atten = attenuation;
  200. Unity_GlossyEnvironmentData ugls_en_data;
  201. ugls_en_data.roughness = 1.0 - gloss;
  202. ugls_en_data.reflUVW = viewReflectDirection;
  203. UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );
  204. lightDirection = gi.light.dir;
  205. lightColor = gi.light.color;
  206. ////// Specular:
  207. float NdotL = max(0, dot( normalDirection, lightDirection ));
  208. float LdotH = max(0.0,dot(lightDirection, halfDirection));
  209. float3 specularColor = 0.0;
  210. float specularMonochrome;
  211. float depth = saturate((sceneZ-partZ)/_Depth);
  212. float RimAllphaMultiply = ((saturate((sceneZ-partZ)/_RimDistance)-pow(saturate((sceneZ-partZ)/_RimSize),_Rimfalloff))*_RimColor.a); // Control rim opacity with color alpha
  213. float node_2352 = WaveSpeed;
  214. fixed2 rimTiling = (Tiling*_Rimtiling);
  215. fixed2 rimPanningU = (rimTiling+node_2352*float2(0.5,0.1));
  216. float4 rimU_Tex = tex2D(_Shadermap,rimPanningU);
  217. fixed2 rimPanningV = (rimTiling+node_2352*float2(0,1));
  218. float4 rimV_Tex = tex2D(_Shadermap,rimPanningV);
  219. float Intersection = saturate((RimAllphaMultiply+(RimAllphaMultiply*(1.0 - (rimU_Tex.b*rimV_Tex.b))*_RimColor.a)));
  220. float2 node_5626 = ((Tiling*_WaveSize)+(WaveSpeed*0.5)*float2(0,1));
  221. float4 HeightmapTex = tex2D(_Shadermap,node_5626);
  222. float3 Color = saturate((lerp(lerp(_FresnelColor.rgb,lerp(lerp(_WaterColor.rgb,(_WaterColor.rgb*(1.0 - _Depthdarkness)),depth),_RimColor.rgb,Intersection),(1.0 - (pow((1.0-max(0,dot(i.normalDir, viewDirection))),_Fresnelexponent)*_FresnelColor.a))),float3(1,1,1),SurfaceHighlights)-(HeightmapTex.g*_Wavetint)));
  223. float3 diffuseColor = Color; // Need this for specular when using metallic
  224. diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );
  225. specularMonochrome = 1.0-specularMonochrome;
  226. float NdotV = max(0.0,dot( normalDirection, viewDirection ));
  227. float NdotH = max(0.0,dot( normalDirection, halfDirection ));
  228. float VdotH = max(0.0,dot( viewDirection, halfDirection ));
  229. float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, 1.0-gloss );
  230. float normTerm = max(0.0, GGXTerm(NdotH, 1.0-gloss));
  231. float specularPBL = (NdotL*visTerm*normTerm) * (UNITY_PI / 4);
  232. if (IsGammaSpace())
  233. specularPBL = sqrt(max(1e-4h, specularPBL));
  234. specularPBL = max(0, specularPBL * NdotL);
  235. float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
  236. float3 specular = directSpecular;
  237. /////// Diffuse:
  238. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  239. half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
  240. float nlPow5 = Pow5(1-NdotL);
  241. float nvPow5 = Pow5(1-NdotV);
  242. float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;
  243. float3 indirectDiffuse = float3(0,0,0);
  244. indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb; // Ambient Light
  245. float3 Reflection = saturate((_Glossiness*texCUBE(_Reflection,viewReflectDirection).rgb));
  246. indirectDiffuse += Reflection; // Diffuse Ambient Light
  247. float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
  248. /// Final Color:
  249. float3 finalColor = diffuse + specular;
  250. float node_8832 = Intersection;
  251. float Opacity = saturate(( (_Transparency+node_8832) > 0.5 ? (1.0-(1.0-2.0*((_Transparency+node_8832)-0.5))*(1.0-depth)) : (2.0*(_Transparency+node_8832)*depth) ));
  252. fixed4 finalRGBA = fixed4(lerp(sceneColor.rgb, finalColor,Opacity),1);
  253. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  254. return finalRGBA;
  255. }
  256. ENDCG
  257. }
  258. Pass {
  259. Name "FORWARD_DELTA"
  260. Tags {
  261. "LightMode"="ForwardAdd"
  262. }
  263. Blend One One
  264. ZWrite Off
  265.  
  266. CGPROGRAM
  267. #pragma vertex vert
  268. #pragma fragment frag
  269. #define UNITY_PASS_FORWARDADD
  270. #include "UnityCG.cginc"
  271. #include "AutoLight.cginc"
  272. #include "UnityPBSLighting.cginc"
  273. #include "UnityStandardBRDF.cginc"
  274. #pragma multi_compile_fwdadd
  275. #pragma multi_compile_fog
  276. #pragma exclude_renderers d3d11_9x xbox360 ps3 psp2
  277. #pragma target 3.0
  278. #pragma glsl
  279. uniform sampler2D _GrabTexture;
  280. uniform sampler2D _CameraDepthTexture;
  281. uniform float4 _TimeEditor;
  282. uniform fixed _RimSize;
  283. uniform fixed4 _WaterColor;
  284. uniform fixed4 _RimColor;
  285. uniform sampler2D _Shadermap;
  286. uniform fixed _Tiling;
  287. uniform float _RefractionAmount;
  288. uniform float _Transparency;
  289. uniform sampler2D _Normals;
  290. uniform fixed _Wavesspeed;
  291. uniform float _Glossiness;
  292. uniform float _Wavesstrength;
  293. uniform fixed _Depth;
  294. uniform fixed _Depthdarkness;
  295. uniform fixed _Rimtiling;
  296. uniform fixed _Worldspacetiling;
  297. uniform fixed _Rimfalloff;
  298. uniform float _SurfaceHighlight;
  299. uniform float _Surfacehightlightsize;
  300. uniform float _SurfaceHightlighttiling;
  301. uniform float _Fresnelexponent;
  302. uniform float4 _FresnelColor;
  303. uniform float _RimDistance;
  304. uniform fixed _HighlightPanning;
  305. uniform float _Wavetint;
  306. uniform float _WaveSize;
  307. uniform float _NormalStrength;
  308. uniform float _UseIntersectionHighlight;
  309. struct VertexInput {
  310. float4 vertex : POSITION;
  311. float3 normal : NORMAL;
  312. float4 tangent : TANGENT;
  313. float2 texcoord0 : TEXCOORD0;
  314. };
  315. struct VertexOutput {
  316. float4 pos : SV_POSITION;
  317. float2 uv0 : TEXCOORD0;
  318. float4 posWorld : TEXCOORD1;
  319. float3 normalDir : TEXCOORD2;
  320. float3 tangentDir : TEXCOORD3;
  321. float3 bitangentDir : TEXCOORD4;
  322. float4 screenPos : TEXCOORD5;
  323. float4 projPos : TEXCOORD6;
  324. LIGHTING_COORDS(7,8)
  325. UNITY_FOG_COORDS(9)
  326. };
  327. VertexOutput vert (VertexInput v) {
  328. VertexOutput o = (VertexOutput)0;
  329. o.uv0 = v.texcoord0;
  330. o.normalDir = UnityObjectToWorldNormal(v.normal);
  331. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  332. o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  333. float4 Time = _Time + _TimeEditor;
  334. float WaveSpeed = (Time.g*(_Wavesspeed*0.1));
  335. fixed2 Tiling = (lerp( ((-20.0)*o.uv0), mul(unity_ObjectToWorld, v.vertex).rgb.rb, _Worldspacetiling )*(1.0 - _Tiling));
  336. float2 node_5626 = ((Tiling*_WaveSize)+(WaveSpeed*0.5)*float2(0,1));
  337. float4 HeightmapTex = tex2Dlod(_Shadermap,float4(node_5626,0.0,0));
  338. float DisplacementDirection = (HeightmapTex.g*_Wavesstrength);
  339. float3 Displacement = (v.normal*DisplacementDirection);
  340. float3 node_933 = Displacement;
  341. v.vertex.xyz += node_933;
  342. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  343. float3 lightColor = _LightColor0.rgb;
  344. o.pos = UnityObjectToClipPos(v.vertex );
  345. UNITY_TRANSFER_FOG(o,o.pos);
  346. o.projPos = ComputeScreenPos (o.pos);
  347. COMPUTE_EYEDEPTH(o.projPos.z);
  348. o.screenPos = o.pos;
  349. TRANSFER_VERTEX_TO_FRAGMENT(o)
  350. return o;
  351. }
  352. float4 frag(VertexOutput i) : COLOR {
  353. #if UNITY_UV_STARTS_AT_TOP
  354. float grabSign = -_ProjectionParams.x;
  355. #else
  356. float grabSign = _ProjectionParams.x;
  357. #endif
  358. i.normalDir = normalize(i.normalDir);
  359. i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
  360. i.screenPos.y *= _ProjectionParams.x;
  361. float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
  362. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  363. float4 Time = _Time + _TimeEditor;
  364. float WaveSpeed = (Time.g*(_Wavesspeed*0.1));
  365. fixed mWaveSpeed = WaveSpeed;
  366. fixed2 Tiling = (lerp( ((-20.0)*i.uv0), i.posWorld.rgb.rb, _Worldspacetiling )*(1.0 - _Tiling));
  367. fixed2 mTiling = Tiling;
  368. fixed2 WavePanningV = (mTiling+mWaveSpeed*float2(0,1));
  369. fixed3 WavePanningV_Tex = UnpackNormal(tex2D(_Normals,WavePanningV));
  370. fixed2 WavePanningU = (mTiling+mWaveSpeed*float2(0.1,0));
  371. fixed3 WavePanningU_Tex = UnpackNormal(tex2D(_Normals,WavePanningU));
  372. float3 WaveNormalBlend_nrm_base = WavePanningV_Tex.rgb + float3(0,0,1);
  373. float3 WaveNormalBlend_nrm_detail = WavePanningU_Tex.rgb * float3(-1,-1,1);
  374. float3 WaveNormalBlend_nrm_combined = WaveNormalBlend_nrm_base*dot(WaveNormalBlend_nrm_base, WaveNormalBlend_nrm_detail)/WaveNormalBlend_nrm_base.z - WaveNormalBlend_nrm_detail;
  375. float3 WaveNormalBlend = WaveNormalBlend_nrm_combined;
  376. float2 HighlightPanningV = (WavePanningV*_SurfaceHightlighttiling);
  377. float4 HighlightPanningV_Tex = tex2D(_Shadermap,HighlightPanningV);
  378. float node_8200 = lerp(HighlightPanningV_Tex.r,HighlightPanningV_Tex.b,_UseIntersectionHighlight);
  379. float2 HightlightPanningU = (WavePanningU*_SurfaceHightlighttiling);
  380. float4 HightlightPanningU_Tex = tex2D(_Shadermap,HightlightPanningU);
  381. float node_5823 = lerp(HightlightPanningU_Tex.r,HightlightPanningU_Tex.b,_UseIntersectionHighlight);
  382. float SurfaceHighlights = saturate((_SurfaceHighlight*lerp(step(_Surfacehightlightsize,(node_8200-node_5823)),(1.0 - lerp( node_5823, (node_8200*node_5823), _HighlightPanning )),_UseIntersectionHighlight)));
  383. float3 Normals = lerp(i.normalDir,lerp(WaveNormalBlend,float3(0,0,1),SurfaceHighlights),_NormalStrength);
  384. float3 normalLocal = Normals;
  385. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  386. float sceneZ = max(0,LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)))) - _ProjectionParams.g);
  387. float partZ = max(0,i.projPos.z - _ProjectionParams.g);
  388. float2 Refraction = (_RefractionAmount*float2(WavePanningV_Tex.r,WavePanningU_Tex.g));
  389. float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + Refraction;
  390. float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
  391. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
  392. float3 lightColor = _LightColor0.rgb;
  393. float3 halfDirection = normalize(viewDirection+lightDirection);
  394. ////// Lighting:
  395. float attenuation = LIGHT_ATTENUATION(i);
  396. float3 attenColor = attenuation * _LightColor0.xyz;
  397. float Pi = 3.141592654;
  398. float InvPi = 0.31830988618;
  399. ///////// Gloss:
  400. float Roughness = (saturate((1.0-(1.0-WavePanningV_Tex.r)*(1.0-WavePanningU_Tex.g)))*_Glossiness);
  401. float gloss = 1.0 - Roughness; // Convert roughness to gloss
  402. float specPow = exp2( gloss * 10.0+1.0);
  403. ////// Specular:
  404. float NdotL = max(0, dot( normalDirection, lightDirection ));
  405. float LdotH = max(0.0,dot(lightDirection, halfDirection));
  406. float3 specularColor = 0.0;
  407. float specularMonochrome;
  408. float depth = saturate((sceneZ-partZ)/_Depth);
  409. float RimAllphaMultiply = ((saturate((sceneZ-partZ)/_RimDistance)-pow(saturate((sceneZ-partZ)/_RimSize),_Rimfalloff))*_RimColor.a); // Control rim opacity with color alpha
  410. float node_2352 = WaveSpeed;
  411. fixed2 rimTiling = (Tiling*_Rimtiling);
  412. fixed2 rimPanningU = (rimTiling+node_2352*float2(0.5,0.1));
  413. float4 rimU_Tex = tex2D(_Shadermap,rimPanningU);
  414. fixed2 rimPanningV = (rimTiling+node_2352*float2(0,1));
  415. float4 rimV_Tex = tex2D(_Shadermap,rimPanningV);
  416. float Intersection = saturate((RimAllphaMultiply+(RimAllphaMultiply*(1.0 - (rimU_Tex.b*rimV_Tex.b))*_RimColor.a)));
  417. float2 node_5626 = ((Tiling*_WaveSize)+(WaveSpeed*0.5)*float2(0,1));
  418. float4 HeightmapTex = tex2D(_Shadermap,node_5626);
  419. float3 Color = saturate((lerp(lerp(_FresnelColor.rgb,lerp(lerp(_WaterColor.rgb,(_WaterColor.rgb*(1.0 - _Depthdarkness)),depth),_RimColor.rgb,Intersection),(1.0 - (pow((1.0-max(0,dot(i.normalDir, viewDirection))),_Fresnelexponent)*_FresnelColor.a))),float3(1,1,1),SurfaceHighlights)-(HeightmapTex.g*_Wavetint)));
  420. float3 diffuseColor = Color; // Need this for specular when using metallic
  421. diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome );
  422. specularMonochrome = 1.0-specularMonochrome;
  423. float NdotV = max(0.0,dot( normalDirection, viewDirection ));
  424. float NdotH = max(0.0,dot( normalDirection, halfDirection ));
  425. float VdotH = max(0.0,dot( viewDirection, halfDirection ));
  426. float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, 1.0-gloss );
  427. float normTerm = max(0.0, GGXTerm(NdotH, 1.0-gloss));
  428. float specularPBL = (NdotL*visTerm*normTerm) * (UNITY_PI / 4);
  429. if (IsGammaSpace())
  430. specularPBL = sqrt(max(1e-4h, specularPBL));
  431. specularPBL = max(0, specularPBL * NdotL);
  432. float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
  433. float3 specular = directSpecular;
  434. /////// Diffuse:
  435. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  436. half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
  437. float nlPow5 = Pow5(1-NdotL);
  438. float nvPow5 = Pow5(1-NdotV);
  439. float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor;
  440. float3 diffuse = directDiffuse * diffuseColor;
  441. /// Final Color:
  442. float3 finalColor = diffuse + specular;
  443. float node_8832 = Intersection;
  444. float Opacity = saturate(( (_Transparency+node_8832) > 0.5 ? (1.0-(1.0-2.0*((_Transparency+node_8832)-0.5))*(1.0-depth)) : (2.0*(_Transparency+node_8832)*depth) ));
  445. fixed4 finalRGBA = fixed4(finalColor * Opacity,0);
  446. UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
  447. return finalRGBA;
  448. }
  449. ENDCG
  450. }
  451. }
  452. FallBack "Unlit/Transparent"
  453. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement