# Lambert漫反射光照模型归纳

I_ambdiff = K_d * I_a;

I_ldiff = K_d * I_l * cosa;

I_ldiff = K_d * I_l * (N﹒L);

I_diff = K_d * I_a + K_d * I_l * (N﹒L);

/******************************************************/

/*Lambert漫反射光照模型                                */

/******************************************************/

struct vertex_In

{

float4 in_Position : POSITION;

float4 in_Normal   : NORMAL;

};

struct vertex_Out

{

float4 out_Position : POSITION;

float4 out_Color    : COLOR0;

};

void main_v(vertex_In vertexI,

out vertex_Out vertexO,

uniform float4*4 modelViewProj,

uniform float4*4 worldMatrix,

uniform float4*4 worldMatrix_IT,

uniform float3 globalAmbient,//全局光光强

uniform float3 lightPosition,

uniform float3 lightColor,

uniform float3 K_d//漫反射体反射系数

)

{

vertexO.out_Position = mul(modelViewProj , vertexI.in_Position);//进行投影变换

float3 worldPosition = mul(worldMatrix , vertexI.in_Position).xyz;//计算顶点的世界位置

float3 N = mul(worldMatrix_IT , vertexI.in_Normal).xyz;//计算顶点的法向量

N = normalize(N);//向量规范化

//计算方向光方向

float3 L = lightPosition - worldPosition;

L = normalize(L);//向量规范化

//计算环境光漫反射光强

float3 ambColor = Kd * globalAmbient;

//计算方向光漫反射光强

float3 dirColor = Kd * lightColor * max(dot(N , L) , 0);

vertexO.out_color.rgb = ambColor + dirColor;

vertexO.out_color.a = 1;

}