// Shader created with Shader Forge Beta 0.36 
// Shader Forge (c) Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:0.36;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:1,uamb:True,mssp:True,lmpd:False,lprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,rpth:0,hqsc:True,hqlp:False,tesm:0,blpr:1,bsrc:3,bdst:7,culm:0,dpts:2,wrdp:False,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,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:1,x:32520,y:32699|diff-153-OUT,normal-88-OUT,alpha-291-OUT,refract-86-OUT,olcol-273-RGB,voffset-86-OUT;n:type:ShaderForge.SFN_Fresnel,id:2,x:33662,y:32591|EXP-12-OUT;n:type:ShaderForge.SFN_Slider,id:12,x:33662,y:32509,ptlb:Fresnel Exponent,ptin:_FresnelExponent,min:0,cur:5,max:5;n:type:ShaderForge.SFN_Color,id:14,x:33662,y:32339,ptlb:Diffuse Color,ptin:_DiffuseColor,glob:False,c1:0.5294118,c2:0.5294118,c3:0.5294118,c4:1;n:type:ShaderForge.SFN_Multiply,id:15,x:33409,y:32546|A-14-RGB,B-2-OUT,C-12-OUT;n:type:ShaderForge.SFN_Desaturate,id:16,x:33233,y:32546|COL-15-OUT;n:type:ShaderForge.SFN_Tex2d,id:39,x:33278,y:33016,ptlb:Normal,ptin:_Normal,tex:a494016e3a3d2f84b806b5cfc7e5ce1a,ntxv:3,isnm:True|UVIN-106-UVOUT;n:type:ShaderForge.SFN_ComponentMask,id:40,x:33073,y:33039,cc1:0,cc2:1,cc3:-1,cc4:-1|IN-39-RGB;n:type:ShaderForge.SFN_Vector1,id:52,x:32878,y:33004,v1:0.1;n:type:ShaderForge.SFN_Slider,id:84,x:33278,y:33211,ptlb:Refraction Intensity,ptin:_RefractionIntensity,min:0,cur:1,max:1;n:type:ShaderForge.SFN_Multiply,id:85,x:33073,y:33196|A-84-OUT,B-87-OUT;n:type:ShaderForge.SFN_Multiply,id:86,x:32878,y:33064|A-40-OUT,B-85-OUT;n:type:ShaderForge.SFN_Vector1,id:87,x:33278,y:33302,v1:0.2;n:type:ShaderForge.SFN_Lerp,id:88,x:33073,y:32890|A-89-OUT,B-39-RGB,T-84-OUT;n:type:ShaderForge.SFN_Vector3,id:89,x:33278,y:32890,v1:0,v2:0,v3:1;n:type:ShaderForge.SFN_TexCoord,id:97,x:33897,y:32958,uv:0;n:type:ShaderForge.SFN_Vector1,id:98,x:33897,y:33124,v1:1;n:type:ShaderForge.SFN_Multiply,id:99,x:33662,y:33016|A-97-UVOUT,B-98-OUT;n:type:ShaderForge.SFN_Panner,id:106,x:33472,y:33016,spu:0.05,spv:0.05|UVIN-99-OUT;n:type:ShaderForge.SFN_Desaturate,id:152,x:33073,y:32771|COL-88-OUT;n:type:ShaderForge.SFN_Multiply,id:153,x:32878,y:32626|A-16-OUT,B-159-OUT;n:type:ShaderForge.SFN_OneMinus,id:159,x:33083,y:32636|IN-152-OUT;n:type:ShaderForge.SFN_Color,id:273,x:32886,y:33541,ptlb:Outline Color,ptin:_OutlineColor,glob:False,c1:0.5,c2:0.5,c3:0.5,c4:1;n:type:ShaderForge.SFN_Slider,id:291,x:32886,y:33317,ptlb:Alpha,ptin:_Alpha,min:0,cur:0,max:1;proporder:14-39-12-84-273-291;pass:END;sub:END;*/

