需求
1 基于涅菲尔反射的变形
- 原理 (近处的反射少,远处反射多)
1)公式(近似):F = Fscale + (1-Fscale)(1-v·n)^5
- 利用fresnel做边缘发光,代码
fixed fresnel = _FresnelScale + (1 - _FresnelScale) * pow(1 - dot(viewDir, worldNormal), _PowVal);//涅菲尔公式:_PowVal =5
_ColorFresnel * saturate(fresnel)
2 基于表面着色器Unity2019
Shader "Unlit/FirstShader"
{
Properties
{
_MainTex(" Diffuse (RGB)", 2D) = "white" {}
_NormalMap("Normal Map", 2D) = "bump" {}
_RimColor ("Rim Color", Color) = (1.0, 1.0, 1.0, 0.0)
//_RimConcentration ("Rim Concentration", Range(0.5, 5.0)) = 0.9
_RimStrength ("Rim Strength", Range(1.0, 4.0)) = 1.45
}
SubShader
{
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _NormalMap;
float4 _RimColor;
float _RimConcentration;
float _RimStrength;
struct Input
{
float2 uv_MainTex;
float2 uv_NormalMap;
float3 viewDir;
};
void surf(Input In, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, In.uv_MainTex);
float Lc = saturate(dot(normalize(In.viewDir), o.Normal));
half rim = 1.0 - Lc;
o.Albedo = c.rgb;
o.Normal = UnpackNormal(tex2D(_NormalMap, In.uv_NormalMap));
o.Alpha = c.a;
//o.Emission = _RimColor.rgb * pow(rim, _RimConcentration);
o.Emission = _RimStrength * (_RimColor.rgb * smoothstep(0.2, 0.6, rim));
}
ENDCG
}
FallBack "Diffuse"
}