# openGL CG 系列教程3-Pixel Lighting

*原创文章，转载请注明出处*

openGL CG 系列教程3-Pixel Lighting

03vs.cg

 struct output {       float4 position  : POSITION;           float3 objectPos : TEXCOORD0;          float3 normal     : TEXCOORD1; };   output vs_main( float4 position : POSITION,                   float3 normal   : NORMAL,                   uniform float4x4 MV,                   uniform float4x4 MVP                     ) {       output OUT;       OUT.position = mul(MVP, position);       OUT.objectPos = mul(MV, position).xyz;       OUT.normal = mul(MV, float4(normal,0.0)).xyz;         return OUT; }

03fs.cg

 uniform float3 LightPosition; uniform float3 eyePosition; uniform float3 I; uniform float3 Ka; uniform float3 Kd; uniform float3 Ks; uniform float shininess;   struct input{       float3 objectPos: TEXCOORD0;          float3 normal   : TEXCOORD1; };   struct output{       float4 color     : COLOR; };   output fs_main( in input IN ) {       output OUT;         float3 N = normalize(IN.normal);       float3 P = IN.objectPos;         float3 L = normalize(LightPosition - P);       float NdotL = max(dot(N,L),0);         float3 ambient = Ka * I;       float3 diffuse = Kd * I * NdotL;         float3 V = normalize(eyePosition - P);       float3 H = normalize(L+V);       float NdotH = pow(max(dot(N,H), 0), shininess);         if(NdotL<=0)            NdotH = 0.0;       float3 specular = Ks*I*NdotH;         float3 color = ambient + diffuse + specular;       OUT.color.xyz= color;       OUT.color.w = 1.0;         return OUT; }

*原创文章，转载请注明出处*

• 本文已收录于以下专栏：

举报原因： 您举报文章：openGL CG 系列教程3-Pixel Lighting 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)