Shader "Shader Forge/GhostWalls" {
    Properties {
        _DiffuseColor ("Diffuse Color", Color) = (0.5294118,0.5294118,0.5294118,1)
        _Normal ("Normal", 2D) = "bump" {}
        _FresnelExponent ("Fresnel Exponent", Range(0, 5)) = 5
        _RefractionIntensity ("Refraction Intensity", Range(0, 1)) = 1
        _OutlineColor ("Outline Color", Color) = (0.5,0.5,0.5,1)
        _Alpha ("Alpha", Range(0, 1)) = 0
        [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent"
        }
        GrabPass{ }
        Pass {
            Name "ForwardBase"
            Tags {
                "LightMode"="ForwardBase"
            }
            Blend SrcAlpha OneMinusSrcAlpha
            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
            #pragma glsl
            uniform float4 _LightColor0;
            uniform sampler2D _GrabTexture;
            uniform float4 _TimeEditor;
            uniform float _FresnelExponent;
            uniform float4 _DiffuseColor;
            uniform sampler2D _Normal; uniform float4 _Normal_ST;
            uniform float _RefractionIntensity;
            uniform float _Alpha;
            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;
                o.uv0 = v.texcoord0;
                o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
                o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
                o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
                float4 node_310 = _Time + _TimeEditor;
                float2 node_106 = ((o.uv0.rg*1.0)+node_310.g*float2(0.05,0.05));
                float3 node_39 = UnpackNormal(tex2Dlod(_Normal,float4(TRANSFORM_TEX(node_106, _Normal),0.0,0)));
                float2 node_86 = (node_39.rgb.rg*(_RefractionIntensity*0.2));
                v.vertex.xyz += float3(node_86,0.0);
                o.posWorld = mul(_Object2World, v.vertex);
                o.pos = mul(UNITY_MATRIX_MVP, 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;
                float4 node_310 = _Time + _TimeEditor;
                float2 node_106 = ((i.uv0.rg*1.0)+node_310.g*float2(0.05,0.05));
                float3 node_39 = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(node_106, _Normal)));
                float2 node_86 = (node_39.rgb.rg*(_RefractionIntensity*0.2));
                float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + node_86;
                float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
                float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
                float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
/////// Normals:
                float3 node_88 = lerp(float3(0,0,1),node_39.rgb,_RefractionIntensity);
                float3 normalLocal = node_88;
                float3 normalDirection =  normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
                float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
////// Lighting:
                float attenuation = 1;
                float3 attenColor = attenuation * _LightColor0.xyz;
/////// Diffuse:
                float NdotL = dot( normalDirection, lightDirection );
                float3 diffuse = max( 0.0, NdotL) * attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb;
                float3 finalColor = 0;
                float3 diffuseLight = diffuse;
                float node_153 = (dot((_DiffuseColor.rgb*pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelExponent)*_FresnelExponent),float3(0.3,0.59,0.11))*(1.0 - dot(node_88,float3(0.3,0.59,0.11))));
                finalColor += diffuseLight * float3(node_153,node_153,node_153);
/// Final Color:
                return fixed4(lerp(sceneColor.rgb, finalColor,_Alpha),1);
            }
            ENDCG
        }
        Pass {
            Name "ForwardAdd"
            Tags {
                "LightMode"="ForwardAdd"
            }
            Blend One One
            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
            #pragma glsl
            uniform float4 _LightColor0;
            uniform sampler2D _GrabTexture;
            uniform float4 _TimeEditor;
            uniform float _FresnelExponent;
            uniform float4 _DiffuseColor;
            uniform sampler2D _Normal; uniform float4 _Normal_ST;
            uniform float _RefractionIntensity;
            uniform float _Alpha;
            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;
                o.uv0 = v.texcoord0;
                o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
                o.tangentDir = normalize( mul( _Object2World, float4( v.tangent.xyz, 0.0 ) ).xyz );
                o.binormalDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
                float4 node_311 = _Time + _TimeEditor;
                float2 node_106 = ((o.uv0.rg*1.0)+node_311.g*float2(0.05,0.05));
                float3 node_39 = UnpackNormal(tex2Dlod(_Normal,float4(TRANSFORM_TEX(node_106, _Normal),0.0,0)));
                float2 node_86 = (node_39.rgb.rg*(_RefractionIntensity*0.2));
                v.vertex.xyz += float3(node_86,0.0);
                o.posWorld = mul(_Object2World, v.vertex);
                o.pos = mul(UNITY_MATRIX_MVP, 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;
                float4 node_311 = _Time + _TimeEditor;
                float2 node_106 = ((i.uv0.rg*1.0)+node_311.g*float2(0.05,0.05));
                float3 node_39 = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(node_106, _Normal)));
                float2 node_86 = (node_39.rgb.rg*(_RefractionIntensity*0.2));
                float2 sceneUVs = float2(1,grabSign)*i.screenPos.xy*0.5+0.5 + node_86;
                float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
                float3x3 tangentTransform = float3x3( i.tangentDir, i.binormalDir, i.normalDir);
                float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
