【Shader】角色受擊閃白效果
阿新 • • 發佈:2019-02-16
Shader "Custom/BeAttackFlashColor"
{
Properties {
_MainTex ("MainTex (RGB)", 2D) = "white" {}
_FlashColor("FlashColor" , Color) = (1,1,1,1)
_ColorRange("ColorRange" , Range(0.0, 0.7)) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// 定義自己的光照模型
#pragma surface surf CustomDiffuse
/*
引數:SurfaceOutput 經過表面計算後的輸入;lightDir 光線方向;atten 光衰減係數
*/
half4 LightingCustomDiffuse(SurfaceOutput s, half3 lightDir, half atten) {
half difLight = max(0, dot(s.Normal, lightDir)); //點積調整當前點的亮度
difLight = difLight * 0.5 + 0.5; //低光下增亮效果,範圍從 0-1 到 0.5-1
half4 col;
col.rgb = s.Albedo * _LightColor0.rgb * (difLight * atten * 1.5); //根據物體的顏色、光顏色、光亮度、衰減度計算當前點的顏色
col.a = s.Alpha;
return col;
}
sampler2D _MainTex;
half4 _FlashColor;
float _ColorRange;
struct Input {
float2 uv_MainTex;
float3 viewDir;
};
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
IN.viewDir = normalize(IN.viewDir);
float NdotV = dot(o.Normal, IN.viewDir);
if(NdotV < _ColorRange)
o.Emission = _FlashColor.rgb * lerp(0, 1, (_ColorRange - NdotV)/(1 - _ColorRange));
}
ENDCG
}
FallBack "Diffuse"
}