-
Notifications
You must be signed in to change notification settings - Fork 13
/
lambertDiffuse_vertex.shader
58 lines (51 loc) · 1.55 KB
/
lambertDiffuse_vertex.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Shader "LX/lambertDiffuse_vertex"
{
Properties
{
_Diffuse("Diffuse",Color)=(1,1,1,1)
}
SubShader
{
Pass
{
Tags
{
"LightMode"="ForwardBase"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Lighting.cginc"
fixed4 _Diffuse;
struct a2v
{
float4 position : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float4 pos : SV_POSITION;
fixed3 color:COLOR;
};
v2f vert(a2v vertData)
{
v2f o;
o.pos = UnityObjectToClipPos(vertData.position);
//获取在unity编辑器中定义的环境光
fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz;
//把顶点法线变换到世界坐标系下
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, vertData.normal));
//获取光照方向
fixed3 worldLight = normalize(_WorldSpaceLightPos0.xyz);
fixed3 diffuse =_LightColor0.rgb * _Diffuse.rgb * saturate(dot(worldNormal, worldLight));
o.color = diffuse + ambient;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return fixed4(i.color, 1);
}
ENDCG
}
}
}