FT_Distortion.shader 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. // Shader created with Shader Forge v1.05
  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.05;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:1,uamb:True,mssp:True,lmpd:False,lprd:False,rprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,tesm:0,blpr:0,bsrc:0,bdst:1,culm:2,dpts:2,wrdp:False,dith:2,ufog:True,aust:False,igpj:True,qofs:0,qpre:4,rntp:2,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,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:2397,x:33022,y:32711,varname:node_2397,prsc:2|diff-5316-OUT,spec-3636-OUT,gloss-6641-OUT,normal-7213-RGB,transm-4222-OUT,lwrap-4222-OUT,alpha-2748-OUT,refract-8574-OUT;n:type:ShaderForge.SFN_ComponentMask,id:91,x:32284,y:32977,varname:node_91,prsc:2,cc1:0,cc2:1,cc3:-1,cc4:-1|IN-7213-RGB;n:type:ShaderForge.SFN_Multiply,id:9028,x:32511,y:32997,varname:node_9028,prsc:2|A-91-OUT,B-6398-OUT;n:type:ShaderForge.SFN_Fresnel,id:5316,x:32265,y:32629,varname:node_5316,prsc:2;n:type:ShaderForge.SFN_Vector1,id:4222,x:32265,y:32841,varname:node_4222,prsc:2,v1:1;n:type:ShaderForge.SFN_Tex2d,id:7213,x:32101,y:32927,ptovrint:False,ptlb:Texture,ptin:_Texture,varname:node_7213,prsc:2,ntxv:3,isnm:True|UVIN-7100-UVOUT;n:type:ShaderForge.SFN_Vector1,id:3636,x:32458,y:32734,varname:node_3636,prsc:2,v1:6;n:type:ShaderForge.SFN_Vector1,id:6641,x:32413,y:32788,varname:node_6641,prsc:2,v1:0.8;n:type:ShaderForge.SFN_Panner,id:7100,x:31850,y:32927,varname:node_7100,prsc:2,spu:-6,spv:-10;n:type:ShaderForge.SFN_Slider,id:6398,x:31981,y:33183,ptovrint:False,ptlb:Distortion_Strength,ptin:_Distortion_Strength,varname:node_6398,prsc:2,min:0,cur:0,max:0.1;n:type:ShaderForge.SFN_Tex2d,id:3875,x:32534,y:33148,ptovrint:False,ptlb:Mask,ptin:_Mask,varname:node_3875,prsc:2,tex:5881beee1f3bab347b0a3302e6dddd17,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Vector1,id:2748,x:32779,y:33220,varname:node_2748,prsc:2,v1:0;n:type:ShaderForge.SFN_Lerp,id:8574,x:32734,y:33044,varname:node_8574,prsc:2|A-8736-OUT,B-9028-OUT,T-3875-R;n:type:ShaderForge.SFN_Vector1,id:8736,x:32643,y:32958,varname:node_8736,prsc:2,v1:0;proporder:7213-3875-6398;pass:END;sub:END;*/
  7. Shader "FT/Distortion" {
  8. Properties {
  9. _Texture ("Texture", 2D) = "bump" {}
  10. _Mask ("Mask", 2D) = "white" {}
  11. _Distortion_Strength ("Distortion_Strength", Range(0, 0.1)) = 0
  12. [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  13. }
  14. SubShader {
  15. Tags {
  16. "IgnoreProjector"="True"
  17. "Queue"="Overlay"
  18. "RenderType"="Transparent"
  19. }
  20. GrabPass{ }
  21. Pass {
  22. Name "ForwardBase"
  23. Tags {
  24. "LightMode"="ForwardBase"
  25. }
  26. Cull Off
  27. ZWrite Off
  28. CGPROGRAM
  29. #pragma vertex vert
  30. #pragma fragment frag
  31. #define UNITY_PASS_FORWARDBASE
  32. #include "UnityCG.cginc"
  33. #pragma multi_compile_fwdbase
  34. #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
  35. #pragma target 3.0
  36. uniform float4 _LightColor0;
  37. uniform sampler2D _GrabTexture;
  38. uniform float4 _TimeEditor;
  39. uniform sampler2D _Texture; uniform float4 _Texture_ST;
  40. uniform float _Distortion_Strength;
  41. uniform sampler2D _Mask; uniform float4 _Mask_ST;
  42. struct VertexInput {
  43. float4 vertex : POSITION;
  44. float3 normal : NORMAL;
  45. float4 tangent : TANGENT;
  46. float2 texcoord0 : TEXCOORD0;
  47. };
  48. struct VertexOutput {
  49. float4 pos : SV_POSITION;
  50. float2 uv0 : TEXCOORD0;
  51. float4 posWorld : TEXCOORD1;
  52. float3 normalDir : TEXCOORD2;
  53. float3 tangentDir : TEXCOORD3;
  54. float3 binormalDir : TEXCOORD4;
  55. float4 screenPos : TEXCOORD5;
  56. };
  57. VertexOutput vert (VertexInput v) {
  58. VertexOutput o = (VertexOutput)0;
  59. o.uv0 = v.texcoord0;
  60. o.normalDir = mul(unity_ObjectToWorld, float4(v.normal,0)).xyz;
  61. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  62. o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  63. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  64. float3 lightColor = _LightColor0.rgb;
  65. o.pos = UnityObjectToClipPos(v.vertex);
  66. o.screenPos = o.pos;
  67. return o;
  68. }
  69. fixed4 frag(VertexOutput i) : COLOR {
  70. #if UNITY_UV_STARTS_AT_TOP
  71. float grabSign = -_ProjectionParams.x;
  72. #else
  73. float grabSign = _ProjectionParams.x;
  74. #endif
  75. i.normalDir = normalize(i.normalDir);
  76. i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
  77. i.screenPos.y *= _ProjectionParams.x;
  78. float node_8736 = 0.0;
  79. float4 node_2569 = _Time + _TimeEditor;
  80. float2 node_7100 = (i.uv0+node_2569.g*float2(-6,-10));
  81. float3 _Texture_var = UnpackNormal(tex2D(_Texture,TRANSFORM_TEX(node_7100, _Texture)));
  82. float4 _Mask_var = tex2D(_Mask,TRANSFORM_TEX(i.uv0, _Mask));
  83. float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + lerp(float2(node_8736,node_8736),(_Texture_var.rgb.rg*_Distortion_Strength),_Mask_var.r);
  84. float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
  85. float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
  86. /////// Vectors:
  87. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  88. float3 normalLocal = _Texture_var.rgb;
  89. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  90. float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface
  91. i.normalDir *= nSign;
  92. normalDirection *= nSign;
  93. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  94. float3 lightColor = _LightColor0.rgb;
  95. float3 halfDirection = normalize(viewDirection+lightDirection);
  96. ////// Lighting:
  97. float attenuation = 1;
  98. float3 attenColor = attenuation * _LightColor0.xyz;
  99. ///////// Gloss:
  100. float gloss = 0.8;
  101. float specPow = exp2( gloss * 10.0+1.0);
  102. ////// Specular:
  103. float NdotL = max(0, dot( normalDirection, lightDirection ));
  104. float node_3636 = 6.0;
  105. float3 specularColor = float3(node_3636,node_3636,node_3636);
  106. float3 directSpecular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(halfDirection,normalDirection)),specPow);
  107. float3 specular = directSpecular * specularColor;
  108. /////// Diffuse:
  109. NdotL = dot( normalDirection, lightDirection );
  110. float node_4222 = 1.0;
  111. float3 w = float3(node_4222,node_4222,node_4222)*0.5; // Light wrapping
  112. float3 NdotLWrap = NdotL * ( 1.0 - w );
  113. float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w );
  114. float3 backLight = max(float3(0.0,0.0,0.0), -NdotLWrap + w ) * float3(node_4222,node_4222,node_4222);
  115. float3 indirectDiffuse = float3(0,0,0);
  116. float3 directDiffuse = (forwardLight+backLight) * attenColor;
  117. indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb; // Ambient Light
  118. float node_5316 = (1.0-max(0,dot(normalDirection, viewDirection)));
  119. float3 diffuse = (directDiffuse + indirectDiffuse) * float3(node_5316,node_5316,node_5316);
  120. /// Final Color:
  121. float3 finalColor = diffuse + specular;
  122. return fixed4(lerp(sceneColor.rgb, finalColor,0.0),1);
  123. }
  124. ENDCG
  125. }
  126. Pass {
  127. Name "ForwardAdd"
  128. Tags {
  129. "LightMode"="ForwardAdd"
  130. }
  131. Blend One One
  132. Cull Off
  133. ZWrite Off
  134. Fog { Color (0,0,0,0) }
  135. CGPROGRAM
  136. #pragma vertex vert
  137. #pragma fragment frag
  138. #define UNITY_PASS_FORWARDADD
  139. #include "UnityCG.cginc"
  140. #include "AutoLight.cginc"
  141. #pragma multi_compile_fwdadd
  142. #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
  143. #pragma target 3.0
  144. uniform float4 _LightColor0;
  145. uniform sampler2D _GrabTexture;
  146. uniform float4 _TimeEditor;
  147. uniform sampler2D _Texture; uniform float4 _Texture_ST;
  148. uniform float _Distortion_Strength;
  149. uniform sampler2D _Mask; uniform float4 _Mask_ST;
  150. struct VertexInput {
  151. float4 vertex : POSITION;
  152. float3 normal : NORMAL;
  153. float4 tangent : TANGENT;
  154. float2 texcoord0 : TEXCOORD0;
  155. };
  156. struct VertexOutput {
  157. float4 pos : SV_POSITION;
  158. float2 uv0 : TEXCOORD0;
  159. float4 posWorld : TEXCOORD1;
  160. float3 normalDir : TEXCOORD2;
  161. float3 tangentDir : TEXCOORD3;
  162. float3 binormalDir : TEXCOORD4;
  163. float4 screenPos : TEXCOORD5;
  164. LIGHTING_COORDS(6,7)
  165. };
  166. VertexOutput vert (VertexInput v) {
  167. VertexOutput o = (VertexOutput)0;
  168. o.uv0 = v.texcoord0;
  169. o.normalDir = mul(unity_ObjectToWorld, float4(v.normal,0)).xyz;
  170. o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
  171. o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
  172. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  173. float3 lightColor = _LightColor0.rgb;
  174. o.pos = UnityObjectToClipPos(v.vertex);
  175. o.screenPos = o.pos;
  176. TRANSFER_VERTEX_TO_FRAGMENT(o)
  177. return o;
  178. }
  179. fixed4 frag(VertexOutput i) : COLOR {
  180. #if UNITY_UV_STARTS_AT_TOP
  181. float grabSign = -_ProjectionParams.x;
  182. #else
  183. float grabSign = _ProjectionParams.x;
  184. #endif
  185. i.normalDir = normalize(i.normalDir);
  186. i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 );
  187. i.screenPos.y *= _ProjectionParams.x;
  188. float node_8736 = 0.0;
  189. float4 node_472 = _Time + _TimeEditor;
  190. float2 node_7100 = (i.uv0+node_472.g*float2(-6,-10));
  191. float3 _Texture_var = UnpackNormal(tex2D(_Texture,TRANSFORM_TEX(node_7100, _Texture)));
  192. float4 _Mask_var = tex2D(_Mask,TRANSFORM_TEX(i.uv0, _Mask));
  193. float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + lerp(float2(node_8736,node_8736),(_Texture_var.rgb.rg*_Distortion_Strength),_Mask_var.r);
  194. float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
  195. float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
  196. /////// Vectors:
  197. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  198. float3 normalLocal = _Texture_var.rgb;
  199. float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
  200. float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface
  201. i.normalDir *= nSign;
  202. normalDirection *= nSign;
  203. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
  204. float3 lightColor = _LightColor0.rgb;
  205. float3 halfDirection = normalize(viewDirection+lightDirection);
  206. ////// Lighting:
  207. float attenuation = LIGHT_ATTENUATION(i);
  208. float3 attenColor = attenuation * _LightColor0.xyz;
  209. ///////// Gloss:
  210. float gloss = 0.8;
  211. float specPow = exp2( gloss * 10.0+1.0);
  212. ////// Specular:
  213. float NdotL = max(0, dot( normalDirection, lightDirection ));
  214. float node_3636 = 6.0;
  215. float3 specularColor = float3(node_3636,node_3636,node_3636);
  216. float3 directSpecular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow);
  217. float3 specular = directSpecular * specularColor;
  218. /////// Diffuse:
  219. NdotL = dot( normalDirection, lightDirection );
  220. float node_4222 = 1.0;
  221. float3 w = float3(node_4222,node_4222,node_4222)*0.5; // Light wrapping
  222. float3 NdotLWrap = NdotL * ( 1.0 - w );
  223. float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w );
  224. float3 backLight = max(float3(0.0,0.0,0.0), -NdotLWrap + w ) * float3(node_4222,node_4222,node_4222);
  225. float3 directDiffuse = (forwardLight+backLight) * attenColor;
  226. float node_5316 = (1.0-max(0,dot(normalDirection, viewDirection)));
  227. float3 diffuse = directDiffuse * float3(node_5316,node_5316,node_5316);
  228. /// Final Color:
  229. float3 finalColor = diffuse + specular;
  230. return fixed4(finalColor * 0.0,0);
  231. }
  232. ENDCG
  233. }
  234. }
  235. FallBack "Diffuse"
  236. CustomEditor "ShaderForgeMaterialInspector"
  237. }