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

File Contents

# User Rev Content
1 root 1.1 // final pixel output:
2     // data from pixel shader to frame buffer
3 root 1.2 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 root 1.1
12     struct pixelOut {
13     float4 col : COLOR;
14     };
15 root 1.3
16 root 1.1 // pixel shader
17 root 1.7 pixelOut main(vertexOut IN)
18 root 1.1 {
19 root 1.4 float SpecExpon = 120;
20 root 1.5 float4 LightColor = { 1, 1, 1, 1 };
21 root 1.3
22 root 1.1 pixelOut OUT; // output of the pixel shader
23     float3 Ln = normalize(IN.LightVec);
24     float3 Nn = normalize(IN.WorldNormal);
25 root 1.7 float3 Vn = (IN.WorldView);
26     float3 Hn = 0.5 * (Vn + Ln);
27 root 1.1 // scalar product between light and normal vectors:
28 root 1.6 float ldn = abs(dot(Ln,Nn));
29 root 1.1 // scalar product between halfway and normal vectors:
30 root 1.6 float hdn = abs(dot(Hn,Nn));
31 root 1.1 // specialized "lit" function computes weights for
32     // diffuse and specular parts:
33     float4 litV = lit(ldn,hdn,SpecExpon);
34 root 1.5 float4 diffContrib = glstate.material.diffuse * ( litV.y * LightColor + glstate.lightmodel.ambient);
35 root 1.1 float4 specContrib = litV.y*litV.z * LightColor;
36     // sum of diffuse and specular contributions:
37     float4 result = diffContrib + specContrib;
38 root 1.5 OUT.col = result;
39 root 1.1 return OUT; // output of pixel shader
40     }
41