/////// Normals:
                float3 node_88 = lerp(float3(0,0,1),node_39.rgb,_RefractionIntensity);
                float3 normalLocal = node_88;
                float3 normalDirection =  normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
                float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
////// Lighting:
                float attenuation = LIGHT_ATTENUATION(i);
                float3 attenColor = attenuation * _LightColor0.xyz;
/////// Diffuse:
                float NdotL = dot( normalDirection, lightDirection );
                float3 diffuse = max( 0.0, NdotL) * attenColor;
                float3 finalColor = 0;
                float3 diffuseLight = diffuse;
                float node_153 = (dot((_DiffuseColor.rgb*pow(1.0-max(0,dot(normalDirection, viewDirection)),_FresnelExponent)*_FresnelExponent),float3(0.3,0.59,0.11))*(1.0 - dot(node_88,float3(0.3,0.59,0.11))));
                finalColor += diffuseLight * float3(node_153,node_153,node_153);
/// Final Color:
                return fixed4(finalColor * _Alpha,0);
            }
            ENDCG
        }
        Pass {
            Name "ShadowCollector"
            Tags {
                "LightMode"="ShadowCollector"
            }
            
            Fog {Mode Off}
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_SHADOWCOLLECTOR
            #define SHADOW_COLLECTOR_PASS
            #include "UnityCG.cginc"
            #include "Lighting.cginc"
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma multi_compile_shadowcollector
            #pragma exclude_renderers xbox360 ps3 flash d3d11_9x 
            #pragma target 3.0
            #pragma glsl
            uniform float4 _TimeEditor;
            uniform sampler2D _Normal; uniform float4 _Normal_ST;
            uniform float _RefractionIntensity;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                V2F_SHADOW_COLLECTOR;
                float2 uv0 : TEXCOORD5;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o;
                o.uv0 = v.texcoord0;
                float4 node_312 = _Time + _TimeEditor;
                float2 node_106 = ((o.uv0.rg*1.0)+node_312.g*float2(0.05,0.05));
                float3 node_39 = UnpackNormal(tex2Dlod(_Normal,float4(TRANSFORM_TEX(node_106, _Normal),0.0,0)));
                float2 node_86 = (node_39.rgb.rg*(_RefractionIntensity*0.2));
                v.vertex.xyz += float3(node_86,0.0);
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                TRANSFER_SHADOW_COLLECTOR(o)
                return o;
            }
            fixed4 frag(VertexOutput i) : COLOR {
                SHADOW_COLLECTOR_FRAGMENT(i)
            }
            ENDCG
        }
        Pass {
            Name "ShadowCaster"
            Tags {
                "LightMode"="ShadowCaster"
            }
            Cull Off
            Offset 1, 1
            
            Fog {Mode Off}
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_SHADOWCASTER
            #include "UnityCG.cginc"
            #include "Lighting.cginc"
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma multi_compile_shadowcaster
            #pragma exclude_renderers xbox360 ps3 flash d3d11_9x 
            #pragma target 3.0
            #pragma glsl
            uniform float4 _TimeEditor;
            uniform sampler2D _Normal; uniform float4 _Normal_ST;
            uniform float _RefractionIntensity;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                V2F_SHADOW_CASTER;
                float2 uv0 : TEXCOORD1;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o;
                o.uv0 = v.texcoord0;
                float4 node_313 = _Time + _TimeEditor;
                float2 node_106 = ((o.uv0.rg*1.0)+node_313.g*float2(0.05,0.05));
                float3 node_39 = UnpackNormal(tex2Dlod(_Normal,float4(TRANSFORM_TEX(node_106, _Normal),0.0,0)));
                float2 node_86 = (node_39.rgb.rg*(_RefractionIntensity*0.2));
                v.vertex.xyz += float3(node_86,0.0);
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                TRANSFER_SHADOW_CASTER(o)
                return o;
            }
            fixed4 frag(VertexOutput i) : COLOR {
                SHADOW_CASTER_FRAGMENT(i)
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
    CustomEditor "ShaderForgeMaterialInspector"
}
