Shader "Custom/LightingModule"{
Properties{
_MainColor("Base Color",color) = (1,1,1,1)
_AmibentColor("Amient Color",color) = (1,1,1,1)
_MySliderValue("This Slider",range(0,10)) = 2.5
_RampTex ("Ramp Texture", 2D) = "white"{}
}
SubShader{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface suf BasicDiffuse
float4 _MainColor;
float4 _AmibentColor;
float _MySliderValue;
sampler2D _RampTex;
struct Input{
float2 uv_MainTex;
};
void suf (Input IN,inout SurfaceOutput o )
{
float4 c = pow((_MainColor + _AmibentColor),_MySliderValue);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
//-------------------基于半兰伯特光照模型---------------------------//
//自定义光照模型 函数必须要以 Lighting 开头
inline float4 LightingBasicDiffuse(SurfaceOutput s,fixed3 lightDirection,fixed atten)
{
float difLight = max(0, dot (s.Normal, lightDirection));
// Add this line
float hLambert = difLight * 0.5 + 0.5;
float3 ramp = tex2D(_RampTex, float2(hLambert,1)).rgb;
float4 col;
// Modify this line
col.rgb = s.Albedo * _LightColor0.rgb * ramp;
col.a = s.Alpha;
return col;
}
//-------------------基于兰伯特光照模型---------------------------//
// inline float4 LightingBasicDiffuse (SurfaceOutput s, fixed3 lightDir, fixed atten)
// {
// float difLight = max(0, dot (s.Normal, lightDir));
// float4 col;
// col.rgb = s.Albedo * _LightColor0.rgb * (difLight * atten * 2);
// col.a = s.Alpha;
// return col;
// }
ENDCG
}
FallBack "Diffuse"
}
<Shader> 自定义光照模型
最新推荐文章于 2024-01-08 09:45:00 发布
本文介绍了一个使用Unity Shader创建的自定义光照模型,通过调整基础颜色、环境颜色及滑块值来改变材质表现,并利用纹理贴图实现半兰伯特光照效果。

4929

被折叠的 条评论
为什么被折叠?



