ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/fsh.cg
Revision: 1.7
Committed: Tue Oct 5 08:28:39 2004 UTC (19 years, 8 months ago) by root
Branch: MAIN
Changes since 1.6: +3 -8 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 // final pixel output:
2 // data from pixel shader to frame buffer
3 struct vertexOut {
4 float4 HPosition : POSITION;
5 float4 TexCoord : TEXCOORD0;
6 float3 LightVec : TEXCOORD1;
7 float3 WorldNormal : TEXCOORD2;
8 float3 WorldPos : TEXCOORD3;
9 float3 WorldView : TEXCOORD4;
10 };
11
12 struct pixelOut {
13 float4 col : COLOR;
14 };
15
16 // pixel shader
17 pixelOut main(vertexOut IN)
18 {
19 float SpecExpon = 120;
20 float4 LightColor = { 1, 1, 1, 1 };
21
22 pixelOut OUT; // output of the pixel shader
23 float3 Ln = normalize(IN.LightVec);
24 float3 Nn = normalize(IN.WorldNormal);
25 float3 Vn = (IN.WorldView);
26 float3 Hn = 0.5 * (Vn + Ln);
27 // scalar product between light and normal vectors:
28 float ldn = abs(dot(Ln,Nn));
29 // scalar product between halfway and normal vectors:
30 float hdn = abs(dot(Hn,Nn));
31 // specialized "lit" function computes weights for
32 // diffuse and specular parts:
33 float4 litV = lit(ldn,hdn,SpecExpon);
34 float4 diffContrib = glstate.material.diffuse * ( litV.y * LightColor + glstate.lightmodel.ambient);
35 float4 specContrib = litV.y*litV.z * LightColor;
36 // sum of diffuse and specular contributions:
37 float4 result = diffContrib + specContrib;
38 OUT.col = result;
39 return OUT; // output of pixel shader
40 }
41