// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' // Shader created with Shader Forge v1.05 // Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/ // Note: Manually altering this data may prevent you from opening it in Shader Forge /*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;*/ Shader "FT/Distortion" { Properties { _Texture ("Texture", 2D) = "bump" {} _Mask ("Mask", 2D) = "white" {} _Distortion_Strength ("Distortion_Strength", Range(0, 0.1)) = 0 [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { Tags { "IgnoreProjector"="True" "Queue"="Overlay" "RenderType"="Transparent" } GrabPass{ } Pass { Name "ForwardBase" Tags { "LightMode"="ForwardBase" } Cull Off ZWrite Off CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_FORWARDBASE #include "UnityCG.cginc" #pragma multi_compile_fwdbase #pragma exclude_renderers xbox360 ps3 flash d3d11_9x #pragma target 3.0 uniform float4 _LightColor0; uniform sampler2D _GrabTexture; uniform float4 _TimeEditor; uniform sampler2D _Texture; uniform float4 _Texture_ST; uniform float _Distortion_Strength; uniform sampler2D _Mask; uniform float4 _Mask_ST; struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float4 tangent : TANGENT; float2 texcoord0 : TEXCOORD0; }; struct VertexOutput { float4 pos : SV_POSITION; float2 uv0 : TEXCOORD0; float4 posWorld : TEXCOORD1; float3 normalDir : TEXCOORD2; float3 tangentDir : TEXCOORD3; float3 binormalDir : TEXCOORD4; float4 screenPos : TEXCOORD5; }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.uv0 = v.texcoord0; o.normalDir = mul(unity_ObjectToWorld, float4(v.normal,0)).xyz; o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz ); o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w); o.posWorld = mul(unity_ObjectToWorld, v.vertex); float3 lightColor = _LightColor0.rgb; o.pos = UnityObjectToClipPos(v.vertex); o.screenPos = o.pos; return o; } fixed4 frag(VertexOutput i) : COLOR { #if UNITY_UV_STARTS_AT_TOP float grabSign = -_ProjectionParams.x; #else float grabSign = _ProjectionParams.x; #endif i.normalDir = normalize(i.normalDir); i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 ); i.screenPos.y *= _ProjectionParams.x; float node_8736 = 0.0; float4 node_2569 = _Time + _TimeEditor; float2 node_7100 = (i.uv0+node_2569.g*float2(-6,-10)); float3 _Texture_var = UnpackNormal(tex2D(_Texture,TRANSFORM_TEX(node_7100, _Texture))); float4 _Mask_var = tex2D(_Mask,TRANSFORM_TEX(i.uv0, _Mask)); 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); float4 sceneColor = tex2D(_GrabTexture, sceneUVs); float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir); /////// Vectors: float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float3 normalLocal = _Texture_var.rgb; float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface i.normalDir *= nSign; normalDirection *= nSign; float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz); float3 lightColor = _LightColor0.rgb; float3 halfDirection = normalize(viewDirection+lightDirection); ////// Lighting: float attenuation = 1; float3 attenColor = attenuation * _LightColor0.xyz; ///////// Gloss: float gloss = 0.8; float specPow = exp2( gloss * 10.0+1.0); ////// Specular: float NdotL = max(0, dot( normalDirection, lightDirection )); float node_3636 = 6.0; float3 specularColor = float3(node_3636,node_3636,node_3636); float3 directSpecular = (floor(attenuation) * _LightColor0.xyz) * pow(max(0,dot(halfDirection,normalDirection)),specPow); float3 specular = directSpecular * specularColor; /////// Diffuse: NdotL = dot( normalDirection, lightDirection ); float node_4222 = 1.0; float3 w = float3(node_4222,node_4222,node_4222)*0.5; // Light wrapping float3 NdotLWrap = NdotL * ( 1.0 - w ); float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w ); float3 backLight = max(float3(0.0,0.0,0.0), -NdotLWrap + w ) * float3(node_4222,node_4222,node_4222); float3 indirectDiffuse = float3(0,0,0); float3 directDiffuse = (forwardLight+backLight) * attenColor; indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb; // Ambient Light float node_5316 = (1.0-max(0,dot(normalDirection, viewDirection))); float3 diffuse = (directDiffuse + indirectDiffuse) * float3(node_5316,node_5316,node_5316); /// Final Color: float3 finalColor = diffuse + specular; return fixed4(lerp(sceneColor.rgb, finalColor,0.0),1); } ENDCG } Pass { Name "ForwardAdd" Tags { "LightMode"="ForwardAdd" } Blend One One Cull Off ZWrite Off Fog { Color (0,0,0,0) } CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_FORWARDADD #include "UnityCG.cginc" #include "AutoLight.cginc" #pragma multi_compile_fwdadd #pragma exclude_renderers xbox360 ps3 flash d3d11_9x #pragma target 3.0 uniform float4 _LightColor0; uniform sampler2D _GrabTexture; uniform float4 _TimeEditor; uniform sampler2D _Texture; uniform float4 _Texture_ST; uniform float _Distortion_Strength; uniform sampler2D _Mask; uniform float4 _Mask_ST; struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float4 tangent : TANGENT; float2 texcoord0 : TEXCOORD0; }; struct VertexOutput { float4 pos : SV_POSITION; float2 uv0 : TEXCOORD0; float4 posWorld : TEXCOORD1; float3 normalDir : TEXCOORD2; float3 tangentDir : TEXCOORD3; float3 binormalDir : TEXCOORD4; float4 screenPos : TEXCOORD5; LIGHTING_COORDS(6,7) }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.uv0 = v.texcoord0; o.normalDir = mul(unity_ObjectToWorld, float4(v.normal,0)).xyz; o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz ); o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w); o.posWorld = mul(unity_ObjectToWorld, v.vertex); float3 lightColor = _LightColor0.rgb; o.pos = UnityObjectToClipPos(v.vertex); o.screenPos = o.pos; TRANSFER_VERTEX_TO_FRAGMENT(o) return o; } fixed4 frag(VertexOutput i) : COLOR { #if UNITY_UV_STARTS_AT_TOP float grabSign = -_ProjectionParams.x; #else float grabSign = _ProjectionParams.x; #endif i.normalDir = normalize(i.normalDir); i.screenPos = float4( i.screenPos.xy / i.screenPos.w, 0, 0 ); i.screenPos.y *= _ProjectionParams.x; float node_8736 = 0.0; float4 node_472 = _Time + _TimeEditor; float2 node_7100 = (i.uv0+node_472.g*float2(-6,-10)); float3 _Texture_var = UnpackNormal(tex2D(_Texture,TRANSFORM_TEX(node_7100, _Texture))); float4 _Mask_var = tex2D(_Mask,TRANSFORM_TEX(i.uv0, _Mask)); 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); float4 sceneColor = tex2D(_GrabTexture, sceneUVs); float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir); /////// Vectors: float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float3 normalLocal = _Texture_var.rgb; float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface i.normalDir *= nSign; normalDirection *= nSign; float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w)); float3 lightColor = _LightColor0.rgb; float3 halfDirection = normalize(viewDirection+lightDirection); ////// Lighting: float attenuation = LIGHT_ATTENUATION(i); float3 attenColor = attenuation * _LightColor0.xyz; ///////// Gloss: float gloss = 0.8; float specPow = exp2( gloss * 10.0+1.0); ////// Specular: float NdotL = max(0, dot( normalDirection, lightDirection )); float node_3636 = 6.0; float3 specularColor = float3(node_3636,node_3636,node_3636); float3 directSpecular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow); float3 specular = directSpecular * specularColor; /////// Diffuse: NdotL = dot( normalDirection, lightDirection ); float node_4222 = 1.0; float3 w = float3(node_4222,node_4222,node_4222)*0.5; // Light wrapping float3 NdotLWrap = NdotL * ( 1.0 - w ); float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w ); float3 backLight = max(float3(0.0,0.0,0.0), -NdotLWrap + w ) * float3(node_4222,node_4222,node_4222); float3 directDiffuse = (forwardLight+backLight) * attenColor; float node_5316 = (1.0-max(0,dot(normalDirection, viewDirection))); float3 diffuse = directDiffuse * float3(node_5316,node_5316,node_5316); /// Final Color: float3 finalColor = diffuse + specular; return fixed4(finalColor * 0.0,0); } ENDCG } } FallBack "Diffuse" CustomEditor "ShaderForgeMaterialInspector" }