// Shader created with Shader Forge v1.40 // Shader Forge (c) Freya Holmer - http://www.acegikmo.com/shaderforge/ // Note: Manually altering this data may prevent you from opening it in Shader Forge /*SF_DATA;ver:1.40;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,cgin:,cpap:True,lico:1,lgpr:1,limd:3,spmd:1,trmd:0,grmd:1,uamb:True,mssp:True,bkdf:True,hqlp:False,rprd:True,enco:False,rmgx:True,imps: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,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:False,qofs:0,qpre:2,rntp:3,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,atwp: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,fsmp:False;n:type:ShaderForge.SFN_Final,id:2865,x:32719,y:32712,varname:node_2865,prsc:2|diff-6343-OUT,spec-4712-OUT,gloss-1813-OUT,normal-5964-RGB,emission-9267-OUT,difocc-5414-R,clip-422-OUT;n:type:ShaderForge.SFN_Multiply,id:6343,x:31965,y:32543,varname:node_6343,prsc:2|A-7736-RGB,B-6665-RGB;n:type:ShaderForge.SFN_Color,id:6665,x:31717,y:32728,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:31762,y:32377,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:32013,y:32974,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:32013,y:32790,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,max:1;n:type:ShaderForge.SFN_Slider,id:1813,x:32143,y:32882,ptovrint:False,ptlb:Roughness,ptin:_Roughness,varname:_Metallic_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.8,max:1;n:type:ShaderForge.SFN_Tex2d,id:6117,x:32112,y:32611,ptovrint:False,ptlb:Met,ptin:_Met,varname:node_6117,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Multiply,id:4712,x:32419,y:32741,varname:node_4712,prsc:2|A-6117-R,B-358-OUT;n:type:ShaderForge.SFN_Slider,id:914,x:30202,y:32877,ptovrint:False,ptlb:Tile,ptin:_Tile,varname:node_914,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:10,max:50;n:type:ShaderForge.SFN_TexCoord,id:1838,x:30154,y:33097,varname:node_1838,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Vector1,id:2015,x:30359,y:32684,varname:node_2015,prsc:2,v1:1;n:type:ShaderForge.SFN_Divide,id:4960,x:30556,y:32810,varname:node_4960,prsc:2|A-2015-OUT,B-914-OUT;n:type:ShaderForge.SFN_Multiply,id:8113,x:30443,y:33080,varname:node_8113,prsc:2|A-914-OUT,B-1838-UVOUT;n:type:ShaderForge.SFN_Ceil,id:7493,x:30618,y:33080,varname:node_7493,prsc:2|IN-8113-OUT;n:type:ShaderForge.SFN_Multiply,id:4612,x:30854,y:33027,varname:node_4612,prsc:2|A-4960-OUT,B-7493-OUT;n:type:ShaderForge.SFN_Tex2d,id:3693,x:31335,y:32710,ptovrint:False,ptlb:Edge,ptin:_Edge,varname:node_3693,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False|UVIN-4612-OUT;n:type:ShaderForge.SFN_Color,id:9046,x:31335,y:32936,ptovrint:False,ptlb:EdgeColor,ptin:_EdgeColor,varname:node_9046,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,c1:0,c2:0.8317747,c3:1,c4:1;n:type:ShaderForge.SFN_Multiply,id:9267,x:31974,y:33125,varname:node_9267,prsc:2|A-3693-RGB,B-9046-RGB,C-3274-OUT;n:type:ShaderForge.SFN_RemapRange,id:4670,x:30275,y:33386,varname:node_4670,prsc:2,frmn:0,frmx:1,tomn:-1.2,tomx:1|IN-4612-OUT;n:type:ShaderForge.SFN_Length,id:3851,x:30504,y:33386,varname:node_3851,prsc:2|IN-4670-OUT;n:type:ShaderForge.SFN_OneMinus,id:1103,x:30701,y:33386,varname:node_1103,prsc:2|IN-3851-OUT;n:type:ShaderForge.SFN_Clamp01,id:3621,x:30917,y:33386,varname:node_3621,prsc:2|IN-1103-OUT;n:type:ShaderForge.SFN_OneMinus,id:2440,x:30275,y:33594,varname:node_2440,prsc:2|IN-1838-V;n:type:ShaderForge.SFN_Min,id:1978,x:30515,y:33594,varname:node_1978,prsc:2|A-1838-V,B-2440-OUT;n:type:ShaderForge.SFN_Multiply,id:6142,x:31119,y:33464,varname:node_6142,prsc:2|A-3621-OUT,B-1978-OUT;n:type:ShaderForge.SFN_Slider,id:6935,x:31131,y:33266,ptovrint:False,ptlb:Dissoltion,ptin:_Dissoltion,varname:node_6935,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.4789392,max:1;n:type:ShaderForge.SFN_Subtract,id:8485,x:31413,y:33458,varname:node_8485,prsc:2|A-6935-OUT,B-4-OUT;n:type:ShaderForge.SFN_Slider,id:4,x:31173,y:33708,ptovrint:False,ptlb:With,ptin:_With,varname:node_4,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0,max:1;n:type:ShaderForge.SFN_Step,id:422,x:31642,y:33468,varname:node_422,prsc:2|A-8485-OUT,B-6142-OUT;n:type:ShaderForge.SFN_Step,id:9385,x:31592,y:33238,varname:node_9385,prsc:2|A-6935-OUT,B-6142-OUT;n:type:ShaderForge.SFN_Subtract,id:3274,x:31777,y:33294,varname:node_3274,prsc:2|A-422-OUT,B-9385-OUT;n:type:ShaderForge.SFN_Tex2d,id:5414,x:32464,y:32998,ptovrint:False,ptlb:ao,ptin:_ao,varname:node_5414,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False;proporder:5964-6665-7736-358-1813-6117-914-3693-9046-6935-4-5414;pass:END;sub:END;*/ Shader "Shader Forge/pbrfog" { Properties { _BumpMap ("Normal Map", 2D) = "bump" {} _Color ("Color", Color) = (0.5019608,0.5019608,0.5019608,1) _MainTex ("Base Color", 2D) = "white" {} _Metallic ("Metallic", Range(0, 1)) = 0 _Roughness ("Roughness", Range(0, 1)) = 0.8 _Met ("Met", 2D) = "white" {} _Tile ("Tile", Range(0, 50)) = 10 _Edge ("Edge", 2D) = "white" {} _EdgeColor ("EdgeColor", Color) = (0,0.8317747,1,1) _Dissoltion ("Dissoltion", Range(0, 1)) = 0.4789392 _With ("With", Range(0, 1)) = 0 _ao ("ao", 2D) = "white" {} [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" } Pass { Name "FORWARD" Tags { "LightMode"="ForwardBase" } CGPROGRAM #pragma vertex vert #pragma fragment frag #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) ) #define _GLOSSYENV 1 #pragma multi_compile_instancing #include "UnityCG.cginc" #include "AutoLight.cginc" #include "Lighting.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #pragma multi_compile_fwdbase_fullshadows #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON #pragma multi_compile_fog #pragma target 3.0 uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST; uniform sampler2D _Met; uniform float4 _Met_ST; uniform sampler2D _Edge; uniform float4 _Edge_ST; uniform sampler2D _ao; uniform float4 _ao_ST; UNITY_INSTANCING_BUFFER_START( Props ) UNITY_DEFINE_INSTANCED_PROP( float4, _Color) UNITY_DEFINE_INSTANCED_PROP( float, _Metallic) UNITY_DEFINE_INSTANCED_PROP( float, _Roughness) UNITY_DEFINE_INSTANCED_PROP( float, _Tile) UNITY_DEFINE_INSTANCED_PROP( float4, _EdgeColor) UNITY_DEFINE_INSTANCED_PROP( float, _Dissoltion) UNITY_DEFINE_INSTANCED_PROP( float, _With) UNITY_INSTANCING_BUFFER_END( Props ) struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float4 tangent : TANGENT; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; float2 texcoord2 : TEXCOORD2; }; struct VertexOutput { float4 pos : SV_POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; float4 posWorld : TEXCOORD3; float3 normalDir : TEXCOORD4; float3 tangentDir : TEXCOORD5; float3 bitangentDir : TEXCOORD6; LIGHTING_COORDS(7,8) UNITY_FOG_COORDS(9) #if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH) float4 ambientOrLightmapUV : TEXCOORD10; #endif }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; UNITY_SETUP_INSTANCE_ID( v ); UNITY_TRANSFER_INSTANCE_ID( v, o ); o.uv0 = v.texcoord0; o.uv1 = v.texcoord1; o.uv2 = v.texcoord2; #ifdef LIGHTMAP_ON o.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; o.ambientOrLightmapUV.zw = 0; #elif UNITY_SHOULD_SAMPLE_SH #endif #ifdef DYNAMICLIGHTMAP_ON o.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; #endif o.normalDir = UnityObjectToWorldNormal(v.normal); o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz ); o.bitangentDir = 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 ); UNITY_TRANSFER_FOG(o,o.pos); TRANSFER_VERTEX_TO_FRAGMENT(o) return o; } float4 frag(VertexOutput i) : COLOR { UNITY_SETUP_INSTANCE_ID( i ); i.normalDir = normalize(i.normalDir); float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(i.uv0, _BumpMap))); float3 normalLocal = _BumpMap_var.rgb; float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals float3 viewReflectDirection = reflect( -viewDirection, normalDirection ); float _Dissoltion_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Dissoltion ); float _With_var = UNITY_ACCESS_INSTANCED_PROP( Props, _With ); float _Tile_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Tile ); float2 node_4612 = ((1.0/_Tile_var)*ceil((_Tile_var*i.uv0))); float node_6142 = (saturate((1.0 - length((node_4612*2.2+-1.2))))*min(i.uv0.g,(1.0 - i.uv0.g))); float node_422 = step((_Dissoltion_var-_With_var),node_6142); clip(node_422 - 0.5); float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz); float3 lightColor = _LightColor0.rgb; float3 halfDirection = normalize(viewDirection+lightDirection); ////// Lighting: float attenuation = LIGHT_ATTENUATION(i); float3 attenColor = attenuation * _LightColor0.xyz; float Pi = 3.141592654; float InvPi = 0.31830988618; ///////// Gloss: float _Roughness_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Roughness ); float gloss = 1.0 - _Roughness_var; // Convert roughness to gloss float perceptualRoughness = _Roughness_var; float roughness = perceptualRoughness * perceptualRoughness; float specPow = exp2( gloss * 10.0 + 1.0 ); /////// GI Data: UnityLight light; #ifdef LIGHTMAP_OFF light.color = lightColor; light.dir = lightDirection; light.ndotl = LambertTerm (normalDirection, light.dir); #else light.color = half3(0.f, 0.f, 0.f); light.ndotl = 0.0f; light.dir = half3(0.f, 0.f, 0.f); #endif UnityGIInput d; d.light = light; d.worldPos = i.posWorld.xyz; d.worldViewDir = viewDirection; d.atten = attenuation; #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) d.ambient = 0; d.lightmapUV = i.ambientOrLightmapUV; #else d.ambient = i.ambientOrLightmapUV; #endif #if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION d.boxMin[0] = unity_SpecCube0_BoxMin; d.boxMin[1] = unity_SpecCube1_BoxMin; #endif #if UNITY_SPECCUBE_BOX_PROJECTION d.boxMax[0] = unity_SpecCube0_BoxMax; d.boxMax[1] = unity_SpecCube1_BoxMax; d.probePosition[0] = unity_SpecCube0_ProbePosition; d.probePosition[1] = unity_SpecCube1_ProbePosition; #endif d.probeHDR[0] = unity_SpecCube0_HDR; d.probeHDR[1] = unity_SpecCube1_HDR; Unity_GlossyEnvironmentData ugls_en_data; ugls_en_data.roughness = 1.0 - gloss; ugls_en_data.reflUVW = viewReflectDirection; UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data ); lightDirection = gi.light.dir; lightColor = gi.light.color; ////// Specular: float NdotL = saturate(dot( normalDirection, lightDirection )); float LdotH = saturate(dot(lightDirection, halfDirection)); float4 _Met_var = tex2D(_Met,TRANSFORM_TEX(i.uv0, _Met)); float _Metallic_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Metallic ); float3 specularColor = (_Met_var.r*_Metallic_var); float specularMonochrome; float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex)); float4 _Color_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Color ); float3 diffuseColor = (_MainTex_var.rgb*_Color_var.rgb); // Need this for specular when using metallic diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome ); specularMonochrome = 1.0-specularMonochrome; float NdotV = abs(dot( normalDirection, viewDirection )); float NdotH = saturate(dot( normalDirection, halfDirection )); float VdotH = saturate(dot( viewDirection, halfDirection )); float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness ); float normTerm = GGXTerm(NdotH, roughness); float specularPBL = (visTerm*normTerm) * UNITY_PI; #ifdef UNITY_COLORSPACE_GAMMA specularPBL = sqrt(max(1e-4h, specularPBL)); #endif specularPBL = max(0, specularPBL * NdotL); #if defined(_SPECULARHIGHLIGHTS_OFF) specularPBL = 0.0; #endif half surfaceReduction; #ifdef UNITY_COLORSPACE_GAMMA surfaceReduction = 1.0-0.28*roughness*perceptualRoughness; #else surfaceReduction = 1.0/(roughness*roughness + 1.0); #endif specularPBL *= any(specularColor) ? 1.0 : 0.0; float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH); half grazingTerm = saturate( gloss + specularMonochrome ); float3 indirectSpecular = (gi.indirect.specular); indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV); indirectSpecular *= surfaceReduction; float3 specular = (directSpecular + indirectSpecular); /////// Diffuse: NdotL = max(0.0,dot( normalDirection, lightDirection )); half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss); float nlPow5 = Pow5(1-NdotL); float nvPow5 = Pow5(1-NdotV); float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor; float3 indirectDiffuse = float3(0,0,0); indirectDiffuse += gi.indirect.diffuse; float4 _ao_var = tex2D(_ao,TRANSFORM_TEX(i.uv0, _ao)); indirectDiffuse *= _ao_var.r; // Diffuse AO float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor; ////// Emissive: float4 _Edge_var = tex2D(_Edge,TRANSFORM_TEX(node_4612, _Edge)); float4 _EdgeColor_var = UNITY_ACCESS_INSTANCED_PROP( Props, _EdgeColor ); float3 emissive = (_Edge_var.rgb*_EdgeColor_var.rgb*(node_422-step(_Dissoltion_var,node_6142))); /// Final Color: float3 finalColor = diffuse + specular + emissive; fixed4 finalRGBA = fixed4(finalColor,1); UNITY_APPLY_FOG(i.fogCoord, finalRGBA); return finalRGBA; } ENDCG } Pass { Name "FORWARD_DELTA" Tags { "LightMode"="ForwardAdd" } Blend One One CGPROGRAM #pragma vertex vert #pragma fragment frag #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) ) #define _GLOSSYENV 1 #pragma multi_compile_instancing #include "UnityCG.cginc" #include "AutoLight.cginc" #include "Lighting.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #pragma multi_compile_fwdadd_fullshadows #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON #pragma multi_compile_fog #pragma target 3.0 uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST; uniform sampler2D _Met; uniform float4 _Met_ST; uniform sampler2D _Edge; uniform float4 _Edge_ST; UNITY_INSTANCING_BUFFER_START( Props ) UNITY_DEFINE_INSTANCED_PROP( float4, _Color) UNITY_DEFINE_INSTANCED_PROP( float, _Metallic) UNITY_DEFINE_INSTANCED_PROP( float, _Roughness) UNITY_DEFINE_INSTANCED_PROP( float, _Tile) UNITY_DEFINE_INSTANCED_PROP( float4, _EdgeColor) UNITY_DEFINE_INSTANCED_PROP( float, _Dissoltion) UNITY_DEFINE_INSTANCED_PROP( float, _With) UNITY_INSTANCING_BUFFER_END( Props ) struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float4 tangent : TANGENT; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; float2 texcoord2 : TEXCOORD2; }; struct VertexOutput { float4 pos : SV_POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; float4 posWorld : TEXCOORD3; float3 normalDir : TEXCOORD4; float3 tangentDir : TEXCOORD5; float3 bitangentDir : TEXCOORD6; LIGHTING_COORDS(7,8) UNITY_FOG_COORDS(9) }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; UNITY_SETUP_INSTANCE_ID( v ); UNITY_TRANSFER_INSTANCE_ID( v, o ); o.uv0 = v.texcoord0; o.uv1 = v.texcoord1; o.uv2 = v.texcoord2; o.normalDir = UnityObjectToWorldNormal(v.normal); o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz ); o.bitangentDir = 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 ); UNITY_TRANSFER_FOG(o,o.pos); TRANSFER_VERTEX_TO_FRAGMENT(o) return o; } float4 frag(VertexOutput i) : COLOR { UNITY_SETUP_INSTANCE_ID( i ); i.normalDir = normalize(i.normalDir); float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(i.uv0, _BumpMap))); float3 normalLocal = _BumpMap_var.rgb; float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals float _Dissoltion_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Dissoltion ); float _With_var = UNITY_ACCESS_INSTANCED_PROP( Props, _With ); float _Tile_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Tile ); float2 node_4612 = ((1.0/_Tile_var)*ceil((_Tile_var*i.uv0))); float node_6142 = (saturate((1.0 - length((node_4612*2.2+-1.2))))*min(i.uv0.g,(1.0 - i.uv0.g))); float node_422 = step((_Dissoltion_var-_With_var),node_6142); clip(node_422 - 0.5); 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; float Pi = 3.141592654; float InvPi = 0.31830988618; ///////// Gloss: float _Roughness_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Roughness ); float gloss = 1.0 - _Roughness_var; // Convert roughness to gloss float perceptualRoughness = _Roughness_var; float roughness = perceptualRoughness * perceptualRoughness; float specPow = exp2( gloss * 10.0 + 1.0 ); ////// Specular: float NdotL = saturate(dot( normalDirection, lightDirection )); float LdotH = saturate(dot(lightDirection, halfDirection)); float4 _Met_var = tex2D(_Met,TRANSFORM_TEX(i.uv0, _Met)); float _Metallic_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Metallic ); float3 specularColor = (_Met_var.r*_Metallic_var); float specularMonochrome; float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex)); float4 _Color_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Color ); float3 diffuseColor = (_MainTex_var.rgb*_Color_var.rgb); // Need this for specular when using metallic diffuseColor = DiffuseAndSpecularFromMetallic( diffuseColor, specularColor, specularColor, specularMonochrome ); specularMonochrome = 1.0-specularMonochrome; float NdotV = abs(dot( normalDirection, viewDirection )); float NdotH = saturate(dot( normalDirection, halfDirection )); float VdotH = saturate(dot( viewDirection, halfDirection )); float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness ); float normTerm = GGXTerm(NdotH, roughness); float specularPBL = (visTerm*normTerm) * UNITY_PI; #ifdef UNITY_COLORSPACE_GAMMA specularPBL = sqrt(max(1e-4h, specularPBL)); #endif specularPBL = max(0, specularPBL * NdotL); #if defined(_SPECULARHIGHLIGHTS_OFF) specularPBL = 0.0; #endif specularPBL *= any(specularColor) ? 1.0 : 0.0; float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH); float3 specular = directSpecular; /////// Diffuse: NdotL = max(0.0,dot( normalDirection, lightDirection )); half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss); float nlPow5 = Pow5(1-NdotL); float nvPow5 = Pow5(1-NdotV); float3 directDiffuse = ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL) * attenColor; float3 diffuse = directDiffuse * diffuseColor; /// Final Color: float3 finalColor = diffuse + specular; fixed4 finalRGBA = fixed4(finalColor * 1,0); UNITY_APPLY_FOG(i.fogCoord, finalRGBA); return finalRGBA; } ENDCG } Pass { Name "ShadowCaster" Tags { "LightMode"="ShadowCaster" } Offset 1, 1 Cull Back CGPROGRAM #pragma vertex vert #pragma fragment frag #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) ) #define _GLOSSYENV 1 #pragma multi_compile_instancing #include "UnityCG.cginc" #include "Lighting.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #pragma fragmentoption ARB_precision_hint_fastest #pragma multi_compile_shadowcaster #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON #pragma multi_compile_fog #pragma target 3.0 UNITY_INSTANCING_BUFFER_START( Props ) UNITY_DEFINE_INSTANCED_PROP( float, _Tile) UNITY_DEFINE_INSTANCED_PROP( float, _Dissoltion) UNITY_DEFINE_INSTANCED_PROP( float, _With) UNITY_INSTANCING_BUFFER_END( Props ) struct VertexInput { float4 vertex : POSITION; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; float2 texcoord2 : TEXCOORD2; }; struct VertexOutput { V2F_SHADOW_CASTER; UNITY_VERTEX_INPUT_INSTANCE_ID float2 uv0 : TEXCOORD1; float2 uv1 : TEXCOORD2; float2 uv2 : TEXCOORD3; float4 posWorld : TEXCOORD4; }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; UNITY_SETUP_INSTANCE_ID( v ); UNITY_TRANSFER_INSTANCE_ID( v, o ); o.uv0 = v.texcoord0; o.uv1 = v.texcoord1; o.uv2 = v.texcoord2; o.posWorld = mul(unity_ObjectToWorld, v.vertex); o.pos = UnityObjectToClipPos( v.vertex ); TRANSFER_SHADOW_CASTER(o) return o; } float4 frag(VertexOutput i) : COLOR { UNITY_SETUP_INSTANCE_ID( i ); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float _Dissoltion_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Dissoltion ); float _With_var = UNITY_ACCESS_INSTANCED_PROP( Props, _With ); float _Tile_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Tile ); float2 node_4612 = ((1.0/_Tile_var)*ceil((_Tile_var*i.uv0))); float node_6142 = (saturate((1.0 - length((node_4612*2.2+-1.2))))*min(i.uv0.g,(1.0 - i.uv0.g))); float node_422 = step((_Dissoltion_var-_With_var),node_6142); clip(node_422 - 0.5); SHADOW_CASTER_FRAGMENT(i) } ENDCG } Pass { Name "Meta" Tags { "LightMode"="Meta" } Cull Off CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_META 1 #define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) ) #define _GLOSSYENV 1 #pragma multi_compile_instancing #include "UnityCG.cginc" #include "Lighting.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #include "UnityMetaPass.cginc" #pragma fragmentoption ARB_precision_hint_fastest #pragma multi_compile_shadowcaster #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON #pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE #pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON #pragma multi_compile_fog #pragma target 3.0 uniform sampler2D _MainTex; uniform float4 _MainTex_ST; uniform sampler2D _Met; uniform float4 _Met_ST; uniform sampler2D _Edge; uniform float4 _Edge_ST; UNITY_INSTANCING_BUFFER_START( Props ) UNITY_DEFINE_INSTANCED_PROP( float4, _Color) UNITY_DEFINE_INSTANCED_PROP( float, _Metallic) UNITY_DEFINE_INSTANCED_PROP( float, _Roughness) UNITY_DEFINE_INSTANCED_PROP( float, _Tile) UNITY_DEFINE_INSTANCED_PROP( float4, _EdgeColor) UNITY_DEFINE_INSTANCED_PROP( float, _Dissoltion) UNITY_DEFINE_INSTANCED_PROP( float, _With) UNITY_INSTANCING_BUFFER_END( Props ) struct VertexInput { float4 vertex : POSITION; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; float2 texcoord2 : TEXCOORD2; }; struct VertexOutput { float4 pos : SV_POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; float4 posWorld : TEXCOORD3; }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; UNITY_SETUP_INSTANCE_ID( v ); UNITY_TRANSFER_INSTANCE_ID( v, o ); o.uv0 = v.texcoord0; o.uv1 = v.texcoord1; o.uv2 = v.texcoord2; o.posWorld = mul(unity_ObjectToWorld, v.vertex); o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST ); return o; } float4 frag(VertexOutput i) : SV_Target { UNITY_SETUP_INSTANCE_ID( i ); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); UnityMetaInput o; UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o ); float _Tile_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Tile ); float2 node_4612 = ((1.0/_Tile_var)*ceil((_Tile_var*i.uv0))); float4 _Edge_var = tex2D(_Edge,TRANSFORM_TEX(node_4612, _Edge)); float4 _EdgeColor_var = UNITY_ACCESS_INSTANCED_PROP( Props, _EdgeColor ); float _Dissoltion_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Dissoltion ); float _With_var = UNITY_ACCESS_INSTANCED_PROP( Props, _With ); float node_6142 = (saturate((1.0 - length((node_4612*2.2+-1.2))))*min(i.uv0.g,(1.0 - i.uv0.g))); float node_422 = step((_Dissoltion_var-_With_var),node_6142); o.Emission = (_Edge_var.rgb*_EdgeColor_var.rgb*(node_422-step(_Dissoltion_var,node_6142))); float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex)); float4 _Color_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Color ); float3 diffColor = (_MainTex_var.rgb*_Color_var.rgb); float specularMonochrome; float3 specColor; float4 _Met_var = tex2D(_Met,TRANSFORM_TEX(i.uv0, _Met)); float _Metallic_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Metallic ); diffColor = DiffuseAndSpecularFromMetallic( diffColor, (_Met_var.r*_Metallic_var), specColor, specularMonochrome ); float _Roughness_var = UNITY_ACCESS_INSTANCED_PROP( Props, _Roughness ); float roughness = _Roughness_var; o.Albedo = diffColor + specColor * roughness * roughness * 0.5; return UnityMetaFragment( o ); } ENDCG } } FallBack "Diffuse" CustomEditor "ShaderForgeMaterialInspector" }