在前一篇的基础上,加入图片并绘制出来图片的色彩。
在Propertices中加入_RampTex("Ramp Textrue", 2D) = " "{ }
然后在SubShader中CGPROGRAM 结构体中加入 #pragma surface surf BasicDiffuse 添加sampler2D _RampTex;
在
inline float4 LightBasicDiffuse(SurfaceOutput s , fixed3 lightDir ,fixed atten)
{
float difLight = dot(s.Normal,lightDir);
float rimLight = dot(s.Normal , viewDir);
float hLambert = difLight * 0.5 + 0.5;
//加入2D图片
//float3 ramp = tex2D( _RampTex . float2(hLambert , rimLight )).rgb;
float4 col;
col.rgb = s.Albedo * _LightColor0.rgb * (hLambert * atten * 2);
// col.rgb = s.Albedo * _LightColor0.rgb * (ramp);
col.a = s.Alpha;
return col;
}
加入图片 以及加入 ViewDirection
inline float4 LightBasicDiffuse(SurfaceOutput s , fixed3 lightDir , fixed3 viewDir, fixed atten)
{
float difLight = dot(s.Normal,lightDir);
float rimLight = dot(s.Normal , viewDir);
float hLambert = difLight * 0.5 + 0.5;
//加入2D图片。转换为rgb的模式
float3 ramp = tex2D( _RampTex . float2(hLambert , rimLight )).rgb;
float4 col;
col.rgb = s.Albedo * _LightColor0.rgb * (hLambert * atten * 2);
col.rgb = s.Albedo * _LightColor0.rgb * (ramp);
col.a = s.Alpha;
return col;
}
在LightBasicDiffuse函数中 加入 fiexed3 ViewDir然后出现的,相关的原理如下
编写出来出现的效果,如下图所示:
面板层的具体参数设置如下图所示: