用 unity shaderlab 编写一个 lambert shader
时间: 2024-05-10 19:21:05 浏览: 175
以下是一个简单的Lambert着色器,它使用Unity的Standard Surface Shader来定义其表面属性:
```
Shader "Custom/Lambert" {
Properties {
_Color ("Color", Color) = (1, 1, 1, 1)
}
SubShader {
Tags {"RenderType"="Opaque"}
CGPROGRAM
#pragma surface surf Lambert
//定义表面属性
struct Input {
float2 uv_MainTex;
float3 worldPos;
};
//定义表面函数
void surf (Input IN, inout SurfaceOutputStandard o) {
//设置基本属性
o.Albedo = _Color.rgb;
o.Metallic = 0.0;
o.Smoothness = 0.5;
o.Normal = float3(0,0,1);
//计算光照
float3 lightDir = normalize(_WorldSpaceLightPos0.xyz - IN.worldPos);
float diffuse = max(0, dot(IN.worldNormal, lightDir));
o.Emission = _Color.rgb * diffuse;
}
ENDCG
}
FallBack "Diffuse"
}
```
阅读全文