###### GAIA LABORATORY FOR GRAPHICS

Department of Game and Multimedia Engineering

###### 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

1970年01月01日 08:00

#### OpenGL CG 系列教程1 - Hello CG

2013-04-27 12:24:56

#### OpenGL - Lighting

2015-08-31 16:46:44

#### openGL CG 系列教程2 - Vertex Lighting

2010-04-28 22:54:00

#### 【转】OpenGL CG系列教程2,vertex lighting

2013-08-26 11:31:29

#### openGL CG 系列教程4 - Lighting + Texture

2010-05-05 19:38:00

#### OpenGL: CG简介

2014-02-27 11:03:43

#### 【GPU编程】The Cg Runtime:OpenGL中调用Cg程序

2012-01-10 14:54:49

#### openGL CG 系列教程1 - Hello CG

2010-04-28 19:46:00

#### OpenGL&CG技术之Render To Texture

2015-12-26 14:21:02

## 不良信息举报

openGL CG 系列教程3-Pixel Lighting