模仿腾讯非洲之心写的u3d着色器,可用于水晶、钻石、玻璃,但是考虑到塔科夫的兼容性,因此该着色器是一个SSS(standard surface shader),缺少部分特效,效果不如原版
Shader "Custom/StandardSurface/BlenderStyleGlass_DoubleSided"
{
Properties
{
_FresnelIOR1 ("Fresnel IOR 1", Range(1.0, 1.5)) = 1.320
_FresnelIOR2 ("Fresnel IOR 2", Range(1.0, 1.5)) = 1.260
_FresnelIOR3 ("Fresnel IOR 3", Range(1.0, 1.5)) = 1.090
_FresnelIOR4 ("Fresnel IOR 4", Range(1.0, 1.5)) = 1.010
_FresnelMul1 ("Fresnel Multiply 1", Range(0, 50)) = 20.0
_FresnelMul2 ("Fresnel Multiply 2", Range(0, 50)) = 8.1
_FresnelMul3 ("Fresnel Multiply 3", Range(0, 50)) = 40.0
_FresnelAdd1 ("Fresnel Add 1", Range(0, 1)) = 0.1
_FresnelAdd2 ("Fresnel Add 2", Range(0, 1)) = 0.0
_GlobalValue ("Global Value", Range(0, 5)) = 2.416
_Roughness ("Roughness", Range(0, 1)) = 0.1
_ColorRed ("Glass Color Red", Color) = (1,0,0,1)
_ColorGreen ("Glass Color Green", Color) = (0,1,0,1)
_ColorBlue ("Glass Color Blue", Color) = (0,0,1,1)
_TransparentColor ("Transparent Color", Color) = (1,1,1,1)
// 背面贡献强度(Blender 体感的关键)
_BackFaceStrength ("Backface Contribution", Range(0, 2)) = 1.0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"RenderType"="Transparent"
}
LOD 300
Cull Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf Standard fullforwardshadows alpha:fade
#pragma target 3.0
struct Input
{
float3 worldNormal;
float3 viewDir;
float facing : VFACE;
};
half _FresnelIOR1, _FresnelIOR2, _FresnelIOR3, _FresnelIOR4;
half _FresnelMul1, _FresnelMul2, _FresnelMul3;
half _FresnelAdd1, _FresnelAdd2;
half _GlobalValue;
half _Roughness;
half _BackFaceStrength;
fixed4 _ColorRed;
fixed4 _ColorGreen;
fixed4 _ColorBlue;
fixed4 _TransparentColor;
inline half FresnelTerm(half3 n, half3 v, half ior)
{
half ndv = saturate(dot(normalize(n), normalize(v)));
return pow(1.0h - ndv, ior);
}
fixed3 ComputeGlassColor(half3 n, half3 v)
{
half f1 = saturate(FresnelTerm(n, v, _FresnelIOR1) * _FresnelMul1 + _FresnelAdd1);
half f2 = saturate(FresnelTerm(n, v, _FresnelIOR2) * _FresnelMul2 + _FresnelAdd2);
half f3 = saturate(FresnelTerm(n, v, _FresnelIOR3) * _FresnelMul3);
half f4 = saturate(FresnelTerm(n, v, _FresnelIOR4));
fixed3 col = lerp(_ColorRed.rgb, _ColorGreen.rgb, f1);
col = lerp(col, _ColorBlue.rgb, f2);
col = lerp(col, _TransparentColor.rgb, f4 * _GlobalValue);
return col;
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
half3 N = normalize(IN.worldNormal);
half3 V = normalize(IN.viewDir);
// 正面
fixed3 frontCol = ComputeGlassColor(N, V);
// 背面:翻转法线重新计算
fixed3 backCol = ComputeGlassColor(-N, V);
// 根据是否是正面像素,混合背面贡献
half backWeight = saturate(-IN.facing) * _BackFaceStrength;
fixed3 finalCol = frontCol + backCol * backWeight;
o.Albedo = finalCol;
o.Metallic = 0.0h;
o.Smoothness = 1.0h - _Roughness;
// Alpha:正面 + 背面共同决定
o.Alpha = saturate((1.0h - _Roughness) * (1.0h + backWeight));
}
ENDCG
}
FallBack "Standard"
}









