519 lines
29 KiB
Plaintext
519 lines
29 KiB
Plaintext
// Shader created with Shader Forge v1.38
|
|
// 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.38;sub:START;pass:START;ps:flbk:Standard (Specular setup),iptp:0,cusa:False,bamd:0,cgin:,lico:1,lgpr:1,limd:3,spmd:0,trmd:0,grmd:0,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:2,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.4985801,fgcg:0.5,fgcb:0.4742647,fgca:1,fgde:0.002,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:32723,y:32706,varname:node_2865,prsc:2|diff-6343-OUT,spec-2918-OUT,gloss-5055-OUT,normal-5964-RGB,transm-6736-OUT,alpha-6381-OUT,refract-9861-OUT;n:type:ShaderForge.SFN_Multiply,id:6343,x:31992,y:32413,varname:node_6343,prsc:2|A-7736-RGB,B-6665-RGB;n:type:ShaderForge.SFN_Color,id:6665,x:31680,y:32528,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:31680,y:32335,ptovrint:True,ptlb:Diffuse,ptin:_MainTex,varname:_MainTex,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False|UVIN-2430-UVOUT;n:type:ShaderForge.SFN_Tex2d,id:5964,x:31789,y:33116,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|UVIN-2430-UVOUT;n:type:ShaderForge.SFN_Panner,id:2430,x:31401,y:32637,varname:node_2430,prsc:2,spu:0,spv:2|UVIN-4340-UVOUT;n:type:ShaderForge.SFN_TexCoord,id:4340,x:31007,y:32642,varname:node_4340,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Slider,id:2134,x:31680,y:32709,ptovrint:False,ptlb:Opacity,ptin:_Opacity,varname:node_2134,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_Multiply,id:2667,x:32008,y:32682,varname:node_2667,prsc:2|A-7736-A,B-2134-OUT;n:type:ShaderForge.SFN_Vector1,id:5695,x:32163,y:32197,varname:node_5695,prsc:2,v1:0.96;n:type:ShaderForge.SFN_Vector1,id:6831,x:32184,y:32064,varname:node_6831,prsc:2,v1:0.05;n:type:ShaderForge.SFN_VertexColor,id:2090,x:31636,y:32909,varname:node_2090,prsc:2;n:type:ShaderForge.SFN_Multiply,id:6381,x:32231,y:32898,varname:node_6381,prsc:2|A-2667-OUT,B-1957-OUT;n:type:ShaderForge.SFN_Desaturate,id:1957,x:32022,y:32909,varname:node_1957,prsc:2|COL-7317-OUT;n:type:ShaderForge.SFN_Multiply,id:2918,x:32384,y:32041,varname:node_2918,prsc:2|A-6831-OUT,B-1957-OUT;n:type:ShaderForge.SFN_Multiply,id:5055,x:32384,y:32186,varname:node_5055,prsc:2|A-5695-OUT,B-1957-OUT;n:type:ShaderForge.SFN_Vector1,id:621,x:31980,y:32611,varname:node_621,prsc:2,v1:0.75;n:type:ShaderForge.SFN_Multiply,id:6736,x:32200,y:32577,varname:node_6736,prsc:2|A-6343-OUT,B-621-OUT;n:type:ShaderForge.SFN_Slider,id:6853,x:31413,y:33084,ptovrint:False,ptlb:VertexBlendAmount,ptin:_VertexBlendAmount,varname:node_6853,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.5,max:1;n:type:ShaderForge.SFN_Multiply,id:7317,x:31857,y:32909,varname:node_7317,prsc:2|A-2090-RGB,B-6853-OUT,C-3310-OUT;n:type:ShaderForge.SFN_Vector1,id:3310,x:31570,y:33167,varname:node_3310,prsc:2,v1:2;n:type:ShaderForge.SFN_ComponentMask,id:5363,x:32109,y:33118,varname:node_5363,prsc:2,cc1:0,cc2:1,cc3:-1,cc4:-1|IN-5964-RGB;n:type:ShaderForge.SFN_Multiply,id:8561,x:32291,y:33118,varname:node_8561,prsc:2|A-5363-OUT,B-5380-OUT;n:type:ShaderForge.SFN_Multiply,id:9861,x:32466,y:33118,varname:node_9861,prsc:2|A-8561-OUT,B-1957-OUT;n:type:ShaderForge.SFN_Slider,id:5380,x:31942,y:33341,ptovrint:False,ptlb:Refraction,ptin:_Refraction,varname:node_5380,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.035,max:0.1;proporder:6665-7736-5964-2134-6853-5380;pass:END;sub:END;*/
|
|
|
|
Shader "TFP/TFP_FlowingWater" {
|
|
Properties {
|
|
_Color ("Color", Color) = (0.5019608,0.5019608,0.5019608,1)
|
|
_MainTex ("Diffuse", 2D) = "white" {}
|
|
_BumpMap ("Normal Map", 2D) = "bump" {}
|
|
_Opacity ("Opacity", Range(0, 1)) = 0.8
|
|
_VertexBlendAmount ("VertexBlendAmount", Range(0, 1)) = 0.5
|
|
_Refraction ("Refraction", Range(0, 0.1)) = 0.035
|
|
[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
|
|
}
|
|
SubShader {
|
|
Tags {
|
|
"IgnoreProjector"="True"
|
|
"Queue"="Transparent"
|
|
"RenderType"="Transparent"
|
|
}
|
|
LOD 300
|
|
GrabPass{ }
|
|
Pass {
|
|
Name "FORWARD"
|
|
Tags {
|
|
"LightMode"="ForwardBase"
|
|
}
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
Cull Off
|
|
ZWrite Off
|
|
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
|
|
#define _GLOSSYENV 1
|
|
#include "UnityCG.cginc"
|
|
#include "Lighting.cginc"
|
|
#include "UnityPBSLighting.cginc"
|
|
#include "UnityStandardBRDF.cginc"
|
|
#pragma multi_compile_fwdbase
|
|
#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 only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
|
|
#pragma target 3.0
|
|
uniform sampler2D _GrabTexture;
|
|
uniform float4 _Color;
|
|
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
|
|
uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
|
|
uniform float _Opacity;
|
|
uniform float _VertexBlendAmount;
|
|
uniform float _Refraction;
|
|
struct VertexInput {
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float4 tangent : TANGENT;
|
|
float2 texcoord0 : TEXCOORD0;
|
|
float2 texcoord1 : TEXCOORD1;
|
|
float2 texcoord2 : TEXCOORD2;
|
|
float4 vertexColor : COLOR;
|
|
};
|
|
struct VertexOutput {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv0 : TEXCOORD0;
|
|
float2 uv1 : TEXCOORD1;
|
|
float2 uv2 : TEXCOORD2;
|
|
float4 posWorld : TEXCOORD3;
|
|
float3 normalDir : TEXCOORD4;
|
|
float3 tangentDir : TEXCOORD5;
|
|
float3 bitangentDir : TEXCOORD6;
|
|
float4 vertexColor : COLOR;
|
|
float4 projPos : TEXCOORD7;
|
|
UNITY_FOG_COORDS(8)
|
|
#if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH)
|
|
float4 ambientOrLightmapUV : TEXCOORD9;
|
|
#endif
|
|
};
|
|
VertexOutput vert (VertexInput v) {
|
|
VertexOutput o = (VertexOutput)0;
|
|
o.uv0 = v.texcoord0;
|
|
o.uv1 = v.texcoord1;
|
|
o.uv2 = v.texcoord2;
|
|
o.vertexColor = v.vertexColor;
|
|
#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);
|
|
o.projPos = ComputeScreenPos (o.pos);
|
|
COMPUTE_EYEDEPTH(o.projPos.z);
|
|
return o;
|
|
}
|
|
float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
|
|
float isFrontFace = ( facing >= 0 ? 1 : 0 );
|
|
float faceSign = ( facing >= 0 ? 1 : -1 );
|
|
i.normalDir = normalize(i.normalDir);
|
|
i.normalDir *= faceSign;
|
|
float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
|
|
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
|
|
float4 node_4178 = _Time;
|
|
float2 node_2430 = (i.uv0+node_4178.g*float2(0,2));
|
|
float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(node_2430, _BumpMap)));
|
|
float3 normalLocal = _BumpMap_var.rgb;
|
|
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
|
|
float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
|
|
float node_1957 = dot((i.vertexColor.rgb*_VertexBlendAmount*2.0),float3(0.3,0.59,0.11));
|
|
float2 sceneUVs = (i.projPos.xy / i.projPos.w) + ((_BumpMap_var.rgb.rg*_Refraction)*node_1957);
|
|
float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
|
|
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
|
|
float3 lightColor = _LightColor0.rgb;
|
|
float3 halfDirection = normalize(viewDirection+lightDirection);
|
|
////// Lighting:
|
|
float attenuation = 1;
|
|
float3 attenColor = attenuation * _LightColor0.xyz;
|
|
float Pi = 3.141592654;
|
|
float InvPi = 0.31830988618;
|
|
///////// Gloss:
|
|
float gloss = (0.96*node_1957);
|
|
float perceptualRoughness = 1.0 - (0.96*node_1957);
|
|
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));
|
|
float node_2918 = (0.05*node_1957);
|
|
float3 specularColor = float3(node_2918,node_2918,node_2918);
|
|
float specularMonochrome;
|
|
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_2430, _MainTex));
|
|
float3 node_6343 = (_MainTex_var.rgb*_Color.rgb);
|
|
float3 diffuseColor = node_6343; // Need this for specular when using metallic
|
|
diffuseColor = EnergyConservationBetweenDiffuseAndSpecular(diffuseColor, 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 = dot( normalDirection, lightDirection );
|
|
float3 forwardLight = max(0.0, NdotL );
|
|
float3 backLight = max(0.0, -NdotL ) * (node_6343*0.75);
|
|
NdotL = max(0.0,dot( normalDirection, lightDirection ));
|
|
half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
|
|
float3 NdotLWrap = max(0,NdotL);
|
|
float nlPow5 = Pow5(1-NdotLWrap);
|
|
float nvPow5 = Pow5(1-NdotV);
|
|
float3 directDiffuse = ((forwardLight+backLight) + ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL)) * attenColor;
|
|
float3 indirectDiffuse = float3(0,0,0);
|
|
indirectDiffuse += gi.indirect.diffuse;
|
|
diffuseColor *= 1-specularMonochrome;
|
|
float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
|
|
/// Final Color:
|
|
float3 finalColor = diffuse + specular;
|
|
fixed4 finalRGBA = fixed4(lerp(sceneColor.rgb, finalColor,((_MainTex_var.a*_Opacity)*node_1957)),1);
|
|
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
|
|
return finalRGBA;
|
|
}
|
|
ENDCG
|
|
}
|
|
Pass {
|
|
Name "FORWARD_DELTA"
|
|
Tags {
|
|
"LightMode"="ForwardAdd"
|
|
}
|
|
Blend One One
|
|
Cull Off
|
|
ZWrite Off
|
|
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
|
|
#define _GLOSSYENV 1
|
|
#include "UnityCG.cginc"
|
|
#include "AutoLight.cginc"
|
|
#include "Lighting.cginc"
|
|
#include "UnityPBSLighting.cginc"
|
|
#include "UnityStandardBRDF.cginc"
|
|
#pragma multi_compile_fwdadd
|
|
#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 only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
|
|
#pragma target 3.0
|
|
uniform sampler2D _GrabTexture;
|
|
uniform float4 _Color;
|
|
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
|
|
uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
|
|
uniform float _Opacity;
|
|
uniform float _VertexBlendAmount;
|
|
uniform float _Refraction;
|
|
struct VertexInput {
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float4 tangent : TANGENT;
|
|
float2 texcoord0 : TEXCOORD0;
|
|
float2 texcoord1 : TEXCOORD1;
|
|
float2 texcoord2 : TEXCOORD2;
|
|
float4 vertexColor : COLOR;
|
|
};
|
|
struct VertexOutput {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv0 : TEXCOORD0;
|
|
float2 uv1 : TEXCOORD1;
|
|
float2 uv2 : TEXCOORD2;
|
|
float4 posWorld : TEXCOORD3;
|
|
float3 normalDir : TEXCOORD4;
|
|
float3 tangentDir : TEXCOORD5;
|
|
float3 bitangentDir : TEXCOORD6;
|
|
float4 vertexColor : COLOR;
|
|
float4 projPos : TEXCOORD7;
|
|
LIGHTING_COORDS(8,9)
|
|
UNITY_FOG_COORDS(10)
|
|
};
|
|
VertexOutput vert (VertexInput v) {
|
|
VertexOutput o = (VertexOutput)0;
|
|
o.uv0 = v.texcoord0;
|
|
o.uv1 = v.texcoord1;
|
|
o.uv2 = v.texcoord2;
|
|
o.vertexColor = v.vertexColor;
|
|
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);
|
|
o.projPos = ComputeScreenPos (o.pos);
|
|
COMPUTE_EYEDEPTH(o.projPos.z);
|
|
TRANSFER_VERTEX_TO_FRAGMENT(o)
|
|
return o;
|
|
}
|
|
float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
|
|
float isFrontFace = ( facing >= 0 ? 1 : 0 );
|
|
float faceSign = ( facing >= 0 ? 1 : -1 );
|
|
i.normalDir = normalize(i.normalDir);
|
|
i.normalDir *= faceSign;
|
|
float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
|
|
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
|
|
float4 node_3210 = _Time;
|
|
float2 node_2430 = (i.uv0+node_3210.g*float2(0,2));
|
|
float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(node_2430, _BumpMap)));
|
|
float3 normalLocal = _BumpMap_var.rgb;
|
|
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
|
|
float node_1957 = dot((i.vertexColor.rgb*_VertexBlendAmount*2.0),float3(0.3,0.59,0.11));
|
|
float2 sceneUVs = (i.projPos.xy / i.projPos.w) + ((_BumpMap_var.rgb.rg*_Refraction)*node_1957);
|
|
float4 sceneColor = tex2D(_GrabTexture, sceneUVs);
|
|
float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
|
|
float3 lightColor = _LightColor0.rgb;
|
|
float3 halfDirection = normalize(viewDirection+lightDirection);
|
|
////// Lighting:
|
|
UNITY_LIGHT_ATTENUATION(attenuation,i, i.posWorld.xyz);
|
|
float3 attenColor = attenuation * _LightColor0.xyz;
|
|
float Pi = 3.141592654;
|
|
float InvPi = 0.31830988618;
|
|
///////// Gloss:
|
|
float gloss = (0.96*node_1957);
|
|
float perceptualRoughness = 1.0 - (0.96*node_1957);
|
|
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));
|
|
float node_2918 = (0.05*node_1957);
|
|
float3 specularColor = float3(node_2918,node_2918,node_2918);
|
|
float specularMonochrome;
|
|
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_2430, _MainTex));
|
|
float3 node_6343 = (_MainTex_var.rgb*_Color.rgb);
|
|
float3 diffuseColor = node_6343; // Need this for specular when using metallic
|
|
diffuseColor = EnergyConservationBetweenDiffuseAndSpecular(diffuseColor, 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 = dot( normalDirection, lightDirection );
|
|
float3 forwardLight = max(0.0, NdotL );
|
|
float3 backLight = max(0.0, -NdotL ) * (node_6343*0.75);
|
|
NdotL = max(0.0,dot( normalDirection, lightDirection ));
|
|
half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
|
|
float3 NdotLWrap = max(0,NdotL);
|
|
float nlPow5 = Pow5(1-NdotLWrap);
|
|
float nvPow5 = Pow5(1-NdotV);
|
|
float3 directDiffuse = ((forwardLight+backLight) + ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL)) * attenColor;
|
|
diffuseColor *= 1-specularMonochrome;
|
|
float3 diffuse = directDiffuse * diffuseColor;
|
|
/// Final Color:
|
|
float3 finalColor = diffuse + specular;
|
|
fixed4 finalRGBA = fixed4(finalColor * ((_MainTex_var.a*_Opacity)*node_1957),0);
|
|
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
|
|
return finalRGBA;
|
|
}
|
|
ENDCG
|
|
}
|
|
Pass {
|
|
Name "ShadowCaster"
|
|
Tags {
|
|
"LightMode"="ShadowCaster"
|
|
}
|
|
Offset 1, 1
|
|
Cull Off
|
|
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
|
|
#define _GLOSSYENV 1
|
|
#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 only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
|
|
#pragma target 3.0
|
|
struct VertexInput {
|
|
float4 vertex : POSITION;
|
|
float2 texcoord1 : TEXCOORD1;
|
|
float2 texcoord2 : TEXCOORD2;
|
|
};
|
|
struct VertexOutput {
|
|
V2F_SHADOW_CASTER;
|
|
float2 uv1 : TEXCOORD1;
|
|
float2 uv2 : TEXCOORD2;
|
|
float4 posWorld : TEXCOORD3;
|
|
};
|
|
VertexOutput vert (VertexInput v) {
|
|
VertexOutput o = (VertexOutput)0;
|
|
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, float facing : VFACE) : COLOR {
|
|
float isFrontFace = ( facing >= 0 ? 1 : 0 );
|
|
float faceSign = ( facing >= 0 ? 1 : -1 );
|
|
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
|
|
SHADOW_CASTER_FRAGMENT(i)
|
|
}
|
|
ENDCG
|
|
}
|
|
Pass {
|
|
Name "Meta"
|
|
Tags {
|
|
"LightMode"="Meta"
|
|
}
|
|
Cull Off
|
|
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
|
|
#define _GLOSSYENV 1
|
|
#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 only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
|
|
#pragma target 3.0
|
|
uniform float4 _Color;
|
|
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
|
|
uniform float _VertexBlendAmount;
|
|
struct VertexInput {
|
|
float4 vertex : POSITION;
|
|
float2 texcoord0 : TEXCOORD0;
|
|
float2 texcoord1 : TEXCOORD1;
|
|
float2 texcoord2 : TEXCOORD2;
|
|
float4 vertexColor : COLOR;
|
|
};
|
|
struct VertexOutput {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv0 : TEXCOORD0;
|
|
float2 uv1 : TEXCOORD1;
|
|
float2 uv2 : TEXCOORD2;
|
|
float4 posWorld : TEXCOORD3;
|
|
float4 vertexColor : COLOR;
|
|
};
|
|
VertexOutput vert (VertexInput v) {
|
|
VertexOutput o = (VertexOutput)0;
|
|
o.uv0 = v.texcoord0;
|
|
o.uv1 = v.texcoord1;
|
|
o.uv2 = v.texcoord2;
|
|
o.vertexColor = v.vertexColor;
|
|
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, float facing : VFACE) : SV_Target {
|
|
float isFrontFace = ( facing >= 0 ? 1 : 0 );
|
|
float faceSign = ( facing >= 0 ? 1 : -1 );
|
|
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
|
|
UnityMetaInput o;
|
|
UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );
|
|
|
|
o.Emission = 0;
|
|
|
|
float4 node_8353 = _Time;
|
|
float2 node_2430 = (i.uv0+node_8353.g*float2(0,2));
|
|
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(node_2430, _MainTex));
|
|
float3 node_6343 = (_MainTex_var.rgb*_Color.rgb);
|
|
float3 diffColor = node_6343;
|
|
float node_1957 = dot((i.vertexColor.rgb*_VertexBlendAmount*2.0),float3(0.3,0.59,0.11));
|
|
float node_2918 = (0.05*node_1957);
|
|
float3 specColor = float3(node_2918,node_2918,node_2918);
|
|
float specularMonochrome = max(max(specColor.r, specColor.g),specColor.b);
|
|
diffColor *= (1.0-specularMonochrome);
|
|
float roughness = 1.0 - (0.96*node_1957);
|
|
o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
|
|
|
|
return UnityMetaFragment( o );
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
FallBack "Standard (Specular setup)"
|
|
CustomEditor "ShaderForgeMaterialInspector"
|
|
}
|