冯乐乐的《Unity Shader入门精要》附带项目,其中部分shader已经修改测试
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

433 lines
27 KiB

// Shader created with Shader Forge v1.38
// 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.38;sub:START;pass:START;ps:flbk:,iptp:0,cusa:False,bamd:0,cgin:,lico:1,lgpr:1,limd:3,spmd:1,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:0,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:False,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,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:35516,y:31853,varname:node_2865,prsc:2|diff-9564-OUT,spec-2528-OUT,gloss-9662-OUT,normal-5964-RGB,alpha-9203-OUT,refract-8987-OUT;n:type:ShaderForge.SFN_Color,id:6665,x:34395,y:31393,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:5964,x:35068,y:32171,ptovrint:True,ptlb:Normal Map I,ptin:_BumpMap,varname:_BumpMap,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:e3ba8bc476e919b4b9308f1d6abe660b,ntxv:3,isnm:True;n:type:ShaderForge.SFN_Slider,id:358,x:34381,y:31757,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.6030321,max:1;n:type:ShaderForge.SFN_Slider,id:1813,x:34303,y:31868,ptovrint:False,ptlb:Gloss,ptin:_Gloss,varname:_Metallic_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.3252537,max:1;n:type:ShaderForge.SFN_NormalVector,id:923,x:30267,y:32984,prsc:2,pt:False;n:type:ShaderForge.SFN_Abs,id:1916,x:30875,y:33194,varname:node_1916,prsc:2|IN-2671-OUT;n:type:ShaderForge.SFN_Multiply,id:3104,x:31086,y:33121,varname:node_3104,prsc:2|A-2671-OUT,B-1916-OUT;n:type:ShaderForge.SFN_ComponentMask,id:6719,x:31301,y:33047,cmnt:Here we got the G component from the RGB mask,varname:node_6719,prsc:2,cc1:1,cc2:-1,cc3:-1,cc4:-1|IN-3104-OUT;n:type:ShaderForge.SFN_Tex2d,id:2075,x:34257,y:31552,ptovrint:False,ptlb:snow,ptin:_snow,varname:node_2075,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:50c397b0cfd8e7f4cb233370c8999495,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Subtract,id:2187,x:32969,y:32608,cmnt:We remove G info to get cracks,varname:node_2187,prsc:2|A-6719-OUT;n:type:ShaderForge.SFN_Multiply,id:4640,x:33255,y:32639,varname:node_4640,prsc:2|A-2187-OUT,B-7590-OUT;n:type:ShaderForge.SFN_ConstantClamp,id:9434,x:33151,y:32864,cmnt:Choosing a smaller range of info,varname:node_9434,prsc:2,min:0,max:0.8;n:type:ShaderForge.SFN_Slider,id:7590,x:32754,y:32362,ptovrint:False,ptlb:snow_slider,ptin:_snow_slider,varname:node_7590,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:7.350427,max:10;n:type:ShaderForge.SFN_Clamp01,id:4570,x:33466,y:32596,cmnt:This removes negative info wich includes the G values at the bottom,varname:node_4570,prsc:2|IN-4640-OUT;n:type:ShaderForge.SFN_Tex2d,id:3573,x:32867,y:33239,ptovrint:False,ptlb:Normal Map II,ptin:_NormalMapII,varname:node_3573,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:fbba011cc6fa1474294f6700f3e9ac41,ntxv:3,isnm:True;n:type:ShaderForge.SFN_Vector1,id:2855,x:34460,y:31954,varname:node_2855,prsc:2,v1:0.7;n:type:ShaderForge.SFN_Vector1,id:5029,x:34617,y:31836,varname:node_5029,prsc:2,v1:1;n:type:ShaderForge.SFN_Multiply,id:8846,x:33623,y:32376,varname:node_8846,prsc:2|A-7044-OUT,B-8462-OUT,C-4570-OUT;n:type:ShaderForge.SFN_ConstantClamp,id:8462,x:33277,y:32401,varname:node_8462,prsc:2,min:0,max:1.2|IN-7590-OUT;n:type:ShaderForge.SFN_Vector1,id:7044,x:33277,y:32310,varname:node_7044,prsc:2,v1:0.7;n:type:ShaderForge.SFN_Add,id:8245,x:33871,y:32398,cmnt:added freezing effect,varname:node_8245,prsc:2|A-8846-OUT,B-7249-OUT;n:type:ShaderForge.SFN_Multiply,id:7249,x:33681,y:32878,cmnt:added freezing effect...,varname:node_7249,prsc:2|A-9434-OUT,B-4603-OUT;n:type:ShaderForge.SFN_Slider,id:4603,x:33341,y:32971,ptovrint:False,ptlb:Freeze effect (normal),ptin:_Freezeeffectnormal,varname:node_4603,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:4.77537,max:10;n:type:ShaderForge.SFN_Transform,id:1053,x:30472,y:32829,varname:node_1053,prsc:2,tffrom:0,tfto:1|IN-923-OUT;n:type:ShaderForge.SFN_SwitchProperty,id:2671,x:30670,y:33000,ptovrint:False,ptlb:Local/Global,ptin:_LocalGlobal,cmnt:Change between local orientation or global,varname:node_2671,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,on:False|A-1053-XYZ,B-923-OUT;n:type:ShaderForge.SFN_Fresnel,id:1294,x:34865,y:32565,varname:node_1294,prsc:2|EXP-6482-OUT;n:type:ShaderForge.SFN_Lerp,id:9203,x:35088,y:32445,varname:node_9203,prsc:2|A-1294-OUT,B-337-OUT,T-5885-OUT;n:type:ShaderForge.SFN_Vector1,id:337,x:34865,y:32406,varname:node_337,prsc:2,v1:1;n:type:ShaderForge.SFN_TexCoord,id:4152,x:34983,y:32715,varname:node_4152,prsc:2,uv:0,uaff:False;n:type:ShaderForge.SFN_Multiply,id:8987,x:35200,y:32661,varname:node_8987,prsc:2|A-4152-UVOUT,B-1294-OUT;n:type:ShaderForge.SFN_Multiply,id:9564,x:34884,y:31515,varname:node_9564,prsc:2|A-6665-RGB,B-2075-RGB;n:type:ShaderForge.SFN_Slider,id:5885,x:34492,y:32458,ptovrint:False,ptlb:Transparency,ptin:_Transparency,varname:node_5885,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:-1,cur:0.490779,max:1;n:type:ShaderForge.SFN_Slider,id:6482,x:34492,y:32585,ptovrint:False,ptlb:Ice_fresnel,ptin:_Ice_fresnel,varname:node_6482,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.4528386,max:3;n:type:ShaderForge.SFN_Multiply,id:2528,x:35018,y:31779,varname:node_2528,prsc:2|A-358-OUT,B-5029-OUT;n:type:ShaderForge.SFN_Multiply,id:9662,x:35107,y:31969,varname:node_9662,prsc:2|A-1813-OUT,B-2855-OUT;proporder:2075-6665-358-1813-5964-3573-7590-4603-2671-5885-6482;pass:END;sub:END;*/
Shader "Olanigan/Glass" {
Properties {
_snow ("snow", 2D) = "white" {}
_Color ("Color", Color) = (0.5019608,0.5019608,0.5019608,1)
_Metallic ("Metallic", Range(0, 1)) = 0.6030321
_Gloss ("Gloss", Range(0, 1)) = 0.3252537
_BumpMap ("Normal Map I", 2D) = "bump" {}
_NormalMapII ("Normal Map II", 2D) = "bump" {}
_snow_slider ("snow_slider", Range(0, 10)) = 7.350427
_Freezeeffectnormal ("Freeze effect (normal)", Range(0, 10)) = 4.77537
[MaterialToggle] _LocalGlobal ("Local/Global", Float ) = 0
_Transparency ("Transparency", Range(-1, 1)) = 0.490779
_Ice_fresnel ("Ice_fresnel", Range(0, 3)) = 0.4528386
[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {
"IgnoreProjector"="True"
"Queue"="Transparent"
"RenderType"="Transparent"
}
GrabPass{ }
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#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 n3ds wiiu
#pragma target 3.0
uniform sampler2D _GrabTexture;
uniform float4 _Color;
uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
uniform float _Metallic;
uniform float _Gloss;
uniform sampler2D _snow; uniform float4 _snow_ST;
uniform float _Transparency;
uniform float _Ice_fresnel;
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;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
float3 normalDir : TEXCOORD4;
float3 tangentDir : TEXCOORD5;
float3 bitangentDir : TEXCOORD6;
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;
#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) : COLOR {
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 node_1294 = pow(1.0-max(0,dot(normalDirection, viewDirection)),_Ice_fresnel);
float2 sceneUVs = (i.projPos.xy / i.projPos.w) + (i.uv0*node_1294);
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 = (_Gloss*0.7);
float perceptualRoughness = 1.0 - (_Gloss*0.7);
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));
float3 specularColor = (_Metallic*1.0);
float specularMonochrome;
float4 _snow_var = tex2D(_snow,TRANSFORM_TEX(i.uv0, _snow));
float3 diffuseColor = (_Color.rgb*_snow_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;
float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
/// Final Color:
float3 finalColor = diffuse + specular;
fixed4 finalRGBA = fixed4(lerp(sceneColor.rgb, finalColor,lerp(node_1294,1.0,_Transparency)),1);
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
return finalRGBA;
}
ENDCG
}
Pass {
Name "FORWARD_DELTA"
Tags {
"LightMode"="ForwardAdd"
}
Blend One One
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDADD
#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 n3ds wiiu
#pragma target 3.0
uniform sampler2D _GrabTexture;
uniform float4 _Color;
uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
uniform float _Metallic;
uniform float _Gloss;
uniform sampler2D _snow; uniform float4 _snow_ST;
uniform float _Transparency;
uniform float _Ice_fresnel;
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;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
float3 normalDir : TEXCOORD4;
float3 tangentDir : TEXCOORD5;
float3 bitangentDir : TEXCOORD6;
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.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) : COLOR {
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 node_1294 = pow(1.0-max(0,dot(normalDirection, viewDirection)),_Ice_fresnel);
float2 sceneUVs = (i.projPos.xy / i.projPos.w) + (i.uv0*node_1294);
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:
float attenuation = LIGHT_ATTENUATION(i);
float3 attenColor = attenuation * _LightColor0.xyz;
float Pi = 3.141592654;
float InvPi = 0.31830988618;
///////// Gloss:
float gloss = (_Gloss*0.7);
float perceptualRoughness = 1.0 - (_Gloss*0.7);
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));
float3 specularColor = (_Metallic*1.0);
float specularMonochrome;
float4 _snow_var = tex2D(_snow,TRANSFORM_TEX(i.uv0, _snow));
float3 diffuseColor = (_Color.rgb*_snow_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 * lerp(node_1294,1.0,_Transparency),0);
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
return finalRGBA;
}
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
#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 n3ds wiiu
#pragma target 3.0
uniform float4 _Color;
uniform float _Metallic;
uniform float _Gloss;
uniform sampler2D _snow; uniform float4 _snow_ST;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
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 {
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
UnityMetaInput o;
UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );
o.Emission = 0;
float4 _snow_var = tex2D(_snow,TRANSFORM_TEX(i.uv0, _snow));
float3 diffColor = (_Color.rgb*_snow_var.rgb);
float specularMonochrome;
float3 specColor;
diffColor = DiffuseAndSpecularFromMetallic( diffColor, (_Metallic*1.0), specColor, specularMonochrome );
float roughness = 1.0 - (_Gloss*0.7);
o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
return UnityMetaFragment( o );
}
ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}